diff --git a/src/sys/mm/memory.c b/src/sys/mm/memory.c index 3096a71..84d45bd 100644 --- a/src/sys/mm/memory.c +++ b/src/sys/mm/memory.c @@ -112,7 +112,7 @@ { if(mmFreePages == NULL) { - //UBU: replace this with static location + //UBU: replace this with static location + offset mmFreePages = kmalloc(sizeof(mMap)); mmFreePages->First = mmFreePages; mmFreePages->Last = mmFreePages; @@ -122,7 +122,7 @@ } else { - //UBU: replace this with static location + //UBU: replace this with static location + offset tmpMap = kmalloc(sizeof(mMap)); mmFreePages->Last->Next = tmpMap; tmpMap->Previous = mmFreePages->Last; @@ -162,74 +162,77 @@ return (0); } -uInt32 countMemory() { - register uInt32 *mem = 0x0; - unsigned long memCount = -1, tempMemory = 0x0; - unsigned short memKb = 0; - unsigned char irq1State, irq2State; - unsigned long cr0 = 0x0; +uInt32 countMemory() +{ + register uInt32 *mem = 0x0; + unsigned long memCount = -1, tempMemory = 0x0; + unsigned short memKb = 0; + uInt8 irq1State, irq2State; + unsigned long cr0 = 0x0; - /* - * Save The States Of Both IRQ 1 And 2 So We Can Turn Them Off And Restore - * Them Later - */ - irq1State = inportByte(0x21); - irq2State = inportByte(0xA1); + /* + * Save The States Of Both IRQ 1 And 2 So We Can Turn Them Off And Restore + * Them Later + */ + irq1State = inportByte(0x21); + irq2State = inportByte(0xA1); - /* Turn Off IRQ 1 And 2 To Prevent Chances Of Faults While Examining Memory */ - outportByte(0x21, 0xFF); - outportByte(0xA1, 0xFF); + /* Turn Off IRQ 1 And 2 To Prevent Chances Of Faults While Examining Memory */ + outportByte(0x21, 0xFF); + outportByte(0xA1, 0xFF); - /* Save The State Of Register CR0 */ - asm volatile ( - "movl %%cr0, %%ebx\n" - : "=a" (cr0) - : - : "ebx" - ); + /* Save The State Of Register CR0 */ + asm volatile ( + "movl %%cr0, %%ebx\n" + : "=a" (cr0) + : + : "ebx" + ); - asm volatile ("wbinvd"); - asm volatile ( - "movl %%ebx, %%cr0\n" - : - : "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) - : "ebx" - ); + asm volatile ("wbinvd"); + asm volatile ( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) + : "ebx" + ); - while (memKb < 4096 && memCount != 0) { - memKb++; - if (memCount == -1) - memCount = 0; - memCount += 1024 * 1024; - mem = (uInt32 *)memCount; - tempMemory = *mem; - *mem = 0x55AA55AA; - asm("": : :"memory"); - if (*mem != 0x55AA55AA) { - memCount = 0; - } - else { - *mem = 0xAA55AA55; - asm("": : :"memory"); - if (*mem != 0xAA55AA55) { - memCount = 0; - } - } - asm("": : :"memory"); - *mem = tempMemory; - } + while (memKb < 4096 && memCount != 0) + { + memKb++; + if (memCount == -1) + memCount = 0; - asm volatile ( - "movl %%ebx, %%cr0\n" - : - : "a" (cr0) - : "ebx" - ); + memCount += 1024 * 1024; + mem = (uInt32 *)memCount; + tempMemory = *mem; + *mem = 0x55AA55AA; + asm("": : :"memory"); - /* Restore States For Both IRQ 1 And 2 */ - outportByte(0x21, irq1State); - outportByte(0xA1, irq2State); + if (*mem != 0x55AA55AA) + memCount = 0; + else + { + *mem = 0xAA55AA55; + asm("": : :"memory"); + if (*mem != 0xAA55AA55) + memCount = 0; + } + asm("": : :"memory"); + *mem = tempMemory; + } - /* Return Amount Of Memory In Pages */ - return ((memKb * 1024 * 1024) / 4096); - } + asm volatile ( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0) + : "ebx" + ); + + /* Restore States For Both IRQ 1 And 2 */ + outportByte(0x21, irq1State); + outportByte(0xA1, irq2State); + + /* Return Amount Of Memory In Pages */ + return ((memKb * 1024 * 1024) / 4096); +}