ReactOS 0.4.16-dev-340-g0540c21
i386-stub-win32.c File Reference
#include <stdio.h>
#include <string.h>
#include "utility/utility.h"
Include dependency graph for i386-stub-win32.c:

Go to the source code of this file.

Macros

#define BUFMAX   400
 
#define NUMREGS   16
 
#define NUMREGBYTES   (NUMREGS * 4)
 
#define STACKSIZE   10000
 
#define SAVE_REGISTERS1()
 
#define SAVE_ERRCODE()
 
#define SAVE_REGISTERS2()
 
#define CHECK_FAULT()
 
#define CALL_HOOK()   asm("call _remcomHandler");
 
#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 ("ret")
 
 asm (" iret")
 
 asm ("mem_fault:")
 
 asm (" popl %eax")
 
 asm (" movl %eax, _gdb_i386errcode")
 
 asm (" popl %ecx")
 
 asm (" popl %edx")
 
 asm (" leave")
 
 asm (" pushl %edx")
 
 asm (" pushl %ecx")
 
 asm (" movl %eax, _mem_fault_routine")
 
 asm ("iret")
 
void _catchException3 ()
 
 asm (".globl __catchException3")
 
 asm ("__catchException3:")
 
 asm ("pushl $3")
 
void _catchException1 ()
 
 asm (".globl __catchException1")
 
 asm ("__catchException1:")
 
 asm ("pushl $1")
 
void _catchException0 ()
 
 asm (".globl __catchException0")
 
 asm ("__catchException0:")
 
 asm ("pushl $0")
 
void _catchException4 ()
 
 asm (".globl __catchException4")
 
 asm ("__catchException4:")
 
 asm ("pushl $4")
 
void _catchException5 ()
 
 asm (".globl __catchException5")
 
 asm ("__catchException5:")
 
 asm ("pushl $5")
 
void _catchException6 ()
 
 asm (".globl __catchException6")
 
 asm ("__catchException6:")
 
 asm ("pushl $6")
 
void _catchException7 ()
 
 asm (".globl __catchException7")
 
 asm ("__catchException7:")
 
 asm ("pushl $7")
 
void _catchException8 ()
 
 asm (".globl __catchException8")
 
 asm ("__catchException8:")
 
 asm ("pushl $8")
 
void _catchException9 ()
 
 asm (".globl __catchException9")
 
 asm ("__catchException9:")
 
 asm ("pushl $9")
 
void _catchException10 ()
 
 asm (".globl __catchException10")
 
 asm ("__catchException10:")
 
 asm ("pushl $10")
 
void _catchException12 ()
 
 asm (".globl __catchException12")
 
 asm ("__catchException12:")
 
 asm ("pushl $12")
 
void _catchException16 ()
 
 asm (".globl __catchException16")
 
 asm ("__catchException16:")
 
 asm ("pushl $16")
 
void _catchException13 ()
 
 asm (".globl __catchException13")
 
 asm ("__catchException13:")
 
 asm ("pushl $13")
 
void _catchException11 ()
 
 asm (".globl __catchException11")
 
 asm ("__catchException11:")
 
 asm ("pushl $11")
 
void _catchException14 ()
 
 asm (".globl __catchException14")
 
 asm ("__catchException14:")
 
 asm ("pushl $14")
 
 asm ("_remcomHandler:")
 
 asm (" movl _stackPtr, %esp")
 
 asm (" call _handle_exception")
 
void _returnFromException ()
 
int hex (char ch)
 
chargetpacket (void)
 
void putpacket (char *buffer)
 
void debug_error (char *format)
 
void set_mem_err (void)
 
int get_char (char *addr)
 
void set_char (char *addr, int val)
 
charmem2hex (char *mem, char *buf, int count, int may_fault)
 
charhex2mem (char *buf, char *mem, int count, int may_fault)
 
int computeSignal (int exceptionVector)
 
int hexToInt (char **ptr, int *intValue)
 
void handle_exception (int exceptionVector)
 
void set_debug_traps (void)
 
void breakpoint (void)
 

Variables

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

Macro Definition Documentation

◆ BREAKPOINT

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

Definition at line 456 of file i386-stub-win32.c.

◆ BUFMAX

#define BUFMAX   400

Definition at line 109 of file i386-stub-win32.c.

◆ CALL_HOOK

CALL_HOOK ( )    asm("call _remcomHandler");

