1 | /* |
---|
2 | ************************************************************************** |
---|
3 | * |
---|
4 | * Component = |
---|
5 | * |
---|
6 | * Synopsis = rdbg/i386/rdbg_f.c |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | * |
---|
10 | ************************************************************************** |
---|
11 | */ |
---|
12 | |
---|
13 | #include <assert.h> |
---|
14 | #include <errno.h> |
---|
15 | #include <rdbg/reg.h> |
---|
16 | #include <rdbg/remdeb.h> |
---|
17 | #include <rdbg/rdbg.h> |
---|
18 | #include <rtems/score/cpu.h> |
---|
19 | #include <rtems/score/thread.h> |
---|
20 | |
---|
21 | void |
---|
22 | CtxToRegs (const CPU_Exception_frame * ctx, xdr_regs * regs) |
---|
23 | { |
---|
24 | regs->tabreg[GS] = 0; |
---|
25 | regs->tabreg[FS] = 0; |
---|
26 | regs->tabreg[ES] = 0; |
---|
27 | regs->tabreg[DS] = 0; |
---|
28 | regs->tabreg[EDI] = ctx->edi; |
---|
29 | regs->tabreg[ESI] = ctx->esi; |
---|
30 | regs->tabreg[EBP] = ctx->ebp; |
---|
31 | regs->tabreg[ESP] = ctx->esp0; |
---|
32 | regs->tabreg[EBX] = ctx->ebx; |
---|
33 | regs->tabreg[EDX] = ctx->edx; |
---|
34 | regs->tabreg[ECX] = ctx->ecx; |
---|
35 | regs->tabreg[EAX] = ctx->eax; |
---|
36 | regs->tabreg[TRAPNO] = ctx->idtIndex; |
---|
37 | regs->tabreg[ERR] = ctx->faultCode; |
---|
38 | regs->tabreg[EIP] = ctx->eip; |
---|
39 | regs->tabreg[CS] = ctx->cs & 0xFFFF; |
---|
40 | regs->tabreg[EFL] = ctx->eflags; |
---|
41 | } |
---|
42 | |
---|
43 | void |
---|
44 | RegsToCtx (const xdr_regs * regs, CPU_Exception_frame * ctx) |
---|
45 | { |
---|
46 | ctx->edi = regs->tabreg[EDI]; |
---|
47 | ctx->esi = regs->tabreg[ESI]; |
---|
48 | ctx->ebp = regs->tabreg[EBP]; |
---|
49 | ctx->esp0 = regs->tabreg[ESP]; |
---|
50 | ctx->ebx = regs->tabreg[EBX]; |
---|
51 | ctx->edx = regs->tabreg[EDX]; |
---|
52 | ctx->ecx = regs->tabreg[ECX]; |
---|
53 | ctx->eax = regs->tabreg[EAX]; |
---|
54 | ctx->idtIndex = regs->tabreg[TRAPNO]; |
---|
55 | ctx->faultCode = regs->tabreg[ERR]; |
---|
56 | ctx->eip = regs->tabreg[EIP]; |
---|
57 | ctx->cs = regs->tabreg[CS]; |
---|
58 | ctx->eflags = regs->tabreg[EFL]; |
---|
59 | } |
---|
60 | |
---|
61 | void |
---|
62 | get_ctx_thread (Thread_Control * thread, CPU_Exception_frame * ctx) |
---|
63 | { |
---|
64 | ctx->edi = thread->Registers.edi; |
---|
65 | ctx->esi = thread->Registers.esi; |
---|
66 | ctx->ebp = (unsigned32) (thread->Registers.ebp); |
---|
67 | ctx->esp0 = (unsigned32) (thread->Registers.esp); |
---|
68 | ctx->ebx = thread->Registers.ebx; |
---|
69 | ctx->edx = 0; |
---|
70 | ctx->ecx = 0; |
---|
71 | ctx->eax = 0; |
---|
72 | ctx->idtIndex = 0; |
---|
73 | ctx->faultCode = 0; |
---|
74 | ctx->eip = *(unsigned int *) (thread->Registers.esp); |
---|
75 | ctx->cs = 0; |
---|
76 | ctx->eflags = thread->Registers.eflags; |
---|
77 | } |
---|
78 | |
---|
79 | void |
---|
80 | set_ctx_thread (Thread_Control * thread, CPU_Exception_frame * ctx) |
---|
81 | { |
---|
82 | thread->Registers.edi = ctx->edi; |
---|
83 | thread->Registers.esi = ctx->esi; |
---|
84 | thread->Registers.ebp = (void *) (ctx->ebp); |
---|
85 | thread->Registers.esp = (void *) (ctx->esp0); |
---|
86 | thread->Registers.ebx = ctx->ebx; |
---|
87 | thread->Registers.eflags = ctx->eflags; |
---|
88 | } |
---|
89 | |
---|
90 | int |
---|
91 | Single_Step (CPU_Exception_frame * ctx) |
---|
92 | { |
---|
93 | /* |
---|
94 | * Check if not already set |
---|
95 | */ |
---|
96 | if ((ctx->eflags & EFLAGS_TF) != 0 || ExitForSingleStep != 0) { |
---|
97 | /* |
---|
98 | * Check coherency |
---|
99 | */ |
---|
100 | assert ((ctx->eflags & EFLAGS_TF) != 0); |
---|
101 | assert (ExitForSingleStep != 0); |
---|
102 | return 0; |
---|
103 | } |
---|
104 | ctx->eflags |= EFLAGS_TF; /* eflags */ |
---|
105 | ++ExitForSingleStep; |
---|
106 | |
---|
107 | return 0; |
---|
108 | } |
---|
109 | |
---|
110 | int |
---|
111 | CheckForSingleStep (CPU_Exception_frame * ctx) |
---|
112 | { |
---|
113 | if (ExitForSingleStep) { |
---|
114 | /* |
---|
115 | * This functions can be called both from |
---|
116 | * INT1 and INT3 handlers. In case it is |
---|
117 | * called from INT3, need to clear TF. |
---|
118 | */ |
---|
119 | ctx->eflags &= ~EFLAGS_TF; |
---|
120 | ExitForSingleStep = 0; |
---|
121 | return 1; |
---|
122 | } |
---|
123 | return 0; |
---|
124 | } |
---|
125 | |
---|
126 | void |
---|
127 | CancelSingleStep (CPU_Exception_frame * ctx) |
---|
128 | { |
---|
129 | /* |
---|
130 | * Cancel scheduled SS |
---|
131 | */ |
---|
132 | ctx->eflags &= ~EFLAGS_TF; |
---|
133 | ExitForSingleStep--; |
---|
134 | } |
---|
135 | |
---|
136 | static cpuExcHandlerType old_currentExcHandler; |
---|
137 | extern void rtems_exception_prologue_50 (); |
---|
138 | |
---|
139 | void |
---|
140 | connect_rdbg_exception () |
---|
141 | { |
---|
142 | interrupt_gate_descriptor *currentIdtEntry; |
---|
143 | unsigned limit; |
---|
144 | unsigned level; |
---|
145 | |
---|
146 | /* |
---|
147 | * Connect the Exception used to debug |
---|
148 | */ |
---|
149 | i386_get_info_from_IDTR (¤tIdtEntry, &limit); |
---|
150 | |
---|
151 | _CPU_ISR_Disable (level); |
---|
152 | create_interrupt_gate_descriptor (¤tIdtEntry[50], |
---|
153 | rtems_exception_prologue_50); |
---|
154 | _CPU_ISR_Enable (level); |
---|
155 | |
---|
156 | if (_currentExcHandler != BreakPointExcHdl) { |
---|
157 | old_currentExcHandler = _currentExcHandler; |
---|
158 | _currentExcHandler = BreakPointExcHdl; |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | void |
---|
163 | disconnect_rdbg_exception () |
---|
164 | { |
---|
165 | if (_currentExcHandler == BreakPointExcHdl) { |
---|
166 | _currentExcHandler = old_currentExcHandler; |
---|
167 | } |
---|
168 | } |
---|