OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [librdbg/] [src/] [i386/] [rdbg_f.c] - Blame information for rev 389

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 **************************************************************************
3
 *
4
 * Component =
5
 *
6
 * Synopsis  =   rdbg/i386/rdbg_f.c
7
 *
8
 * $Id: rdbg_f.c,v 1.2 2001-09-27 12:02:01 chris Exp $
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
 
22
void
23
CtxToRegs (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
46
RegsToCtx (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
 
63
void
64
get_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
 
81
void
82
set_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
 
94
int
95
Single_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
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
        /* Cancel scheduled SS */
130
    ctx->eflags &= ~EFLAGS_TF;
131
    ExitForSingleStep-- ;
132
}
133
 
134
cpuExcHandlerType old_currentExcHandler;
135
extern void  rtems_exception_prologue_50();
136
 
137
void 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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.