This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Adding Registers



dave> Is it possible to add extra registers to gdb that link to a memory address,
      eg R0 links to 0x00h ?

Not directly with out of the box prebuilt stuff. but if you want to
modify/tweak GDB sources to do something like this.... you can do it.

I know you can do that... I've done things like that on a few custom
ports I've done. :->

Basically you need to look at the CPU definition file for the machine
you want want to use.

For instance: Our custom cpu has 3 banks of 16 registers, 32bits each,
plus a few spares. We actually tell GDB there are 4 banks, plus the
extra ones. The "Current bank" and bank 0,1 and 2. The current bank
ends up being a ghost of what ever happens to be the current bank.

Example:

In the various "tm-CPUNAME.h" files (tm-arm.h, tm-m68k.h, etc) Look
for 'NUM_REGS', increase this number.  There are a number of other
macros that need tweaking.

Things like: "REGISTER_BYTES" and "REGISTER_BYTE()" macros,
and the register names to name a few.

In some of the target machine descriptions you'll notice that they
talk about "phony" registers, that's basically what you are doing.

You'll want to look at the functions (really macros) in target.h

       target_fetch_registers()
       target_store_registers()

and work through how they are called.

Basically, when GDB needs a register value, it will
call the function:

	   target_fetch_register( MY_FUNKY_REGISTER )

You'll need to modify whatever that eventually resolves to in the
target machine code (typically the "CPUNAME-tdep.c" file) so that it
does something like this:

void
my_target_fetch_register( int id )
{
	if( (id >= MY_FIRST_FUNKY_REGISTER) && 
	    (id <= MY_LAST_FUNKY_REGISTER) ){
		do_that_special_thing(id);
	} else {
	        call_existing_code(id);
	}
}

There are caviats to this:

GDB will seemingly periodically randomly call and ask for registers
when you least expect it, you quitely must just supply something or
have GDB go wacky on you. [Certian registers are only readable in
certian modes (ie: supervisor or user), or if the hardware is
configured a certian way.]

Another problem is if you are using a graphical front end, like
insight the display register window can get really huge and darn right
ugly.

In the specific example you give, if you modify memory via other means
(ie: Peek/Poke bytes some how) the values in the static register
display will be out of sync with what is in memory.

Doing things like this can be viewed like this: 

      You give a somebody a knife.
      You remind them they can cut themself. 
      They walk away, only to return bleeding and confused. 
      Do you really want to give them the knife?
      Is the knife really that important?

I find that many times you must give them the knife. You just wish
some of the others never found the knife. There are those people who
just don't, won't, or refuse to understand the danger of the knife.

-Duane.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]