frame_regs.h revision 1.4.2.2 1 1.4.2.2 mjf /* $NetBSD: frame_regs.h,v 1.4.2.2 2008/02/18 21:04:21 mjf Exp $ */
2 1.4.2.2 mjf
3 1.4.2.2 mjf #ifndef _AMD64_FRAME_REGS_H_
4 1.4.2.2 mjf #define _AMD64_FRAME_REGS_H_
5 1.4.2.2 mjf
6 1.4.2.2 mjf /*
7 1.4.2.2 mjf * amd64 registers (and friends) ordered as in a trap/interrupt/syscall frame.
8 1.4.2.2 mjf * Also the indexes into the 'general register state' (__greg_t) passed to
9 1.4.2.2 mjf * userland.
10 1.4.2.2 mjf * Historically they were in the same order, but the order in the frames
11 1.4.2.2 mjf * has been changed to improve syscall efficiency.
12 1.4.2.2 mjf *
13 1.4.2.2 mjf * Notes:
14 1.4.2.2 mjf * 1) gdb (src/gnu/dist/gdb6/gdb/amd64nbsd-tdep.c) has a lookup table that
15 1.4.2.2 mjf * assumes the __greg_t ordering.
16 1.4.2.2 mjf * 2) src/lib/libc/arch/x86_64/gen/makecontext.c assumes that the first
17 1.4.2.2 mjf * 6 entries in the __greg_t array match the registers used to pass
18 1.4.2.2 mjf * function arguments.
19 1.4.2.2 mjf * 3) The 'struct reg' from machine/reg.h has to match __greg_t.
20 1.4.2.2 mjf * Since they are both arrays and indexed with the same tokens this
21 1.4.2.2 mjf * shouldn't be a problem, but is rather confusing.
22 1.4.2.2 mjf * This assumption is made in a lot of places!
23 1.4.2.2 mjf * 4) There might be other code out there that relies on the ordering.
24 1.4.2.2 mjf *
25 1.4.2.2 mjf * The first entries below match the registers used for syscall arguments
26 1.4.2.2 mjf * (%rcx is destroyed by the syscall instruction, the libc system call
27 1.4.2.2 mjf * stubs copy %rcx to %r10).
28 1.4.2.2 mjf * arg6-arg9 are copied from the user stack for system calls with more
29 1.4.2.2 mjf * than 6 args (SYS_MAXSYSARGS is 8, + 2 entries for SYS___SYSCALL).
30 1.4.2.2 mjf */
31 1.4.2.2 mjf #define _FRAME_REG(greg, freg) \
32 1.4.2.2 mjf greg(rdi, RDI, 0) \
33 1.4.2.2 mjf greg(rsi, RSI, 1) \
34 1.4.2.2 mjf greg(rdx, RDX, 2) \
35 1.4.2.2 mjf greg(r10, R10, 6) \
36 1.4.2.2 mjf greg(r8, R8, 4) \
37 1.4.2.2 mjf greg(r9, R9, 5) \
38 1.4.2.2 mjf freg(arg6, @, @) /* syscall arg from stack */ \
39 1.4.2.2 mjf freg(arg7, @, @) /* syscall arg from stack */ \
40 1.4.2.2 mjf freg(arg8, @, @) /* syscall arg from stack */ \
41 1.4.2.2 mjf freg(arg9, @, @) /* syscall arg from stack */ \
42 1.4.2.2 mjf greg(rcx, RCX, 3) \
43 1.4.2.2 mjf greg(r11, R11, 7) \
44 1.4.2.2 mjf greg(r12, R12, 8) \
45 1.4.2.2 mjf greg(r13, R13, 9) \
46 1.4.2.2 mjf greg(r14, R14, 10) \
47 1.4.2.2 mjf greg(r15, R15, 11) \
48 1.4.2.2 mjf greg(rbp, RBP, 12) \
49 1.4.2.2 mjf greg(rbx, RBX, 13) \
50 1.4.2.2 mjf greg(rax, RAX, 14) \
51 1.4.2.2 mjf greg(gs, GS, 15) \
52 1.4.2.2 mjf greg(fs, FS, 16) \
53 1.4.2.2 mjf greg(es, ES, 17) \
54 1.4.2.2 mjf greg(ds, DS, 18) \
55 1.4.2.2 mjf greg(trapno, TRAPNO, 19) \
56 1.4.2.2 mjf /* below portion defined in hardware */ \
57 1.4.2.2 mjf greg(err, ERR, 20) /* Dummy inserted if not defined */ \
58 1.4.2.2 mjf greg(rip, RIP, 21) \
59 1.4.2.2 mjf greg(cs, CS, 22) \
60 1.4.2.2 mjf greg(rflags, RFLAGS, 23) \
61 1.4.2.2 mjf /* These are pushed unconditionally on the x86-64 */ \
62 1.4.2.2 mjf greg(rsp, RSP, 24) \
63 1.4.2.2 mjf greg(ss, SS, 25)
64 1.4.2.2 mjf
65 1.4.2.2 mjf #define _FRAME_NOREG(reg, REG, idx)
66 1.4.2.2 mjf
67 1.4.2.2 mjf #define _FRAME_GREG(greg) _FRAME_REG(greg, _FRAME_NOREG)
68 1.4.2.2 mjf
69 1.4.2.2 mjf #endif
70