Previous Thread
Next Thread
Print Thread
Page 1 of 4 1 2 3 4
Debugger Help - Tips, Tricks and Annoyances #94208 05/07/14 02:34 PM
Joined: Apr 2010
Posts: 50
H
Happy Offline OP
Member
OP Offline
Member
H
Joined: Apr 2010
Posts: 50
How to get MIPS registers working.

The debugger does not seem to appreciate/understand the '$' symbol in register names. Typing 'print $at' will result in an error 'invalid number'. To remedy the situation, edit the file /src/emu/cpu/mips/mips3com.c

In function 'mips3com_get_info' at lines 575-606 change

Code:
	case CPUINFO_STR_REGISTER + MIPS3_R1:           sprintf(info->s, "  $at: %08X%08X", (UINT32)(mips->r[1] >> 32), (UINT32)mips->r[1]); break;


to

Code:
	case CPUINFO_STR_REGISTER + MIPS3_R1:           sprintf(info->s, "  at: %08X%08X", (UINT32)(mips->r[1] >> 32), (UINT32)mips->r[1]); break;



Simply delete the '$' symbol from each register name and then in the debugger you can use expressions 'at = 5', 'print at' and so on.


Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94209 05/07/14 03:38 PM
Joined: May 2009
Posts: 1,840
J
Just Desserts Offline
Very Senior Member
Offline
Very Senior Member
J
Joined: May 2009
Posts: 1,840
Sorry, I thought you had something more substantial when I suggested making a thread about it. Yes, that hack does work, but it's a hack: The MIPS ABI is rather clear about register names being prepended with $.

Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94210 05/07/14 03:58 PM
Joined: Apr 2010
Posts: 50
H
Happy Offline OP
Member
OP Offline
Member
H
Joined: Apr 2010
Posts: 50
I realize that it is a hack, which I why I hesitated to make a post. However, if desperate to be able to work with MIPS this is a reasonably small alteration. The disassembler has its own string table for the registers and the disassembly still displays with the '$at' register names. I am still trying to figure out why the '$' symbol trips up the debugger parsing.


I also have looked into why the 'source' command does not work. So far I have found that somewhere between the call to 'process_source_file' and the first lines of the function 'process_source_file', 'global->execution_state == EXECUTION_STATE_STOPPED' ceases to be true.

Code:

		while (global->execution_state == EXECUTION_STATE_STOPPED)
		{
			// flush any pending updates before waiting again
			machine.debug_view().flush_osd_updates();

			// clear the memory modified flag and wait
			global->memory_modified = false;
			if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)
				machine.osd().wait_for_debugger(m_device, firststop);
			else if (machine.debug_flags & DEBUG_FLAG_ENABLED)
				debugint_wait_for_debugger(m_device, firststop);
			firststop = false;

			// if something modified memory, update the screen
			if (global->memory_modified)
			{
				machine.debug_view().update_all(DVT_DISASSEMBLY);
				debugger_refresh_display(m_device.machine());
			}

			// check for commands in the source file
			process_source_file(m_device.machine());

			// if an event got scheduled, resume
			if (machine.scheduled_event_pending())
				global->execution_state = EXECUTION_STATE_RUNNING;
		}
 


and the function

Code:


static void process_source_file(running_machine &machine)
{
	debugcpu_private *global = machine.debugcpu_data;

	/* loop until the file is exhausted or until we are executing again */
	while (global->source_file != NULL)  && global->execution_state == EXECUTION_STATE_STOPPED) 



I am still trying to work out the structure and design of the debugger to understand what can change the execution_state during this process.

Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94211 05/07/14 04:00 PM
Joined: Nov 2003
Posts: 804
S
smf Offline
Senior Member
Offline
Senior Member
S
Joined: Nov 2003
Posts: 804
Originally Posted By Just Desserts
Sorry, I thought you had something more substantial when I suggested making a thread about it. Yes, that hack does work, but it's a hack: The MIPS ABI is rather clear about register names being prepended with $.


Can you point out where that is as I can't find any MIPS manuals that use $ in register names.

