xref: /haiku/src/system/kernel/arch/x86/asm_offsets.cpp (revision e688bf23d48bfd1216a0cacbdbda5e35a1bcd779)
1 /*
2  * Copyright 2007-2011, 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 assembly 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 assembly
9 // code.
10 
11 
12 #include <computed_asm_macros.h>
13 
14 #include <arch_cpu.h>
15 #include <cpu.h>
16 #include <ksignal.h>
17 #include <ksyscalls.h>
18 #include <thread_types.h>
19 
20 
21 #define DEFINE_MACRO(macro, value) DEFINE_COMPUTED_ASM_MACRO(macro, value)
22 
23 #define DEFINE_OFFSET_MACRO(prefix, structure, member) \
24     DEFINE_MACRO(prefix##_##member, offsetof(struct structure, member));
25 
26 #define DEFINE_SIZEOF_MACRO(prefix, structure) \
27     DEFINE_MACRO(prefix##_sizeof, sizeof(struct structure));
28 
29 
30 void
31 dummy()
32 {
33 	// struct cpu_ent
34 	DEFINE_OFFSET_MACRO(CPU_ENT, cpu_ent, fault_handler);
35 	DEFINE_OFFSET_MACRO(CPU_ENT, cpu_ent, fault_handler_stack_pointer);
36 
37 	// struct Thread
38 	DEFINE_OFFSET_MACRO(THREAD, Thread, time_lock);
39 	DEFINE_OFFSET_MACRO(THREAD, Thread, kernel_time);
40 	DEFINE_OFFSET_MACRO(THREAD, Thread, user_time);
41 	DEFINE_OFFSET_MACRO(THREAD, Thread, last_time);
42 	DEFINE_OFFSET_MACRO(THREAD, Thread, in_kernel);
43 	DEFINE_OFFSET_MACRO(THREAD, Thread, flags);
44 	DEFINE_OFFSET_MACRO(THREAD, Thread, kernel_stack_top);
45 	DEFINE_OFFSET_MACRO(THREAD, Thread, fault_handler);
46 
47 #ifdef __x86_64__
48 	// struct arch_thread
49 	DEFINE_OFFSET_MACRO(ARCH_THREAD, arch_thread, syscall_rsp);
50 	DEFINE_OFFSET_MACRO(ARCH_THREAD, arch_thread, user_rsp);
51 	DEFINE_OFFSET_MACRO(ARCH_THREAD, arch_thread, current_stack);
52 #endif
53 
54 	// struct iframe
55 	DEFINE_SIZEOF_MACRO(IFRAME, iframe);
56 	DEFINE_OFFSET_MACRO(IFRAME, iframe, cs);
57 	DEFINE_OFFSET_MACRO(IFRAME, iframe, ax);
58 	DEFINE_OFFSET_MACRO(IFRAME, iframe, dx);
59 	DEFINE_OFFSET_MACRO(IFRAME, iframe, di);
60 	DEFINE_OFFSET_MACRO(IFRAME, iframe, si);
61 	DEFINE_OFFSET_MACRO(IFRAME, iframe, vector);
62 	DEFINE_OFFSET_MACRO(IFRAME, iframe, ip);
63 	DEFINE_OFFSET_MACRO(IFRAME, iframe, flags);
64 	DEFINE_OFFSET_MACRO(IFRAME, iframe, user_sp);
65 #ifdef __x86_64__
66 	DEFINE_OFFSET_MACRO(IFRAME, iframe, r8);
67 	DEFINE_OFFSET_MACRO(IFRAME, iframe, r9);
68 	DEFINE_OFFSET_MACRO(IFRAME, iframe, r10);
69 #else
70 	DEFINE_OFFSET_MACRO(IFRAME, iframe, orig_eax);
71 #endif
72 
73 	// struct syscall_info
74 	DEFINE_SIZEOF_MACRO(SYSCALL_INFO, syscall_info);
75 	DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, function);
76 	DEFINE_OFFSET_MACRO(SYSCALL_INFO, syscall_info, parameter_size);
77 
78 	// struct x86_optimized_functions
79 	DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
80 		memcpy);
81 	DEFINE_OFFSET_MACRO(X86_OPTIMIZED_FUNCTIONS, x86_optimized_functions,
82 		memset);
83 
84 	// struct signal_frame_data
85 	DEFINE_SIZEOF_MACRO(SIGNAL_FRAME_DATA, signal_frame_data);
86 	DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, info);
87 	DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, context);
88 	DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, user_data);
89 	DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, handler);
90 	DEFINE_OFFSET_MACRO(SIGNAL_FRAME_DATA, signal_frame_data, siginfo_handler);
91 
92 	// struct ucontext_t
93 	DEFINE_OFFSET_MACRO(UCONTEXT_T, __ucontext_t, uc_mcontext);
94 
95 	// struct vregs
96 	DEFINE_SIZEOF_MACRO(VREGS, vregs);
97 
98 	// struct siginfo_t
99 	DEFINE_OFFSET_MACRO(SIGINFO_T, __siginfo_t, si_signo);
100 }
101