xref: /openbmc/linux/arch/x86/um/user-offsets.c (revision c819e2cf)
1 #include <stdio.h>
2 #include <stddef.h>
3 #include <signal.h>
4 #include <sys/poll.h>
5 #include <sys/mman.h>
6 #include <sys/user.h>
7 #define __FRAME_OFFSETS
8 #include <asm/ptrace.h>
9 #include <asm/types.h>
10 
11 #ifdef __i386__
12 #define __SYSCALL_I386(nr, sym, compat) [nr] = 1,
13 static char syscalls[] = {
14 #include <asm/syscalls_32.h>
15 };
16 #else
17 #define __SYSCALL_64(nr, sym, compat) [nr] = 1,
18 #define __SYSCALL_COMMON(nr, sym, compat) [nr] = 1,
19 #define __SYSCALL_X32(nr, sym, compat) /* Not supported */
20 static char syscalls[] = {
21 #include <asm/syscalls_64.h>
22 };
23 #endif
24 
25 #define DEFINE(sym, val) \
26 	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
27 
28 #define DEFINE_LONGS(sym, val) \
29 	asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long)))
30 
31 void foo(void)
32 {
33 #ifdef __i386__
34 	DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct));
35 	DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct));
36 
37 	DEFINE(HOST_IP, EIP);
38 	DEFINE(HOST_SP, UESP);
39 	DEFINE(HOST_EFLAGS, EFL);
40 	DEFINE(HOST_AX, EAX);
41 	DEFINE(HOST_BX, EBX);
42 	DEFINE(HOST_CX, ECX);
43 	DEFINE(HOST_DX, EDX);
44 	DEFINE(HOST_SI, ESI);
45 	DEFINE(HOST_DI, EDI);
46 	DEFINE(HOST_BP, EBP);
47 	DEFINE(HOST_CS, CS);
48 	DEFINE(HOST_SS, SS);
49 	DEFINE(HOST_DS, DS);
50 	DEFINE(HOST_FS, FS);
51 	DEFINE(HOST_ES, ES);
52 	DEFINE(HOST_GS, GS);
53 	DEFINE(HOST_ORIG_AX, ORIG_EAX);
54 #else
55 	DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
56 	DEFINE_LONGS(HOST_BX, RBX);
57 	DEFINE_LONGS(HOST_CX, RCX);
58 	DEFINE_LONGS(HOST_DI, RDI);
59 	DEFINE_LONGS(HOST_SI, RSI);
60 	DEFINE_LONGS(HOST_DX, RDX);
61 	DEFINE_LONGS(HOST_BP, RBP);
62 	DEFINE_LONGS(HOST_AX, RAX);
63 	DEFINE_LONGS(HOST_R8, R8);
64 	DEFINE_LONGS(HOST_R9, R9);
65 	DEFINE_LONGS(HOST_R10, R10);
66 	DEFINE_LONGS(HOST_R11, R11);
67 	DEFINE_LONGS(HOST_R12, R12);
68 	DEFINE_LONGS(HOST_R13, R13);
69 	DEFINE_LONGS(HOST_R14, R14);
70 	DEFINE_LONGS(HOST_R15, R15);
71 	DEFINE_LONGS(HOST_ORIG_AX, ORIG_RAX);
72 	DEFINE_LONGS(HOST_CS, CS);
73 	DEFINE_LONGS(HOST_SS, SS);
74 	DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
75 #if 0
76 	DEFINE_LONGS(HOST_FS, FS);
77 	DEFINE_LONGS(HOST_GS, GS);
78 	DEFINE_LONGS(HOST_DS, DS);
79 	DEFINE_LONGS(HOST_ES, ES);
80 #endif
81 
82 	DEFINE_LONGS(HOST_IP, RIP);
83 	DEFINE_LONGS(HOST_SP, RSP);
84 #endif
85 
86 	DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
87 	DEFINE(UM_POLLIN, POLLIN);
88 	DEFINE(UM_POLLPRI, POLLPRI);
89 	DEFINE(UM_POLLOUT, POLLOUT);
90 
91 	DEFINE(UM_PROT_READ, PROT_READ);
92 	DEFINE(UM_PROT_WRITE, PROT_WRITE);
93 	DEFINE(UM_PROT_EXEC, PROT_EXEC);
94 
95 	DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
96 	DEFINE(NR_syscalls, sizeof(syscalls));
97 }
98