CS 452/652 Winter 2022 - Lecture 7
January 21, 2022
prev
next
Kernel Start
SVC mode, working stack, caches disabled, IRQs disabled
set up (K1): SWI handler
set up (K2): caches
set up (later): timers, UART, IRQ handler, IRQs, track
create dedicated first user task (init task)
add to ready queue
start kernel loop
Task Management
task creation: need to set up user stack to enable
leave_kernel()
functionality
handle end of user routine? use dedicate start routine
void task_start(void (*task_function)()) { task_function(); Exit(); }
task termination:
Exit()
system call → kernel retires task
Scheduling
preemption: each kernel entry triggers re-scheduling
but: no time-sliced preemption!
after kernel entry and corresponding processing
task might be blocked → track
task might be ready → back on ready queue
but not both! single intrusive linkage element sufficient
ready queue - keep simple: array of plain FIFO queues
no support for timeout/cancellation of blocking operations
no need to remove internal element from queue
only push to back of queue, pop from front
Memory Management
C/C++ provide very good control over memory layout of structured data
use pointer casting to switch between unstructured and structured view
alternative:
union
declaration
ARM 920T: all relevant unstructured data is 32-bit wide, so no padding or alignment problems
otherwise,
GCC extensions
could be used to increase control over memory layout
techniques for dynamic data structures without heap
intrusive
linkage, i.e., embed
next
(and/or other) pointers in data strucure
slab allocation: dedicated memory region for each relevant data type
stored freed objects in
free list
, use intrusive overlay (cast/union, see above) to manage
allocate first from free list, then from slab
use stack or static (file-)local memory for private / slab
when using static memory: do not share between tasks!
Mixing C and Assembler
Coding
See various examples file in
demo07
. Take a look at the compiled
.s
source
main.c
,
adder.c
- basic argument passing in
r0
,
r1
adder6.c
- beyond 4 arguments passed on stack
main.c
,
asm_adder.S
- manual assembler routine working with C caller
main3.c
,
data_adder.c
- memory-based data exchange between C and assembler
asm.c
- embed assembler in C code; exchange data with local variables
special register access:
msr
/
mrs
for
cpsr
,
spsr
special register access:
mcr
/
mrc
for co-process registers
cp15
Recommendations
use embedded assembler via
asm
only for short code sequences that do not access
sp
use assembler routine linked as C routine for context-switch code