1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

What is the preferred way of doing a context switch on the ARM?

Discussion in 'Embedded' started by Michael, Aug 29, 2008.

  1. Michael

    Michael Guest

    I’m asking, because I see no clean way to do it. On stack based
    machines you simply “pushall” onto the active task’s stack, switch
    stacks, and do a “popall”. The ARM makes this difficult because when
    it switches to a privileged mode, the active task’s stack becomes
    “invisible”, and the CPSR gets saved into the SPSR (as opposed to
    being pushed onto the stack). Thanks!
     
    Michael, Aug 29, 2008
    #1
    1. Advertisements

  2. Op Fri, 29 Aug 2008 07:45:34 +0200 schreef Michael
    User-defined task code is only run in User or System mode, which both use
    the 'unaliased' registers. On an exception, the processor starts using
    alternative registers, but you can go to System mode to access those
    unaliased registers and push them (and the SPSR as well, of course).
     
    Boudewijn Dijkstra, Aug 29, 2008
    #2
    1. Advertisements

  3. Michael

    Michael Guest

    Yes, but I was looking for a clean way to do it (no mode changing).
    Also there's the question of what register to use for the STM / LDM
    instructions. Evidently you need to push a register onto the privilege
    mode's stack. I would think that there would be a cleaner way...
     
    Michael, Aug 29, 2008
    #3
  4. Michael

    Tauno Voipio Guest


    The architecture is designed to use some privileged
    mode (e.g. supervisor) to do the context switch. Do
    not attempt to fight it.
     
    Tauno Voipio, Aug 29, 2008
    #4
  5. Michael

    Michael Guest

    Not fighting it at all, just don't see a clean way to do it in a few
    instructions. Do you have any ideas?
     
    Michael, Aug 29, 2008
    #5
  6. Op Fri, 29 Aug 2008 15:39:06 +0200 schreef Michael
    This is the clean way, because it's the only right way. ;)

    I believe it was designed this way to allow for short & fast ASM-only
    exception
    handlers. Only if you need more registers, then some PSR-switching is
    required.
    That's why they have a stack, and that's what this stack is for. And if
    you
    intend to call a function from the IRQ exception (such as an interrupt
    process
    function), then you need to push R14 anyway.
    But there isn't. Welcome to the dirty realm of possibilities! :)
     
    Boudewijn Dijkstra, Aug 29, 2008
    #6
  7. Michael

    Michael Guest

    Thanks for your help. I'm surprised that the ARM architects didn't
    provide for this (easy context switching).
     
    Michael, Aug 29, 2008
    #7
  8. Michael

    FreeRTOS.org Guest

    Thanks for your help. I'm surprised that the ARM architects didn't
    They did - its called a Cortex M3 ;o)

    --
    Regards,
    Richard.

    + http://www.FreeRTOS.org & http://www.FreeRTOS.org/shop
    17 official architecture ports, more than 6000 downloads per month.

    + http://www.SafeRTOS.com
    Certified by TÜV as meeting the requirements for safety related systems.
     
    FreeRTOS.org, Aug 29, 2008
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.