Definition at line 260 of file i386-stub-win32.c.

◆ CHECK_FAULT

CHECK_FAULT ( )
Value:
asm ("cmpl $0, _mem_fault_routine"); \
asm ("jne mem_fault");

Definition at line 225 of file i386-stub-win32.c.

◆ NUMREGBYTES

#define NUMREGBYTES   (NUMREGS * 4)

Definition at line 122 of file i386-stub-win32.c.

◆ NUMREGS

#define NUMREGS   16

Definition at line 119 of file i386-stub-win32.c.

◆ SAVE_ERRCODE

SAVE_ERRCODE ( )
Value:
asm ("popl %ebx"); \
asm ("movl %ebx, _gdb_i386errcode");

Definition at line 208 of file i386-stub-win32.c.

◆ SAVE_REGISTERS1

SAVE_REGISTERS1 ( )
Value:
asm ("movl %eax, _registers"); \
asm ("movl %ecx, _registers+4"); \
asm ("movl %edx, _registers+8"); \
asm ("movl %ebx, _registers+12"); \
asm ("movl %ebp, _registers+20"); \
asm ("movl %esi, _registers+24"); \
asm ("movl %edi, _registers+28"); \
asm ("movw $0, %ax"); \
asm ("movw %ds, _registers+48"); \
asm ("movw %ax, _registers+50"); \
asm ("movw %es, _registers+52"); \
asm ("movw %ax, _registers+54"); \
asm ("movw %fs, _registers+56"); \
asm ("movw %ax, _registers+58"); \
asm ("movw %gs, _registers+60"); \
asm ("movw %ax, _registers+62");

Definition at line 191 of file i386-stub-win32.c.

◆ SAVE_REGISTERS2

SAVE_REGISTERS2 ( )
Value:
asm ("popl %ebx"); /* old eip */ \
asm ("movl %ebx, _registers+32"); \
asm ("popl %ebx"); /* old cs */ \
asm ("movl %ebx, _registers+40"); \
asm ("movw %ax, _registers+42"); \
asm ("popl %ebx"); /* old eflags */ \
asm ("movl %ebx, _registers+36"); \
/* Now that we've done the pops, we can save the stack pointer."); */ \
asm ("movw %ss, _registers+44"); \
asm ("movw %ax, _registers+46"); \
asm ("movl %esp, _registers+16");

Definition at line 211 of file i386-stub-win32.c.

◆ STACKSIZE

#define STACKSIZE   10000

Definition at line 136 of file i386-stub-win32.c.

Enumeration Type Documentation

◆ regnames

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

Definition at line 124 of file i386-stub-win32.c.

124 {EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
125 PC /* also known as eip */,
126 PS /* also known as eflags */,
127 CS, SS, DS, ES, FS, GS};
@ EDI
@ ESP
@ PS
@ ECX
@ ESI
@ EAX
@ FS
@ ES
@ CS
@ EBX
@ EDX
@ GS
@ PC
@ DS
@ SS
@ EBP

Function Documentation

◆ _catchException0()

void _catchException0 ( )

Referenced by set_debug_traps().

◆ _catchException1()

void _catchException1 ( )

Referenced by set_debug_traps().

◆ _catchException10()

void _catchException10 ( )

Referenced by set_debug_traps().

◆ _catchException11()

void _catchException11 ( )

Referenced by set_debug_traps().

◆ _catchException12()

void _catchException12 ( )

Referenced by set_debug_traps().

◆ _catchException13()

void _catchException13 ( )

Referenced by set_debug_traps().

◆ _catchException14()

void _catchException14 ( )

Referenced by set_debug_traps().

◆ _catchException16()

void _catchException16 ( )

Referenced by set_debug_traps().

◆ _catchException3()

void _catchException3 ( )

Referenced by set_debug_traps().

◆ _catchException4()

void _catchException4 ( )

Referenced by set_debug_traps().

◆ _catchException5()

void _catchException5 ( )

Referenced by set_debug_traps().

◆ _catchException6()

void _catchException6 ( )

Referenced by set_debug_traps().

◆ _catchException7()

void _catchException7 ( )

Referenced by set_debug_traps().

◆ _catchException8()

void _catchException8 ( )

Referenced by set_debug_traps().

◆ _catchException9()

void _catchException9 ( )

Referenced by set_debug_traps().

◆ _returnFromException()

