MSR CPSR_C, #0x13 doesn't work using ARM assembly?
Asked Answered
B

2

5

I'm writing bare metal code (no OS), for an ARM Cortex A9 processor.

I need to read a register which is only accessible on supervisor mode (the multiprocessor affinity register, MPIDR).

When I'm in user mode and try to execute the following instruction (to enter supervisor mode) step by step with a debugger nothing happens.

MSR CPSR_C, #0x13

And my program goes to undefined mode, if I try to read the MPIDR register

Please do you know what i'm missing?

When i use the debugger windows, and force the five first bits of CPSR register to b10011, it works, I go to supervisor.

Becht answered 18/12, 2013 at 8:27 Comment(6)
Are you certain writing to CPSR_C isn't a privileged operation? It doesn't make a lot of sense to protect stuff, if breaking the protection is that easy ...Chalcopyrite
i'm not sure, when i force with the debugger and go to irq mode, and then execute the same instruction, it works.Becht
but if it is a privileged operation, how can i do to enter in supervisor mode coming from user mode, is this not possible?Becht
@rony you do execute a "svc #0" and from user mode and that changes execution to supervisor mode.Vulturine
to expand on that, using the svc/swi instruction from user is a direct path to a supervisor handler, in that handler you can do whatever you want. Not unlike an application layer and kernel layer, somethings you must or should do in the kernel, others can be done in either place your choice. You will need to write a svc/swi handler of course and have a way to communicate to the handler what it is you want it to do (since it is one handler and you may want it to do multiple things) the immediate is tempting but better to just use a register, r0 for example.Sal
@auselen, thanks, that answers to my questionBecht
V
6

You can't change between modes using instructions which directly write to the CPSR mode bits in User mode. Proper way is to use a svc (supervisor call) and execute necessary instruction requested.

Vulturine answered 18/12, 2013 at 8:44 Comment(0)
D
1

Use cps instruction, e.g.

# Disable ABT, IRQ, FIQ and set SVC mode
cpsid aif, #0x13
Doubloon answered 31/8, 2020 at 10:16 Comment(1)
Please provide some explanation why do you think your proposed solution might help the OP.Wampumpeag

© 2022 - 2024 — McMap. All rights reserved.