Download cubeos a component-based operating system for autonomous systems

Transcript
3.4. DETAILED ASPECTS OF THE IMPLEMENTATION
91
_KERN_ptable[new].state = STATE_RUNNING;
_impure_ptr = &(_KERN_ptable[__MYPID].reent);
KERN_contextsw (&(_KERN_ptable[old].regs),
&(_KERN_ptable[new].regs));
/* this is the new task */
return;
}
Whenever the new and the old PID are different, the scheduler executes a context switch. It
saves the complete state of the CPU into a memory block and restores a different state from
a different memory block, excluding the program counter. To analyze its impact, it has to be
analyzed in detail. The context switch is written in assembler. The area where the CPU state is
stored looks like this.
Offset
Content
0
4
1
1
8
d2
12
d3
16
d4
20
d5
24
d6
28
d7
d0
Offset
Content
32
a0 1
36
a1 1
40
a2
44
a3
48
a4
52
a5
56
a6
60
ssp
66
sr 2
68
pc
d1
Offset
Content
64
0x0000 2
The actual context switch routine looks like this. Most of its work is done by the movem.l
instruction which dumps all CPU registers into memory.
Listing 3.13: The context switch
SYM (KERN_contextsw):
move.l
a0,
sp@// Save A0 onto old stack
move.l
sp@(8),a0
// Move address of old area into A0
movem.l
#0xffff,a0@
1
d0,d1,a0 and a1 are saved on the stack prior to the call to the scheduler function according to the calling
convention. See 3.2.1.
2
The status register is only 16 bit wide, so it is padded by zeroes