void _returnFromException ( )

Definition at line 445 of file i386-stub-win32.c.

446{
448}
void return_to_prog()

Referenced by handle_exception().

◆ asm() [1/78]

asm ( " call _handle_exception"  )

◆ asm() [2/78]

asm ( " movl  _stackPtr,
%esp"   
)

◆ asm() [3/78]

asm ( " iret"  )

◆ asm() [4/78]

asm ( " movl _registers+  12,
%ebx"   
)

◆ asm() [5/78]

asm ( " movl _registers+  16,
%esp"   
)

◆ asm() [6/78]

asm ( " movl _registers+  20,
%ebp"   
)

◆ asm() [7/78]

asm ( " movl _registers+  24,
%esi"   
)

◆ asm() [8/78]

asm ( " movl _registers+  28,
%edi"   
)

◆ asm() [9/78]

asm ( " movl _registers+  36,
%eax"   
)

◆ asm() [10/78]

asm ( " movl _registers+  4,
%ecx"   
)

◆ asm() [11/78]

asm ( " movl _registers+  8,
%edx"   
)

◆ asm() [12/78]

asm ( " movl  _registers,
%eax"   
)

◆ asm() [13/78]

asm ( " movw _registers+  44,
%ss"   
)

◆ asm() [14/78]

asm ( " movw _registers+  48,
%ds"   
)

◆ asm() [15/78]

asm ( " movw _registers+  52,
%es"   
)

◆ asm() [16/78]

asm ( " movw _registers+  56,
%fs"   
)

◆ asm() [17/78]

asm ( " movw _registers+  60,
%gs"   
)

◆ asm() [18/78]

asm ( " pushl %eax"  )

◆ asm() [19/78]

asm ( " leave"  )

◆ asm() [20/78]

asm ( " movl %  eax,
_gdb_i386errcode"   
)

◆ asm() [21/78]

asm ( " movl %  eax,
_mem_fault_routine"   
)

◆ asm() [22/78]

asm ( " popl %eax"  )

◆ asm() [23/78]

asm ( " popl %ecx"  )

◆ asm() [24/78]

asm ( " popl %edx"  )

◆ asm() [25/78]

asm ( " pushl %ecx"  )

◆ asm() [26/78]

asm ( " pushl %edx"  )

◆ asm() [27/78]

asm ( ".globl __catchException0"  )

◆ asm() [28/78]

asm ( ".globl __catchException1"  )

◆ asm() [29/78]

asm ( ".globl __catchException10"  )

◆ asm() [30/78]

asm ( ".globl __catchException11"  )

◆ asm() [31/78]

asm ( ".globl __catchException12"  )

◆ asm() [32/78]

asm ( ".globl __catchException13"  )

◆ asm() [33/78]

asm ( ".globl __catchException14"  )

◆ asm() [34/78]

asm ( ".globl __catchException16"  )

◆ asm() [35/78]

asm ( ".globl __catchException3"  )

◆ asm() [36/78]

asm ( ".globl __catchException4"  )

◆ asm() [37/78]

asm ( ".globl __catchException5"  )

◆ asm() [38/78]

asm ( ".globl __catchException6"  )

◆ asm() [39/78]

asm ( ".globl __catchException7"  )

◆ asm() [40/78]

asm ( ".globl __catchException8"  )

◆ asm() [41/78]

asm ( ".globl __catchException9"  )

◆ asm() [42/78]

asm ( ".globl _return_to_prog"  )

◆ asm() [43/78]

asm ( ".text"  )

◆ asm() [44/78]

asm ( "__catchException0:"  )

◆ asm() [45/78]

asm ( "__catchException10:"  )

◆ asm() [46/78]

asm ( "__catchException11:"  )

◆ asm() [47/78]

asm ( "__catchException12:"  )

◆ asm() [48/78]

asm ( "__catchException13:"  )

◆ asm() [49/78]

asm ( "__catchException14:"  )

◆ asm() [50/78]

asm ( "__catchException16:"  )

◆ asm() [51/78]

asm ( "__catchException1:"  )

◆ asm() [52/78]

asm ( "__catchException3:"  )

◆ asm() [53/78]

asm ( "__catchException4:"  )

◆ asm() [54/78]

asm ( "__catchException5:"  )

◆ asm() [55/78]

asm ( "__catchException6:"  )

◆ asm() [56/78]

