diff --git a/Asuro.iso b/Asuro.iso index ac1edd92..f4ff1af9 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/bin/kernel.bin b/bin/kernel.bin new file mode 100755 index 00000000..f09b59da Binary files /dev/null and b/bin/kernel.bin differ diff --git a/iso/boot/asuro.bin b/iso/boot/asuro.bin index cd207ccf..f09b59da 100755 Binary files a/iso/boot/asuro.bin and b/iso/boot/asuro.bin differ diff --git a/lib/kernel.ppu b/lib/kernel.ppu new file mode 100644 index 00000000..ce3052d4 Binary files /dev/null and b/lib/kernel.ppu differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index 2ed8adb1..4a1a1b92 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index e215fd8e..d9e8355d 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index d4d89b5b..ab0d910e 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/lib/memorymanager.ppu b/lib/memorymanager.ppu new file mode 100644 index 00000000..6dfa05f4 Binary files /dev/null and b/lib/memorymanager.ppu differ diff --git a/lib/scheduler.ppu b/lib/scheduler.ppu new file mode 100644 index 00000000..5e5c79eb Binary files /dev/null and b/lib/scheduler.ppu differ diff --git a/src/kernel.pas b/src/kernel.pas index 253584f9..b241bae6 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -13,7 +13,8 @@ uses console, bios_data_area, keyboard, - memorymanager; + memorymanager, + scheduler; procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; @@ -49,8 +50,9 @@ begin idt.init(); isr.init(); irq.init(); - memorymanager.init(); + scheduler.init(); + pint2:= kalloc(18); pint:= kalloc(sizeof(uint32)); if pint = nil then console.writestringln('!'); @@ -59,13 +61,14 @@ begin console.writeintln(pint^); kfree(pint); pint2:= kalloc(128); - util.halt_and_catch_fire; STI; isr32.hook(uint32(@bios_data_area.tick_update)); //drivers keyboard.init(keyboard_layout); + scheduler.add_task(5); + scheduler.add_task(15); asm MOV dds, CS diff --git a/src/scheduler.pas b/src/scheduler.pas new file mode 100644 index 00000000..38558351 --- /dev/null +++ b/src/scheduler.pas @@ -0,0 +1,80 @@ +unit scheduler; + +interface + +uses + console, + isr32, + memorymanager; + +const + Quantum = 64; + +type + TScheduler_Entry = packed record + ThreadID : uint32; + Priority : uint8; + Delta : uint32; + Next : void; + end; + PScheduler_Entry = ^TScheduler_Entry; + +procedure init; +procedure add_task(priority : uint8); + +implementation + +var + Tick : uint32; + Root_Task : PScheduler_Entry = nil; + Current_Task : PScheduler_Entry = nil; + +procedure context_switch(); +begin + // This will switch contexts eventually, + // For now just print upon context switch. + Current_Task:= PScheduler_Entry(Current_Task^.Next); + console.writestring('Task: '); + console.writeintln(Current_Task^.ThreadID); +end; + +procedure add_task(priority : uint8); +var + new_task : PScheduler_Entry; + task : PScheduler_Entry; + i : uint32; + +begin + new_task:= PScheduler_Entry(kalloc(sizeof(TScheduler_Entry))); + new_task^.Priority:= priority; + new_task^.Delta:= Tick; + new_task^.Next:= void(Root_Task); + task:= Root_Task; + i:= 1; + while PScheduler_Entry(task^.next) <> Root_Task do begin + i:= i+1; + task:= PScheduler_Entry(task^.next); + end; + task^.next:= void(new_task); + new_task^.ThreadID:= i; +end; + +procedure delta(data : void); +begin + Tick:= Tick + 1; + If (Current_Task^.Delta + (Current_Task^.Priority * Quantum)) <= Tick then context_switch(); +end; + +procedure init; +begin + Root_Task:= PScheduler_Entry(kalloc(sizeof(TScheduler_Entry))); + Root_Task^.ThreadID:= 0; + Root_Task^.Priority:= 1; + Root_Task^.Delta:= 0; + Root_Task^.Next:= void(Root_Task); + Current_Task:= Root_Task; + Tick:= 0; + isr32.hook(uint32(@delta)); +end; + +end. \ No newline at end of file