What is a task?
As stated this is just a deterministic finite state machine,
3. But there is also the environment
- affects, and
- is affected by.
Two tasks can use the same set of instructions, but
The kernel keeps track of every task's state
The TD normally contains
all ready to be reloaded whenever the task next runs.
Possible states of the task
All the interesting stuff inside done by the kernel is hidden inside
getNextRequest.
int getNextRequest( active ) {
nextRequest = activate( active ); //the active task doesn't change
return nextRequest;
}
What's inside activate( active )?
The hard part to get right is `transfer of control'
void func( ) {
printf( "func: running\n" );
}
void main( ) {
printf( "main: beginning\n" );
func( );
printf( "main: ending\n" );
}
What is an interrupt vector?
func( ) into the interrupt vectorfunc() using a software interruptswinbx or mov pc, lr instruction that
ends func( ) with mov pc, lr.main( ) so that it has contextmain( ) on the stack as the first
thing done inside func( )main( ) from the stack jas the last
thing done before the instruction that ends func( ).To go beyond this we need to think about tasks more concretely
What we did here was to replace a function call with a software interrupt. Why bother?
What is this?
| Architecture | Instruction
Set |
Thumb
Instructions? |
Multiply
Instruction |
DSP
Instructions |
Comments |
| ARMv1 | 1 | no | no | no | Obsolete |
| ARMv2 | 2 | no | no | no | Obsolete |
| ARMv3 | 3 | no | no | no | |
| ARMv3M | 3 | no | yes | no | |
| ARMv4 | 4 | no | yes | no | |
| ARMv4T | 4 | yes | yes | no | This is the one you use |
| ARMv5 | 5 | no | yes | no | Has CLZ |
| ARMv5T | 5 | yes | yes | no | |
| ARMv5TE | 5 | yes | yes | yes |
Thumb instructions are 16 bit, and accelerated.
| Processor
Core |
ARM
ISA |
Thumb
ISA |
Comments |
| ARM7TDMI | v4T | v1 | Most of the ARM7xx processors |
| ARM9TDMI | v4T | v1 | ARM[920|922|940]T: 920T is the one we have. |
| StrongARM | v4 | n/a | Intel SA-110. Found in the IPAQ. |
| ARM9E | v5TE | v2 | |
| ARM10E | v5TE | v2 | |
| XScale | v5TE | v2 | Manufactured by Intel. HP versions of IPAQ. |
partially separate register sets different modes
link register (lr), program counter (pc) are
special, but not very special
| Exception
Type |
Processor
Mode |
Instruction
Address |
| Reset | supervisor | 0x00 |
| Undefined instruction | undefined | 0x04 |
| Software interrupt | supervisor | 0x08 |
| Prefetch abort | abort | 0x0c |
| Data abort | abort | 0x10 |
| Ordinary interrupt | IRQ | 0x18 |
| Fast interrupt | FIQ | 0x1c |
ldr pc, [pc, #0x18]; 0xe590f018
into addresses 0x00 to 0x1c.
0x20
to 0x3c.| 31 | 30 | 29 | 28 | 27 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
| N | Z | C | V | Q | Does Not Matter (DNM) | I | F | T | M4 | M3 | M2 | M1 | M0 |
| n/a
in v4 |
General Comments
Step-by-step
; In calling code
bl <entry point> ; this treats the pc and lr specially
; In called code
entry point:
mov ip, sp
stmdb sp!, {fp, ip, lr} ; and usually others,
; determined by the registers the function uses
...
ldmia sp, {fp, sp, pc} ; and whatever others
Note the role of the link register and stack pointer.
; In calling code swi n ; In kernel kernel entry: ; Change to system mode ; Save user state on user stack ; Return to supervisor mode ldr r4, [lr, #-4] ; gets the request type ; Retrieve kernel state from kernel stack ; Do kernel work
Questions:
Hint. How does gcc pass arguments into a function?
Suggestions:
Return to: