CS452 - Real-Time Programming - Winter 2016

Lecture 8 - Create

Public Service Annoucements

  1. Due date for kernel 1: 28 January, 2015
  2. Some questions suggest that there are students who have made little progress.
  3. Please remember that some aspects of the system configuration you get depends on the state in which it was left by the previous group. I have seen very hard to find bugs occur at the last minute because a group unknowingly relied on state provided by the group before it.

Initializing the Kernel

Set up the Hardware

RedBoot gives you the processor with

There is a subtlety here. There are actually three ways that you can get into RedBoot and the state of the hardware is slightly different.

Then there are a few things you need to do. While RedBoot gives you the system as described above, there may be things done by a previous student that changed what RedBoot thinks it is giving you.

  1. Initialize busy-wait I/O.
  2. Initialize low memory.
  3. Turn off interrupts in the ICU etc.
  4. As a debugging aid I sometimes put distinct bit patterns in the registers in order to get some easy information about what is going where.

Prepare the Kernel Data Structures

Where is the kernel's stack pointer, right now? What is on the bottom of the stack?

The kernel data structures. At the very least you need

  1. an array of empty ready queues
  2. a pointer to the TD of the active task
  3. an array of TDs
  4. a free list of pointers to free TDs. This might take the form of bits set in a couple of words.

Prepare the Memory to be Used by Tasks

Some of the state of a task on creation is task-independent. You can, if you want to, initialize it in every TD and every block of memory right now.

Create the First User Task

Run with hardware interrupts turned off for now. But hardware interrupts in user tasks are turned on in kernel 3 though they stay off in the kernel.

What you do in creating the First User Task is exactly what you do creating any other task. All the same this is a place where you probably don't want to run the same code.

Reminder. The place where the kernel starts executing has the global name main, which cannot be re-used.


Other Primitives

These primitives exist mostly so that we, which includes you, can ensure that task creation and scheduling are working when there is not much else implemented.

Tid MyTid( )

Self-explanatory

A question, to which there is a correct answer, or more specifically, a correct (answer, reason) pair.

Tid MyParentTid( )

Self-explanatory

Where is the parent Tid, and how does the kernel find it?

void Pass( )

Doesn't block: task calling Pass( ) makes a state transition from ACTIVE to READY.

Does reschedule.

When is Pass( ) a NOP?

void Exit( )

Calling task is removed from all queues, but its resources are not reclaimed or reused.

That is, the task goes into a zombie state, and will never become active or ready, but continues to own all its resources.


Return to:

Initializing the Kernel

Initial state of hardware

This depends on whether you have

since the previous program exited. For example, you can inherit the CPU with bwio initialized.

In general, the state is

  1. MMU set so that you see 32 Mbytes of contiguous memory.
  2. Interrupts off in the cpsr.
  3. svc execution mode.
  4. no interrupts enabled in the ICU.
  5. stack pointer pointing at the next/current value at the top of the stack. (predecrement/postincrement versus postdecrement/preincrement)

Set up the Hardware

  1. busy-wait io
  2. low memory
  3. Turn off interrupts in the ICU

Prepare the Kernel Data Structures

Where is the kernel's stack pointer, right now? What does the stack look like?

The kernel data structures

  1. an array of empty ready queues
  2. a poimter to the TD of the active task
  3. an array of TDs
  4. a free list of pointers to free TDs

Prepare the Memory to be Used by Tasks

  1. Think about
  2. Could do some memory initialization at this point.

Create the First User Task

Can run with hardware interrupts turned off for now. But when hardware interrupts are turned on in kernel 3 interrupts in user tasks must be turned on, though they stay off in the kernel.

Reminder. The place where the kernel starts executing has the global name main, which cannot be re-used. The linker usually places main at the beginning of the load image.


Other Primitives

These primitives exist mostly so that we, which includes you, can ensure that task creation and scheduling are working when there is not much else implemented.

Tid MyTid( )

Doesn't block: task calling MyTid( ) makes a state transition from ACTIVE to READY.

A question, to which there is a correct answer, or more specifically, a correct (answer, reason) pair.

Tid MyParentTid( )

Doesn't block: task calling MyParentTid( ) makes a state transition from ACTIVE to READY.

Where is the parent Tid, and how does the kernel find it?

void Pass( )

Doesn't block: task calling Pass( ) makes a state transition from ACTIVE to READY.

Does reschedule.

When is Pass( ) a NOP?

void Exit( )

Calling task is removed from all queues, but its resources are not reclaimed or reused.

That is, the task goes into a zombie state, in which it cannot be active or ready, but continues to own all its resources.

Does reschedule.


Return to: