authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-03-31 00:19:19+02:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-03-31 00:29:41+02:00
logf6f03cd90f5c0a8cce7981b16f384b088f41c319
treeeb23e2a5ff1125cd8dbadb5f17f7fe9b760fa7ff
parentcfedd3aca286881510e4a298756d4a5676e22137

compiler-rt: implement clear_cache for arm32-linux


2 files changed, 20 insertions(+), 28 deletions(-)

lib/std/special/compiler_rt.zig+1-1
......@@ -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+19-27
......@@ -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 @compileError("compilerrt_abort");
66 }
7567 } else if (os == .linux and mips) {
7668 @compileError("TODO");
7769 //const uintptr_t start_int = (uintptr_t)start;