This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Accessing SYSCFG from ARM // Switching to privileged mode

Other Parts Discussed in Thread: OMAP-L138

Hi,

I'm running an OMAP-L138 and I'm trying to access SYSCFG-registers from the ARM.

I run a Linux on that ARM and after booting I call my program. As I understand this program runs in 'user mode' (protected mode) by default. Looking at the memory map of these SYSCFG-registers (http://www.ti.com/lit/ds/symlink/omap-l138.pdf p.74) I can see most of them only being accessable in a 'privileged mode' (unprotected mode) but some seem to be accessable from user mode, such as REVID.

From my program though I get a 'Segmentation fault' when I try to access that register:

CSL_SyscfgRegsOvly sysRegs0 = (CSL_SyscfgRegsOvly) CSL_SYSCFG_0_REGS;

printf("sysRegs0->REVID: %x\n", (sysRegs0->REVID));

Running the very same code from the DSP works. I assume the ARM needs to be in a privileged mode to access any of the SYSCFG-registers?

 

Anyway, how do I conviently switch to a privileged mode from user mode?

I read that this is usually done by software interrupts (SWI / SVC). I don't really know how I would implement something like this is done in assembly. Is there an example around for this?

The other option would be to run the whole application in privileged mode. In the TI-wiki I found this acticle: http://processors.wiki.ti.com/index.php/Boot_Images_for_OMAP-L138
There a file boot.asm is used to do this. How do I link this file?

 

 

Regards,

Mathias

 

 

 

  • Mathias,

    The segmentation fault problem is not an issue related to user mode versus supervisor mode.  You get this error because the program is a Linux process operating in a virtual memory space and you appear to be trying to access the physical address, which is outside the process's virtual memory space. A high-level OS like Linux, running on a processor equipped with an MMU, protects against such accesses. 

    To access a physical address from your program will require the use of the mmap system call.  There is a simple program called devmem2 that shows how this is done.

    If you want to actually modify registers that require you to be in privileged mode, then I think that you will have to do that from the kernel space, which would mean writing a Linux kernel module.

    Regards, Daniel

  • Daniel, thanks a lot for your answer. That piece of code is very helpful.

    As for the modifying registers: Is it really necessary to implement a kernel module?
    I was hoping that I could just enter a supervisor-mode through SVC-call via software-interrupt and then simply modify these registers to my needs.

     

    Regards,

    Mathias

  • Mathias,

    What you are describing is exactly how system calls work in Linux.  These system calls transition you from user space to kernel space (user mode to supervisor mode).  If you were to do a software interrupt, the Linux kernel (who controls the interrupt table and handling) would see that as an attempted system call. So under Linux, you would need to use a real system call (ioctl) and get into the kernel space to call your own code.  As far as I know, this would be the only way to program registers with privileged access restrictions.

    Regards, Daniel

  • Daniel, thanks again for your advice, very much appreciated.

    Regards,

    Mathias