CS452 - Real-Time Programming - Spring 2008

Lecture 10 - Kernel Code


Questions & Comment

  1. First part of kernel

Kernel: Part 1

Primitives to Implement

Test Program


Architecture of X86

Setting up a Task

Every task requires at least two GDTs

The compiler assumes that DS = SS

Set DS = ES = FS = GS = SS for each task

There is no GDT in place when the kernel boots

How is this done

  1. The address of the table is kept in the special register GDTR
  2. lgdt sets GDTR; sgdt reads GDTR

What should be put in the kernel's GDT?

What should be put in a task's GDT?

Yet another register EFLAGS contains processor state such as

Setting up a task

Context Switch in the 386

int <vector>

iretl

Task to kernel

  1. int <vector> in task
  2. pushal saves all the active task's registers on the active task's stack
  3. switch to kernel stack
    1. you got CS, EIP from IDT
    2. ESP from your magic place
    3. DS from the kernel variables
  4. restore remainder of kernel state from stack

Kernel to task

  1. save kernel state on kernel stack
  2. switch to active task's stack
  3. restore general purpose registers: popal
  4. iretl gets EFLAGS, CS, EIP from the task stack.

To get a task going

  1. Set up its stack so that it's all ready to run its first instruction
  2. Schedule
  3. Kernel to task

For the first user task there is only one possibility for active.


Scheduling


Return to: