diff --git a/.bochsrc b/.bochsrc index a7842072..2c976176 100644 --- a/.bochsrc +++ b/.bochsrc @@ -53,7 +53,7 @@ #display_library: amigaos #display_library: beos #display_library: carbon -#display_library: macintosh +display_library: sdl #display_library: nogui #display_library: rfb, options="timeout=60" # time to wait for client #display_library: sdl, options="fullscreen" # startup in fullscreen mode @@ -775,5 +775,5 @@ i440fxsupport: enabled=1 # romimage: file=:bios:BIOS-bochs-latest, address=0xf0000 # floppya: 1_44=[fd:], status=inserted #======================================================================= -display_library: sdl -magic_break: enabled=1 +#display_library: sdl +#magic_break: enabled=1 diff --git a/Asuro.iso b/Asuro.iso index 8b06ece9..3ca62d68 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/lib/kernel.ppu b/lib/kernel.ppu index 33c4b565..fd236e07 100644 Binary files a/lib/kernel.ppu and b/lib/kernel.ppu differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index cb2b97d8..98fd15e2 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index 98bbd1a4..01680bf8 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index 7559fd25..fd91a214 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/lib/multiboot.o b/lib/multiboot.o index 22500298..292888c6 100644 Binary files a/lib/multiboot.o and b/lib/multiboot.o differ diff --git a/lib/multiboot.ppu b/lib/multiboot.ppu index 831f0fe6..e356cbc4 100644 Binary files a/lib/multiboot.ppu and b/lib/multiboot.ppu differ diff --git a/lib/pmemorymanager.ppu b/lib/pmemorymanager.ppu index fef27735..23d63314 100644 Binary files a/lib/pmemorymanager.ppu and b/lib/pmemorymanager.ppu differ diff --git a/lib/vmemorymanager.ppu b/lib/vmemorymanager.ppu index b1b1bf40..0d356513 100644 Binary files a/lib/vmemorymanager.ppu and b/lib/vmemorymanager.ppu differ diff --git a/src/kernel.pas b/src/kernel.pas index a5a1413a..be30828f 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -24,23 +24,21 @@ implementation procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; [public, alias: 'kmain']; var c : uint8; - mbi : Pmultiboot_info_t; - mbm : uint32; z : uint32; dds : uint32; pint : puint32; pint2 : puint32; - keyboard_layout : array [0..1] of TKeyInfo; begin - mbi:= mbinfo; - mbm:= mbmagic; + multibootinfo:= mbinfo; + multibootmagic:= mbmagic; + console.init(); console.writestringln('Booting Asuro...'); - if (mbm <> MULTIBOOT_BOOTLOADER_MAGIC) then begin + if (multibootmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then begin console.setdefaultattribute(console.combinecolors(Red, Black)); console.writestringln('Multiboot Compliant Boot-Loader Needed!'); console.writestringln('HALTING'); diff --git a/src/multiboot.pas b/src/multiboot.pas index 3c8f06b7..95b85ed8 100644 --- a/src/multiboot.pas +++ b/src/multiboot.pas @@ -54,6 +54,10 @@ type mtype: uint32; end; +var + multibootinfo : Pmultiboot_info_t = nil; + multibootmagic : uint32; + implementation end. diff --git a/src/pmemorymanager.pas b/src/pmemorymanager.pas index 2cfcf0ae..4bc5b013 100644 --- a/src/pmemorymanager.pas +++ b/src/pmemorymanager.pas @@ -4,42 +4,133 @@ interface uses util, - console; + console, + multiboot; type TPhysicalMemoryEntry = packed record - Present : Boolean; - MappedTo : uint32; + Scanned : Boolean; + Present : Boolean; + Allocated : Boolean; + MappedTo : uint32; end; TPhysicalMemory = array[0..1023] of TPhysicalMemoryEntry; procedure init; +function alloc_block(block : uint16; caller : uint32) : boolean; function new_block(caller : uint32) : uint16; procedure free_block(block : uint16; caller : uint32); implementation var - PhysicalMemory: TPhysicalMemory; + PhysicalMemory : TPhysicalMemory; + nPresent : uint32; + +procedure set_memory_area_present(base : uint64; length : uint64; present : boolean); +var + BlockHigh, BlockLow : uint16; + +begin + BlockLow:= base SHR 22; + BlockHigh:= base+length SHR 22; + if not present then begin + PhysicalMemory[BlockLow].Scanned:= True; + PhysicalMemory[BlockHigh].Scanned:= True; + PhysicalMemory[BlockLow].Present:= False; + PhysicalMemory[BlockHigh].Present:= False; + end else begin + If not PhysicalMemory[BlockLow].Scanned then begin + PhysicalMemory[BlockLow].Scanned:= True; + PhysicalMemory[BlockLow].Present:= True; + end; + If not PhysicalMemory[BlockHigh].Scanned then begin + PhysicalMemory[BlockHigh].Scanned:= True; + PhysicalMemory[BlockHigh].Present:= True; + end; + end; +end; + +procedure walk_memory_map; +var + mmap : Pmemory_map_t; + address : uint32; + length : uint32; + i : uint16; + +begin + address:= multibootinfo^.mmap_addr + KERNEL_VIRTUAL_BASE; + length:= multibootinfo^.mmap_length; + mmap:= Pmemory_map_t(address); + for i:=0 to 1023 do begin + PhysicalMemory[i].Present:= True; + PhysicalMemory[i].Allocated:= False; + PhysicalMemory[i].Scanned:= False; + PhysicalMemory[i].MappedTo:= 0; + end; + while uint32(mmap) < (address + length) do begin + console.writewordln(mmap^.mtype); + if mmap^.mtype <> $01 then begin + set_memory_area_present(mmap^.base_addr, mmap^.length, False); + end; + mmap:= Pmemory_map_t(uint32(mmap)+mmap^.size+sizeof(mmap^.size)); + end; + nPresent:= 0; + for i:=0 to 1023 do begin + if PhysicalMemory[i].Present then nPresent:= nPresent + 1; + end; +end; + +procedure force_alloc_block(block : uint16; caller : uint32); +begin + PhysicalMemory[block].Allocated:= True; + PhysicalMemory[block].MappedTo:= caller; + console.writestring('PMM: 4MiB Block Force Allocated @ '); + console.writeword(block); + console.writestring(' ['); + console.writehex(block SHL 22); + console.writestring(' - '); + console.writehex(((block+1) SHL 22)); + console.writestringln(']'); +end; procedure init; begin console.writestringln('PMM: INIT BEGIN.'); - with PhysicalMemory[0] do begin - Present:= True; - MappedTo:= 0; - end; - with PhysicalMemory[1] do begin - Present:= True; - MappedTo:= 0; - end; - with PhysicalMemory[2] do begin - Present:= True; - MappedTo:= 0; - end; + walk_memory_map; + force_alloc_block(0, 0); + force_alloc_block(1, 0); + force_alloc_block(2, 0); //First 12MiB reserved for Kernel/BIOS. + console.writestring('PMM: '); + console.writeword(nPresent); + console.writestringln('/1024 Block Available for Allocation.'); console.writestringln('PMM: INIT END.'); end; +function alloc_block(block : uint16; caller : uint32) : boolean; +begin + alloc_block:= false; + if (PhysicalMemory[block].Present) then begin + if PhysicalMemory[block].Allocated then begin + alloc_block:= false; + end else begin + PhysicalMemory[block].Allocated:= True; + PhysicalMemory[block].MappedTo:= caller; + console.writestring('4MiB Block Allocated @ '); + console.writeword(block); + console.writestring(' ['); + console.writehex(block SHL 22); + console.writestring(' - '); + console.writehex(((block+1) SHL 22)); + console.writestringln(']'); + alloc_block:= true; + end; + end else begin + GPF; + alloc_block:= false; + end; +end; + function new_block(caller : uint32) : uint16; var i : uint16; @@ -47,18 +138,13 @@ var begin new_block:= 0; for i:=2 to 1023 do begin - if not PhysicalMemory[i].Present then begin - PhysicalMemory[i].Present:= True; - PhysicalMemory[i].MappedTo:= caller; - new_block:= i; - console.writestring('4MiB Block Added @ '); - console.writeword(i); - console.writestring(' ['); - console.writehex(i SHL 22); - console.writestring(' - '); - console.writehex(((i+1) SHL 22)); - console.writestringln(']'); - exit; + if PhysicalMemory[i].Present then begin + if not PhysicalMemory[i].Allocated then begin + if alloc_block(i, caller) then begin + new_block:= i; + exit; + end; + end; end; end; end; @@ -73,11 +159,15 @@ begin GPF; exit; end; + if not PhysicalMemory[block].Present then begin + GPF; + exit; + end; if PhysicalMemory[block].MappedTo <> caller then begin GPF; exit; end; - PhysicalMemory[block].Present:= false; + PhysicalMemory[block].Allocated:= false; end; end. \ No newline at end of file diff --git a/src/stub/stub.asm b/src/stub/stub.asm index a1e66e96..ce536f12 100644 --- a/src/stub/stub.asm +++ b/src/stub/stub.asm @@ -81,11 +81,11 @@ _loader: jmp ecx kstart: - mov dword [BootPageDirectory], 0 - invlpg [0] + mov dword [BootPageDirectory], 0 + invlpg [0] mov esp, KERNEL_STACK+KERNEL_STACKSIZE ;Create kernel stack push eax ;Multiboot magic number - add ebx, KERNEL_VIRTUAL_BASE + add ebx, KERNEL_VIRTUAL_BASE push ebx ;Multiboot info call kmain ;Call kernel entrypoint cli ;Clear interrupts diff --git a/src/vmemorymanager.pas b/src/vmemorymanager.pas index 1801aa9c..8823bcba 100644 --- a/src/vmemorymanager.pas +++ b/src/vmemorymanager.pas @@ -81,14 +81,14 @@ begin mov eax, rldpd mov CR3, eax end; - console.writestringln('New Page Added:'); + console.writestringln('VMM: New Page Added:'); - console.writestring('- P:'); + console.writestring('VMM: - P:'); console.writehex(page_number); console.writestring('-->B:'); console.writehexln(block); - console.writestring('- P:['); + console.writestring('VMM: - P:['); console.writehex(page_number SHL 22); console.writestring(' - '); console.writehex(((page_number+1) SHL 22));