From 5a0a463feba0426b24619bcb4b4ccf094ef80f1c Mon Sep 17 00:00:00 2001 From: "K. Richard Pixley" Date: Wed, 1 Sep 1993 19:16:57 +0000 Subject: [PATCH] break dcache out of remote-nindy.c --- gdb/ChangeLog | 6 ++ gdb/config/i960/nindy960.mt | 2 +- gdb/remote-nindy.c | 182 ++---------------------------------- 3 files changed, 15 insertions(+), 175 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 26d98bc49f9..5fa4fb6966d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -31,6 +31,12 @@ Tue Aug 31 15:01:27 1993 K. Richard Pixley (rich@sendai.cygnus.com) * Makefile.in (REMOTE_O): add dcache.o. * config/m88k/m88k.mt (TDEPFILES): removed dcache.o. + Break dcache code out of remote-nindy.c. + * remote-nindy.c: removed dcache code. Changed callers to use new + conventions. include dcache.h. + (nindy_dcache): new static variable. + * config/i960/nindy960.mt (TDEPFILES): added dcache.o. + Break dcache code out of remote-bug.c into dcache.[hc]. * Makefile.in (dcache_h): new macro. (HFILES): added $(dcache_h). diff --git a/gdb/config/i960/nindy960.mt b/gdb/config/i960/nindy960.mt index 924bbb43b03..7dd029b8141 100644 --- a/gdb/config/i960/nindy960.mt +++ b/gdb/config/i960/nindy960.mt @@ -1,5 +1,5 @@ # Target: Intel 80960, in an embedded system under the NINDY monitor -TDEPFILES= exec.o i960-pinsn.o i960-tdep.o nindy-tdep.o remote-nindy.o nindy.o Onindy.o ttyflush.o +TDEPFILES= exec.o i960-pinsn.o i960-tdep.o nindy-tdep.o remote-nindy.o dcache.o nindy.o Onindy.o ttyflush.o TM_FILE= tm-nindy960.h # Don't use remote.o; it doesn't compile (and won't work) due to lack of # BREAKPOINT. diff --git a/gdb/remote-nindy.c b/gdb/remote-nindy.c index c168511be7c..3329e49724c 100644 --- a/gdb/remote-nindy.c +++ b/gdb/remote-nindy.c @@ -116,6 +116,10 @@ NINDY ROM monitor at the other end of the line. #include "nindy-share/env.h" #include "nindy-share/stop.h" +#include "dcache.h" + +static DCACHE *nindy_dcache; + extern int unlink(); extern char *getenv(); extern char *mktemp(); @@ -145,12 +149,6 @@ static int regs_changed = 0; /* 1 iff regs were modified since last read */ extern char *exists(); -static void -dcache_flush (), dcache_poke (), dcache_init(); - -static int -dcache_fetch (); - static void nindy_fetch_registers PARAMS ((int)); @@ -190,7 +188,7 @@ nindy_open (name, from_tty) nindy_close (0); have_regs = regs_changed = 0; - dcache_init(); + nindy_dcache = dcache_init(ninMemGet, ninMemPut); /* Allow user to interrupt the following -- we could hang if there's no NINDY at the other end of the remote tty. */ @@ -258,7 +256,7 @@ nindy_resume (pid, step, siggnal) if (siggnal != 0 && siggnal != stop_signal) error ("Can't send signals to remote NINDY targets."); - dcache_flush(); + dcache_flush(nindy_dcache); if ( regs_changed ){ nindy_store_registers (-1); regs_changed = 0; @@ -501,7 +499,7 @@ int nindy_fetch_word (addr) CORE_ADDR addr; { - return dcache_fetch (addr); + return dcache_fetch (nindy_dcache, addr); } /* Write a word WORD into remote address ADDR. @@ -512,7 +510,7 @@ nindy_store_word (addr, word) CORE_ADDR addr; int word; { - dcache_poke (addr, word); + dcache_poke (nindy_dcache, addr, word); } /* Copy LEN bytes to or from inferior's memory starting at MEMADDR @@ -587,170 +585,6 @@ nindy_xfer_inferior_memory(memaddr, myaddr, len, write, target) return len; } -/* The data cache records all the data read from the remote machine - since the last time it stopped. - - Each cache block holds 16 bytes of data - starting at a multiple-of-16 address. */ - -#define DCACHE_SIZE 64 /* Number of cache blocks */ - -struct dcache_block { - struct dcache_block *next, *last; - unsigned int addr; /* Address for which data is recorded. */ - int data[4]; -}; - -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 & 0xfffffff0) == 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[(addr>>2)&3]); -} - -/* 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++; - ninMemGet(addr & ~0xf, (unsigned char *)db->data, 16); - immediate_quit--; - db->addr = addr & ~0xf; - 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++; - ninMemGet(addr & ~0xf, (unsigned char *)db->data, 16); - immediate_quit--; - db->addr = addr & ~0xf; - remque (db); /* Off the free list */ - insque (db, &dcache_valid); /* On the valid list */ - } - - /* Modify the word in the cache. */ - db->data[(addr>>2)&3] = data; - - /* Send the changed word. */ - immediate_quit++; - ninMemPut(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