You are on page 1of 26

Chapter 14:

80x86 Port

1
Register Model and Addressing
15 0

AX AH AL

BX BH BL
General Purpose Registers
CX CH CL

DX DH DL

15 0
BP 15 0
Pointers
SP XXXX XXXX XXXX XXXX 0000 Segment Register
15 0
15 0
SI
DI
Index Registers + 0000 XXXX XXXX XXXX XXXX Offset (Register)

15 0
20 0
IP Instruction Pointer
XXXX XXXX XXXX XXXX XXXX Physical Address
SW OF DF IF TF SF ZF AF PF CF
Status Word
15 0
CS
SS
Segment Registers
DS
ES

2
OS_CPU.H

3
OS_CPU.H

4
OS_CPU_C.C
• OSTaskStkInit

• OSTaskStkInit_FPE_x86
– Borland floating point emulator

• Hook functions
– OSTaskCreateHook()
– OSTaskDelHook()
– OSTaskSwHook()
– OSTaskIdleHook()
– OSTaskStatHook()
– OSTimeTickHook()
– OSInitHookBegin()

5
OS_CPU_C.C
LOW MEMORY

Simulate PUSH DS DS = Current DS OSTCBHighRdy->OSTCBStkPtr


Simulate PUSH ES ES = 0x4444
DI = 0x3333
SI = 0x2222
BP = 0x1111
SP = 0x0000
Simulate PUSHA BX = 0xBBBB
DX = 0xDDDD
CX = 0xCCCC
AX = 0xAAAA
OFF task Stack Growth
Simulate Interrupt SEG task
PSW = 0x0202
OFF task SS:SP points here after executing:
SEG task POP DS
Simulate call to task OFF pdata POP ES
SEG pdata POPA
IRET

HIGH MEMORY 6
OS_CPU.C – OSStkInit()

7
OS_CPU.C – OSStkInit()

LOW MEMORY
Stack Pointer
( 4 )

( 3 )
Saved Processor Registers

( 2 )
Interrupt Return Address Stack Growth
Processor Status Word

( 1 )
@OSTaskDel
Task start address
'pdata'

0xFFFF
HIGH MEMORY

8
OS_CPU.C – OSStkInit()

LOW MEMORY
Stack Pointer
( 4 )

( 3 )
Saved Processor Registers

( 2 )
Interrupt Return Address Stack Growth
Processor Status Word

( 1 )
Task start address
'pdata'

@OSTaskDelSelf
HIGH MEMORY

void OSTaskDelSelf() {
OSTaskDel(OS_PRIO_SELF);
} 9
OS_CPU_A.ASM
• OSStartHighRdy

• OSCtxSw

• OSIntCtxSw

• OSTickISR

10
OSStartHighRdy()

11
LDS, LES, LFS, LGS, and LSS

AX

BX (6F2A) 89

… 30

6F

2A
DS:_OSTCBHighRdy

CS

DS(1000) …

ES(8930) …

10000

12
OSCtxSw()
• The system call which change certain tasks
state needs to activate the scheduler and
throw an software interrupt. (the macro
OS_TASK_SW)

• The software trap vectors to the OSCtxSw.

13
OSCtxSw()

14
OSCtxSw()

15
OS_TCB OS_TCB
OSTCBCur OSTCBHighRdy

( 5 ) ( 6 )

80x86 CPU
(Real-Mode)
SS
SP
OSTCBCur->OSTCBStkPtr OSTCBHighRdy->OSTCBStkPtr
AX
LOW MEMORY BX LOW MEMORY
CX
DX
DS
ES
SI
( 4 )
DI
( 7 )

PUSH DS DS BP DS POP DS
PUSH ES ES ES POP ES
( 3 )
DI ( 1 )
CS ( 7 ) DI ( 8 )

SI ( 2 )
IP ( 8 ) SI
BP ( 3 ) PSW ( 9 ) BP
SP SP
PUSHA BX
( 4 ) ( 1 0 )
BX POPA
( 2 ) ( 9 )
DX DX
CX CX
AX AX
OFF task OFF task
OS_TASK_SW() SEG task SEG task IRET
(INT 128) PSW PSW ( 1 0 )

( 1 )
Stack Growth Stack Growth
HIGH MEMORY HIGH MEMORY

16
OSIntCtxSw()
• OSIntCtxSw is called by OSIntExit to perform a
context switch from an ISR.
– All registers have been saved onto the interrupted
task’s stack
– Stack pointer is also saved into the beginning of
the ISR has already done that.

17
OSIntCtxSw()

18
OSTickISR() – the Setup Procedure

void main():
 Call OSInit
 PC_DOSSaveReturn
 PC_VecSet //install switch vector at vector 0x80
 Create at least one application
 Call OSStart

The first task:


 Install OSTickISR
 (Change the tick rate)
19
Before (DOS only) After (µC/OS-II installed)

Interrupt Vector Table Interrupt Vector Table


(IVT) (IVT)
0x00 0x00

0x01 0x01

0x02 0x02

0x03 0x03

0x04 0x04

0x05 0x05

0x06 0x06

0x07 0x07

0x08
DOS Tick Handler 0x08
OSTickISR()
(18.20648 Hz) (200 Hz):
Every 11 ticks, do 'INT 0x81'

0x7F 0x7F

0x80 0x80
Undefined OSCtxSw()
0x81 0x81
Undefined DOS Tick Handler

20
Pseudocode

21
OSTickISR()

22
OSTickISR()

23
Using OSTaskStkInit_FPE_x86()

24
25
ptos ptos

Size-384
size

pbos

pbos SS:0000
before after 26

You might also like