From 0d6dbcfa649cdb4d8f6d0c6dd4c9424178f9d93d Mon Sep 17 00:00:00 2001 From: Saza <49511480+saza-ku@users.noreply.github.com> Date: Sat, 27 Apr 2024 11:45:32 +0900 Subject: [PATCH] upgrade zig to 0.14 --- .devcontainer/Dockerfile | 2 +- .devcontainer/devcontainer.json | 7 ++++ .gitignore | 1 + Dockerfile | 2 +- build.zig | 54 ++++++++++++-------------- src/drivers/virtio/common.zig | 6 ++- src/fs.zig | 2 +- src/main.zig | 19 +++++++-- src/mem.zig | 32 +++++++++------- src/param.zig | 6 +-- src/pci.zig | 2 +- src/rand.zig | 2 +- src/sync.zig | 8 ++-- src/timer.zig | 2 +- src/wasi.zig | 68 ++++++++++++++++----------------- src/x64.ld | 6 +++ src/x64.zig | 1 - 17 files changed, 122 insertions(+), 98 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 75cdb98f..eec772ce 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm RUN apt-get update && apt-get install -y cmake ARG LLVM_URL=https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4.tar.xz -ARG ZIG_VERSION=zig-linux-x86_64-0.12.0-dev.1856+94c63f31f +ARG ZIG_VERSION=zig-linux-x86_64-0.14.0-dev.2540+f857bf72e ENV PATH="/usr/bin/zig:${PATH}" ENV PATH=/usr/local/llvm/bin:$PATH diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e5f2f22f..5041defd 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,4 +4,11 @@ "context": "..", "dockerfile": "./Dockerfile" }, + "customizations": { + "vscode": { + "extensions": [ + "ziglang.vscode-zig" + ] + } + }, } diff --git a/.gitignore b/.gitignore index ca8ee097..9ba5fe18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ iso_root/ zig-out/ zig-cache/ +.zig-cache/ build/ virtio-net.pcap disk.tar diff --git a/Dockerfile b/Dockerfile index 08c31d92..090e33f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ghcr.io/mewz-project/wasker:latest -ARG ZIG_VERSION=zig-linux-x86_64-0.12.0-dev.1856+94c63f31f +ARG ZIG_VERSION=zig-linux-x86_64-0.14.0-dev.2540+f857bf72e ENV PATH="/usr/bin/zig:${PATH}" diff --git a/build.zig b/build.zig index b0673c9a..3a69e544 100644 --- a/build.zig +++ b/build.zig @@ -1,7 +1,7 @@ const std = @import("std"); const Build = @import("std").Build; const Target = @import("std").Target; -const CrossTarget = @import("std").zig.CrossTarget; +const Query = @import("std").Target.Query; const Feature = @import("std").Target.Cpu.Feature; const TEST_DIR_PATH = "build/test"; @@ -79,49 +79,43 @@ pub fn build(b: *Build) !void { const params = BuildParams.new(b); const options = params.setOptions(b); - const features = Target.x86.Feature; - - var disabled_features = Feature.Set.empty; - var enabled_features = Feature.Set.empty; - - disabled_features.addFeature(@intFromEnum(features.mmx)); - disabled_features.addFeature(@intFromEnum(features.sse)); - disabled_features.addFeature(@intFromEnum(features.sse2)); - disabled_features.addFeature(@intFromEnum(features.avx)); - disabled_features.addFeature(@intFromEnum(features.avx2)); - enabled_features.addFeature(@intFromEnum(features.soft_float)); - - const target = CrossTarget{ .cpu_arch = Target.Cpu.Arch.x86_64, .os_tag = Target.Os.Tag.freestanding, .cpu_features_sub = disabled_features, .cpu_features_add = enabled_features }; - const optimize = b.standardOptimizeOption(.{}); const newlib_build_cmd = b.addSystemCommand(&[_][]const u8{"./scripts/build-newlib.sh"}); const lwip_build_cmd = b.addSystemCommand(&[_][]const u8{"./scripts/build-lwip.sh"}); + const target = b.resolveTargetQuery(.{ + .cpu_arch = .x86_64, + .os_tag = .freestanding, + .ofmt = .elf, + }); + const kernel = b.addExecutable(.{ .name = "mewz.elf", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .optimize = optimize, .target = target, - .linkage = std.build.CompileStep.Linkage.static, + .linkage = .static, + .code_model = .kernel, }); - kernel.code_model = .kernel; - kernel.setLinkerScriptPath(.{ .path = "src/x64.ld" }); - kernel.addAssemblyFile(Build.LazyPath{ .path = "src/boot.S" }); - kernel.addAssemblyFile(Build.LazyPath{ .path = "src/interrupt.S" }); - kernel.addObjectFile(Build.LazyPath{ .path = "build/newlib/libc.a" }); - kernel.addObjectFile(Build.LazyPath{ .path = "build/lwip/libtcpip.a" }); - kernel.addObjectFile(Build.LazyPath{ .path = "build/lwip/liblwipcore.a" }); - kernel.addObjectFile(Build.LazyPath{ .path = "build/lwip/liblwipallapps.a" }); - kernel.addCSourceFile(Build.Step.Compile.CSourceFile{ .file = Build.LazyPath{ .path = "src/c/newlib_support.c" }, .flags = &[_][]const u8{ "-I", "submodules/newlib/newlib/libc/include" } }); - kernel.addCSourceFile(Build.Step.Compile.CSourceFile{ .file = Build.LazyPath{ .path = "src/c/lwip_support.c" }, .flags = &[_][]const u8{ "-I", "submodules/newlib/newlib/libc/include" } }); + + kernel.linker_script = b.path("src/x64.ld"); + kernel.addAssemblyFile(b.path("src/boot.S")); + kernel.addAssemblyFile(b.path("src/interrupt.S")); + kernel.addObjectFile(b.path("build/newlib/libc.a")); + kernel.addObjectFile(b.path("build/lwip/libtcpip.a")); + kernel.addObjectFile(b.path("build/lwip/liblwipcore.a")); + kernel.addObjectFile(b.path("build/lwip/liblwipallapps.a")); + kernel.addCSourceFile(.{ .file = b.path("src/c/newlib_support.c"), .flags = &.{ "-I", "submodules/newlib/newlib/libc/include" } }); + kernel.addCSourceFile(.{ .file = b.path("src/c/lwip_support.c"), .flags = &.{ "-I", "submodules/newlib/newlib/libc/include" } }); if (params.obj_path) |p| { - kernel.addObjectFile(Build.LazyPath{ .path = p }); + kernel.addObjectFile(b.path(p)); } if (params.dir_path) |_| { - kernel.addObjectFile(Build.LazyPath{ .path = "build/disk.o" }); + kernel.addObjectFile(b.path("build/disk.o")); } - kernel.addOptions("options", options); + kernel.root_module.addOptions("options", options); + kernel.entry = .{ .symbol_name = "boot" }; b.installArtifact(kernel); const kernel_step = b.step("kernel", "Build the kernel"); diff --git a/src/drivers/virtio/common.zig b/src/drivers/virtio/common.zig index 4d9520dd..5175a33b 100644 --- a/src/drivers/virtio/common.zig +++ b/src/drivers/virtio/common.zig @@ -301,7 +301,10 @@ pub const AvailRing = struct { fn new(queue_size: u16, allocator: Allocator) Error!Self { const size = @sizeOf(u16) * queue_size + @sizeOf(u16) * 3; - const data = try allocator.alignedAlloc(u8, 2, size); + const data = allocator.alignedAlloc(u8, 8, size) catch |err| { + log.fatal.printf("failed to allocate avail ring: {}\n", .{err}); + return err; + }; @memset(data, 0); return Self{ .data = data, @@ -535,7 +538,6 @@ pub fn VirtioMmioTransport(comptime DeviceConfigType: type) type { } self.common_config.queue_select = virtq.index; - @fence(std.builtin.AtomicOrder.SeqCst); const offset = self.notify_off_multiplier * self.common_config.queue_notify_off; const addr = self.notify + @as(usize, @intCast(offset)); @as(*volatile u16, @ptrFromInt(addr)).* = virtq.index; diff --git a/src/fs.zig b/src/fs.zig index 67585eb9..958057e3 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -7,7 +7,7 @@ const Stream = stream.Stream; const FILES_MAX: usize = 200; -extern const _binary_build_disk_tar_start: [*]u8; +extern var _binary_build_disk_tar_start: [*]u8; pub var files: [FILES_MAX]RegularFile = undefined; pub var dirs: [FILES_MAX]Directory = undefined; diff --git a/src/main.zig b/src/main.zig index a1e8306f..a041b5b9 100644 --- a/src/main.zig +++ b/src/main.zig @@ -23,22 +23,23 @@ const wasi = @import("wasi.zig"); extern fn wasker_main() void; -export fn bspEarlyInit(boot_magic: u32, boot_params: u64) align(16) callconv(.C) void { - _ = boot_magic; +export fn bspEarlyInit(boot_magic: u32, boot_params: u32) align(16) callconv(.C) void { const bootinfo = @as(*multiboot.BootInfo, @ptrFromInt(boot_params)); const cmdline = util.getString(bootinfo.cmdline); + x64.init(); param.parseFromArgs(cmdline); uart.init(); lapic.init(); ioapic.init(); picirq.init(); - x64.init(); + printBootinfo(boot_magic, bootinfo); timer.init(); interrupt.init(); mem.init(bootinfo); pci.init(); + log.debug.print("pci init finish\n"); if (param.params.isNetworkEnabled()) { virtio_net.init(); } @@ -76,3 +77,15 @@ export fn write(fd: i32, b: *const u8, count: usize) callconv(.C) isize { } return -1; } + +fn printBootinfo(magic: u32, bootinfo: *multiboot.BootInfo) void { + log.debug.print("=== bootinfo ===\n"); + log.debug.printf("magic: {x}\n", .{magic}); + log.debug.printf("bootinfo addr: {x}\n", .{@intFromPtr(bootinfo)}); + log.debug.printf("flags: {b:0>8}\n", .{bootinfo.flags}); + log.debug.printf("mmap_addr: {x}\n", .{bootinfo.mmap_addr}); + log.debug.printf("mmap_length: {x}\n", .{bootinfo.mmap_length}); + const boot_loader_name = @as([*]u8, @ptrFromInt(bootinfo.boot_loader_name))[0..20]; + log.debug.printf("boot_loader_name: {s}\n", .{boot_loader_name}); + log.debug.print("================\n"); +} diff --git a/src/mem.zig b/src/mem.zig index 47b52f58..d0531a22 100644 --- a/src/mem.zig +++ b/src/mem.zig @@ -176,20 +176,20 @@ pub fn init(info: *multiboot.BootInfo) void { // disable alignment checks for mmaps @setRuntimeSafety(false); - // mmap_addr points to the MemoryMap array - // mmap_length is the size of the MemoryMap array in bytes - const mmaps_ptr = @as([*]multiboot.MemoryMap, @ptrFromInt(info.mmap_addr)); - const mmaps = mmaps_ptr[0 .. info.mmap_length / @sizeOf(multiboot.MemoryMap)]; - - for (mmaps) |*mmap| { - if (mmap.type == multiboot.MemoryType.available) { - // exclude the kernel image from available memory, because it's already used - const base = @max(image_end_addr, mmap.base); - const end = mmap.base + mmap.length; - if (end <= base) { - continue; - } - log.info.printf("available memory: {x} - {x}\n", .{ base, end }); + var off: usize = 0; + while (off < info.mmap_length) { + const mmap = @as(*multiboot.MemoryMap, @ptrFromInt(off + info.mmap_addr)); + log.debug.printf("mmap.type: {x}\n", .{@intFromEnum(mmap.type)}); + + // exclude the kernel image from available memory, because it's already used + const base = @max(image_end_addr, mmap.base); + const end = mmap.base + mmap.length; + + log.debug.printf("mmap.base: {x}\n", .{mmap.base}); + log.debug.printf("end: {x}\n", .{end}); + + if (mmap.type == multiboot.MemoryType.available and base < end) { + log.debug.printf("available memory: {x} - {x}\n", .{ base, end }); // align the range to BLOCK_SIZE const aligned_base = util.roundUp(usize, base, BLOCK_SIZE); @@ -201,11 +201,15 @@ pub fn init(info: *multiboot.BootInfo) void { const buf = @as([*]u8, @ptrFromInt(aligned_base))[0..length]; boottime_fba = FixedBufferAllocator.init(buf); boottime_allocator = boottime_fba.?.allocator(); + + log.debug.printf("boottime allocator: addr=0x{x}, len=0x{x}\n", .{ aligned_base, length }); } else { // add the range to the free list initRange(aligned_base, length); } } + + off += mmap.size + @sizeOf(u32); } } } diff --git a/src/param.zig b/src/param.zig index bb769afa..b989fb5e 100644 --- a/src/param.zig +++ b/src/param.zig @@ -16,9 +16,9 @@ pub var params = Params{}; // TODO: Add tests pub fn parseFromArgs(args: []const u8) void { - var params_itr = std.mem.split(u8, args, " "); + var params_itr = std.mem.splitScalar(u8, args, ' '); while (params_itr.next()) |part| { - var kv = std.mem.split(u8, part, "="); + var kv = std.mem.splitScalar(u8, part, '='); const k = kv.next() orelse continue; const v = kv.next() orelse continue; @@ -36,7 +36,7 @@ pub fn parseFromArgs(args: []const u8) void { } fn parseIp(ip_str: []const u8) void { - var parts = std.mem.split(u8, ip_str, "/"); + var parts = std.mem.splitScalar(u8, ip_str, '/'); const ip = parts.next() orelse @panic("invalid ip format"); const subnet = parts.next() orelse @panic("invalid ip format"); if (parts.next()) |_| { diff --git a/src/pci.zig b/src/pci.zig index 456375e8..df3c139d 100644 --- a/src/pci.zig +++ b/src/pci.zig @@ -92,7 +92,7 @@ pub const Device = struct { const Self = @This(); fn new(bus: u8, slot: u8, func: u8) (Allocator.Error || Error)!Self { - var config_buffer: [16]u32 align(8) = [16]u32{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + var config_buffer: [16]u32 align(16) = [16]u32{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (0..16) |i| { const config_value = readConfig(bus, slot, func, @as(u8, @intCast(i * 4))); config_buffer[i] = config_value; diff --git a/src/rand.zig b/src/rand.zig index 4a9a47f2..810550ab 100644 --- a/src/rand.zig +++ b/src/rand.zig @@ -1,4 +1,4 @@ -const Random = @import("std").rand.Random; +const Random = @import("std").Random; pub const X64Random = Random{ .ptr = undefined, diff --git a/src/sync.zig b/src/sync.zig index 2815a452..bd6ab511 100644 --- a/src/sync.zig +++ b/src/sync.zig @@ -20,13 +20,13 @@ pub fn SpinLock(comptime T: type) type { @panic("deadlock"); } - while (@atomicRmw(bool, &this.locked, builtin.AtomicRmwOp.Xchg, true, builtin.AtomicOrder.Acquire)) {} + while (@atomicRmw(bool, &this.locked, builtin.AtomicRmwOp.Xchg, true, builtin.AtomicOrder.acquire)) {} return @as(*T, @alignCast(@ptrCast(this.ptr))); } pub fn release(this: *volatile This) void { - _ = @atomicRmw(bool, &this.locked, builtin.AtomicRmwOp.Xchg, false, builtin.AtomicOrder.Release); + _ = @atomicRmw(bool, &this.locked, builtin.AtomicRmwOp.Xchg, false, builtin.AtomicOrder.release); popcli(); } @@ -43,13 +43,13 @@ pub const Waiter = struct { } pub fn setWait(self: *volatile Self) void { - @atomicStore(bool, &self.waiting, true, builtin.AtomicOrder.SeqCst); + @atomicStore(bool, &self.waiting, true, builtin.AtomicOrder.seq_cst); } pub fn wait(self: *volatile Self) void { while (true) { while (self.waiting) {} - if (!@atomicLoad(bool, &self.waiting, builtin.AtomicOrder.SeqCst)) { + if (!@atomicLoad(bool, &self.waiting, builtin.AtomicOrder.seq_cst)) { break; } } diff --git a/src/timer.zig b/src/timer.zig index 324305b5..3603dd13 100644 --- a/src/timer.zig +++ b/src/timer.zig @@ -41,7 +41,7 @@ pub const Timer = struct { } pub fn isFinished(self: *Self) bool { - return @atomicLoad(bool, &self.*.is_finished_internal, std.builtin.AtomicOrder.SeqCst); + return @atomicLoad(bool, &self.*.is_finished_internal, std.builtin.AtomicOrder.seq_cst); } }; diff --git a/src/wasi.zig b/src/wasi.zig index c17a990a..5c0b4fdd 100644 --- a/src/wasi.zig +++ b/src/wasi.zig @@ -639,15 +639,13 @@ pub fn integrationTest() void { lock.acquire().* = 1; lock.release(); - const base = memory_grow(1) * mem.BLOCK_SIZE; - // Socket - log.info.printf("base: {x}\n", .{base}); + _ = memory_grow(1) * mem.BLOCK_SIZE; - if (!testClientSocket(base)) { + if (!testClientSocket()) { return; } - if (!testServerSocket(base)) { + if (!testServerSocket()) { return; } @@ -732,11 +730,11 @@ fn testReadfile() bool { return true; } -fn testServerSocket(base: usize) bool { +fn testServerSocket() bool { @setRuntimeSafety(false); // sock_open - const fd1 = @as(*i32, @ptrFromInt(base + 4 + 0xffff800000000000)); + const fd1 = @as(*i32, @ptrFromInt(4 + linear_memory_offset)); fd1.* = -2; var res = sock_open(@enumFromInt(1), @enumFromInt(2), 4); if (@intFromEnum(res) != 0) { @@ -749,16 +747,16 @@ fn testServerSocket(base: usize) bool { } // sock_bind - var ip = @as([*]u8, @ptrFromInt(base + 8 + 0xffff800000000000)); + var ip = @as([*]u8, @ptrFromInt(8 + linear_memory_offset)); ip[0] = 0; ip[1] = 0; ip[2] = 0; ip[3] = 0; const port = 1234; - var ip_iovec_ptr = @as(*IoVec, @ptrFromInt(base + 12 + 0xffff800000000000)); - ip_iovec_ptr.buf = @as(u32, @intCast(base + 8)); + var ip_iovec_ptr = @as(*IoVec, @ptrFromInt(12 + linear_memory_offset)); + ip_iovec_ptr.buf = 8; ip_iovec_ptr.buf_len = 4; - res = sock_bind(fd1.*, @as(i32, @intCast(base + 12)), port); + res = sock_bind(fd1.*, 12, port); if (@intFromEnum(res) != 0) { log.fatal.printf("sock_bind failed: {d}\n", .{@intFromEnum(res)}); return false; @@ -774,35 +772,35 @@ fn testServerSocket(base: usize) bool { log.info.print("server socket test: sock_listen succeeded\n"); // sock_accept - res = sock_accept(fd1.*, @as(i32, @intCast(base + 20))); + res = sock_accept(fd1.*, 20); if (@intFromEnum(res) != 0) { log.fatal.printf("sock_accept failed: {d}\n", .{@intFromEnum(res)}); return false; } - const fd2 = @as(*i32, @ptrFromInt(base + 20 + 0xffff800000000000)); + const fd2 = @as(*i32, @ptrFromInt(20 + linear_memory_offset)); log.info.print("server socket test: sock_accept succeeded\n"); // sock_recv - var buf_iovec_ptr = @as(*IoVec, @ptrFromInt(base + 24 + 0xffff800000000000)); - buf_iovec_ptr.buf = @as(u32, @intCast(base + 40)); + var buf_iovec_ptr = @as(*IoVec, @ptrFromInt(24 + linear_memory_offset)); + buf_iovec_ptr.buf = 40; buf_iovec_ptr.buf_len = 1024; - res = sock_recv(fd2.*, @as(i32, @intCast(base + 24)), 1, 0, @as(i32, @intCast(base + 32)), @as(i32, @intCast(base + 36))); + res = sock_recv(fd2.*, 24, 1, 0, 32, 36); if (@intFromEnum(res) != 0) { log.fatal.printf("sock_recv failed: {d}\n", .{@intFromEnum(res)}); return false; } log.info.print("server socket test: sock_recv succeeded\n"); - var buf = @as([*]u8, @ptrFromInt(base + 40 + 0xffff800000000000)); - const len = @as(*i32, @ptrFromInt(base + 32 + 0xffff800000000000)); + var buf = @as([*]u8, @ptrFromInt(40 + linear_memory_offset)); + const len = @as(*i32, @ptrFromInt(32 + linear_memory_offset)); const received_buf = buf[0..@as(usize, @intCast(len.*))]; log.info.print(received_buf); // random_get // sock_send - _ = random_get(@as(i32, @intCast(base + 40)), 5); + _ = random_get(40, 5); buf_iovec_ptr.buf_len = 5; - res = sock_send(fd2.*, @as(i32, @intCast(base + 24)), 1, 0, @as(i32, @intCast(base + 32))); + res = sock_send(fd2.*, 24, 1, 0, 32); if (@intFromEnum(res) != 0) { log.fatal.printf("sock_send failed: {d}\n", .{@intFromEnum(res)}); return false; @@ -828,11 +826,11 @@ fn testServerSocket(base: usize) bool { return true; } -fn testClientSocket(base: usize) bool { +fn testClientSocket() bool { @setRuntimeSafety(false); // sock_open - const fd0 = @as(*i32, @ptrFromInt(base + 0 + 0xffff800000000000)); + const fd0 = @as(*i32, @ptrFromInt(0 + linear_memory_offset)); fd0.* = -2; var res = sock_open(@enumFromInt(1), @enumFromInt(2), 0); if (@intFromEnum(res) != 0) { @@ -842,15 +840,15 @@ fn testClientSocket(base: usize) bool { log.info.print("client socket test: sock_open succeeded\n"); // sock_connect - var ip_iovec = @as(*IoVec, @ptrFromInt(base + 4 + 0xffff800000000000)); - ip_iovec.buf = @as(u32, @intCast(base + 8)); + var ip_iovec = @as(*IoVec, @ptrFromInt(4 + linear_memory_offset)); + ip_iovec.buf = 8; ip_iovec.buf_len = 4; - var ip = @as([*]u8, @ptrFromInt(base + 8 + 0xffff800000000000)); + var ip = @as([*]u8, @ptrFromInt(8 + linear_memory_offset)); ip[0] = 1; ip[1] = 1; ip[2] = 1; ip[3] = 1; - res = sock_connect(fd0.*, @as(i32, @intCast(base + 4)), 80); + res = sock_connect(fd0.*, 4, 80); if (@intFromEnum(res) != 0) { log.info.printf("sock_connect failed: {d}\n", .{@intFromEnum(res)}); return false; @@ -858,16 +856,16 @@ fn testClientSocket(base: usize) bool { log.info.print("client socket test: sock_connect succeeded\n"); // fd_write - var buf_iovec = @as([*]IoVec, @ptrFromInt(base + 12 + 0xffff800000000000))[0..2]; - var buf = @as([*]u8, @ptrFromInt(base + 28 + 0xffff800000000000)); + var buf_iovec = @as([*]IoVec, @ptrFromInt(12 + linear_memory_offset))[0..2]; + var buf = @as([*]u8, @ptrFromInt(28 + linear_memory_offset)); @memcpy(buf, "GET / HTT"); - buf_iovec[0].buf = @as(u32, @intCast(base + 28)); + buf_iovec[0].buf = 28; buf_iovec[0].buf_len = 9; - buf = @as([*]u8, @ptrFromInt(base + 40 + 0xffff800000000000)); + buf = @as([*]u8, @ptrFromInt(40 + linear_memory_offset)); @memcpy(buf, "P/1.1\r\n\r\n"); - buf_iovec[1].buf = @as(u32, @intCast(base + 40)); + buf_iovec[1].buf = 40; buf_iovec[1].buf_len = 9; - res = fd_write(fd0.*, @as(i32, @intCast(base + 12)), 2, @as(i32, @intCast(base + 52))); + res = fd_write(fd0.*, 12, 2, 52); if (@intFromEnum(res) != 0) { log.info.printf("fd_write failed: {d}\n", .{@intFromEnum(res)}); return false; @@ -875,7 +873,7 @@ fn testClientSocket(base: usize) bool { log.info.print("client socket test: fd_write succeeded\n"); // sock_getlocaladdr - _ = sock_getlocaladdr(fd0.*, @as(i32, @intCast(base + 4)), @as(i32, @intCast(base + 40)), @as(i32, @intCast(base + 44))); + _ = sock_getlocaladdr(fd0.*, 4, 40, 44); if (ip[0] != 10 or ip[1] != 0 or ip[2] != 2 or ip[3] != 15) { log.info.printf("sock_getlocaladdr failed: {d}.{d}.{d}.{d}\n", .{ ip[0], ip[1], ip[2], ip[3] }); return false; @@ -883,8 +881,8 @@ fn testClientSocket(base: usize) bool { log.info.print("client socket test: sock_getlocaladdr succeeded\n"); // sock_getpeeraddr - _ = sock_getpeeraddr(fd0.*, @as(i32, @intCast(base + 4)), @as(i32, @as(i32, @intCast(base + 40))), @as(i32, @intCast(base + 44))); - const peer_port = @as(*i32, @ptrFromInt(base + 44 + 0xffff800000000000)); + _ = sock_getpeeraddr(fd0.*, 4, 40, 44); + const peer_port = @as(*i32, @ptrFromInt(44 + linear_memory_offset)); if (peer_port.* != 80) { log.info.printf("sock_getpeeraddr failed: {d}\n", .{@intFromEnum(res)}); return false; diff --git a/src/x64.ld b/src/x64.ld index 5d6baf81..3826bad9 100644 --- a/src/x64.ld +++ b/src/x64.ld @@ -51,6 +51,8 @@ SECTIONS { .rodata : AT(ADDR(.rodata) - VMA_OFFSET) { *(.rodata); *(.rodata.*); + *(.lrodata); + *(.lrodata.*); . = ALIGN(4096); __cpu_local = .; @@ -63,6 +65,8 @@ SECTIONS { .data : AT(ADDR(.data) - VMA_OFFSET) { *(.data); *(.data.*); + *(.ldata); + *(.ldata.*); *(.got*); @@ -75,6 +79,8 @@ SECTIONS { __bss = .; *(.bss); *(.bss.*); + *(.lbss); + *(.lbss.*); __bss_end = .; /* The kernel page table (physical addresses). */ diff --git a/src/x64.zig b/src/x64.zig index 68feaa01..14febfb7 100644 --- a/src/x64.zig +++ b/src/x64.zig @@ -4,7 +4,6 @@ pub const EFLAGS_IF = 0x00000200; pub fn init() void { enableSSE(); - @fence(std.builtin.AtomicOrder.SeqCst); enableAVX(); }