Skip to content

Commit 12c5af1

Browse files
committed
compiler-rt: implement clear_cache for arm32-linux
1 parent cfedd3a commit 12c5af1

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

lib/std/special/compiler_rt.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ comptime {
1111

1212
switch (builtin.arch) {
1313
.i386, .x86_64 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = linkage }),
14-
.aarch64, .aarch64_be, .aarch64_32 => {
14+
.aarch64, .aarch64_be, .aarch64_32, .arm, .armeb, .thumb, .thumbeb => {
1515
@export(@import("compiler_rt/clear_cache.zig").clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
1616
},
1717
else => {},

lib/std/special/compiler_rt/clear_cache.zig

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,25 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
4545
@compileError("TODO");
4646
// FlushInstructionCache(GetCurrentProcess(), start, end - start);
4747
} else if (arm32 and !apple) {
48-
@compileError("TODO");
49-
//#if defined(__FreeBSD__) || defined(__NetBSD__)
50-
// struct arm_sync_icache_args arg;
51-
//
52-
// arg.addr = (uintptr_t)start;
53-
// arg.len = (uintptr_t)end - (uintptr_t)start;
54-
//
55-
// sysarch(ARM_SYNC_ICACHE, &arg);
56-
//#elif defined(__linux__)
57-
//// We used to include asm/unistd.h for the __ARM_NR_cacheflush define, but
58-
//// it also brought many other unused defines, as well as a dependency on
59-
//// kernel headers to be installed.
60-
////
61-
//// This value is stable at least since Linux 3.13 and should remain so for
62-
//// compatibility reasons, warranting it's re-definition here.
63-
//#define __ARM_NR_cacheflush 0x0f0002
64-
// register int start_reg __asm("r0") = (int)(intptr_t)start;
65-
// const register int end_reg __asm("r1") = (int)(intptr_t)end;
66-
// const register int flags __asm("r2") = 0;
67-
// const register int syscall_nr __asm("r7") = __ARM_NR_cacheflush;
68-
// __asm __volatile("svc 0x0"
69-
// : "=r"(start_reg)
70-
// : "r"(syscall_nr), "r"(start_reg), "r"(end_reg), "r"(flags));
71-
// assert(start_reg == 0 && "Cache flush syscall failed.");
72-
//#else
73-
// compilerrt_abort();
74-
//#endif
48+
if (os == .freebsd or os == .netbsd) {
49+
// struct arm_sync_icache_args arg;
50+
//
51+
// arg.addr = (uintptr_t)start;
52+
// arg.len = (uintptr_t)end - (uintptr_t)start;
53+
//
54+
// sysarch(ARM_SYNC_ICACHE, &arg);
55+
@compileError("TODO: implement for NetBSD/FreeBSD");
56+
} else if (os == .linux) {
57+
const result = std.os.linux.syscall3(
58+
std.os.linux.SYS_cacheflush,
59+
start,
60+
end,
61+
0,
62+
);
63+
std.debug.assert(result == 0);
64+
} else {
65+
unreachable;
66+
}
7567
} else if (os == .linux and mips) {
7668
@compileError("TODO");
7769
//const uintptr_t start_int = (uintptr_t)start;

0 commit comments

Comments
 (0)