asm ( "__catchException7:"  )

◆ asm() [57/78]

asm ( "__catchException8:"  )

◆ asm() [58/78]

asm ( "__catchException9:"  )

◆ asm() [59/78]

asm ( "_remcomHandler:"  )

◆ asm() [60/78]

asm ( "_return_to_prog:"  )

◆ asm() [61/78]

asm ( "iret"  )

◆ asm() [62/78]

asm ( "mem_fault:"  )

◆ asm() [63/78]

asm ( "pushl $0"  )

◆ asm() [64/78]

asm ( "pushl $1"  )

◆ asm() [65/78]

asm ( "pushl $10"  )

◆ asm() [66/78]

asm ( "pushl $11"  )

◆ asm() [67/78]

asm ( "pushl $12"  )

◆ asm() [68/78]

asm ( "pushl $13"  )

◆ asm() [69/78]

asm ( "pushl $14"  )

◆ asm() [70/78]

asm ( "pushl $16"  )

◆ asm() [71/78]

asm ( "pushl $3"  )

◆ asm() [72/78]

asm ( "pushl $4"  )

◆ asm() [73/78]

asm ( "pushl $5"  )

◆ asm() [74/78]

asm ( "pushl $6"  )

◆ asm() [75/78]

asm ( "pushl $7"  )

◆ asm() [76/78]

asm ( "pushl $8"  )

◆ asm() [77/78]

asm ( "pushl $9"  )

◆ asm() [78/78]

asm ( "ret"  )

◆ breakpoint()

void breakpoint ( void  )

Definition at line 1043 of file i386-stub-win32.c.

1044{
1045 if (initialized)
1046 BREAKPOINT ();
1047}
#define BREAKPOINT()
static char initialized

Referenced by DECLARE_INTERFACE_(), and xmlInitMemory().

◆ computeSignal()

int computeSignal ( int  exceptionVector)

Definition at line 745 of file i386-stub-win32.c.

746{
747 int sigval;
748 switch (exceptionVector)
749 {
750 case 0:
751 sigval = 8;
752 break; /* divide by zero */
753 case 1:
754 sigval = 5;
755 break; /* debug exception */
756 case 3:
757 sigval = 5;
758 break; /* breakpoint */
759 case 4:
760 sigval = 16;
761 break; /* into instruction (overflow) */
762 case 5:
763 sigval = 16;
764 break; /* bound instruction */
765 case 6:
766 sigval = 4;
767 break; /* Invalid opcode */
768 case 7:
769 sigval = 8;
770 break; /* coprocessor not available */
771 case 8:
772 sigval = 7;
773 break; /* double fault */
774 case 9:
775 sigval = 11;
776 break; /* coprocessor segment overrun */
777 case 10:
778 sigval = 11;
779 break; /* Invalid TSS */
780 case 11:
781 sigval = 11;
782 break; /* Segment not present */
783 case 12:
784 sigval = 11;
785 break; /* stack exception */
786 case 13:
787 sigval = 11;
788 break; /* general protection */
789 case 14:
790 sigval = 11;
791 break; /* page fault */
792 case 16:
793 sigval = 7;
794 break; /* coprocessor error */
795 default:
796 sigval = 7; /* "software generated" */
797 }
798 return (sigval);
799}

Referenced by handle_exception().

◆ debug_error()

void debug_error ( char format)

Definition at line 630 of file i386-stub-win32.c.

631{
632 if (remote_debug)
633 fprintf (stderr, format/*, parm*/);
634}
int remote_debug
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Definition: format.c:58

Referenced by handle_exception().

◆ exceptionHandler()

void exceptionHandler ( )

Referenced by set_debug_traps().

◆ get_char()

int get_char ( char addr)

Definition at line 654 of file i386-stub-win32.c.

655{
656 return *addr;
657}
GLenum const GLvoid * addr
Definition: glext.h:9621

Referenced by mem2hex().

◆ getDebugChar()

int getDebugChar ( )

Referenced by getpacket(), and putpacket().

◆ getpacket()

char * getpacket ( void  )

Definition at line 530 of file i386-stub-win32.c.

