- HMS>r
- PC:8000 SR:070C .7NZ.. CP:00 DP:00 EP:00 TP:00 BR:00
- R0-R7: FF5A 0001 F4FE F500 0000 F528 F528 F4EE
- HMS>
-
-
- */
-
-supply_val (n, size, ptr, segptr)
- int n;
- int size;
- char *ptr;
- char *segptr;
-{
- int ok;
- char raw[4];
- switch (size)
- {
- case 2:
- raw[0] = gethex (2, ptr, &ok);
- raw[1] = gethex (2, ptr + 2, &ok);
- supply_register (n, raw);
- break;
- case 1:
- raw[0] = gethex (2, ptr, &ok);
- supply_register (n, raw);
- break;
- case 4:
- {
- int v = gethex (4, ptr, &ok);
- v |= gethex (2, segptr, &ok) << 16;
- raw[0] = 0;
- raw[1] = (v >> 16) & 0xff;
- raw[2] = (v >> 8) & 0xff;
- raw[3] = (v >> 0) & 0xff;
- supply_register (n, raw);
- }
- }
-
-}
-static void
-hms_fetch_register (dummy)
- int dummy;
-{
-#define REGREPLY_SIZE 108
- char linebuf[REGREPLY_SIZE + 1];
- int i;
- int s;
- int gottok;
-
- LONGEST reg[NUM_REGS];
- check_open ();
-
- do
- {
-
- hms_write_cr ("r");
- expect ("r");
- s = timed_read (linebuf + 1, REGREPLY_SIZE, 1);
-
- linebuf[REGREPLY_SIZE] = 0;
- gottok = 0;
- if (linebuf[3] == 'P' &&
- linebuf[4] == 'C' &&
- linebuf[5] == ':' &&
- linebuf[105] == 'H' &&
- linebuf[106] == 'M' &&
- linebuf[107] == 'S')
- {
-
- /*
- 012
- r**
- -------1---------2---------3---------4---------5-----
- 345678901234567890123456789012345678901234567890123456
- PC:8000 SR:070C .7NZ.. CP:00 DP:00 EP:00 TP:00 BR:00**
- ---6---------7---------8---------9--------10----
- 789012345678901234567890123456789012345678901234
- R0-R7: FF5A 0001 F4FE F500 0000 F528 F528 F4EE**
-
- 56789
- HMS>
- */
- gottok = 1;
-
-
- supply_val (PC_REGNUM, 4, linebuf + 6, linebuf + 29);
-
- supply_val (CCR_REGNUM, 2, linebuf + 14);
- supply_val (SEG_C_REGNUM, 1, linebuf + 29);
- supply_val (SEG_D_REGNUM, 1, linebuf + 35);
- supply_val (SEG_E_REGNUM, 1, linebuf + 41);
- supply_val (SEG_T_REGNUM, 1, linebuf + 47);
- for (i = 0; i < 8; i++)
- {
- static int sr[8] =
- {35, 35, 35, 35,
- 41, 41, 47, 47};
-
- char raw[4];
- char *src = linebuf + 64 + 5 * i;
- char *segsrc = linebuf + sr[i];
- supply_val (R0_REGNUM + i, 2, src);
- supply_val (PR0_REGNUM + i, 4, src, segsrc);
- }
- }
- if (!gottok)
- {
- hms_write_cr ("");
- expect ("HMS>");
- }
- }
- while (!gottok);
-}
-#endif
-
-#ifdef GDB_TARGET_IS_H8300
-static void
-hms_fetch_register (dummy)
- int dummy;
-{
-#define REGREPLY_SIZE 79
- char linebuf[REGREPLY_SIZE + 1];
- int i;
- int s;
- int gottok;
-
- unsigned LONGEST reg[NUM_REGS];
-
- check_open ();
-
- do
- {
- hms_write_cr ("r");
-
- s = timed_read (linebuf, 1, 1);
-
- while (linebuf[0] != 'r')
- s = timed_read (linebuf, 1, 1);
-
- s = timed_read (linebuf + 1, REGREPLY_SIZE - 1, 1);
-
- linebuf[REGREPLY_SIZE] = 0;
- gottok = 0;
- if (linebuf[0] == 'r' &&
- linebuf[3] == 'P' &&
- linebuf[4] == 'C' &&
- linebuf[5] == '=' &&
- linebuf[75] == 'H' &&
- linebuf[76] == 'M' &&
- linebuf[77] == 'S')
- {
- /*
- PC=XXXX CCR=XX:XXXXXXXX R0-R7= XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
- 5436789012345678901234567890123456789012345678901234567890123456789012
- 0 1 2 3 4 5 6
- */
- gottok = 1;
-
- reg[PC_REGNUM] = gethex (4, linebuf + 6, &gottok);
- reg[CCR_REGNUM] = gethex (2, linebuf + 15, &gottok);
- for (i = 0; i < 8; i++)
- {
- reg[i] = gethex (4, linebuf + 34 + 5 * i, &gottok);
- }
- }
- }
- while (!gottok);
- for (i = 0; i < NUM_REGS; i++)
- {
- char swapped[2];
-
- swapped[1] = reg[i];
- swapped[0] = (reg[i]) >> 8;
-
- supply_register (i, swapped);
- }
-}
-#endif
-/* Store register REGNO, or all if REGNO == -1.
- Return errno value. */
-static void
-hms_store_register (regno)
- int regno;
-{
- if (regno == -1)
- {
- for (regno = 0; regno < NUM_REGS; regno++)
- {
- hms_store_register (regno);
- }
- }
- else
- {
- char *name = get_reg_name (regno);
- char buffer[100];
- /* Some regs dont really exist */
- if (!(name[0] == 'p' && name[1] == 'r')
- && !(name[0] == 'c' && name[1] == 'y')
- && !(name[0] == 't' && name[1] == 'i')
- && !(name[0] == 'i' && name[1] == 'n'))
- {
- sprintf (buffer, "r %s=%x", name, read_register (regno));
- hms_write_cr (buffer);
- expect_prompt ();
- }
- }
-}
-
-
-/* Get ready to modify the registers array. On machines which store
- individual registers, this doesn't need to do anything. On machines
- which store all the registers in one fell swoop, this makes sure
- that registers contains all the registers from the program being
- debugged. */
-
-void
-hms_prepare_to_store ()
-{
- /* Do nothing, since we can store individual regs */
-}
-
-static CORE_ADDR
-translate_addr (addr)
- CORE_ADDR addr;
-{
-
- return (addr);
-
-}
-
-/* Read a word from remote address ADDR and return it.
- * This goes through the data cache.
- */
-int
-hms_fetch_word (addr)
- CORE_ADDR addr;
-{
- return dcache_fetch (remote_dcache, addr);
-}
-
-/* Write a word WORD into remote address ADDR.
- This goes through the data cache. */
-
-void
-hms_store_word (addr, word)
- CORE_ADDR addr;
- int word;
-{
- dcache_poke (remote_dcache, addr, word);
-}
-
-int
-hms_xfer_inferior_memory (memaddr, myaddr, len, write, target)
- CORE_ADDR memaddr;
- char *myaddr;
- int len;
- int write;
- struct target_ops *target; /* ignored */
-{
- register int i;
-
- /* Round starting address down to longword boundary. */
- register CORE_ADDR addr;
-
- /* Round ending address up; get number of longwords that makes. */
- register int count;
-
- /* Allocate buffer of that many longwords. */
- register int *buffer;
-
- memaddr &= 0xffff;
- addr = memaddr & -sizeof (int);
- count = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
-
- buffer = (int *) alloca (count * sizeof (int));
-
- if (write)
- {
- /* Fill start and end extra bytes of buffer with existing memory data. */
-
- if (addr != memaddr || len < (int) sizeof (int))
- {
- /* Need part of initial word -- fetch it. */
- buffer[0] = hms_fetch_word (addr);
- }
-
- if (count > 1) /* FIXME, avoid if even boundary */
- {
- buffer[count - 1]
- = hms_fetch_word (addr + (count - 1) * sizeof (int));
- }
-
- /* Copy data to be written over corresponding part of buffer */
-
- memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
-
- /* Write the entire buffer. */
-
- for (i = 0; i < count; i++, addr += sizeof (int))
- {
- errno = 0;
- hms_store_word (addr, buffer[i]);
- if (errno)
- {
- return 0;
- }
-
- }
- }
- else
- {
- /* Read all the longwords */
- for (i = 0; i < count; i++, addr += sizeof (int))
- {
- errno = 0;
- buffer[i] = hms_fetch_word (addr);
- if (errno)
- {
- return 0;
- }
- QUIT;
- }
-
- /* Copy appropriate bytes out of the buffer. */
- memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
- }
-
- return len;
-}
-
-int
-hms_write_inferior_memory (memaddr, myaddr, len)
- CORE_ADDR memaddr;
- unsigned char *myaddr;
- int len;
-{
- bfd_vma addr;
- int done;
- int todo;
- char buffer[100];
- done = 0;
- hms_write_cr (".");
- expect_prompt ();
- while (done < len)
- {
- char *ptr = buffer;
- int thisgo;
- int idx;
-
- thisgo = len - done;
- if (thisgo > 20)
- thisgo = 20;
-
- sprintf (ptr, "M.B %4x =", memaddr + done);
- ptr += 10;
- for (idx = 0; idx < thisgo; idx++)
- {
- sprintf (ptr, "%2x ", myaddr[idx + done]);
- ptr += 3;
- }
- hms_write_cr (buffer);
- expect_prompt ();
- done += thisgo;
- }
-}
-
-void
-hms_files_info ()
-{
- char *file = "nothing";
-
- if (exec_bfd)
- file = bfd_get_filename (exec_bfd);
-
- if (exec_bfd)
-#ifdef __GO32__
- printf_filtered ("\tAttached to DOS asynctsr and running program %s\n", file);
-#else
- printf_filtered ("\tAttached to %s at %d baud and running program %s\n", dev_name, baudrate, file);
-#endif
- printf_filtered ("\ton an H8/300 processor.\n");
-}
-
-/* Copy LEN bytes of data from debugger memory at MYADDR
- to inferior's memory at MEMADDR. Returns errno value.
- * sb/sh instructions don't work on unaligned addresses, when TU=1.
- */
-
-/* Read LEN bytes from inferior memory at MEMADDR. Put the result
- at debugger address MYADDR. Returns errno value. */
-int
-hms_read_inferior_memory (memaddr, myaddr, len)
- CORE_ADDR memaddr;
- char *myaddr;
- int len;
-{
- /* Align to nearest low 16 bits */
- int i;
-
- CORE_ADDR start = memaddr;
- CORE_ADDR end = memaddr + len - 1;
-
- int ok = 1;
-
- /*
- AAAA: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX '................'
- 012345678901234567890123456789012345678901234567890123456789012345
- 0 1 2 3 4 5 6
- */
- char buffer[66];
-
- if (memaddr & 0xf)
- abort ();
- if (len != 16)
- abort ();
-
- sprintf (buffer, "m %4x %4x", start & 0xffff, end & 0xffff);
-
- flush ();
- hms_write_cr (buffer);
- /* drop the echo and newline */
- for (i = 0; i < 13; i++)
- readchar ();
-
- /* Grab the lines as they come out and fill the area */
- /* Skip over cr */
- while (1)
- {
- int p;
- int i;
- int addr;
- size_t idx;
-
- char byte[16];
-
- buffer[0] = readchar ();
- while (buffer[0] == '\r'
- || buffer[0] == '\n')
- buffer[0] = readchar ();
-
- if (buffer[0] == 'M')
- break;
-
- for (i = 1; i < 50; i++)
- {
- buffer[i] = readchar ();
- }
- /* sometimes we loose characters in the ascii representation of the
- data. I don't know where. So just scan for the end of line */
- i = readchar ();
- while (i != '\n' && i != '\r')
- i = readchar ();
-
- /* Now parse the line */
-
- addr = gethex (4, buffer, &ok);
- idx = 6;
- for (p = 0; p < 16; p += 2)
- {
- byte[p] = gethex (2, buffer + idx, &ok);
- byte[p + 1] = gethex (2, buffer + idx + 2, &ok);
- idx += 5;
- }
-
- for (p = 0; p < 16; p++)
- {
- if (addr + p >= memaddr &&
- addr + p < memaddr + len)
- {
- myaddr[(addr + p) - memaddr] = byte[p];
-
- }
-
- }
- }
-#ifdef GDB_TARGET_IS_H8500
- expect ("ore>");
-#endif
-#ifdef GDB_TARGET_IS_H8300
- expect ("emory>");
-#endif
- hms_write_cr (".");
-
- expect_prompt ();
- return len;
-}
-
-
-
-#define MAX_BREAKS 16
-static int num_brkpts = 0;
-static int
-hms_insert_breakpoint (addr, save)
- CORE_ADDR addr;
- char *save; /* Throw away, let hms save instructions */
-{
- check_open ();
-
- if (num_brkpts < MAX_BREAKS)
- {
- char buffer[100];
-
- num_brkpts++;
- sprintf (buffer, "b %x", addr & 0xffff);
- hms_write_cr (buffer);
- expect_prompt ();
- return (0);
- }
- else
- {
- fprintf_filtered (gdb_stderr,
- "Too many break points, break point not installed\n");
- return (1);
- }
-
-}
-static int
-hms_remove_breakpoint (addr, save)
- CORE_ADDR addr;
- char *save; /* Throw away, let hms save instructions */
-{
- if (num_brkpts > 0)
- {
- char buffer[100];
-
- num_brkpts--;
- sprintf (buffer, "b - %x", addr & 0xffff);
- hms_write_cr (buffer);
- expect_prompt ();
-
- }
- return (0);
-}
-
-/* Clear the hmss notion of what the break points are */
-static int
-hms_clear_breakpoints ()
-{
-
- if (is_open)
- {
- hms_write_cr ("b -");
- expect_prompt ();
- }
- num_brkpts = 0;
-}