| ... | ... | @@ -62,12 +62,13 @@ fn clear_cache(start: usize, end: usize) callconv(.c) void { |
| 62 | 62 | // exportIt(); |
| 63 | 63 | } else if (arm32 and !apple) { |
| 64 | 64 | switch (os) { |
| 65 | | .freebsd, .netbsd => { |
| 66 | | var arg = arm_sync_icache_args{ |
| 65 | // FreeBSD and NetBSD should be changed to do direct syscalls here... |
| 66 | .freebsd, .netbsd, .openbsd => { |
| 67 | var arg: arm_sync_icache_args = .{ |
| 67 | 68 | .addr = start, |
| 68 | | .len = end - start, |
| 69 | .size = end - start, |
| 69 | 70 | }; |
| 70 | | const result = sysarch(ARM_SYNC_ICACHE, @intFromPtr(&arg)); |
| 71 | const result = sysarch(ARM_SYNC_ICACHE, &arg); |
| 71 | 72 | std.debug.assert(result == 0); |
| 72 | 73 | exportIt(); |
| 73 | 74 | }, |
| ... | ... | @@ -79,32 +80,32 @@ fn clear_cache(start: usize, end: usize) callconv(.c) void { |
| 79 | 80 | else => {}, |
| 80 | 81 | } |
| 81 | 82 | } else if (os == .linux and mips) { |
| 82 | | const flags = 3; // ICACHE | DCACHE |
| 83 | | const result = std.os.linux.syscall3(.cacheflush, start, end - start, flags); |
| 83 | const result = std.os.linux.syscall3(.cacheflush, start, end - start, ICACHE | DCACHE); |
| 84 | 84 | std.debug.assert(result == 0); |
| 85 | 85 | exportIt(); |
| 86 | 86 | } else if (os == .netbsd and mips) { |
| 87 | 87 | // Replace with https://github.com/ziglang/zig/issues/23904 in the future. |
| 88 | | const cfa: extern struct { |
| 89 | | va: usize, |
| 90 | | nbytes: usize, |
| 91 | | whichcache: u32, |
| 92 | | } = .{ |
| 93 | | .va = start, |
| 94 | | .nbytes = end - start, |
| 95 | | .whichcache = 3, // ICACHE | DCACHE |
| 88 | const cfa: mips_cacheflush_args = .{ |
| 89 | .addr = start, |
| 90 | .size = end - start, |
| 91 | .which = ICACHE | DCACHE, |
| 96 | 92 | }; |
| 97 | 93 | asm volatile ("syscall" |
| 98 | 94 | : |
| 99 | 95 | : [_] "{$2}" (165), // nr = SYS_sysarch |
| 100 | | [_] "{$4}" (0), // op = MIPS_CACHEFLUSH |
| 96 | [_] "{$4}" (MIPS_CACHEFLUSH), // op |
| 101 | 97 | [_] "{$5}" (&cfa), // args = &cfa |
| 102 | 98 | : .{ .r1 = true, .r2 = true, .r3 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true, .r13 = true, .r14 = true, .r15 = true, .r24 = true, .r25 = true, .hi = true, .lo = true, .memory = true }); |
| 103 | 99 | exportIt(); |
| 104 | 100 | } else if (mips and os == .openbsd) { |
| 105 | | // TODO |
| 106 | | //cacheflush(start, (uintptr_t)end - (uintptr_t)start, BCACHE); |
| 107 | | // exportIt(); |
| 101 | const cfa: mips_cacheflush_args = .{ |
| 102 | .addr = start, |
| 103 | .size = end - start, |
| 104 | .which = ICACHE | DCACHE, |
| 105 | }; |
| 106 | const result = sysarch(MIPS_CACHEFLUSH, &cfa); |
| 107 | std.debug.assert(result == 0); |
| 108 | exportIt(); |
| 108 | 109 | } else if (os == .linux and riscv) { |
| 109 | 110 | const result = std.os.linux.syscall3(.riscv_flush_icache, start, end - start, 0); |
| 110 | 111 | std.debug.assert(result == 0); |
| ... | ... | @@ -191,12 +192,25 @@ fn exportIt() void { |
| 191 | 192 | @export(&clear_cache, .{ .name = "__clear_cache", .linkage = common.linkage, .visibility = common.visibility }); |
| 192 | 193 | } |
| 193 | 194 | |
| 195 | // MIPS-only |
| 196 | const ICACHE = 0x1; |
| 197 | const DCACHE = 0x2; |
| 198 | |
| 194 | 199 | // Darwin-only |
| 195 | 200 | extern fn sys_icache_invalidate(start: usize, len: usize) void; |
| 201 | |
| 196 | 202 | // BSD-only |
| 203 | const ARM_SYNC_ICACHE = 0; |
| 197 | 204 | const arm_sync_icache_args = extern struct { |
| 198 | | addr: usize, // Virtual start address |
| 199 | | len: usize, // Region size |
| 205 | addr: usize, |
| 206 | size: usize, |
| 200 | 207 | }; |
| 201 | | const ARM_SYNC_ICACHE = 0; |
| 202 | | extern "c" fn sysarch(number: i32, args: usize) i32; |
| 208 | |
| 209 | const MIPS_CACHEFLUSH = 0; |
| 210 | const mips_cacheflush_args = extern struct { |
| 211 | addr: usize, |
| 212 | size: usize, |
| 213 | which: c_uint, |
| 214 | }; |
| 215 | |
| 216 | extern fn sysarch(op: c_uint, args: *const anyopaque) c_int; |