mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-31 15:28:21 +00:00
refactor: use root instead of base
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
|
||||
pub const std_options = b.std_options;
|
||||
pub const panic = b.panic;
|
||||
pub const std_options = r.std_options;
|
||||
pub const panic = r.panic;
|
||||
|
||||
const c = @cImport({
|
||||
@cInclude("SDL.h");
|
||||
@@ -10,10 +10,10 @@ const c = @cImport({
|
||||
});
|
||||
|
||||
const std = @import("std");
|
||||
const ke = b.ke;
|
||||
const pl = b.pl;
|
||||
const ke = r.ke;
|
||||
const pl = r.pl;
|
||||
|
||||
const default_mem_size = b.gib(1);
|
||||
const default_mem_size = r.gib(1);
|
||||
|
||||
fn parse_mem_size(str: []const u8) !usize {
|
||||
if (str.len == 0) return default_mem_size;
|
||||
@@ -21,9 +21,9 @@ fn parse_mem_size(str: []const u8) !usize {
|
||||
const last = str[str.len - 1];
|
||||
|
||||
const mul: usize = switch (std.ascii.toLower(last)) {
|
||||
'k' => b.kib(1),
|
||||
'm' => b.mib(1),
|
||||
'g' => b.gib(1),
|
||||
'k' => r.kib(1),
|
||||
'm' => r.mib(1),
|
||||
'g' => r.gib(1),
|
||||
else => 1,
|
||||
};
|
||||
|
||||
|
||||
+17
-15
@@ -1,11 +1,13 @@
|
||||
const std = @import("std");
|
||||
const linux = std.os.linux;
|
||||
const b = @import("base");
|
||||
const pl = b.pl;
|
||||
const ke = b.ke;
|
||||
const ki = b.ke.private;
|
||||
const r = @import("root");
|
||||
const pl = r.pl;
|
||||
const ke = r.ke;
|
||||
const ki = r.ke.private;
|
||||
const posix = std.posix;
|
||||
|
||||
pub const entry = @import("entry.zig");
|
||||
|
||||
const timer = @import("timer.zig");
|
||||
|
||||
pub const c = @cImport({
|
||||
@@ -61,7 +63,7 @@ pub fn check_function(fn_name: []const u8, ret: usize) void {
|
||||
|
||||
pub var cpu_offsets: []usize = undefined;
|
||||
|
||||
pub fn early_init(_: *pl.BootInfo) linksection(b.init) void {
|
||||
pub fn early_init(_: *pl.BootInfo) linksection(r.init) void {
|
||||
percpu.local().pthread = c.pthread_self();
|
||||
my_cpu_id = 0;
|
||||
|
||||
@@ -82,16 +84,16 @@ pub fn early_init(_: *pl.BootInfo) linksection(b.init) void {
|
||||
global_state.phys_memory_memfd = memfd;
|
||||
global_state.phys_base = phys_base;
|
||||
|
||||
const pfndb_base = linux.mmap(null, b.tib(1), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
|
||||
const pfndb_base = linux.mmap(null, r.tib(1), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
|
||||
|
||||
check_function("mmap", pfndb_base);
|
||||
|
||||
const heap_base = linux.mmap(null, b.gib(8), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
|
||||
const heap_base = linux.mmap(null, r.gib(8), .{}, .{ .ANONYMOUS = true, .TYPE = .PRIVATE }, -1, 0);
|
||||
|
||||
check_function("mmap", heap_base);
|
||||
|
||||
b.kernel_pfndb_base = pfndb_base;
|
||||
b.kernel_heap_base = heap_base;
|
||||
r.kernel_pfndb_base = pfndb_base;
|
||||
r.kernel_heap_base = heap_base;
|
||||
|
||||
std.log.info("um: kernel heap lives at {X}", .{heap_base});
|
||||
}
|
||||
@@ -102,10 +104,10 @@ fn sigusr1_handler(_: posix.SIG, _: *const posix.siginfo_t, _: ?*anyopaque) call
|
||||
}
|
||||
}
|
||||
|
||||
fn make_thread(entry: *const fn (?*anyopaque) void, td: *ke.Thread) void {
|
||||
fn make_thread(entrypoint: *const fn (?*anyopaque) void, td: *ke.Thread) void {
|
||||
const stack = std.heap.page_allocator.alloc(u8, 16384) catch @panic("wtf");
|
||||
|
||||
td.init(@intFromPtr(stack.ptr), 16384, entry, null);
|
||||
td.init(@intFromPtr(stack.ptr), 16384, entrypoint, null);
|
||||
|
||||
td.priority = 0;
|
||||
td.priority_class = .Idle;
|
||||
@@ -127,14 +129,14 @@ fn other_cpu_entry(_: ?*anyopaque) callconv(.c) ?*anyopaque {
|
||||
return null;
|
||||
}
|
||||
|
||||
var cpu: ke.Cpu linksection(b.percpu) = undefined;
|
||||
var cpu: ke.Cpu linksection(r.percpu) = undefined;
|
||||
|
||||
fn idle(_: ?*anyopaque) void {}
|
||||
|
||||
extern var __percpu_start: u8;
|
||||
extern var __percpu_end: u8;
|
||||
|
||||
pub fn late_init(_: *pl.BootInfo) linksection(b.init) void {
|
||||
pub fn late_init(_: *pl.BootInfo) linksection(r.init) void {
|
||||
timer.init();
|
||||
timer.init_cpu();
|
||||
|
||||
@@ -180,14 +182,14 @@ pub fn late_init(_: *pl.BootInfo) linksection(b.init) void {
|
||||
cpuset.__bits[i / 64] |= @as(c_ulong, 1) << @intCast(i % 64);
|
||||
_ = c.pthread_attr_setaffinity_np(&attr, @sizeOf(c.cpu_set_t), &cpuset);
|
||||
|
||||
const r = c.pthread_create(
|
||||
const ret = c.pthread_create(
|
||||
&other_threads[i - 1],
|
||||
&attr,
|
||||
other_cpu_entry,
|
||||
null,
|
||||
);
|
||||
|
||||
if (r != 0) {
|
||||
if (ret != 0) {
|
||||
@panic("pthread_create() failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const std = @import("std");
|
||||
const posix = std.posix;
|
||||
const linux = std.os.linux;
|
||||
const c = b.pl.impl.c;
|
||||
const ke = b.ke;
|
||||
const c = r.pl.impl.c;
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
threadlocal var timerid: c.timer_t = undefined;
|
||||
@@ -20,7 +20,7 @@ fn timer_handler(_: posix.SIG, _: *const posix.siginfo_t, _: ?*anyopaque) callco
|
||||
}
|
||||
}
|
||||
|
||||
pub fn arm_timer(ns: b.Nanoseconds) void {
|
||||
pub fn arm_timer(ns: r.Nanoseconds) void {
|
||||
const value: c.struct_itimerspec = .{ .it_value = .{
|
||||
.tv_sec = @intCast(ns / std.time.ns_per_s),
|
||||
.tv_nsec = @intCast(ns % std.time.ns_per_s),
|
||||
|
||||
Reference in New Issue
Block a user