mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
compiler-rt: More clear_cache implementations
This commit is contained in:
parent
d57b5205c6
commit
e9c49f423d
2 changed files with 33 additions and 17 deletions
|
|
@ -20,6 +20,8 @@ comptime {
|
||||||
.aarch64,
|
.aarch64,
|
||||||
.aarch64_be,
|
.aarch64_be,
|
||||||
.aarch64_32,
|
.aarch64_32,
|
||||||
|
.riscv32,
|
||||||
|
.riscv64,
|
||||||
=> @export(@import("compiler_rt/clear_cache.zig").clear_cache, .{
|
=> @export(@import("compiler_rt/clear_cache.zig").clear_cache, .{
|
||||||
.name = "__clear_cache",
|
.name = "__clear_cache",
|
||||||
.linkage = linkage,
|
.linkage = linkage,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
|
||||||
.mips, .mipsel, .mips64, .mips64el => true,
|
.mips, .mipsel, .mips64, .mips64el => true,
|
||||||
else => false,
|
else => false,
|
||||||
};
|
};
|
||||||
|
const riscv = switch (arch) {
|
||||||
|
.riscv32, .riscv64 => true,
|
||||||
|
else => false,
|
||||||
|
};
|
||||||
const powerpc64 = switch (arch) {
|
const powerpc64 = switch (arch) {
|
||||||
.powerpc64, .powerpc64le => true,
|
.powerpc64, .powerpc64le => true,
|
||||||
else => false,
|
else => false,
|
||||||
|
|
@ -45,28 +49,31 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
|
||||||
@compileError("TODO");
|
@compileError("TODO");
|
||||||
// FlushInstructionCache(GetCurrentProcess(), start, end - start);
|
// FlushInstructionCache(GetCurrentProcess(), start, end - start);
|
||||||
} else if (arm32 and !apple) {
|
} else if (arm32 and !apple) {
|
||||||
if (os == .freebsd or os == .netbsd) {
|
switch (os) {
|
||||||
// struct arm_sync_icache_args arg;
|
.freebsd, .netbsd => {
|
||||||
//
|
var arg = arm_sync_icache_args{
|
||||||
// arg.addr = (uintptr_t)start;
|
.addr = start,
|
||||||
// arg.len = (uintptr_t)end - (uintptr_t)start;
|
.len = end - start,
|
||||||
//
|
};
|
||||||
// sysarch(ARM_SYNC_ICACHE, &arg);
|
const result = sysarch(ARM_SYNC_ICACHE, @ptrToInt(&arg));
|
||||||
@compileError("TODO: implement for NetBSD/FreeBSD");
|
std.debug.assert(result == 0);
|
||||||
} else if (os == .linux) {
|
},
|
||||||
const result = std.os.linux.syscall3(.cacheflush, start, end, 0);
|
.linux => {
|
||||||
std.debug.assert(result == 0);
|
const result = std.os.linux.syscall3(.cacheflush, start, end, 0);
|
||||||
} else {
|
std.debug.assert(result == 0);
|
||||||
@compileError("no __clear_cache implementation available for this target");
|
},
|
||||||
|
else => @compileError("TODO"),
|
||||||
}
|
}
|
||||||
} else if (os == .linux and mips) {
|
} else if (os == .linux and mips) {
|
||||||
@compileError("TODO");
|
const flags = 3; // ICACHE | DCACHE
|
||||||
//const uintptr_t start_int = (uintptr_t)start;
|
const result = std.os.linux.syscall3(std.os.linux.SYS_cacheflush, start, end - start, flags);
|
||||||
//const uintptr_t end_int = (uintptr_t)end;
|
std.debug.assert(result == 0);
|
||||||
//syscall(__NR_cacheflush, start, (end_int - start_int), BCACHE);
|
|
||||||
} else if (mips and os == .openbsd) {
|
} else if (mips and os == .openbsd) {
|
||||||
@compileError("TODO");
|
@compileError("TODO");
|
||||||
//cacheflush(start, (uintptr_t)end - (uintptr_t)start, BCACHE);
|
//cacheflush(start, (uintptr_t)end - (uintptr_t)start, BCACHE);
|
||||||
|
} else if (os == .linux and riscv) {
|
||||||
|
const result = std.os.linux.syscall3(std.os.linux.SYS_riscv_flush_icache, start, end - start, 0);
|
||||||
|
std.debug.assert(result == 0);
|
||||||
} else if (arm64 and !apple) {
|
} else if (arm64 and !apple) {
|
||||||
// Get Cache Type Info.
|
// Get Cache Type Info.
|
||||||
// TODO memoize this?
|
// TODO memoize this?
|
||||||
|
|
@ -142,3 +149,10 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
|
||||||
|
|
||||||
// Darwin-only
|
// Darwin-only
|
||||||
extern fn sys_icache_invalidate(start: usize, len: usize) void;
|
extern fn sys_icache_invalidate(start: usize, len: usize) void;
|
||||||
|
// BSD-only
|
||||||
|
const arm_sync_icache_args = extern struct {
|
||||||
|
addr: usize, // Virtual start address
|
||||||
|
len: usize, // Region size
|
||||||
|
};
|
||||||
|
const ARM_SYNC_ICACHE = 0;
|
||||||
|
extern "c" fn sysarch(number: i32, args: usize) i32;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue