Graphical-Micro-Architecture-Simulator icon indicating copy to clipboard operation
Graphical-Micro-Architecture-Simulator copied to clipboard

BL writes the target PC address to LR instead of the actual return address

Open bobbirrer opened this issue 3 years ago • 6 comments

It appears that rather than writing PC +4 to the LR, the tool instead writes the address of the function to LR. This causes functions to loop endless rather than returning.

bobbirrer avatar Feb 17 '22 14:02 bobbirrer

Hi @bobbirrer ,

Thank you for flagging this up

We are trying to reproduce this issue on our side. Please can you give us more details and examples of the test cases you used for the issues?

Thanks.

OyinkuroBenafa avatar Mar 04 '22 11:03 OyinkuroBenafa

I used the following test code. The program loops infinitely in SUM.

	ADDI	X0, X0, 1
	ADDI	X1, X1, 5
	BL	SUM
END:	B	END
SUM:	ADD	X0, X0, X1
	BR	LR

bobbirrer avatar Mar 04 '22 16:03 bobbirrer

Hi @bobbirrer . Thanks, we will be looking into this. Meanwhile, if you do happen to have an existing bug fix that you would like to contribute to our repository, please see https://github.com/arm-university/Graphical-Micro-Architecture-Simulator/tree/main/Contributions_and_Modifications

franciscatan-armedu avatar Mar 11 '22 11:03 franciscatan-armedu

@franciscatan-armedu - Unfortunately I cannot build the tool. However, I think if you switch lines 876 and 877 of /LEGv8_Simulator/src/com/arm/legv8simulator/client/cpu/CPU.java it should resolve the issue.

Change:

	private void BL(int branchIndex) {
		instructionIndex = branchIndex;
		registerFile[LR] = instructionIndex * INSTRUCTION_SIZE + Memory.TEXT_SEGMENT_OFFSET;
		cpuLog.append("BL \t" + "0x" + Long.toHexString(registerFile[LR]) + " \n");
	}

To:

	private void BL(int branchIndex) {
		registerFile[LR] = instructionIndex * INSTRUCTION_SIZE + Memory.TEXT_SEGMENT_OFFSET;
		instructionIndex = branchIndex;
		cpuLog.append("BL \t" + "0x" + Long.toHexString(registerFile[LR]) + " \n");
	} 

bobbirrer avatar Mar 11 '22 19:03 bobbirrer

Is there an ETC on when this bug might be fixed?

bobbirrer avatar Jun 10 '22 16:06 bobbirrer

@bobbirrer if you are still interested in knowing how to build this project and make the changes yourself I have uploaded a tutorial in this pull request #7

simdeistud avatar Dec 07 '23 20:12 simdeistud