2005-10-06 19:56:22 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2006-07-20 19:55:40 +02:00
|
|
|
|
2005-10-06 19:56:22 +02:00
|
|
|
align 32
|
|
|
|
irq0:
|
2006-01-25 14:19:21 +01:00
|
|
|
save_ring3_context
|
2005-10-16 15:30:23 +02:00
|
|
|
mov ax, os_data
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
inc dword [timer_ticks]
|
|
|
|
|
|
|
|
mov eax, [timer_ticks]
|
2005-11-10 18:59:41 +01:00
|
|
|
call playNote ; <<<--- Speaker driver
|
|
|
|
|
2005-10-06 19:56:22 +02:00
|
|
|
cmp eax,[next_usage_update]
|
|
|
|
jb .nocounter
|
|
|
|
add eax,100
|
|
|
|
mov [next_usage_update],eax
|
|
|
|
call updatecputimes
|
|
|
|
.nocounter:
|
|
|
|
|
2006-07-20 19:55:40 +02: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
|
2007-02-28 09:52:06 +01:00
|
|
|
|
2006-07-20 19:55:40 +02:00
|
|
|
.return:
|
|
|
|
restore_ring3_context
|
|
|
|
iret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
change_task:
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
|
|
|
|
|
|
|
call update_counters
|
2006-10-20 10:35:15 +02:00
|
|
|
; \begin{Mario79}
|
|
|
|
cmp [dma_task_switched], 1
|
|
|
|
jne .find_next_task
|
|
|
|
mov [dma_task_switched], 0
|
|
|
|
mov ebx, [dma_process]
|
2007-02-28 09:52:06 +01:00
|
|
|
cmp [CURRENT_TASK], ebx
|
2006-10-20 10:35:15 +02:00
|
|
|
je .return
|
|
|
|
mov edi, [dma_slot_ptr]
|
2007-02-28 09:52:06 +01:00
|
|
|
mov [CURRENT_TASK], ebx
|
|
|
|
mov [TASK_BASE], edi
|
2006-10-20 10:35:15 +02:00
|
|
|
jmp @f
|
|
|
|
.find_next_task:
|
|
|
|
; \end{Mario79}
|
2006-07-20 19:55:40 +02:00
|
|
|
call find_next_task
|
|
|
|
test eax, eax ; the same task -> skip switch
|
|
|
|
jnz .return
|
2006-10-20 10:35:15 +02:00
|
|
|
@@:
|
2006-07-20 19:55:40 +02:00
|
|
|
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 19:56:22 +02:00
|
|
|
|
2006-07-20 19:55:40 +02:00
|
|
|
|
|
|
|
update_counters:
|
2007-02-28 09:52:06 +01:00
|
|
|
mov edi, [TASK_BASE]
|
2006-08-06 12:29:45 +02:00
|
|
|
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
|
2005-10-06 19:56:22 +02:00
|
|
|
call _rdtsc
|
|
|
|
sub eax, ebx
|
2006-08-06 12:29:45 +02:00
|
|
|
add eax, [edi+TASKDATA.counter_sum] ; counter sum
|
|
|
|
mov [edi+TASKDATA.counter_sum], eax
|
2006-07-20 19:55:40 +02:00
|
|
|
ret
|
|
|
|
|
2005-10-06 19:56:22 +02:00
|
|
|
|
2006-07-20 19:55:40 +02:00
|
|
|
; Find next task to execute
|
|
|
|
; result: ebx = number of the selected task
|
2006-07-23 16:47:32 +02:00
|
|
|
; eax = 1 if the task is the same
|
|
|
|
; edi = address of the data for the task in ebx
|
|
|
|
; [0x3000] = ebx and [0x3010] = edi
|
|
|
|
; corrupts other regs
|
2006-07-20 19:55:40 +02:00
|
|
|
find_next_task:
|
2007-02-28 09:52:06 +01:00
|
|
|
mov ebx, [CURRENT_TASK]
|
|
|
|
mov edi, [TASK_BASE]
|
2005-11-07 16:50:30 +01:00
|
|
|
mov [prev_slot], ebx
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
.waiting_for_termination:
|
|
|
|
.waiting_for_reuse:
|
2005-11-07 16:50:30 +01:00
|
|
|
.waiting_for_event:
|
2006-01-25 14:19:21 +01:00
|
|
|
.suspended:
|
2007-02-28 09:52:06 +01:00
|
|
|
cmp ebx, [TASK_COUNT]
|
2005-11-07 16:50:30 +01:00
|
|
|
jb @f
|
2007-02-28 09:52:06 +01:00
|
|
|
mov edi, CURRENT_TASK
|
2005-11-07 16:50:30 +01:00
|
|
|
xor ebx, ebx
|
|
|
|
@@:
|
|
|
|
|
2005-10-06 19:56:22 +02:00
|
|
|
add edi,0x20
|
|
|
|
inc ebx
|
|
|
|
|
2006-08-06 12:29:45 +02:00
|
|
|
mov al, byte [edi+TASKDATA.state]
|
2006-07-20 19:55:40 +02:00
|
|
|
test al, al
|
|
|
|
jz .found
|
2006-01-25 14:19:21 +01:00
|
|
|
cmp al, 1
|
|
|
|
jz .suspended
|
|
|
|
cmp al, 2
|
|
|
|
jz .suspended
|
2005-10-06 19:56:22 +02:00
|
|
|
cmp al, 3
|
|
|
|
je .waiting_for_termination
|
|
|
|
cmp al, 4
|
|
|
|
je .waiting_for_termination
|
|
|
|
cmp al, 9
|
|
|
|
je .waiting_for_reuse
|
|
|
|
|
2007-02-28 09:52:06 +01:00
|
|
|
mov [CURRENT_TASK],ebx
|
|
|
|
mov [TASK_BASE],edi
|
2005-10-06 19:56:22 +02:00
|
|
|
|
2005-11-07 16:50:30 +01:00
|
|
|
cmp al, 5
|
|
|
|
jne .noevents
|
|
|
|
call get_event_for_app
|
|
|
|
test eax, eax
|
|
|
|
jz .waiting_for_event
|
|
|
|
mov [event_sched], eax
|
2006-08-06 12:29:45 +02:00
|
|
|
mov [edi+TASKDATA.state], byte 0
|
2005-11-25 08:33:08 +01:00
|
|
|
.noevents:
|
2006-07-20 19:55:40 +02:00
|
|
|
.found:
|
2007-02-28 09:52:06 +01:00
|
|
|
mov [CURRENT_TASK],ebx
|
|
|
|
mov [TASK_BASE],edi
|
2005-10-06 19:56:22 +02:00
|
|
|
call _rdtsc
|
2006-08-06 12:29:45 +02:00
|
|
|
mov [edi+TASKDATA.counter_add],eax
|
2005-10-06 19:56:22 +02:00
|
|
|
|
2006-07-20 19:55:40 +02:00
|
|
|
xor eax, eax
|
|
|
|
cmp ebx, [prev_slot]
|
|
|
|
sete al
|
|
|
|
ret
|
|
|
|
|
|
|
|
; in: ebx = TSS selector index
|
|
|
|
do_change_task:
|
2005-10-06 19:56:22 +02:00
|
|
|
shl ebx, 3
|
|
|
|
xor eax, eax
|
|
|
|
add ebx, tss0
|
2006-07-20 19:55:40 +02:00
|
|
|
mov [far_jump.sel], bx ; selector
|
|
|
|
mov [far_jump.offs], eax ; offset
|
2005-10-27 14:40:46 +02:00
|
|
|
jmp pword [far_jump]
|
2005-10-17 17:53:11 +02:00
|
|
|
inc [context_counter] ;noname & halyavin
|
2006-07-20 19:55:40 +02:00
|
|
|
ret
|
2005-10-06 19:56:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
updatecputimes:
|
|
|
|
|
|
|
|
mov eax,[idleuse]
|
|
|
|
mov [idleusesec],eax
|
|
|
|
mov [idleuse],dword 0
|
2007-02-28 09:52:06 +01:00
|
|
|
mov ecx, [TASK_COUNT]
|
|
|
|
mov edi, TASK_DATA
|
2005-10-06 19:56:22 +02:00
|
|
|
.newupdate:
|
2006-08-06 12:29:45 +02:00
|
|
|
mov ebx,[edi+TASKDATA.counter_sum]
|
|
|
|
mov [edi+TASKDATA.cpu_usage],ebx
|
|
|
|
mov [edi+TASKDATA.counter_sum],dword 0
|
2005-10-06 19:56:22 +02:00
|
|
|
add edi,0x20
|
|
|
|
dec ecx
|
|
|
|
jnz .newupdate
|
|
|
|
|
|
|
|
ret
|