this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[kernel] Initial implementation of MacOS and Linux syscall for ARM64

Thomas A 3f5bc3e3 3c89ad0f

+61
+5
src/kernel/emulation/linux/linux-syscall.S
··· 69 69 pop %ebp 70 70 ret 71 71 72 + #elif __arm64__ 73 + mov w8,w6 74 + svc #0 75 + ret 76 + 72 77 #else 73 78 74 79 # error Missing assembly!
+4
src/kernel/emulation/linux/mach/darling_mach_syscall.S
··· 106 106 107 107 .subsections_via_symbols 108 108 109 + #elif defined(__arm64__) 110 + // To keep things simple, __darling_bsd_syscall will handle the 111 + // Mach Syscall. See syscalls-table.S for more details. 112 + 109 113 #else 110 114 # error Missing assembly 111 115 #endif
+52
src/kernel/emulation/linux/syscalls-table.S
··· 96 96 97 97 .subsections_via_symbols 98 98 99 + 100 + #elif defined(__arm64__) 101 + // For i386/x64, the `syscall_sw.h` file has the BSD and Mach syscall defined 102 + // between two different macros (`UNIX_SYSCALL_TRAP` and `kernel_trap`). This 103 + // is not the case for ARM. 104 + 105 + // For ARM64, there is only one syscall that is used for either BSD and Mach. 106 + // If the syscall number is less then zero, it will do a Mach syscall; otherwise, 107 + // it will do a BSD syscall. 108 + 109 + // Because of the above, I decided to have the both the BSD and Mach syscall be 110 + // handled by the __darling_bsd_syscall. 111 + 112 + // Notes: 113 + // https://stackoverflow.com/a/56993314/5988706 114 + // xnu/osfmk/arm64/sleh.c - handle_svc function 115 + 116 + __darling_bsd_syscall: 117 + ; Push temporary registers (syscalls don't modify temp register) 118 + sub sp,sp,#16 119 + stp x9,x10,[sp] 120 + 121 + ; if (x16 / *syscall number */ < 0) 122 + cmp x16,#0 123 + blt .get_mach_table 124 + 125 + ; Get &___bsd_syscall_table (function pointer) 126 + adrp x9, ___bsd_syscall_table@PAGE 127 + add x9, x9, ___bsd_syscall_table@PAGEOFF 128 + mov x10,x16 129 + b .calc_offset 130 + 131 + .get_mach_table: 132 + ; Get &___mach_syscall_table (function pointer) 133 + adrp x9, ___mach_syscall_table@PAGE 134 + add x9, x9, ___mach_syscall_table@PAGEOFF 135 + neg x10,x16 136 + 137 + .calc_offset: 138 + ; &syscall_table + x10 * sizeof(void*) 139 + lsl x10,x10,3 140 + add x9,x9,x10 141 + 142 + ; Call ___bsd_syscall_table method 143 + blr x9 144 + 145 + ; Restore original temp register values 146 + ldp x9,x10,[sp] 147 + add sp,sp,#16 148 + ret 149 + 150 + #warning "Heed to improve __darling_bsd_syscall ARM64 implementation" 99 151 #else 100 152 # error Missing assembly 101 153 #endif