source: grub-pc/trunk/fuentes/grub-core/gdb/i386/machdep.S @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 4.1 KB
Line 
1/* machdep.S - machine dependent assembly routines for the GDB stub */
2/*
3 *  Copyright (C) 2006  Lubomir Kundrak
4 *
5 *  This program is free software; you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation; either version 2 of the License, or
8 *  (at your option) any later version.
9 *
10 *  This program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with this program; if not, write to the Free Software
17 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <grub/cpu/gdb.h>
21#include <grub/symbol.h>
22
23#define EC_PRESENT      1
24#define EC_ABSENT       0
25
26#define GRUB_GDB_STACKSIZE      40000
27
28#define SEP ,
29
30#ifdef __APPLE__
31        .zerofill __DATA, __bss, LOCAL(grub_gdb_stack_end), GRUB_GDB_STACKSIZE, 4
32        LOCAL(grub_gdb_stack) = LOCAL(grub_gdb_stack_end)
33#else
34/*
35 * The .data index for the address vector.
36 */
37
38#define VECTOR          1
39
40        .bss
41        .space GRUB_GDB_STACKSIZE
42VARIABLE(grub_gdb_stack)
43#endif
44
45/*
46 * Supplemental macros for register saving/restoration
47 * on exception handler entry/leave.
48 */
49
50#ifdef __APPLE__
51.macro save32
52#define REG $0
53#define NDX $1
54#else
55.macro save32 reg ndx
56#define REG \reg
57#define NDX \ndx
58#endif
59        movl REG, EXT_C(grub_gdb_regs)+(NDX * 4)
60.endm
61
62#undef REG
63#undef NDX
64
65#ifdef __APPLE__
66.macro save16
67#define REG $0
68#define NDX $1
69#else
70.macro save16 reg ndx
71#define REG \reg
72#define NDX \ndx
73#endif
74        xorl %eax, %eax
75        movw REG, EXT_C(grub_gdb_regs)+(NDX * 4)
76        movw %ax, EXT_C(grub_gdb_regs)+(NDX * 4 + 2)
77        movl EXT_C(grub_gdb_regs)+(EAX * 4), %eax
78.endm
79
80#undef REG
81#undef NDX
82
83#ifdef __APPLE__
84.macro load32
85#define NDX $0
86#define REG $1
87#else
88.macro load32 ndx reg
89#define REG \reg
90#define NDX \ndx
91#endif
92        movl EXT_C(grub_gdb_regs)+(NDX * 4), REG
93.endm
94
95#undef REG
96#undef NDX
97
98#ifdef __APPLE__
99.macro load16
100#define NDX $0
101#define REG $1
102#else
103.macro load16 ndx reg
104#define NDX \ndx
105#define REG \reg
106#endif
107        movw EXT_C(grub_gdb_regs)+(NDX * 4), REG
108.endm
109
110#undef REG
111#undef NDX
112
113.macro save_context
114        save32 %eax, EAX
115
116        save32 %ecx, ECX
117        save32 %edx, EDX
118        save32 %ebx, EBX
119        save32 %ebp, EBP
120        save32 %esi, ESI
121        save32 %edi, EDI
122
123        popl %ebx
124        save32 %ebx, EIP
125        popl %ebx
126        save32 %ebx, CS
127        popl %ebx
128        save32 %ebx, EFLAGS
129
130        save32 %esp, ESP
131
132        save16 %ds, DS
133        save16 %es, ES
134        save16 %fs, FS
135        save16 %gs, GS
136        save16 %ss, SS
137.endm
138
139.macro load_context
140        load16 SS, %ss
141        load32 ESP, %esp
142
143        load32 EBP, %ebp
144        load32 ESI, %esi
145        load32 EDI, %edi
146
147        load16 DS, %ds
148        load16 ES, %es
149        load16 FS, %fs
150        load16 GS, %gs
151
152        load32 EFLAGS, %eax
153        pushl %eax
154        load32 CS, %eax
155        pushl %eax
156        load32 EIP, %eax
157        pushl %eax
158
159        load32 EBX, %ebx
160        load32 EDX, %edx
161        load32 ECX, %ecx
162        load32 EAX, %eax
163.endm
164
165/*
166 * This macro creates handlers for a given range of exception numbers
167 * and adds their addresses to the grub_gdb_trapvec array.
168 */
169
170#ifdef __APPLE__
171.macro ent
172#define EC $0
173#define BEG $1
174#define END $2
175#else
176.macro ent ec beg end=0
177#define EC \ec
178#define BEG \beg
179#define END \end
180#endif
181
182        /*
183         * Wrapper body itself.
184         */
185
186        .text
1871:     
188        .if EC
189                add MACRO_DOLLAR(4), %esp
190        .endif
191
192        save_context
193#ifdef __APPLE__
194        mov     $LOCAL(grub_gdb_stack), %esp
195#else
196        mov     $EXT_C(grub_gdb_stack), %esp
197#endif
198        mov     $(BEG), %eax    /* trap number */
199        call    EXT_C(grub_gdb_trap)
200        load_context
201        iret
202
203        /*
204         * Address entry in trapvec array.
205         */
206
207#ifdef __APPLE__
208        .section __DATA, VECTOR
209#else
210       .data VECTOR
211#endif
212        .long 1b
213
214        /*
215         * Next... (recursion).
216         */
217
218        .if END-BEG > 0
219#ifdef __APPLE__
220                ent EC, (BEG+1), END
221#else
222                ent \ec "(\beg+1)" \end
223#endif
224        .endif
225.endm
226
227/*
228 * Here does the actual construction of the address array and handlers
229 * take place.
230 */
231#ifdef __APPLE__
232        .section __DATA, VECTOR
233#else
234       .data VECTOR
235#endif
236VARIABLE(grub_gdb_trapvec)
237        ent EC_ABSENT,  0, 7
238        ent EC_PRESENT, 8
239        ent EC_ABSENT,  9
240        ent EC_PRESENT, 10, 14
241        /*
242         * You may have to split this further or as(1)
243         * will complain about nesting being too deep.
244         */
245        ent EC_ABSENT,  15, GRUB_GDB_LAST_TRAP
Note: See TracBrowser for help on using the repository browser.