Skip to content

Commit

Permalink
[PIT/KMain] Using scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
Vild committed May 6, 2016
1 parent c3b9fa1 commit 6a390a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
18 changes: 17 additions & 1 deletion Kernel/src/CPU/PIT.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import CPU.IDT;
import IO.Port;
import IO.Log;
import Data.Register;
import Task.Scheduler;

struct PIT {
public:
static void Init(uint hz = 100) {
static void Init(uint hz = 1000) {
IDT.Register(IRQ(0), &onTick);
this.hz = hz;
uint divisor = 1193180 / hz;
Expand All @@ -31,6 +32,21 @@ private:
__gshared uint hz;
__gshared ulong counter;
static void onTick(Registers* regs) {
import Memory.FrameAllocator;
import Task.Scheduler;
import IO.TextMode : scr = GetScreen;

counter++;

const ulong usedMiB = FrameAllocator.UsedFrames / 256;
const ulong maxMiB = FrameAllocator.MaxFrames / 256;
const ulong pid = (scheduler) ? scheduler.CurrentProcess.Pid : 0;
ulong memory;
if (maxMiB)
memory = (usedMiB * 100) / maxMiB;
scr.WriteStatus("Memory used: ", usedMiB, "MiB/", maxMiB, "MiB(", memory, "%)\tPID: ", pid, "\tSeconds since boot: ", Seconds);

if (scheduler)
scheduler.SchedulerTick();
}
}
34 changes: 22 additions & 12 deletions Kernel/src/KMain.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Memory.FrameAllocator;
import Data.Linker;
import Data.Address;
import Memory.Heap;
import Task.Scheduler;
import Task.Process;

alias scr = GetScreen;

Expand All @@ -28,6 +30,18 @@ immutable uint minor = __VERSION__ % 1000;

__gshared FSRoot rootFS;

void a() {
while (true) {

}
}

void b() {
while (true) {

}
}

extern (C) int kmain(uint magic, ulong info) {
PreInit();
Welcome();
Expand All @@ -36,29 +50,23 @@ extern (C) int kmain(uint magic, ulong info) {
sti;
}

KernelProcess aProc = new KernelProcess(&a);
scheduler.AddProcess(aProc);

KernelProcess bProc = new KernelProcess(&b);
scheduler.AddProcess(bProc);

scr.Writeln();
scr.Writeln("User input:");

dchar key;
import HW.PS2.KBSet : KeyCode;

while (key != 27 /* KeyCode.Escape */ ) {
const ulong usedMiB = FrameAllocator.UsedFrames / 256;
const ulong maxMiB = FrameAllocator.MaxFrames / 256;
const ulong memory = (usedMiB * 100) / maxMiB;
scr.WriteStatus("Memory used: ", usedMiB, "MiB/", maxMiB, "MiB(", memory, "%)\t\t\tSeconds since boot: ", PIT.Seconds);

// Get User input and write it out
key = Keyboard.Pop();
if (key != '\0' && key < 0x100 && key != 27)
scr.Write(cast(char)key);
ulong * mem = cast(ulong*)GetKernelHeap.Alloc(1*1024*1024);
if (!mem) {
scr.color.Foreground = Colors.Magenta;
scr.color.Background = Colors.Yellow;
scr.Writeln("Out of memory ;)");
return -1;
}
}
scr.Writeln();

Expand Down Expand Up @@ -106,6 +114,8 @@ void Init(uint magic, ulong info) {

scr.Writeln("Initrd initializing...");
LoadInitrd();

scheduler = new Scheduler();
}

void LoadInitrd() {
Expand Down

0 comments on commit 6a390a5

Please sign in to comment.