gcc44: remove my copyright from dragonfly-unwind.h
[dragonfly.git] / contrib / gcc-4.4 / gcc / config / i386 / dragonfly-unwind.h
CommitLineData
00195b67 1/* DWARF2 EH unwinding support for DragonFly BSD: AMD x86-64 and x86. */
eae7a19e
JM
2
3/* Do code reading to identify a signal frame, and set the frame
4 state data appropriately. See unwind-dw2.c for the structs. */
5
6#include <sys/types.h>
7#include <sys/sysctl.h>
8#include <signal.h>
9#include <sys/ucontext.h>
10#include <machine/sigframe.h>
11
12
13#define REG_NAME(reg) sf_uc.uc_mcontext.mc_## reg
14
15#ifdef __x86_64__
16#define MD_FALLBACK_FRAME_STATE_FOR x86_64_dragonfly_fallback_frame_state
17
18
19static void
20x86_64_sigtramp_range (unsigned char **start, unsigned char **end)
21{
22 unsigned long ps_strings;
23 int mib[2];
24 size_t len;
25
26 mib[0] = CTL_KERN;
27 mib[1] = KERN_PS_STRINGS;
28 len = sizeof (ps_strings);
29 sysctl (mib, 2, &ps_strings, &len, NULL, 0);
30
31 *start = (unsigned char *)ps_strings - 32;
32 *end = (unsigned char *)ps_strings;
33}
34
35
36static _Unwind_Reason_Code
37x86_64_dragonfly_fallback_frame_state
38(struct _Unwind_Context *context, _Unwind_FrameState *fs)
39{
40 unsigned char *pc = context->ra;
41 unsigned char *sigtramp_start, *sigtramp_end;
42 struct sigframe *sf;
43 long new_cfa;
44
45 x86_64_sigtramp_range(&sigtramp_start, &sigtramp_end);
46 if (pc >= sigtramp_end || pc < sigtramp_start)
47 return _URC_END_OF_STACK;
48
49 sf = (struct sigframe *) context->cfa;
50 new_cfa = sf->REG_NAME(rsp);
51 fs->regs.cfa_how = CFA_REG_OFFSET;
52 /* Register 7 is rsp */
53 fs->regs.cfa_reg = 7;
54 fs->regs.cfa_offset = new_cfa - (long) context->cfa;
55
56 /* The SVR4 register numbering macros aren't usable in libgcc. */
57 fs->regs.reg[0].how = REG_SAVED_OFFSET;
58 fs->regs.reg[0].loc.offset = (long)&sf->REG_NAME(rax) - new_cfa;
59 fs->regs.reg[1].how = REG_SAVED_OFFSET;
60 fs->regs.reg[1].loc.offset = (long)&sf->REG_NAME(rdx) - new_cfa;
61 fs->regs.reg[2].how = REG_SAVED_OFFSET;
62 fs->regs.reg[2].loc.offset = (long)&sf->REG_NAME(rcx) - new_cfa;
63 fs->regs.reg[3].how = REG_SAVED_OFFSET;
64 fs->regs.reg[3].loc.offset = (long)&sf->REG_NAME(rbx) - new_cfa;
65 fs->regs.reg[4].how = REG_SAVED_OFFSET;
66 fs->regs.reg[4].loc.offset = (long)&sf->REG_NAME(rsi) - new_cfa;
67 fs->regs.reg[5].how = REG_SAVED_OFFSET;
68 fs->regs.reg[5].loc.offset = (long)&sf->REG_NAME(rdi) - new_cfa;
69 fs->regs.reg[6].how = REG_SAVED_OFFSET;
70 fs->regs.reg[6].loc.offset = (long)&sf->REG_NAME(rbp) - new_cfa;
71 fs->regs.reg[8].how = REG_SAVED_OFFSET;
72 fs->regs.reg[8].loc.offset = (long)&sf->REG_NAME(r8) - new_cfa;
73 fs->regs.reg[9].how = REG_SAVED_OFFSET;
74 fs->regs.reg[9].loc.offset = (long)&sf->REG_NAME(r9) - new_cfa;
75 fs->regs.reg[10].how = REG_SAVED_OFFSET;
76 fs->regs.reg[10].loc.offset = (long)&sf->REG_NAME(r10) - new_cfa;
77 fs->regs.reg[11].how = REG_SAVED_OFFSET;
78 fs->regs.reg[11].loc.offset = (long)&sf->REG_NAME(r11) - new_cfa;
79 fs->regs.reg[12].how = REG_SAVED_OFFSET;
80 fs->regs.reg[12].loc.offset = (long)&sf->REG_NAME(r12) - new_cfa;
81 fs->regs.reg[13].how = REG_SAVED_OFFSET;
82 fs->regs.reg[13].loc.offset = (long)&sf->REG_NAME(r13) - new_cfa;
83 fs->regs.reg[14].how = REG_SAVED_OFFSET;
84 fs->regs.reg[14].loc.offset = (long)&sf->REG_NAME(r14) - new_cfa;
85 fs->regs.reg[15].how = REG_SAVED_OFFSET;
86 fs->regs.reg[15].loc.offset = (long)&sf->REG_NAME(r15) - new_cfa;
87 fs->regs.reg[16].how = REG_SAVED_OFFSET;
88 fs->regs.reg[16].loc.offset = (long)&sf->REG_NAME(rip) - new_cfa;
89 fs->retaddr_column = 16;
90 fs->signal_frame = 1;
91 return _URC_NO_REASON;
92}
93
94#else /* Next section is for i386 */
95
96#define MD_FALLBACK_FRAME_STATE_FOR x86_dragonfly_fallback_frame_state
97
98
99static void
100x86_sigtramp_range (unsigned char **start, unsigned char **end)
101{
102 unsigned long ps_strings;
103 int mib[2];
104 size_t len;
105
106 mib[0] = CTL_KERN;
107 mib[1] = KERN_PS_STRINGS;
108 len = sizeof (ps_strings);
109 sysctl (mib, 2, &ps_strings, &len, NULL, 0);
110
111 *start = (unsigned char *)ps_strings - 128;
112 *end = (unsigned char *)ps_strings;
113}
114
115
116static _Unwind_Reason_Code
117x86_dragonfly_fallback_frame_state
118(struct _Unwind_Context *context, _Unwind_FrameState *fs)
119{
120 unsigned char *pc = context->ra;
121 unsigned char *sigtramp_start, *sigtramp_end;
122 struct sigframe *sf;
123 long new_cfa;
124
125 x86_sigtramp_range(&sigtramp_start, &sigtramp_end);
126
127 if (pc >= sigtramp_end || pc < sigtramp_start)
128 return _URC_END_OF_STACK;
129
130 sf = (struct sigframe *) context->cfa;
131 new_cfa = sf->REG_NAME(esp);
132 fs->regs.cfa_how = CFA_REG_OFFSET;
133 fs->regs.cfa_reg = 4;
134 fs->regs.cfa_offset = new_cfa - (long) context->cfa;
135
136 /* The SVR4 register numbering macros aren't usable in libgcc. */
137 fs->regs.reg[0].how = REG_SAVED_OFFSET;
138 fs->regs.reg[0].loc.offset = (long)&sf->REG_NAME(eax) - new_cfa;
139 fs->regs.reg[3].how = REG_SAVED_OFFSET;
140 fs->regs.reg[3].loc.offset = (long)&sf->REG_NAME(ebx) - new_cfa;
141 fs->regs.reg[1].how = REG_SAVED_OFFSET;
142 fs->regs.reg[1].loc.offset = (long)&sf->REG_NAME(ecx) - new_cfa;
143 fs->regs.reg[2].how = REG_SAVED_OFFSET;
144 fs->regs.reg[2].loc.offset = (long)&sf->REG_NAME(edx) - new_cfa;
145 fs->regs.reg[6].how = REG_SAVED_OFFSET;
146 fs->regs.reg[6].loc.offset = (long)&sf->REG_NAME(esi) - new_cfa;
147 fs->regs.reg[7].how = REG_SAVED_OFFSET;
148 fs->regs.reg[7].loc.offset = (long)&sf->REG_NAME(edi) - new_cfa;
149 fs->regs.reg[5].how = REG_SAVED_OFFSET;
150 fs->regs.reg[5].loc.offset = (long)&sf->REG_NAME(ebp) - new_cfa;
151 fs->regs.reg[8].how = REG_SAVED_OFFSET;
152 fs->regs.reg[8].loc.offset = (long)&sf->REG_NAME(eip) - new_cfa;
153 fs->retaddr_column = 8;
154 fs->signal_frame = 1;
155 return _URC_NO_REASON;
156}
157#endif /* ifdef __x86_64__ */