implemented page allocator
This commit is contained in:
parent
48421fc0ef
commit
4341e1dce2
6 changed files with 195 additions and 10 deletions
29
src/main.zig
29
src/main.zig
|
|
@ -2,10 +2,11 @@ const std = @import("std");
|
|||
const isa = @import("riscv/isa.zig");
|
||||
const Fdt = @import("Fdt.zig");
|
||||
const Console = @import("drivers/Console.zig");
|
||||
const debug = @import("debug.zig");
|
||||
const mem = @import("mem.zig");
|
||||
|
||||
const UART_BASE: usize = 0x10000000;
|
||||
|
||||
var console: Console = undefined;
|
||||
const MEMORY_START = @extern([*]u8, .{.name = "__memory_start"});
|
||||
|
||||
fn uart_put(c: u8) void {
|
||||
const uart: *volatile u8 = @ptrFromInt(UART_BASE);
|
||||
|
|
@ -32,9 +33,29 @@ export fn kmain(hartid: u64, fdt_ptr: *const anyopaque) callconv(.c) noreturn {
|
|||
while (true) asm volatile ("wfi");
|
||||
};
|
||||
|
||||
console = Console.init(fdt).?;
|
||||
const root = fdt.root().?;
|
||||
|
||||
console.print("booting hydra...\n", .{});
|
||||
const console = Console.init(fdt).?;
|
||||
debug.init(console);
|
||||
|
||||
debug.print("booting hydra...\n", .{});
|
||||
|
||||
var reservations = fdt.memoryReservations();
|
||||
|
||||
while (reservations.next()) |reservation| {
|
||||
debug.print("0x{x}:0x{x}\n", .{reservation.address, reservation.size});
|
||||
}
|
||||
const memory = fdt.memory().?;
|
||||
var reg_iter = Fdt.parseReg(memory.getProperty("reg").?.data, root.addressCells(), root.sizeCells());
|
||||
const reg = reg_iter.next().?;
|
||||
const memory_end = reg.address + reg.size;
|
||||
|
||||
var buddy: mem.BuddyAllocator = .{};
|
||||
buddy.init(MEMORY_START[0..memory_end - @intFromPtr(MEMORY_START)]);
|
||||
debug.print("memory allocator initialized.\n", .{});
|
||||
|
||||
const allocator = buddy.allocator();
|
||||
_ = allocator;
|
||||
|
||||
while (true) {
|
||||
asm volatile ("wfi");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue