source: rtems/c/src/librdbg/src/i386/rdbg_f.c @ 1591a1aa

4.104.114.84.95
Last change on this file since 1591a1aa was 981b99f, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 10, 1999 at 4:41:44 PM

Patch from Eric Valette <valette@…> and Emmanuel Raguet
<raguet@…>:

  • the dec21140 driver code has been hardened (various bug fixed) Emmanuel,
  • bug in the mcp750 init code have been fixed (interrupt stack/initial stack initialization), BSS correctly cleared (Eric V)
  • remote debugging over TCP/IP is nearly complete (berakpoints, backtrace, variables,...) (Eric V),
  • exception handling code has also been improved in order to fully support RDBG requirements (Eric V),
  • Property mode set to 100644
File size: 3.8 KB
Line 
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
22void
23CtxToRegs (const CPU_Exception_frame* ctx, xdr_regs* regs)
24{
25    regs->tabreg [GS]           = 0;
26    regs->tabreg [FS]           = 0;
27    regs->tabreg [ES]           = 0;
28    regs->tabreg [DS]           = 0;
29    regs->tabreg [EDI]          = ctx->edi;
30    regs->tabreg [ESI]          = ctx->esi;
31    regs->tabreg [EBP]          = ctx->ebp;
32    regs->tabreg [ESP]          = ctx->esp0;
33    regs->tabreg [EBX]          = ctx->ebx;
34    regs->tabreg [EDX]          = ctx->edx;
35    regs->tabreg [ECX]          = ctx->ecx;
36    regs->tabreg [EAX]          = ctx->eax;
37    regs->tabreg [TRAPNO]       = ctx->idtIndex;
38    regs->tabreg [ERR]          = ctx->faultCode;
39    regs->tabreg [EIP]          = ctx->eip;
40    regs->tabreg [CS]           = ctx->cs & 0xFFFF;
41    regs->tabreg [EFL]          = ctx->eflags;
42}
43
44
45    void
46RegsToCtx (const xdr_regs* regs, CPU_Exception_frame* ctx)
47{
48    ctx->edi            = regs->tabreg [EDI];
49    ctx->esi            = regs->tabreg [ESI];
50    ctx->ebp            = regs->tabreg [EBP];
51    ctx->esp0           = regs->tabreg [ESP];
52    ctx->ebx            = regs->tabreg [EBX];
53    ctx->edx            = regs->tabreg [EDX];
54    ctx->ecx            = regs->tabreg [ECX];
55    ctx->eax            = regs->tabreg [EAX];
56    ctx->idtIndex       = regs->tabreg [TRAPNO];
57    ctx->faultCode      = regs->tabreg [ERR];
58    ctx->eip            = regs->tabreg [EIP];
59    ctx->cs             = regs->tabreg [CS];
60    ctx->eflags         = regs->tabreg [EFL];
61}
62
63void
64get_ctx_thread( Thread_Control *thread, CPU_Exception_frame* ctx)
65{
66    ctx->edi            = thread->Registers.edi;
67    ctx->esi            = thread->Registers.esi;
68    ctx->ebp            = (unsigned32)(thread->Registers.ebp);
69    ctx->esp0           = (unsigned32)(thread->Registers.esp);
70    ctx->ebx            = thread->Registers.ebx;
71    ctx->edx            = 0;
72    ctx->ecx            = 0;
73    ctx->eax            = 0;
74    ctx->idtIndex       = 0;
75    ctx->faultCode      = 0;
76    ctx->eip            = *(unsigned int*)(thread->Registers.esp);
77    ctx->cs             = 0;
78    ctx->eflags         = thread->Registers.eflags;
79}
80
81void
82set_ctx_thread( Thread_Control *thread, CPU_Exception_frame* ctx)
83{
84  thread->Registers.edi = ctx->edi;
85  thread->Registers.esi = ctx->esi;             
86  thread->Registers.ebp = (void*)(ctx->ebp);           
87  thread->Registers.esp = (void*)(ctx->esp0);           
88  thread->Registers.ebx = ctx->ebx;             
89  thread->Registers.eflags = ctx->eflags;               
90}
91
92 
93
94int
95Single_Step(CPU_Exception_frame* ctx)
96{
97  /* Check if not already set */
98  if ((ctx->eflags & EFLAGS_TF) != 0  ||  ExitForSingleStep != 0) {
99    /* Check coherency */
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
111CheckForSingleStep (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
126void
127CancelSingleStep (CPU_Exception_frame* ctx)
128{
129        /* Cancel scheduled SS */
130    ctx->eflags &= ~EFLAGS_TF;
131    ExitForSingleStep-- ;
132}
133
134cpuExcHandlerType old_currentExcHandler;
135extern void  rtems_exception_prologue_50();
136
137void connect_rdbg_exception()
138{
139  interrupt_gate_descriptor      *currentIdtEntry;
140  unsigned                       limit;
141  unsigned                       level;
142
143  /*
144   *  Connect the Exception used to debug
145   */
146  i386_get_info_from_IDTR (&currentIdtEntry, &limit);
147 
148  _CPU_ISR_Disable(level);
149  create_interrupt_gate_descriptor (&currentIdtEntry[50], rtems_exception_prologue_50);
150  _CPU_ISR_Enable(level);
151
152  old_currentExcHandler = _currentExcHandler;
153  _currentExcHandler = BreakPointExcHdl ;
154
155}
Note: See TracBrowser for help on using the repository browser.