| ... | ... | @@ -45,9 +45,11 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 45 | 45 | if (x86) { |
| 46 | 46 | // Intel processors have a unified instruction and data cache |
| 47 | 47 | // so there is nothing to do |
| 48 | exportIt(); |
| 48 | 49 | } else if (os == .windows and (arm32 or arm64)) { |
| 49 | | @compileError("TODO"); |
| 50 | // TODO |
| 50 | 51 | // FlushInstructionCache(GetCurrentProcess(), start, end - start); |
| 52 | // exportIt(); |
| 51 | 53 | } else if (arm32 and !apple) { |
| 52 | 54 | switch (os) { |
| 53 | 55 | .freebsd, .netbsd => { |
| ... | ... | @@ -57,23 +59,28 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 57 | 59 | }; |
| 58 | 60 | const result = sysarch(ARM_SYNC_ICACHE, @ptrToInt(&arg)); |
| 59 | 61 | std.debug.assert(result == 0); |
| 62 | exportIt(); |
| 60 | 63 | }, |
| 61 | 64 | .linux => { |
| 62 | 65 | const result = std.os.linux.syscall3(.cacheflush, start, end, 0); |
| 63 | 66 | std.debug.assert(result == 0); |
| 67 | exportIt(); |
| 64 | 68 | }, |
| 65 | | else => @compileError("TODO"), |
| 69 | else => {}, |
| 66 | 70 | } |
| 67 | 71 | } else if (os == .linux and mips) { |
| 68 | 72 | const flags = 3; // ICACHE | DCACHE |
| 69 | | const result = std.os.linux.syscall3(std.os.linux.SYS_cacheflush, start, end - start, flags); |
| 73 | const result = std.os.linux.syscall3(.cacheflush, start, end - start, flags); |
| 70 | 74 | std.debug.assert(result == 0); |
| 75 | exportIt(); |
| 71 | 76 | } else if (mips and os == .openbsd) { |
| 72 | | @compileError("TODO"); |
| 77 | // TODO |
| 73 | 78 | //cacheflush(start, (uintptr_t)end - (uintptr_t)start, BCACHE); |
| 79 | // exportIt(); |
| 74 | 80 | } else if (os == .linux and riscv) { |
| 75 | | const result = std.os.linux.syscall3(std.os.linux.SYS_riscv_flush_icache, start, end - start, 0); |
| 81 | const result = std.os.linux.syscall3(.riscv_flush_icache, start, end - start, 0); |
| 76 | 82 | std.debug.assert(result == 0); |
| 83 | exportIt(); |
| 77 | 84 | } else if (arm64 and !apple) { |
| 78 | 85 | // Get Cache Type Info. |
| 79 | 86 | // TODO memoize this? |
| ... | ... | @@ -112,8 +119,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 112 | 119 | } |
| 113 | 120 | } |
| 114 | 121 | asm volatile ("isb sy"); |
| 122 | exportIt(); |
| 115 | 123 | } else if (powerpc64) { |
| 116 | | @compileError("TODO"); |
| 124 | // TODO |
| 117 | 125 | //const size_t line_size = 32; |
| 118 | 126 | //const size_t len = (uintptr_t)end - (uintptr_t)start; |
| 119 | 127 | // |
| ... | ... | @@ -128,8 +136,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 128 | 136 | //for (uintptr_t line = start_line; line < end_line; line += line_size) |
| 129 | 137 | // __asm__ volatile("icbi 0, %0" : : "r"(line)); |
| 130 | 138 | //__asm__ volatile("isync"); |
| 139 | // exportIt(); |
| 131 | 140 | } else if (sparc) { |
| 132 | | @compileError("TODO"); |
| 141 | // TODO |
| 133 | 142 | //const size_t dword_size = 8; |
| 134 | 143 | //const size_t len = (uintptr_t)end - (uintptr_t)start; |
| 135 | 144 | // |
| ... | ... | @@ -139,14 +148,20 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 139 | 148 | // |
| 140 | 149 | //for (uintptr_t dword = start_dword; dword < end_dword; dword += dword_size) |
| 141 | 150 | // __asm__ volatile("flush %0" : : "r"(dword)); |
| 151 | // exportIt(); |
| 142 | 152 | } else if (apple) { |
| 143 | 153 | // On Darwin, sys_icache_invalidate() provides this functionality |
| 144 | 154 | sys_icache_invalidate(start, end - start); |
| 145 | | } else { |
| 146 | | @compileError("no __clear_cache implementation available for this target"); |
| 155 | exportIt(); |
| 147 | 156 | } |
| 148 | 157 | } |
| 149 | 158 | |
| 159 | const linkage = if (std.builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak; |
| 160 | |
| 161 | inline fn exportIt() void { |
| 162 | @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage }); |
| 163 | } |
| 164 | |
| 150 | 165 | // Darwin-only |
| 151 | 166 | extern fn sys_icache_invalidate(start: usize, len: usize) void; |
| 152 | 167 | // BSD-only |