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.

how to access PSR register in OMAL138

Other Parts Discussed in Thread: OMAPL138

Hi,

I was trying to write PINMUX register. But I was told to be a fault operation. The FLTADDR displays the address of the PINMUX register and FLTSTAT shows 2 (User write) in the TYPE field. I doubted that maybe I was in user mode thus can't write PINMUX register. So I want to to the PSR register, which is used to control the operating mode as said in the processor manual. However, I was unable to find such a register in the debug window. Is it possible this version of ARM in omapl138 doesn't have this register?

Since I wrote the PINMUX register right after the emulator was connected to omapl138, so no operating modes was changed after the emulator was connected. This means in the emulation state, our programming is in user mode instead of supervisor mode. So how can I switch to supervisor mode without generating an interrupt? Do I have to modify the boot file that was used by emulator? If I do, what and where is the boot file emulator is using?

Does anybody know this?

Thanks,

Fu

  • One more point: I was using the ARM part in omapl138. In DSP, the codes run very well.

  • Zhang,

    If you are using Linux and u-boot bootloader, there is an easy way out. You can just go to the u-boot command prompt, and type the memory write command "mw 0xffset 0xvalue". This will write to the memory address specified.

  • Hi Renjith

    Thanks for your reply. Unfortunately, I am writing some codes on omapl138 without running any operating system on it. I can only change operating state by my own codes. I was thinking if PSR is not a memory mapped register, there should be some instruction that can directly modify PSR register, but I could not find these instructions neither.

    Fu

  • Fu,

    I guess you are referring to CPSR (Current Program Status Register). This is ARM core's internal register. It will be used to maintain the current program state and processor mode etc. You should be able to see the register in the debugger's CPU registers window. You can change the CPU mode in this register's last 5 bits.

  • Renjith,

    You are right, I found that register under the Core Register list. After connecting to omapl138, it is indeed in user mode as I guessed. If I change it to be supervisor mode, my codes run very well.  But it seems very inconvenient to change it before running the codes every time. So I was wondering is there a way to change the boot file used by emulator such that It doesn't go to user mode?

    Thanks very much,

    Fu

  • Fu,

    The proper method is to switch to supervisor mode in the init code of your bootloader. Generally all bootloaders startup code does that first. You can try your own assembly code in the beginning of your code.

  • Renjith,

    You are pretty right, int the debug session window, I noticed that the function running right before my main function is a segment code called _c_int00.  In the memory, I found that segment codes, where  there is a line like MSR CPSR_cf, #0x10, which I believe is used to set the CPSR mode field to be 0x10, which is user mode. But the problem is that If I click the debug button, CCS will use its default bootloader and runs _c_int00. At the moment I can control it the ARM is already in user mode, It seems that I cannot switch back to supervisor mode from user mode by just writing the CPSR registers. So I have to modify _c_int00, change it to be MSR CPSR_cf, #0x13, which means supervisor mode. To do this I have to access the bootloader. But I don't know where is the bootloader and how to access it in CCS. Do you have any idea or some other way to do this?

    Thanks,

    Fu

  • Fu,

    If you are loading the program from your CCS debugger, then _c_int00 is the entry point of your program. It will do basic initializations, stack, BSS etc.. Then it will give control to your program. Since your purpose of switching to SVC mode is to just to write PINMUX register, you can write the register from the GEL file that you are using. 

    Alternatively, you can write a startup code for your program, write few lines of assembly code to SVC mode, write the pinmux register and then jump to _c_int00. It will continue the execution from there.

    Third way is to write a routine in your code to switch to SVC and call it from your main function. 

  • Renjith,

    Thanks for your suggestion, they are very helpful. 

    Actually, my purpose is not only writing PINMUX, I may want to access those registers frequently in my following codes. So I want to all my codes running in supervisor mode. So writing PINMUX in the GEL file may not the final solution. Even startup code can switch ARM to SVC, but it will run _c_int00 eventually switching back to user mode again. Both the first and third method will lead my main function is user mode. However, I think switching to SVC from main functions or its routine may not work because the main function is already running in user mode and switching from user mode to SVC can only be done by generating an interrupt (But I'd prefer not dealing with interrupt now ). 

    This is why I want to _c_int00, where I can disable the line of switching to user mode. This can result in my main function in SVC. But I don't know how to change _c_int00 in the CCS. Or _c_int00 can not be changed?

    Thanks,

    Fu

  • Fu,

    _c_int00 is part of a library that CCS provides. You can copy first few lines of that code and create your own startup code. Then you don't have to use the library(rtse32.lib). You've to take care of three primary things in your code.

    1. SVC mode

    2. Stack pointer setup

    3. BSS segment clearing. 

    But if you don't use this library, then you won't be able to use the stdio functions like printf, fwrite etc. in your code.