home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / config / gould / tm-np1.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-26  |  18.3 KB  |  493 lines

  1. /* Parameters for targeting on a Gould NP1, for GDB, the GNU debugger.
  2.    Copyright 1986, 1987, 1989, 1991, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #define GOULD_NPL
  21.  
  22. #define TARGET_BYTE_ORDER BIG_ENDIAN
  23.  
  24. /* N_ENTRY appears in libraries on Gould machines.
  25.    Don't know what 0xa4 is; it's mentioned in stab.h
  26.    but only in the sdb symbol list.  */
  27. #define IGNORE_SYMBOL(type) (type == N_ENTRY || type == 0xa4)
  28.  
  29. /* We don't want the extra gnu symbols on the machine;
  30.    they will interfere with the shared segment symbols.  */
  31. #define NO_GNU_STABS
  32.  
  33. /* Macro for text-offset and data info (in NPL a.out format).  */
  34. #define    TEXTINFO                        \
  35.         text_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr);    \
  36.         exec_data_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr)\
  37.                 + exec_aouthdr.a_text
  38.  
  39. /* Macro for number of symbol table entries */
  40. #define NUMBER_OF_SYMBOLS                    \
  41.     (coffhdr.f_nsyms)
  42.  
  43. /* Macro for file-offset of symbol table (in NPL a.out format).  */
  44. #define SYMBOL_TABLE_OFFSET                    \
  45.     N_SYMOFF (coffhdr)
  46.  
  47. /* Macro for file-offset of string table (in NPL a.out format).  */
  48. #define STRING_TABLE_OFFSET                    \
  49.     (N_STROFF (coffhdr))
  50.  
  51. /* Macro to store the length of the string table data in INTO.  */
  52. #define READ_STRING_TABLE_SIZE(INTO)                \
  53.     { INTO = hdr.a_stsize; }
  54.  
  55. /* Macro to declare variables to hold the file's header data.  */
  56. #define DECLARE_FILE_HEADERS  struct exec hdr;            \
  57.                   FILHDR coffhdr
  58.  
  59. /* Macro to read the header data from descriptor DESC and validate it.
  60.    NAME is the file name, for error messages.  */
  61. #define READ_FILE_HEADERS(DESC, NAME)                \
  62. { val = myread (DESC, &coffhdr, sizeof coffhdr);        \
  63.   if (val < 0)                            \
  64.     perror_with_name (NAME);                    \
  65.   val = myread (DESC, &hdr, sizeof hdr);            \
  66.   if (val < 0)                            \
  67.     perror_with_name (NAME);                    \
  68.   if (coffhdr.f_magic != GNP1MAGIC)                \
  69.     error ("File \"%s\" not in coff executable format.", NAME);    \
  70.   if (N_BADMAG (hdr))                        \
  71.     error ("File \"%s\" not in executable format.", NAME); }
  72.  
  73. /* Define COFF and other symbolic names needed on NP1 */
  74. #define    NS32GMAGIC    GNP1MAGIC
  75. #define    NS32SMAGIC    GPNMAGIC
  76.  
  77. /* Address of blocks in N_LBRAC and N_RBRAC symbols are absolute addresses,
  78.    not relative to start of source address.  */
  79. #define BLOCK_ADDRESS_ABSOLUTE
  80.  
  81. /* Offset from address of function to start of its code.
  82.    Zero on most machines.  */
  83. #define FUNCTION_START_OFFSET    8
  84.  
  85. /* Advance PC across any function entry prologue instructions
  86.    to reach some "real" code.  One NPL we can have one two startup
  87.    sequences depending on the size of the local stack:
  88.  
  89.    Either:
  90.       "suabr b2, #"
  91.    of
  92.       "lil r4, #", "suabr b2, #(r4)"
  93.  
  94.    "lwbr b6, #", "stw r1, 8(b2)"
  95.    Optional "stwbr b3, c(b2)"
  96.    Optional "trr r2,r7"      (Gould first argument register passing)
  97.      or
  98.    Optional "stw r2,8(b3)"   (Gould first argument register passing)
  99.  */
  100. #define SKIP_PROLOGUE(pc) {                         \
  101.     register int op = read_memory_integer ((pc), 4);        \
  102.     if ((op & 0xffff0000) == 0xFA0B0000) {                 \
  103.         pc += 4;                            \
  104.         op = read_memory_integer ((pc), 4);                \
  105.         if ((op & 0xffff0000) == 0x59400000) {            \
  106.         pc += 4;                        \
  107.             op = read_memory_integer ((pc), 4);            \
  108.         if ((op & 0xffff0000) == 0x5F000000) {            \
  109.             pc += 4;                        \
  110.                 op = read_memory_integer ((pc), 4);            \
  111.             if (op == 0xD4820008) {                \
  112.                 pc += 4;                    \
  113.                     op = read_memory_integer ((pc), 4);        \
  114.                 if (op == 0x5582000C) {                \
  115.                     pc += 4;                    \
  116.                         op = read_memory_integer ((pc), 2);        \
  117.                     if (op == 0x2fa0) {                \
  118.                         pc += 2;                \
  119.                     } else {                    \
  120.                             op = read_memory_integer ((pc), 4);    \
  121.                         if (op == 0xd5030008) {            \
  122.                             pc += 4;                \
  123.                         }                    \
  124.                     }                        \
  125.                 } else {                    \
  126.                         op = read_memory_integer ((pc), 2);        \
  127.                     if (op == 0x2fa0) {                \
  128.                         pc += 2;                \
  129.                     }                        \
  130.                 }                        \
  131.             }                            \
  132.         }                            \
  133.         }                                \
  134.     }                                 \
  135.     if ((op & 0xffff0000) == 0x59000000) {                 \
  136.         pc += 4;                            \
  137.         op = read_memory_integer ((pc), 4);                \
  138.         if ((op & 0xffff0000) == 0x5F000000) {            \
  139.         pc += 4;                        \
  140.             op = read_memory_integer ((pc), 4);            \
  141.         if (op == 0xD4820008) {                    \
  142.             pc += 4;                        \
  143.                 op = read_memory_integer ((pc), 4);            \
  144.             if (op == 0x5582000C) {                \
  145.                 pc += 4;                    \
  146.                     op = read_memory_integer ((pc), 2);        \
  147.                 if (op == 0x2fa0) {                \
  148.                     pc += 2;                    \
  149.                 } else {                    \
  150.                         op = read_memory_integer ((pc), 4);        \
  151.                     if (op == 0xd5030008) {            \
  152.                         pc += 4;                \
  153.                     }                        \
  154.                 }                        \
  155.             } else {                        \
  156.                     op = read_memory_integer ((pc), 2);        \
  157.                 if (op == 0x2fa0) {                \
  158.                     pc += 2;                    \
  159.                 }                        \
  160.             }                            \
  161.         }                            \
  162.         }                                \
  163.     }                                 \
  164. }
  165.  
  166. /* Immediately after a function call, return the saved pc.
  167.    Can't go through the frames for this because on some machines
  168.    the new frame is not set up until the new function executes
  169.    some instructions.  True on NPL! Return address is in R1.
  170.    The true return address is REALLY 4 past that location! */
  171. #define SAVED_PC_AFTER_CALL(frame) \
  172.     (read_register(R1_REGNUM) + 4)
  173.  
  174. /* Address of end of stack space.  */
  175. #define STACK_END_ADDR         0x7fffc000
  176.  
  177. /* Stack grows downward.  */
  178. #define INNER_THAN         <
  179.  
  180. /* Sequence of bytes for breakpoint instruction.
  181.    This is padded out to the size of a machine word.  When it was just
  182.    {0x28, 0x09} it gave problems if hit breakpoint on returning from a
  183.    function call.  */
  184. #define BREAKPOINT         {0x28, 0x09, 0x0, 0x0}
  185.  
  186. /* Amount PC must be decremented by after a breakpoint.
  187.    This is often the number of bytes in BREAKPOINT
  188.    but not always.  */
  189. #define DECR_PC_AFTER_BREAK    2
  190.  
  191. /* Nonzero if instruction at PC is a return instruction. "bu 4(r1)" */
  192. #define ABOUT_TO_RETURN(pc)    (read_memory_integer (pc, 4) == 0x40100004)
  193.  
  194. /* Return 1 if P points to an invalid floating point value.  */
  195. #define INVALID_FLOAT(p, len)     ((*(short *)p & 0xff80) == 0x8000)
  196.  
  197. /* Say how long (ordinary) registers are.  This is a piece of bogosity
  198.    used in push_word and a few other places; REGISTER_RAW_SIZE is the
  199.    real way to know how big a register is.  */
  200.  
  201. #define REGISTER_SIZE 4
  202.  
  203. /* Size of bytes of vector register (NP1 only), 32 elements * sizeof(int) */
  204. #define VR_SIZE            128
  205.  
  206. /* Number of machine registers */
  207. #define NUM_REGS         27
  208. #define NUM_GEN_REGS        16
  209. #define NUM_CPU_REGS        4
  210. #define NUM_VECTOR_REGS        7
  211.  
  212. /* Initializer for an array of names of registers.
  213.    There should be NUM_REGS strings in this initializer.  */
  214. #define REGISTER_NAMES { \
  215.   "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
  216.   "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", \
  217.   "sp", "ps", "pc", "ve", \
  218.   "v1", "v2", "v3", "v4", "v5", "v6", "v7", \
  219. }
  220.  
  221. /* Register numbers of various important registers.
  222.    Note that some of these values are "real" register numbers,
  223.    and correspond to the general registers of the machine,
  224.    and some are "phony" register numbers which are too large
  225.    to be actual register numbers as far as the user is concerned
  226.    but do serve to get the desired values when passed to read_register.  */
  227. #define R1_REGNUM    1    /* Gr1 => return address of caller */
  228. #define R2_REGNUM    2    /* Gr2 => return value from function */
  229. #define R4_REGNUM    4    /* Gr4 => register save area */
  230. #define R5_REGNUM    5    /* Gr5 => register save area */
  231. #define R6_REGNUM    6    /* Gr6 => register save area */
  232. #define R7_REGNUM    7    /* Gr7 => register save area */
  233. #define B1_REGNUM    9    /* Br1 => start of this code routine */
  234. #define SP_REGNUM    10    /* Br2 == (sp) */
  235. #define AP_REGNUM    11    /* Br3 == (ap) */
  236. #define FP_REGNUM     16    /* A copy of Br2 saved in trap */
  237. #define PS_REGNUM     17    /* Contains processor status */
  238. #define PC_REGNUM     18    /* Contains program counter */
  239. #define VE_REGNUM     19    /* Vector end (user setup) register */
  240. #define V1_REGNUM     20    /* First vector register */
  241. #define V7_REGNUM     26    /* First vector register */
  242.  
  243. /* Total amount of space needed to store our copies of the machine's
  244.    register state, the array `registers'.  */
  245. #define REGISTER_BYTES \
  246.     (NUM_GEN_REGS*4 + NUM_VECTOR_REGS*VR_SIZE + NUM_CPU_REGS*4)
  247.  
  248. /* Index within `registers' of the first byte of the space for
  249.    register N.  */
  250. #define REGISTER_BYTE(N)  \
  251.     (((N) < V1_REGNUM) ? ((N) * 4) : (((N) - V1_REGNUM) * VR_SIZE) + 80)
  252.  
  253. /* Number of bytes of storage in the actual machine representation
  254.    for register N.  On the NP1, all normal regs are 4 bytes, but
  255.    the vector registers are VR_SIZE*4 bytes long. */
  256. #define REGISTER_RAW_SIZE(N) \
  257.     (((N) < V1_REGNUM) ? 4 : VR_SIZE)
  258.  
  259. /* Number of bytes of storage in the program's representation
  260.    for register N.  On the NP1, all regs are 4 bytes. */
  261. #define REGISTER_VIRTUAL_SIZE(N) \
  262.     (((N) < V1_REGNUM) ? 4 : VR_SIZE)
  263.  
  264. /* Largest value REGISTER_RAW_SIZE can have.  */
  265. #define MAX_REGISTER_RAW_SIZE        VR_SIZE
  266.  
  267. /* Largest value REGISTER_VIRTUAL_SIZE can have.  */
  268. #define MAX_REGISTER_VIRTUAL_SIZE    VR_SIZE
  269.  
  270. /* Return the GDB type object for the "standard" data type
  271.    of data in register N.  */
  272. #define REGISTER_VIRTUAL_TYPE(N)    \
  273.   ((N) > VE_REGNUM ? builtin_type_np1_vector : builtin_type_int)
  274. extern struct type *builtin_type_np1_vector;
  275.  
  276. /* Store the address of the place in which to copy the structure the
  277.    subroutine will return.  This is called from call_function.
  278.  
  279.    On this machine this is a no-op, because gcc isn't used on it
  280.    yet.  So this calling convention is not used. */
  281.  
  282. #define STORE_STRUCT_RETURN(ADDR, SP) push_word(SP + 8, ADDR)
  283.  
  284. /* Extract from an arrary REGBUF containing the (raw) register state
  285.    a function return value of type TYPE, and copy that, in virtual format,
  286.    into VALBUF. */
  287.  
  288. #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
  289.     memcpy (VALBUF, ((int *)(REGBUF)) + 2, TYPE_LENGTH (TYPE))
  290.  
  291. /* Write into appropriate registers a function return value
  292.    of type TYPE, given in virtual format.  */
  293.  
  294. #define STORE_RETURN_VALUE(TYPE,VALBUF) \
  295.     write_register_bytes (REGISTER_BYTE (R2_REGNUM), VALBUF,      \
  296.                   TYPE_LENGTH (TYPE))
  297.  
  298. /* Extract from an array REGBUF containing the (raw) register state
  299.    the address in which a function should return its structure value,
  300.    as a CORE_ADDR (or an expression that can be used as one).  */
  301.  
  302. #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*((int *)(REGBUF) + 2))
  303.  
  304. /* Both gcc and cc return small structs in registers (i.e. in GDB
  305.    terminology, small structs don't use the struct return convention).  */
  306. #define USE_STRUCT_CONVENTION(gcc_p, type) (TYPE_LENGTH(type) > 8)
  307.  
  308. /* Describe the pointer in each stack frame to the previous stack frame
  309.    (its caller).  */
  310.  
  311. /* FRAME_CHAIN takes a frame's nominal address
  312.    and produces the frame's chain-pointer.
  313.  
  314.    However, if FRAME_CHAIN_VALID returns zero,
  315.    it means the given frame is the outermost one and has no caller.  */
  316.  
  317. /* In the case of the NPL, the frame's norminal address is Br2 and the 
  318.    previous routines frame is up the stack X bytes, where X is the
  319.    value stored in the code function header xA(Br1). */
  320. #define FRAME_CHAIN(thisframe)        (findframe(thisframe))
  321.  
  322. #define FRAME_CHAIN_VALID(chain, thisframe) \
  323.         (chain != 0 && chain != (thisframe)->frame)
  324.  
  325. /* Define other aspects of the stack frame on NPL.  */
  326. #define FRAME_SAVED_PC(FRAME) \
  327.     (read_memory_integer ((FRAME)->frame + 8, 4))
  328.  
  329. #define FRAME_ARGS_ADDRESS(fi) \
  330.     ((fi)->next ? \
  331.      read_memory_integer ((fi)->frame + 12, 4) : \
  332.      read_register (AP_REGNUM))
  333.  
  334. #define FRAME_LOCALS_ADDRESS(fi)    ((fi)->frame)
  335.  
  336. /* Set VAL to the number of args passed to frame described by FI.
  337.    Can set VAL to -1, meaning no way to tell.  */
  338.  
  339. /* We can check the stab info to see how
  340.    many arg we have.  No info in stack will tell us */
  341. #define FRAME_NUM_ARGS(val,fi)        (val = findarg(fi))
  342.  
  343. /* Return number of bytes at start of arglist that are not really args.  */
  344. #define FRAME_ARGS_SKIP            8
  345.  
  346. /* Put here the code to store, into a struct frame_saved_regs,
  347.    the addresses of the saved registers of frame described by FRAME_INFO.
  348.    This includes special registers such as pc and fp saved in special
  349.    ways in the stack frame.  sp is even more special:
  350.    the address we return for it IS the sp for the next frame.  */
  351.  
  352. #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs)        \
  353. {                                                                       \
  354.   memset (&frame_saved_regs, '\0', sizeof frame_saved_regs);            \
  355.   (frame_saved_regs).regs[SP_REGNUM] = framechain (frame_info);         \
  356.   (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 8;        \
  357.   (frame_saved_regs).regs[R4_REGNUM] = (frame_info)->frame + 0x30;    \
  358.   (frame_saved_regs).regs[R5_REGNUM] = (frame_info)->frame + 0x34;    \
  359.   (frame_saved_regs).regs[R6_REGNUM] = (frame_info)->frame + 0x38;    \
  360.   (frame_saved_regs).regs[R7_REGNUM] = (frame_info)->frame + 0x3C;    \
  361. }
  362.  
  363. /* Things needed for making the inferior call functions.  */
  364.  
  365. #define CALL_DUMMY_LOCATION    BEFORE_TEXT_END
  366. #define    NEED_TEXT_START_END
  367.  
  368. /* Push an empty stack frame, to record the current PC, etc.  */
  369.  
  370. #define PUSH_DUMMY_FRAME \
  371. { register CORE_ADDR sp = read_register (SP_REGNUM); \
  372.   register int regnum;                               \
  373.   for (regnum = 0; regnum < FP_REGNUM; regnum++)     \
  374.     sp = push_word (sp, read_register (regnum));     \
  375.   sp = push_word (sp, read_register (PS_REGNUM));    \
  376.   sp = push_word (sp, read_register (PC_REGNUM));    \
  377.   write_register (SP_REGNUM, sp);}
  378.  
  379. /* Discard from the stack the innermost frame, 
  380.    restoring all saved registers.  */
  381. /* FIXME: Should be using {store,extract}_unsigned_integer.  */
  382.  
  383. #define POP_FRAME  \
  384. { CORE_ADDR sp = read_register(SP_REGNUM);             \
  385.   unsigned LONGEST reg;                                   \
  386.   int regnum;                                          \
  387.   for(regnum = 0;regnum < FP_REGNUM;regnum++){         \
  388.     sp-=REGISTER_SIZE;                         \
  389.     read_memory(sp,®,REGISTER_SIZE);        \
  390.     write_register(regnum,reg);}                       \
  391.   sp-=REGISTER_SIZE;                           \
  392.   read_memory(sp,®,REGISTER_SIZE);          \
  393.   write_register(PS_REGNUM,reg);                       \
  394.   sp-=REGISTER_SIZE;                           \
  395.   read_memory(sp,®,REGISTER_SIZE);          \
  396.   write_register(PC_REGNUM,reg);}
  397.  
  398. /* MJD - Size of dummy frame pushed onto stack by PUSH_DUMMY_FRAME */
  399.  
  400. #define DUMMY_FRAME_SIZE (0x48)
  401.  
  402. /* MJD - The sequence of words in the instructions is
  403.    halt
  404.    halt
  405.    halt
  406.    halt
  407.    subr    b2,stack size,0             grab stack space for dummy call
  408.    labr    b3,x0(b2),0                 set AP_REGNUM to point at arguments
  409.    lw      r2,x8(b3),0                 load r2 with first argument    
  410.    lwbr    b1,arguments size(b2),0     load address of function to be called
  411.    brlnk   r1,x8(b1),0                 call function
  412.    halt
  413.    halt
  414.    labr    b2,stack size(b2),0         give back stack
  415.    break                               break
  416.    */
  417.  
  418. #define CALL_DUMMY {0x00000000,  \
  419.             0x00000000,  \
  420.             0x59000000,  \
  421.             0x598a0000,  \
  422.             0xb5030008,  \
  423.             0x5c820000,  \
  424.             0x44810008,  \
  425.             0x00000000,  \
  426.             0x590a0000,  \
  427.             0x28090000 }
  428.  
  429. #define CALL_DUMMY_LENGTH 40
  430.  
  431. #define CALL_DUMMY_START_OFFSET 8
  432.  
  433. #define CALL_DUMMY_STACK_ADJUST 8
  434.  
  435. /* MJD - Fixup CALL_DUMMY for the specific function call.
  436.    OK heres the problems
  437.    1) On a trap there are two copies of the stack pointer, one in SP_REGNUM
  438.       which is read/write and one in FP_REGNUM which is only read. It seems
  439.       that when restarting the GOULD NP1 uses FP_REGNUM's value.
  440.    2) Loading function address into b1 looks a bit difficult if bigger than
  441.       0x0000fffc, infact from what I can tell the compiler sets up table of
  442.       function address in base3 through which function calls are referenced.
  443.  
  444.    OK my solutions
  445.      Calculate the size of the dummy stack frame and do adjustments of
  446.      SP_REGNUM in the dummy call.
  447.      Push function address onto the stack and load it in the dummy call
  448.  */
  449.  
  450. #define FIX_CALL_DUMMY(dummyname, sp, fun, nargs, args, type, gcc_p) \
  451.   {   int i;\
  452.       int arg_len = 0, total_len;\
  453.       old_sp = push_word(old_sp,fun);\
  454.       for(i = nargs - 1;i >= 0;i--)\
  455.     arg_len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i])));\
  456.       if(struct_return)\
  457.     arg_len += TYPE_LENGTH(value_type);\
  458.       total_len = DUMMY_FRAME_SIZE+CALL_DUMMY_STACK_ADJUST+4+arg_len;\
  459.       dummyname[0] += total_len;\
  460.       dummyname[2] += total_len;\
  461.       dummyname[5] += arg_len+CALL_DUMMY_STACK_ADJUST;\
  462.       dummyname[8] += total_len;}
  463.  
  464. /* MJD - So the stack should end up looking like this
  465.  
  466.                    | Normal stack frame  |
  467.                    | from normal program |
  468.                    | flow                |
  469.                    +---------------------+ <- Final sp - 0x08 - argument size
  470.                    |                     |    - 0x4 - dummy_frame_size
  471.                    | Pushed dummy frame  |
  472.                    |  b0-b7, r0-r7       |
  473.                    |  pc and ps          |
  474.                    |                     |
  475.                    +---------------------+
  476.                    | Function address    |
  477.                    +---------------------+ <- Final sp - 0x8 - arguments size
  478.                    |                     |
  479.                    |                     |
  480.                    |                     |
  481.                    |  Arguments to       |
  482.                    |       Function      |
  483.                    |                     |
  484.                    |                     |
  485.                    |                     |
  486.                    +---------------------+ <- Final sp - 0x8
  487.                    | Dummy_stack_adjust  |
  488.                    +---------------------+ <- Final sp
  489.                    |                     |
  490.                    | where call will     |
  491.                    |   build frame       |
  492. */
  493.