CS452 - Real-Time Programming - Spring 2008
Lecture 10 - Kernel Code
Questions & Comment
- 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
- accessed through CS and DS
- This includes the kernel
The compiler assumes that DS = SS
- That is, the stack is in the data segment.
Set DS = ES = FS = GS = SS for each task
There is no GDT in place when the kernel boots
How is this done
- The address of the table is kept in the special register GDTR
- 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
- condition codes
- what is enabled
- Getting started you want to have interrupts disabled!
Setting up a task
- CS points to code in ELF executable
- DS points to memory you allocate for the task.
Context Switch in the 386
int <vector>
iretl
- pops EFLAGS, CS, EIP from the active task's stack
- puts them in the registers
Task to kernel
int <vector> in task
pushal saves all the active task's registers on the active
task's stack
- switch to kernel stack
- you got CS, EIP from IDT
- ESP from your magic place
- DS from the kernel variables
- restore remainder of kernel state from stack
Kernel to task
- save kernel state on kernel stack
- switch to active task's stack
- restore general purpose registers:
popal
- iretl gets EFLAGS, CS, EIP from the task stack.
To get a task going
- Set up its stack so that it's all ready to run its first
instruction
- Schedule
- Kernel to task
For the first user task there is only one possibility for active.
Scheduling
Return to: