1 /* machdep.S - machine dependent assembly routines for the GDB stub */
3 * Copyright (C) 2006 Lubomir Kundrak
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.
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.
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.
20 #include <grub/cpu/gdb.h>
21 #include <grub/symbol.h>
26 #define GRUB_GDB_STACKSIZE 40000
31 .zerofill __DATA, __bss, LOCAL(grub_gdb_stack_end), GRUB_GDB_STACKSIZE, 4
32 LOCAL(grub_gdb_stack) = LOCAL(grub_gdb_stack_end)
35 * The .data index for the address vector.
41 .space GRUB_GDB_STACKSIZE
42 VARIABLE(grub_gdb_stack)
46 * Supplemental macros for register saving/restoration
47 * on exception handler entry/leave.
59 movl REG, EXT_C(grub_gdb_regs)+(NDX * 4)
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
92 movl EXT_C(grub_gdb_regs)+(NDX * 4), REG
103 .macro load16 ndx reg
107 movw EXT_C(grub_gdb_regs)+(NDX * 4), REG
166 * This macro creates handlers for a given range of exception numbers
167 * and adds their addresses to the grub_gdb_trapvec array.
176 .macro ent ec beg end=0
183 * Wrapper body itself.
189 add MACRO_DOLLAR(4), %esp
194 mov $LOCAL(grub_gdb_stack), %esp
196 mov $EXT_C(grub_gdb_stack), %esp
198 mov $(BEG), %eax /* trap number */
199 call EXT_C(grub_gdb_trap)
204 * Address entry in trapvec array.
208 .section __DATA, VECTOR
215 * Next... (recursion).
222 ent \ec "(\beg+1)" \end
228 * Here does the actual construction of the address array and handlers
232 .section __DATA, VECTOR
236 VARIABLE(grub_gdb_trapvec)
240 ent EC_PRESENT, 10, 14
242 * You may have to split this further or as(1)
243 * will complain about nesting being too deep.
245 ent EC_ABSENT, 15, GRUB_GDB_LAST_TRAP