Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bobbirrer opened this issue Feb 17, 2022 · 6 comments
Assignees

Comments

@bobbirrer
Copy link

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.

@OyinkuroBenafa
Copy link

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.

@bobbirrer
Copy link
Author

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

@franciscatan-armedu
Copy link
Contributor

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

@bobbirrer
Copy link
Author

@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
Copy link
Author

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

@simdeistud
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants