CS452 - Real-Time Programming - Spring 2008

Lecture 8 - Kernel Code

Questions & Comments

  1. Hand back the first assignment, with comments.
  2. Trains lab

Kernel of a Real-time Operating System

Kernel Structure

The kernel is just a function like any other, but which runs forever.

kernel( ) {
  initialize( );
    request = getNextRequest( );
    handle( request );

There are two other ways of writing the kernel, which are both equivalent to the one above.

  initialize( );
  exit-kernel( );
  request = determine-request( );
  handle( request );
  exit-kernel( );


  initialize( );
  exit-kernel( );
  handle( CREATE );
  exit-kernel( );
  and so on;

The first one is the most common. It hides all the interesting stuff inside

int getNextRequest( ) {
  active = schedule( ); //active is a pointer to a TD
  activate( active );
  return determine-request( active ); //the active task doesn't change

What's inside activate( active )?

How do you get the right PC into the interrupt vectors?

Getting the Kernel Started

Each task is a C function

So is the kernel

Each gets compiled and linked into an ELF executable

Then 452-post.py (/u/cs452/public/tools/bin/452-post.py) binds the ELFs together to be downloaded.


Before starting to execute the kernel needs to have

  1. A stack, on which it can place data, with the stack pointer set.
  2. Its first instruction in the PC

The boot loader does this. How?

  1. The bound executable obeys the multiboot specification
  2. The kernel is called by int main( unsigned long magic, multiboot_info_t *mbiaddr )
  3. The stack starts as mbiaddr, magic
  4. multiboot_info_t is a struct with the following interesting fields
    typedef struct multiboot_info {
      unsigned long mods_count;
      unsigned long mods_addr;
    } multiboot_info_t
    The second is a pointer to module_t, the first module record.
  5. module_t is a struct with the following interesting fields
    typedef struct module {
      unsigned long mod_start;
      unsigned long mod_end;
      unsigned long string;
    } module_t

You might find these URLs have some interesting information (and links) if you are really interested in how executables are structured.


or in the multiboot boot process


Return to: