diff --git a/Asuro.iso b/Asuro.iso index cf1140d7..f9ba05ce 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/bin/kernel.bin b/bin/kernel.bin index 35590a2c..74f98bc2 100755 Binary files a/bin/kernel.bin and b/bin/kernel.bin differ diff --git a/iso/boot/asuro.bin b/iso/boot/asuro.bin index 35590a2c..74f98bc2 100755 Binary files a/iso/boot/asuro.bin and b/iso/boot/asuro.bin differ diff --git a/lib/gdt.ppu b/lib/gdt.ppu index cc358ba7..e6b11cdc 100644 Binary files a/lib/gdt.ppu and b/lib/gdt.ppu differ diff --git a/lib/kernel.ppu b/lib/kernel.ppu index 318a5522..302190f2 100644 Binary files a/lib/kernel.ppu and b/lib/kernel.ppu differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index 9aea99a0..2c2e8ca2 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index 5a3ddfda..0c8d9f83 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index 4b7fde25..f357d2d3 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/lib/scheduler.ppu b/lib/scheduler.ppu index 4080d073..b95ada6e 100644 Binary files a/lib/scheduler.ppu and b/lib/scheduler.ppu differ diff --git a/lib/vmemorymanager.ppu b/lib/vmemorymanager.ppu index 4fb6f5f5..c5fb2875 100644 Binary files a/lib/vmemorymanager.ppu and b/lib/vmemorymanager.ppu differ diff --git a/src/contextswitcher.pas b/src/contextswitcher.pas index e69de29b..b8061f83 100644 --- a/src/contextswitcher.pas +++ b/src/contextswitcher.pas @@ -0,0 +1,16 @@ +{ ************************************************ + * Asuro + * Unit: ContextSwitcher + * Description: Switches context between processes + * when preempted by the scheduler. + ************************************************ + * Author: K Morris + * Contributors: + ************************************************ } +unit contextswitcher; + +interface + +implementation; + +end. \ No newline at end of file diff --git a/src/gdt.pas b/src/gdt.pas index cb1b8d26..452386b4 100644 --- a/src/gdt.pas +++ b/src/gdt.pas @@ -35,6 +35,7 @@ var gdt_pointer : TGDT_Pointer; procedure init(); +procedure set_gate(Gate_Number : uint32; Base : uint32; Limit : uint32; Access : uint8; Granularity : uint8); implementation @@ -71,11 +72,11 @@ begin console.writestringln('GDT: INIT START.'); gdt_pointer.limit := (sizeof(TGDT_Entry) * 5) - 1; gdt_pointer.base := uint32(@gdt_entries); - set_gate($00, $00, $00, $00, $00); - set_gate($01, $00, $FFFFFFFF, $9A, $CF); - set_gate($02, $00, $FFFFFFFF, $92, $CF); - set_gate($03, $00, $FFFFFFFF, $FA, $CF); - set_gate($04, $00, $FFFFFFFF, $F2, $CF); + set_gate($00, $00, $00, $00, $00); //OFFSET: 0 + set_gate($01, $00, $FFFFFFFF, $9A, $CF); //OFFSET: 8 + set_gate($02, $00, $FFFFFFFF, $92, $CF); //OFFSET: 16 + set_gate($03, $00, $FFFFFFFF, $FA, $CF); //OFFSET: 24 + set_gate($04, $00, $FFFFFFFF, $F2, $CF); //OFFSET: 32 console.writestringln('GDT: FLUSH.'); flush_gdt(uint32(@gdt_pointer)); console.writestringln('GDT: INIT END.'); diff --git a/src/kernel.pas b/src/kernel.pas index c05b8db0..5692ac4b 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -25,6 +25,7 @@ uses vmemorymanager, pmemorymanager, lmemorymanager, + tss, scheduler, PCI; @@ -64,9 +65,11 @@ begin pmemorymanager.init(); vmemorymanager.init(); lmemorymanager.init(); - + tss.init(); scheduler.init(); + while true do begin end; + STI; isr32.hook(uint32(@bios_data_area.tick_update)); diff --git a/src/scheduler.pas b/src/scheduler.pas index 867f13dd..06dbf971 100644 --- a/src/scheduler.pas +++ b/src/scheduler.pas @@ -32,6 +32,9 @@ type end; PScheduler_Entry = ^TScheduler_Entry; +var + Active : Boolean; + procedure init; procedure add_task(priority : uint8); @@ -70,9 +73,11 @@ end; procedure delta(data : void); begin - Tick:= Tick + 1; - If Tick = 0 then context_switch(); - If (Current_Task^.Delta + (Current_Task^.Priority * Quantum)) <= Tick then context_switch(); + If Active then begin + Tick:= Tick + 1; + If Tick = 0 then context_switch(); + If (Current_Task^.Delta + (Current_Task^.Priority * Quantum)) <= Tick then context_switch(); + end; end; procedure init; @@ -85,6 +90,7 @@ begin Root_Task^.Next:= void(Root_Task); Current_Task:= Root_Task; Tick:= 0; + Active:= False; isr32.hook(uint32(@delta)); console.writestringln('SCHEDULER: INIT END.'); end; diff --git a/src/vmemorymanager.pas b/src/vmemorymanager.pas index c44f30ae..bd82a9d1 100644 --- a/src/vmemorymanager.pas +++ b/src/vmemorymanager.pas @@ -36,17 +36,42 @@ type PPageDirectory = ^TPageDirectory; var + KERNEL_PAGE_DIRECTORY : PPageDirectory; PageDirectory : PPageDirectory; procedure init; function new_page(page_number : uint16) : boolean; function map_page(page_number : uint16; block : uint16) : boolean; +function map_page_ex(page_number : uint16; block : uint16; PD : PPageDirectory) : boolean; function new_page_at_address(address : uint32) : boolean; procedure free_page(page_number : uint16); procedure free_page_at_address(address : uint32); +function new_page_directory : uint32; +function new_kernel_mapped_page_directory : uint32; implementation +uses + lmemorymanager; + +function new_page_directory : uint32; +begin + new_page_directory:= uint32(kalloc(sizeof(TPageDirectory))); +end; + +function new_kernel_mapped_page_directory : uint32; +var + PD : PPageDirectory; + i : uint32; + +begin + PD:= PPageDirectory(new_page_directory); + for i:=KERNEL_PAGE_NUMBER to 1023 do begin + PD^[i]:= KERNEL_PAGE_DIRECTORY^[i]; + end; + new_kernel_mapped_page_directory:= uint32(PD); +end; + function load_current_page_directory : PPageDirectory; var Directory : uint32; @@ -67,30 +92,26 @@ var begin console.writestringln('VMM: INIT BEGIN.'); PageDirectory:= load_current_page_directory; + KERNEL_PAGE_DIRECTORY:= PageDirectory; map_page(KERNEL_PAGE_NUMBER + 1, 1); map_page(KERNEL_PAGE_NUMBER + 2, 2); map_page(KERNEL_PAGE_NUMBER + 3, 3); console.writestringln('VMM: INIT END.'); end; -function map_page(page_number : uint16; block : uint16) : boolean; +function map_page_ex(page_number : uint16; block : uint16; PD : PPageDirectory) : boolean; var addr : ubit20; page : uint16; - rldpd : uint32; begin - map_page:= false; - PageDirectory^[page_number].Present:= true; + map_page_ex:= false; + PD^[page_number].Present:= true; addr:= block; - PageDirectory^[page_number].Address:= addr SHL 10; - PageDirectory^[page_number].PageSize:= true; - PageDirectory^[page_number].Writable:= true; - rldpd:= uint32(PageDirectory) - KERNEL_VIRTUAL_BASE; - asm - mov eax, rldpd - mov CR3, eax - end; + PD^[page_number].Address:= addr SHL 10; + PD^[page_number].PageSize:= true; + PD^[page_number].Writable:= true; + console.writestringln('VMM: New Page Added:'); console.writestring('VMM: - P:'); @@ -107,7 +128,28 @@ begin console.writestring(' - '); console.writehex(((block+1) SHL 22)); console.writestringln(']'); - map_page:= true; + map_page_ex:= true; +end; + +function map_page(page_number : uint16; block : uint16) : boolean; +var + addr : ubit20; + page : uint16; + rldpd : uint32; + +begin + map_page:= false; + PageDirectory^[page_number].Present:= true; + addr:= block; + PageDirectory^[page_number].Address:= addr SHL 10; + PageDirectory^[page_number].PageSize:= true; + PageDirectory^[page_number].Writable:= true; + map_page:= map_page_ex(page_number, block, PageDirectory); + rldpd:= uint32(PageDirectory) - KERNEL_VIRTUAL_BASE; + asm + mov eax, rldpd + mov CR3, eax + end; end; function new_page(page_number : uint16) : boolean;