Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / gdb / i386 / idt.c
blob69bfcb089c42cb186306fdd31e7a175e1290678e
1 /* idt.c - routines for constructing IDT fot the GDB stub */
2 /*
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/machine/memory.h>
21 #include <grub/misc.h>
22 #include <grub/cpu/gdb.h>
23 #include <grub/gdb.h>
25 static struct grub_cpu_interrupt_gate grub_gdb_idt[GRUB_GDB_LAST_TRAP + 1]
26 __attribute__ ((aligned(16)));
28 /* Sets up a gate descriptor in the IDT table. */
29 static void
30 grub_idt_gate (struct grub_cpu_interrupt_gate *gate, void (*offset) (void),
31 grub_uint16_t selector, grub_uint8_t type, grub_uint8_t dpl)
33 gate->offset_lo = (int) offset & 0xffff;
34 gate->selector = selector & 0xffff;
35 gate->unused = 0;
36 gate->gate = (type & 0x1f) | ((dpl & 0x3) << 5) | 0x80;
37 gate->offset_hi = ((int) offset >> 16) & 0xffff;
40 static struct grub_cpu_idt_descriptor grub_gdb_orig_idt_desc
41 __attribute__ ((aligned(16)));
42 static struct grub_cpu_idt_descriptor grub_gdb_idt_desc
43 __attribute__ ((aligned(16)));
45 /* Set up interrupt and trap handler descriptors in IDT. */
46 void
47 grub_gdb_idtinit (void)
49 int i;
50 grub_uint16_t seg;
52 asm volatile ("xorl %%eax, %%eax\n"
53 "mov %%cs, %%ax\n" :"=a" (seg));
55 for (i = 0; i <= GRUB_GDB_LAST_TRAP; i++)
57 grub_idt_gate (&grub_gdb_idt[i],
58 grub_gdb_trapvec[i], seg,
59 GRUB_CPU_TRAP_GATE, 0);
62 grub_gdb_idt_desc.base = (grub_addr_t) grub_gdb_idt;
63 grub_gdb_idt_desc.limit = sizeof (grub_gdb_idt) - 1;
64 asm volatile ("sidt %0" : : "m" (grub_gdb_orig_idt_desc));
65 asm volatile ("lidt %0" : : "m" (grub_gdb_idt_desc));
68 void
69 grub_gdb_idtrestore (void)
71 asm volatile ("lidt %0" : : "m" (grub_gdb_orig_idt_desc));
74 void
75 grub_gdb_breakpoint (void)
77 asm volatile ("int $3");