comparison packages/hal/i386/arch/current/src/i386_stub.c @ 72:da3908c9cd10 ecos-sw-2000-02-17

Merge from eCos master repository on 2000-02-17-18:56:14-GMT
author jlarmour
date Thu, 17 Feb 2000 19:38:13 +0000
parents
children 6ed91473a1cd
comparison
equal deleted inserted replaced
71:f4a0d3a26b92 72:da3908c9cd10
1 /* i386_stub.c - helper functions for stub, generic to all i386 processors
2 *
3 * Copyright (c) 1998,1999 Cygnus Solutions
4 *
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
13 * they apply.
14 */
15
16 /*
17 - pjo, 29 sep 1999
18 - Copied from the ARM configuration and merged with an older GDB i386-stub.c.
19 */
20
21 #include <stddef.h>
22
23 #include <pkgconf/hal.h>
24
25 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
26
27 #ifdef CYGPKG_HAL_I386_SIM
28 #error "GDB Stub support not implemented for i386 SIM"
29 #endif
30
31 #include <cyg/hal/hal_stub.h>
32 #include <cyg/hal/hal_arch.h>
33 #include <cyg/hal/hal_intr.h>
34
35 #ifndef FALSE
36 #define FALSE 0
37 #define TRUE 1
38 #endif
39
40 #ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
41 #include <cyg/hal/dbg-threads-api.h> // dbg_currthread_id
42 #endif
43
44 /* Given a trap value TRAP, return the corresponding signal. */
45
46 int __computeSignal (unsigned int trap_number)
47 {
48 switch (trap_number)
49 {
50 case CYGNUM_HAL_VECTOR_DIV0:
51 /* This isn't quite accurrate: this is integer division only. */
52 return SIGFPE ;
53
54 case CYGNUM_HAL_VECTOR_DEBUG:
55 return SIGTRAP ;
56
57 case CYGNUM_HAL_VECTOR_NMI:
58 return SIGINT ;
59
60 case CYGNUM_HAL_VECTOR_BREAKPOINT:
61 return SIGTRAP ;
62
63 case CYGNUM_HAL_VECTOR_OVERFLOW:
64 case CYGNUM_HAL_VECTOR_BOUND:
65 return SIGSEGV ;
66
67 case CYGNUM_HAL_VECTOR_OPCODE:
68 return SIGILL ;
69
70 case CYGNUM_HAL_VECTOR_NO_DEVICE:
71 case CYGNUM_HAL_VECTOR_FPE:
72 return SIGFPE ;
73
74 case CYGNUM_HAL_VECTOR_DOUBLE_FAULT:
75 return SIGTRAP ;
76
77 case CYGNUM_HAL_VECTOR_INVALID_TSS:
78 case CYGNUM_HAL_VECTOR_SEGV:
79 case CYGNUM_HAL_VECTOR_STACK_FAULT:
80 case CYGNUM_HAL_VECTOR_PROTECTION:
81 case CYGNUM_HAL_VECTOR_PAGE:
82 case CYGNUM_HAL_VECTOR_ALIGNMENT:
83 return SIGSEGV ;
84
85 default:
86 return SIGTRAP;
87 }
88 }
89
90
91 /* Return the trap number corresponding to the last-taken trap. */
92
93 int __get_trap_number (void)
94 {
95 extern int hal_pc_trap_number ;
96 // The vector is not not part of the GDB register set so get it
97 // directly from the save context.
98 return hal_pc_trap_number ;
99 }
100
101 /* Set the currently-saved pc register value to PC. */
102
103 void set_pc (target_register_t pc)
104 {
105 put_register (PC, pc);
106 }
107
108
109 /*----------------------------------------------------------------------
110 * Single-step support
111 */
112
113 /* Set things up so that the next user resume will execute one instruction.
114 This may be done by setting breakpoints or setting a single step flag
115 in the saved user registers, for example. */
116
117
118 /* We just turn on the trap bit in the flags register for the particular
119 thread. When it resumes, we'll get another debugger trap.
120 */
121 void __single_step (void)
122 { put_register(PS, get_register(PS) | PS_T) ;
123 }
124
125 /* Clear the single-step state. */
126
127 void __clear_single_step (void)
128 { put_register(PS, get_register(PS) & ~PS_T) ;
129 }
130
131 void __install_breakpoints (void)
132 {
133 // FIXME();
134 }
135
136 void __clear_breakpoints (void)
137 {
138 #ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
139 extern cyg_uint32 hal_pc_break_pc ;
140 if (hal_pc_break_pc)
141 {
142 cyg_hal_gdb_remove_break(hal_pc_break_pc) ;
143 #if 0
144 hal_pc_break_pc = 0 ;
145 // asm("movl %0, %%dr0" : /* No outputs */ : "m" (hal_pc_break_pc)) ;
146 asm("
147 movl %%dr7, %%eax
148 andl $0xFFFFFFFC, %%eax
149 movl %%eax, %%dr7"
150 : /* No outputs. */
151 : /* No inputs. */
152 : "eax");
153 #endif
154 }
155 #endif
156
157 }
158
159 /* If the breakpoint we hit is in the breakpoint() instruction, return a
160 non-zero value. */
161
162 int isBreakpointFunction ;
163
164 int
165 __is_breakpoint_function ()
166 {
167 isBreakpointFunction = (get_register (PC) == (target_register_t)&CYG_LABEL_NAME(breakinst));
168 return isBreakpointFunction ;
169 }
170
171
172 /* Skip the current instruction. Since this is only called by the
173 stub when the PC points to a breakpoint or trap instruction,
174 we can safely just skip 4. */
175
176 void __skipinst (void)
177 {
178 // FIXME() ;
179 }
180
181
182 #if 0
183 void hal_get_gdb_registers(target_register_t * d, HAL_SavedRegisters * s)
184 {
185 d[ESP] = s->esp ;
186 d[ESP] = s->esp ;
187 d[EBP] = s->ebp ;
188 d[EBX] = s->ebx ;
189 d[ESI] = s->esi ;
190 d[EDI] = s->edi ;
191 d[PC] = s->eip ;
192 }
193
194
195 void hal_set_gdb_registers(HAL_SavedRegisters * d, target_register_t * s)
196 {
197 d->esp = s[ESP] ;
198 d->next_context = 0 ;
199 d->ebp = s[EBP] ;
200 d->ebx = s[EBX] ;
201 d->esi = s[ESI] ;
202 d->edi = s[EDI] ;
203 d->eip = s[PC] ;
204 }
205 #endif
206
207
208 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS