ARM. Access to R13 and R14 Users from Supervisor Mode

How do I access users R13 and R14 that are saved when I enter supervisor mode? I am using ARM7TDMI.

those. I do not want to access the R14 dispatcher, which now contains the return address in user mode, instead the value of the link register in user mode is required. This is part of the debugger I am writing.

Are there special aliases for these registers?

thanks

+6
arm
source share
2 answers

I will describe the answer to your specific question, but the same approach applies to other modes.

You will need to change the processor mode by changing the mode bits in CPSR in system mode. This will give you access to the SP / LR user mode (R13 and R14). Remember that system mode is privileged, but its R13 and R14 are the same as user mode R13 and R14.

Once you are in system mode, read R13 and R14 and place them where you want. Then just switch the mode bit back to the previous mode (I believe it was the supervisor mode in your example), and you are good to go.

Please note that we did not switch from supervisor to user mode. If you switched from supervisor to user, you could not return to supervisor mode . (Otherwise, there will be no protection against elevation of privileges of the user code). That's why we used system mode - system mode has the privilege, but the registers are the same as in user mode.

You can switch between any privileged modes as you wish by manipulating the mode bits in CPSR. I think they are the lower 5 bits? I am on the road and I have no information at my fingertips. Otherwise, I would provide you with assembly code for what I described above. In fact, if you want to put some hair on your chest, take what I gave you, sell, test and publish here.: - D

(One thing I have to add for the “general case” (yours is very specific) - you can study SPSR to see “where you came from” - and use this to determine which mode you need to switch to.)

By the way, I just recently did this for one of my clients ... a small world, I think.

+9
source share

I found a better way: -

When executing STM, if r15 is not one of the operands, then ^ gives access to user-mode registers. However, auto-increment does not seem to work on the team, and after that, nop is required if you want to access the register bank.

Something like

stmfd r13, {r13-r14}^ ;store r13 and r14 usermode nop sub r13, r13, #8 ;update stack pointer 
+3
source share

All Articles