Skip to content

Commit

Permalink
Address Spaces: LLVM F segment address space test
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Sep 4, 2021
1 parent a56ea37 commit 05dfe25
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/stage2/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
\\}
, "");
}
}

0 comments on commit 05dfe25

Please sign in to comment.