diff options
Diffstat (limited to 'gdb/stubs')
-rw-r--r-- | gdb/stubs/i386-stub.c | 472 | ||||
-rw-r--r-- | gdb/stubs/ia64vms-stub.c | 663 | ||||
-rw-r--r-- | gdb/stubs/m32r-stub.c | 426 | ||||
-rw-r--r-- | gdb/stubs/m68k-stub.c | 248 | ||||
-rw-r--r-- | gdb/stubs/sh-stub.c | 1088 | ||||
-rw-r--r-- | gdb/stubs/sparc-stub.c | 333 | ||||
-rw-r--r-- | gdb/stubs/z80-stub.c | 578 |
7 files changed, 1852 insertions, 1956 deletions
diff --git a/gdb/stubs/i386-stub.c b/gdb/stubs/i386-stub.c index 04996b7..094db32 100644 --- a/gdb/stubs/i386-stub.c +++ b/gdb/stubs/i386-stub.c @@ -97,32 +97,47 @@ * external low-level support routines */ -extern void putDebugChar(); /* write a single character */ -extern int getDebugChar(); /* read and return a single char */ -extern void exceptionHandler(); /* assign an exception handler */ +extern void putDebugChar (); /* write a single character */ +extern int getDebugChar (); /* read and return a single char */ +extern void exceptionHandler (); /* assign an exception handler */ /************************************************************************/ /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/ /* at least NUMREGBYTES*2 are needed for register packets */ #define BUFMAX 400 -static char initialized; /* boolean flag. != 0 means we've been initialized */ +static char initialized; /* boolean flag. != 0 means we've been initialized */ -int remote_debug; +int remote_debug; /* debug > 0 prints ill-formed commands in valid packets & checksum errors */ -static const char hexchars[]="0123456789abcdef"; +static const char hexchars[] = "0123456789abcdef"; /* Number of registers. */ -#define NUMREGS 16 +#define NUMREGS 16 /* Number of bytes of registers. */ #define NUMREGBYTES (NUMREGS * 4) -enum regnames {EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, - PC /* also known as eip */, - PS /* also known as eflags */, - CS, SS, DS, ES, FS, GS}; +enum regnames +{ + EAX, + ECX, + EDX, + EBX, + ESP, + EBP, + ESI, + EDI, + PC /* also known as eip */, + PS /* also known as eflags */, + CS, + SS, + DS, + ES, + FS, + GS +}; /* * these should not be static cuz they can be used outside this module @@ -130,45 +145,44 @@ enum regnames {EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, int registers[NUMREGS]; #define STACKSIZE 10000 -int remcomStack[STACKSIZE/sizeof(int)]; -static int* stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1]; +int remcomStack[STACKSIZE / sizeof (int)]; +static int *stackPtr = &remcomStack[STACKSIZE / sizeof (int) - 1]; /*************************** ASSEMBLY CODE MACROS *************************/ /* */ -extern void -return_to_prog (); +extern void return_to_prog (); /* Restore the program's registers (including the stack pointer, which means we get the right stack and don't have to worry about popping our return address and any stack frames and so on) and return. */ -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"); /* saved eflags */ -asm(" movl _registers+40, %eax"); -asm(" pushl %eax"); /* saved cs */ -asm(" movl _registers+32, %eax"); -asm(" pushl %eax"); /* saved eip */ -asm(" movl _registers, %eax"); +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"); /* saved eflags */ +asm (" movl _registers+40, %eax"); +asm (" pushl %eax"); /* saved cs */ +asm (" movl _registers+32, %eax"); +asm (" pushl %eax"); /* saved eip */ +asm (" movl _registers, %eax"); /* use iret to restore pc and flags together so that trace flag works right. */ -asm(" iret"); +asm (" iret"); -#define BREAKPOINT() asm(" int $3"); +#define BREAKPOINT() asm (" int $3"); /* Put the error code here just in case the user cares. */ int gdb_i386errcode; @@ -178,42 +192,42 @@ int gdb_i386vector = -1; /* GDB stores segment registers in 32-bit words (that's just the way m-i386v.h is written). So zero the appropriate areas in registers. */ -#define SAVE_REGISTERS1() \ - 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"); \ +#define SAVE_REGISTERS1() \ + 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"); #define SAVE_ERRCODE() \ - asm ("popl %ebx"); \ + asm ("popl %ebx"); \ asm ("movl %ebx, _gdb_i386errcode"); -#define SAVE_REGISTERS2() \ - 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"); \ +#define SAVE_REGISTERS2() \ + 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"); /* See if mem_fault_routine is set, if so just IRET to that address. */ -#define CHECK_FAULT() \ - asm ("cmpl $0, _mem_fault_routine"); \ +#define CHECK_FAULT() \ + asm ("cmpl $0, _mem_fault_routine"); \ asm ("jne mem_fault"); asm (".text"); @@ -246,7 +260,7 @@ asm (" movl %eax, _mem_fault_routine"); asm ("iret"); -#define CALL_HOOK() asm("call _remcomHandler"); +#define CALL_HOOK() asm ("call _remcomHandler"); /* This function is called when a i386 exception occurs. It saves * all the cpu regs in the _registers array, munges the stack a bit, @@ -258,127 +272,127 @@ asm ("iret"); * old eip * */ -extern void _catchException3(); -asm(".text"); -asm(".globl __catchException3"); -asm("__catchException3:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException3 (); +asm (".text"); +asm (".globl __catchException3"); +asm ("__catchException3:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $3"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 1. */ -extern void _catchException1(); -asm(".text"); -asm(".globl __catchException1"); -asm("__catchException1:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException1 (); +asm (".text"); +asm (".globl __catchException1"); +asm ("__catchException1:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $1"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 0. */ -extern void _catchException0(); -asm(".text"); -asm(".globl __catchException0"); -asm("__catchException0:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException0 (); +asm (".text"); +asm (".globl __catchException0"); +asm ("__catchException0:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $0"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 4. */ -extern void _catchException4(); -asm(".text"); -asm(".globl __catchException4"); -asm("__catchException4:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException4 (); +asm (".text"); +asm (".globl __catchException4"); +asm ("__catchException4:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $4"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 5. */ -extern void _catchException5(); -asm(".text"); -asm(".globl __catchException5"); -asm("__catchException5:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException5 (); +asm (".text"); +asm (".globl __catchException5"); +asm ("__catchException5:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $5"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 6. */ -extern void _catchException6(); -asm(".text"); -asm(".globl __catchException6"); -asm("__catchException6:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException6 (); +asm (".text"); +asm (".globl __catchException6"); +asm ("__catchException6:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $6"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 7. */ -extern void _catchException7(); -asm(".text"); -asm(".globl __catchException7"); -asm("__catchException7:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException7 (); +asm (".text"); +asm (".globl __catchException7"); +asm ("__catchException7:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $7"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 8. */ -extern void _catchException8(); -asm(".text"); -asm(".globl __catchException8"); -asm("__catchException8:"); -SAVE_REGISTERS1(); -SAVE_ERRCODE(); -SAVE_REGISTERS2(); +extern void _catchException8 (); +asm (".text"); +asm (".globl __catchException8"); +asm ("__catchException8:"); +SAVE_REGISTERS1 (); +SAVE_ERRCODE (); +SAVE_REGISTERS2 (); asm ("pushl $8"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 9. */ -extern void _catchException9(); -asm(".text"); -asm(".globl __catchException9"); -asm("__catchException9:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException9 (); +asm (".text"); +asm (".globl __catchException9"); +asm ("__catchException9:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $9"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 10. */ -extern void _catchException10(); -asm(".text"); -asm(".globl __catchException10"); -asm("__catchException10:"); -SAVE_REGISTERS1(); -SAVE_ERRCODE(); -SAVE_REGISTERS2(); +extern void _catchException10 (); +asm (".text"); +asm (".globl __catchException10"); +asm ("__catchException10:"); +SAVE_REGISTERS1 (); +SAVE_ERRCODE (); +SAVE_REGISTERS2 (); asm ("pushl $10"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 12. */ -extern void _catchException12(); -asm(".text"); -asm(".globl __catchException12"); -asm("__catchException12:"); -SAVE_REGISTERS1(); -SAVE_ERRCODE(); -SAVE_REGISTERS2(); +extern void _catchException12 (); +asm (".text"); +asm (".globl __catchException12"); +asm ("__catchException12:"); +SAVE_REGISTERS1 (); +SAVE_ERRCODE (); +SAVE_REGISTERS2 (); asm ("pushl $12"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 16. */ -extern void _catchException16(); -asm(".text"); -asm(".globl __catchException16"); -asm("__catchException16:"); -SAVE_REGISTERS1(); -SAVE_REGISTERS2(); +extern void _catchException16 (); +asm (".text"); +asm (".globl __catchException16"); +asm ("__catchException16:"); +SAVE_REGISTERS1 (); +SAVE_REGISTERS2 (); asm ("pushl $16"); -CALL_HOOK(); +CALL_HOOK (); /* For 13, 11, and 14 we have to deal with the CHECK_FAULT stuff. */ @@ -387,47 +401,47 @@ extern void _catchException13 (); asm (".text"); asm (".globl __catchException13"); asm ("__catchException13:"); -CHECK_FAULT(); -SAVE_REGISTERS1(); -SAVE_ERRCODE(); -SAVE_REGISTERS2(); +CHECK_FAULT (); +SAVE_REGISTERS1 (); +SAVE_ERRCODE (); +SAVE_REGISTERS2 (); asm ("pushl $13"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 11. */ extern void _catchException11 (); asm (".text"); asm (".globl __catchException11"); asm ("__catchException11:"); -CHECK_FAULT(); -SAVE_REGISTERS1(); -SAVE_ERRCODE(); -SAVE_REGISTERS2(); +CHECK_FAULT (); +SAVE_REGISTERS1 (); +SAVE_ERRCODE (); +SAVE_REGISTERS2 (); asm ("pushl $11"); -CALL_HOOK(); +CALL_HOOK (); /* Same thing for exception 14. */ extern void _catchException14 (); asm (".text"); asm (".globl __catchException14"); asm ("__catchException14:"); -CHECK_FAULT(); -SAVE_REGISTERS1(); -SAVE_ERRCODE(); -SAVE_REGISTERS2(); +CHECK_FAULT (); +SAVE_REGISTERS1 (); +SAVE_ERRCODE (); +SAVE_REGISTERS2 (); asm ("pushl $14"); -CALL_HOOK(); +CALL_HOOK (); /* * remcomHandler is a front end for handle_exception. It moves the * stack pointer into an area reserved for debugger use. */ -asm("_remcomHandler:"); -asm(" popl %eax"); /* pop off return address */ -asm(" popl %eax"); /* get the exception number */ -asm(" movl _stackPtr, %esp"); /* move to remcom stack area */ -asm(" pushl %eax"); /* push exception onto stack */ -asm(" call _handle_exception"); /* this never returns */ +asm ("_remcomHandler:"); +asm (" popl %eax"); /* pop off return address */ +asm (" popl %eax"); /* get the exception number */ +asm (" movl _stackPtr, %esp"); /* move to remcom stack area */ +asm (" pushl %eax"); /* push exception onto stack */ +asm (" call _handle_exception"); /* this never returns */ void _returnFromException () @@ -437,7 +451,7 @@ _returnFromException () int hex (ch) - char ch; +char ch; { if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10); @@ -498,15 +512,16 @@ getpacket (void) { if (remote_debug) { - fprintf (stderr, - "bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n", - checksum, xmitcsum, buffer); + fprintf ( + stderr, + "bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n", + checksum, xmitcsum, buffer); } - putDebugChar ('-'); /* failed checksum */ + putDebugChar ('-'); /* failed checksum */ } else { - putDebugChar ('+'); /* successful transfer */ + putDebugChar ('+'); /* successful transfer */ /* if a sequence char is present, reply the sequence ID */ if (buffer[2] == ':') @@ -549,15 +564,12 @@ putpacket (unsigned char *buffer) putDebugChar ('#'); putDebugChar (hexchars[checksum >> 4]); putDebugChar (hexchars[checksum % 16]); - } while (getDebugChar () != '+'); } -void -debug_error (format, parm) - char *format; - char *parm; +void debug_error (format, parm) char *format; +char *parm; { if (remote_debug) fprintf (stderr, format, parm); @@ -598,10 +610,10 @@ set_char (char *addr, int val) a fault; if zero treat a fault like any other fault in the stub. */ char * mem2hex (mem, buf, count, may_fault) - char *mem; - char *buf; - int count; - int may_fault; +char *mem; +char *buf; +int count; +int may_fault; { int i; unsigned char ch; @@ -626,10 +638,10 @@ mem2hex (mem, buf, count, may_fault) /* return a pointer to the character AFTER the last byte written */ char * hex2mem (buf, mem, count, may_fault) - char *buf; - char *mem; - int count; - int may_fault; +char *buf; +char *mem; +int count; +int may_fault; { int i; unsigned char ch; @@ -659,51 +671,51 @@ computeSignal (int exceptionVector) { case 0: sigval = 8; - break; /* divide by zero */ + break; /* divide by zero */ case 1: sigval = 5; - break; /* debug exception */ + break; /* debug exception */ case 3: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 4: sigval = 16; - break; /* into instruction (overflow) */ + break; /* into instruction (overflow) */ case 5: sigval = 16; - break; /* bound instruction */ + break; /* bound instruction */ case 6: sigval = 4; - break; /* Invalid opcode */ + break; /* Invalid opcode */ case 7: sigval = 8; - break; /* coprocessor not available */ + break; /* coprocessor not available */ case 8: sigval = 7; - break; /* double fault */ + break; /* double fault */ case 9: sigval = 11; - break; /* coprocessor segment overrun */ + break; /* coprocessor segment overrun */ case 10: sigval = 11; - break; /* Invalid TSS */ + break; /* Invalid TSS */ case 11: sigval = 11; - break; /* Segment not present */ + break; /* Segment not present */ case 12: sigval = 11; - break; /* stack exception */ + break; /* stack exception */ case 13: sigval = 11; - break; /* general protection */ + break; /* general protection */ case 14: sigval = 11; - break; /* page fault */ + break; /* page fault */ case 16: sigval = 7; - break; /* coprocessor error */ + break; /* coprocessor error */ default: - sigval = 7; /* "software generated" */ + sigval = 7; /* "software generated" */ } return (sigval); } @@ -752,8 +764,8 @@ handle_exception (int exceptionVector) if (remote_debug) { - printf ("vector=%d, sr=0x%x, pc=0x%x\n", - exceptionVector, registers[PS], registers[PC]); + printf ("vector=%d, sr=0x%x, pc=0x%x\n", exceptionVector, registers[PS], + registers[PC]); } /* reply to host that an exception has occurred */ @@ -761,28 +773,28 @@ handle_exception (int exceptionVector) ptr = remcomOutBuffer; - *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */ + *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */ *ptr++ = hexchars[sigval >> 4]; *ptr++ = hexchars[sigval & 0xf]; - *ptr++ = hexchars[ESP]; + *ptr++ = hexchars[ESP]; *ptr++ = ':'; - ptr = mem2hex((char *)®isters[ESP], ptr, 4, 0); /* SP */ + ptr = mem2hex ((char *) ®isters[ESP], ptr, 4, 0); /* SP */ *ptr++ = ';'; - *ptr++ = hexchars[EBP]; + *ptr++ = hexchars[EBP]; *ptr++ = ':'; - ptr = mem2hex((char *)®isters[EBP], ptr, 4, 0); /* FP */ + ptr = mem2hex ((char *) ®isters[EBP], ptr, 4, 0); /* FP */ *ptr++ = ';'; - *ptr++ = hexchars[PC]; + *ptr++ = hexchars[PC]; *ptr++ = ':'; - ptr = mem2hex((char *)®isters[PC], ptr, 4, 0); /* PC */ + ptr = mem2hex ((char *) ®isters[PC], ptr, 4, 0); /* PC */ *ptr++ = ';'; *ptr = '\0' - putpacket (remcomOutBuffer); + putpacket (remcomOutBuffer); stepping = 0; @@ -800,16 +812,16 @@ handle_exception (int exceptionVector) remcomOutBuffer[3] = 0; break; case 'd': - remote_debug = !(remote_debug); /* toggle debug flag */ + remote_debug = !(remote_debug); /* toggle debug flag */ break; - case 'g': /* return the value of the CPU registers */ + case 'g': /* return the value of the CPU registers */ mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES, 0); break; - case 'G': /* set the value of the CPU registers - return OK */ + case 'G': /* set the value of the CPU registers - return OK */ hex2mem (ptr, (char *) registers, NUMREGBYTES, 0); strcpy (remcomOutBuffer, "OK"); break; - case 'P': /* set the value of a single CPU register - return OK */ + case 'P': /* set the value of a single CPU register - return OK */ { int regno; @@ -895,18 +907,18 @@ handle_exception (int exceptionVector) if (stepping) registers[PS] |= 0x100; - _returnFromException (); /* this is a jump */ + _returnFromException (); /* this is a jump */ break; /* kill the program */ - case 'k': /* do nothing */ + case 'k': /* do nothing */ #if 0 /* Huh? This doesn't look like "nothing". m68k-stub.c and sparc-stub.c don't have it. */ BREAKPOINT (); #endif break; - } /* switch */ + } /* switch */ /* reply to the request */ putpacket (remcomOutBuffer); diff --git a/gdb/stubs/ia64vms-stub.c b/gdb/stubs/ia64vms-stub.c index 8e8132e..f983598 100644 --- a/gdb/stubs/ia64vms-stub.c +++ b/gdb/stubs/ia64vms-stub.c @@ -74,8 +74,8 @@ /* Declared in lib$ots. */ extern void ots$fill (void *addr, size_t len, unsigned char b); extern void ots$move (void *dst, size_t len, const void *src); -extern int ots$strcmp_eql (const void *str1, size_t str1len, - const void *str2, size_t str2len); +extern int ots$strcmp_eql (const void *str1, size_t str1len, const void *str2, + size_t str2len); /* Stub port number. */ static unsigned int serv_port = 1234; @@ -84,7 +84,7 @@ static unsigned int serv_port = 1234; struct dbgext_control_block { unsigned short dbgext$w_function_code; -#define DBGEXT$K_NEXT_TASK 3 +#define DBGEXT$K_NEXT_TASK 3 #define DBGEXT$K_STOP_ALL_OTHER_TASKS 31 #define DBGEXT$K_GET_REGS 33 unsigned short dbgext$w_facility_id; @@ -99,8 +99,8 @@ struct dbgext_control_block unsigned int dbgext$l_task_number; unsigned int dbgext$l_ada_flags; unsigned int dbgext$l_stop_value; -#define dbgext$l_priority dbgext$l_stop_value; -#define dbgext$l_symb_addr dbgext$l_stop_value; +#define dbgext$l_priority dbgext$l_stop_value; +#define dbgext$l_symb_addr dbgext$l_stop_value; #define dbgext$l_time_slice dbgext$l_stop_value; unsigned int dbgext$l_active_registers; }; @@ -130,28 +130,29 @@ struct debug_flag }; /* Macro to define a debugging flag. */ -#define DEBUG_FLAG_ENTRY(str) \ - { { sizeof (str) - 1, DSC$K_DTYPE_T, DSC$K_CLASS_S, str }, 0} +#define DEBUG_FLAG_ENTRY(str) \ + { \ + { sizeof (str) - 1, DSC$K_DTYPE_T, DSC$K_CLASS_S, str }, 0 \ + } -static struct debug_flag debug_flags[] = -{ +static struct debug_flag debug_flags[] = { /* Disp packets exchanged with gdb. */ - DEBUG_FLAG_ENTRY("packets"), + DEBUG_FLAG_ENTRY ("packets"), #define trace_pkt (debug_flags[0].val) /* Display entry point informations. */ - DEBUG_FLAG_ENTRY("entry"), + DEBUG_FLAG_ENTRY ("entry"), #define trace_entry (debug_flags[1].val) /* Be verbose about exceptions. */ - DEBUG_FLAG_ENTRY("excp"), + DEBUG_FLAG_ENTRY ("excp"), #define trace_excp (debug_flags[2].val) /* Be verbose about unwinding. */ - DEBUG_FLAG_ENTRY("unwind"), + DEBUG_FLAG_ENTRY ("unwind"), #define trace_unwind (debug_flags[3].val) /* Display image at startup. */ - DEBUG_FLAG_ENTRY("images"), + DEBUG_FLAG_ENTRY ("images"), #define trace_images (debug_flags[4].val) /* Display pthread_debug info. */ - DEBUG_FLAG_ENTRY("pthreaddbg") + DEBUG_FLAG_ENTRY ("pthreaddbg") #define trace_pthreaddbg (debug_flags[5].val) }; @@ -173,7 +174,7 @@ struct sockchar }; /* Chain of images loaded. */ -extern IMCB* ctl$gl_imglstptr; +extern IMCB *ctl$gl_imglstptr; /* IA64 integer register representation. */ union ia64_ireg @@ -183,74 +184,74 @@ union ia64_ireg }; /* IA64 register numbers, as defined by ia64-tdep.h. */ -#define IA64_GR0_REGNUM 0 -#define IA64_GR32_REGNUM (IA64_GR0_REGNUM + 32) +#define IA64_GR0_REGNUM 0 +#define IA64_GR32_REGNUM (IA64_GR0_REGNUM + 32) /* Floating point registers; 128 82-bit wide registers. */ -#define IA64_FR0_REGNUM 128 +#define IA64_FR0_REGNUM 128 /* Predicate registers; There are 64 of these one bit registers. It'd be more convenient (implementation-wise) to use a single 64 bit word with all of these register in them. Note that there's also a IA64_PR_REGNUM below which contains all the bits and is used for communicating the actual values to the target. */ -#define IA64_PR0_REGNUM 256 +#define IA64_PR0_REGNUM 256 /* Branch registers: 8 64-bit registers for holding branch targets. */ -#define IA64_BR0_REGNUM 320 +#define IA64_BR0_REGNUM 320 /* Virtual frame pointer; this matches IA64_FRAME_POINTER_REGNUM in gcc/config/ia64/ia64.h. */ -#define IA64_VFP_REGNUM 328 +#define IA64_VFP_REGNUM 328 /* Virtual return address pointer; this matches IA64_RETURN_ADDRESS_POINTER_REGNUM in gcc/config/ia64/ia64.h. */ -#define IA64_VRAP_REGNUM 329 +#define IA64_VRAP_REGNUM 329 /* Predicate registers: There are 64 of these 1-bit registers. We define a single register which is used to communicate these values to/from the target. We will somehow contrive to make it appear that IA64_PR0_REGNUM thru IA64_PR63_REGNUM hold the actual values. */ -#define IA64_PR_REGNUM 330 +#define IA64_PR_REGNUM 330 /* Instruction pointer: 64 bits wide. */ -#define IA64_IP_REGNUM 331 +#define IA64_IP_REGNUM 331 /* Process Status Register. */ -#define IA64_PSR_REGNUM 332 +#define IA64_PSR_REGNUM 332 /* Current Frame Marker (raw form may be the cr.ifs). */ -#define IA64_CFM_REGNUM 333 +#define IA64_CFM_REGNUM 333 /* Application registers; 128 64-bit wide registers possible, but some of them are reserved. */ -#define IA64_AR0_REGNUM 334 -#define IA64_KR0_REGNUM (IA64_AR0_REGNUM + 0) -#define IA64_KR7_REGNUM (IA64_KR0_REGNUM + 7) - -#define IA64_RSC_REGNUM (IA64_AR0_REGNUM + 16) -#define IA64_BSP_REGNUM (IA64_AR0_REGNUM + 17) -#define IA64_BSPSTORE_REGNUM (IA64_AR0_REGNUM + 18) -#define IA64_RNAT_REGNUM (IA64_AR0_REGNUM + 19) -#define IA64_FCR_REGNUM (IA64_AR0_REGNUM + 21) -#define IA64_EFLAG_REGNUM (IA64_AR0_REGNUM + 24) -#define IA64_CSD_REGNUM (IA64_AR0_REGNUM + 25) -#define IA64_SSD_REGNUM (IA64_AR0_REGNUM + 26) -#define IA64_CFLG_REGNUM (IA64_AR0_REGNUM + 27) -#define IA64_FSR_REGNUM (IA64_AR0_REGNUM + 28) -#define IA64_FIR_REGNUM (IA64_AR0_REGNUM + 29) -#define IA64_FDR_REGNUM (IA64_AR0_REGNUM + 30) -#define IA64_CCV_REGNUM (IA64_AR0_REGNUM + 32) -#define IA64_UNAT_REGNUM (IA64_AR0_REGNUM + 36) -#define IA64_FPSR_REGNUM (IA64_AR0_REGNUM + 40) -#define IA64_ITC_REGNUM (IA64_AR0_REGNUM + 44) -#define IA64_PFS_REGNUM (IA64_AR0_REGNUM + 64) -#define IA64_LC_REGNUM (IA64_AR0_REGNUM + 65) -#define IA64_EC_REGNUM (IA64_AR0_REGNUM + 66) +#define IA64_AR0_REGNUM 334 +#define IA64_KR0_REGNUM (IA64_AR0_REGNUM + 0) +#define IA64_KR7_REGNUM (IA64_KR0_REGNUM + 7) + +#define IA64_RSC_REGNUM (IA64_AR0_REGNUM + 16) +#define IA64_BSP_REGNUM (IA64_AR0_REGNUM + 17) +#define IA64_BSPSTORE_REGNUM (IA64_AR0_REGNUM + 18) +#define IA64_RNAT_REGNUM (IA64_AR0_REGNUM + 19) +#define IA64_FCR_REGNUM (IA64_AR0_REGNUM + 21) +#define IA64_EFLAG_REGNUM (IA64_AR0_REGNUM + 24) +#define IA64_CSD_REGNUM (IA64_AR0_REGNUM + 25) +#define IA64_SSD_REGNUM (IA64_AR0_REGNUM + 26) +#define IA64_CFLG_REGNUM (IA64_AR0_REGNUM + 27) +#define IA64_FSR_REGNUM (IA64_AR0_REGNUM + 28) +#define IA64_FIR_REGNUM (IA64_AR0_REGNUM + 29) +#define IA64_FDR_REGNUM (IA64_AR0_REGNUM + 30) +#define IA64_CCV_REGNUM (IA64_AR0_REGNUM + 32) +#define IA64_UNAT_REGNUM (IA64_AR0_REGNUM + 36) +#define IA64_FPSR_REGNUM (IA64_AR0_REGNUM + 40) +#define IA64_ITC_REGNUM (IA64_AR0_REGNUM + 44) +#define IA64_PFS_REGNUM (IA64_AR0_REGNUM + 64) +#define IA64_LC_REGNUM (IA64_AR0_REGNUM + 65) +#define IA64_EC_REGNUM (IA64_AR0_REGNUM + 66) /* NAT (Not A Thing) Bits for the general registers; there are 128 of these. */ -#define IA64_NAT0_REGNUM 462 +#define IA64_NAT0_REGNUM 462 /* Process registers when a condition is caught. */ struct ia64_all_regs @@ -295,14 +296,14 @@ term_raw_write (const char *str, unsigned int len) unsigned short status; struct _iosb iosb; - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - term_chan, /* I/O channel. */ - IO$_WRITEVBLK, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - (char *)str, /* P1 - buffer address. */ - len, /* P2 - buffer length. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + term_chan, /* I/O channel. */ + IO$_WRITEVBLK, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + (char *) str, /* P1 - buffer address. */ + len, /* P2 - buffer length. */ 0, 0, 0, 0); if (status & STS$M_SUCCESS) @@ -384,8 +385,8 @@ term_fao (const char *str, unsigned int str_len, ...) int i; __int64 *args; int status; - struct dsc$descriptor_s dstr = - { str_len, DSC$K_DTYPE_T, DSC$K_CLASS_S, (__char_ptr32)str }; + struct dsc$descriptor_s dstr + = { str_len, DSC$K_DTYPE_T, DSC$K_CLASS_S, (__char_ptr32) str }; char buf[128]; $DESCRIPTOR (buf_desc, buf); @@ -407,7 +408,7 @@ term_fao (const char *str, unsigned int str_len, ...) term_flush (); } } - + va_end (vargs); } @@ -426,7 +427,7 @@ term_putnl (void) static void term_init (void) { - unsigned int status,i; + unsigned int status, i; unsigned short len; char resstring[LNM$C_NAMLENGTH]; static const $DESCRIPTOR (tabdesc, "LNM$FILE_DEV"); @@ -442,11 +443,11 @@ term_init (void) item_lst[1].ile3$w_code = 0; /* Translate the logical name. */ - status = SYS$TRNLNM (0, /* Attr of the logical name. */ + status = SYS$TRNLNM (0, /* Attr of the logical name. */ (void *) &tabdesc, /* Logical name table. */ (void *) &logdesc, /* Logical name. */ - 0, /* Access mode. */ - item_lst); /* Item list. */ + 0, /* Access mode. */ + item_lst); /* Item list. */ if (!(status & STS$M_SUCCESS)) LIB$SIGNAL (status); @@ -460,9 +461,9 @@ term_init (void) } /* Assign a channel. */ - status = sys$assign (&term_desc, /* Device name. */ - &term_chan, /* I/O channel. */ - 0, /* Access mode. */ + status = sys$assign (&term_desc, /* Device name. */ + &term_chan, /* I/O channel. */ + 0, /* Access mode. */ 0); if (!(status & STS$M_SUCCESS)) LIB$SIGNAL (status); @@ -508,7 +509,7 @@ sock_init (void) /* Initialize socket characteristics. */ listen_sockchar.prot = TCPIP$C_TCP; listen_sockchar.type = TCPIP$C_STREAM; - listen_sockchar.af = TCPIP$C_AF_INET; + listen_sockchar.af = TCPIP$C_AF_INET; /* Assign I/O channels to network device. */ status = sys$assign ((void *) &inet_device, &listen_channel, 0, 0); @@ -521,13 +522,13 @@ sock_init (void) } /* Create a listen socket. */ - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - listen_channel, /* I/O channel. */ - IO$_SETMODE, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - &listen_sockchar, /* P1 - socket characteristics. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + listen_channel, /* I/O channel. */ + IO$_SETMODE, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + &listen_sockchar, /* P1 - socket characteristics. */ 0, 0, 0, 0, 0); if (status & STS$M_SUCCESS) status = iosb.iosb$w_status; @@ -539,25 +540,25 @@ sock_init (void) /* Set reuse address option. */ /* Initialize reuseaddr's item-list element. */ - reuseaddr_itemlst.ile2$w_length = sizeof (optval); - reuseaddr_itemlst.ile2$w_code = TCPIP$C_REUSEADDR; + reuseaddr_itemlst.ile2$w_length = sizeof (optval); + reuseaddr_itemlst.ile2$w_code = TCPIP$C_REUSEADDR; reuseaddr_itemlst.ile2$ps_bufaddr = &optval; /* Initialize setsockopt's item-list descriptor. */ - sockopt_itemlst.ile2$w_length = sizeof (reuseaddr_itemlst); - sockopt_itemlst.ile2$w_code = TCPIP$C_SOCKOPT; + sockopt_itemlst.ile2$w_length = sizeof (reuseaddr_itemlst); + sockopt_itemlst.ile2$w_code = TCPIP$C_SOCKOPT; sockopt_itemlst.ile2$ps_bufaddr = &reuseaddr_itemlst; - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - listen_channel, /* I/O channel. */ - IO$_SETMODE, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - 0, /* P1. */ - 0, /* P2. */ - 0, /* P3. */ - 0, /* P4. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + listen_channel, /* I/O channel. */ + IO$_SETMODE, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + 0, /* P1. */ + 0, /* P2. */ + 0, /* P3. */ + 0, /* P4. */ (__int64) &sockopt_itemlst, /* P5 - socket options. */ 0); if (status & STS$M_SUCCESS) @@ -576,18 +577,18 @@ sock_init (void) serv_addr.sin_addr.s_addr = TCPIP$C_INADDR_ANY; /* Initialize server's item-list descriptor. */ - serv_itemlst.ile2$w_length = sizeof (serv_addr); - serv_itemlst.ile2$w_code = TCPIP$C_SOCK_NAME; + serv_itemlst.ile2$w_length = sizeof (serv_addr); + serv_itemlst.ile2$w_code = TCPIP$C_SOCK_NAME; serv_itemlst.ile2$ps_bufaddr = &serv_addr; - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - listen_channel, /* I/O channel. */ - IO$_SETMODE, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - 0, /* P1. */ - 0, /* P2. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + listen_channel, /* I/O channel. */ + IO$_SETMODE, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + 0, /* P1. */ + 0, /* P2. */ (__int64) &serv_itemlst, /* P3 - local socket name. */ 0, 0, 0); if (status & STS$M_SUCCESS) @@ -599,16 +600,16 @@ sock_init (void) } /* Set socket as a listen socket. */ - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - listen_channel, /* I/O channel. */ - IO$_SETMODE, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - 0, /* P1. */ - 0, /* P2. */ - 0, /* P3. */ - 1, /* P4 - connection backlog. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + listen_channel, /* I/O channel. */ + IO$_SETMODE, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + 0, /* P1. */ + 0, /* P2. */ + 0, /* P3. */ + 1, /* P4 - connection backlog. */ 0, 0); if (status & STS$M_SUCCESS) status = iosb.iosb$w_status; @@ -622,15 +623,15 @@ sock_init (void) TERM_FAO ("Waiting for a client connection on port: !ZW!/", wordswap (serv_addr.sin_port)); - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - listen_channel, /* I/O channel. */ - IO$_ACCESS|IO$M_ACCEPT, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - 0, /* P1. */ - 0, /* P2. */ - 0, /* P3. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + listen_channel, /* I/O channel. */ + IO$_ACCESS | IO$M_ACCEPT, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + 0, /* P1. */ + 0, /* P2. */ + 0, /* P3. */ (__int64) &conn_channel, /* P4 - I/O channel for conn. */ 0, 0); @@ -647,17 +648,17 @@ sock_init (void) cli_itemlst.ile3$w_code = TCPIP$C_SOCK_NAME; cli_itemlst.ile3$ps_bufaddr = &cli_addr; cli_itemlst.ile3$ps_retlen_addr = &cli_addrlen; - ots$fill (&cli_addr, sizeof(cli_addr), 0); - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - conn_channel, /* I/O channel. */ - IO$_SENSEMODE, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - 0, /* P1. */ - 0, /* P2. */ - 0, /* P3. */ - (__int64) &cli_itemlst, /* P4 - peer socket name. */ + ots$fill (&cli_addr, sizeof (cli_addr), 0); + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + conn_channel, /* I/O channel. */ + IO$_SENSEMODE, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + 0, /* P1. */ + 0, /* P2. */ + 0, /* P3. */ + (__int64) &cli_itemlst, /* P4 - peer socket name. */ 0, 0); if (status & STS$M_SUCCESS) status = iosb.iosb$w_status; @@ -684,12 +685,12 @@ sock_close (void) unsigned int status; /* Close socket. */ - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - conn_channel, /* I/O channel. */ - IO$_DEACCESS, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + conn_channel, /* I/O channel. */ + IO$_DEACCESS, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ 0, 0, 0, 0, 0, 0); if (status & STS$M_SUCCESS) @@ -720,8 +721,8 @@ page_set_rw (unsigned __int64 startva, unsigned __int64 len, unsigned __int64 retva; unsigned __int64 retlen; - status = SYS$SETPRT_64 ((void *)startva, len, PSL$C_USER, PRT$C_UW, - (void *)&retva, &retlen, oldprot); + status = SYS$SETPRT_64 ((void *) startva, len, PSL$C_USER, PRT$C_UW, + (void *) &retva, &retlen, oldprot); return status; } @@ -729,15 +730,15 @@ page_set_rw (unsigned __int64 startva, unsigned __int64 len, static void page_restore_rw (unsigned __int64 startva, unsigned __int64 len, - unsigned int prot) + unsigned int prot) { unsigned int status; unsigned __int64 retva; unsigned __int64 retlen; unsigned int oldprot; - status = SYS$SETPRT_64 ((void *)startva, len, PSL$C_USER, prot, - (void *)&retva, &retlen, &oldprot); + status = SYS$SETPRT_64 ((void *) startva, len, PSL$C_USER, prot, + (void *) &retva, &retlen, &oldprot); if (!(status & STS$M_SUCCESS)) LIB$SIGNAL (status); } @@ -747,7 +748,7 @@ page_restore_rw (unsigned __int64 startva, unsigned __int64 len, static pthread_t get_teb (void) { - return (pthread_t)__getReg (_IA64_REG_TP); + return (pthread_t) __getReg (_IA64_REG_TP); } /* Enable thread scheduling if VAL is true. */ @@ -768,8 +769,8 @@ set_thread_scheduling (int val) status = dbgext_func (&blk); if (!(status & STS$M_SUCCESS)) { - TERM_FAO ("set_thread_scheduling error, val=!SL, status=!XL!/", - val, blk.dbgext$l_status); + TERM_FAO ("set_thread_scheduling error, val=!SL, status=!XL!/", val, + blk.dbgext$l_status); lib$signal (status); } @@ -802,10 +803,8 @@ thread_next (unsigned int thr) /* Pthread Debug callbacks. */ static int -read_callback (pthreadDebugClient_t context, - pthreadDebugTargetAddr_t addr, - pthreadDebugAddr_t buf, - size_t size) +read_callback (pthreadDebugClient_t context, pthreadDebugTargetAddr_t addr, + pthreadDebugAddr_t buf, size_t size) { if (trace_pthreaddbg) TERM_FAO ("read_callback (!XH, !XH, !SL)!/", addr, buf, size); @@ -814,10 +813,8 @@ read_callback (pthreadDebugClient_t context, } static int -write_callback (pthreadDebugClient_t context, - pthreadDebugTargetAddr_t addr, - pthreadDebugLongConstAddr_t buf, - size_t size) +write_callback (pthreadDebugClient_t context, pthreadDebugTargetAddr_t addr, + pthreadDebugLongConstAddr_t buf, size_t size) { if (trace_pthreaddbg) TERM_FAO ("write_callback (!XH, !XH, !SL)!/", addr, buf, size); @@ -840,8 +837,7 @@ resume_callback (pthreadDebugClient_t context) } static int -kthdinfo_callback (pthreadDebugClient_t context, - pthreadDebugKId_t kid, +kthdinfo_callback (pthreadDebugClient_t context, pthreadDebugKId_t kid, pthreadDebugKThreadInfo_p thread_info) { if (trace_pthreaddbg) @@ -850,8 +846,7 @@ kthdinfo_callback (pthreadDebugClient_t context, } static int -hold_callback (pthreadDebugClient_t context, - pthreadDebugKId_t kid) +hold_callback (pthreadDebugClient_t context, pthreadDebugKId_t kid) { if (trace_pthreaddbg) term_puts ("hold_callback"); @@ -859,8 +854,7 @@ hold_callback (pthreadDebugClient_t context, } static int -unhold_callback (pthreadDebugClient_t context, - pthreadDebugKId_t kid) +unhold_callback (pthreadDebugClient_t context, pthreadDebugKId_t kid) { if (trace_pthreaddbg) term_puts ("unhold_callback"); @@ -868,8 +862,7 @@ unhold_callback (pthreadDebugClient_t context, } static int -getfreg_callback (pthreadDebugClient_t context, - pthreadDebugFregs_t *reg, +getfreg_callback (pthreadDebugClient_t context, pthreadDebugFregs_t *reg, pthreadDebugKId_t kid) { if (trace_pthreaddbg) @@ -878,8 +871,7 @@ getfreg_callback (pthreadDebugClient_t context, } static int -setfreg_callback (pthreadDebugClient_t context, - const pthreadDebugFregs_t *reg, +setfreg_callback (pthreadDebugClient_t context, const pthreadDebugFregs_t *reg, pthreadDebugKId_t kid) { if (trace_pthreaddbg) @@ -888,8 +880,7 @@ setfreg_callback (pthreadDebugClient_t context, } static int -getreg_callback (pthreadDebugClient_t context, - pthreadDebugRegs_t *reg, +getreg_callback (pthreadDebugClient_t context, pthreadDebugRegs_t *reg, pthreadDebugKId_t kid) { if (trace_pthreaddbg) @@ -898,8 +889,7 @@ getreg_callback (pthreadDebugClient_t context, } static int -setreg_callback (pthreadDebugClient_t context, - const pthreadDebugRegs_t *reg, +setreg_callback (pthreadDebugClient_t context, const pthreadDebugRegs_t *reg, pthreadDebugKId_t kid) { if (trace_pthreaddbg) @@ -908,8 +898,7 @@ setreg_callback (pthreadDebugClient_t context, } static int -output_callback (pthreadDebugClient_t context, - pthreadDebugConstString_t line) +output_callback (pthreadDebugClient_t context, pthreadDebugConstString_t line) { term_puts (line); term_putnl (); @@ -917,8 +906,7 @@ output_callback (pthreadDebugClient_t context, } static int -error_callback (pthreadDebugClient_t context, - pthreadDebugConstString_t line) +error_callback (pthreadDebugClient_t context, pthreadDebugConstString_t line) { term_puts (line); term_putnl (); @@ -938,8 +926,8 @@ malloc_callback (pthreadDebugClient_t caller_context, size_t size) LIB$SIGNAL (status); if (trace_pthreaddbg) TERM_FAO ("malloc_callback (!UL) -> !XA!/", size, res); - *(unsigned int *)res = len; - return (char *)res + 16; + *(unsigned int *) res = len; + return (char *) res + 16; } static void @@ -949,8 +937,8 @@ free_callback (pthreadDebugClient_t caller_context, pthreadDebugAddr_t address) unsigned int res; int len; - res = (unsigned int)address - 16; - len = *(unsigned int *)res; + res = (unsigned int) address - 16; + len = *(unsigned int *) res; if (trace_pthreaddbg) TERM_FAO ("free_callback (!XA)!/", address); status = lib$free_vm (&len, &res, 0); @@ -966,25 +954,13 @@ speckthd_callback (pthreadDebugClient_t caller_context, return ENOTSUP; } -static pthreadDebugCallbacks_t pthread_debug_callbacks = { - PTHREAD_DEBUG_VERSION, - read_callback, - write_callback, - suspend_callback, - resume_callback, - kthdinfo_callback, - hold_callback, - unhold_callback, - getfreg_callback, - setfreg_callback, - getreg_callback, - setreg_callback, - output_callback, - error_callback, - malloc_callback, - free_callback, - speckthd_callback -}; +static pthreadDebugCallbacks_t pthread_debug_callbacks + = { PTHREAD_DEBUG_VERSION, read_callback, write_callback, + suspend_callback, resume_callback, kthdinfo_callback, + hold_callback, unhold_callback, getfreg_callback, + setfreg_callback, getreg_callback, setreg_callback, + output_callback, error_callback, malloc_callback, + free_callback, speckthd_callback }; /* Name of the pthread shared library. */ static const $DESCRIPTOR (pthread_rtl_desc, "PTHREAD$RTL"); @@ -997,18 +973,20 @@ struct pthread_debug_entry __void_ptr32 func; }; -#define DEBUG_ENTRY(str) { sizeof(str) - 1, str, 0 } - -static struct pthread_debug_entry pthread_debug_entries[] = { - DEBUG_ENTRY("pthreadDebugContextInit"), - DEBUG_ENTRY("pthreadDebugThdSeqInit"), - DEBUG_ENTRY("pthreadDebugThdSeqNext"), - DEBUG_ENTRY("pthreadDebugThdSeqDestroy"), - DEBUG_ENTRY("pthreadDebugThdGetInfo"), - DEBUG_ENTRY("pthreadDebugThdGetInfoAddr"), - DEBUG_ENTRY("pthreadDebugThdGetReg"), - DEBUG_ENTRY("pthreadDebugCmd") -}; +#define DEBUG_ENTRY(str) \ + { \ + sizeof (str) - 1, str, 0 \ + } + +static struct pthread_debug_entry pthread_debug_entries[] + = { DEBUG_ENTRY ("pthreadDebugContextInit"), + DEBUG_ENTRY ("pthreadDebugThdSeqInit"), + DEBUG_ENTRY ("pthreadDebugThdSeqNext"), + DEBUG_ENTRY ("pthreadDebugThdSeqDestroy"), + DEBUG_ENTRY ("pthreadDebugThdGetInfo"), + DEBUG_ENTRY ("pthreadDebugThdGetInfoAddr"), + DEBUG_ENTRY ("pthreadDebugThdGetReg"), + DEBUG_ENTRY ("pthreadDebugCmd") }; /* Pthread debug context. */ static pthreadDebugContext_t debug_context; @@ -1018,53 +996,47 @@ static pthreadDebugContext_t debug_context; static int pthread_debug_thd_seq_init (pthreadDebugId_t *id) { - return ((int (*)())pthread_debug_entries[1].func) - (debug_context, id); + return ((int (*) ()) pthread_debug_entries[1].func) (debug_context, id); } static int pthread_debug_thd_seq_next (pthreadDebugId_t *id) { - return ((int (*)())pthread_debug_entries[2].func) - (debug_context, id); + return ((int (*) ()) pthread_debug_entries[2].func) (debug_context, id); } static int pthread_debug_thd_seq_destroy (void) { - return ((int (*)())pthread_debug_entries[3].func) - (debug_context); + return ((int (*) ()) pthread_debug_entries[3].func) (debug_context); } static int pthread_debug_thd_get_info (pthreadDebugId_t id, pthreadDebugThreadInfo_t *info) { - return ((int (*)())pthread_debug_entries[4].func) - (debug_context, id, info); + return ((int (*) ()) pthread_debug_entries[4].func) (debug_context, id, + info); } static int -pthread_debug_thd_get_info_addr (pthread_t thr, - pthreadDebugThreadInfo_t *info) +pthread_debug_thd_get_info_addr (pthread_t thr, pthreadDebugThreadInfo_t *info) { - return ((int (*)())pthread_debug_entries[5].func) - (debug_context, thr, info); + return ((int (*) ()) pthread_debug_entries[5].func) (debug_context, thr, + info); } static int -pthread_debug_thd_get_reg (pthreadDebugId_t thr, - pthreadDebugRegs_t *regs) +pthread_debug_thd_get_reg (pthreadDebugId_t thr, pthreadDebugRegs_t *regs) { - return ((int (*)())pthread_debug_entries[6].func) - (debug_context, thr, regs); + return ((int (*) ()) pthread_debug_entries[6].func) (debug_context, thr, + regs); } static int stub_pthread_debug_cmd (const char *cmd) { - return ((int (*)())pthread_debug_entries[7].func) - (debug_context, cmd); + return ((int (*) ()) pthread_debug_entries[7].func) (debug_context, cmd); } /* Show all the threads. */ @@ -1109,15 +1081,14 @@ threads_init (void) int i; void *caller_context = 0; - status = lib$find_image_symbol - ((void *) &pthread_rtl_desc, (void *) &dbgext_desc, - (int *) &dbgext_func); + status = lib$find_image_symbol ((void *) &pthread_rtl_desc, + (void *) &dbgext_desc, (int *) &dbgext_func); if (!(status & STS$M_SUCCESS)) LIB$SIGNAL (status); - - status = lib$find_image_symbol - ((void *) &pthread_rtl_desc, (void *) &dbgsymtable_desc, - (int *) &dbg_symtable); + + status = lib$find_image_symbol ((void *) &pthread_rtl_desc, + (void *) &dbgsymtable_desc, + (int *) &dbg_symtable); if (!(status & STS$M_SUCCESS)) LIB$SIGNAL (status); @@ -1126,21 +1097,20 @@ threads_init (void) i < sizeof (pthread_debug_entries) / sizeof (pthread_debug_entries[0]); i++) { - struct dsc$descriptor_s sym = - { pthread_debug_entries[i].namelen, - DSC$K_DTYPE_T, DSC$K_CLASS_S, - pthread_debug_entries[i].name }; - status = lib$find_image_symbol - ((void *) &pthread_debug_desc, (void *) &sym, - (int *) &pthread_debug_entries[i].func); + struct dsc$descriptor_s sym + = { pthread_debug_entries[i].namelen, DSC$K_DTYPE_T, DSC$K_CLASS_S, + pthread_debug_entries[i].name }; + status + = lib$find_image_symbol ((void *) &pthread_debug_desc, (void *) &sym, + (int *) &pthread_debug_entries[i].func); if (!(status & STS$M_SUCCESS)) lib$signal (status); } if (trace_pthreaddbg) TERM_FAO ("debug symtable: !XH!/", dbg_symtable); - status = ((int (*)()) pthread_debug_entries[0].func) - (&caller_context, &pthread_debug_callbacks, dbg_symtable, &debug_context); + status = ((int (*) ()) pthread_debug_entries[0].func) ( + &caller_context, &pthread_debug_callbacks, dbg_symtable, &debug_context); if (status != 0) TERM_FAO ("cannot initialize pthread_debug: !UL!/", status); TERM_FAO ("pthread debug done!/", 0); @@ -1341,16 +1311,18 @@ handle_q_packet (const unsigned char *pkt, unsigned int pktlen) return; } else if (pktlen > XFER_UIB_LEN - && ots$strcmp_eql (pkt, XFER_UIB_LEN, xfer_uib, XFER_UIB_LEN)) + && ots$strcmp_eql (pkt, XFER_UIB_LEN, xfer_uib, XFER_UIB_LEN)) { /* Get unwind information block. */ unsigned __int64 pc; unsigned int pos = XFER_UIB_LEN; unsigned int off; unsigned int len; + union { unsigned char bytes[32]; + struct { unsigned __int64 code_start_va; @@ -1359,6 +1331,7 @@ handle_q_packet (const unsigned char *pkt, unsigned int pktlen) unsigned __int64 gp_value; } data; } uei; + int res; int i; @@ -1392,8 +1365,8 @@ handle_q_packet (const unsigned char *pkt, unsigned int pktlen) mem2bin (uei.bytes, sizeof (uei.bytes)); } else if (pktlen == QFTHREADINFO_LEN - && ots$strcmp_eql (pkt, QFTHREADINFO_LEN, - qfthreadinfo, QFTHREADINFO_LEN)) + && ots$strcmp_eql (pkt, QFTHREADINFO_LEN, qfthreadinfo, + QFTHREADINFO_LEN)) { /* Get first thread(s). */ gdb_buf[0] = '$'; @@ -1410,8 +1383,8 @@ handle_q_packet (const unsigned char *pkt, unsigned int pktlen) long2pkt (first_thread); } else if (pktlen == QSTHREADINFO_LEN - && ots$strcmp_eql (pkt, QSTHREADINFO_LEN, - qsthreadinfo, QSTHREADINFO_LEN)) + && ots$strcmp_eql (pkt, QSTHREADINFO_LEN, qsthreadinfo, + QSTHREADINFO_LEN)) { /* Get subsequent threads. */ gdb_buf[0] = '$'; @@ -1435,8 +1408,8 @@ handle_q_packet (const unsigned char *pkt, unsigned int pktlen) gdb_buf[1] = 'l'; } else if (pktlen > QTHREADEXTRAINFO_LEN - && ots$strcmp_eql (pkt, QTHREADEXTRAINFO_LEN, - qthreadextrainfo, QTHREADEXTRAINFO_LEN)) + && ots$strcmp_eql (pkt, QTHREADEXTRAINFO_LEN, qthreadextrainfo, + QTHREADEXTRAINFO_LEN)) { /* Get extra info about a thread. */ pthread_t thr; @@ -1459,18 +1432,17 @@ handle_q_packet (const unsigned char *pkt, unsigned int pktlen) } gdb_buf[0] = '$'; gdb_blen = 1; - mem2hex ((const unsigned char *)"VMS-thread", 11); + mem2hex ((const unsigned char *) "VMS-thread", 11); } else if (pktlen > QSUPPORTED_LEN - && ots$strcmp_eql (pkt, QSUPPORTED_LEN, - qsupported, QSUPPORTED_LEN)) + && ots$strcmp_eql (pkt, QSUPPORTED_LEN, qsupported, QSUPPORTED_LEN)) { /* Get supported features. */ pthread_t thr; unsigned int pos = QSUPPORTED_LEN; pthreadDebugThreadInfo_t info; int res; - + /* Ignore gdb features. */ gdb_buf[0] = '$'; gdb_blen = 1; @@ -1483,7 +1455,7 @@ handle_q_packet (const unsigned char *pkt, unsigned int pktlen) if (trace_pkt) { term_puts ("unknown <: "); - term_write ((char *)pkt, pktlen); + term_write ((char *) pkt, pktlen); term_putnl (); } return; @@ -1512,7 +1484,7 @@ handle_v_packet (const unsigned char *pkt, unsigned int pktlen) if (trace_pkt) { term_puts ("unknown <: "); - term_write ((char *)pkt, pktlen); + term_write ((char *) pkt, pktlen); term_putnl (); } return 0; @@ -1601,7 +1573,7 @@ handle_packet (unsigned char *pkt, unsigned int len) if (len == 1) { /* Clear psr.ss. */ - excp_regs.psr.v &= ~(unsigned __int64)PSR$M_SS; + excp_regs.psr.v &= ~(unsigned __int64) PSR$M_SS; return 1; } else @@ -1626,7 +1598,7 @@ handle_packet (unsigned char *pkt, unsigned int len) int res; unsigned __int64 val; pthreadDebugThreadInfo_t info; - + pos++; val = pkt2val (pkt, &pos); if (pos != len) @@ -1715,7 +1687,7 @@ handle_packet (unsigned char *pkt, unsigned int len) /* Transfer. */ for (i = 0; i < l; i++) - byte2hex (gdb_buf + 1 + 2 * i, ((unsigned char *)addr)[i]); + byte2hex (gdb_buf + 1 + 2 * i, ((unsigned char *) addr)[i]); gdb_blen += 2 * l; } break; @@ -1764,7 +1736,7 @@ handle_packet (unsigned char *pkt, unsigned int len) { int v = hex2byte (pkt + pos); pos += 2; - ((unsigned char *)addr)[i] = v; + ((unsigned char *) addr)[i] = v; } /* Sync caches. */ @@ -1826,7 +1798,7 @@ handle_packet (unsigned char *pkt, unsigned int len) if (len == 1) { /* Set psr.ss. */ - excp_regs.psr.v |= (unsigned __int64)PSR$M_SS; + excp_regs.psr.v |= (unsigned __int64) PSR$M_SS; return 1; } else @@ -1844,7 +1816,7 @@ handle_packet (unsigned char *pkt, unsigned int len) int res; unsigned __int64 val; unsigned int fthr, thr; - + val = pkt2val (pkt, &pos); /* Default is error (but only after parsing is complete). */ packet_error (0); @@ -1878,7 +1850,7 @@ handle_packet (unsigned char *pkt, unsigned int len) if (has_threads) { pkt[len] = 0; - stub_pthread_debug_cmd ((char *)pkt + 4); + stub_pthread_debug_cmd ((char *) pkt + 4); packet_ok (); } else @@ -1889,7 +1861,7 @@ handle_packet (unsigned char *pkt, unsigned int len) if (trace_pkt) { term_puts ("unknown <: "); - term_write ((char *)pkt, len); + term_write ((char *) pkt, len); term_putnl (); } break; @@ -1906,14 +1878,14 @@ sock_write (const unsigned char *buf, int len) unsigned int status; /* Write data to connection. */ - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - conn_channel, /* I/O channel. */ - IO$_WRITEVBLK, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - (char *)buf, /* P1 - buffer address. */ - len, /* P2 - buffer length. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + conn_channel, /* I/O channel. */ + IO$_WRITEVBLK, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + (char *) buf, /* P1 - buffer address. */ + len, /* P2 - buffer length. */ 0, 0, 0, 0); if (status & STS$M_SUCCESS) status = iosb.iosb$w_status; @@ -1943,7 +1915,7 @@ send_pkt (void) if (trace_pkt > 1) { term_puts (">: "); - term_write ((char *)gdb_buf, gdb_blen + 3); + term_write ((char *) gdb_buf, gdb_blen + 3); term_putnl (); } } @@ -1968,26 +1940,26 @@ one_command (void) while (1) { /* Read data from connection. */ - status = sys$qiow (EFN$C_ENF, /* Event flag. */ - conn_channel, /* I/O channel. */ - IO$_READVBLK, /* I/O function code. */ - &iosb, /* I/O status block. */ - 0, /* Ast service routine. */ - 0, /* Ast parameter. */ - gdb_buf + off, /* P1 - buffer address. */ + status = sys$qiow (EFN$C_ENF, /* Event flag. */ + conn_channel, /* I/O channel. */ + IO$_READVBLK, /* I/O function code. */ + &iosb, /* I/O status block. */ + 0, /* Ast service routine. */ + 0, /* Ast parameter. */ + gdb_buf + off, /* P1 - buffer address. */ sizeof (gdb_buf) - off, /* P2 - buffer leng. */ 0, 0, 0, 0); if (status & STS$M_SUCCESS) status = iosb.iosb$w_status; if (!(status & STS$M_SUCCESS)) { - term_puts ("Failed to read data from connection\n" ); + term_puts ("Failed to read data from connection\n"); LIB$SIGNAL (status); } #ifdef RAW_DUMP term_puts ("{: "); - term_write ((char *)gdb_buf + off, iosb.iosb$w_bcnt); + term_write ((char *) gdb_buf + off, iosb.iosb$w_bcnt); term_putnl (); #endif @@ -2006,8 +1978,7 @@ one_command (void) continue; } /* Search for '#'. */ - for (sharp_off = dollar_off + 1; - sharp_off < gdb_blen; + for (sharp_off = dollar_off + 1; sharp_off < gdb_blen; sharp_off++) if (gdb_buf[sharp_off] == '#') break; @@ -2048,7 +2019,7 @@ one_command (void) } else { - sock_write ((const unsigned char *)"+", 1); + sock_write ((const unsigned char *) "+", 1); break; } } @@ -2057,14 +2028,15 @@ one_command (void) if (trace_pkt > 1) { term_puts ("<: "); - term_write ((char *)gdb_buf + dollar_off, sharp_off - dollar_off + 1); + term_write ((char *) gdb_buf + dollar_off, sharp_off - dollar_off + 1); term_putnl (); } cmd_off = dollar_off + 1; cmd_len = sharp_off - dollar_off - 1; - if (handle_packet (gdb_buf + dollar_off + 1, sharp_off - dollar_off - 1) == 1) + if (handle_packet (gdb_buf + dollar_off + 1, sharp_off - dollar_off - 1) + == 1) return 1; send_pkt (); @@ -2087,8 +2059,8 @@ display_excp (struct chf64$signal_array *sig64, struct chf$mech_array *mech) { char msg2[160]; unsigned short msg2len; - struct dsc$descriptor_s msg2_desc = - { sizeof (msg2), DSC$K_DTYPE_T, DSC$K_CLASS_S, msg2}; + struct dsc$descriptor_s msg2_desc + = { sizeof (msg2), DSC$K_DTYPE_T, DSC$K_CLASS_S, msg2 }; msg_desc.dsc$w_length = msglen; status = SYS$FAOL_64 (&msg_desc, &msg2len, &msg2_desc, &sig64->chf64$q_sig_arg1); @@ -2101,9 +2073,8 @@ display_excp (struct chf64$signal_array *sig64, struct chf$mech_array *mech) if (trace_excp > 1) { - TERM_FAO (" Frame: !XH, Depth: !4SL, Esf: !XH!/", - mech->chf$q_mch_frame, mech->chf$q_mch_depth, - mech->chf$q_mch_esf_addr); + TERM_FAO (" Frame: !XH, Depth: !4SL, Esf: !XH!/", mech->chf$q_mch_frame, + mech->chf$q_mch_depth, mech->chf$q_mch_esf_addr); } } @@ -2112,10 +2083,9 @@ display_excp (struct chf64$signal_array *sig64, struct chf$mech_array *mech) static void read_all_registers (struct chf$mech_array *mech) { - struct _intstk *intstk = - (struct _intstk *)mech->chf$q_mch_esf_addr; - struct chf64$signal_array *sig64 = - (struct chf64$signal_array *)mech->chf$ph_mch_sig64_addr; + struct _intstk *intstk = (struct _intstk *) mech->chf$q_mch_esf_addr; + struct chf64$signal_array *sig64 + = (struct chf64$signal_array *) mech->chf$ph_mch_sig64_addr; unsigned int cnt = sig64->chf64$w_sig_arg_count; unsigned __int64 pc = (&sig64->chf64$q_sig_name)[cnt - 2]; @@ -2144,7 +2114,7 @@ read_all_registers (struct chf$mech_array *mech) excp_regs.gr[9].v = intstk->intstk$q_r9; excp_regs.gr[10].v = intstk->intstk$q_r10; excp_regs.gr[11].v = intstk->intstk$q_r11; - excp_regs.gr[12].v = (unsigned __int64)intstk + intstk->intstk$l_stkalign; + excp_regs.gr[12].v = (unsigned __int64) intstk + intstk->intstk$l_stkalign; excp_regs.gr[13].v = intstk->intstk$q_r13; excp_regs.gr[14].v = intstk->intstk$q_r14; excp_regs.gr[15].v = intstk->intstk$q_r15; @@ -2179,8 +2149,7 @@ read_all_registers (struct chf$mech_array *mech) static void write_all_registers (struct chf$mech_array *mech) { - struct _intstk *intstk = - (struct _intstk *)mech->chf$q_mch_esf_addr; + struct _intstk *intstk = (struct _intstk *) mech->chf$q_mch_esf_addr; intstk->intstk$q_ipsr = excp_regs.psr.v; } @@ -2190,8 +2159,7 @@ write_all_registers (struct chf$mech_array *mech) static void do_debug (struct chf$mech_array *mech) { - struct _intstk *intstk = - (struct _intstk *)mech->chf$q_mch_esf_addr; + struct _intstk *intstk = (struct _intstk *) mech->chf$q_mch_esf_addr; unsigned int old_ast; unsigned int old_sch; unsigned int status; @@ -2239,11 +2207,10 @@ do_debug (struct chf$mech_array *mech) /* The condition handler. That's the core of the stub. */ static int -excp_handler (struct chf$signal_array *sig, - struct chf$mech_array *mech) +excp_handler (struct chf$signal_array *sig, struct chf$mech_array *mech) { - struct chf64$signal_array *sig64 = - (struct chf64$signal_array *)mech->chf$ph_mch_sig64_addr; + struct chf64$signal_array *sig64 + = (struct chf64$signal_array *) mech->chf$ph_mch_sig64_addr; unsigned int code = sig->chf$l_sig_name & STS$M_COND_ID; unsigned int cnt = sig64->chf64$w_sig_arg_count; unsigned __int64 pc; @@ -2254,7 +2221,7 @@ excp_handler (struct chf$signal_array *sig, /* Completely ignore some conditions (signaled indirectly by this stub). */ switch (code) { - case LIB$_KEYNOTFOU & STS$M_COND_ID: + case LIB$_KEYNOTFOU &STS$M_COND_ID: return SS$_RESIGNAL_64; default: break; @@ -2275,9 +2242,7 @@ excp_handler (struct chf$signal_array *sig, TERM_FAO ("excp_handler: code: !XL, pc=!XH!/", code, pc); /* If break on the entry point, restore the bundle. */ - if (code == (SS$_BREAK & STS$M_COND_ID) - && pc == entry_pc - && entry_pc != 0) + if (code == (SS$_BREAK & STS$M_COND_ID) && pc == entry_pc && entry_pc != 0) { static unsigned int entry_prot; @@ -2285,32 +2250,31 @@ excp_handler (struct chf$signal_array *sig, term_puts ("initial entry breakpoint\n"); page_set_rw (entry_pc, 16, &entry_prot); - ots$move ((void *)entry_pc, 16, entry_saved); + ots$move ((void *) entry_pc, 16, entry_saved); __fc (entry_pc); page_restore_rw (entry_pc, 16, entry_prot); } switch (code) { - case SS$_ACCVIO & STS$M_COND_ID: + case SS$_ACCVIO &STS$M_COND_ID: if (trace_excp <= 1) display_excp (sig64, mech); /* Fall through. */ - case SS$_BREAK & STS$M_COND_ID: - case SS$_OPCDEC & STS$M_COND_ID: - case SS$_TBIT & STS$M_COND_ID: - case SS$_DEBUG & STS$M_COND_ID: + case SS$_BREAK &STS$M_COND_ID: + case SS$_OPCDEC &STS$M_COND_ID: + case SS$_TBIT &STS$M_COND_ID: + case SS$_DEBUG &STS$M_COND_ID: if (trace_excp > 1) { int i; - struct _intstk *intstk = - (struct _intstk *)mech->chf$q_mch_esf_addr; + struct _intstk *intstk = (struct _intstk *) mech->chf$q_mch_esf_addr; display_excp (sig64, mech); TERM_FAO (" intstk: !XH!/", intstk); for (i = 0; i < cnt + 1; i++) - TERM_FAO (" !XH!/", ((unsigned __int64 *)sig64)[i]); + TERM_FAO (" !XH!/", ((unsigned __int64 *) sig64)[i]); } do_debug (mech); ret = SS$_CONTINUE_64; @@ -2349,11 +2313,11 @@ trace_init (void) item_lst[1].ile3$w_code = 0; /* Translate the logical name. */ - status = SYS$TRNLNM (0, /* Attributes of the logical name. */ - (void *)&tabdesc, /* Logical name table. */ - (void *)&logdesc, /* Logical name. */ - 0, /* Access mode. */ - &item_lst); /* Item list. */ + status = SYS$TRNLNM (0, /* Attributes of the logical name. */ + (void *) &tabdesc, /* Logical name table. */ + (void *) &logdesc, /* Logical name. */ + 0, /* Access mode. */ + &item_lst); /* Item list. */ if (status == SS$_NOLOGNAM) return; if (!(status & STS$M_SUCCESS)) @@ -2371,8 +2335,9 @@ trace_init (void) sub_desc.dsc$w_length = i - start; for (j = 0; j < NBR_DEBUG_FLAGS; j++) - if (str$case_blind_compare (&sub_desc, - (void *)&debug_flags[j].name) == 0) + if (str$case_blind_compare (&sub_desc, + (void *) &debug_flags[j].name) + == 0) { debug_flags[j].val++; break; @@ -2391,13 +2356,11 @@ trace_init (void) term_putnl (); } - /* Entry point. */ static int -stub_start (unsigned __int64 *progxfer, void *cli_util, - EIHD *imghdr, IFD *imgfile, - unsigned int linkflag, unsigned int cliflag) +stub_start (unsigned __int64 *progxfer, void *cli_util, EIHD *imghdr, + IFD *imgfile, unsigned int linkflag, unsigned int cliflag) { static int initialized; int i; @@ -2423,8 +2386,8 @@ stub_start (unsigned __int64 *progxfer, void *cli_util, if (trace_entry && !is_attached) { - TERM_FAO ("xfer: !XH, imghdr: !XH, ifd: !XH!/", - progxfer, imghdr, imgfile); + TERM_FAO ("xfer: !XH, imghdr: !XH, ifd: !XH!/", progxfer, imghdr, + imgfile); for (i = -2; i < 8; i++) TERM_FAO (" at !2SW: !XH!/", i, progxfer[i]); } @@ -2444,15 +2407,14 @@ stub_start (unsigned __int64 *progxfer, void *cli_util, return 0; } else - TERM_FAO ("Entry: !XH!/",entry_pc); + TERM_FAO ("Entry: !XH!/", entry_pc); } } else entry_pc = progxfer[0]; has_threads = 0; - for (imcb = ctl$gl_imglstptr->imcb$l_flink; - imcb != ctl$gl_imglstptr; + for (imcb = ctl$gl_imglstptr->imcb$l_flink; imcb != ctl$gl_imglstptr; imcb = imcb->imcb$l_flink) { if (ots$strcmp_eql (pthread_rtl_desc.dsc$a_pointer, @@ -2460,15 +2422,14 @@ stub_start (unsigned __int64 *progxfer, void *cli_util, imcb->imcb$t_log_image_name + 1, imcb->imcb$t_log_image_name[0])) has_threads = 1; - + if (trace_images) { unsigned int j; LDRIMG *ldrimg = imcb->imcb$l_ldrimg; LDRISD *ldrisd; - TERM_FAO ("!XA-!XA ", - imcb->imcb$l_starting_address, + TERM_FAO ("!XA-!XA ", imcb->imcb$l_starting_address, imcb->imcb$l_end_address); switch (imcb->imcb$b_act_code) @@ -2485,8 +2446,7 @@ stub_start (unsigned __int64 *progxfer, void *cli_util, default: term_puts ("????"); } - TERM_FAO (" !AD !40AC!/", - 1, "KESU" + (imcb->imcb$b_access_mode & 3), + TERM_FAO (" !AD !40AC!/", 1, "KESU" + (imcb->imcb$b_access_mode & 3), imcb->imcb$t_log_image_name); if ((long) ldrimg < 0 || trace_images < 2) @@ -2502,17 +2462,15 @@ stub_start (unsigned __int64 *progxfer, void *cli_util, term_puts (flags & 0x01000000 ? " Prot" : " "); term_puts (flags & 0x04000000 ? " Shrt" : " "); term_puts (flags & 0x08000000 ? " Shrd" : " "); - TERM_FAO (" !XA-!XA!/", - ldrisd[j].ldrisd$p_base, - (unsigned __int64) ldrisd[j].ldrisd$p_base - + ldrisd[j].ldrisd$i_len - 1); + TERM_FAO (" !XA-!XA!/", ldrisd[j].ldrisd$p_base, + (unsigned __int64) ldrisd[j].ldrisd$p_base + + ldrisd[j].ldrisd$i_len - 1); } ldrisd = ldrimg->ldrimg$l_dyn_seg; if (ldrisd) - TERM_FAO (" dynamic !XA-!XA!/", - ldrisd->ldrisd$p_base, - (unsigned __int64) ldrisd->ldrisd$p_base - + ldrisd->ldrisd$i_len - 1); + TERM_FAO (" dynamic !XA-!XA!/", ldrisd->ldrisd$p_base, + (unsigned __int64) ldrisd->ldrisd$p_base + + ldrisd->ldrisd$i_len - 1); } } @@ -2543,13 +2501,12 @@ stub_start (unsigned __int64 *progxfer, void *cli_util, 00 00 00 02 00 00 nop.i 0x0 00 00 04 00 nop.i 0x0;; */ - static const unsigned char initbp[16] = - { 0x01, 0x08, 0x00, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x04, 0x00 }; + static const unsigned char initbp[16] + = { 0x01, 0x08, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00 }; unsigned int entry_prot; unsigned int status; - + status = page_set_rw (entry_pc, 16, &entry_prot); if (!(status & STS$M_SUCCESS)) @@ -2564,11 +2521,11 @@ stub_start (unsigned __int64 *progxfer, void *cli_util, else LIB$SIGNAL (status); } - + if (entry_pc != 0) { - ots$move (entry_saved, 16, (void *)entry_pc); - ots$move ((void *)entry_pc, 16, (void *)initbp); + ots$move (entry_saved, 16, (void *) entry_pc); + ots$move ((void *) entry_pc, 16, (void *) initbp); __fc (entry_pc); page_restore_rw (entry_pc, 16, entry_prot); } @@ -2597,5 +2554,5 @@ struct xfer_vector #pragma __extern_model save #pragma __extern_model strict_refdef "XFER_PSECT" -struct xfer_vector xfer_vector = {0, 0, stub_start}; +struct xfer_vector xfer_vector = { 0, 0, stub_start }; #pragma __extern_model restore diff --git a/gdb/stubs/m32r-stub.c b/gdb/stubs/m32r-stub.c index e52188e..bbe05ab 100644 --- a/gdb/stubs/m32r-stub.c +++ b/gdb/stubs/m32r-stub.c @@ -91,14 +91,13 @@ * ****************************************************************************/ - /************************************************************************ * * external low-level support routines */ -extern void putDebugChar (); /* write a single character */ -extern int getDebugChar (); /* read and return a single char */ -extern void exceptionHandler (); /* assign an exception handler */ +extern void putDebugChar (); /* write a single character */ +extern int getDebugChar (); /* read and return a single char */ +extern void exceptionHandler (); /* assign an exception handler */ /***************************************************************************** * BUFMAX defines the maximum number of characters in inbound/outbound buffers @@ -106,7 +105,7 @@ extern void exceptionHandler (); /* assign an exception handler */ */ #define BUFMAX 400 -static char initialized; /* boolean flag. != 0 means we've been initialized */ +static char initialized; /* boolean flag. != 0 means we've been initialized */ int remote_debug; /* debug > 0 prints ill-formed commands in valid packets & checksum errors */ @@ -117,10 +116,33 @@ static const unsigned char hexchars[] = "0123456789abcdef"; /* Number of bytes of registers. */ #define NUMREGBYTES (NUMREGS * 4) + enum regnames -{ R0, R1, R2, R3, R4, R5, R6, R7, - R8, R9, R10, R11, R12, R13, R14, R15, - PSW, CBR, SPI, SPU, BPC, PC, ACCL, ACCH +{ + R0, + R1, + R2, + R3, + R4, + R5, + R6, + R7, + R8, + R9, + R10, + R11, + R12, + R13, + R14, + R15, + PSW, + CBR, + SPI, + SPU, + BPC, + PC, + ACCL, + ACCH }; enum SYS_calls @@ -158,7 +180,7 @@ static unsigned char remcomOutBuffer[BUFMAX]; static int remcomStack[STACKSIZE / sizeof (int)]; static int *stackPtr = &remcomStack[STACKSIZE / sizeof (int) - 1]; -static unsigned int save_vectors[18]; /* previous exception vectors */ +static unsigned int save_vectors[18]; /* previous exception vectors */ /* Indicate to caller of mem2hex or hex2mem that there has been an error. */ static volatile int mem_err = 0; @@ -168,7 +190,7 @@ static volatile int mem_err = 0; int gdb_m32r_vector = -1; #if 0 -#include "syscall.h" /* for SYS_exit, SYS_write etc. */ +#include "syscall.h" /* for SYS_exit, SYS_write etc. */ #endif /* Global entry points: @@ -215,7 +237,7 @@ handle_exception (int exceptionVector) int binary; if (!finish_from_step ()) - return; /* "false step": let the target continue */ + return; /* "false step": let the target continue */ gdb_m32r_vector = exceptionVector; @@ -232,30 +254,30 @@ handle_exception (int exceptionVector) ptr = remcomOutBuffer; - *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */ + *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */ *ptr++ = hexchars[sigval >> 4]; *ptr++ = hexchars[sigval & 0xf]; *ptr++ = hexchars[PC >> 4]; *ptr++ = hexchars[PC & 0xf]; *ptr++ = ':'; - ptr = mem2hex ((unsigned char *) ®isters[PC], ptr, 4, 0); /* PC */ + ptr = mem2hex ((unsigned char *) ®isters[PC], ptr, 4, 0); /* PC */ *ptr++ = ';'; *ptr++ = hexchars[R13 >> 4]; *ptr++ = hexchars[R13 & 0xf]; *ptr++ = ':'; - ptr = mem2hex ((unsigned char *) ®isters[R13], ptr, 4, 0); /* FP */ + ptr = mem2hex ((unsigned char *) ®isters[R13], ptr, 4, 0); /* FP */ *ptr++ = ';'; *ptr++ = hexchars[R15 >> 4]; *ptr++ = hexchars[R15 & 0xf]; *ptr++ = ':'; - ptr = mem2hex ((unsigned char *) ®isters[R15], ptr, 4, 0); /* SP */ + ptr = mem2hex ((unsigned char *) ®isters[R15], ptr, 4, 0); /* SP */ *ptr++ = ';'; *ptr++ = 0; - if (exceptionVector == 0) /* simulated SYS call stuff */ + if (exceptionVector == 0) /* simulated SYS call stuff */ { mem2hex ((unsigned char *) ®isters[PC], buf, 4, 0); switch (registers[R0]) @@ -279,11 +301,11 @@ handle_exception (int exceptionVector) gdb_error ("Target attempts SYS_read call at %s\n", buf); break; case SYS_write: - if (registers[R1] == 1 || /* write to stdout */ - registers[R1] == 2) /* write to stderr */ - { /* (we can do that) */ - registers[R0] = - gdb_write ((void *) registers[R2], registers[R3]); + if (registers[R1] == 1 || /* write to stdout */ + registers[R1] == 2) /* write to stderr */ + { /* (we can do that) */ + registers[R0] + = gdb_write ((void *) registers[R2], registers[R3]); return; } else @@ -321,7 +343,7 @@ handle_exception (int exceptionVector) binary = 0; switch (*ptr++) { - default: /* Unknown code. Return an empty reply message. */ + default: /* Unknown code. Return an empty reply message. */ break; case 'R': if (hexToInt (&ptr, &addr)) @@ -331,9 +353,9 @@ handle_exception (int exceptionVector) case '!': strcpy (remcomOutBuffer, "OK"); break; - case 'X': /* XAA..AA,LLLL:<binary data>#cs */ + case 'X': /* XAA..AA,LLLL:<binary data>#cs */ binary = 1; - case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ + case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */ { if (hexToInt (&ptr, &addr)) @@ -363,7 +385,7 @@ handle_exception (int exceptionVector) } } break; - case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ + case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ if (hexToInt (&ptr, &addr)) if (*(ptr++) == ',') @@ -371,8 +393,7 @@ handle_exception (int exceptionVector) { ptr = 0; mem_err = 0; - mem2hex ((unsigned char *) addr, remcomOutBuffer, length, - 1); + mem2hex ((unsigned char *) addr, remcomOutBuffer, length, 1); if (mem_err) { strcpy (remcomOutBuffer, "E03"); @@ -391,13 +412,13 @@ handle_exception (int exceptionVector) remcomOutBuffer[3] = 0; break; case 'd': - remote_debug = !(remote_debug); /* toggle debug flag */ + remote_debug = !(remote_debug); /* toggle debug flag */ break; - case 'g': /* return the value of the CPU registers */ + case 'g': /* return the value of the CPU registers */ mem2hex ((unsigned char *) registers, remcomOutBuffer, NUMREGBYTES, 0); break; - case 'P': /* set the value of a single CPU register - return OK */ + case 'P': /* set the value of a single CPU register - return OK */ { int regno; @@ -412,28 +433,30 @@ handle_exception (int exceptionVector) * make sure to keep the several stack pointers consistant. */ stackmode = registers[PSW] & 0x80; - if (regno == R15) /* stack pointer changed */ - { /* need to change SPI or SPU */ + if (regno == R15) /* stack pointer changed */ + { /* need to change SPI or SPU */ if (stackmode == 0) registers[SPI] = registers[R15]; else registers[SPU] = registers[R15]; } - else if (regno == SPU) /* "user" stack pointer changed */ + else if (regno == SPU) /* "user" stack pointer changed */ { - if (stackmode != 0) /* stack in user mode: copy SP */ + if (stackmode != 0) /* stack in user mode: copy SP */ registers[R15] = registers[SPU]; } - else if (regno == SPI) /* "interrupt" stack pointer changed */ + else if (regno + == SPI) /* "interrupt" stack pointer changed */ { - if (stackmode == 0) /* stack in interrupt mode: copy SP */ + if (stackmode + == 0) /* stack in interrupt mode: copy SP */ registers[R15] = registers[SPI]; } - else if (regno == PSW) /* stack mode may have changed! */ - { /* force SP to either SPU or SPI */ - if (stackmode == 0) /* stack in user mode */ + else if (regno == PSW) /* stack mode may have changed! */ + { /* force SP to either SPU or SPI */ + if (stackmode == 0) /* stack in user mode */ registers[R15] = registers[SPI]; - else /* stack in interrupt mode */ + else /* stack in interrupt mode */ registers[R15] = registers[SPU]; } strcpy (remcomOutBuffer, "OK"); @@ -442,53 +465,51 @@ handle_exception (int exceptionVector) strcpy (remcomOutBuffer, "E01"); break; } - case 'G': /* set the value of the CPU registers - return OK */ + case 'G': /* set the value of the CPU registers - return OK */ hex2mem (ptr, (unsigned char *) registers, NUMREGBYTES, 0); strcpy (remcomOutBuffer, "OK"); break; - case 's': /* sAA..AA Step one instruction from AA..AA(optional) */ + case 's': /* sAA..AA Step one instruction from AA..AA(optional) */ stepping = 1; - case 'c': /* cAA..AA Continue from address AA..AA(optional) */ + case 'c': /* cAA..AA Continue from address AA..AA(optional) */ /* try to read optional parameter, pc unchanged if no parm */ if (hexToInt (&ptr, &addr)) registers[PC] = addr; - if (stepping) /* single-stepping */ + if (stepping) /* single-stepping */ { - if (!prepare_to_step (0)) /* set up for single-step */ + if (!prepare_to_step (0)) /* set up for single-step */ { /* prepare_to_step has already emulated the target insn: Send SIGTRAP to gdb, don't resume the target at all. */ ptr = remcomOutBuffer; - *ptr++ = 'T'; /* Simulate stopping with SIGTRAP */ + *ptr++ = 'T'; /* Simulate stopping with SIGTRAP */ *ptr++ = '0'; *ptr++ = '5'; - *ptr++ = hexchars[PC >> 4]; /* send PC */ + *ptr++ = hexchars[PC >> 4]; /* send PC */ *ptr++ = hexchars[PC & 0xf]; *ptr++ = ':'; ptr = mem2hex ((unsigned char *) ®isters[PC], ptr, 4, 0); *ptr++ = ';'; - *ptr++ = hexchars[R13 >> 4]; /* send FP */ + *ptr++ = hexchars[R13 >> 4]; /* send FP */ *ptr++ = hexchars[R13 & 0xf]; *ptr++ = ':'; - ptr = - mem2hex ((unsigned char *) ®isters[R13], ptr, 4, 0); + ptr = mem2hex ((unsigned char *) ®isters[R13], ptr, 4, 0); *ptr++ = ';'; - *ptr++ = hexchars[R15 >> 4]; /* send SP */ + *ptr++ = hexchars[R15 >> 4]; /* send SP */ *ptr++ = hexchars[R15 & 0xf]; *ptr++ = ':'; - ptr = - mem2hex ((unsigned char *) ®isters[R15], ptr, 4, 0); + ptr = mem2hex ((unsigned char *) ®isters[R15], ptr, 4, 0); *ptr++ = ';'; *ptr++ = 0; break; } } - else /* continuing, not single-stepping */ + else /* continuing, not single-stepping */ { /* OK, about to do a "continue". First check to see if the target pc is on an odd boundary (second instruction in the @@ -500,7 +521,7 @@ handle_exception (int exceptionVector) return; - case 'D': /* Detach */ + case 'D': /* Detach */ #if 0 /* I am interpreting this to mean, release the board from control by the remote stub. To do this, I am restoring the original @@ -515,25 +536,24 @@ handle_exception (int exceptionVector) break; #endif case 'q': - if (*ptr++ == 'C' && - *ptr++ == 'R' && *ptr++ == 'C' && *ptr++ == ':') + if (*ptr++ == 'C' && *ptr++ == 'R' && *ptr++ == 'C' && *ptr++ == ':') { unsigned long start, len, our_crc; - if (hexToInt (&ptr, (int *) &start) && - *ptr++ == ',' && hexToInt (&ptr, (int *) &len)) + if (hexToInt (&ptr, (int *) &start) && *ptr++ == ',' + && hexToInt (&ptr, (int *) &len)) { remcomOutBuffer[0] = 'C'; our_crc = crc32 ((unsigned char *) start, len, 0xffffffff); - mem2hex ((char *) &our_crc, - &remcomOutBuffer[1], sizeof (long), 0); - } /* else do nothing */ - } /* else do nothing */ + mem2hex ((char *) &our_crc, &remcomOutBuffer[1], + sizeof (long), 0); + } /* else do nothing */ + } /* else do nothing */ break; - case 'k': /* kill the program */ + case 'k': /* kill the program */ continue; - } /* switch */ + } /* switch */ /* reply to the request */ putpacket (remcomOutBuffer); @@ -637,11 +657,11 @@ getpacket (void) gdb_error ("sent count = %s\n", buf); gdb_error (" -- Bad buffer: \"%s\"\n", buffer); } - putDebugChar ('-'); /* failed checksum */ + putDebugChar ('-'); /* failed checksum */ } else { - putDebugChar ('+'); /* successful transfer */ + putDebugChar ('+'); /* successful transfer */ /* if a sequence char is present, reply the sequence ID */ if (buffer[2] == ':') @@ -705,19 +725,19 @@ set_mem_err (void) static int mem_safe (unsigned char *addr) { -#define BAD_RANGE_ONE_START ((unsigned char *) 0x600000) -#define BAD_RANGE_ONE_END ((unsigned char *) 0xa00000) -#define BAD_RANGE_TWO_START ((unsigned char *) 0xff680000) -#define BAD_RANGE_TWO_END ((unsigned char *) 0xff800000) +#define BAD_RANGE_ONE_START ((unsigned char *) 0x600000) +#define BAD_RANGE_ONE_END ((unsigned char *) 0xa00000) +#define BAD_RANGE_TWO_START ((unsigned char *) 0xff680000) +#define BAD_RANGE_TWO_END ((unsigned char *) 0xff800000) if (addr < BAD_RANGE_ONE_START) - return 1; /* safe */ + return 1; /* safe */ if (addr < BAD_RANGE_ONE_END) - return 0; /* unsafe */ + return 0; /* unsafe */ if (addr < BAD_RANGE_TWO_START) - return 1; /* safe */ + return 1; /* safe */ if (addr < BAD_RANGE_TWO_END) - return 0; /* unsafe */ + return 0; /* unsafe */ } /* These are separate functions so that they are so short and sweet @@ -822,9 +842,9 @@ bin2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault) { switch (*(buf + 1)) { - case 0x3: /* # */ - case 0x4: /* $ */ - case 0x5d: /* escape char */ + case 0x3: /* # */ + case 0x4: /* $ */ + case 0x5d: /* escape char */ buf++; *buf |= 0x20; break; @@ -856,61 +876,61 @@ computeSignal (int exceptionVector) { case 0: sigval = 23; - break; /* I/O trap */ + break; /* I/O trap */ case 1: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 2: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 3: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 4: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 5: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 6: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 7: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 8: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 9: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 10: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 11: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 12: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 13: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 14: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 15: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ case 16: sigval = 10; - break; /* BUS ERROR (alignment) */ + break; /* BUS ERROR (alignment) */ case 17: sigval = 2; - break; /* INTerrupt */ + break; /* INTerrupt */ default: sigval = 7; - break; /* "software generated" */ + break; /* "software generated" */ } return (sigval); } @@ -968,18 +988,18 @@ hexToInt (unsigned char **ptr, int *intValue) static int isShortBranch (unsigned char *instr) { - unsigned char instr0 = instr[0] & 0x7F; /* mask off high bit */ + unsigned char instr0 = instr[0] & 0x7F; /* mask off high bit */ - if (instr0 == 0x10 && instr[1] == 0xB6) /* RTE */ - return 1; /* return from trap or exception */ + if (instr0 == 0x10 && instr[1] == 0xB6) /* RTE */ + return 1; /* return from trap or exception */ - if (instr0 == 0x1E || instr0 == 0x1F) /* JL or JMP */ + if (instr0 == 0x1E || instr0 == 0x1F) /* JL or JMP */ if ((instr[1] & 0xF0) == 0xC0) - return 2; /* jump thru a register */ + return 2; /* jump thru a register */ - if (instr0 == 0x7C || instr0 == 0x7D || /* BC, BNC, BL, BRA */ + if (instr0 == 0x7C || instr0 == 0x7D || /* BC, BNC, BL, BRA */ instr0 == 0x7E || instr0 == 0x7F) - return 3; /* eight bit PC offset */ + return 3; /* eight bit PC offset */ return 0; } @@ -987,18 +1007,18 @@ isShortBranch (unsigned char *instr) static int isLongBranch (unsigned char *instr) { - if (instr[0] == 0xFC || instr[0] == 0xFD || /* BRA, BNC, BL, BC */ - instr[0] == 0xFE || instr[0] == 0xFF) /* 24 bit relative */ + if (instr[0] == 0xFC || instr[0] == 0xFD || /* BRA, BNC, BL, BC */ + instr[0] == 0xFE || instr[0] == 0xFF) /* 24 bit relative */ return 4; - if ((instr[0] & 0xF0) == 0xB0) /* 16 bit relative */ + if ((instr[0] & 0xF0) == 0xB0) /* 16 bit relative */ { - if ((instr[1] & 0xF0) == 0x00 || /* BNE, BEQ */ + if ((instr[1] & 0xF0) == 0x00 || /* BNE, BEQ */ (instr[1] & 0xF0) == 0x10) return 5; - if (instr[0] == 0xB0) /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ, BEQZ */ - if ((instr[1] & 0xF0) == 0x80 || (instr[1] & 0xF0) == 0x90 || - (instr[1] & 0xF0) == 0xA0 || (instr[1] & 0xF0) == 0xB0 || - (instr[1] & 0xF0) == 0xC0 || (instr[1] & 0xF0) == 0xD0) + if (instr[0] == 0xB0) /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ, BEQZ */ + if ((instr[1] & 0xF0) == 0x80 || (instr[1] & 0xF0) == 0x90 + || (instr[1] & 0xF0) == 0xA0 || (instr[1] & 0xF0) == 0xB0 + || (instr[1] & 0xF0) == 0xC0 || (instr[1] & 0xF0) == 0xD0) return 6; } return 0; @@ -1008,7 +1028,7 @@ isLongBranch (unsigned char *instr) then it's a 2-byte instruction, else it's a 4-byte instruction. */ #define INSTRUCTION_SIZE(addr) \ - ((((int) addr & 2) || (((unsigned char *) addr)[0] & 0x80) == 0) ? 2 : 4) + ((((int) addr & 2) || (((unsigned char *) addr)[0] & 0x80) == 0) ? 2 : 4) static int isBranch (unsigned char *instr) @@ -1025,54 +1045,54 @@ willBranch (unsigned char *instr, int branchCode) switch (branchCode) { case 0: - return 0; /* not a branch */ + return 0; /* not a branch */ case 1: - return 1; /* RTE */ + return 1; /* RTE */ case 2: - return 1; /* JL or JMP */ - case 3: /* BC, BNC, BL, BRA (short) */ - case 4: /* BC, BNC, BL, BRA (long) */ + return 1; /* JL or JMP */ + case 3: /* BC, BNC, BL, BRA (short) */ + case 4: /* BC, BNC, BL, BRA (long) */ switch (instr[0] & 0x0F) { - case 0xC: /* Branch if Condition Register */ + case 0xC: /* Branch if Condition Register */ return (registers[CBR] != 0); - case 0xD: /* Branch if NOT Condition Register */ + case 0xD: /* Branch if NOT Condition Register */ return (registers[CBR] == 0); - case 0xE: /* Branch and Link */ - case 0xF: /* Branch (unconditional) */ + case 0xE: /* Branch and Link */ + case 0xF: /* Branch (unconditional) */ return 1; - default: /* oops? */ + default: /* oops? */ return 0; } - case 5: /* BNE, BEQ */ + case 5: /* BNE, BEQ */ switch (instr[1] & 0xF0) { - case 0x00: /* Branch if r1 equal to r2 */ + case 0x00: /* Branch if r1 equal to r2 */ return (registers[instr[0] & 0x0F] == registers[instr[1] & 0x0F]); - case 0x10: /* Branch if r1 NOT equal to r2 */ + case 0x10: /* Branch if r1 NOT equal to r2 */ return (registers[instr[0] & 0x0F] != registers[instr[1] & 0x0F]); - default: /* oops? */ + default: /* oops? */ return 0; } - case 6: /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ ,BEQZ */ + case 6: /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ ,BEQZ */ switch (instr[1] & 0xF0) { - case 0x80: /* Branch if reg equal to zero */ + case 0x80: /* Branch if reg equal to zero */ return (registers[instr[1] & 0x0F] == 0); - case 0x90: /* Branch if reg NOT equal to zero */ + case 0x90: /* Branch if reg NOT equal to zero */ return (registers[instr[1] & 0x0F] != 0); - case 0xA0: /* Branch if reg less than zero */ + case 0xA0: /* Branch if reg less than zero */ return (registers[instr[1] & 0x0F] < 0); - case 0xB0: /* Branch if reg greater or equal to zero */ + case 0xB0: /* Branch if reg greater or equal to zero */ return (registers[instr[1] & 0x0F] >= 0); - case 0xC0: /* Branch if reg less than or equal to zero */ + case 0xC0: /* Branch if reg less than or equal to zero */ return (registers[instr[1] & 0x0F] <= 0); - case 0xD0: /* Branch if reg greater than zero */ + case 0xD0: /* Branch if reg greater than zero */ return (registers[instr[1] & 0x0F] > 0); - default: /* oops? */ + default: /* oops? */ return 0; } - default: /* oops? */ + default: /* oops? */ return 0; } } @@ -1083,20 +1103,20 @@ branchDestination (unsigned char *instr, int branchCode) switch (branchCode) { default: - case 0: /* not a branch */ + case 0: /* not a branch */ return 0; - case 1: /* RTE */ - return registers[BPC] & ~3; /* pop BPC into PC */ - case 2: /* JL or JMP */ - return registers[instr[1] & 0x0F] & ~3; /* jump thru a register */ - case 3: /* BC, BNC, BL, BRA (short, 8-bit relative offset) */ + case 1: /* RTE */ + return registers[BPC] & ~3; /* pop BPC into PC */ + case 2: /* JL or JMP */ + return registers[instr[1] & 0x0F] & ~3; /* jump thru a register */ + case 3: /* BC, BNC, BL, BRA (short, 8-bit relative offset) */ return (((int) instr) & ~3) + ((char) instr[1] << 2); - case 4: /* BC, BNC, BL, BRA (long, 24-bit relative offset) */ - return ((int) instr + - ((((char) instr[1] << 16) | (instr[2] << 8) | (instr[3])) << - 2)); - case 5: /* BNE, BEQ (16-bit relative offset) */ - case 6: /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ ,BEQZ (ditto) */ + case 4: /* BC, BNC, BL, BRA (long, 24-bit relative offset) */ + return ((int) instr + + ((((char) instr[1] << 16) | (instr[2] << 8) | (instr[3])) + << 2)); + case 5: /* BNE, BEQ (16-bit relative offset) */ + case 6: /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ ,BEQZ (ditto) */ return ((int) instr + ((((char) instr[2] << 8) | (instr[3])) << 2)); } @@ -1115,31 +1135,31 @@ branchSideEffects (unsigned char *instr, int branchCode) { switch (branchCode) { - case 1: /* RTE */ - return; /* I <THINK> this is already handled... */ - case 2: /* JL (or JMP) */ - case 3: /* BL (or BC, BNC, BRA) */ + case 1: /* RTE */ + return; /* I <THINK> this is already handled... */ + case 2: /* JL (or JMP) */ + case 3: /* BL (or BC, BNC, BRA) */ case 4: - if ((instr[0] & 0x0F) == 0x0E) /* branch/jump and link */ + if ((instr[0] & 0x0F) == 0x0E) /* branch/jump and link */ registers[R14] = (registers[PC] & ~3) + 4; return; - default: /* any other branch has no side effects */ + default: /* any other branch has no side effects */ return; } } static struct STEPPING_CONTEXT { - int stepping; /* true when we've started a single-step */ - unsigned long target_addr; /* the instr we're trying to execute */ - unsigned long target_size; /* the size of the target instr */ - unsigned long noop_addr; /* where we've inserted a no-op, if any */ - unsigned long trap1_addr; /* the trap following the target instr */ - unsigned long trap2_addr; /* the trap at a branch destination, if any */ - unsigned short noop_save; /* instruction overwritten by our no-op */ - unsigned short trap1_save; /* instruction overwritten by trap1 */ - unsigned short trap2_save; /* instruction overwritten by trap2 */ - unsigned short continue_p; /* true if NOT returning to gdb after step */ + int stepping; /* true when we've started a single-step */ + unsigned long target_addr; /* the instr we're trying to execute */ + unsigned long target_size; /* the size of the target instr */ + unsigned long noop_addr; /* where we've inserted a no-op, if any */ + unsigned long trap1_addr; /* the trap following the target instr */ + unsigned long trap2_addr; /* the trap at a branch destination, if any */ + unsigned short noop_save; /* instruction overwritten by our no-op */ + unsigned short trap1_save; /* instruction overwritten by trap1 */ + unsigned short trap2_save; /* instruction overwritten by trap2 */ + unsigned short continue_p; /* true if NOT returning to gdb after step */ } stepping; /* Function: prepare_to_step @@ -1153,15 +1173,15 @@ static struct STEPPING_CONTEXT in which case we simply report to GDB that the instruction has already been executed. */ -#define TRAP1 0x10f1; /* trap #1 instruction */ -#define NOOP 0x7000; /* noop instruction */ +#define TRAP1 0x10f1; /* trap #1 instruction */ +#define NOOP 0x7000; /* noop instruction */ static unsigned short trap1 = TRAP1; static unsigned short noop = NOOP; static int prepare_to_step (continue_p) - int continue_p; /* if this isn't REALLY a single-step (see below) */ +int continue_p; /* if this isn't REALLY a single-step (see below) */ { unsigned long pc = registers[PC]; int branchCode = isBranch ((unsigned char *) pc); @@ -1173,16 +1193,16 @@ prepare_to_step (continue_p) p < ((unsigned char *) &stepping) + sizeof (stepping); p++) *p = 0; - if (branchCode != 0) /* next instruction is a branch */ + if (branchCode != 0) /* next instruction is a branch */ { branchSideEffects ((unsigned char *) pc, branchCode); if (willBranch ((unsigned char *) pc, branchCode)) registers[PC] = branchDestination ((unsigned char *) pc, branchCode); else registers[PC] = pc + INSTRUCTION_SIZE (pc); - return 0; /* branch "executed" -- just notify GDB */ + return 0; /* branch "executed" -- just notify GDB */ } - else if (((int) pc & 2) != 0) /* "second-slot" instruction */ + else if (((int) pc & 2) != 0) /* "second-slot" instruction */ { /* insert no-op before pc */ stepping.noop_addr = pc - 2; @@ -1193,7 +1213,7 @@ prepare_to_step (continue_p) stepping.trap1_save = *(unsigned short *) stepping.trap1_addr; *(unsigned short *) stepping.trap1_addr = trap1; } - else /* "first-slot" instruction */ + else /* "first-slot" instruction */ { /* insert trap after pc */ stepping.trap1_addr = pc + INSTRUCTION_SIZE (pc); @@ -1205,7 +1225,7 @@ prepare_to_step (continue_p) one single-step before continuing, because the PC is on a half-word boundary. There's no way to simply resume at such an address. */ stepping.continue_p = continue_p; - stepping.stepping = 1; /* starting a single-step */ + stepping.stepping = 1; /* starting a single-step */ return 1; } @@ -1223,39 +1243,39 @@ prepare_to_step (continue_p) static int finish_from_step (void) { - if (stepping.stepping) /* anything to do? */ + if (stepping.stepping) /* anything to do? */ { int continue_p = stepping.continue_p; unsigned char *p; - if (stepping.noop_addr) /* replace instr "under" our no-op */ + if (stepping.noop_addr) /* replace instr "under" our no-op */ *(unsigned short *) stepping.noop_addr = stepping.noop_save; - if (stepping.trap1_addr) /* replace instr "under" our trap */ + if (stepping.trap1_addr) /* replace instr "under" our trap */ *(unsigned short *) stepping.trap1_addr = stepping.trap1_save; - if (stepping.trap2_addr) /* ditto our other trap, if any */ + if (stepping.trap2_addr) /* ditto our other trap, if any */ *(unsigned short *) stepping.trap2_addr = stepping.trap2_save; - for (p = (unsigned char *) &stepping; /* zero out the stepping context */ + for (p = (unsigned char *) &stepping; /* zero out the stepping context */ p < ((unsigned char *) &stepping) + sizeof (stepping); p++) *p = 0; return !(continue_p); } - else /* we didn't single-step, therefore this must be a legitimate stop */ + else /* we didn't single-step, therefore this must be a legitimate stop */ return 1; } struct PSWreg -{ /* separate out the bit flags in the PSW register */ - int pad1:16; - int bsm:1; - int bie:1; - int pad2:5; - int bc:1; - int sm:1; - int ie:1; - int pad3:5; - int c:1; +{ /* separate out the bit flags in the PSW register */ + int pad1 : 16; + int bsm : 1; + int bie : 1; + int pad2 : 5; + int bc : 1; + int sm : 1; + int ie : 1; + int pad3 : 5; + int c : 1; } *psw; /* Upon entry the value for LR to save has been pushed. @@ -1314,13 +1334,13 @@ stash_registers:\n\ static void cleanup_stash (void) { - psw = (struct PSWreg *) ®isters[PSW]; /* fields of PSW register */ - psw->sm = psw->bsm; /* fix up pre-trap values of psw fields */ + psw = (struct PSWreg *) ®isters[PSW]; /* fields of PSW register */ + psw->sm = psw->bsm; /* fix up pre-trap values of psw fields */ psw->ie = psw->bie; psw->c = psw->bc; - registers[CBR] = psw->bc; /* fix up pre-trap "C" register */ + registers[CBR] = psw->bc; /* fix up pre-trap "C" register */ -#if 0 /* FIXME: Was in previous version. Necessary? +#if 0 /* FIXME: Was in previous version. Necessary? (Remember that we use the "rte" insn to return from the trap/interrupt so the values of bsm, bie, bc are important. */ psw->bsm = psw->bie = psw->bc = 0; /* zero post-trap values */ @@ -1328,10 +1348,10 @@ cleanup_stash (void) /* FIXME: Copied from previous version. This can probably be deleted since methinks stash_registers has already done this. */ - registers[PC] = registers[BPC]; /* pre-trap PC */ + registers[PC] = registers[BPC]; /* pre-trap PC */ /* FIXME: Copied from previous version. Necessary? */ - if (psw->sm) /* copy R15 into (psw->sm ? SPU : SPI) */ + if (psw->sm) /* copy R15 into (psw->sm ? SPU : SPI) */ registers[SPU] = registers[R15]; else registers[SPI] = registers[R15]; @@ -1389,7 +1409,8 @@ process_exception (int num) ld r15, @r1 ; setup local stack (protect user stack)\n\ mv r0, %0\n\ bl handle_exception\n\ - bl restore_and_return"::"r" (num):"r0", "r1"); + bl restore_and_return" ::"r"(num) + : "r0", "r1"); } void _catchException0 (); @@ -1582,7 +1603,6 @@ _catchException17:\n\ ldi r0, #17\n\ bl process_exception"); - /* this function is used to set up exception handlers for tracing and breakpoints */ void @@ -1591,8 +1611,8 @@ set_debug_traps (void) /* extern void remcomHandler(); */ int i; - for (i = 0; i < 18; i++) /* keep a copy of old vectors */ - if (save_vectors[i] == 0) /* only copy them the first time */ + for (i = 0; i < 18; i++) /* keep a copy of old vectors */ + if (save_vectors[i] == 0) /* only copy them the first time */ save_vectors[i] = getExceptionHandler (i); stackPtr = &remcomStack[STACKSIZE / sizeof (int) - 1]; @@ -1673,8 +1693,8 @@ gdb_write (char *data, int len) i = 0; while (i < len) { - for (cpy = buf + 1; - i < len && cpy < buf + sizeof (remcomOutBuffer) - 3; i++) + for (cpy = buf + 1; i < len && cpy < buf + sizeof (remcomOutBuffer) - 3; + i++) { *cpy++ = hexchars[data[i] >> 4]; *cpy++ = hexchars[data[i] & 0x0F]; @@ -1711,16 +1731,16 @@ gdb_error (char *format, char *parm) if (format && *format) len = strlen (format); else - return; /* empty input */ + return; /* empty input */ if (parm && *parm) len += strlen (parm); for (cpy = buf; *format;) { - if (format[0] == '%' && format[1] == 's') /* include second string */ + if (format[0] == '%' && format[1] == 's') /* include second string */ { - format += 2; /* advance two chars instead of just one */ + format += 2; /* advance two chars instead of just one */ while (parm && *parm) *cpy++ = *parm++; } diff --git a/gdb/stubs/m68k-stub.c b/gdb/stubs/m68k-stub.c index 826f922..e31f681 100644 --- a/gdb/stubs/m68k-stub.c +++ b/gdb/stubs/m68k-stub.c @@ -113,44 +113,69 @@ * * external low-level support routines */ -typedef void (*ExceptionHook)(int); /* pointer to function with int parm */ -typedef void (*Function)(); /* pointer to a function */ +typedef void (*ExceptionHook) (int); /* pointer to function with int parm */ +typedef void (*Function) (); /* pointer to a function */ -extern void putDebugChar(); /* write a single character */ -extern int getDebugChar(); /* read and return a single char */ +extern void putDebugChar (); /* write a single character */ +extern int getDebugChar (); /* read and return a single char */ -extern Function exceptionHandler(); /* assign an exception handler */ +extern Function exceptionHandler (); /* assign an exception handler */ extern ExceptionHook exceptionHook; /* hook variable for errors/exceptions */ /************************/ /* FORWARD DECLARATIONS */ /************************/ -static void -initializeRemcomErrorFrame (); +static void initializeRemcomErrorFrame (); /************************************************************************/ /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/ /* at least NUMREGBYTES*2 are needed for register packets */ #define BUFMAX 400 -static char initialized; /* boolean flag. != 0 means we've been initialized */ +static char initialized; /* boolean flag. != 0 means we've been initialized */ -int remote_debug; -/* debug > 0 prints ill-formed commands in valid packets & checksum errors */ +int remote_debug; +/* debug > 0 prints ill-formed commands in valid packets & checksum errors */ -static const char hexchars[]="0123456789abcdef"; +static const char hexchars[] = "0123456789abcdef"; /* there are 180 bytes of registers on a 68020 w/68881 */ /* many of the fpa registers are 12 byte (96 bit) registers */ #define NUMREGBYTES 180 -enum regnames {D0,D1,D2,D3,D4,D5,D6,D7, - A0,A1,A2,A3,A4,A5,A6,A7, - PS,PC, - FP0,FP1,FP2,FP3,FP4,FP5,FP6,FP7, - FPCONTROL,FPSTATUS,FPIADDR - }; - - + +enum regnames +{ + D0, + D1, + D2, + D3, + D4, + D5, + D6, + D7, + A0, + A1, + A2, + A3, + A4, + A5, + A6, + A7, + PS, + PC, + FP0, + FP1, + FP2, + FP3, + FP4, + FP5, + FP6, + FP7, + FPCONTROL, + FPSTATUS, + FPIADDR +}; + /* We keep a whole frame cache here. "Why?", I hear you cry, "doesn't GDB handle that sort of thing?" Well, yes, I believe the only reason for this cache is to save and restore floating point state @@ -161,30 +186,30 @@ enum regnames {D0,D1,D2,D3,D4,D5,D6,D7, typedef struct FrameStruct { - struct FrameStruct *previous; - int exceptionPC; /* pc value when this frame created */ - int exceptionVector; /* cpu vector causing exception */ - short frameSize; /* size of cpu frame in words */ - short sr; /* for 68000, this not always sr */ - int pc; - short format; - int fsaveHeader; - int morejunk[0]; /* exception frame, fp save... */ + struct FrameStruct *previous; + int exceptionPC; /* pc value when this frame created */ + int exceptionVector; /* cpu vector causing exception */ + short frameSize; /* size of cpu frame in words */ + short sr; /* for 68000, this not always sr */ + int pc; + short format; + int fsaveHeader; + int morejunk[0]; /* exception frame, fp save... */ } Frame; #define FRAMESIZE 500 -int gdbFrameStack[FRAMESIZE]; +int gdbFrameStack[FRAMESIZE]; static Frame *lastFrame; /* * these should not be static cuz they can be used outside this module */ -int registers[NUMREGBYTES/4]; +int registers[NUMREGBYTES / 4]; int superStack; #define STACKSIZE 10000 -int remcomStack[STACKSIZE/sizeof(int)]; -static int* stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1]; +int remcomStack[STACKSIZE / sizeof (int)]; +static int *stackPtr = &remcomStack[STACKSIZE / sizeof (int) - 1]; /* * In many cases, the system will want to continue exception processing @@ -199,11 +224,13 @@ static ExceptionHook oldExceptionHook; * exception. The following table is the number of WORDS used * for each exception format. */ -const short exceptionSize[] = { 4,4,6,4,4,4,4,4,29,10,16,46,12,4,4,4 }; +const short exceptionSize[] + = { 4, 4, 6, 4, 4, 4, 4, 4, 29, 10, 16, 46, 12, 4, 4, 4 }; #endif #ifdef mc68332 -static const short exceptionSize[] = { 4,4,6,4,4,4,4,4,4,4,4,4,16,4,4,4 }; +static const short exceptionSize[] + = { 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4 }; #endif /************* jump buffer used for setjmp/longjmp **************************/ @@ -214,11 +241,12 @@ jmp_buf remcomEnv; #ifdef __HAVE_68881__ /* do an fsave, then remember the address to begin a restore from */ -#define SAVE_FP_REGS() asm(" fsave a0@-"); \ - asm(" fmovemx fp0-fp7,_registers+72"); \ - asm(" fmoveml fpcr/fpsr/fpi,_registers+168"); -#define RESTORE_FP_REGS() \ -asm(" \n\ +#define SAVE_FP_REGS() \ + asm (" fsave a0@-"); \ + asm (" fmovemx fp0-fp7,_registers+72"); \ + asm (" fmoveml fpcr/fpsr/fpi,_registers+168"); +#define RESTORE_FP_REGS() \ + asm (" \n\ fmoveml _registers+168,fpcr/fpsr/fpi \n\ fmovemx _registers+72,fp0-fp7 \n\ cmpl #-1,a0@ | skip frestore flag set ? \n\ @@ -232,8 +260,8 @@ skip_frestore: \n\ #define RESTORE_FP_REGS() #endif /* __HAVE_68881__ */ -void return_to_super(); -void return_to_user(); +void return_to_super (); +void return_to_user (); asm(" .text @@ -256,9 +284,9 @@ return_to_any: movew a0@+,d0 /* get # of words in cpu frame */ addw d0,a0 /* point to end of data */ addw d0,a0 /* point to end of data */ - movel a0,a1 -# -# copy the stack frame + movel a0,a1 +# +#copy the stack frame subql #1,d0 copyUserLoop: movew a1@-,sp@- @@ -266,10 +294,10 @@ copyUserLoop: "); RESTORE_FP_REGS() asm(" moveml _registers,d0-d7/a0-a6"); - asm(" rte"); /* pop and go! */ + asm(" rte"); /* pop and go! */ -#define DISABLE_INTERRUPTS() asm(" oriw #0x0700,sr"); -#define BREAKPOINT() asm(" trap #1"); +#define DISABLE_INTERRUPTS() asm (" oriw #0x0700,sr"); +#define BREAKPOINT() asm (" trap #1"); /* this function is called immediately when a level 7 interrupt occurs */ /* if the previous interrupt level was 7 then we're already servicing */ @@ -280,7 +308,7 @@ asm(" .globl __debug_level7 __debug_level7: movew d0,sp@-"); -#if defined (mc68020) || defined (mc68332) +#if defined(mc68020) || defined(mc68332) asm(" movew sp@(2),d0"); #else asm(" movew sp@(6),d0"); @@ -292,14 +320,14 @@ asm(" andiw #0x700,d0 bra __catchException _already7: movew sp@+,d0"); -#if !defined (mc68020) && !defined (mc68332) +#if !defined(mc68020) && !defined(mc68332) asm(" lea sp@(4),sp"); /* pull off 68000 return address */ #endif asm(" rte"); extern void _catchException (); -#if defined (mc68020) || defined (mc68332) +#if defined(mc68020) || defined(mc68332) /* This function is called when a 68020 exception occurs. It saves * all the cpu and fpcp regs in the _registers array, creates a frame on a * linked list of frames which has the cpu and fpcp stack frames needed @@ -333,7 +361,7 @@ asm(" movel a4,a5@(68) /* save pc in _regisers[] */ # -# figure out how many bytes in the stack frame +#figure out how many bytes in the stack frame movew sp@(6),d0 /* get '020 exception format */ movew d0,d2 /* make a copy of format word */ andiw #0xf000,d0 /* mask off format type */ @@ -347,13 +375,13 @@ asm(" movel a0,a1 /* copy save pointer */ subql #1,d0 /* predecrement loop counter */ # -# copy the frame +#copy the frame saveFrameLoop: movew sp@+,a1@+ dbf d0,saveFrameLoop # -# now that the stack has been clenaed, -# save the a7 in use at time of exception +#now that the stack has been clenaed, +#save the a7 in use at time of exception movel sp,_superStack /* save supervisor sp */ andiw #0x2000,d1 /* were we in supervisor mode ? */ beq userMode @@ -365,19 +393,19 @@ userMode: a7saveDone: # -# save size of frame +#save size of frame movew d3,a0@- # -# compute exception number +#compute exception number andl #0xfff,d2 /* mask off vector offset */ lsrw #2,d2 /* divide by 4 to get vect num */ movel d2,a0@- /* save it */ # -# save pc causing exception +#save pc causing exception movel a4,a0@- # -# save old frame link and set the new value +#save old frame link and set the new value movel _lastFrame,a1 /* last frame pointer */ movel a1,a0@- /* save pointer to prev frame */ movel a0,_lastFrame @@ -450,7 +478,7 @@ saveDone: movel a4,a0@- /* push exception pc */ # -# save old frame link and set the new value +#save old frame link and set the new value movel _lastFrame,a1 /* last frame pointer */ movel a1,a0@- /* save pointer to prev frame */ movel a0,_lastFrame @@ -486,10 +514,10 @@ _returnFromException (Frame * frame) frame = lastFrame; frame->frameSize = 4; frame->format = 0; - frame->fsaveHeader = -1; /* restore regs, but we dont have fsave info */ + frame->fsaveHeader = -1; /* restore regs, but we dont have fsave info */ } -#if !defined (mc68020) && !defined (mc68332) +#if !defined(mc68020) && !defined(mc68332) /* a 68000 cannot use the internal info pushed onto a bus error * or address error frame when doing an RTE so don't put this info * onto the stack or the stack will creep every time this happens. @@ -509,7 +537,7 @@ _returnFromException (Frame * frame) return_to_super (); } else - { /* return to user mode */ + { /* return to user mode */ return_to_user (); } } @@ -577,15 +605,16 @@ getpacket (void) { if (remote_debug) { - fprintf (stderr, - "bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n", - checksum, xmitcsum, buffer); + fprintf ( + stderr, + "bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n", + checksum, xmitcsum, buffer); } - putDebugChar ('-'); /* failed checksum */ + putDebugChar ('-'); /* failed checksum */ } else { - putDebugChar ('+'); /* successful transfer */ + putDebugChar ('+'); /* successful transfer */ /* if a sequence char is present, reply the sequence ID */ if (buffer[2] == ':') @@ -629,7 +658,6 @@ putpacket (buffer) putDebugChar ('#'); putDebugChar (hexchars[checksum >> 4]); putDebugChar (hexchars[checksum % 16]); - } while (getDebugChar () != '+'); @@ -703,34 +731,34 @@ computeSignal (exceptionVector) { case 2: sigval = 10; - break; /* bus error */ + break; /* bus error */ case 3: sigval = 10; - break; /* address error */ + break; /* address error */ case 4: sigval = 4; - break; /* illegal instruction */ + break; /* illegal instruction */ case 5: sigval = 8; - break; /* zero divide */ + break; /* zero divide */ case 6: sigval = 8; - break; /* chk instruction */ + break; /* chk instruction */ case 7: sigval = 8; - break; /* trapv instruction */ + break; /* trapv instruction */ case 8: sigval = 11; - break; /* privilege violation */ + break; /* privilege violation */ case 9: sigval = 5; - break; /* trace trap */ + break; /* trace trap */ case 10: sigval = 4; - break; /* line 1010 emulator */ + break; /* line 1010 emulator */ case 11: sigval = 4; - break; /* line 1111 emulator */ + break; /* line 1111 emulator */ /* Coprocessor protocol violation. Using a standard MMU or FPU this cannot be triggered by software. Call it a SIGBUS. */ @@ -740,10 +768,10 @@ computeSignal (exceptionVector) case 31: sigval = 2; - break; /* interrupt */ + break; /* interrupt */ case 33: sigval = 5; - break; /* breakpoint */ + break; /* breakpoint */ /* This is a trap #8 instruction. Apparently it is someone's software convention for some sort of SIGFPE condition. Whose? How many @@ -751,31 +779,31 @@ computeSignal (exceptionVector) Is there a clean solution? */ case 40: sigval = 8; - break; /* floating point err */ + break; /* floating point err */ case 48: sigval = 8; - break; /* floating point err */ + break; /* floating point err */ case 49: sigval = 8; - break; /* floating point err */ + break; /* floating point err */ case 50: sigval = 8; - break; /* zero divide */ + break; /* zero divide */ case 51: sigval = 8; - break; /* underflow */ + break; /* underflow */ case 52: sigval = 8; - break; /* operand error */ + break; /* operand error */ case 53: sigval = 8; - break; /* overflow */ + break; /* overflow */ case 54: sigval = 8; - break; /* NAN */ + break; /* NAN */ default: - sigval = 7; /* "software generated" */ + sigval = 7; /* "software generated" */ } return (sigval); } @@ -822,8 +850,8 @@ handle_exception (int exceptionVector) Frame *frame; if (remote_debug) - printf ("vector=%d, sr=0x%x, pc=0x%x\n", - exceptionVector, registers[PS], registers[PC]); + printf ("vector=%d, sr=0x%x, pc=0x%x\n", exceptionVector, registers[PS], + registers[PC]); /* reply to host that an exception has occurred */ sigval = computeSignal (exceptionVector); @@ -849,12 +877,12 @@ handle_exception (int exceptionVector) remcomOutBuffer[3] = 0; break; case 'd': - remote_debug = !(remote_debug); /* toggle debug flag */ + remote_debug = !(remote_debug); /* toggle debug flag */ break; - case 'g': /* return the value of the CPU registers */ + case 'g': /* return the value of the CPU registers */ mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES); break; - case 'G': /* set the value of the CPU registers - return OK */ + case 'G': /* set the value of the CPU registers - return OK */ hex2mem (ptr, (char *) registers, NUMREGBYTES); strcpy (remcomOutBuffer, "OK"); break; @@ -951,21 +979,21 @@ handle_exception (int exceptionVector) while (frame) { if (remote_debug) - printf ("frame at 0x%x has pc=0x%x, except#=%d\n", - frame, frame->exceptionPC, frame->exceptionVector); + printf ("frame at 0x%x has pc=0x%x, except#=%d\n", frame, + frame->exceptionPC, frame->exceptionVector); if (frame->exceptionPC == newPC) - break; /* bingo! a match */ + break; /* bingo! a match */ /* * for a breakpoint instruction, the saved pc may * be off by two due to re-executing the instruction * replaced by the trap instruction. Check for this. */ - if ((frame->exceptionVector == 33) && - (frame->exceptionPC == (newPC + 2))) + if ((frame->exceptionVector == 33) + && (frame->exceptionPC == (newPC + 2))) break; if (frame == frame->previous) { - frame = 0; /* no match found */ + frame = 0; /* no match found */ break; } frame = frame->previous; @@ -979,16 +1007,16 @@ handle_exception (int exceptionVector) */ if (frame) { - if ((frame->exceptionVector != 9) && - (frame->exceptionVector != 31) && - (frame->exceptionVector != 33)) + if ((frame->exceptionVector != 9) + && (frame->exceptionVector != 31) + && (frame->exceptionVector != 33)) { /* * invoke the previous handler. */ if (oldExceptionHook) (*oldExceptionHook) (frame->exceptionVector); - newPC = registers[PC]; /* pc may have changed */ + newPC = registers[PC]; /* pc may have changed */ if (newPC != frame->exceptionPC) { if (remote_debug) @@ -997,7 +1025,7 @@ handle_exception (int exceptionVector) frame->exceptionVector); /* re-use the last frame, we're skipping it (longjump?) */ frame = (Frame *) 0; - _returnFromException (frame); /* this is a jump */ + _returnFromException (frame); /* this is a jump */ } } } @@ -1019,17 +1047,17 @@ handle_exception (int exceptionVector) } frame->previous = lastFrame; lastFrame = frame; - frame = 0; /* null so _return... will properly initialize it */ + frame = 0; /* null so _return... will properly initialize it */ } - _returnFromException (frame); /* this is a jump */ + _returnFromException (frame); /* this is a jump */ break; /* kill the program */ - case 'k': /* do nothing */ + case 'k': /* do nothing */ break; - } /* switch */ + } /* switch */ /* reply to the request */ putpacket (remcomOutBuffer); @@ -1040,7 +1068,7 @@ handle_exception (int exceptionVector) void initializeRemcomErrorFrame (void) { - lastFrame = ((Frame *) & gdbFrameStack[FRAMESIZE - 1]) - 1; + lastFrame = ((Frame *) &gdbFrameStack[FRAMESIZE - 1]) - 1; lastFrame->previous = lastFrame; } diff --git a/gdb/stubs/sh-stub.c b/gdb/stubs/sh-stub.c index 03a865e..151e8f1 100644 --- a/gdb/stubs/sh-stub.c +++ b/gdb/stubs/sh-stub.c @@ -26,7 +26,6 @@ ****************************************************************************/ - /* Remote communication protocol. A debug packet whose contents are <data> @@ -149,31 +148,31 @@ /* Renesas SH architecture instruction encoding masks */ -#define COND_BR_MASK 0xff00 +#define COND_BR_MASK 0xff00 #define UCOND_DBR_MASK 0xe000 #define UCOND_RBR_MASK 0xf0df -#define TRAPA_MASK 0xff00 +#define TRAPA_MASK 0xff00 -#define COND_DISP 0x00ff -#define UCOND_DISP 0x0fff -#define UCOND_REG 0x0f00 +#define COND_DISP 0x00ff +#define UCOND_DISP 0x0fff +#define UCOND_REG 0x0f00 /* Renesas SH instruction opcodes */ -#define BF_INSTR 0x8b00 -#define BT_INSTR 0x8900 -#define BRA_INSTR 0xa000 -#define BSR_INSTR 0xb000 -#define JMP_INSTR 0x402b -#define JSR_INSTR 0x400b -#define RTS_INSTR 0x000b -#define RTE_INSTR 0x002b -#define TRAPA_INSTR 0xc300 -#define SSTEP_INSTR 0xc3ff +#define BF_INSTR 0x8b00 +#define BT_INSTR 0x8900 +#define BRA_INSTR 0xa000 +#define BSR_INSTR 0xb000 +#define JMP_INSTR 0x402b +#define JSR_INSTR 0x400b +#define RTS_INSTR 0x000b +#define RTE_INSTR 0x002b +#define TRAPA_INSTR 0xc300 +#define SSTEP_INSTR 0xc3ff /* Renesas SH processor register masks */ -#define T_BIT_MASK 0x0001 +#define T_BIT_MASK 0x0001 /* * BUFMAX defines the maximum number of characters in inbound/outbound @@ -184,7 +183,7 @@ /* * Number of bytes for registers */ -#define NUMREGBYTES 112 /* 92 */ +#define NUMREGBYTES 112 /* 92 */ /* * typedef @@ -204,7 +203,7 @@ static void putpacket (char *); static void handle_buserror (void); static int computeSignal (int exceptionVector); static void handle_exception (int exceptionVector); -void init_serial(); +void init_serial (); void putDebugChar (char); char getDebugChar (void); @@ -219,36 +218,32 @@ void catch_exception_32 (void); void catch_exception_33 (void); void catch_exception_255 (void); - - -#define catch_exception_random catch_exception_255 /* Treat all odd ones like 255 */ +#define catch_exception_random \ + catch_exception_255 /* Treat all odd ones like 255 */ void breakpoint (void); +#define init_stack_size \ + 8 * 1024 /* if you change this you should also modify BINIT */ +#define stub_stack_size 8 * 1024 -#define init_stack_size 8*1024 /* if you change this you should also modify BINIT */ -#define stub_stack_size 8*1024 - -int init_stack[init_stack_size] __attribute__ ((section ("stack"))) = {0}; -int stub_stack[stub_stack_size] __attribute__ ((section ("stack"))) = {0}; - +int init_stack[init_stack_size] __attribute__ ((section ("stack"))) = { 0 }; +int stub_stack[stub_stack_size] __attribute__ ((section ("stack"))) = { 0 }; void INIT (); void BINIT (); -#define CPU_BUS_ERROR_VEC 9 +#define CPU_BUS_ERROR_VEC 9 #define DMA_BUS_ERROR_VEC 10 -#define NMI_VEC 11 -#define INVALID_INSN_VEC 4 -#define INVALID_SLOT_VEC 6 -#define TRAP_VEC 32 -#define IO_VEC 33 -#define USER_VEC 255 +#define NMI_VEC 11 +#define INVALID_INSN_VEC 4 +#define INVALID_SLOT_VEC 6 +#define TRAP_VEC 32 +#define IO_VEC 33 +#define USER_VEC 255 - - -char in_nmi; /* Set when handling an NMI, so we don't reenter */ -int dofault; /* Non zero, bus errors will raise exception */ +char in_nmi; /* Set when handling an NMI, so we don't reenter */ +int dofault; /* Non zero, bus errors will raise exception */ int *stub_sp; @@ -259,19 +254,42 @@ int remote_debug; jmp_buf remcomEnv; enum regnames - { - R0, R1, R2, R3, R4, R5, R6, R7, - R8, R9, R10, R11, R12, R13, R14, - R15, PC, PR, GBR, VBR, MACH, MACL, SR, - TICKS, STALLS, CYCLES, INSTS, PLR - }; +{ + R0, + R1, + R2, + R3, + R4, + R5, + R6, + R7, + R8, + R9, + R10, + R11, + R12, + R13, + R14, + R15, + PC, + PR, + GBR, + VBR, + MACH, + MACL, + SR, + TICKS, + STALLS, + CYCLES, + INSTS, + PLR +}; typedef struct - { - short *memAddr; - short oldInstr; - } -stepData; +{ + short *memAddr; + short oldInstr; +} stepData; int registers[NUMREGBYTES / 4]; stepData instrBuffer; @@ -280,12 +298,14 @@ static const char hexchars[] = "0123456789abcdef"; static char remcomInBuffer[BUFMAX]; static char remcomOutBuffer[BUFMAX]; -char highhex(int x) +char +highhex (int x) { return hexchars[(x >> 4) & 0xf]; } -char lowhex(int x) +char +lowhex (int x) { return hexchars[x & 0xf]; } @@ -294,8 +314,7 @@ char lowhex(int x) * Assembly macros */ -#define BREAKPOINT() asm("trapa #0x20"::); - +#define BREAKPOINT() asm ("trapa #0x20" ::); /* * Routines to handle hex data @@ -397,7 +416,7 @@ getpacket (void) while ((ch = getDebugChar ()) != '$') ; -retry: + retry: checksum = 0; xmitcsum = -1; count = 0; @@ -425,11 +444,11 @@ retry: if (checksum != xmitcsum) { - putDebugChar ('-'); /* failed checksum */ + putDebugChar ('-'); /* failed checksum */ } else { - putDebugChar ('+'); /* successful transfer */ + putDebugChar ('+'); /* successful transfer */ /* if a sequence char is present, reply the sequence ID */ if (buffer[2] == ':') @@ -446,7 +465,6 @@ retry: } } - /* send the packet in buffer. */ static void @@ -467,11 +485,11 @@ putpacket (char *buffer) int runlen; /* Do run length encoding */ - for (runlen = 0; runlen < 100; runlen ++) + for (runlen = 0; runlen < 100; runlen++) { - if (src[0] != src[runlen]) + if (src[0] != src[runlen]) { - if (runlen > 3) + if (runlen > 3) { int encode; /* Got a useful amount */ @@ -494,15 +512,13 @@ putpacket (char *buffer) } } - putDebugChar ('#'); - putDebugChar (highhex(checksum)); - putDebugChar (lowhex(checksum)); + putDebugChar (highhex (checksum)); + putDebugChar (lowhex (checksum)); } - while (getDebugChar() != '+'); + while (getDebugChar () != '+'); } - /* a bus error has occurred, perform a longjmp to return execution and allow handling of the error */ @@ -524,19 +540,19 @@ computeSignal (int exceptionVector) { case INVALID_INSN_VEC: sigval = 4; - break; + break; case INVALID_SLOT_VEC: sigval = 4; - break; + break; case CPU_BUS_ERROR_VEC: sigval = 10; - break; + break; case DMA_BUS_ERROR_VEC: sigval = 10; - break; + break; case NMI_VEC: sigval = 2; - break; + break; case TRAP_VEC: case USER_VEC: @@ -544,7 +560,7 @@ computeSignal (int exceptionVector) break; default: - sigval = 7; /* "software generated"*/ + sigval = 7; /* "software generated"*/ break; } return (sigval); @@ -627,7 +643,6 @@ doSStep (void) *instrMem = SSTEP_INSTR; } - /* Undo the effect of a previous doSStep. If we single stepped, restore the old instruction. */ @@ -635,7 +650,8 @@ void undoSStep (void) { if (stepped) - { short *instrMem; + { + short *instrMem; instrMem = instrBuffer.memAddr; *instrMem = instrBuffer.oldInstr; } @@ -651,7 +667,6 @@ When in the monitor mode we talk a human on the serial line rather than gdb. */ - void gdb_handle_exception (int exceptionVector) { @@ -662,7 +677,7 @@ gdb_handle_exception (int exceptionVector) /* reply to host that an exception has occurred */ sigval = computeSignal (exceptionVector); remcomOutBuffer[0] = 'S'; - remcomOutBuffer[1] = highhex(sigval); + remcomOutBuffer[1] = highhex (sigval); remcomOutBuffer[2] = lowhex (sigval); remcomOutBuffer[3] = 0; @@ -674,8 +689,7 @@ gdb_handle_exception (int exceptionVector) * PC by one instruction, since this instruction * will later be replaced by its original one! */ - if (exceptionVector == 0xff - || exceptionVector == 0x20) + if (exceptionVector == 0xff || exceptionVector == 0x20) registers[PC] -= 2; /* @@ -700,12 +714,12 @@ gdb_handle_exception (int exceptionVector) remcomOutBuffer[3] = 0; break; case 'd': - remote_debug = !(remote_debug); /* toggle debug flag */ + remote_debug = !(remote_debug); /* toggle debug flag */ break; - case 'g': /* return the value of the CPU registers */ + case 'g': /* return the value of the CPU registers */ mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES); break; - case 'G': /* set the value of the CPU registers - return OK */ + case 'G': /* set the value of the CPU registers - return OK */ hex2mem (ptr, (char *) registers, NUMREGBYTES); strcpy (remcomOutBuffer, "OK"); break; @@ -776,37 +790,38 @@ gdb_handle_exception (int exceptionVector) break; /* kill the program */ - case 'k': /* do nothing */ + case 'k': /* do nothing */ break; - } /* switch */ + } /* switch */ /* reply to the request */ putpacket (remcomOutBuffer); } } - -#define GDBCOOKIE 0x5ac +#define GDBCOOKIE 0x5ac static int ingdbmode; + /* We've had an exception - choose to go into the monitor or the gdb stub */ -void handle_exception(int exceptionVector) +void +handle_exception (int exceptionVector) { #ifdef MONITOR - if (ingdbmode != GDBCOOKIE) - monitor_handle_exception (exceptionVector); - else + if (ingdbmode != GDBCOOKIE) + monitor_handle_exception (exceptionVector); + else #endif - gdb_handle_exception (exceptionVector); - + gdb_handle_exception (exceptionVector); } void gdb_mode (void) { ingdbmode = GDBCOOKIE; - breakpoint(); + breakpoint (); } + /* This function will generate a breakpoint exception. It is used at the beginning of a program to sync up with a debugger and can be used otherwise as a quick means to stop program execution and "break" into @@ -815,7 +830,7 @@ gdb_mode (void) void breakpoint (void) { - BREAKPOINT (); + BREAKPOINT (); } /**** Processor-specific routines start here ****/ @@ -842,300 +857,177 @@ breakpoint (void) /* SH1/SH2 exception vector table format */ typedef struct - { - void (*func_cold) (); - int *stack_cold; - void (*func_warm) (); - int *stack_warm; - void (*(handler[256 - 4])) (); - } -vec_type; +{ + void (*func_cold) (); + int *stack_cold; + void (*func_warm) (); + int *stack_warm; + void (*(handler[256 - 4])) (); +} vec_type; /* vectable is the SH1/SH2 vector table. It must be at address 0 or wherever your vbr points. */ -const vec_type vectable = -{ +const vec_type vectable = { &BINIT, /* 0: Power-on reset PC */ init_stack + init_stack_size, /* 1: Power-on reset SP */ &BINIT, /* 2: Manual reset PC */ init_stack + init_stack_size, /* 3: Manual reset SP */ -{ - &catch_exception_4, /* 4: General invalid instruction */ - &catch_exception_random, /* 5: Reserved for system */ - &catch_exception_6, /* 6: Invalid slot instruction */ - &catch_exception_random, /* 7: Reserved for system */ - &catch_exception_random, /* 8: Reserved for system */ - &catch_exception_9, /* 9: CPU bus error */ - &catch_exception_10, /* 10: DMA bus error */ - &catch_exception_11, /* 11: NMI */ - &catch_exception_random, /* 12: User break */ - &catch_exception_random, /* 13: Reserved for system */ - &catch_exception_random, /* 14: Reserved for system */ - &catch_exception_random, /* 15: Reserved for system */ - &catch_exception_random, /* 16: Reserved for system */ - &catch_exception_random, /* 17: Reserved for system */ - &catch_exception_random, /* 18: Reserved for system */ - &catch_exception_random, /* 19: Reserved for system */ - &catch_exception_random, /* 20: Reserved for system */ - &catch_exception_random, /* 21: Reserved for system */ - &catch_exception_random, /* 22: Reserved for system */ - &catch_exception_random, /* 23: Reserved for system */ - &catch_exception_random, /* 24: Reserved for system */ - &catch_exception_random, /* 25: Reserved for system */ - &catch_exception_random, /* 26: Reserved for system */ - &catch_exception_random, /* 27: Reserved for system */ - &catch_exception_random, /* 28: Reserved for system */ - &catch_exception_random, /* 29: Reserved for system */ - &catch_exception_random, /* 30: Reserved for system */ - &catch_exception_random, /* 31: Reserved for system */ - &catch_exception_32, /* 32: Trap instr (user vectors) */ - &catch_exception_33, /* 33: Trap instr (user vectors) */ - &catch_exception_random, /* 34: Trap instr (user vectors) */ - &catch_exception_random, /* 35: Trap instr (user vectors) */ - &catch_exception_random, /* 36: Trap instr (user vectors) */ - &catch_exception_random, /* 37: Trap instr (user vectors) */ - &catch_exception_random, /* 38: Trap instr (user vectors) */ - &catch_exception_random, /* 39: Trap instr (user vectors) */ - &catch_exception_random, /* 40: Trap instr (user vectors) */ - &catch_exception_random, /* 41: Trap instr (user vectors) */ - &catch_exception_random, /* 42: Trap instr (user vectors) */ - &catch_exception_random, /* 43: Trap instr (user vectors) */ - &catch_exception_random, /* 44: Trap instr (user vectors) */ - &catch_exception_random, /* 45: Trap instr (user vectors) */ - &catch_exception_random, /* 46: Trap instr (user vectors) */ - &catch_exception_random, /* 47: Trap instr (user vectors) */ - &catch_exception_random, /* 48: Trap instr (user vectors) */ - &catch_exception_random, /* 49: Trap instr (user vectors) */ - &catch_exception_random, /* 50: Trap instr (user vectors) */ - &catch_exception_random, /* 51: Trap instr (user vectors) */ - &catch_exception_random, /* 52: Trap instr (user vectors) */ - &catch_exception_random, /* 53: Trap instr (user vectors) */ - &catch_exception_random, /* 54: Trap instr (user vectors) */ - &catch_exception_random, /* 55: Trap instr (user vectors) */ - &catch_exception_random, /* 56: Trap instr (user vectors) */ - &catch_exception_random, /* 57: Trap instr (user vectors) */ - &catch_exception_random, /* 58: Trap instr (user vectors) */ - &catch_exception_random, /* 59: Trap instr (user vectors) */ - &catch_exception_random, /* 60: Trap instr (user vectors) */ - &catch_exception_random, /* 61: Trap instr (user vectors) */ - &catch_exception_random, /* 62: Trap instr (user vectors) */ - &catch_exception_random, /* 63: Trap instr (user vectors) */ - &catch_exception_random, /* 64: IRQ0 */ - &catch_exception_random, /* 65: IRQ1 */ - &catch_exception_random, /* 66: IRQ2 */ - &catch_exception_random, /* 67: IRQ3 */ - &catch_exception_random, /* 68: IRQ4 */ - &catch_exception_random, /* 69: IRQ5 */ - &catch_exception_random, /* 70: IRQ6 */ - &catch_exception_random, /* 71: IRQ7 */ - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_random, - &catch_exception_255}}; - -#define BCR (*(volatile short *)(0x05FFFFA0)) /* Bus control register */ -#define BAS (0x800) /* Byte access select */ -#define WCR1 (*(volatile short *)(0x05ffffA2)) /* Wait state control register */ + { &catch_exception_4, /* 4: General invalid instruction */ + &catch_exception_random, /* 5: Reserved for system */ + &catch_exception_6, /* 6: Invalid slot instruction */ + &catch_exception_random, /* 7: Reserved for system */ + &catch_exception_random, /* 8: Reserved for system */ + &catch_exception_9, /* 9: CPU bus error */ + &catch_exception_10, /* 10: DMA bus error */ + &catch_exception_11, /* 11: NMI */ + &catch_exception_random, /* 12: User break */ + &catch_exception_random, /* 13: Reserved for system */ + &catch_exception_random, /* 14: Reserved for system */ + &catch_exception_random, /* 15: Reserved for system */ + &catch_exception_random, /* 16: Reserved for system */ + &catch_exception_random, /* 17: Reserved for system */ + &catch_exception_random, /* 18: Reserved for system */ + &catch_exception_random, /* 19: Reserved for system */ + &catch_exception_random, /* 20: Reserved for system */ + &catch_exception_random, /* 21: Reserved for system */ + &catch_exception_random, /* 22: Reserved for system */ + &catch_exception_random, /* 23: Reserved for system */ + &catch_exception_random, /* 24: Reserved for system */ + &catch_exception_random, /* 25: Reserved for system */ + &catch_exception_random, /* 26: Reserved for system */ + &catch_exception_random, /* 27: Reserved for system */ + &catch_exception_random, /* 28: Reserved for system */ + &catch_exception_random, /* 29: Reserved for system */ + &catch_exception_random, /* 30: Reserved for system */ + &catch_exception_random, /* 31: Reserved for system */ + &catch_exception_32, /* 32: Trap instr (user vectors) */ + &catch_exception_33, /* 33: Trap instr (user vectors) */ + &catch_exception_random, /* 34: Trap instr (user vectors) */ + &catch_exception_random, /* 35: Trap instr (user vectors) */ + &catch_exception_random, /* 36: Trap instr (user vectors) */ + &catch_exception_random, /* 37: Trap instr (user vectors) */ + &catch_exception_random, /* 38: Trap instr (user vectors) */ + &catch_exception_random, /* 39: Trap instr (user vectors) */ + &catch_exception_random, /* 40: Trap instr (user vectors) */ + &catch_exception_random, /* 41: Trap instr (user vectors) */ + &catch_exception_random, /* 42: Trap instr (user vectors) */ + &catch_exception_random, /* 43: Trap instr (user vectors) */ + &catch_exception_random, /* 44: Trap instr (user vectors) */ + &catch_exception_random, /* 45: Trap instr (user vectors) */ + &catch_exception_random, /* 46: Trap instr (user vectors) */ + &catch_exception_random, /* 47: Trap instr (user vectors) */ + &catch_exception_random, /* 48: Trap instr (user vectors) */ + &catch_exception_random, /* 49: Trap instr (user vectors) */ + &catch_exception_random, /* 50: Trap instr (user vectors) */ + &catch_exception_random, /* 51: Trap instr (user vectors) */ + &catch_exception_random, /* 52: Trap instr (user vectors) */ + &catch_exception_random, /* 53: Trap instr (user vectors) */ + &catch_exception_random, /* 54: Trap instr (user vectors) */ + &catch_exception_random, /* 55: Trap instr (user vectors) */ + &catch_exception_random, /* 56: Trap instr (user vectors) */ + &catch_exception_random, /* 57: Trap instr (user vectors) */ + &catch_exception_random, /* 58: Trap instr (user vectors) */ + &catch_exception_random, /* 59: Trap instr (user vectors) */ + &catch_exception_random, /* 60: Trap instr (user vectors) */ + &catch_exception_random, /* 61: Trap instr (user vectors) */ + &catch_exception_random, /* 62: Trap instr (user vectors) */ + &catch_exception_random, /* 63: Trap instr (user vectors) */ + &catch_exception_random, /* 64: IRQ0 */ + &catch_exception_random, /* 65: IRQ1 */ + &catch_exception_random, /* 66: IRQ2 */ + &catch_exception_random, /* 67: IRQ3 */ + &catch_exception_random, /* 68: IRQ4 */ + &catch_exception_random, /* 69: IRQ5 */ + &catch_exception_random, /* 70: IRQ6 */ + &catch_exception_random, /* 71: IRQ7 */ + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_random, &catch_exception_random, &catch_exception_random, + &catch_exception_255 } +}; + +#define BCR (*(volatile short *) (0x05FFFFA0)) /* Bus control register */ +#define BAS (0x800) /* Byte access select */ +#define WCR1 \ + (*(volatile short *) (0x05ffffA2)) /* Wait state control register */ asm ("_BINIT: mov.l L1,r15"); asm ("bra _INIT"); asm ("nop"); asm ("L1: .long _init_stack + 8*1024*4"); + void INIT (void) { /* First turn on the ram */ - WCR1 = 0; /* Never sample wait */ - BCR = BAS; /* use lowbyte/high byte */ + WCR1 = 0; /* Never sample wait */ + BCR = BAS; /* use lowbyte/high byte */ - init_serial(); + init_serial (); #ifdef MONITOR reset_hook (); #endif - in_nmi = 0; dofault = 1; stepped = 0; @@ -1147,11 +1039,9 @@ INIT (void) ; } - -static void sr() +static void +sr () { - - /* Calling Reset does the same as pressing the button */ asm (".global _Reset .global _WarmReset @@ -1214,10 +1104,10 @@ L_stubstack: .long _stub_sp L_hdl_except: .long _handle_exception"); - } -static void rr() +static void +rr () { asm(" .align 2 @@ -1263,230 +1153,245 @@ restoreRegisters: "); } - -static __inline__ void code_for_catch_exception(int n) +static __inline__ void +code_for_catch_exception (int n) { - asm(" .globl _catch_exception_%O0" : : "i" (n) ); - asm(" _catch_exception_%O0:" :: "i" (n) ); - - asm(" add #-4, r15 ! reserve spot on stack "); - asm(" mov.l r1, @-r15 ! push R1 "); +asm (" .globl _catch_exception_%O0" : : "i"(n)); +asm (" _catch_exception_%O0:" ::"i"(n)); - if (n == NMI_VEC) - { - /* Special case for NMI - make sure that they don't nest */ - asm(" mov.l r0, @-r15 ! push R0"); - asm(" mov.l L_in_nmi, r0"); - asm(" tas.b @r0 ! Fend off against addtnl NMIs"); - asm(" bt noNMI"); - asm(" mov.l @r15+, r0"); - asm(" mov.l @r15+, r1"); - asm(" add #4, r15"); - asm(" rte"); - asm(" nop"); - asm(".align 2"); - asm("L_in_nmi: .long _in_nmi"); - asm("noNMI:"); - } - else - { +asm (" add #-4, r15 ! reserve " + "spot on stack "); +asm (" mov.l r1, @-r15 ! push " + "R1 "); - if (n == CPU_BUS_ERROR_VEC) - { - /* Exception 9 (bus errors) are disasbleable - so that you +if (n == NMI_VEC) + { + /* Special case for NMI - make sure that they don't nest */ + asm (" mov.l r0, @-r15 ! " + "push R0"); + asm (" mov.l L_in_nmi, r0"); + asm (" tas.b @r0 ! " + "Fend off against addtnl NMIs"); + asm (" bt noNMI"); + asm (" mov.l @r15+, r0"); + asm (" mov.l @r15+, r1"); + asm (" add #4, r15"); + asm (" rte"); + asm (" nop"); + asm (".align 2"); + asm ("L_in_nmi: .long _in_nmi"); + asm ("noNMI:"); + } +else + { + if (n == CPU_BUS_ERROR_VEC) + { + /* Exception 9 (bus errors) are disasbleable - so that you can probe memory and get zero instead of a fault. Because the vector table may be in ROM we don't revector the interrupt like all the other stubs, we check in here */ - asm("mov.l L_dofault,r1"); - asm("mov.l @r1,r1"); - asm("tst r1,r1"); - asm("bf faultaway"); - asm("bsr _handle_buserror"); - asm(".align 2"); - asm("L_dofault: .long _dofault"); - asm("faultaway:"); - } - asm(" mov #15<<4, r1 "); - asm(" ldc r1, sr ! disable interrupts "); - asm(" mov.l r0, @-r15 ! push R0 "); - } + asm ("mov.l L_dofault,r1"); + asm ("mov.l @r1,r1"); + asm ("tst r1,r1"); + asm ("bf faultaway"); + asm ("bsr _handle_buserror"); + asm (".align 2"); + asm ("L_dofault: .long _dofault"); + asm ("faultaway:"); + } + asm (" mov #15<<4, r1 " + " "); + asm (" ldc r1, sr ! " + "disable interrupts "); + asm (" mov.l r0, @-r15 ! " + "push R0 "); + } - /* Prepare for saving context, we've already pushed r0 and r1, stick exception number +/* Prepare for saving context, we've already pushed r0 and r1, stick exception number into the frame */ - asm(" mov r15, r0 "); - asm(" add #8, r0 "); - asm(" mov %0,r1" :: "i" (n) ); - asm(" extu.b r1,r1 "); - asm(" bra saveRegisters ! save register values "); - asm(" mov.l r1, @r0 ! save exception # "); +asm (" mov r15, r0 " + " "); +asm (" add #8, r0 " + " "); +asm (" mov %0,r1" ::"i"(n)); +asm (" extu.b r1,r1 " + " "); +asm (" bra saveRegisters ! save " + "register values "); +asm (" mov.l r1, @r0 ! save " + "exception # "); } - -static void +static void exceptions (void) { - code_for_catch_exception (CPU_BUS_ERROR_VEC); - code_for_catch_exception (DMA_BUS_ERROR_VEC); - code_for_catch_exception (INVALID_INSN_VEC); - code_for_catch_exception (INVALID_SLOT_VEC); - code_for_catch_exception (NMI_VEC); - code_for_catch_exception (TRAP_VEC); - code_for_catch_exception (USER_VEC); - code_for_catch_exception (IO_VEC); +code_for_catch_exception (CPU_BUS_ERROR_VEC); +code_for_catch_exception (DMA_BUS_ERROR_VEC); +code_for_catch_exception (INVALID_INSN_VEC); +code_for_catch_exception (INVALID_SLOT_VEC); +code_for_catch_exception (NMI_VEC); +code_for_catch_exception (TRAP_VEC); +code_for_catch_exception (USER_VEC); +code_for_catch_exception (IO_VEC); } - - - - - /* Support for Serial I/O using on chip uart */ -#define SMR0 (*(volatile char *)(0x05FFFEC0)) /* Channel 0 serial mode register */ -#define BRR0 (*(volatile char *)(0x05FFFEC1)) /* Channel 0 bit rate register */ -#define SCR0 (*(volatile char *)(0x05FFFEC2)) /* Channel 0 serial control register */ -#define TDR0 (*(volatile char *)(0x05FFFEC3)) /* Channel 0 transmit data register */ -#define SSR0 (*(volatile char *)(0x05FFFEC4)) /* Channel 0 serial status register */ -#define RDR0 (*(volatile char *)(0x05FFFEC5)) /* Channel 0 receive data register */ - -#define SMR1 (*(volatile char *)(0x05FFFEC8)) /* Channel 1 serial mode register */ -#define BRR1 (*(volatile char *)(0x05FFFEC9)) /* Channel 1 bit rate register */ -#define SCR1 (*(volatile char *)(0x05FFFECA)) /* Channel 1 serial control register */ -#define TDR1 (*(volatile char *)(0x05FFFECB)) /* Channel 1 transmit data register */ -#define SSR1 (*(volatile char *)(0x05FFFECC)) /* Channel 1 serial status register */ -#define RDR1 (*(volatile char *)(0x05FFFECD)) /* Channel 1 receive data register */ +#define SMR0 \ + (*(volatile char *) (0x05FFFEC0)) /* Channel 0 serial mode register */ +#define BRR0 \ + (*(volatile char *) (0x05FFFEC1)) /* Channel 0 bit rate register */ +#define SCR0 \ + (*(volatile char *) (0x05FFFEC2)) /* Channel 0 serial control register */ +#define TDR0 \ + (*(volatile char *) (0x05FFFEC3)) /* Channel 0 transmit data register */ +#define SSR0 \ + (*(volatile char *) (0x05FFFEC4)) /* Channel 0 serial status register */ +#define RDR0 \ + (*(volatile char *) (0x05FFFEC5)) /* Channel 0 receive data register */ + +#define SMR1 \ + (*(volatile char *) (0x05FFFEC8)) /* Channel 1 serial mode register */ +#define BRR1 \ + (*(volatile char *) (0x05FFFEC9)) /* Channel 1 bit rate register */ +#define SCR1 \ + (*(volatile char *) (0x05FFFECA)) /* Channel 1 serial control register */ +#define TDR1 \ + (*(volatile char *) (0x05FFFECB)) /* Channel 1 transmit data register */ +#define SSR1 \ + (*(volatile char *) (0x05FFFECC)) /* Channel 1 serial status register */ +#define RDR1 \ + (*(volatile char *) (0x05FFFECD)) /* Channel 1 receive data register */ /* * Serial mode register bits */ -#define SYNC_MODE 0x80 -#define SEVEN_BIT_DATA 0x40 -#define PARITY_ON 0x20 -#define ODD_PARITY 0x10 -#define STOP_BITS_2 0x08 -#define ENABLE_MULTIP 0x04 -#define PHI_64 0x03 -#define PHI_16 0x02 -#define PHI_4 0x01 +#define SYNC_MODE 0x80 +#define SEVEN_BIT_DATA 0x40 +#define PARITY_ON 0x20 +#define ODD_PARITY 0x10 +#define STOP_BITS_2 0x08 +#define ENABLE_MULTIP 0x04 +#define PHI_64 0x03 +#define PHI_16 0x02 +#define PHI_4 0x01 /* * Serial control register bits */ -#define SCI_TIE 0x80 /* Transmit interrupt enable */ -#define SCI_RIE 0x40 /* Receive interrupt enable */ -#define SCI_TE 0x20 /* Transmit enable */ -#define SCI_RE 0x10 /* Receive enable */ -#define SCI_MPIE 0x08 /* Multiprocessor interrupt enable */ -#define SCI_TEIE 0x04 /* Transmit end interrupt enable */ -#define SCI_CKE1 0x02 /* Clock enable 1 */ -#define SCI_CKE0 0x01 /* Clock enable 0 */ +#define SCI_TIE 0x80 /* Transmit interrupt enable */ +#define SCI_RIE 0x40 /* Receive interrupt enable */ +#define SCI_TE 0x20 /* Transmit enable */ +#define SCI_RE 0x10 /* Receive enable */ +#define SCI_MPIE 0x08 /* Multiprocessor interrupt enable */ +#define SCI_TEIE 0x04 /* Transmit end interrupt enable */ +#define SCI_CKE1 0x02 /* Clock enable 1 */ +#define SCI_CKE0 0x01 /* Clock enable 0 */ /* * Serial status register bits */ -#define SCI_TDRE 0x80 /* Transmit data register empty */ -#define SCI_RDRF 0x40 /* Receive data register full */ -#define SCI_ORER 0x20 /* Overrun error */ -#define SCI_FER 0x10 /* Framing error */ -#define SCI_PER 0x08 /* Parity error */ -#define SCI_TEND 0x04 /* Transmit end */ -#define SCI_MPB 0x02 /* Multiprocessor bit */ -#define SCI_MPBT 0x01 /* Multiprocessor bit transfer */ - +#define SCI_TDRE 0x80 /* Transmit data register empty */ +#define SCI_RDRF 0x40 /* Receive data register full */ +#define SCI_ORER 0x20 /* Overrun error */ +#define SCI_FER 0x10 /* Framing error */ +#define SCI_PER 0x08 /* Parity error */ +#define SCI_TEND 0x04 /* Transmit end */ +#define SCI_MPB 0x02 /* Multiprocessor bit */ +#define SCI_MPBT 0x01 /* Multiprocessor bit transfer */ /* * Port B IO Register (PBIOR) */ -#define PBIOR (*(volatile char *)(0x05FFFFC6)) -#define PB15IOR 0x8000 -#define PB14IOR 0x4000 -#define PB13IOR 0x2000 -#define PB12IOR 0x1000 -#define PB11IOR 0x0800 -#define PB10IOR 0x0400 -#define PB9IOR 0x0200 -#define PB8IOR 0x0100 -#define PB7IOR 0x0080 -#define PB6IOR 0x0040 -#define PB5IOR 0x0020 -#define PB4IOR 0x0010 -#define PB3IOR 0x0008 -#define PB2IOR 0x0004 -#define PB1IOR 0x0002 -#define PB0IOR 0x0001 +#define PBIOR (*(volatile char *) (0x05FFFFC6)) +#define PB15IOR 0x8000 +#define PB14IOR 0x4000 +#define PB13IOR 0x2000 +#define PB12IOR 0x1000 +#define PB11IOR 0x0800 +#define PB10IOR 0x0400 +#define PB9IOR 0x0200 +#define PB8IOR 0x0100 +#define PB7IOR 0x0080 +#define PB6IOR 0x0040 +#define PB5IOR 0x0020 +#define PB4IOR 0x0010 +#define PB3IOR 0x0008 +#define PB2IOR 0x0004 +#define PB1IOR 0x0002 +#define PB0IOR 0x0001 /* * Port B Control Register (PBCR1) */ -#define PBCR1 (*(volatile short *)(0x05FFFFCC)) -#define PB15MD1 0x8000 -#define PB15MD0 0x4000 -#define PB14MD1 0x2000 -#define PB14MD0 0x1000 -#define PB13MD1 0x0800 -#define PB13MD0 0x0400 -#define PB12MD1 0x0200 -#define PB12MD0 0x0100 -#define PB11MD1 0x0080 -#define PB11MD0 0x0040 -#define PB10MD1 0x0020 -#define PB10MD0 0x0010 -#define PB9MD1 0x0008 -#define PB9MD0 0x0004 -#define PB8MD1 0x0002 -#define PB8MD0 0x0001 - -#define PB15MD PB15MD1|PB14MD0 -#define PB14MD PB14MD1|PB14MD0 -#define PB13MD PB13MD1|PB13MD0 -#define PB12MD PB12MD1|PB12MD0 -#define PB11MD PB11MD1|PB11MD0 -#define PB10MD PB10MD1|PB10MD0 -#define PB9MD PB9MD1|PB9MD0 -#define PB8MD PB8MD1|PB8MD0 - -#define PB_TXD1 PB11MD1 -#define PB_RXD1 PB10MD1 -#define PB_TXD0 PB9MD1 -#define PB_RXD0 PB8MD1 +#define PBCR1 (*(volatile short *) (0x05FFFFCC)) +#define PB15MD1 0x8000 +#define PB15MD0 0x4000 +#define PB14MD1 0x2000 +#define PB14MD0 0x1000 +#define PB13MD1 0x0800 +#define PB13MD0 0x0400 +#define PB12MD1 0x0200 +#define PB12MD0 0x0100 +#define PB11MD1 0x0080 +#define PB11MD0 0x0040 +#define PB10MD1 0x0020 +#define PB10MD0 0x0010 +#define PB9MD1 0x0008 +#define PB9MD0 0x0004 +#define PB8MD1 0x0002 +#define PB8MD0 0x0001 + +#define PB15MD PB15MD1 | PB14MD0 +#define PB14MD PB14MD1 | PB14MD0 +#define PB13MD PB13MD1 | PB13MD0 +#define PB12MD PB12MD1 | PB12MD0 +#define PB11MD PB11MD1 | PB11MD0 +#define PB10MD PB10MD1 | PB10MD0 +#define PB9MD PB9MD1 | PB9MD0 +#define PB8MD PB8MD1 | PB8MD0 + +#define PB_TXD1 PB11MD1 +#define PB_RXD1 PB10MD1 +#define PB_TXD0 PB9MD1 +#define PB_RXD0 PB8MD1 /* * Port B Control Register (PBCR2) */ -#define PBCR2 0x05FFFFCE -#define PB7MD1 0x8000 -#define PB7MD0 0x4000 -#define PB6MD1 0x2000 -#define PB6MD0 0x1000 -#define PB5MD1 0x0800 -#define PB5MD0 0x0400 -#define PB4MD1 0x0200 -#define PB4MD0 0x0100 -#define PB3MD1 0x0080 -#define PB3MD0 0x0040 -#define PB2MD1 0x0020 -#define PB2MD0 0x0010 -#define PB1MD1 0x0008 -#define PB1MD0 0x0004 -#define PB0MD1 0x0002 -#define PB0MD0 0x0001 - -#define PB7MD PB7MD1|PB7MD0 -#define PB6MD PB6MD1|PB6MD0 -#define PB5MD PB5MD1|PB5MD0 -#define PB4MD PB4MD1|PB4MD0 -#define PB3MD PB3MD1|PB3MD0 -#define PB2MD PB2MD1|PB2MD0 -#define PB1MD PB1MD1|PB1MD0 -#define PB0MD PB0MD1|PB0MD0 - +#define PBCR2 0x05FFFFCE +#define PB7MD1 0x8000 +#define PB7MD0 0x4000 +#define PB6MD1 0x2000 +#define PB6MD0 0x1000 +#define PB5MD1 0x0800 +#define PB5MD0 0x0400 +#define PB4MD1 0x0200 +#define PB4MD0 0x0100 +#define PB3MD1 0x0080 +#define PB3MD0 0x0040 +#define PB2MD1 0x0020 +#define PB2MD0 0x0010 +#define PB1MD1 0x0008 +#define PB1MD0 0x0004 +#define PB0MD1 0x0002 +#define PB0MD0 0x0001 + +#define PB7MD PB7MD1 | PB7MD0 +#define PB6MD PB6MD1 | PB6MD0 +#define PB5MD PB5MD1 | PB5MD0 +#define PB4MD PB4MD1 | PB4MD0 +#define PB3MD PB3MD1 | PB3MD0 +#define PB2MD PB2MD1 | PB2MD0 +#define PB1MD PB1MD1 | PB1MD0 +#define PB0MD PB0MD1 | PB0MD0 #ifdef MHZ -#define BPS 32 * 9600 * MHZ / ( BAUD * 10) +#define BPS 32 * 9600 * MHZ / (BAUD * 10) #else -#define BPS 32 /* 9600 for 10 Mhz */ +#define BPS 32 /* 9600 for 10 Mhz */ #endif void handleError (char theSSR); @@ -1494,90 +1399,89 @@ void handleError (char theSSR); void nop (void) { - } -void + +void init_serial (void) { - int i; +int i; - /* Clear TE and RE in Channel 1's SCR */ - SCR1 &= ~(SCI_TE | SCI_RE); +/* Clear TE and RE in Channel 1's SCR */ +SCR1 &= ~(SCI_TE | SCI_RE); - /* Set communication to be async, 8-bit data, no parity, 1 stop bit and use internal clock */ +/* Set communication to be async, 8-bit data, no parity, 1 stop bit and use internal clock */ - SMR1 = 0; - BRR1 = BPS; +SMR1 = 0; +BRR1 = BPS; - SCR1 &= ~(SCI_CKE1 | SCI_CKE0); +SCR1 &= ~(SCI_CKE1 | SCI_CKE0); - /* let the hardware settle */ +/* let the hardware settle */ - for (i = 0; i < 1000; i++) - nop (); +for (i = 0; i < 1000; i++) + nop (); - /* Turn on in and out */ - SCR1 |= SCI_RE | SCI_TE; +/* Turn on in and out */ +SCR1 |= SCI_RE | SCI_TE; - /* Set the PFC to make RXD1 (pin PB8) an input pin and TXD1 (pin PB9) an output pin */ - PBCR1 &= ~(PB_TXD1 | PB_RXD1); - PBCR1 |= PB_TXD1 | PB_RXD1; +/* Set the PFC to make RXD1 (pin PB8) an input pin and TXD1 (pin PB9) an output pin */ +PBCR1 &= ~(PB_TXD1 | PB_RXD1); +PBCR1 |= PB_TXD1 | PB_RXD1; } - int getDebugCharReady (void) { - char mySSR; - mySSR = SSR1 & ( SCI_PER | SCI_FER | SCI_ORER ); - if ( mySSR ) - handleError ( mySSR ); - return SSR1 & SCI_RDRF ; +char mySSR; +mySSR = SSR1 & (SCI_PER | SCI_FER | SCI_ORER); +if (mySSR) + handleError (mySSR); +return SSR1 & SCI_RDRF; } -char +char getDebugChar (void) { - char ch; - char mySSR; +char ch; +char mySSR; - while ( ! getDebugCharReady()) - ; +while (!getDebugCharReady ()) + ; - ch = RDR1; - SSR1 &= ~SCI_RDRF; +ch = RDR1; +SSR1 &= ~SCI_RDRF; - mySSR = SSR1 & (SCI_PER | SCI_FER | SCI_ORER); +mySSR = SSR1 & (SCI_PER | SCI_FER | SCI_ORER); - if (mySSR) - handleError (mySSR); +if (mySSR) + handleError (mySSR); - return ch; +return ch; } -int +int putDebugCharReady (void) { - return (SSR1 & SCI_TDRE); +return (SSR1 & SCI_TDRE); } void putDebugChar (char ch) { - while (!putDebugCharReady()) - ; +while (!putDebugCharReady ()) + ; - /* +/* * Write data into TDR and clear TDRE */ - TDR1 = ch; - SSR1 &= ~SCI_TDRE; +TDR1 = ch; +SSR1 &= ~SCI_TDRE; } -void +void handleError (char theSSR) { - SSR1 &= ~(SCI_ORER | SCI_PER | SCI_FER); +SSR1 &= ~(SCI_ORER | SCI_PER | SCI_FER); } #endif diff --git a/gdb/stubs/sparc-stub.c b/gdb/stubs/sparc-stub.c index acb7743..6015b02 100644 --- a/gdb/stubs/sparc-stub.c +++ b/gdb/stubs/sparc-stub.c @@ -89,39 +89,106 @@ * external low-level support routines */ -extern void putDebugChar(); /* write a single character */ -extern int getDebugChar(); /* read and return a single char */ +extern void putDebugChar (); /* write a single character */ +extern int getDebugChar (); /* read and return a single char */ /************************************************************************/ /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/ /* at least NUMREGBYTES*2 are needed for register packets */ #define BUFMAX 2048 -static int initialized = 0; /* !0 means we've been initialized */ +static int initialized = 0; /* !0 means we've been initialized */ -static void set_mem_fault_trap(); +static void set_mem_fault_trap (); -static const char hexchars[]="0123456789abcdef"; +static const char hexchars[] = "0123456789abcdef"; #define NUMREGS 72 /* Number of bytes of registers. */ #define NUMREGBYTES (NUMREGS * 4) -enum regnames {G0, G1, G2, G3, G4, G5, G6, G7, - O0, O1, O2, O3, O4, O5, SP, O7, - L0, L1, L2, L3, L4, L5, L6, L7, - I0, I1, I2, I3, I4, I5, FP, I7, - F0, F1, F2, F3, F4, F5, F6, F7, - F8, F9, F10, F11, F12, F13, F14, F15, - F16, F17, F18, F19, F20, F21, F22, F23, - F24, F25, F26, F27, F28, F29, F30, F31, - Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR }; +enum regnames +{ + G0, + G1, + G2, + G3, + G4, + G5, + G6, + G7, + O0, + O1, + O2, + O3, + O4, + O5, + SP, + O7, + L0, + L1, + L2, + L3, + L4, + L5, + L6, + L7, + I0, + I1, + I2, + I3, + I4, + I5, + FP, + I7, + + F0, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, + F22, + F23, + F24, + F25, + F26, + F27, + F28, + F29, + F30, + F31, + Y, + PSR, + WIM, + TBR, + PC, + NPC, + FPSR, + CPSR +}; /*************************** ASSEMBLY CODE MACROS *************************/ /* */ -extern void trap_low(); +extern void trap_low (); asm(" .reserve trapstack, 1000 * 4, \"bss\", 8 @@ -272,11 +339,11 @@ static int hex (unsigned char ch) { if (ch >= 'a' && ch <= 'f') - return ch-'a'+10; + return ch - 'a' + 10; if (ch >= '0' && ch <= '9') - return ch-'0'; + return ch - '0'; if (ch >= 'A' && ch <= 'F') - return ch-'A'+10; + return ch - 'A' + 10; return -1; } @@ -300,7 +367,7 @@ getpacket (void) while ((ch = getDebugChar ()) != '$') ; -retry: + retry: checksum = 0; xmitcsum = -1; count = 0; @@ -328,11 +395,11 @@ retry: if (checksum != xmitcsum) { - putDebugChar ('-'); /* failed checksum */ + putDebugChar ('-'); /* failed checksum */ } else { - putDebugChar ('+'); /* successful transfer */ + putDebugChar ('+'); /* successful transfer */ /* if a sequence char is present, reply the sequence ID */ if (buffer[2] == ':') @@ -361,23 +428,22 @@ putpacket (unsigned char *buffer) /* $<packet info>#<checksum>. */ do { - putDebugChar('$'); + putDebugChar ('$'); checksum = 0; count = 0; while (ch = buffer[count]) { - putDebugChar(ch); + putDebugChar (ch); checksum += ch; count += 1; } - putDebugChar('#'); - putDebugChar(hexchars[checksum >> 4]); - putDebugChar(hexchars[checksum & 0xf]); - + putDebugChar ('#'); + putDebugChar (hexchars[checksum >> 4]); + putDebugChar (hexchars[checksum & 0xf]); } - while (getDebugChar() != '+'); + while (getDebugChar () != '+'); } /* Indicate to caller of mem2hex or hex2mem that there has been an @@ -396,7 +462,7 @@ mem2hex (unsigned char *mem, unsigned char *buf, int count, int may_fault) { unsigned char ch; - set_mem_fault_trap(may_fault); + set_mem_fault_trap (may_fault); while (count-- > 0) { @@ -409,7 +475,7 @@ mem2hex (unsigned char *mem, unsigned char *buf, int count, int may_fault) *buf = 0; - set_mem_fault_trap(0); + set_mem_fault_trap (0); return buf; } @@ -423,18 +489,18 @@ hex2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault) int i; unsigned char ch; - set_mem_fault_trap(may_fault); + set_mem_fault_trap (may_fault); - for (i=0; i<count; i++) + for (i = 0; i < count; i++) { - ch = hex(*buf++) << 4; - ch |= hex(*buf++); + ch = hex (*buf++) << 4; + ch |= hex (*buf++); *mem++ = ch; if (mem_err) return 0; } - set_mem_fault_trap(0); + set_mem_fault_trap (0); return mem; } @@ -445,8 +511,8 @@ hex2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault) static struct hard_trap_info { - unsigned char tt; /* Trap type code for SPARClite */ - unsigned char signo; /* Signal that we map this trap into */ + unsigned char tt; /* Trap type code for SPARClite */ + unsigned char signo; /* Signal that we map this trap into */ } hard_trap_info[] = { {1, SIGSEGV}, /* instruction access error */ {2, SIGILL}, /* privileged instruction */ @@ -468,7 +534,7 @@ set_debug_traps (void) struct hard_trap_info *ht; for (ht = hard_trap_info; ht->tt && ht->signo; ht++) - exceptionHandler(ht->tt, trap_low); + exceptionHandler (ht->tt, trap_low); initialized = 1; } @@ -492,13 +558,13 @@ _fltr_set_mem_err: static void set_mem_fault_trap (int enable) { - extern void fltr_set_mem_err(); + extern void fltr_set_mem_err (); mem_err = 0; if (enable) - exceptionHandler(9, fltr_set_mem_err); + exceptionHandler (9, fltr_set_mem_err); else - exceptionHandler(9, trap_low); + exceptionHandler (9, trap_low); } /* Convert the SPARC hardware trap type code to a unix signal number. */ @@ -512,7 +578,7 @@ computeSignal (int tt) if (ht->tt == tt) return ht->signo; - return SIGHUP; /* default for things we don't know about */ + return SIGHUP; /* default for things we don't know about */ } /* @@ -530,12 +596,12 @@ hexToInt(char **ptr, int *intValue) while (**ptr) { - hexValue = hex(**ptr); + hexValue = hex (**ptr); if (hexValue < 0) break; *intValue = (*intValue << 4) | hexValue; - numChars ++; + numChars++; (*ptr)++; } @@ -554,14 +620,14 @@ extern void breakinst(); static void handle_exception (unsigned long *registers) { - int tt; /* Trap type */ + int tt; /* Trap type */ int sigval; int addr; int length; char *ptr; unsigned long *sp; -/* First, we must force all of the windows to be spilled out */ + /* First, we must force all of the windows to be spilled out */ asm(" save %sp, -64, %sp save %sp, -64, %sp @@ -583,8 +649,8 @@ handle_exception (unsigned long *registers) if (registers[PC] == (unsigned long)breakinst) { - registers[PC] = registers[NPC]; - registers[NPC] += 4; + registers[PC] = registers[NPC]; + registers[NPC] += 4; } sp = (unsigned long *)registers[SP]; @@ -635,128 +701,123 @@ handle_exception (unsigned long *registers) while (1) { - remcomOutBuffer[0] = 0; - - ptr = getpacket(); - switch (*ptr++) - { - case '?': - remcomOutBuffer[0] = 'S'; - remcomOutBuffer[1] = hexchars[sigval >> 4]; - remcomOutBuffer[2] = hexchars[sigval & 0xf]; - remcomOutBuffer[3] = 0; - break; + remcomOutBuffer[0] = 0; + + ptr = getpacket (); + switch (*ptr++) + { + case '?': + remcomOutBuffer[0] = 'S'; + remcomOutBuffer[1] = hexchars[sigval >> 4]; + remcomOutBuffer[2] = hexchars[sigval & 0xf]; + remcomOutBuffer[3] = 0; + break; - case 'd': /* toggle debug flag */ - break; + case 'd': /* toggle debug flag */ + break; - case 'g': /* return the value of the CPU registers */ - { - ptr = remcomOutBuffer; - ptr = mem2hex((char *)registers, ptr, 16 * 4, 0); /* G & O regs */ - ptr = mem2hex(sp + 0, ptr, 16 * 4, 0); /* L & I regs */ - memset(ptr, '0', 32 * 8); /* Floating point */ - mem2hex((char *)®isters[Y], - ptr + 32 * 4 * 2, - 8 * 4, - 0); /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */ - } - break; + case 'g': /* return the value of the CPU registers */ + { + ptr = remcomOutBuffer; + ptr = mem2hex ((char *) registers, ptr, 16 * 4, 0); /* G & O regs */ + ptr = mem2hex (sp + 0, ptr, 16 * 4, 0); /* L & I regs */ + memset (ptr, '0', 32 * 8); /* Floating point */ + mem2hex ((char *) ®isters[Y], ptr + 32 * 4 * 2, 8 * 4, + 0); /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */ + } + break; - case 'G': /* set the value of the CPU registers - return OK */ - { - unsigned long *newsp, psr; + case 'G': /* set the value of the CPU registers - return OK */ + { + unsigned long *newsp, psr; - psr = registers[PSR]; + psr = registers[PSR]; - hex2mem(ptr, (char *)registers, 16 * 4, 0); /* G & O regs */ - hex2mem(ptr + 16 * 4 * 2, sp + 0, 16 * 4, 0); /* L & I regs */ - hex2mem(ptr + 64 * 4 * 2, (char *)®isters[Y], - 8 * 4, 0); /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */ + hex2mem (ptr, (char *) registers, 16 * 4, 0); /* G & O regs */ + hex2mem (ptr + 16 * 4 * 2, sp + 0, 16 * 4, 0); /* L & I regs */ + hex2mem (ptr + 64 * 4 * 2, (char *) ®isters[Y], 8 * 4, + 0); /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */ - /* See if the stack pointer has moved. If so, then copy the saved + /* See if the stack pointer has moved. If so, then copy the saved locals and ins to the new location. This keeps the window overflow and underflow routines happy. */ - newsp = (unsigned long *)registers[SP]; - if (sp != newsp) - sp = memcpy(newsp, sp, 16 * 4); + newsp = (unsigned long *) registers[SP]; + if (sp != newsp) + sp = memcpy (newsp, sp, 16 * 4); - /* Don't allow CWP to be modified. */ + /* Don't allow CWP to be modified. */ - if (psr != registers[PSR]) - registers[PSR] = (psr & 0x1f) | (registers[PSR] & ~0x1f); + if (psr != registers[PSR]) + registers[PSR] = (psr & 0x1f) | (registers[PSR] & ~0x1f); - strcpy(remcomOutBuffer,"OK"); - } - break; + strcpy (remcomOutBuffer, "OK"); + } + break; - case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ - /* Try to read %x,%x. */ + case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ + /* Try to read %x,%x. */ - if (hexToInt(&ptr, &addr) - && *ptr++ == ',' - && hexToInt(&ptr, &length)) - { - if (mem2hex((char *)addr, remcomOutBuffer, length, 1)) - break; + if (hexToInt (&ptr, &addr) && *ptr++ == ',' + && hexToInt (&ptr, &length)) + { + if (mem2hex ((char *) addr, remcomOutBuffer, length, 1)) + break; - strcpy (remcomOutBuffer, "E03"); - } - else - strcpy(remcomOutBuffer,"E01"); - break; + strcpy (remcomOutBuffer, "E03"); + } + else + strcpy (remcomOutBuffer, "E01"); + break; - case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ - /* Try to read '%x,%x:'. */ + case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ + /* Try to read '%x,%x:'. */ - if (hexToInt(&ptr, &addr) - && *ptr++ == ',' - && hexToInt(&ptr, &length) - && *ptr++ == ':') - { - if (hex2mem(ptr, (char *)addr, length, 1)) - strcpy(remcomOutBuffer, "OK"); - else - strcpy(remcomOutBuffer, "E03"); - } - else - strcpy(remcomOutBuffer, "E02"); - break; + if (hexToInt (&ptr, &addr) && *ptr++ == ',' && hexToInt (&ptr, &length) + && *ptr++ == ':') + { + if (hex2mem (ptr, (char *) addr, length, 1)) + strcpy (remcomOutBuffer, "OK"); + else + strcpy (remcomOutBuffer, "E03"); + } + else + strcpy (remcomOutBuffer, "E02"); + break; - case 'c': /* cAA..AA Continue at address AA..AA(optional) */ - /* try to read optional parameter, pc unchanged if no parm */ + case 'c': /* cAA..AA Continue at address AA..AA(optional) */ + /* try to read optional parameter, pc unchanged if no parm */ - if (hexToInt(&ptr, &addr)) - { - registers[PC] = addr; - registers[NPC] = addr + 4; - } + if (hexToInt (&ptr, &addr)) + { + registers[PC] = addr; + registers[NPC] = addr + 4; + } -/* Need to flush the instruction cache here, as we may have deposited a + /* Need to flush the instruction cache here, as we may have deposited a breakpoint, and the icache probably has no way of knowing that a data ref to some location may have changed something that is in the instruction cache. */ - flush_i_cache(); - return; + flush_i_cache (); + return; - /* kill the program */ - case 'k' : /* do nothing */ - break; + /* kill the program */ + case 'k': /* do nothing */ + break; #if 0 case 't': /* Test feature */ asm (" std %f30,[%sp]"); break; #endif - case 'r': /* Reset */ + case 'r': /* Reset */ asm ("call 0 nop "); break; - } /* switch */ + } /* switch */ - /* reply to the request */ - putpacket(remcomOutBuffer); + /* reply to the request */ + putpacket (remcomOutBuffer); } } diff --git a/gdb/stubs/z80-stub.c b/gdb/stubs/z80-stub.c index c85b28c..bd4525d 100644 --- a/gdb/stubs/z80-stub.c +++ b/gdb/stubs/z80-stub.c @@ -167,16 +167,16 @@ void debug_nmi (void); */ void debug_int (void); -#define EX_SWBREAK 0 /* sw breakpoint */ -#define EX_HWBREAK -1 /* hw breakpoint */ -#define EX_WWATCH -2 /* memory write watch */ -#define EX_RWATCH -3 /* memory read watch */ -#define EX_AWATCH -4 /* memory access watch */ -#define EX_SIGINT 2 -#define EX_SIGTRAP 5 -#define EX_SIGABRT 6 -#define EX_SIGBUS 10 -#define EX_SIGSEGV 11 +#define EX_SWBREAK 0 /* sw breakpoint */ +#define EX_HWBREAK -1 /* hw breakpoint */ +#define EX_WWATCH -2 /* memory write watch */ +#define EX_RWATCH -3 /* memory read watch */ +#define EX_AWATCH -4 /* memory access watch */ +#define EX_SIGINT 2 +#define EX_SIGTRAP 5 +#define EX_SIGABRT 6 +#define EX_SIGBUS 10 +#define EX_SIGSEGV 11 /* or any standard *nix signal value */ /* Enter to debug mode (after receiving BREAK from GDB, for example) @@ -188,7 +188,7 @@ void debug_int (void); void debug_exception (int ex); /* Prints to debugger console. */ -void debug_print(const char *str); +void debug_print (const char *str); /******************************************************************************\ Required functions \******************************************************************************/ @@ -197,12 +197,12 @@ extern int getDebugChar (void); extern void putDebugChar (int ch); #ifdef DBG_SWBREAK -#define DO_EXPAND(VAL) VAL ## 123456 -#define EXPAND(VAL) DO_EXPAND(VAL) +#define DO_EXPAND(VAL) VAL##123456 +#define EXPAND(VAL) DO_EXPAND (VAL) #if EXPAND(DBG_SWBREAK) != 123456 #define DBG_SWBREAK_PROC DBG_SWBREAK -extern int DBG_SWBREAK(int set, void *addr); +extern int DBG_SWBREAK (int set, void *addr); #endif #undef EXPAND @@ -210,23 +210,23 @@ extern int DBG_SWBREAK(int set, void *addr); #endif /* DBG_SWBREAK */ #ifdef DBG_HWBREAK -extern int DBG_HWBREAK(int set, void *addr); +extern int DBG_HWBREAK (int set, void *addr); #endif #ifdef DBG_MEMCPY -extern void* DBG_MEMCPY (void *dest, const void *src, unsigned n); +extern void *DBG_MEMCPY (void *dest, const void *src, unsigned n); #endif #ifdef DBG_WWATCH -extern int DBG_WWATCH(int set, void *addr, unsigned size); +extern int DBG_WWATCH (int set, void *addr, unsigned size); #endif #ifdef DBG_RWATCH -extern int DBG_RWATCH(int set, void *addr, unsigned size); +extern int DBG_RWATCH (int set, void *addr, unsigned size); #endif #ifdef DBG_AWATCH -extern int DBG_AWATCH(int set, void *addr, unsigned size); +extern int DBG_AWATCH (int set, void *addr, unsigned size); #endif /******************************************************************************\ @@ -236,7 +236,7 @@ extern int DBG_AWATCH(int set, void *addr, unsigned size); #include <string.h> #ifndef NULL -# define NULL (void*)0 +#define NULL (void *) 0 #endif typedef unsigned char byte; @@ -244,40 +244,40 @@ typedef unsigned short word; /* CPU state */ #ifdef __SDCC_ez80_adl -# define REG_SIZE 3 +#define REG_SIZE 3 #else -# define REG_SIZE 2 +#define REG_SIZE 2 #endif /* __SDCC_ez80_adl */ -#define R_AF (0*REG_SIZE) -#define R_BC (1*REG_SIZE) -#define R_DE (2*REG_SIZE) -#define R_HL (3*REG_SIZE) -#define R_SP (4*REG_SIZE) -#define R_PC (5*REG_SIZE) +#define R_AF (0 * REG_SIZE) +#define R_BC (1 * REG_SIZE) +#define R_DE (2 * REG_SIZE) +#define R_HL (3 * REG_SIZE) +#define R_SP (4 * REG_SIZE) +#define R_PC (5 * REG_SIZE) #ifndef __SDCC_gbz80 -#define R_IX (6*REG_SIZE) -#define R_IY (7*REG_SIZE) -#define R_AF_ (8*REG_SIZE) -#define R_BC_ (9*REG_SIZE) -#define R_DE_ (10*REG_SIZE) -#define R_HL_ (11*REG_SIZE) -#define R_IR (12*REG_SIZE) +#define R_IX (6 * REG_SIZE) +#define R_IY (7 * REG_SIZE) +#define R_AF_ (8 * REG_SIZE) +#define R_BC_ (9 * REG_SIZE) +#define R_DE_ (10 * REG_SIZE) +#define R_HL_ (11 * REG_SIZE) +#define R_IR (12 * REG_SIZE) #ifdef __SDCC_ez80_adl -#define R_SPS (13*REG_SIZE) -#define NUMREGBYTES (14*REG_SIZE) +#define R_SPS (13 * REG_SIZE) +#define NUMREGBYTES (14 * REG_SIZE) #else -#define NUMREGBYTES (13*REG_SIZE) +#define NUMREGBYTES (13 * REG_SIZE) #endif /* __SDCC_ez80_adl */ #else -#define NUMREGBYTES (6*REG_SIZE) +#define NUMREGBYTES (6 * REG_SIZE) #define FASTCALL #endif /*__SDCC_gbz80 */ static byte state[NUMREGBYTES]; -#if DBG_PACKET_SIZE < (NUMREGBYTES*2+5) +#if DBG_PACKET_SIZE < (NUMREGBYTES * 2 + 5) #error "Too small DBG_PACKET_SIZE" #endif @@ -288,7 +288,7 @@ static byte state[NUMREGBYTES]; /* dedicated stack */ #ifdef DBG_STACK_SIZE -#define LOAD_SP ld sp, #_stack + DBG_STACK_SIZE +#define LOAD_SP ld sp, #_stack + DBG_STACK_SIZE static char stack[DBG_STACK_SIZE]; @@ -326,22 +326,15 @@ static void rest_cpu_state (void); void debug_swbreak (void) __naked { - __asm - ld (#_state + R_SP), sp - LOAD_SP - call _save_cpu_state - ld hl, #-DBG_SWBREAK_SIZE - push hl - ld hl, #EX_SWBREAK - push hl - call _stub_main - .globl _break_handler + __asm ld (#_state + R_SP), sp LOAD_SP call _save_cpu_state ld hl, +#- DBG_SWBREAK_SIZE push hl ld hl, +#EX_SWBREAK push hl call _stub_main.globl _break_handler #ifdef DBG_SWBREAK_RST -_break_handler = DBG_SWBREAK_RST + _break_handler = DBG_SWBREAK_RST #else -_break_handler = _debug_swbreak + _break_handler = _debug_swbreak #endif - __endasm; + __endasm; } #endif /* DBG_SWBREAK */ /******************************************************************************/ @@ -352,94 +345,58 @@ _break_handler = _debug_swbreak void debug_hwbreak (void) __naked { - __asm - ld (#_state + R_SP), sp - LOAD_SP - call _save_cpu_state - ld hl, #-DBG_HWBREAK_SIZE - push hl - ld hl, #EX_HWBREAK - push hl - call _stub_main - __endasm; + __asm ld (#_state + R_SP), sp LOAD_SP call _save_cpu_state ld hl, +#- DBG_HWBREAK_SIZE push hl ld hl, +#EX_HWBREAK push hl call _stub_main __endasm; } #endif /* DBG_HWBREAK_SET */ /******************************************************************************/ void debug_exception (int ex) __naked { - __asm - ld (#_state + R_SP), sp - LOAD_SP - call _save_cpu_state - ld hl, #0 - push hl + __asm ld (#_state + R_SP), sp LOAD_SP call _save_cpu_state ld hl, +# 0 push hl #ifdef __SDCC_gbz80 - ld hl, #_state + R_SP - ld a, (hl+) - ld h, (hl) - ld l, a + ld hl, +#_state + R_SP ld a, (hl +) ld h, (hl) ld l, + a #else - ld hl, (#_state + R_SP) + ld hl, + (#_state + R_SP) #endif - inc hl - inc hl - ld e, (hl) - inc hl - ld d, (hl) - push de - call _stub_main - __endasm; - (void)ex; + inc hl inc hl ld e, + (hl) inc hl ld d, (hl) push de call _stub_main __endasm; + (void) ex; } + /******************************************************************************/ #ifndef __SDCC_gbz80 void -debug_nmi(void) __naked +debug_nmi (void) __naked { - __asm - ld (#_state + R_SP), sp - LOAD_SP - call _save_cpu_state - ld hl, #0 ;pc_adj - push hl - ld hl, #DBG_NMI_EX - push hl - ld hl, #_stub_main - push hl - push hl - retn - __endasm; + __asm ld (#_state + R_SP), sp LOAD_SP call _save_cpu_state ld hl, #0; + pc_adj push hl ld hl, #DBG_NMI_EX push hl ld hl, +#_stub_main push hl push hl retn __endasm; } #endif /******************************************************************************/ void -debug_int(void) __naked +debug_int (void) __naked { - __asm - ld (#_state + R_SP), sp - LOAD_SP - call _save_cpu_state - ld hl, #0 ;pc_adj - push hl - ld hl, #DBG_INT_EX - push hl - ld hl, #_stub_main - push hl - push hl - ei - reti - __endasm; + __asm ld (#_state + R_SP), sp LOAD_SP call _save_cpu_state ld hl, #0; + pc_adj push hl ld hl, #DBG_INT_EX push hl ld hl, +#_stub_main push hl push hl ei reti __endasm; } + /******************************************************************************/ #ifdef DBG_PRINT void -debug_print(const char *str) +debug_print (const char *str) { putDebugChar ('$'); putDebugChar ('O'); char csum = 'O'; - for (; *str != '\0'; ) + for (; *str != '\0';) { char c = high_hex (*str); csum += c; @@ -455,11 +412,16 @@ debug_print(const char *str) #endif /* DBG_PRINT */ /******************************************************************************/ static void store_pc_sp (int pc_adj) FASTCALL; -#define get_reg_value(mem) (*(void* const*)(mem)) -#define set_reg_value(mem,val) do { (*(void**)(mem) = (val)); } while (0) -static char* byte2hex(char *buf, byte val); +#define get_reg_value(mem) (*(void *const *) (mem)) +#define set_reg_value(mem, val) \ + do \ + { \ + (*(void **) (mem) = (val)); \ + } \ + while (0) +static char *byte2hex (char *buf, byte val); static int hex2int (const char **buf) FASTCALL; -static char* int2hex (char *buf, int v); +static char *int2hex (char *buf, int v); static void get_packet (char *buffer); static void put_packet (const char *buffer); static char process (char *buffer) FASTCALL; @@ -468,8 +430,8 @@ static void rest_cpu_state (void); static void stub_main (int ex, int pc_adj) { - char buffer[DBG_PACKET_SIZE+1]; - sigval = (signed char)ex; + char buffer[DBG_PACKET_SIZE + 1]; + sigval = (signed char) ex; store_pc_sp (pc_adj); DBG_ENTER @@ -500,8 +462,9 @@ get_packet (char *buffer) for (;; putDebugChar ('-')) { /* wait for packet start character */ - while (getDebugChar () != '$'); -retry: + while (getDebugChar () != '$') + ; + retry: csum = 0; esc = 0; p = buffer; @@ -526,7 +489,7 @@ retry: csum += ch; } while (count != 0); -finish: + finish: *p = '\0'; if (ch != '#') /* packet is too large */ continue; @@ -550,15 +513,17 @@ put_packet (const char *buffer) putDebugChar ('$'); char checksum = put_packet_info (buffer); putDebugChar ('#'); - putDebugChar (high_hex(checksum)); - putDebugChar (low_hex(checksum)); + putDebugChar (high_hex (checksum)); + putDebugChar (low_hex (checksum)); for (;;) { char c = getDebugChar (); switch (c) { - case '+': return; - case '-': break; + case '+': + return; + case '-': + break; default: putDebugChar (c); continue; @@ -617,7 +582,7 @@ process_question (char *p) FASTCALL sig = sigval; if (sig <= 0) sig = EX_SIGTRAP; - p = byte2hex (p, (byte)sig); + p = byte2hex (p, (byte) sig); *p = '\0'; return 0; } @@ -632,11 +597,12 @@ process_question (char *p) FASTCALL sig = sigval; if (sig <= 0) sig = EX_SIGTRAP; - p = byte2hex (p, (byte)sig); - p = format_reg_value(p, R_AF/REG_SIZE, &state[R_AF]); - p = format_reg_value(p, R_SP/REG_SIZE, &state[R_SP]); - p = format_reg_value(p, R_PC/REG_SIZE, &state[R_PC]); -#if defined(DBG_SWBREAK_PROC) || defined(DBG_HWBREAK) || defined(DBG_WWATCH) || defined(DBG_RWATCH) || defined(DBG_AWATCH) + p = byte2hex (p, (byte) sig); + p = format_reg_value (p, R_AF / REG_SIZE, &state[R_AF]); + p = format_reg_value (p, R_SP / REG_SIZE, &state[R_SP]); + p = format_reg_value (p, R_PC / REG_SIZE, &state[R_PC]); +#if defined(DBG_SWBREAK_PROC) || defined(DBG_HWBREAK) || defined(DBG_WWATCH) \ + || defined(DBG_RWATCH) || defined(DBG_AWATCH) const char *reason; unsigned addr = 0; switch (sigval) @@ -677,7 +643,7 @@ process_question (char *p) FASTCALL --p; *p++ = ':'; if (addr != 0) - p = int2hex(p, addr); + p = int2hex (p, addr); *p++ = ';'; finish: #endif /* DBG_HWBREAK, DBG_WWATCH, DBG_RWATCH, DBG_AWATCH */ @@ -687,8 +653,8 @@ finish: #endif /* DBG_MINSIZE */ #define STRING2(x) #x -#define STRING1(x) STRING2(x) -#define STRING(x) STRING1(x) +#define STRING1(x) STRING2 (x) +#define STRING(x) STRING1 (x) #ifdef DBG_MEMORY_MAP static void read_memory_map (char *buffer, unsigned offset, unsigned length); #endif @@ -743,7 +709,7 @@ process_q (char *buffer) FASTCALL { /* Just report that GDB attached to existing process if it is not applicable for you, then send patches */ - memcpy(buffer, "1", 2); + memcpy (buffer, "1", 2); return 0; } #endif /* DBG_MIN_SIZE */ @@ -769,25 +735,25 @@ process_G (char *buffer) FASTCALL static signed char process_m (char *buffer) FASTCALL -{/* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ +{ /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ char *p = &buffer[1]; - byte *addr = (void*)hex2int(&p); + byte *addr = (void *) hex2int (&p); if (*p++ != ',') return 1; - unsigned len = (unsigned)hex2int(&p); + unsigned len = (unsigned) hex2int (&p); if (len == 0) return 2; - if (len > DBG_PACKET_SIZE/2) + if (len > DBG_PACKET_SIZE / 2) return 3; p = buffer; #ifdef DBG_MEMCPY do { byte tmp[16]; - unsigned tlen = sizeof(tmp); + unsigned tlen = sizeof (tmp); if (tlen > len) tlen = len; - if (!DBG_MEMCPY(tmp, addr, tlen)) + if (!DBG_MEMCPY (tmp, addr, tlen)) return 4; p = mem2hex (p, tmp, tlen); addr += tlen; @@ -802,31 +768,31 @@ process_m (char *buffer) FASTCALL static signed char process_M (char *buffer) FASTCALL -{/* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ +{ /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ char *p = &buffer[1]; - byte *addr = (void*)hex2int(&p); + byte *addr = (void *) hex2int (&p); if (*p != ',') return 1; ++p; - unsigned len = (unsigned)hex2int(&p); + unsigned len = (unsigned) hex2int (&p); if (*p++ != ':') return 2; if (len == 0) goto end; - if (len*2 + (p - buffer) > DBG_PACKET_SIZE) + if (len * 2 + (p - buffer) > DBG_PACKET_SIZE) return 3; #ifdef DBG_MEMCPY do { byte tmp[16]; - unsigned tlen = sizeof(tmp); + unsigned tlen = sizeof (tmp); if (tlen > len) tlen = len; p = hex2mem (tmp, p, tlen); - if (!DBG_MEMCPY(addr, tmp, tlen)) + if (!DBG_MEMCPY (addr, tmp, tlen)) return 4; addr += tlen; - len -= tlen; + len -= tlen; } while (len); #else @@ -841,13 +807,13 @@ end: #ifndef DBG_MIN_SIZE static signed char process_X (char *buffer) FASTCALL -{/* XAA..AA,LLLL: Write LLLL binary bytes at address AA.AA return OK */ +{ /* XAA..AA,LLLL: Write LLLL binary bytes at address AA.AA return OK */ char *p = &buffer[1]; - byte *addr = (void*)hex2int(&p); + byte *addr = (void *) hex2int (&p); if (*p != ',') return 1; ++p; - unsigned len = (unsigned)hex2int(&p); + unsigned len = (unsigned) hex2int (&p); if (*p++ != ':') return 2; if (len == 0) @@ -855,7 +821,7 @@ process_X (char *buffer) FASTCALL if (len + (p - buffer) > DBG_PACKET_SIZE) return 3; #ifdef DBG_MEMCPY - if (!DBG_MEMCPY(addr, p, len)) + if (!DBG_MEMCPY (addr, p, len)) return 4; #else memcpy (addr, p, len); @@ -865,22 +831,22 @@ end: *buffer = '\0'; return 0; } -#else /* DBG_MIN_SIZE */ +#else /* DBG_MIN_SIZE */ static signed char process_X (char *buffer) FASTCALL { - (void)buffer; + (void) buffer; return -1; } #endif /* DBG_MIN_SIZE */ static signed char process_c (char *buffer) FASTCALL -{/* 'cAAAA' - Continue at address AAAA(optional) */ +{ /* 'cAAAA' - Continue at address AAAA(optional) */ const char *p = &buffer[1]; if (*p != '\0') { - void *addr = (void*)hex2int(&p); + void *addr = (void *) hex2int (&p); set_reg_value (&state[R_PC], addr); } rest_cpu_state (); @@ -889,17 +855,17 @@ process_c (char *buffer) FASTCALL static signed char process_D (char *buffer) FASTCALL -{/* 'D' - detach the program: continue execution */ +{ /* 'D' - detach the program: continue execution */ *buffer = '\0'; return -2; } static signed char process_k (char *buffer) FASTCALL -{/* 'k' - Kill the program */ +{ /* 'k' - Kill the program */ set_reg_value (&state[R_PC], 0); rest_cpu_state (); - (void)buffer; + (void) buffer; return 0; } @@ -920,7 +886,7 @@ process_v (char *buffer) FASTCALL if (buffer[5] == ';' && (buffer[6] == 'c' || buffer[6] == 'C')) return -2; /* resume execution */ return 1; - } + } #endif /* DBG_MIN_SIZE */ return -1; } @@ -928,42 +894,42 @@ process_v (char *buffer) FASTCALL static signed char process_zZ (char *buffer) FASTCALL { /* insert/remove breakpoint */ -#if defined(DBG_SWBREAK_PROC) || defined(DBG_HWBREAK) || \ - defined(DBG_WWATCH) || defined(DBG_RWATCH) || defined(DBG_AWATCH) +#if defined(DBG_SWBREAK_PROC) || defined(DBG_HWBREAK) || defined(DBG_WWATCH) \ + || defined(DBG_RWATCH) || defined(DBG_AWATCH) const byte set = (*buffer == 'Z'); const char *p = &buffer[3]; - void *addr = (void*)hex2int(&p); + void *addr = (void *) hex2int (&p); if (*p != ',') return 1; p++; - int kind = hex2int(&p); + int kind = hex2int (&p); *buffer = '\0'; switch (buffer[1]) { #ifdef DBG_SWBREAK_PROC case '0': /* sw break */ - return DBG_SWBREAK_PROC(set, addr); + return DBG_SWBREAK_PROC (set, addr); #endif #ifdef DBG_HWBREAK case '1': /* hw break */ - return DBG_HWBREAK(set, addr); + return DBG_HWBREAK (set, addr); #endif #ifdef DBG_WWATCH case '2': /* write watch */ - return DBG_WWATCH(set, addr, kind); + return DBG_WWATCH (set, addr, kind); #endif #ifdef DBG_RWATCH case '3': /* read watch */ - return DBG_RWATCH(set, addr, kind); + return DBG_RWATCH (set, addr, kind); #endif #ifdef DBG_AWATCH case '4': /* access watch */ - return DBG_AWATCH(set, addr, kind); + return DBG_AWATCH (set, addr, kind); #endif default:; /* not supported */ } #endif - (void)buffer; + (void) buffer; return -1; } @@ -972,20 +938,34 @@ do_process (char *buffer) FASTCALL { switch (*buffer) { - case '?': return process_question (buffer); - case 'G': return process_G (buffer); - case 'k': return process_k (buffer); - case 'M': return process_M (buffer); - case 'X': return process_X (buffer); - case 'Z': return process_zZ (buffer); - case 'c': return process_c (buffer); - case 'D': return process_D (buffer); - case 'g': return process_g (buffer); - case 'm': return process_m (buffer); - case 'q': return process_q (buffer); - case 'v': return process_v (buffer); - case 'z': return process_zZ (buffer); - default: return -1; /* empty response */ + case '?': + return process_question (buffer); + case 'G': + return process_G (buffer); + case 'k': + return process_k (buffer); + case 'M': + return process_M (buffer); + case 'X': + return process_X (buffer); + case 'Z': + return process_zZ (buffer); + case 'c': + return process_c (buffer); + case 'D': + return process_D (buffer); + case 'g': + return process_g (buffer); + case 'm': + return process_m (buffer); + case 'q': + return process_q (buffer); + case 'v': + return process_v (buffer); + case 'z': + return process_zZ (buffer); + default: + return -1; /* empty response */ } } @@ -1011,7 +991,7 @@ process (char *buffer) FASTCALL *p = '\0'; } else if (*p == '\0') - memcpy(p, "OK", 3); + memcpy (p, "OK", 3); return ret; } @@ -1040,7 +1020,7 @@ hex2byte (const char *p) FASTCALL signed char l = hex2val (p[1]); if (h < 0 || l < 0) return -1; - return (byte)((byte)h << 4) | (byte)l; + return (byte) ((byte) h << 4) | (byte) l; } static int @@ -1049,32 +1029,32 @@ hex2int (const char **buf) FASTCALL word r = 0; for (;; (*buf)++) { - signed char a = hex2val(**buf); + signed char a = hex2val (**buf); if (a < 0) break; r <<= 4; - r += (byte)a; + r += (byte) a; } - return (int)r; + return (int) r; } static char * int2hex (char *buf, int v) { - buf = byte2hex(buf, (word)v >> 8); - return byte2hex(buf, (byte)v); + buf = byte2hex (buf, (word) v >> 8); + return byte2hex (buf, (byte) v); } static char high_hex (byte v) FASTCALL { - return low_hex(v >> 4); + return low_hex (v >> 4); } static char low_hex (byte v) FASTCALL { -/* + /* __asm ld a, l and a, #0x0f @@ -1088,7 +1068,7 @@ low_hex (byte v) FASTCALL */ v &= 0x0f; v += '0'; - if (v < '9'+1) + if (v < '9' + 1) return v; return v + 'a' - '0' - 10; } @@ -1134,7 +1114,7 @@ static void read_memory_map (char *buffer, unsigned offset, unsigned length) { const char *map = DBG_MEMORY_MAP; - const unsigned map_sz = strlen(map); + const unsigned map_sz = strlen (map); if (offset >= map_sz) { buffer[0] = 'l'; @@ -1145,7 +1125,7 @@ read_memory_map (char *buffer, unsigned offset, unsigned length) length = map_sz - offset; buffer[0] = 'm'; memcpy (&buffer[1], &map[offset], length); - buffer[1+length] = '\0'; + buffer[1 + length] = '\0'; } #endif @@ -1156,13 +1136,13 @@ format_reg_value (char *p, unsigned reg_num, const byte *value) { char *d = p; unsigned char i; - d = byte2hex(d, reg_num); + d = byte2hex (d, reg_num); *d++ = ':'; value += REG_SIZE; i = REG_SIZE; do { - d = byte2hex(d, *--value); + d = byte2hex (d, *--value); } while (--i != 0); *d++ = ';'; @@ -1173,133 +1153,69 @@ format_reg_value (char *p, unsigned reg_num, const byte *value) #ifdef __SDCC_gbz80 /* saves all state.except PC and SP */ static void -save_cpu_state() __naked +save_cpu_state () __naked { - __asm - push af - ld a, l - ld (#_state + R_HL + 0), a - ld a, h - ld (#_state + R_HL + 1), a - ld hl, #_state + R_HL - 1 - ld (hl), d - dec hl - ld (hl), e - dec hl - ld (hl), b - dec hl - ld (hl), c - dec hl - pop bc - ld (hl), b - dec hl - ld (hl), c - ret - __endasm; + __asm push af ld a, l ld (#_state + R_HL + 0), a ld a, + h ld (#_state + R_HL + 1), a ld hl, #_state + R_HL - 1 ld (hl), + d dec hl ld (hl), e dec hl ld (hl), b dec hl ld (hl), + c dec hl pop bc ld (hl), b dec hl ld (hl), c ret __endasm; } /* restore CPU state and continue execution */ static void -rest_cpu_state() __naked +rest_cpu_state () __naked { - __asm -;restore SP - ld a, (#_state + R_SP + 0) - ld l,a - ld a, (#_state + R_SP + 1) - ld h,a - ld sp, hl -;push PC value as return address - ld a, (#_state + R_PC + 0) - ld l, a - ld a, (#_state + R_PC + 1) - ld h, a - push hl -;restore registers - ld hl, #_state + R_AF - ld c, (hl) - inc hl - ld b, (hl) - inc hl - push bc - ld c, (hl) - inc hl - ld b, (hl) - inc hl - ld e, (hl) - inc hl - ld d, (hl) - inc hl - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - pop af - ret - __endasm; + __asm; + restore SP ld a, (#_state + R_SP + 0) ld l, a ld a, + (#_state + R_SP + 1) ld h, a ld sp, hl; + push PC value as return address ld a, (#_state + R_PC + 0) ld l, a ld a, + (#_state + R_PC + 1) ld h, a push hl; + restore registers ld hl, #_state + R_AF ld c, (hl) inc hl ld b, + (hl) inc hl push bc ld c, (hl) inc hl ld b, (hl) inc hl ld e, + (hl) inc hl ld d, (hl) inc hl ld a, (hl) inc hl ld h, (hl) ld l, + a pop af ret __endasm; } #else /* saves all state.except PC and SP */ static void -save_cpu_state() __naked +save_cpu_state () __naked { - __asm - ld (#_state + R_HL), hl - ld (#_state + R_DE), de - ld (#_state + R_BC), bc - push af - pop hl - ld (#_state + R_AF), hl - ld a, r ;R is increased by 7 or by 8 if called via RST - ld l, a - sub a, #7 - xor a, l - and a, #0x7f - xor a, l + __asm ld (#_state + R_HL), hl ld (#_state + R_DE), de ld (#_state + R_BC), + bc push af pop hl ld (#_state + R_AF), hl ld a, r; + R is increased by 7 or by 8 if called via RST ld l, a sub a, #7 xor a, + l and a, #0x7f xor a, + l #ifdef __SDCC_ez80_adl - ld hl, i - ex de, hl - ld hl, #_state + R_IR - ld (hl), a - inc hl - ld (hl), e - inc hl - ld (hl), d - ld a, MB - ld (#_state + R_AF+2), a + ld hl, + i ex de, hl ld hl, #_state + R_IR ld (hl), a inc hl ld (hl), + e inc hl ld (hl), d ld a, MB ld (#_state + R_AF + 2), + a #else - ld l, a - ld a, i - ld h, a - ld (#_state + R_IR), hl + ld l, + a ld a, i ld h, a ld (#_state + R_IR), + hl #endif /* __SDCC_ez80_adl */ - ld (#_state + R_IX), ix - ld (#_state + R_IY), iy - ex af, af' ;' - exx - ld (#_state + R_HL_), hl - ld (#_state + R_DE_), de - ld (#_state + R_BC_), bc - push af - pop hl - ld (#_state + R_AF_), hl - ret - __endasm; + ld (#_state + R_IX), + ix ld (#_state + R_IY), iy ex af, af ' ;' exx ld (#_state + R_HL_), + hl ld (#_state + R_DE_), de ld (#_state + R_BC_), + bc push af pop hl ld (#_state + R_AF_), hl ret __endasm; } /* restore CPU state and continue execution */ static void -rest_cpu_state() __naked +rest_cpu_state () __naked { __asm #ifdef DBG_USE_TRAMPOLINE - ld sp, _stack + DBG_STACK_SIZE - ld hl, (#_state + R_PC) - push hl /* resume address */ + ld sp, + _stack + DBG_STACK_SIZE ld hl, + (#_state + R_PC) push hl /* resume address */ #ifdef __SDCC_ez80_adl - ld hl, 0xc30000 ; use 0xc34000 for jp.s + ld hl, + 0xc30000; use 0xc34000 for jp.s #else - ld hl, 0xc300 + ld hl, + 0xc300 #endif push hl /* JP opcode */ #endif /* DBG_USE_TRAMPOLINE */ @@ -1316,40 +1232,38 @@ rest_cpu_state() __naked #ifdef __SDCC_ez80_adl ld a, (#_state + R_AF + 2) ld MB, a - ld hl, (#_state + R_IR + 1) ;I register - ld i, hl - ld a, (#_state + R_IR + 0) ; R register - ld l, a + ld hl, (#_state + R_IR + 1) ; + I register ld i, hl ld a, (#_state + R_IR + 0); + R register ld l, + a #else - ld hl, (#_state + R_IR) - ld a, h - ld i, a - ld a, l + ld hl, + (#_state + R_IR) ld a, h ld i, a ld a, + l #endif /* __SDCC_ez80_adl */ - sub a, #10 ;number of M1 cycles after ld r,a - xor a, l - and a, #0x7f - xor a, l - ld r, a - ld de, (#_state + R_DE) - ld bc, (#_state + R_BC) - ld hl, (#_state + R_AF) - push hl - pop af - ld sp, (#_state + R_SP) + sub a, +# 10; + number of M1 cycles after ld r, a xor a, l and a, #0x7f xor a, l ld r, + a ld de, (#_state + R_DE) ld bc, (#_state + R_BC) ld hl, + (#_state + R_AF) push hl pop af ld sp, + (#_state + R_SP) #ifndef DBG_USE_TRAMPOLINE - ld hl, (#_state + R_PC) - push hl - ld hl, (#_state + R_HL) - DBG_RESUME + ld hl, + (#_state + R_PC) push hl ld hl, + (#_state + R_HL) DBG_RESUME #else - ld hl, (#_state + R_HL) + ld hl, + (#_state + R_HL) #ifdef __SDCC_ez80_adl - jp #_stack + DBG_STACK_SIZE - 4 + jp #_stack + + DBG_STACK_SIZE + - 4 #else - jp #_stack + DBG_STACK_SIZE - 3 + jp #_stack + + DBG_STACK_SIZE + - 3 #endif #endif /* DBG_USE_TRAMPOLINE */ - __endasm; + __endasm; } #endif /* __SDCC_gbz80 */ |