From 05dfe2583a67bf007bbaf9e7c72dc567a28752c9 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Fri, 3 Sep 2021 04:37:07 +0200 Subject: [PATCH] Address Spaces: LLVM F segment address space test --- test/stage2/llvm.zig | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/stage2/llvm.zig b/test/stage2/llvm.zig index e1d32aa086c2..820768efe3e3 100644 --- a/test/stage2/llvm.zig +++ b/test/stage2/llvm.zig @@ -372,4 +372,54 @@ pub fn addCases(ctx: *TestContext) !void { \\pub export fn main() void { _ = entry; } ); } + + { + var case = ctx.exeUsingLlvmBackend("f segment address space reading and writing", linux_x64); + case.addCompareOutput( + \\fn assert(ok: bool) void { + \\ if (!ok) unreachable; + \\} + \\ + \\fn setFs(value: c_ulong) void { + \\ asm volatile ( + \\ \\syscall + \\ : + \\ : [number] "{rax}" (158), + \\ [code] "{rdi}" (0x1002), + \\ [val] "{rsi}" (value), + \\ : "rcx", "r11", "memory" + \\ ); + \\} + \\ + \\fn getFs() c_ulong { + \\ var result: c_ulong = undefined; + \\ asm volatile ( + \\ \\syscall + \\ : + \\ : [number] "{rax}" (158), + \\ [code] "{rdi}" (0x1003), + \\ [ptr] "{rsi}" (@ptrToInt(&result)), + \\ : "rcx", "r11", "memory" + \\ ); + \\ return result; + \\} + \\ + \\var test_value: u64 = 12345; + \\ + \\pub export fn main() c_int { + \\ const orig_fs = getFs(); + \\ + \\ setFs(@ptrToInt(&test_value)); + \\ assert(getFs() == @ptrToInt(&test_value)); + \\ + \\ var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0); + \\ assert(test_ptr.* == 12345); + \\ test_ptr.* = 98765; + \\ assert(test_value == 98765); + \\ + \\ setFs(orig_fs); + \\ return 0; + \\} + , ""); + } }