mutlitasking in real mode
Posted: Mon Jul 22, 2002 6:54 am
I've a very big problem about multitasking in real mode, that makes me crazy!!
I would realize a little program to simulate a simple round robin scheduler using system clock interrupt.
The idea is to rewrite the interrupt service routine about 1Ch (system clock).
This procedure will simply invoke a dispatcher every temporal quantum...
...this is my procedure:
Interrupt_1Ch_handler: ; system clock ISR
; Call dispatcher every temporal quantum
inc byte [TICK]
cmp byte [TICK], 10 ; temporal quantum = 10 tick
jz dispatcher
iret
Dispatcher should save system registers, call a scheduler and restore the registers:
dispatcher:
mov byte [TICK], 0
; Save general purpose regs
mov word [ax_reg], ax
mov word [bx_reg], bx
mov word [cx_reg], cx
mov word [dx_reg], dx
mov word [si_reg], si
mov word [di_reg], di
; Save old flag register & PC
pop word [ip_reg]
pop word [cs_reg]
pop word [flag_reg]
call _sched ; Call scheduler
; Restore new general purpose regs
mov word ax, [ax_reg]
mov word bx, [bx_reg]
mov word cx, [cx_reg]
mov word dx, [dx_reg]
mov word si, [si_reg]
mov word di, [di_reg]
; Restore new flag register & PC
push word [flag_reg]
push word [cs_reg]
push word [ip_reg]
; Jump to the next instruction of the new task
iret
For now scheduler is very very simple... just a round robin policy and doesn't save general purpose regs content:
_sched:
; only switch between task1 start and task2 start
cmp byte [TURN], 0
jz go_t1
cmp byte [TURN], 1
jz go_t2
go_t1:
mov byte [TURN], 1
mov [cs_reg], cs
mov word [ip_reg], task1
ret
go_t2:
mov byte [TURN], 0
mov [cs_reg], cs
mov word [ip_reg], task2
ret
TURN db 0
At last these are the 2 task that I would like to execute:
task1:
mov ah, 0Eh
mov al, 65 ; Print 'A' char
int 10h
jmp task1
task2:
mov ah, 0Eh
mov al, 66 ; Print 'B' char
int 10h
jmp task2
Ok, sorry for this long introduction.. but it has been necessary to explain me better.. since my English is not so perfect
So.. scheduler works, but when task1 is executed, system clock ISR is never invoked!!! ?task1 fill the screen with A and B is never written, it seems that it makes a cli?
I don't know where is the problem, since if I write a simple procedure in the scheduler like "print a character on the screen" it works?
Thanks to all that want to help me?
I would realize a little program to simulate a simple round robin scheduler using system clock interrupt.
The idea is to rewrite the interrupt service routine about 1Ch (system clock).
This procedure will simply invoke a dispatcher every temporal quantum...
...this is my procedure:
Interrupt_1Ch_handler: ; system clock ISR
; Call dispatcher every temporal quantum
inc byte [TICK]
cmp byte [TICK], 10 ; temporal quantum = 10 tick
jz dispatcher
iret
Dispatcher should save system registers, call a scheduler and restore the registers:
dispatcher:
mov byte [TICK], 0
; Save general purpose regs
mov word [ax_reg], ax
mov word [bx_reg], bx
mov word [cx_reg], cx
mov word [dx_reg], dx
mov word [si_reg], si
mov word [di_reg], di
; Save old flag register & PC
pop word [ip_reg]
pop word [cs_reg]
pop word [flag_reg]
call _sched ; Call scheduler
; Restore new general purpose regs
mov word ax, [ax_reg]
mov word bx, [bx_reg]
mov word cx, [cx_reg]
mov word dx, [dx_reg]
mov word si, [si_reg]
mov word di, [di_reg]
; Restore new flag register & PC
push word [flag_reg]
push word [cs_reg]
push word [ip_reg]
; Jump to the next instruction of the new task
iret
For now scheduler is very very simple... just a round robin policy and doesn't save general purpose regs content:
_sched:
; only switch between task1 start and task2 start
cmp byte [TURN], 0
jz go_t1
cmp byte [TURN], 1
jz go_t2
go_t1:
mov byte [TURN], 1
mov [cs_reg], cs
mov word [ip_reg], task1
ret
go_t2:
mov byte [TURN], 0
mov [cs_reg], cs
mov word [ip_reg], task2
ret
TURN db 0
At last these are the 2 task that I would like to execute:
task1:
mov ah, 0Eh
mov al, 65 ; Print 'A' char
int 10h
jmp task1
task2:
mov ah, 0Eh
mov al, 66 ; Print 'B' char
int 10h
jmp task2
Ok, sorry for this long introduction.. but it has been necessary to explain me better.. since my English is not so perfect
So.. scheduler works, but when task1 is executed, system clock ISR is never invoked!!! ?task1 fill the screen with A and B is never written, it seems that it makes a cli?
I don't know where is the problem, since if I write a simple procedure in the scheduler like "print a character on the screen" it works?
Thanks to all that want to help me?