2005-10-06 21:56:22 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
align 32
|
|
|
|
irq0:
|
2006-01-25 16:19:21 +03:00
|
|
|
save_ring3_context
|
2005-10-16 17:30:23 +04:00
|
|
|
mov ax, os_data
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
2005-10-06 21:56:22 +04:00
|
|
|
|
|
|
|
inc dword [timer_ticks]
|
|
|
|
|
|
|
|
mov eax, [timer_ticks]
|
2005-11-10 20:59:41 +03:00
|
|
|
call playNote ; <<<--- Speaker driver
|
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
cmp eax,[next_usage_update]
|
|
|
|
jb .nocounter
|
|
|
|
add eax,100
|
|
|
|
mov [next_usage_update],eax
|
|
|
|
call updatecputimes
|
|
|
|
.nocounter:
|
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
cmp [0xffff], byte 1
|
|
|
|
jne .change_task
|
|
|
|
|
|
|
|
mov al,0x20 ; send End Of Interrupt signal
|
|
|
|
mov dx,0x20
|
|
|
|
out dx,al
|
|
|
|
|
|
|
|
mov [0xffff], byte 0
|
|
|
|
|
|
|
|
restore_ring3_context
|
|
|
|
iret
|
|
|
|
|
|
|
|
.change_task:
|
|
|
|
call update_counters
|
|
|
|
|
|
|
|
call find_next_task
|
|
|
|
mov ecx, eax
|
|
|
|
|
|
|
|
mov al,0x20 ; send End Of Interrupt signal
|
|
|
|
mov dx,0x20
|
|
|
|
out dx,al
|
|
|
|
|
|
|
|
test ecx, ecx ; if there is only one running process
|
|
|
|
jnz .return
|
|
|
|
|
|
|
|
call do_change_task
|
|
|
|
|
|
|
|
.return:
|
|
|
|
restore_ring3_context
|
|
|
|
iret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
change_task:
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
|
|
|
|
|
|
|
call update_counters
|
|
|
|
call find_next_task
|
|
|
|
test eax, eax ; the same task -> skip switch
|
|
|
|
jnz .return
|
|
|
|
|
|
|
|
mov [0xffff],byte 1
|
|
|
|
call do_change_task
|
|
|
|
|
|
|
|
.return:
|
|
|
|
popad
|
|
|
|
popfd
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
uglobal
|
|
|
|
align 4
|
|
|
|
far_jump:
|
|
|
|
.offs dd ?
|
|
|
|
.sel dw ?
|
|
|
|
context_counter dd ? ;noname & halyavin
|
|
|
|
next_usage_update dd ?
|
|
|
|
timer_ticks dd ?
|
|
|
|
prev_slot dd ?
|
|
|
|
event_sched dd ?
|
|
|
|
endg
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
|
|
|
|
update_counters:
|
|
|
|
mov edi, [0x3010]
|
2005-10-06 21:56:22 +04:00
|
|
|
mov ebx, [edi+0x18] ; time stamp counter add
|
|
|
|
call _rdtsc
|
|
|
|
sub eax, ebx
|
|
|
|
add eax, [edi+0x14] ; counter sum
|
|
|
|
mov [edi+0x14], eax
|
2006-07-20 21:55:40 +04:00
|
|
|
ret
|
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
; Find next task to execute
|
|
|
|
; result: ebx = number of the selected task
|
|
|
|
; [0xffff] = 1 if the task is the same
|
|
|
|
find_next_task:
|
2005-10-06 21:56:22 +04:00
|
|
|
mov ebx,[0x3000]
|
2005-11-07 18:50:30 +03:00
|
|
|
mov [prev_slot], ebx
|
2005-10-06 21:56:22 +04:00
|
|
|
|
|
|
|
.waiting_for_termination:
|
|
|
|
.waiting_for_reuse:
|
2005-11-07 18:50:30 +03:00
|
|
|
.waiting_for_event:
|
2006-01-25 16:19:21 +03:00
|
|
|
.suspended:
|
2005-11-07 18:50:30 +03:00
|
|
|
cmp ebx, [0x3004]
|
|
|
|
jb @f
|
|
|
|
mov edi, 0x3000
|
|
|
|
xor ebx, ebx
|
|
|
|
@@:
|
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
add edi,0x20
|
|
|
|
inc ebx
|
|
|
|
|
|
|
|
mov al, byte [edi+0xA]
|
2006-07-20 21:55:40 +04:00
|
|
|
test al, al
|
|
|
|
jz .found
|
2006-01-25 16:19:21 +03:00
|
|
|
cmp al, 1
|
|
|
|
jz .suspended
|
|
|
|
cmp al, 2
|
|
|
|
jz .suspended
|
2005-10-06 21:56:22 +04:00
|
|
|
cmp al, 3
|
|
|
|
je .waiting_for_termination
|
|
|
|
cmp al, 4
|
|
|
|
je .waiting_for_termination
|
|
|
|
cmp al, 9
|
|
|
|
je .waiting_for_reuse
|
|
|
|
|
|
|
|
mov [0x3000],ebx
|
|
|
|
mov [0x3010],edi
|
|
|
|
|
2005-11-07 18:50:30 +03:00
|
|
|
cmp al, 5
|
|
|
|
jne .noevents
|
|
|
|
call get_event_for_app
|
|
|
|
test eax, eax
|
|
|
|
jz .waiting_for_event
|
|
|
|
mov [event_sched], eax
|
|
|
|
mov [edi+0xA], byte 0
|
2005-11-25 10:33:08 +03:00
|
|
|
.noevents:
|
2006-07-20 21:55:40 +04:00
|
|
|
.found:
|
|
|
|
mov [0x3000],ebx
|
|
|
|
mov [0x3010],edi
|
2005-10-06 21:56:22 +04:00
|
|
|
call _rdtsc
|
|
|
|
mov [edi+0x18],eax
|
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
xor eax, eax
|
|
|
|
cmp ebx, [prev_slot]
|
|
|
|
sete al
|
|
|
|
ret
|
|
|
|
|
|
|
|
; in: ebx = TSS selector index
|
|
|
|
do_change_task:
|
2005-10-06 21:56:22 +04:00
|
|
|
shl ebx, 3
|
|
|
|
xor eax, eax
|
|
|
|
add ebx, tss0
|
2006-07-20 21:55:40 +04:00
|
|
|
mov [far_jump.sel], bx ; selector
|
|
|
|
mov [far_jump.offs], eax ; offset
|
2005-10-27 16:40:46 +04:00
|
|
|
jmp pword [far_jump]
|
2005-10-17 19:53:11 +04:00
|
|
|
inc [context_counter] ;noname & halyavin
|
2006-07-20 21:55:40 +04:00
|
|
|
ret
|
2005-10-06 21:56:22 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
updatecputimes:
|
|
|
|
|
|
|
|
mov eax,[idleuse]
|
|
|
|
mov [idleusesec],eax
|
|
|
|
mov [idleuse],dword 0
|
|
|
|
mov ecx, [0x3004]
|
|
|
|
mov edi, 0x3020
|
|
|
|
.newupdate:
|
|
|
|
mov ebx,[edi+0x14]
|
|
|
|
mov [edi+0x1c],ebx
|
|
|
|
mov [edi+0x14],dword 0
|
|
|
|
add edi,0x20
|
|
|
|
dec ecx
|
|
|
|
jnz .newupdate
|
|
|
|
|
|
|
|
ret
|