MicrOS
gdb_stub.c File Reference
#include <stdio.h>
#include <string.h>
#include "cpu/idt/state/exception_state.h"

Macros

#define BUFMAX   400
 
#define NUMREGS   16
 
#define NUMREGBYTES   (NUMREGS * 4)
 
#define STACKSIZE   10000
 
#define BREAKPOINT()   asm(" int $3");
 

Enumerations

enum  regnames {
  EAX, ECX, EDX, EBX,
  ESP, EBP, ESI, EDI,
  PC, PS, CS, SS,
  DS, ES, FS, GS
}
 

Functions

void putDebugChar ()
 
int getDebugChar ()
 
void exceptionHandler ()
 
void return_to_prog ()
 
 asm (".text")
 
 asm (".globl return_to_prog")
 
 asm ("return_to_prog:")
 
 asm (" movw registers+44, %ss")
 
 asm (" movl registers+16, %esp")
 
 asm (" movl registers+4, %ecx")
 
 asm (" movl registers+8, %edx")
 
 asm (" movl registers+12, %ebx")
 
 asm (" movl registers+20, %ebp")
 
 asm (" movl registers+24, %esi")
 
 asm (" movl registers+28, %edi")
 
 asm (" movw registers+48, %ds")
 
 asm (" movw registers+52, %es")
 
 asm (" movw registers+56, %fs")
 
 asm (" movw registers+60, %gs")
 
 asm (" movl registers+36, %eax")
 
 asm (" pushl %eax")
 
 asm (" movl registers, %eax")
 
 asm (" iret")
 
void _returnFromException ()
 
int hex (char ch)
 
unsigned char * getpacket (void)
 
void putpacket (unsigned char *buffer)
 
void debug_error (char *format, char *parm)
 
void set_mem_err (void)
 
int get_char (char *addr)
 
void set_char (char *addr, int val)
 
char * mem2hex (char *mem, char *buf, int count, int may_fault)
 
char * hex2mem (char *buf, char *mem, int count, int may_fault)
 
int computeSignal (int exceptionVector)
 
int hexToInt (char **ptr, int *intValue)
 
void handle_exception (exception_state *state)
 
void set_debug_traps (void)
 
void breakpoint (void)
 

Variables

static char initialized
 
int remote_debug
 
static const char hexchars [] ="0123456789abcdef"
 
unsigned int registers [NUMREGS]
 
int remcomStack [STACKSIZE/sizeof(int)]
 
static int * stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1]
 
int gdb_i386errcode
 
int gdb_i386vector = -1
 
static char remcomInBuffer [BUFMAX]
 
static char remcomOutBuffer [BUFMAX]
 
void(*volatile mem_fault_routine )() = NULL
 
volatile int mem_err = 0
 

Macro Definition Documentation

◆ BREAKPOINT

#define BREAKPOINT ( )    asm(" int $3");

◆ BUFMAX

#define BUFMAX   400

◆ NUMREGBYTES

#define NUMREGBYTES   (NUMREGS * 4)

◆ NUMREGS

#define NUMREGS   16

◆ STACKSIZE

#define STACKSIZE   10000

Enumeration Type Documentation

◆ regnames

enum regnames
Enumerator
EAX 
ECX 
EDX 
EBX 
ESP 
EBP 
ESI 
EDI 
PC 
PS 
CS 
SS 
DS 
ES 
FS 
GS 

Function Documentation

◆ _returnFromException()

void _returnFromException ( )

◆ asm() [1/19]

asm ( ".text"  )

◆ asm() [2/19]

asm ( ".globl return_to_prog )

◆ asm() [3/19]

asm ( "return_to_prog:"  )

◆ asm() [4/19]

asm ( " movw registers 44,
%ss"   
)

◆ asm() [5/19]

asm ( " movl registers 16,
%esp"   
)

◆ asm() [6/19]

asm ( " movl registers 4,
%ecx"   
)

◆ asm() [7/19]

asm ( " movl registers 8,
%edx"   
)

◆ asm() [8/19]

asm ( " movl registers 12,
%ebx"   
)

◆ asm() [9/19]

asm ( " movl registers 20,
%ebp"   
)

◆ asm() [10/19]

asm ( " movl registers 24,
%esi"   
)

◆ asm() [11/19]

asm ( " movl registers 28,
%edi"   
)

◆ asm() [12/19]

asm ( " movw registers 48,
%ds"   
)

◆ asm() [13/19]

asm ( " movw registers 52,
%es"   
)

◆ asm() [14/19]

asm ( " movw registers 56,
%fs"   
)

◆ asm() [15/19]

asm ( " movw registers 60,
%gs"   
)

◆ asm() [16/19]

asm ( " movl registers 36,
%eax"   
)

◆ asm() [17/19]

asm ( " pushl %eax"  )

◆ asm() [18/19]

asm ( " movl  registers,
%eax"   
)

◆ asm() [19/19]

asm ( " iret"  )

◆ breakpoint()

void breakpoint ( void  )

◆ computeSignal()

int computeSignal ( int  exceptionVector)

◆ debug_error()

void debug_error ( char *  format,
char *  parm 
)

◆ exceptionHandler()

void exceptionHandler ( )

◆ get_char()

int get_char ( char *  addr)

◆ getDebugChar()

int getDebugChar ( )

◆ getpacket()

unsigned char* getpacket ( void  )

◆ handle_exception()

void handle_exception ( exception_state state)

◆ hex()

int hex ( char  ch)

◆ hex2mem()

char* hex2mem ( char *  buf,
char *  mem,
int  count,
int  may_fault 
)

◆ hexToInt()

int hexToInt ( char **  ptr,
int *  intValue 
)

◆ mem2hex()

char* mem2hex ( char *  mem,
char *  buf,
int  count,
int  may_fault 
)

◆ putDebugChar()

void putDebugChar ( )

◆ putpacket()

void putpacket ( unsigned char *  buffer)

◆ return_to_prog()

void return_to_prog ( )

◆ set_char()

void set_char ( char *  addr,
int  val 
)

◆ set_debug_traps()

void set_debug_traps ( void  )

◆ set_mem_err()

void set_mem_err ( void  )

Variable Documentation

◆ gdb_i386errcode

int gdb_i386errcode

◆ gdb_i386vector

int gdb_i386vector = -1

◆ hexchars

const char hexchars[] ="0123456789abcdef"
static

◆ initialized

char initialized
static

◆ mem_err

volatile int mem_err = 0

◆ mem_fault_routine

void(*volatile mem_fault_routine) () = NULL

◆ registers

unsigned int registers[NUMREGS]

◆ remcomInBuffer

char remcomInBuffer[BUFMAX]
static

◆ remcomOutBuffer

char remcomOutBuffer[BUFMAX]
static

◆ remcomStack

int remcomStack[STACKSIZE/sizeof(int)]

◆ remote_debug

int remote_debug

◆ stackPtr

int* stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1]
static