531{
532 char *buffer = &remcomInBuffer[0];
533 unsigned char checksum;
534 unsigned char xmitcsum;
535 int count;
536 char ch;
537
538 while (1)
539 {
540 /* wait around for the start character, ignore all other characters */
541 while ((ch = getDebugChar ()) != '$')
542 ;
543
544 retry:
545 checksum = 0;
546 xmitcsum = -1;
547 count = 0;
548
549 /* now, read until a # or end of buffer is found */
550 while (count < BUFMAX - 1)
551 {
552 ch = getDebugChar ();
553 if (ch == '$')
554 goto retry;
555 if (ch == '#')
556 break;
557 checksum = checksum + ch;
558 buffer[count] = ch;
559 count = count + 1;
560 }
561 buffer[count] = 0;
562
563 if (ch == '#')
564 {
565 ch = getDebugChar ();
566 xmitcsum = hex (ch) << 4;
567 ch = getDebugChar ();
568 xmitcsum += hex (ch);
569
570 if (checksum != xmitcsum)
571 {
572 if (remote_debug)
573 {
575 "bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n",
576 checksum, xmitcsum, buffer);
577 }
578 putDebugChar ('-'); /* failed checksum */
579 }
580 else
581 {
582 putDebugChar ('+'); /* successful transfer */
583
584 /* if a sequence char is present, reply the sequence ID */
585 if (buffer[2] == ':')
586 {
587 putDebugChar (buffer[0]);
588 putDebugChar (buffer[1]);
589
590 return &buffer[3];
591 }
592
593 return &buffer[0];
594 }
595 }
596 }
597}
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
Definition: fdi.c:353
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
void putDebugChar()
int getDebugChar()
static char remcomInBuffer[BUFMAX]
#define BUFMAX
int hex(char ch)

Referenced by handle_exception().

◆ handle_exception()

void handle_exception ( int  exceptionVector)

Definition at line 834 of file i386-stub-win32.c.

835{
836 int sigval, stepping;
837 int addr, length;
838 char *ptr;
839
840#ifndef WIN32 //MF
841 gdb_i386vector = exceptionVector;
842#endif
843
844 if (remote_debug)
845 {
846 printf ("vector=%d, sr=0x%x, pc=0x%x\n",
847 exceptionVector, registers[PS], registers[PC]);
848 }
849
850 /* reply to host that an exception has occurred */
851 sigval = computeSignal (exceptionVector);
852
854
855 *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */
856 *ptr++ = hexchars[sigval >> 4];
857 *ptr++ = hexchars[sigval & 0xf];
858
859 *ptr++ = hexchars[ESP];
860 *ptr++ = ':';
861 ptr = mem2hex((char *)&registers[ESP], ptr, 4, 0); /* SP */
862 *ptr++ = ';';
863
864 *ptr++ = hexchars[EBP];
865 *ptr++ = ':';
866 ptr = mem2hex((char *)&registers[EBP], ptr, 4, 0); /* FP */
867 *ptr++ = ';';
868
869 *ptr++ = hexchars[PC];
870 *ptr++ = ':';
871 ptr = mem2hex((char *)&registers[PC], ptr, 4, 0); /* PC */
872 *ptr++ = ';';
873
874 *ptr = '\0';
875
877
878 stepping = 0;
879
880 while (1 == 1)
881 {
882 remcomOutBuffer[0] = 0;
883 ptr = getpacket ();
884
885 switch (*ptr++)
886 {
887 case '?':
888 remcomOutBuffer[0] = 'S';
889 remcomOutBuffer[1] = hexchars[sigval >> 4];
890 remcomOutBuffer[2] = hexchars[sigval % 16];
891 remcomOutBuffer[3] = 0;
892 break;
893 case 'd':
894 remote_debug = !(remote_debug); /* toggle debug flag */
895 break;
896 case 'g': /* return the value of the CPU registers */
898 break;
899 case 'G': /* set the value of the CPU registers - return OK */
900 hex2mem (ptr, (char *) registers, NUMREGBYTES, 0);
902 break;
903 case 'P': /* set the value of a single CPU register - return OK */
904 {
905 int regno;
906
907 if (hexToInt (&ptr, &regno) && *ptr++ == '=')
908 if (regno >= 0 && regno < NUMREGS)
909 {
910 hex2mem (ptr, (char *) &registers[regno], 4, 0);
912 break;
913 }
914
916 break;
917 }
918
919 /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
920 case 'm':
921 /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
922 if (hexToInt (&ptr, &addr))
923 if (*(ptr++) == ',')
924 if (hexToInt (&ptr, &length))
925 {
926 ptr = 0;
927 mem_err = 0;
928 mem2hex ((char *) addr, remcomOutBuffer, length, 1);
929 if (mem_err)
930 {
932 debug_error ("memory fault");
933 }
934 }
935
936 if (ptr)
937 {
939 }
940 break;
941
942 /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
943 case 'M':
944 /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
945 if (hexToInt (&ptr, &addr))
946 if (*(ptr++) == ',')
947 if (hexToInt (&ptr, &length))
948 if (*(ptr++) == ':')
949 {
950 mem_err = 0;
951 hex2mem (ptr, (char *) addr, length, 1);
952
953 if (mem_err)
954 {
956 debug_error ("memory fault");
957 }
958 else
959 {
961 }
962
963 ptr = 0;
964 }
965 if (ptr)
966 {
968 }
969 break;
970
971 /* cAA..AA Continue at address AA..AA(optional) */
972 /* sAA..AA Step one instruction from AA..AA(optional) */
973 case 's':
974 stepping = 1;
975 case 'c':
976 /* try to read optional parameter, pc unchanged if no parm */
977 if (hexToInt (&ptr, &addr))
978 registers[PC] = addr;
979
980 /* clear the trace bit */
981 registers[PS] &= 0xfffffeff;
982
983 /* set the trace bit if we're stepping */
984 if (stepping)
985 registers[PS] |= 0x100;
986
987#ifdef WIN32 //MF
988 return;
989#else
990 _returnFromException (); /* this is a jump */
991#endif
992 break;
993
994 /* kill the program */
995 case 'k': /* do nothing */
996#if 0
997 /* Huh? This doesn't look like "nothing".
998 m68k-stub.c and sparc-stub.c don't have it. */
999 BREAKPOINT ();
1000#endif
1001 break;
1002 } /* switch */
1003
1004 /* reply to the request */
1006 }
1007}
#define printf
Definition: freeldr.h:97
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
static const char hexchars[]
int gdb_i386vector
void putpacket(char *buffer)
char * hex2mem(char *buf, char *mem, int count, int may_fault)
int registers[NUMREGS]
static volatile int mem_err
static char remcomOutBuffer[BUFMAX]
#define NUMREGS
char * getpacket(void)
#define NUMREGBYTES
int computeSignal(int exceptionVector)
int hexToInt(char **ptr, int *intValue)
void debug_error(char *format)
void _returnFromException()
char * mem2hex(char *mem, char *buf, int count, int may_fault)
#define strcpy_s(d, l, s)
Definition: utility.h:200
static PVOID ptr
Definition: dispmode.c:27

