1 /* 2 * Copyright 2022, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2009, Johannes Wischert, johanneswi@gmail.com. 6 * Distributed under the terms of the MIT License. 7 */ 8 9 10 #include <commpage.h> 11 12 #include <string.h> 13 14 #include <KernelExport.h> 15 16 #include <cpu.h> 17 #include <elf.h> 18 #include <smp.h> 19 20 21 extern "C" void arch_user_thread_exit(); 22 23 24 static void 25 register_commpage_function(const char* functionName, int32 commpageIndex, 26 const char* commpageSymbolName, addr_t expectedAddress) 27 { 28 // get address and size of function 29 elf_symbol_info symbolInfo; 30 if (elf_lookup_kernel_symbol(functionName, &symbolInfo) != B_OK) { 31 panic("register_commpage_function(): Failed to find " 32 "function \"%s\"!", functionName); 33 } 34 35 ASSERT(expectedAddress == symbolInfo.address); 36 37 // fill in the commpage table entry 38 addr_t position = fill_commpage_entry(commpageIndex, 39 (void*)symbolInfo.address, symbolInfo.size); 40 41 // add symbol to the commpage image 42 image_id image = get_commpage_image(); 43 elf_add_memory_image_symbol(image, commpageSymbolName, position, 44 symbolInfo.size, B_SYMBOL_TYPE_TEXT); 45 } 46 47 48 status_t 49 arch_commpage_init(void) 50 { 51 return B_OK; 52 } 53 54 55 status_t 56 arch_commpage_init_post_cpus(void) 57 { 58 register_commpage_function("arch_user_thread_exit", 59 COMMPAGE_ENTRY_ARM_THREAD_EXIT, "commpage_thread_exit", 60 (addr_t)&arch_user_thread_exit); 61 62 return B_OK; 63 } 64 65