They are pretty unclear on the assembler syntax too as they always list the syntax with rs/rt/rd. However there are a couple of samples in the manual, which don't use $

SW R2, (r3) # uncached store
NOP # NOP 1
NOP # NOP 2
NOP # NOP 3
NOP # NOP 4
NOP # NOP 5
NOP # NOP 6
NOP # NOP 7
SW R2, (R3) # uncached store

They stopped using the at/v0 etc names for registers by the r4400 manual. They aren't listed at all anywhere.

Two of the CPU general purpose registers have assigned functions:
r0 is hardwired to a value of zero, and can be used as the target register for any instruction whose result is to be discarded. r0 can also be used as a source when a zero value is needed.
r31 is the link register used by Jump and Link instructions. It should not be used by other instructions.
The CPU has three special purpose registers:
PC Program Counter register
HI Multiply and Divide register higher result
LO Multiply and Divide register lower result

Last edited by smf; 05/07/14 04:15 PM.
Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94213 05/07/14 04:11 PM
Joined: Mar 2001
Posts: 16,473
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,473
IDA Pro uses the $ notation, with your choice of bare r0-r31 or the more customary v0/s0/etc.

Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94214 05/07/14 04:20 PM
Joined: Nov 2003
Posts: 804
S
smf Offline
Senior Member
Offline
Senior Member
S
Joined: Nov 2003
Posts: 804
I guess IDA Pro adds the $ because some assembler uses it. Like gas syntax would end up with us adding % to the front of all x86 registers

movl -4(%ebp, %edx, 4), %eax # Full example: load *(ebp - 4 + (edx * 4)) into eax
movl -4(%ebp), %eax # Typical example: load a stack variable into eax
movl (%ecx), %edx # No offset: copy the target of a pointer into a register
leal 8(,%eax,4), %eax # Arithmetic: multiply eax by 4 and add 8
leal (%eax,%eax,2), %eax # Arithmetic: multiply eax by 2 and add eax (i.e. multiply by 3)

That doesn't mean we should add them to the disassembly and worse to the register list.

Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94338 05/17/14 07:21 PM
Joined: Apr 2010
Posts: 50
H
Happy Offline OP
Member
OP Offline
Member
H
Joined: Apr 2010
Posts: 50
I have found where a change would need to be made to parse '$at' as a symbol, however, given the differing opinions on what the proper symbol should be, I will let the boffins decide what to do.

Anyway, in file emu/debug/express.c at line 930 in 'parse_symbol_or_number'

Code:

	// if we have a $ prefix, we are a hex value
	if (buffer[0] == '$')
		return parse_number(token, buffer.cstr() + 1, 16, expression_error::INVALID_NUMBER);



decides that anything starting with a '$' must be a hex number and not a symbol. Thus '$at' ends up as an INVALID_NUMBER.

Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94339 05/17/14 08:26 PM
Joined: Apr 2004
Posts: 1,554
J
judge Online Content
Very Senior Member
Online Content
Very Senior Member
J
Joined: Apr 2004
Posts: 1,554
we would simply need to add support for an escape character for cases like this

Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94340 05/17/14 08:40 PM
Joined: Nov 2003
Posts: 804
S
smf Offline
Senior Member
Offline
Senior Member
S
Joined: Nov 2003
Posts: 804
That would make sense except none of the MIPS documentation ever mentions the $.

It especially makes no sense in the register names, even if the disassembler has to match IDA rather than the MIPS documentation.

Re: Debugger Help - Tips, Tricks and Annoyances [Re: Happy] #94341 05/17/14 08:49 PM
Joined: Mar 2001
Posts: 16,473
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,473
So someone remove the $ from the names then. And add a raw/ABI switch for bonus points.

Page 1 of 4 1 2 3 4

Who's Online Now
2 registered members (Stiletto, reenigne), 123 guests, and 1 spider.
Key: Admin, Global Mod, Mod
ShoutChat Box
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,764
Posts115,179
Members4,889
Most Online890
Jan 17th, 2020
Powered by UBB.threads™ PHP Forum Software 7.7.3