◆ hex()

◆ hex2mem()

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

Definition at line 705 of file i386-stub-win32.c.

710{
711 int i;
712 unsigned char ch;
713
714#ifdef WIN32 //MF
715 // MinGW does not support structured exception handling, so let's
716 // go safe and make memory writable by default
717 DWORD old_protect;
718
720#else
721 if (may_fault)
723#endif
724
725 for (i = 0; i < count; i++)
726 {
727 ch = hex (*buf++) << 4;
728 ch = ch + hex (*buf++);
729 set_char (mem++, ch);
730 if (may_fault && mem_err)
731 return (mem);
732 }
733
734#ifndef WIN32 //MF
735 if (may_fault)
737#endif
738
739 return (mem);
740}
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static void(*volatile mem_fault_routine)()
void set_mem_err(void)
void set_char(char *addr, int val)
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
Definition: mem.c:349
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:135

Referenced by handle_exception().

◆ hexToInt()

int hexToInt ( char **  ptr,
int intValue 
)

Definition at line 806 of file i386-stub-win32.c.

807{
808 int numChars = 0;
809 int hexValue;
810
811 *intValue = 0;
812
813 while (**ptr)
814 {
815 hexValue = hex (**ptr);
816 if (hexValue >= 0)
817 {
818 *intValue = (*intValue << 4) | hexValue;
819 numChars++;
820 }
821 else
822 break;
823
824 (*ptr)++;
825 }
826
827 return (numChars);
828}
USHORT numChars

Referenced by handle_exception().

◆ mem2hex()

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

Definition at line 670 of file i386-stub-win32.c.

