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