rockstar
rockstar

Reputation: 3538

Switch from `User` to `Supervisor` mode in AMR7TDMI processor

I was trying to switch from the User to Supervisor mode on a old board running a ARM7TDMI processor. It has seven operating modes: User, FIQ, IRQ, Supervisor, Abort, Undefined and System. User is the only non-priv mode. I wish to go into Supervisor mode. I am using qemu to emulate this board and also use a Gnu GCC compiler toolchain. I have Linux kernel on the board as well.

From the technical documentation of the processors manual i can see that do so I need to generate a SWI ( Software Interupt) . Here is what the docs say

http://bear.ces.cwru.edu/eecs_382/ARM7-TDMI-manual-pt2.pdf [ Section 4.13 ]

The software interrupt instruction is used to enter Supervisor mode in a controlled
manner. The instruction causes the software interrupt trap to be taken, which effects
the mode change.

I guess i need to write my own interupt handler for the SWI. I can see some posts about it

writing interrupt routines using gcc for arm

Simplest bare metal program for ARM

However when i follow the instructions outlined in the above i get a Segfault. I am a bit confused here. Reading up the way i need to code the interupt handler I realize i need to tweak the Interupt Vector Table to include my new SWI handler. This seems too much of a security risk for a user space program to do. My Segmentation fault may becasue I am corrpting my memory space or simply because I am not allowed make changes to the memory ( i.e add my handler to the IVT)

Can anyone guide me to better resources on how to achieve this ?

Any suggestions on how to solve this problem. I am new to embedded programming so i think my knowledge isnt very good.

Upvotes: 2

Views: 2570

Answers (1)

paulsm4
paulsm4

Reputation: 121699

https://groups.google.com/forum/#!topic/comp.sys.arm/3ybxWHwKKcA

However no ARM chip allows the processor to be switched from user mode to a privileged via an MSR, as this would completely invalidate any process protection implemented by the operating system.

The only way to switch out of user mode is to cause an exception which results in the processor switching to a privileged mode in order to service it via the hardware vectors. The normal way is to use a SWI (software interrupt) instruction either directly or via an OS API, however it is entirely up to the operating system whether implement this facility or grant permission to a particular task.

So, rather than just writing an "ARM interrupt handler", you really need to address the problem at the OS level. In other words, you need to research how to write a Linux kernel driver (which will in turn invoke the ARM commands to switch modes).

There are many, many resources to introduce you to kernel programming. For example:

Upvotes: 2

Related Questions