home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / nlm / alpha.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-19  |  6.7 KB  |  326 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <errno.h>
  6.  
  7. #include <nwtypes.h>
  8. #include <nwdfs.h>
  9. #include <nwconio.h>
  10. #include <nwadv.h>
  11. #include <nwdbgapi.h>
  12. #include <nwthread.h>
  13. #include <aio.h>
  14.  
  15. #include "alpha.h"
  16.  
  17. extern char *mem2hex (void *mem, char *buf, int count, int may_fault);
  18. extern char *hex2mem (char *buf, void *mem, int count, int may_fault);
  19. extern int computeSignal (int exceptionVector);
  20.  
  21. /* Get the registers out of the frame information.  */
  22.  
  23. void
  24. frame_to_registers (frame, regs)
  25.      struct StackFrame *frame;
  26.      char *regs;
  27. {
  28.   mem2hex (&frame->ExceptionPC, ®s[PC_REGNUM * 8 * 2], 8 * 1, 0);
  29.  
  30.   mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET], ®s[V0_REGNUM * 8 * 2], 8 * 64, 0);
  31. }
  32.  
  33. /* Put the registers back into the frame information.  */
  34.  
  35. void
  36. registers_to_frame (regs, frame)
  37.      char *regs;
  38.      struct StackFrame *frame;
  39. {
  40.   hex2mem (®s[PC_REGNUM * 8 * 2], &frame->ExceptionPC, 8 * 1, 0);
  41.  
  42.   hex2mem (®s[V0_REGNUM * 8 * 2], &frame->ExceptionRegs[SF_IREG_OFFSET], 8 * 64, 0);
  43. }
  44.  
  45. union inst
  46. {
  47.   LONG l;
  48.  
  49.   struct
  50.     {
  51.       union
  52.     {
  53.       struct
  54.         {
  55.           unsigned hint : 16;
  56.           unsigned rb : 5;
  57.           unsigned ra : 5;
  58.           unsigned opcode : 6;
  59.         } jump;
  60.       struct
  61.         {
  62.           signed disp : 21;
  63.           unsigned ra : 5;
  64.           unsigned opcode : 6;
  65.         } branch;
  66.     } variant;
  67.     } inst;
  68. };
  69.  
  70. static LONG saved_inst;
  71. static LONG *saved_inst_pc = 0;
  72. static LONG saved_target_inst;
  73. static LONG *saved_target_inst_pc = 0;
  74.  
  75. void
  76. set_step_traps (frame)
  77.      struct StackFrame *frame;
  78. {
  79.   union inst inst;
  80.   LONG *target;
  81.   int opcode;
  82.   int ra, rb;
  83.   LONG *pc = (LONG *)frame->ExceptionPC;
  84.  
  85.   inst.l = *pc++;
  86.  
  87.   opcode = inst.inst.variant.branch.opcode;
  88.  
  89.   if ((opcode & 0x30) == 0x30)    /* A branch of some sort */
  90.     target = inst.inst.variant.branch.disp + pc;
  91.   else if (opcode == 0x1a)    /* jmp, ret, etc... */
  92.     target = (LONG *)(frame->ExceptionRegs[SF_IREG_OFFSET
  93.                        + inst.inst.variant.jump.rb].lo
  94.               & ~3);
  95.   else
  96.     target = pc;
  97.  
  98.   saved_inst = *pc;
  99.   *pc = 0x80;            /* call_pal bpt */
  100.   saved_inst_pc = pc;
  101.  
  102.   if (target != pc)
  103.     {
  104.       saved_target_inst = *target;
  105.       *target = 0x80;        /* call_pal bpt */
  106.       saved_target_inst_pc = target;
  107.     }
  108. }
  109.  
  110. /* Remove step breakpoints.  Returns non-zero if pc was at a step breakpoint,
  111.    zero otherwise.  This routine works even if there were no step breakpoints
  112.    set.  */
  113.  
  114. int
  115. clear_step_traps (frame)
  116.      struct StackFrame *frame;
  117. {
  118.   int retcode;
  119.   LONG *pc = (LONG *)frame->ExceptionPC;
  120.  
  121.   if (saved_inst_pc == pc || saved_target_inst_pc == pc)
  122.     retcode = 1;
  123.   else
  124.     retcode = 0;
  125.  
  126.   if (saved_inst_pc)
  127.     {
  128.       *saved_inst_pc = saved_inst;
  129.       saved_inst_pc = 0;
  130.     }
  131.  
  132.   if (saved_target_inst_pc)
  133.     {
  134.       *saved_target_inst_pc = saved_target_inst;
  135.       saved_target_inst_pc = 0;
  136.     }
  137.  
  138.   return retcode;
  139. }
  140.  
  141. void
  142. do_status (ptr, frame)
  143.      char *ptr;
  144.      struct StackFrame *frame;
  145. {
  146.   int sigval;
  147.  
  148.   sigval = computeSignal (frame->ExceptionNumber);
  149.  
  150.   sprintf (ptr, "T%02x", sigval);
  151.   ptr += 3;
  152.  
  153.   sprintf (ptr, "%02x:", PC_REGNUM);
  154.   ptr = mem2hex (&frame->ExceptionPC, ptr + 3, 8, 0);
  155.   *ptr++ = ';';
  156.  
  157.   sprintf (ptr, "%02x:", SP_REGNUM);
  158.   ptr = mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET + SP_REGNUM], ptr + 3, 8, 0);
  159.   *ptr++ = ';';
  160.  
  161.   sprintf (ptr, "%02x:", RA_REGNUM);
  162.   ptr = mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET + RA_REGNUM], ptr + 3, 8, 0);
  163.   *ptr++ = ';';
  164.  
  165.   sprintf (ptr, "%02x:", FP_REGNUM);
  166.   ptr = mem2hex (&frame->ExceptionRegs[SF_IREG_OFFSET + FP_REGNUM], ptr + 3, 8, 0);
  167.   *ptr++ = ';';
  168.  
  169.   *ptr = '\000';
  170. }
  171.  
  172. /* This section provides stubs and equivalent interfaces for all functions that
  173.    the debugger stub needs, but aren't yet implemented (such as the AIO nlm). */
  174.  
  175. #include <nwtypes.h>
  176. #include <errno.h>
  177. #include <stdio.h>
  178. #include <aio.h>
  179.  
  180. #define CONST const
  181.  
  182. #define com1Rbr    0x3f8        /* Receiver Buffer - Read    */
  183. #define com1Thr    0x3f8        /* Transmitter Holding - Write    */
  184. #define com1Ier    0x3f9        /* Interrupt Enable        */
  185. #define com1Iir    0x3fa        /* Interrupt Identification    */
  186. #define com1Lcr    0x3fb        /* Line Control            */
  187. #define com1Mcr    0x3fc        /* Modem Control        */
  188. #define com1Lsr    0x3fd        /* Line Status            */
  189. #define com1Msr    0x3fe        /* Modem Status            */
  190. #define com1Scr    0x3ff        /* Scratch            */
  191. #define com1Dll    0x3f8        /* Divisor Latch - lsb        */
  192. #define com1Dlm    0x3f9        /* Divisor Latch - msb        */
  193.  
  194. #define com2Rbr    0x2f8        /* Receiver Buffer - Read    */
  195. #define com2Thr    0x2f8        /* Transmitter Holding - Write    */
  196. #define com2Ier    0x2f9        /* Interrupt Enable        */
  197. #define com2Iir    0x2fa        /* Interrupt Identification    */
  198. #define com2Lcr    0x2fb        /* Line Control            */
  199. #define com2Mcr    0x2fc        /* Modem Control        */
  200. #define com2Lsr    0x2fd        /* Line Status            */
  201. #define com2Msr    0x2fe        /* Modem Status            */
  202. #define com2Scr    0x2ff        /* Scratch            */
  203. #define com2Dll    0x2f8        /* Divisor Latch - lsb        */
  204. #define com2Dlm    0x2f9        /* Divisor Latch - msb        */
  205.  
  206. #define COM1 0x8000
  207. #define COM2 0x9000
  208.  
  209. static ULONG
  210. uart_getchar (void)
  211. {
  212.   while ((inVti(com1Lsr) & 1) == 0);
  213.  
  214.   return inVti (com1Rbr);
  215. }
  216.  
  217. static void  
  218. uart_putchar (char c)
  219.   while ((inVti(com1Lsr) & 0x20) == 0);
  220.  
  221.   outVti (com1Thr,c);
  222. }
  223.  
  224. static int
  225. uart_init (int baud)
  226. {
  227.   int i;
  228.   int baudconst;
  229.  
  230.   baudconst = 115200 / baud;
  231.  
  232.   outVti (com1Lcr, 0x87);
  233.   outVti (com1Dlm, 0);
  234.   outVti (com1Dll, baudconst);
  235.   outVti (com1Lcr, 0x07);
  236.   outVti (com1Mcr, 0x0F);
  237.   outVti (com1Ier, 0x0);
  238. }
  239.  
  240. int
  241. AIOReadData (int portHandle, char  *buffer, LONG length, LONG *numberBytesRead)
  242. {
  243.   ULONG c;
  244.  
  245.   while (1)
  246.     {
  247.       c = uart_getchar ();
  248.       if ((c & ~0377) == COM1)
  249.     break;
  250.     }
  251.  
  252.   *buffer = c;
  253.   *numberBytesRead = 1;
  254.  
  255.   return AIO_SUCCESS;
  256. }
  257.  
  258. int
  259. AIOWriteData (int portHandle, char *buffer, LONG length,
  260.           LONG *numberBytesWritten)
  261.     
  262. {
  263.   *numberBytesWritten = length;
  264.  
  265.   while (length-- > 0)
  266.     uart_putchar (*buffer++);
  267.  
  268.   return AIO_SUCCESS;
  269. }
  270.  
  271. int
  272. AIOAcquirePort (int *hardwareType, int *boardNumber, int *portNumber,
  273.         int *portHandle)
  274. {
  275.   return AIO_SUCCESS;
  276. }
  277.  
  278. int
  279. AIOConfigurePort (int portHandle, BYTE bitRate,    BYTE dataBits, BYTE stopBits,
  280.           BYTE parityMode, BYTE flowCtrlMode)
  281. {
  282.   uart_init (9600);
  283.  
  284.   return AIO_SUCCESS;
  285. }
  286.  
  287. int
  288. AIOGetPortConfiguration (int portHandle, AIOPORTCONFIG *pPortConfig,
  289.                  AIODVRCONFIG *pDvrConfig)
  290. {
  291.   fprintf (stderr, "AIOGetPortConfiguration stubbed out\n");
  292.   exit (1);
  293. }
  294.  
  295. int
  296. AIOReleasePort (int portHandle)
  297. {
  298.   return AIO_SUCCESS;
  299. }
  300.     
  301. int
  302. AIOSetExternalControl (int portHandle, int requestType, int requestValue)
  303. {
  304.   return AIO_SUCCESS;
  305. }
  306.  
  307. int
  308. AIOGetExternalStatus (int portHandle, LONG *extStatus, LONG *chgdExtStatus)
  309. {
  310.   fprintf (stderr, "AIOGetExternalStatus stubbed out\n");
  311.   exit (1);
  312. }
  313.  
  314. void
  315. StopBell ()
  316. {
  317. }
  318.  
  319. int
  320. Breakpoint (int __arg)
  321. {
  322.   fprintf (stderr, "Breakpoint() stubbed out\n");
  323.   exit (1);
  324. }
  325.