Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
Signed-off-by: TalonFloof <[email protected]>
  • Loading branch information
TalonFloof committed Nov 27, 2024
1 parent 1d4cb5c commit e790469
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion kobold/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn build(b: *std.Build) void {
personality.root_module.code_model = .medium;
}
personality.root_module.addImport("perlib", perlibMod);
b.getInstallStep().dependOn(addInstallObjectFile(b, personality, entry.name));
//b.getInstallStep().dependOn(addInstallObjectFile(b, personality, entry.name));
}
}

Expand Down
2 changes: 1 addition & 1 deletion kobold/hal/hal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub export fn HALInitialize(stackTop: usize, dtb: *allowzero anyopaque) callconv
pub fn HALOops(s: []const u8) void {
const oldInt = arch.intControl(false);
std.log.err("oops (hart 0x{x}) {s}", .{ arch.getHart().hartID, s });
debug.PrintBacktrace(0);
debug.PrintBacktrace(@returnAddress());
debug.EnterDebugger();
_ = arch.intControl(oldInt);
}
Expand Down
2 changes: 2 additions & 0 deletions kobold/hal/x86_64/mem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub fn init() void {
highestAddress = end;
}
physmem.Free(entry.base + 0xffff8000_00000000, entry.length);
} else if (entry.kind == .bootloader_reclaimable or entry.kind == .kernel_and_modules or entry.kind == .acpi_reclaimable) {
physmem.reservedMem += entry.length;
}
}
std.log.info("PFN Information Coverage Range 0x{x:0>16}-0x{x:0>16} ({} entries)", .{ lowestAddress, highestAddress, (highestAddress - lowestAddress) / 4096 });
Expand Down
6 changes: 4 additions & 2 deletions kobold/hal/x86_64/timer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn init() void {
hpetAddr[2] = 1;

const hz = 1000000000000000.0 / @as(f64, @floatFromInt(clock));
const interval = @as(usize, @intFromFloat(apic.hpetTicksPer100NS * 10000.0 * 1000.0));
const interval = @as(usize, @intFromFloat(apic.hpetTicksPer100NS * 10000.0 * 100.0));
timer_log.info("HPET @ {d} MHz for APIC Timer Calibration", .{hz / 1000 / 1000});
apic.write(0x320, 0x10000);
apic.write(0x3e0, 0xb);
Expand Down Expand Up @@ -80,7 +80,9 @@ pub fn init() void {
const count = 0xffffffff - apic.read(0x390);
ticksPerSecond = @intFromFloat(@as(f64, @floatFromInt(count)) * freq);
}
timer_log.info("{} APIC Ticks/s", .{ticksPerSecond});
const rawTicks = ticksPerSecond;
ticksPerSecond = (ticksPerSecond / 100000) * 100000;
timer_log.info("~{} APIC Ticks/s ({} Raw Ticks)", .{ ticksPerSecond, rawTicks });
}
}
apic.write(0x3e0, 0xb);
Expand Down
19 changes: 14 additions & 5 deletions kobold/kernel/physmem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ var freeCache: FreeCache = .{};

var firstFree: ?*FreeHeader = null;

pub var freeMem: usize = 0;
pub var usedMem: usize = 0;
pub var reservedMem: usize = 0;

fn allocate(size: usize, align_: usize) ?*anyopaque {
const newSize = size + align_;
freeMem -= size;
usedMem += size;

var cursor = firstFree;
while (cursor) |node| {
Expand Down Expand Up @@ -153,18 +159,23 @@ fn allocate(size: usize, align_: usize) ?*anyopaque {
}
cursor = next;
}
freeMem += size;
usedMem -= size;
return null;
}

pub fn Allocate(size: usize, align_: usize) ?*anyopaque {
lock.acquire();
const a = allocate(size, align_);
const s = hal.AlignUp(usize, size, 16);
const a = allocate(s, align_);
lock.release();
return a;
}

pub fn Free(address: usize, size: usize) void {
pub fn Free(address: usize, s: usize) void {
lock.acquire();
const size = hal.AlignUp(usize, s, 16);
freeMem += size;
const end = address + size;
var cursor = firstFree;
var prev: ?*FreeHeader = null;
Expand Down Expand Up @@ -234,13 +245,11 @@ 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});
std.log.debug(" {} KiB Used\n {} KiB System Reserved\n {} KiB Free\n {} KiB Total\n", .{ usedMem / 1024, reservedMem / 1024, freeMem / 1024, (usedMem + reservedMem + freeMem) / 1024 });
}

pub fn DebugInit() void {
Expand Down
1 change: 1 addition & 0 deletions kobold/kernel/port.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const std = @import("std");

pub const Message = struct {
sourceTID: usize = 0,
memBase: usize = 0,
memSize: usize = 0,
bufSize: usize = 0,
Expand Down
Empty file added kobold/kernel/syscall.zig
Empty file.
4 changes: 2 additions & 2 deletions scripts/generateDebugFile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sys import stdin
import sys

files = {}
curFile = ""
files = {"kernel": []}
curFile = "kernel"
symbolCount = 0

for line in stdin:
Expand Down

0 comments on commit e790469

Please sign in to comment.