home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / utils / amd-udi / mondfe / icmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-23  |  14.9 KB  |  500 lines

  1. static char _[] = "@(#)icmd.c    5.20 93/07/30 16:38:37, Srini, AMD.";
  2. /******************************************************************************
  3.  * Copyright 1991 Advanced Micro Devices, Inc.
  4.  *
  5.  * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
  6.  * specifically  grants the user the right to modify, use and distribute this
  7.  * software provided this notice is not removed or altered.  All other rights
  8.  * are reserved by AMD.
  9.  *
  10.  * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
  11.  * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
  12.  * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
  13.  * USE OF THIS SOFTWARE.
  14.  *
  15.  * So that all may benefit from your experience, please report  any  problems
  16.  * or  suggestions about this software to the 29K Technical Support Center at
  17.  * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
  18.  * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
  19.  *
  20.  * Advanced Micro Devices, Inc.
  21.  * 29K Support Products
  22.  * Mail Stop 573
  23.  * 5900 E. Ben White Blvd.
  24.  * Austin, TX 78741
  25.  * 800-292-9263
  26.  *****************************************************************************
  27.  *      Engineer: Srini Subramanian.
  28.  *****************************************************************************
  29.  **       This code implements a subset of the MON29K-like "i"
  30.  **       commands.  Access the 2903x cashe, ix, ia, il
  31.  *****************************************************************************
  32.  */
  33.  
  34.  
  35. #include <stdio.h>
  36. #include <ctype.h>
  37. #include <memory.h>
  38. #include "main.h"
  39. #include "macros.h"
  40. #include "miniint.h"
  41. #include "memspcs.h"
  42. #include "error.h"
  43.  
  44.  
  45. #ifdef MSDOS
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #else
  49. #include <string.h>
  50. #endif
  51.  
  52. INT32    i_cmd PARAMS((char **, int));
  53. INT32    ix_cmd PARAMS((char **, int));
  54. INT32    il_cmd PARAMS((char **, int));
  55.  
  56. int   get_addr_29k PARAMS((char *, struct addr_29k_t *));
  57. int   addr_29k_ok PARAMS((struct addr_29k_t *));
  58. int   print_addr_29k PARAMS((INT32, ADDR32));
  59. int get_word PARAMS((char *buffer, INT32 *data_word));
  60. void convert32 PARAMS(( BYTE *byte));
  61.  
  62. void  dasm_instr PARAMS((ADDR32, struct instr_t *));
  63.  
  64. /* Variable definitions */
  65. struct xp_cmd_t {
  66.    INT32  vtb;
  67.    INT32  ops;
  68.    INT32  cps;
  69.    INT32  cfg;
  70.    INT32  cha;
  71.    INT32  chd;
  72.    INT32  chc;
  73.    INT32  rbp;
  74.    INT32  tmc;
  75.    INT32  tmr;
  76.    INT32  pc0;
  77.    INT32  pc1;
  78.    INT32  pc2;
  79.    INT32  mmuc;
  80.    INT32  lru;
  81. };
  82. #define    XP_CMD_SZ    15 * sizeof (INT32)
  83. /* #define    XP_CMD_SZ    sizeof(struct xp_cmd_t) */
  84.  
  85.  
  86. INT32
  87. i_cmd(token, token_count)
  88.    char   *token[];
  89.    int     token_count;
  90.    {
  91.    INT32    result;
  92.  
  93.    if (strcmp(token[0], "ix") == 0)
  94.       result = ix_cmd(token, token_count);
  95.    else
  96.    if (strcmp(token[0], "il") == 0)
  97.       result = il_cmd(token, token_count);
  98.    else
  99.       result = EMSYNTAX;
  100.  
  101.    return (result);
  102.    }  /* end xcmd() */
  103.  
  104.  
  105.  
  106. /*
  107. ** The function below is used to implement the MON29K-like
  108. ** "i" commands.  the function below, i_cmd() is called
  109. ** in the main command loop parser of the monitor.  The
  110. ** parameters passed to this function are:
  111. **
  112. ** token - This is an array of pointers to strings.  Each string
  113. **         referenced by this array is a "token" of the user's
  114. **         input, translated to lower case.
  115. **
  116. ** token_count - This is the number of tokens in "token".
  117. **
  118. ** This function then calls the specific "i" commands,
  119. ** such as "ix", "il" or "ia".
  120. */
  121.  
  122. /*
  123. **  il
  124. **  This command will dissasseble the contents of the cache  
  125. ** This command is used to examine the contents of the cache
  126. ** in the Am29030.  First set 0 is printed, starting with the
  127. **  This command will dissasseble the contents of the cache  
  128. ** tag, followed by a disassembly of four instructions in
  129. ** the set.  Set 1 for the line follows similarly.
  130. **
  131. ** The data comes in from the READ_ACK message in the following
  132. ** order:
  133. **
  134. **            tag      (data[0-3]    (set 0)
  135. **         instr1      (data[4-7]
  136. **         instr1      (data[8-11]
  137. **         instr1      (data[12-15]
  138. **         instr1      (data[16-19]
  139. **
  140. **            tag      (data[20-23]  (set 1)
  141. **         instr1      (data[24-27]
  142. **         instr1      (data[28-31]
  143. **         instr1      (data[32-35]
  144. **         instr1      (data[36-39]
  145. */
  146.  
  147. INT32
  148. il_cmd(token, token_count)
  149.    char   *token[];
  150.    int     token_count;
  151.    {
  152.    static INT32  memory_space=I_CACHE;
  153.    static ADDR32 cache_line=0;
  154.    static INT32  byte_count=(10*sizeof(INST32));
  155.    static INT32  count=1;
  156.    ADDR32 address;
  157.    INT32  i;
  158.    int    j;
  159.    int    set;
  160.    int    index;
  161.    int    result;
  162.    struct instr_t instr;
  163.    INT32  cache_line_start;
  164.    INT32  cache_line_end;
  165.  
  166.    INT32    retval;
  167.    INT32    bytes_ret;
  168.    INT32    host_endian;
  169.    BYTE        read_buffer[10*sizeof(INST32)];
  170.    char        prtbuf[256];
  171.  
  172.  
  173.    /* Is it an 'il' command? */
  174.    if (strcmp(token[0], "il") != 0)
  175.       return (EMSYNTAX);
  176.  
  177.    /*
  178.    ** Parse parameters
  179.    */
  180.  
  181.    if (token_count == 1) {
  182.       cache_line = cache_line + count;
  183.       }
  184.    else
  185.    if (token_count == 2) {
  186.       result = get_word(token[1], &cache_line_start);
  187.       if (result != 0)
  188.          return (EMSYNTAX);
  189.       if ((cache_line_start < 0) ||
  190.           (cache_line_start >255))
  191.          return (EMBADADDR);
  192.       cache_line = cache_line_start;
  193.       }
  194.    else
  195.    if (token_count == 3) {
  196.       /* Get first cache line to be dumped */
  197.       result = get_word(token[1], &cache_line_start);
  198.       if (result != 0)
  199.          return (EMSYNTAX);
  200.       if ((cache_line_start < 0) ||
  201.           (cache_line_start > 255))
  202.          return (EMBADADDR);
  203.       /* Get last cache line to be dumped */
  204.       result = get_word(token[2], &cache_line_end);
  205.       if (result != 0)
  206.          return (EMSYNTAX);
  207.       if ((cache_line_end < 0) ||
  208.           (cache_line_end > 255))
  209.          return (EMBADADDR);
  210.       if (cache_line_start > cache_line_end)
  211.          return (EMBADADDR);
  212.       cache_line = cache_line_start;
  213.       count = (cache_line_end - cache_line_start) + 1;
  214.       }
  215.    else
  216.    /* Too many args */
  217.       return (EMSYNTAX);
  218.  
  219.    i = 0;
  220.    while (i < count) {
  221.  
  222.       host_endian = FALSE;
  223.       if ((retval = Mini_read_req(memory_space,
  224.                   (cache_line + i),
  225.                   byte_count/4,
  226.                   (INT16) 4, /* size */
  227.                   &bytes_ret,
  228.                   read_buffer,
  229.                   host_endian)) != SUCCESS) {
  230.      return(FAILURE);
  231.       };
  232.       /* The following is executed if SUCCESSful */
  233.  
  234.       for (set=0; set<2; set++) {
  235.  
  236.          /* Print out formatted address tag and status information */
  237.          index = (set * 20);
  238.          sprintf(&prtbuf[0], "\n");
  239.          sprintf(&prtbuf[strlen(prtbuf)], "Cache line 0x%lx, set %d.\n", (int) (cache_line+i), set);
  240.          sprintf(&prtbuf[strlen(prtbuf)], "\n");
  241.          if (io_config.echo_mode == (INT32) TRUE)
  242.             fprintf (io_config.echo_file, "%s", &prtbuf[0]);
  243.          fprintf (stderr, "%s", &prtbuf[0]);
  244.          sprintf(&prtbuf[0], "IATAG  V  P US\n");
  245.          if (io_config.echo_mode == (INT32) TRUE)
  246.             fprintf (io_config.echo_file, "%s", &prtbuf[0]);
  247.          fprintf (stderr, "%s", &prtbuf[0]);
  248.          sprintf(&prtbuf[0], "%02x%02x%1x  %1x  %1x  %1x\n",
  249.                 read_buffer[index],
  250.                 read_buffer[index + 1],
  251.                 ((read_buffer[index + 2] >> 4) & 0x0f),
  252.                 ((read_buffer[index + 3] >> 2) & 0x01),
  253.                 ((read_buffer[index + 3] >> 1) & 0x01),
  254.                 (read_buffer[index + 3] & 0x01));
  255.          sprintf(&prtbuf[strlen(prtbuf)], "\n");
  256.         if (io_config.echo_mode == (INT32) TRUE)
  257.              fprintf (io_config.echo_file, "%s", &prtbuf[0]);
  258.         fprintf (stderr, "%s", &prtbuf[0]);
  259.  
  260.          /* Address = IATAG + line_number + <16 byte adddress> */
  261.          address = ((read_buffer[index] << 24) |
  262.                     (read_buffer[index + 1] << 16) |
  263.                     (read_buffer[index + 2] << 8) |
  264.                     ((cache_line+i) << 4));
  265.  
  266.          /* Disassemble four words */
  267.          for (j=0; j<4; j=j+1) {
  268.             index = (set * 20) + ((j+1) * sizeof(INT32));
  269.             instr.op = read_buffer[index];
  270.             instr.c = read_buffer[index + 1];
  271.             instr.a = read_buffer[index + 2];
  272.             instr.b = read_buffer[index + 3];
  273.  
  274.             /* Print address of instruction (in hex) */
  275.             address = (address & 0xfffffff0);  /* Clear low four bits */
  276.             address = (address | (j << 2));
  277.             fprintf(stderr, "%08lx    ", address);
  278.         if (io_config.echo_mode == (INT32) TRUE)
  279.                fprintf(io_config.echo_file, "%08lx    ", address);
  280.  
  281.             /* Print instruction (in hex) */
  282.         if (io_config.echo_mode == (INT32) TRUE)
  283.                fprintf(io_config.echo_file, "%02x%02x%02x%02x    ", instr.op, instr.c,
  284.                    instr.a, instr.b);
  285.             fprintf(stderr, "%02x%02x%02x%02x    ", instr.op, instr.c,
  286.                    instr.a, instr.b);
  287.  
  288.             /* Disassemble instruction */
  289.             dasm_instr(address, &instr);
  290.             fprintf(stderr, "\n");
  291.         if (io_config.echo_mode == (INT32) TRUE)
  292.                fprintf(io_config.echo_file, "\n");
  293.  
  294.             }  /* end for(j) */
  295.  
  296.          fprintf(stderr, "\n");
  297.      if (io_config.echo_mode == (INT32) TRUE)
  298.            fprintf(io_config.echo_file, "\n");
  299.  
  300.          }  /* end for(set) */
  301.  
  302.       i = i + 1;
  303.  
  304.       }  /* end while loop */
  305.  
  306.    return (0);
  307.  
  308.    }  /* end il_cmd() */
  309.  
  310.  
  311.  
  312. /*
  313. **  ix
  314. **  This command will dump the contents of the cache in hex 
  315. ** This command is used to examine the contents of the cache
  316. ** in the Am29030.  
  317. ** First set 0 is printed, starting with the
  318. ** tag, followed by a disassembly of four instructions in
  319. ** the set.  Set 1 for the line follows similarly.
  320. **
  321. ** The data comes in from the READ_ACK message in the following
  322. ** order:
  323. **
  324. **            tag      (data[0-3]    (set 0)
  325. **         instr1      (data[4-7]
  326. **         instr1      (data[8-11]
  327. **         instr1      (data[12-15]
  328. **         instr1      (data[16-19]
  329. **
  330. **            tag      (data[20-23]  (set 1)
  331. **         instr1      (data[24-27]
  332. **         instr1      (data[28-31]
  333. **         instr1      (data[32-35]
  334. **         instr1      (data[36-39]
  335. */
  336.  
  337. INT32
  338. ix_cmd(token, token_count)
  339.    char   *token[];
  340.    int     token_count;
  341.    {
  342.    static INT32  memory_space=I_CACHE;
  343.    static ADDR32 cache_line=0;
  344.    static INT32  byte_count=(10*sizeof(INST32));
  345.    static INT32  count=1;
  346.    ADDR32 address;
  347.    INT32  i;
  348.    int    j;
  349.    int    set;
  350.    int    index;
  351.    int    result;
  352.    struct instr_t instr;
  353.    INT32  cache_line_start;
  354.    INT32  cache_line_end;
  355.  
  356.    INT32    retval;
  357.    INT32    bytes_ret;
  358.    INT32    host_endian;
  359.    BYTE        read_buffer[10*sizeof(INST32)];
  360.    char        prtbuf[256];
  361.  
  362.  
  363.    /* Is it an 'ix' command? */
  364.    if (strcmp(token[0], "ix") != 0)
  365.       return (EMSYNTAX);
  366.  
  367.    /*
  368.    ** Parse parameters
  369.    */
  370.    if (token_count == 1) {
  371.       cache_line = cache_line + count;
  372.       }
  373.    else
  374.    if (token_count == 2) {
  375.       result = get_word(token[1], &cache_line_start);
  376.       if (result != 0)
  377.          return (EMSYNTAX);
  378.       if ((cache_line_start < 0) ||
  379.           (cache_line_start >255))
  380.          return (EMBADADDR);
  381.       cache_line = cache_line_start;
  382.       }
  383.    else
  384.    if (token_count == 3) {
  385.       /* Get first cache line to be dumped */
  386.       result = get_word(token[1], &cache_line_start);
  387.       if (result != 0)
  388.          return (EMSYNTAX);
  389.       if ((cache_line_start < 0) ||
  390.           (cache_line_start > 255))
  391.          return (EMBADADDR);
  392.       /* Get last cache line to be dumped */
  393.       result = get_word(token[2], &cache_line_end);
  394.       if (result != 0)
  395.          return (EMSYNTAX);
  396.       if ((cache_line_end < 0) ||
  397.           (cache_line_end > 255))
  398.          return (EMBADADDR);
  399.       if (cache_line_start > cache_line_end)
  400.          return (EMBADADDR);
  401.       cache_line = cache_line_start;
  402.       count = (cache_line_end - cache_line_start) + 1;
  403.       }
  404.    else
  405.    /* Too many args */
  406.       return (EMSYNTAX);
  407.  
  408.    i = 0;
  409.    while (i < count) {
  410.  
  411.       host_endian = FALSE;
  412.       if ((retval = Mini_read_req(memory_space,
  413.                   (cache_line + i),
  414.                   byte_count/4,
  415.                   (INT16) 4, /* size */
  416.                   &bytes_ret,
  417.                   read_buffer,
  418.                   host_endian)) != SUCCESS) {
  419.      return(FAILURE);
  420.       };
  421.       /* The following is executed if SUCCESSful */
  422.  
  423.       for (set=0; set<2; set++) {
  424.  
  425.          /* Print out formatted address tag and status information */
  426.          index = (set * 20);
  427.          sprintf(&prtbuf[0], "\n");
  428.          sprintf(&prtbuf[strlen(prtbuf)], "Cache line 0x%lx, set %d.\n", (int) (cache_line+i), set);
  429.          sprintf(&prtbuf[strlen(prtbuf)], "\n");
  430.          if (io_config.echo_mode == (INT32) TRUE)
  431.             fprintf (io_config.echo_file, "%s", &prtbuf[0]);
  432.          fprintf (stderr, "%s", &prtbuf[0]);
  433.          sprintf(&prtbuf[0], "IATAG  V  P US\n");
  434.          if (io_config.echo_mode == (INT32) TRUE)
  435.             fprintf (io_config.echo_file, "%s", &prtbuf[0]);
  436.          fprintf (stderr, "%s", &prtbuf[0]);
  437.          sprintf(&prtbuf[0], "%02x%02x%1x  %1x  %1x  %1x\n",
  438.                 read_buffer[index],
  439.                 read_buffer[index + 1],
  440.                 ((read_buffer[index + 2] >> 4) & 0x0f),
  441.                 ((read_buffer[index + 3] >> 2) & 0x01),
  442.                 ((read_buffer[index + 3] >> 1) & 0x01),
  443.                 (read_buffer[index + 3] & 0x01));
  444.          sprintf(&prtbuf[strlen(prtbuf)], "\n");
  445.         if (io_config.echo_mode == (INT32) TRUE)
  446.              fprintf (io_config.echo_file, "%s", &prtbuf[0]);
  447.         fprintf (stderr, "%s", &prtbuf[0]);
  448.  
  449.          /* Address = IATAG + line_number + <16 byte adddress> */
  450.          address = ((read_buffer[index] << 24) |
  451.                     (read_buffer[index + 1] << 16) |
  452.                     (read_buffer[index + 2] << 8) |
  453.                     ((cache_line+i) << 4));
  454.  
  455.          /* Disassemble four words */
  456.          for (j=0; j<4; j=j+1) {
  457.             index = (set * 20) + ((j+1) * sizeof(INT32));
  458.             instr.op = read_buffer[index];
  459.             instr.c = read_buffer[index + 1];
  460.             instr.a = read_buffer[index + 2];
  461.             instr.b = read_buffer[index + 3];
  462.  
  463.             /* Print address of instruction (in hex) */
  464.             address = (address & 0xfffffff0);  /* Clear low four bits */
  465.             address = (address | (j << 2));
  466.             fprintf(stderr, "%08lx    ", address);
  467.         if (io_config.echo_mode == (INT32) TRUE)
  468.                fprintf(io_config.echo_file, "%08lx    ", address);
  469.  
  470.             /* Print instruction (in hex) */
  471.         if (io_config.echo_mode == (INT32) TRUE)
  472.                fprintf(io_config.echo_file, "%02x%02x%02x%02x    ", instr.op, instr.c,
  473.                    instr.a, instr.b);
  474.             fprintf(stderr, "%02x%02x%02x%02x    ", instr.op, instr.c,
  475.                    instr.a, instr.b);
  476.  
  477.             /* Disassemble instruction */
  478.             dasm_instr(address, &instr);
  479.             fprintf(stderr, "\n");
  480.         if (io_config.echo_mode == (INT32) TRUE)
  481.                fprintf(io_config.echo_file, "\n");
  482.  
  483.             }  /* end for(j) */
  484.  
  485.          fprintf(stderr, "\n");
  486.      if (io_config.echo_mode == (INT32) TRUE)
  487.            fprintf(io_config.echo_file, "\n");
  488.  
  489.          }  /* end for(set) */
  490.  
  491.       i = i + 1;
  492.  
  493.       }  /* end while loop */
  494.  
  495.    return (0);
  496.  
  497.    }  /* end ix_cmd() */
  498.  
  499.  
  500.