2 * Interrupt Descriptor Table (IDT) setup and interrupt handlers for GDB stub.
7 #define SIZEOF_I386_REGS 32
8 #define SIZEOF_I386_FLAGS 4
10 /****************************************************************************
11 * Interrupt Descriptor Table
12 ****************************************************************************
14 .section ".data16", "aw", @progbits
22 /* IDT entries have the following format:
23 * offset_lo, segment selector, flags, offset_hi
25 * Since it is not possible to specify relocations in arbitrary
26 * expressions like (int_overflow & 0xffff), we initialise the
27 * IDT with entries in an incorrect format.
29 * The entries are shuffled into the correct format in init_librm().
31 #define IDT_ENTRY_EMPTY(name) .word 0, 0, 0, 0
32 #define IDT_ENTRY_PRESENT(name) \
34 .word 0x8e00, VIRTUAL_CS
38 IDT_ENTRY_PRESENT(divide_error)
39 IDT_ENTRY_PRESENT(debug_trap)
40 IDT_ENTRY_EMPTY(non_maskable_interrupt)
41 IDT_ENTRY_PRESENT(breakpoint)
42 IDT_ENTRY_PRESENT(overflow)
43 IDT_ENTRY_PRESENT(bound_range_exceeded)
44 IDT_ENTRY_PRESENT(invalid_opcode)
45 IDT_ENTRY_EMPTY(device_not_available)
46 IDT_ENTRY_PRESENT(double_fault)
47 IDT_ENTRY_EMPTY(coprocessor_segment_overrun)
48 IDT_ENTRY_PRESENT(invalid_tss)
49 IDT_ENTRY_PRESENT(segment_not_present)
50 IDT_ENTRY_PRESENT(stack_segment_fault)
51 IDT_ENTRY_PRESENT(general_protection)
52 IDT_ENTRY_PRESENT(page_fault)
54 .equ idt_length, idt_end - idt
56 /* The IDT entries are fixed up (once) in init_librm() */
60 /****************************************************************************
61 * idt_init (real-mode near call, 16-bit real-mode near return address)
63 * Initialise the IDT, called from init_librm.
66 * %eax : IDT base address
68 * Destroys %ax, %bx, and %di.
69 ****************************************************************************
71 .section ".text16", "ax", @progbits
78 /* IDT entries are only fixed up once */
84 /* Shuffle IDT entries into the correct format */
85 movb $(idt_length / 8), %al
99 /****************************************************************************
101 ****************************************************************************
103 .section ".text", "ax", @progbits
106 /* POSIX signal numbers for reporting traps to GDB */
124 int_bound_range_exceeded:
137 int_segment_not_present:
138 int_stack_segment_fault:
139 int_general_protection:
141 movl $SIGSEGV, (%esp)
144 /* When invoked, the stack contains: eflags, cs, eip, signo. */
145 #define IH_OFFSET_GDB_REGS ( 0 )
146 #define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS )
147 #define IH_OFFSET_GDB_EFLAGS ( IH_OFFSET_GDB_EIP + 4 )
148 #define IH_OFFSET_GDB_SEG_REGS ( IH_OFFSET_GDB_EFLAGS + SIZEOF_I386_FLAGS )
149 #define IH_OFFSET_GDB_END ( IH_OFFSET_GDB_SEG_REGS + 6 * 4 )
150 #define IH_OFFSET_SIGNO ( IH_OFFSET_GDB_END )
151 #define IH_OFFSET_OLD_EIP ( IH_OFFSET_SIGNO + 4 )
152 #define IH_OFFSET_OLD_CS ( IH_OFFSET_OLD_EIP + 4 )
153 #define IH_OFFSET_OLD_EFLAGS ( IH_OFFSET_OLD_CS + 4 )
154 #define IH_OFFSET_END ( IH_OFFSET_OLD_EFLAGS + 4 )
156 /* We also access the stack whilst still storing or restoring
157 * the register snapshot. Since ESP is in flux, we need
160 #define IH_OFFSET_FLUX_OLD_CS ( IH_OFFSET_OLD_CS - 44 )
161 #define IH_OFFSET_FLUX_OLD_EFLAGS ( IH_OFFSET_OLD_EFLAGS - 40 )
162 #define IH_OFFSET_FLUX_OLD_EIP ( IH_OFFSET_OLD_EIP - 36 )
163 #define IH_OFFSET_FLUX_END ( IH_OFFSET_END - 20 )
165 /* Store CPU state in GDB register snapshot */
177 pushw IH_OFFSET_FLUX_OLD_CS + 2(%esp)
178 pushl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
179 pushl IH_OFFSET_FLUX_OLD_EIP(%esp)
183 leal IH_OFFSET_FLUX_END(%esp), %edi
184 pushl %edi /* old ESP */
190 /* Call GDB stub exception handler */
192 pushl (IH_OFFSET_SIGNO + 4)(%esp)
196 /* Restore CPU state from GDB register snapshot */
201 addl $4, %esp /* Changing ESP currently not supported */
205 popl IH_OFFSET_FLUX_OLD_EIP(%esp)
206 popl IH_OFFSET_FLUX_OLD_EFLAGS(%esp)
207 popl IH_OFFSET_FLUX_OLD_CS(%esp)
214 addl $4, %esp /* drop signo */