675{
676 int i;
677 unsigned char ch;
678
679#ifdef WIN32 //MF
680 if (IsBadReadPtr(mem, count))
681 return mem;
682#else
683 if (may_fault)
685#endif
686 for (i = 0; i < count; i++)
687 {
688 ch = get_char (mem++);
689 if (may_fault && mem_err)
690 return (buf);
691 *buf++ = hexchars[ch >> 4];
692 *buf++ = hexchars[ch % 16];
693 }
694 *buf = 0;
695#ifndef WIN32 //MF
696 if (may_fault)
698#endif
699 return (buf);
700}
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:805
int get_char(char *addr)

Referenced by handle_exception().

◆ putDebugChar()

void putDebugChar ( )

Referenced by getpacket(), and putpacket().

◆ putpacket()

void putpacket ( char buffer)

Definition at line 602 of file i386-stub-win32.c.

603{
604 unsigned char checksum;
605 int count;
606 char ch;
607
608 /* $<packet info>#<checksum>. */
609 do
610 {
611 putDebugChar ('$');
612 checksum = 0;
613 count = 0;
614
615 while ((ch = buffer[count]) != 0)
616 {
617 putDebugChar (ch);
618 checksum += ch;
619 count += 1;
620 }
621
622 putDebugChar ('#');
625
626 }
627 while (getDebugChar () != '+');
628}

Referenced by handle_exception().

◆ return_to_prog()

void return_to_prog ( )

Referenced by _returnFromException().

◆ set_char()

void set_char ( char addr,
int  val 
)

Definition at line 660 of file i386-stub-win32.c.

661{
662 *addr = val;
663}
GLuint GLfloat * val
Definition: glext.h:7180

Referenced by hex2mem().

◆ set_debug_traps()

void set_debug_traps ( void  )

Definition at line 1012 of file i386-stub-win32.c.

1013{
1014#ifndef WIN32 //MF
1015 stackPtr = &remcomStack[STACKSIZE / sizeof (int) - 1];
1016
1032#endif // WIN32
1033
1034 initialized = 1;
1035}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define STACKSIZE
void _catchException10()
void _catchException4()
static int * stackPtr
void _catchException12()
void _catchException6()
void _catchException0()
void _catchException5()
void _catchException3()
void _catchException11()
void _catchException13()
void _catchException8()
void _catchException9()
void _catchException7()
void _catchException14()
void _catchException1()
void exceptionHandler()
void _catchException16()
int remcomStack[STACKSIZE/sizeof(int)]

◆ set_mem_err()

void set_mem_err ( void  )

Definition at line 644 of file i386-stub-win32.c.

645{
646 mem_err = 1;
647}

Referenced by hex2mem(), and mem2hex().

Variable Documentation

◆ gdb_i386errcode

int gdb_i386errcode

Definition at line 184 of file i386-stub-win32.c.

◆ gdb_i386vector

int gdb_i386vector = -1

Definition at line 187 of file i386-stub-win32.c.

Referenced by handle_exception().

◆ hexchars

const char hexchars[] ="0123456789abcdef"
static

Definition at line 116 of file i386-stub-win32.c.

Referenced by handle_exception(), mem2hex(), and putpacket().

◆ initialized

char initialized
static

Definition at line 111 of file i386-stub-win32.c.

Referenced by breakpoint(), and set_debug_traps().

◆ mem_err

volatile int mem_err = 0
static

Definition at line 641 of file i386-stub-win32.c.

Referenced by handle_exception(), hex2mem(), mem2hex(), and set_mem_err().

◆ mem_fault_routine

void(*volatile mem_fault_routine) () ( ) = NULL
static

Definition at line 637 of file i386-stub-win32.c.

Referenced by hex2mem(), and mem2hex().

◆ registers

◆ remcomInBuffer

char remcomInBuffer[BUFMAX]
static

Definition at line 524 of file i386-stub-win32.c.

Referenced by getpacket().

◆ remcomOutBuffer

char remcomOutBuffer[BUFMAX]
static

Definition at line 525 of file i386-stub-win32.c.

Referenced by handle_exception().

◆ remcomStack

int remcomStack[STACKSIZE/sizeof(int)]

Definition at line 137 of file i386-stub-win32.c.

Referenced by set_debug_traps().

◆ remote_debug

int remote_debug

Definition at line 113 of file i386-stub-win32.c.

Referenced by debug_error(), getpacket(), and handle_exception().

◆ stackPtr

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

Definition at line 138 of file i386-stub-win32.c.

Referenced by set_debug_traps().