-/* External data declarations */
-extern int stop_soon_quietly; /* for wait_for_inferior */
-
-/* Forward data declarations */
-extern struct target_ops hms_ops; /* Forward declaration */
-
-/* Forward function declarations */
-static void hms_fetch_registers ();
-static int hms_store_registers ();
-static void hms_close ();
-static int hms_clear_breakpoints();
-
-extern struct target_ops hms_ops;
-
-static int quiet = 1;
-
-#ifdef DEBUG
-# define DENTER(NAME) if (!quiet) (printf_filtered("Entering %s\n",NAME), fflush(stdout))
-# define DEXIT(NAME) if (!quiet) (printf_filtered("Exiting %s\n",NAME), fflush(stdout))
-#else
-# define DENTER(NAME)
-# define DEXIT(NAME)
-#endif
-
-
-/***********************************************************************/
-/* Caching stuff stolen from remote-nindy.c */
-
-/* The data cache records all the data read from the remote machine
- since the last time it stopped.
-
- Each cache block holds LINE_SIZE bytes of data
- starting at a multiple-of-LINE_SIZE address. */
-
-
-#define LINE_SIZE_POWER 4
-#define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
-#define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
-#define DCACHE_SIZE 64 /* Number of cache blocks */
-#define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
-struct dcache_block {
- struct dcache_block *next, *last;
- unsigned int addr; /* Address for which data is recorded. */
- int data[LINE_SIZE/sizeof(int)];
-};
-
-struct dcache_block dcache_free, dcache_valid;
-
-/* Free all the data cache blocks, thus discarding all cached data. */
-static
-void
-dcache_flush ()
-{
- register struct dcache_block *db;
-
- while ((db = dcache_valid.next) != &dcache_valid)
- {
- remque (db);
- insque (db, &dcache_free);
- }
-}
-
-/*
- * If addr is present in the dcache, return the address of the block
- * containing it.
- */
-static
-struct dcache_block *
-dcache_hit (addr)
- unsigned int addr;
-{
- register struct dcache_block *db;
-
- if (addr & 3)
- abort ();
-
- /* Search all cache blocks for one that is at this address. */
- db = dcache_valid.next;
- while (db != &dcache_valid)
- {
- if ((addr & ~LINE_SIZE_MASK)== db->addr)
- return db;
- db = db->next;
- }
- return NULL;
-}
-
-/* Return the int data at address ADDR in dcache block DC. */
-static
-int
-dcache_value (db, addr)
- struct dcache_block *db;
- unsigned int addr;
-{
- if (addr & 3)
- abort ();
- return (db->data[XFORM(addr)]);
-}
-
-/* Get a free cache block, put or keep it on the valid list,
- and return its address. The caller should store into the block
- the address and data that it describes, then remque it from the
- free list and insert it into the valid list. This procedure
- prevents errors from creeping in if a ninMemGet is interrupted
- (which used to put garbage blocks in the valid list...). */
-static
-struct dcache_block *
-dcache_alloc ()
-{
- register struct dcache_block *db;
-
- if ((db = dcache_free.next) == &dcache_free)
- {
- /* If we can't get one from the free list, take last valid and put
- it on the free list. */
- db = dcache_valid.last;
- remque (db);
- insque (db, &dcache_free);
- }
-
- remque (db);
- insque (db, &dcache_valid);
- return (db);
-}
-
-/* Return the contents of the word at address ADDR in the remote machine,
- using the data cache. */
-static
-int
-dcache_fetch (addr)
- CORE_ADDR addr;
-{
- register struct dcache_block *db;
-
- db = dcache_hit (addr);
- if (db == 0)
- {
- db = dcache_alloc ();
- immediate_quit++;
- hms_read_inferior_memory(addr & ~LINE_SIZE_MASK, (unsigned char *)db->data, LINE_SIZE);
- immediate_quit--;
- db->addr = addr & ~LINE_SIZE_MASK;
- remque (db); /* Off the free list */
- insque (db, &dcache_valid); /* On the valid list */
- }
- return (dcache_value (db, addr));
-}
-
-/* Write the word at ADDR both in the data cache and in the remote machine. */
-static void
-dcache_poke (addr, data)
- CORE_ADDR addr;
- int data;
-{
- register struct dcache_block *db;
-
- /* First make sure the word is IN the cache. DB is its cache block. */
- db = dcache_hit (addr);
- if (db == 0)
- {
- db = dcache_alloc ();
- immediate_quit++;
- hms_write_inferior_memory(addr & ~LINE_SIZE_MASK, (unsigned char *)db->data, LINE_SIZE);
- immediate_quit--;
- db->addr = addr & ~LINE_SIZE_MASK;
- remque (db); /* Off the free list */
- insque (db, &dcache_valid); /* On the valid list */
- }
-
- /* Modify the word in the cache. */
- db->data[XFORM(addr)] = data;
-
- /* Send the changed word. */
- immediate_quit++;
- hms_write_inferior_memory(addr, (unsigned char *)&data, 4);
- immediate_quit--;
-}
-
-/* The cache itself. */
-struct dcache_block the_cache[DCACHE_SIZE];
-
-/* Initialize the data cache. */
-static void
-dcache_init ()
-{
- register i;
- register struct dcache_block *db;
-
- db = the_cache;
- dcache_free.next = dcache_free.last = &dcache_free;
- dcache_valid.next = dcache_valid.last = &dcache_valid;
- for (i=0;i<DCACHE_SIZE;i++,db++)
- insque (db, &dcache_free);
-}
-
-
-/***********************************************************************
- * I/O stuff stolen from remote-eb.c
- ***********************************************************************/
-
-static int timeout = 2;
-
-static const char *dev_name;
-
-
-/* Descriptor for I/O to remote machine. Initialize it to -1 so that
- hms_open knows that we don't have a file open when the program
- starts. */
-
-
-int is_open = 0;
-int check_open()
-{
- if (!is_open)
- {
- error("remote device not open");
- }
-}
-
-#define ON 1
-#define OFF 0
-
-/* Read a character from the remote system, doing all the fancy
- timeout stuff. */
-static int
-readchar ()
-{
- int ok;
- int buf;
- buf = serial_timedreadchar(timeout, &ok);
-
- if (!ok)
- error ("Timeout reading from remote system.");
-
- if (!quiet)
- printf("%c",buf);
-
- return buf & 0x7f;
-}
-
-static int
-readchar_nofail ()
-{
- int ok;
- int buf;
- buf = serial_timedreadchar(timeout, &ok);
- if (!ok) buf = 0;
- if (!quiet)
- printf("%c",buf);
-
- return buf & 0x7f;
-
-}
-
-/* Keep discarding input from the remote system, until STRING is found.
- Let the user break out immediately. */