CS452 - Real-Time Programming - Fall 2010

Lecture 7 - Creating a Task

Pubilic Service Announcements

  1. Re-organized web pages
  2. Performance criteria for the kernel
  3. -3 return value doesn't make sense

After the Software Interrupt

In the kernel

The order matters

kernel entry:
  1. Change to system state
  2. Save the user state
  3. Return to supervisor mode
  4. Get the request
    ldr r3, [lr, #-4]
  5. Retrieve the kernel state, which should not include the scratch registers
  6. Put what you want in the task's TD
  7. Some where above you must have picked up the arguments
  8. Return from getNextRequest( active ) and get to work

Before the Software Interrupt

After a while it's time to leave the kernel

  1. Schedule the next task to run
  2. Call GetNextRequest( active )
  3. Save kernel state on kernel stack
  4. From TD
  5. Set return value by overwriting r0 on user stack
  6. Switch to system mode
  7. Load registers from user stack
  8. Return to supervisor mode
  9. Let it go
    movs   pc, lr
  10. You are now in the stub code
  11. Put the return value where gcc wants it
  12. Return from the stub code

After a while it comes to a kernel primitive

  1. gcc saves the scratch registers to memory
  2. gcc puts the arguments into the scratch registers
  3. bl to your stub code
  4. gcc saves caller state
  5. put the arguments in the right place

Creating a Task

In creating a task you have to do two things

  1. Get and initialize resources needed by the task
  2. Make the task look as if it had just entered the kernel

Things you need to do

Get an unused TD and memory for its stack

Mostly filling in fields in the TD.

  1. task id
  2. stack pointer
  3. SPSR
  4. link register
  5. parent tid
  6. return value
  7. state
  8. install in the ready queues

Must also create the initial stack

The Create Function

You also need a int Create( int priority, void (*code) ( ) ) function to call from user tasks.

Although it's no more than a wrapper there are a few problems to solve.

  1. Passing arguments
  2. Jumping into the kernel
  3. Getting the return value from the kernel and returning it.

What follows just seems to say the same thing again. But we might as well leave it here because some student might find it useful.

How do we implement the API for user code?

  1. This requires a bit of assembly language.
  2. In assembly language all arguments & return values are words.
  3. What happens when Create is called?

What happens when Create returns?

When the caller is next activated,

Return to: