Skip to content

Commit

Permalink
meow
Browse files Browse the repository at this point in the history
Signed-off-by: TalonFloof <[email protected]>
  • Loading branch information
TalonFloof committed Nov 15, 2024
1 parent 7362a8b commit 101e121
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ iso: build_pc64
rm -r --force /tmp/kobold_iso

run_pc64: iso
qemu-system-x86_64 -enable-kvm -cpu host,migratable=off -m 32M -serial stdio -device pcie-pci-bridge -cdrom kobold.iso -no-shutdown -no-reboot
qemu-system-x86_64 -enable-kvm -cpu host,migratable=off -m 8M -serial stdio -device pcie-pci-bridge -cdrom kobold.iso

run_rv64: build_rv64
qemu-system-riscv64 -machine virt -m 128M -serial stdio -device ramfb -device virtio-keyboard-device -device virtio-mouse-device -kernel kobold/zig-out/bin/kernel
Expand Down
16 changes: 8 additions & 8 deletions kobold/hal/alarmqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@ pub const AlarmQueue = struct {
_ = hal.arch.intControl(old);
}

fn schedule(self: *AlarmQueue) void {
const elapsedTime = self.timerNextInterval - hal.arch.getRemainingTime();
pub fn schedule(self: *AlarmQueue) void {
const elapsedTime = self.timerNextInterval - hal.arch.getRemainingTime.?();
self.timerCounter += elapsedTime;
var closestDeadline: u64 = 0xffff_ffff_ffff_ffff;
var ind = self.list.first;
while (ind) |i| {
if(self.timerCounter >= i.data.deadline) {
if (self.timerCounter >= i.data.deadline) {
const next = i.next;
i.data.func(i.data.data);
list.remove(i);
self.list.remove(i);
ind = next;
} else if(i.data.deadline < closestDeadline) {
} else if (i.data.deadline < closestDeadline) {
closestDeadline = i.data.deadline;
ind = i.next;
} else {
ind = i.next;
}
}
if(closestDeadline == 0xffff_ffff_ffff_ffff) {
if (closestDeadline == 0xffff_ffff_ffff_ffff) {
self.timerNextInterval = 0;
return;
} else {
self.timerNextInterval = closestDeadline-self.timerCounter;
hal.arch.setTimerDeadline(self.timerNextInterval);
self.timerNextInterval = closestDeadline - self.timerCounter;
hal.arch.setTimerDeadline.?(self.timerNextInterval);
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion kobold/hal/hal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub const ArchInterface = struct {
getHart: fn () *HartInfo,
intControl: fn (bool) bool,
waitForInt: fn () void,
setTimerDeadline: ?fn (usize) void = null, // In Microseconds, will be ticked if not implemented
setTimerDeadline: ?fn (u64) void = null, // In Microseconds, will be ticked if not implemented
getRemainingTime: ?fn () u64 = null,
debugGet: ?fn () u8 = null,
debugDisasm: ?fn (usize, *anyopaque) callconv(.C) usize = null,
memModel: memmodel.MemoryModel,
Expand Down
7 changes: 6 additions & 1 deletion kobold/hal/x86_64/isr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ pub export fn ExceptionHandler(entry: u8, con: *hal.arch.Context) callconv(.C) v

pub export fn IRQHandler(entry: u8, con: *hal.arch.Context) callconv(.C) *hal.arch.Context {
// TODO: Write IRQ Handler
std.log.warn("IRQ 0x{x}!", .{entry - 0x20});
apic.write(0xb0, 0);
if (entry - 0x20 == 0x0) {
const queue = &(hal.arch.getHart()).alarmQueue;
queue.lock.acquire();
queue.schedule();
queue.lock.release();
}
return con;
}
1 change: 1 addition & 0 deletions kobold/hal/x86_64/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ pub const Interface: hal.ArchInterface = .{
.intControl = ArchIntControl,
.waitForInt = ArchWaitForInt,
.setTimerDeadline = timer.setDeadline,
.getRemainingTime = timer.getRemainingUs,
.debugGet = ArchDebugGet,
.debugDisasm = disasm,
.memModel = .{
Expand Down
6 changes: 3 additions & 3 deletions kobold/hal/x86_64/timer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ pub fn init() void {
apic.write(0x320, 0x20);
}

pub fn setDeadline(microsecs: usize) void {
const t: usize = @intFromFloat(@as(f64, @floatFromInt(ticksPerSecond)) * (@as(f64, @floatFromInt(microsecs)) / 1000000.0));
pub fn setDeadline(microsecs: u64) void {
const t: u64 = @intFromFloat(@as(f64, @floatFromInt(ticksPerSecond)) * (@as(f64, @floatFromInt(microsecs)) / 1000000.0));
apic.write(0x380, t);
}

pub fn getRemainingUs() usize {
pub fn getRemainingUs() u64 {
const count = 0xffffffff - apic.read(0x390);
return @intFromFloat(@as(f64, @floatFromInt(count)) * (@as(f64, @floatFromInt(ticksPerSecond)) / 1000000.0));
}
5 changes: 4 additions & 1 deletion kobold/kernel/physmem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub fn Free(address: usize, size: usize) void {
}

pub fn AllocateC(size: usize) callconv(.C) ?*anyopaque {
return Allocate(size + @sizeOf(usize), 0);
return Allocate(size, @alignOf(usize));
}

pub fn FreeC(addr: ?*anyopaque, size: usize) callconv(.C) void {
Expand All @@ -234,10 +234,13 @@ pub fn PrintMap(cmd: []const u8, iter: *std.mem.SplitIterator(u8, .sequence)) vo
_ = cmd;
_ = iter;
var cursor = firstFree;
var freeSpace: usize = 0;
while (cursor) |node| {
std.log.debug("0x{x}-0x{x} Free\n", .{ node.start, node.end - 1 });
freeSpace += node.end - node.start;
cursor = node.next;
}
std.log.debug(" {} KiB Free\n", .{freeSpace / 1024});
}

pub fn DebugInit() void {
Expand Down
1 change: 0 additions & 1 deletion scripts/generateDebugFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
if syms[i][1] == -1:
if i+1 < len(syms):
syms[i][1] = syms[i+1][0]-syms[i][0]
print(syms[i][3], syms[i][1])
else:
syms[i][1] = 0

Expand Down

0 comments on commit 101e121

Please sign in to comment.