1 /* 2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 // This file is used to get C structure offsets into assembler code. 7 // The build system assembles the file and processes the output to create 8 // a header file with macro definitions, that can be included from assembler 9 // code. 10 11 #include <arch_cpu.h> 12 #include <ksyscalls.h> 13 #include <thread_types.h> 14 15 16 #define DEFINE_MACRO(macro, value) \ 17 asm volatile("#define " #macro " %0" : : "i" (value)) 18 19 #define DEFINE_OFFSET_MACRO(prefix, structure, member) \ 20 DEFINE_MACRO(prefix##_##member, offsetof(struct structure, member)); 21 22 #define DEFINE_SIZEOF_MACRO(prefix, structure) \ 23 DEFINE_MACRO(prefix##_sizeof, sizeof(struct structure)); 24 25 26 void 27 dummy() 28 { 29 // struct thread 30 DEFINE_OFFSET_MACRO(THREAD, thread, kernel_time); 31 DEFINE_OFFSET_MACRO(THREAD, thread, user_time); 32 DEFINE_OFFSET_MACRO(THREAD, thread, last_time); 33 DEFINE_OFFSET_MACRO(THREAD, thread, in_kernel); 34 DEFINE_OFFSET_MACRO(THREAD, thread, flags); 35 DEFINE_OFFSET_MACRO(THREAD, thread, kernel_stack_top); 36 DEFINE_OFFSET_MACRO(THREAD, thread, fault_handler); 37 38 // struct iframe 39 DEFINE_OFFSET_MACRO(IFRAME, iframe, cs); 40 DEFINE_OFFSET_MACRO(IFRAME, iframe, eax); 41 DEFINE_OFFSET_MACRO(IFRAME, iframe, edx); 42 DEFINE_OFFSET_MACRO(IFRAME, iframe, orig_eax); 43 DEFINE_OFFSET_MACRO(IFRAME, iframe, vector); 44 DEFINE_OFFSET_MACRO(IFRAME, iframe, eip); 45 DEFINE_OFFSET_MACRO(IFRAME, iframe, flags); 46 DEFINE_OFFSET_MACRO(IFRAME, iframe, user_esp); 47 48 // struct syscall_info 49 DEFINE_SIZEOF_MACRO(SYSCALL_INFO, syscall_info); 50 DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, function); 51 DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, parameter_size); 52 53 // struct x86_optimized_functions 54 DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions, 55 memcpy); 56 } 57