ds
git-svn-id: https://spexeah.com:8443/svn/Asuro@145 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
d53b41750a
commit
126ec01343
6
.bochsrc
6
.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
|
||||
|
BIN
lib/kernel.ppu
BIN
lib/kernel.ppu
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/libpsystem.a
BIN
lib/libpsystem.a
Binary file not shown.
BIN
lib/multiboot.o
BIN
lib/multiboot.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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');
|
||||
|
@ -54,6 +54,10 @@ type
|
||||
mtype: uint32;
|
||||
end;
|
||||
|
||||
var
|
||||
multibootinfo : Pmultiboot_info_t = nil;
|
||||
multibootmagic : uint32;
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
@ -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.
|
@ -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
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user