2007-03-26 16:18:08 +04: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 ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2007-07-27 17:52:03 +04:00
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
align 32
|
|
|
|
irq0:
|
2007-04-18 10:37:14 +04:00
|
|
|
; pushfd
|
|
|
|
pushad
|
|
|
|
mov ax, app_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
|
2007-04-18 10:37:14 +04:00
|
|
|
.nocounter:
|
2007-03-01 23:32:19 +03:00
|
|
|
cmp [DONT_SWITCH], byte 1
|
2006-07-20 21:55:40 +04:00
|
|
|
jne .change_task
|
|
|
|
|
|
|
|
mov al,0x20 ; send End Of Interrupt signal
|
|
|
|
mov dx,0x20
|
|
|
|
out dx,al
|
|
|
|
|
2007-03-01 23:32:19 +03:00
|
|
|
mov [DONT_SWITCH], byte 0
|
2006-07-20 21:55:40 +04:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
popad
|
|
|
|
; popfd
|
|
|
|
iretd
|
2006-07-20 21:55:40 +04:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
.change_task:
|
2006-07-20 21:55:40 +04: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 11:52:06 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
.return:
|
|
|
|
popad
|
|
|
|
; popfd
|
|
|
|
iretd
|
2006-07-20 21:55:40 +04:00
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
change_task:
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
|
|
|
|
|
|
|
call update_counters
|
2007-04-18 10:37:14 +04:00
|
|
|
|
|
|
|
if 0
|
|
|
|
|
2006-10-20 12:35:15 +04:00
|
|
|
; \begin{Mario79}
|
|
|
|
cmp [dma_task_switched], 1
|
|
|
|
jne .find_next_task
|
|
|
|
mov [dma_task_switched], 0
|
|
|
|
mov ebx, [dma_process]
|
2007-02-28 11:52:06 +03:00
|
|
|
cmp [CURRENT_TASK], ebx
|
2006-10-20 12:35:15 +04:00
|
|
|
je .return
|
|
|
|
mov edi, [dma_slot_ptr]
|
2007-02-28 11:52:06 +03:00
|
|
|
mov [CURRENT_TASK], ebx
|
|
|
|
mov [TASK_BASE], edi
|
2006-10-20 12:35:15 +04:00
|
|
|
jmp @f
|
|
|
|
.find_next_task:
|
|
|
|
; \end{Mario79}
|
2007-04-18 10:37:14 +04:00
|
|
|
|
|
|
|
end if
|
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
call find_next_task
|
|
|
|
test eax, eax ; the same task -> skip switch
|
|
|
|
jnz .return
|
2006-10-20 12:35:15 +04:00
|
|
|
@@:
|
2007-03-01 23:32:19 +03:00
|
|
|
mov [DONT_SWITCH],byte 1
|
2006-07-20 21:55:40 +04:00
|
|
|
call do_change_task
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
.return:
|
2006-07-20 21:55:40 +04: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 21:56:22 +04:00
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
|
|
|
|
update_counters:
|
2007-02-28 11:52:06 +03:00
|
|
|
mov edi, [TASK_BASE]
|
2006-08-06 14:29:45 +04:00
|
|
|
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
|
2007-04-18 10:37:14 +04:00
|
|
|
rdtsc
|
2005-10-06 21:56:22 +04:00
|
|
|
sub eax, ebx
|
2006-08-06 14:29:45 +04:00
|
|
|
add eax, [edi+TASKDATA.counter_sum] ; counter sum
|
|
|
|
mov [edi+TASKDATA.counter_sum], 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
|
2006-07-23 18:47:32 +04: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 21:55:40 +04:00
|
|
|
find_next_task:
|
2007-02-28 11:52:06 +03:00
|
|
|
mov ebx, [CURRENT_TASK]
|
|
|
|
mov edi, [TASK_BASE]
|
2005-11-07 18:50:30 +03:00
|
|
|
mov [prev_slot], ebx
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
.waiting_for_termination:
|
|
|
|
.waiting_for_reuse:
|
|
|
|
.waiting_for_event:
|
|
|
|
.suspended:
|
2007-02-28 11:52:06 +03:00
|
|
|
cmp ebx, [TASK_COUNT]
|
2005-11-07 18:50:30 +03:00
|
|
|
jb @f
|
2007-02-28 11:52:06 +03:00
|
|
|
mov edi, CURRENT_TASK
|
2005-11-07 18:50:30 +03:00
|
|
|
xor ebx, ebx
|
2007-04-18 10:37:14 +04:00
|
|
|
@@:
|
2005-11-07 18:50:30 +03:00
|
|
|
|
2005-10-06 21:56:22 +04:00
|
|
|
add edi,0x20
|
|
|
|
inc ebx
|
|
|
|
|
2006-08-06 14:29:45 +04:00
|
|
|
mov al, byte [edi+TASKDATA.state]
|
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
|
|
|
|
|
2007-02-28 11:52:06 +03:00
|
|
|
mov [CURRENT_TASK],ebx
|
|
|
|
mov [TASK_BASE],edi
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2005-11-07 18:50:30 +03:00
|
|
|
cmp al, 5
|
|
|
|
jne .noevents
|
|
|
|
call get_event_for_app
|
|
|
|
test eax, eax
|
2007-06-04 12:58:32 +04:00
|
|
|
jnz @f
|
|
|
|
mov eax, ebx
|
|
|
|
shl eax, 8
|
|
|
|
mov eax, [SLOT_BASE + APPDATA.wait_timeout + eax]
|
|
|
|
cmp eax, [timer_ticks]
|
|
|
|
jae .waiting_for_event
|
|
|
|
xor eax, eax
|
|
|
|
@@:
|
2005-11-07 18:50:30 +03:00
|
|
|
mov [event_sched], eax
|
2006-08-06 14:29:45 +04:00
|
|
|
mov [edi+TASKDATA.state], byte 0
|
2007-04-18 10:37:14 +04:00
|
|
|
.noevents:
|
|
|
|
.found:
|
2007-02-28 11:52:06 +03:00
|
|
|
mov [CURRENT_TASK],ebx
|
|
|
|
mov [TASK_BASE],edi
|
2007-04-18 10:37:14 +04:00
|
|
|
rdtsc ;call _rdtsc
|
2006-08-06 14:29:45 +04:00
|
|
|
mov [edi+TASKDATA.counter_add],eax
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov esi, [prev_slot]
|
2006-07-20 21:55:40 +04:00
|
|
|
xor eax, eax
|
2007-04-18 10:37:14 +04:00
|
|
|
cmp ebx, esi
|
2006-07-20 21:55:40 +04:00
|
|
|
sete al
|
|
|
|
ret
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
; param
|
|
|
|
; ebx = incoming task
|
|
|
|
; esi = outcomig task
|
|
|
|
|
2006-07-20 21:55:40 +04:00
|
|
|
do_change_task:
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2007-04-18 10:37:14 +04: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]
|
2007-06-27 03:33:43 +04:00
|
|
|
cmp eax, [esi+APPDATA.dir_table]
|
|
|
|
je @F
|
2007-04-18 10:37:14 +04:00
|
|
|
mov cr3, eax
|
2007-06-27 03:33:43 +04:00
|
|
|
@@:
|
2008-02-04 18:31:59 +03:00
|
|
|
mov eax, [ebx+APPDATA.saved_esp0]
|
|
|
|
mov [tss._esp0], eax
|
|
|
|
; mov eax, [ebx+APPDATA.pl0_stack]
|
|
|
|
; add eax, RING0_STACK_SIZE
|
|
|
|
; mov [tss._esp0], eax
|
2007-06-27 03:33:43 +04:00
|
|
|
mov ax, graph_data
|
|
|
|
mov gs, ax
|
2007-04-18 10:37:14 +04:00
|
|
|
mov ecx, cr0
|
|
|
|
or ecx, CR0_TS ;set task switch flag
|
|
|
|
mov cr0, ecx
|
|
|
|
inc [context_counter] ;noname & halyavin
|
2005-10-06 21:56:22 +04:00
|
|
|
|
2007-04-18 10:37:14 +04: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 21:56:22 +04:00
|
|
|
|
|
|
|
align 4
|
|
|
|
updatecputimes:
|
|
|
|
|
|
|
|
mov eax,[idleuse]
|
|
|
|
mov [idleusesec],eax
|
|
|
|
mov [idleuse],dword 0
|
2007-02-28 11:52:06 +03:00
|
|
|
mov ecx, [TASK_COUNT]
|
|
|
|
mov edi, TASK_DATA
|
2007-04-18 10:37:14 +04:00
|
|
|
.newupdate:
|
2006-08-06 14:29:45 +04:00
|
|
|
mov ebx,[edi+TASKDATA.counter_sum]
|
|
|
|
mov [edi+TASKDATA.cpu_usage],ebx
|
|
|
|
mov [edi+TASKDATA.counter_sum],dword 0
|
2005-10-06 21:56:22 +04:00
|
|
|
add edi,0x20
|
|
|
|
dec ecx
|
|
|
|
jnz .newupdate
|
|
|
|
|
|
|
|
ret
|
2007-04-18 10:37:14 +04: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
|
|
|
|
|