this repo has no description
1
fork

Configure Feed

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

[mldr] Implement WIP ARM64 Support

+48 -5
+11 -1
src/startup/mldr/commpage.c
··· 21 21 22 22 static uint64_t get_cpu_caps(void); 23 23 24 + int PAGE_SIZE; 25 + 24 26 #define CGET(p) (commpage + ((p)-_COMM_PAGE_START_ADDRESS)) 25 27 26 28 void commpage_setup(bool _64bit) ··· 35 37 uint8_t *physcpus, *logcpus; 36 38 uint8_t *user_page_shift, *kernel_page_shift; 37 39 struct sysinfo si; 40 + 41 + PAGE_SIZE = sysconf(_SC_PAGESIZE); 38 42 39 43 commpage = (uint8_t*) mmap((void*)(_64bit ? _COMM_PAGE64_BASE_ADDRESS : _COMM_PAGE32_BASE_ADDRESS), 40 44 _64bit ? _COMM_PAGE64_AREA_LENGTH : _COMM_PAGE32_AREA_LENGTH, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); ··· 69 73 // as a substitute for log2(). 70 74 user_page_shift = (uint8_t*)CGET(_64bit ? _COMM_PAGE_USER_PAGE_SHIFT_64 : _COMM_PAGE_USER_PAGE_SHIFT_32); 71 75 kernel_page_shift = (uint8_t*)CGET(_COMM_PAGE_KERNEL_PAGE_SHIFT); 72 - *kernel_page_shift = *user_page_shift = (uint8_t)__builtin_ctzl(sysconf(_SC_PAGESIZE)); 76 + *kernel_page_shift = *user_page_shift = (uint8_t)__builtin_ctzl(PAGE_SIZE); 73 77 74 78 my_caps = get_cpu_caps(); 75 79 if (*ncpus == 1) ··· 166 170 return _64bit ? _COMM_PAGE64_BASE_ADDRESS : _COMM_PAGE32_BASE_ADDRESS; 167 171 } 168 172 173 + #ifdef __aarch64__ 174 + vm_address_t _get_commpage_priv_address(void) { 175 + // Not sure if this is correct... 176 + return _COMM_PAGE64_BASE_ADDRESS; 177 + } 178 + #endif
+23
src/startup/mldr/elfcalls/threads.c
··· 268 268 register uintptr_t arg6 asm("r9") = args.arg3; 269 269 #elif __i386__ 270 270 uintptr_t arg3 = args.real_entry_point; 271 + #elif __aarch64__ 272 + register void* arg1 asm("x0") = args.pth; 273 + register int arg2 asm("w1") = args.port; 274 + register uintptr_t arg3 asm("x2") = args.real_entry_point; 275 + register uintptr_t arg4 asm("x3") = args.arg1; 276 + register uintptr_t arg5 asm("x4") = args.arg2; 277 + register uintptr_t arg6 asm("x5") = args.arg3; 271 278 #endif 272 279 273 280 if (arg3 == 0) { ··· 314 321 // Function arguments to push to the stack. 315 322 [args] "r"(&args), [arg3]"r"(arg3), 316 323 324 + [entry_point] "r"(args.entry_point), 325 + [stack_ptr] "r"(stack_ptr) 326 + ); 327 + #elif defined(__aarch64__) 328 + asm volatile( 329 + // Zero out the frame base register. 330 + "mov fp, #0\n" 331 + // Switch to the new stack. 332 + "mov %[stack_ptr], sp\n" 333 + // Push a fake return address. 334 + "mov lr, #0\n" 335 + // Jump to the entry point. 336 + "br %[entry_point]" :: 337 + // Function arguments 338 + "r"(arg1),"r"(arg2),"r"(arg3),"r"(arg4),"r"(arg5),"r"(arg6), 339 + 317 340 [entry_point] "r"(args.entry_point), 318 341 [stack_ptr] "r"(stack_ptr) 319 342 );
+14 -4
src/startup/mldr/mldr.c
··· 383 383 if (arch.cputype == CPU_TYPE_X86) 384 384 best_arch = arch; 385 385 #elif defined (__aarch64__) 386 - #error TODO: arm 386 + if (arch.cputype == CPU_TYPE_ARM64) 387 + best_arch = arch; 387 388 #else 388 389 #error Unsupported CPU architecture 389 390 #endif ··· 420 421 } 421 422 }; 422 423 423 - #ifdef __x86_64__ 424 + #if defined(__x86_64__ ) || defined(__aarch64__) 424 425 #define GEN_64BIT 425 426 #include "loader.c" 426 427 #include "stack.c" ··· 816 817 // Using the default stack top would cause the stack to be placed just above the commpage 817 818 // and would collide with it eventually. 818 819 // Instead, we manually allocate a new stack below the commpage. 819 - #if __x86_64__ 820 + #if defined(__x86_64__) || defined(__aarch64__) 820 821 lr->stack_top = commpage_address(true); 821 - #elif __i386__ 822 + #elif defined(__i386__) 822 823 lr->stack_top = commpage_address(false); 823 824 #else 824 825 #error Unsupported architecture ··· 931 932 __asm__ volatile( 932 933 "mov sp, %1\n" 933 934 "bx %0" 935 + :: 936 + "r"(lr->entry_point), 937 + "r"(lr->stack_top) 938 + : 939 + ); 940 + #elif defined(__aarch64__) 941 + __asm__ volatile( 942 + "mov sp, %1\n" 943 + "br %0" 934 944 :: 935 945 "r"(lr->entry_point), 936 946 "r"(lr->stack_top)