Task Scheduler

git-svn-id: https://spexeah.com:8443/svn/Asuro@109 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
kieron
2017-05-18 16:17:22 +00:00
parent 8ce80d46c0
commit 31db2c943b
11 changed files with 86 additions and 3 deletions
BIN
View File
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+6 -3
View File
@@ -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
+80
View File
@@ -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.