2007-03-21 23:58:33 +01:00
|
|
|
$Revision$
|
2007-03-26 14:18:08 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2005-10-06 19:56:22 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
2005-10-06 19:56:22 +02:00
|
|
|
align 32
|
|
|
|
irq0:
|
2007-04-18 08:37:14 +02:00
|
|
|
; pushfd
|
|
|
|
pushad
|
|
|
|
mov ax, app_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
|
2007-04-18 08:37:14 +02:00
|
|
|
.nocounter:
|
2007-03-01 21:32:19 +01:00
|
|
|
cmp [DONT_SWITCH], byte 1
|
2006-07-20 19:55:40 +02:00
|
|
|
jne .change_task
|
|
|
|
|
|
|
|
mov al,0x20 ; send End Of Interrupt signal
|
|
|
|
mov dx,0x20
|
|
|
|
out dx,al
|
|
|
|
|
2007-03-01 21:32:19 +01:00
|
|
|
mov [DONT_SWITCH], byte 0
|
2006-07-20 19:55:40 +02:00
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
popad
|
|
|
|
; popfd
|
|
|
|
iretd
|
2006-07-20 19:55:40 +02:00
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
.change_task:
|
2006-07-20 19:55:40 +02:00
|
|
|
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
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
.return:
|
|
|
|
popad
|
|
|
|
; popfd
|
|
|
|
iretd
|
2006-07-20 19:55:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
change_task:
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
|
|
|
|
|
|
|
call update_counters
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
if 0
|
|
|
|
|
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}
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
end if
|
|
|
|
|
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
|
|
|
@@:
|
2007-03-01 21:32:19 +01:00
|
|
|
mov [DONT_SWITCH],byte 1
|
2006-07-20 19:55:40 +02:00
|
|
|
call do_change_task
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
.return:
|
2006-07-20 19:55:40 +02:00
|
|
|
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
|
2007-04-18 08:37:14 +02:00
|
|
|
rdtsc
|
2005-10-06 19:56:22 +02:00
|
|
|
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
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
.waiting_for_termination:
|
|
|
|
.waiting_for_reuse:
|
|
|
|
.waiting_for_event:
|
|
|
|
.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
|
2007-04-18 08:37:14 +02:00
|
|
|
@@:
|
2005-11-07 16:50:30 +01:00
|
|
|
|
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
|
2007-04-18 08:37:14 +02:00
|
|
|
.noevents:
|
|
|
|
.found:
|
2007-02-28 09:52:06 +01:00
|
|
|
mov [CURRENT_TASK],ebx
|
|
|
|
mov [TASK_BASE],edi
|
2007-04-18 08:37:14 +02:00
|
|
|
rdtsc ;call _rdtsc
|
2006-08-06 12:29:45 +02:00
|
|
|
mov [edi+TASKDATA.counter_add],eax
|
2005-10-06 19:56:22 +02:00
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
mov esi, [prev_slot]
|
2006-07-20 19:55:40 +02:00
|
|
|
xor eax, eax
|
2007-04-18 08:37:14 +02:00
|
|
|
cmp ebx, esi
|
2006-07-20 19:55:40 +02:00
|
|
|
sete al
|
|
|
|
ret
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
; param
|
|
|
|
; ebx = incoming task
|
|
|
|
; esi = outcomig task
|
|
|
|
|
2006-07-20 19:55:40 +02:00
|
|
|
do_change_task:
|
2005-10-06 19:56:22 +02:00
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
shl ebx, 8
|
|
|
|
add ebx, SLOT_BASE
|
|
|
|
mov [current_slot], ebx
|
|
|
|
|
|
|
|
shl esi, 8
|
|
|
|
add esi, SLOT_BASE
|
|
|
|
|
|
|
|
mov [esi+APPDATA.saved_esp], esp
|
|
|
|
mov esp, [ebx+APPDATA.saved_esp]
|
|
|
|
|
|
|
|
; set thread io map
|
|
|
|
|
|
|
|
mov ecx, [ebx+APPDATA.io_map]
|
|
|
|
mov edx, [ebx+APPDATA.io_map+4]
|
|
|
|
mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], ecx
|
|
|
|
mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx
|
|
|
|
|
|
|
|
mov eax, [ebx+APPDATA.dir_table]
|
|
|
|
mov cr3, eax
|
|
|
|
mov ebx, [ebx+APPDATA.pl0_stack]
|
|
|
|
add ebx, RING0_STACK_SIZE
|
|
|
|
mov [tss._esp0], ebx
|
|
|
|
mov ecx, cr0
|
|
|
|
or ecx, CR0_TS ;set task switch flag
|
|
|
|
mov cr0, ecx
|
|
|
|
inc [context_counter] ;noname & halyavin
|
2005-10-06 19:56:22 +02:00
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
test [ebx+APPDATA.dbg_state], 1
|
|
|
|
jnz @F
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
mov eax, [ebx+APPDATA.dbg_regs.dr0]
|
|
|
|
mov dr0, eax
|
|
|
|
mov eax, [ebx+APPDATA.dbg_regs.dr1]
|
|
|
|
mov dr1, eax
|
|
|
|
mov eax, [ebx+APPDATA.dbg_regs.dr2]
|
|
|
|
mov dr2, eax
|
|
|
|
mov eax, [ebx+APPDATA.dbg_regs.dr3]
|
|
|
|
mov dr3, eax
|
|
|
|
xor eax, eax
|
|
|
|
mov dr6, eax
|
|
|
|
mov eax, [ebx+APPDATA.dbg_regs.dr7]
|
|
|
|
mov dr7, eax
|
|
|
|
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
|
2007-04-18 08:37:14 +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
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
if 0
|
|
|
|
|
|
|
|
|
|
|
|
struc TIMER
|
|
|
|
{
|
|
|
|
.next dd ?
|
|
|
|
.exp_time dd ?
|
|
|
|
.func dd ?
|
|
|
|
.arg dd ?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MAX_PROIRITY 0 ; highest, used for kernel tasks
|
|
|
|
MAX_USER_PRIORITY 0 ; highest priority for user processes
|
|
|
|
USER_PRIORITY 7 ; default (should correspond to nice 0)
|
|
|
|
MIN_USER_PRIORITY 14 ; minimum priority for user processes
|
|
|
|
IDLE_PRIORITY 15 ; lowest, only IDLE process goes here
|
|
|
|
NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1
|
|
|
|
|
|
|
|
rdy_head rd 16
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
pick_task:
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
.pick:
|
|
|
|
mov ebx, [rdy_head+eax*4]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .next
|
|
|
|
|
|
|
|
mov [next_task], ebx
|
|
|
|
test [ebx+flags.billable]
|
|
|
|
jz @F
|
|
|
|
mov [bill_task], ebx
|
|
|
|
@@:
|
|
|
|
ret
|
|
|
|
.next:
|
|
|
|
inc eax
|
|
|
|
jmp .pick
|
|
|
|
|
|
|
|
|
|
|
|
; param
|
|
|
|
; eax= task
|
|
|
|
;
|
|
|
|
; retval
|
|
|
|
; eax= task
|
|
|
|
; ebx= queue
|
|
|
|
; ecx= front if 1 or back if 0
|
|
|
|
|
|
|
|
align 4
|
|
|
|
shed:
|
|
|
|
cmp [eax+.tics_left], 0 ;signed compare
|
|
|
|
mov ebx, [eax+.priority]
|
|
|
|
setg ecx
|
|
|
|
jg @F
|
|
|
|
|
|
|
|
mov edx, [eax+.tics_quantum]
|
|
|
|
mov [eax+.ticks_left], edx
|
|
|
|
cmp ebx, (IDLE_PRIORITY-1)
|
|
|
|
je @F
|
|
|
|
inc ebx
|
|
|
|
@@:
|
|
|
|
ret
|
|
|
|
|
|
|
|
; param
|
|
|
|
; eax= task
|
|
|
|
|
|
|
|
align 4
|
|
|
|
enqueue:
|
|
|
|
call shed ;eax
|
|
|
|
cmp [rdy_head+ebx*4],0
|
|
|
|
jnz @F
|
|
|
|
|
|
|
|
mov [rdy_head+ebx*4], eax
|
|
|
|
mov [rdy_tail+ebx*4], eax
|
|
|
|
mov [eax+.next_ready], 0
|
|
|
|
jmp .pick
|
|
|
|
@@:
|
|
|
|
test ecx, ecx
|
|
|
|
jz .back
|
|
|
|
|
|
|
|
mov ecx, [rdy_head+ebx*4]
|
|
|
|
mov [eax+.next_ready], ecx
|
|
|
|
mov [rdy_head+ebx*4], eax
|
|
|
|
jmp .pick
|
|
|
|
.back:
|
|
|
|
mov ecx, [rdy_tail+ebx*4]
|
|
|
|
mov [ecx+.next_ready], eax
|
|
|
|
mov [rdy_tail+ebx*4], eax
|
|
|
|
mov [eax+.next_ready], 0
|
|
|
|
.pick:
|
|
|
|
call pick_proc ;select next task
|
|
|
|
ret
|
|
|
|
|
|
|
|
end if
|
|
|
|
|