Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 3534 → Rev 3533

/kernel/trunk/blkdev/cd_drv.inc
710,20 → 710,6
;* ChannelNumber - íîìåð êàíàëà; *
;* DiskNumber - íîìåð äèñêà íà êàíàëå. *
;*************************************************
proc check_ATAPI_device_event_has_work?
mov eax, [timer_ticks]
sub eax, [timer_ATAPI_check]
cmp eax, 100
jb .no
.yes:
xor eax, eax
inc eax
ret
.no:
xor eax, eax
ret
endp
 
align 4
check_ATAPI_device_event:
pusha
/kernel/trunk/blkdev/flp_drv.inc
284,24 → 284,6
;*****************************************
;* ÏÐÎÂÅÐÊÀ ÇÀÄÅÐÆÊÈ ÂÛÊËÞ×ÅÍÈß ÌÎÒÎÐÀ *
;*****************************************
proc check_fdd_motor_status_has_work?
cmp [flp_status], 0
jnz .yes
cmp [fdd_motor_status], 0
jz .no
mov eax, [timer_ticks]
sub eax, [timer_fdd_motor]
cmp eax, 500
jb .no
.yes:
xor eax, eax
inc eax
ret
.no:
xor eax, eax
ret
endp
 
align 4
check_fdd_motor_status:
cmp [fdd_motor_status], 0
/kernel/trunk/core/taskman.inc
90,7 → 90,7
stdcall set_cursor, [def_cursor_clock]
mov [handle], eax
mov [redrawmouse_unconditional], 1
call wakeup_osloop
call __sys_draw_pointer
popad
@@:
mov [flags], edx
152,8 → 152,20
test eax, eax
jz .err_hdr
 
call lock_application_table
.wait_lock:
cmp [application_table_status], 0
je .get_lock
call change_task
jmp .wait_lock
 
.get_lock:
mov eax, 1
xchg eax, [application_table_status]
test eax, eax
jnz .wait_lock
 
call set_application_table_status
 
call get_new_process_place
test eax, eax
mov esi, -0x20 ; too many processes
234,8 → 246,9
mov eax, [save_cr3]
call set_cr3
 
xor ebx, ebx
mov [application_table_status], ebx;unlock application_table_status mutex
mov eax, [process_number];set result
call unlock_application_table
 
jmp .final
 
246,7 → 259,8
.err_hdr:
stdcall kernel_free, [file_base]
.err_file:
call unlock_application_table
xor eax, eax
mov [application_table_status], eax
mov eax, esi
.final:
cmp [SCR_MODE], word 0x13
254,7 → 268,7
pushad
stdcall set_cursor, [handle]
mov [redrawmouse_unconditional], 1
call wakeup_osloop
call __sys_draw_pointer
popad
@@:
ret
884,8 → 898,20
mov [app_path], eax
;mov esi,new_process_loading
;call sys_msg_board_str
call lock_application_table
.wait_lock:
cmp [application_table_status], 0
je .get_lock
call change_task
jmp .wait_lock
 
.get_lock:
mov eax, 1
xchg eax, [application_table_status]
test eax, eax
jnz .wait_lock
 
call set_application_table_status
 
call get_new_process_place
test eax, eax
jz .failed
941,13 → 967,14
 
;mov esi,new_process_running
;call sys_msg_board_str ;output information about succefull startup
xor eax, eax
mov [application_table_status], eax ;unlock application_table_status mutex
mov eax, [process_number] ;set result
call unlock_application_table
ret
.failed:
xor eax, eax
.failed1:
call unlock_application_table
mov [application_table_status], eax
dec eax ;-1
ret
endp
1121,7 → 1148,6
mov eax, [esi+0x08] ;app_eip
mov [ebx+REG_EIP], eax;app_entry
mov [ebx+REG_CS], dword app_code
mov ecx, USER_PRIORITY
mov eax, [CURRENT_TASK]
shl eax, 8 ; created by kernel?
cmp [SLOT_BASE+eax+APPDATA.dir_table], sys_pgdir - OS_BASE
1129,7 → 1155,6
cmp [app_path], 0 ; it is a thread?
jnz @f
mov [ebx+REG_CS], dword os_code ; kernel thread
mov ecx, MAX_PRIORITY
@@:
mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF
 
1137,22 → 1162,20
mov [ebx+REG_APP_ESP], eax;app_stack
mov [ebx+REG_SS], dword app_data
 
lea edx, [ebx+REG_RET]
lea ecx, [ebx+REG_RET]
mov ebx, [slot]
shl ebx, 5
mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx
mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], ecx
 
xor edx, edx; process state - running
xor ecx, ecx; process state - running
; set if debuggee
test byte [flags], 1
jz .no_debug
inc edx ; process state - suspended
inc ecx ; process state - suspended
mov eax, [CURRENT_TASK]
mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax
.no_debug:
mov [CURRENT_TASK+ebx+TASKDATA.state], dl
lea edx, [SLOT_BASE+ebx*8]
call scheduler_add_thread
mov [CURRENT_TASK+ebx+TASKDATA.state], cl
;mov esi,new_process_running
;call sys_msg_board_str ;output information about succefull startup
ret
/kernel/trunk/core/irq.inc
267,6 → 267,7
.fail:
inc [irq_failed+ebp*4]
.exit:
mov [check_idle_semaphore], 5
 
mov ecx, ebp
call irq_eoi
/kernel/trunk/core/sched.inc
89,6 → 89,9
ret
align 4
updatecputimes:
xor eax, eax
xchg eax, [idleuse]
mov [idleusesec], eax
mov ecx, [TASK_COUNT]
mov edi, TASK_DATA
.newupdate:
99,6 → 102,56
loop .newupdate
ret
 
align 4
find_next_task:
;info:
; Find next task to execute
;retval:
; ebx = address of the APPDATA for the selected task (slot-base)
; esi = previous slot-base ([current_slot] at the begin)
; edi = address of the TASKDATA for the selected task
; ZF = 1 if the task is the same
;warning:
; [CURRENT_TASK] = bh , [TASK_BASE] = edi -- as result
; [current_slot] is not set to new value (ebx)!!!
;scratched: eax,ecx
call update_counters ; edi := [TASK_BASE]
Mov esi, ebx, [current_slot]
.loop:
cmp bh, [TASK_COUNT]
jb @f
xor bh, bh
mov edi, CURRENT_TASK
@@:
inc bh ; ebx += APPDATA.size
add edi, 0x20; edi += TASKDATA.size
mov al, [edi+TASKDATA.state]
test al, al
jz .found ; state == 0
cmp al, 5
jne .loop ; state == 1,2,3,4,9
; state == 5
pushad ; more freedom for [APPDATA.wait_test]
call [ebx+APPDATA.wait_test]
mov [esp+28], eax
popad
or eax, eax
jnz @f
; testing for timeout
mov ecx, [timer_ticks]
sub ecx, [ebx+APPDATA.wait_begin]
cmp ecx, [ebx+APPDATA.wait_timeout]
jb .loop
@@:
mov [ebx+APPDATA.wait_param], eax ; retval for wait
mov [edi+TASKDATA.state], 0
.found:
mov [CURRENT_TASK], bh
mov [TASK_BASE], edi
rdtsc ;call _rdtsc
mov [edi+TASKDATA.counter_add], eax; for next using update_counters
cmp ebx, esi ;esi - previous slot-base
ret
;TODO: Íàäî áû óáðàòü èñïîëüçîâàíèå do_change_task èç V86...
; è ïîñëå ýòîãî ïåðåíåñòè îáðàáîòêó TASKDATA.counter_add/sum â do_change_task
 
252,143 → 305,6
 
purge MUTEX_WAITER
 
MAX_PRIORITY = 0 ; highest, used for kernel tasks
USER_PRIORITY = 1 ; default
IDLE_PRIORITY = 2 ; lowest, only IDLE thread goes here
NR_SCHED_QUEUES = 3 ; MUST equal IDLE_PRIORYTY + 1
 
uglobal
; [scheduler_current + i*4] = zero if there are no threads with priority i,
; pointer to APPDATA of the current thread with priority i otherwise.
align 4
scheduler_current rd NR_SCHED_QUEUES
endg
 
; Add the given thread to the given priority list for the scheduler.
; in: edx -> APPDATA, ecx = priority
proc scheduler_add_thread
; 1. Acquire the lock.
spin_lock_irqsave SchedulerLock
; 2. Store the priority in APPDATA structure.
mov [edx+APPDATA.priority], ecx
; 3. There are two different cases: the given list is empty or not empty.
; In first case, go to 6. Otherwise, advance to 4.
mov eax, [scheduler_current+ecx*4]
test eax, eax
jz .new_list
; 4. Insert the new item immediately before the current item.
mov ecx, [eax+APPDATA.in_schedule.prev]
mov [edx+APPDATA.in_schedule.next], eax
mov [edx+APPDATA.in_schedule.prev], ecx
mov [eax+APPDATA.in_schedule.prev], edx
mov [ecx+APPDATA.in_schedule.next], edx
; 5. Release the lock and return.
spin_unlock_irqrestore SchedulerLock
ret
.new_list:
; 6. Initialize the list with one item and make it the current item.
mov [edx+APPDATA.in_schedule.next], edx
mov [edx+APPDATA.in_schedule.prev], edx
mov [scheduler_current+ecx*4], edx
; 7. Release the lock and return.
spin_unlock_irqrestore SchedulerLock
ret
endp
 
; Remove the given thread from the corresponding priority list for the scheduler.
; in: edx -> APPDATA
proc scheduler_remove_thread
; 1. Acquire the lock.
spin_lock_irqsave SchedulerLock
; 2. Remove the item from the corresponding list.
mov eax, [edx+APPDATA.in_schedule.next]
mov ecx, [edx+APPDATA.in_schedule.prev]
mov [eax+APPDATA.in_schedule.prev], ecx
mov [ecx+APPDATA.in_schedule.next], eax
; 3. If the given thread is the current item in the list,
; advance the current item.
; 3a. Check whether the given thread is the current item;
; if no, skip the rest of this step.
mov ecx, [edx+APPDATA.priority]
cmp [scheduler_current+ecx*4], edx
jnz .return
; 3b. Set the current item to eax; step 2 has set eax = next item.
mov [scheduler_current+ecx*4], eax
; 3c. If there were only one item in the list, zero the current item.
cmp eax, edx
jnz .return
mov [scheduler_current+ecx*4], 0
.return:
; 4. Release the lock and return.
spin_unlock_irqrestore SchedulerLock
ret
endp
 
;info:
; Find next task to execute
;retval:
; ebx = address of the APPDATA for the selected task (slot-base)
; edi = address of the TASKDATA for the selected task
; ZF = 1 if the task is the same
;warning:
; [CURRENT_TASK] = bh , [TASK_BASE] = edi -- as result
; [current_slot] is not set to new value (ebx)!!!
;scratched: eax,ecx
proc find_next_task
call update_counters
spin_lock_irqsave SchedulerLock
xor ecx, ecx
.priority_loop:
mov ebx, [scheduler_current+ecx*4]
test ebx, ebx
jz .priority_next
.task_loop:
mov ebx, [ebx+APPDATA.in_schedule.next]
mov edi, ebx
shr edi, 3
add edi, CURRENT_TASK - (SLOT_BASE shr 3)
mov al, [edi+TASKDATA.state]
test al, al
jz .task_found ; state == 0
cmp al, 5
jne .task_next ; state == 1,2,3,4,9
; state == 5
pushad ; more freedom for [APPDATA.wait_test]
call [ebx+APPDATA.wait_test]
mov [esp+28], eax
popad
or eax, eax
jnz @f
; testing for timeout
mov eax, [timer_ticks]
sub eax, [ebx+APPDATA.wait_begin]
cmp eax, [ebx+APPDATA.wait_timeout]
jb .task_next
xor eax, eax
@@:
mov [ebx+APPDATA.wait_param], eax ; retval for wait
mov [edi+TASKDATA.state], 0
.task_found:
mov [scheduler_current+ecx*4], ebx
spin_unlock_irqrestore SchedulerLock
.found:
mov [CURRENT_TASK], bh
mov [TASK_BASE], edi
rdtsc ;call _rdtsc
mov [edi+TASKDATA.counter_add], eax; for next using update_counters
cmp ebx, [current_slot]
ret
.task_next:
cmp ebx, [scheduler_current+ecx*4]
jnz .task_loop
.priority_next:
inc ecx
cmp ecx, NR_SCHED_QUEUES
jb .priority_loop
hlt
jmp $-1
endp
 
if 0
 
struc TIMER
400,6 → 316,13
}
 
 
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
 
uglobal
rdy_head rd 16
endg
/kernel/trunk/core/memory.inc
1136,6 → 1136,11
mov eax, [dst_slot]
shl eax, 8
or [eax+SLOT_BASE+0xA8], dword 0x40
cmp dword [check_idle_semaphore], 20
jge .ipc_no_cis
 
mov dword [check_idle_semaphore], 5
.ipc_no_cis:
push 0
jmp .ret
.no_pid:
/kernel/trunk/core/sys32.inc
159,7 → 159,6
call show_error_parameters ;; only ONE using, inline ???
;mov edx, [TASK_BASE]
mov [edx + TASKDATA.state], byte 4 ; terminate
call wakeup_osloop
jmp change_task ; stack - here it does not matter at all, SEE: core/shed.inc
.debug:
; we are debugged process, notify debugger and suspend ourself
262,10 → 261,8
 
 
align 4
lock_application_table:
push eax ecx edx
mov ecx, application_table_mutex
call mutex_lock
set_application_table_status:
push eax
 
mov eax, [CURRENT_TASK]
shl eax, 5
272,22 → 269,29
add eax, CURRENT_TASK+TASKDATA.pid
mov eax, [eax]
 
mov [application_table_owner], eax
mov [application_table_status], eax
 
pop edx ecx eax
pop eax
 
ret
 
align 4
unlock_application_table:
push eax ecx edx
clear_application_table_status:
push eax
 
mov [application_table_owner], 0
mov ecx, application_table_mutex
call mutex_unlock
mov eax, [CURRENT_TASK]
shl eax, 5
add eax, CURRENT_TASK+TASKDATA.pid
mov eax, [eax]
 
pop edx ecx eax
cmp eax, [application_table_status]
jne apptsl1
xor eax, eax
mov [application_table_status], eax
apptsl1:
 
pop eax
 
ret
 
; * eax = 64 - íîìåð ôóíêöèè
334,11 → 338,17
mov [CURRENT_TASK+esi+TASKDATA.state], 9
ret
@@:
lea edx, [SLOT_BASE+esi]
call scheduler_remove_thread
;mov esi,process_terminating
;call sys_msg_board_str
call lock_application_table
@@:
cli
cmp [application_table_status], 0
je term9
sti
call change_task
jmp @b
term9:
call set_application_table_status
 
; if the process is in V86 mode...
mov eax, [.slot]
381,11 → 391,11
stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
 
mov esi, [.slot]
cmp [fpu_owner], esi ; if user fpu last -> fpu user = 2
cmp [fpu_owner], esi ; if user fpu last -> fpu user = 1
jne @F
 
mov [fpu_owner], 2
mov eax, [256*2+SLOT_BASE+APPDATA.fpu_state]
mov [fpu_owner], 1
mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
clts
bt [cpu_caps], CAPS_SSE
jnc .no_SSE
678,7 → 688,7
mov [MOUSE_BACKGROUND], byte 0; no mouse background
mov [DONT_DRAW_MOUSE], byte 0; draw mouse
 
call unlock_application_table
and [application_table_status], 0
;mov esi,process_terminated
;call sys_msg_board_str
add esp, 4
/kernel/trunk/core/fpu.inc
179,5 → 179,5
iret
 
iglobal
fpu_owner dd 2
fpu_owner dd 0
endg
/kernel/trunk/core/timers.inc
203,28 → 203,3
call unlock_timer_list
; 4. Return.
ret
 
; This is a simplified version of check_timers that does not call anything,
; just checks whether check_timers should do something.
proc check_timers_has_work?
pushf
cli
mov eax, [timer_list+TIMER.Next]
.loop:
cmp eax, timer_list
jz .done_nowork
mov edx, [timer_ticks]
sub edx, [eax+TIMER.Time]
jns .done_haswork
mov eax, [eax+TIMER.Next]
jmp .loop
.done_nowork:
popf
xor eax, eax
ret
.done_haswork:
popf
xor eax, eax
inc eax
ret
endp
/kernel/trunk/bus/usb/init.inc
163,6 → 163,7
test ebx, ebx
jz usb_wakeup.nothing
usb_wakeup:
mov [check_idle_semaphore], 5 ; we really, really need a normal scheduler
xor edx, edx
mov eax, [usb_event]
mov ebx, [eax+EVENT.id]
/kernel/trunk/kernel.asm
348,9 → 348,6
mov ecx, unpack_mutex
call mutex_init
 
mov ecx, application_table_mutex
call mutex_init
 
; SAVE REAL MODE VARIABLES
mov ax, [BOOT_VAR + BOOT_IDE_BASE_ADDR]
mov [IDEContrRegsBaseAddr], ax
526,7 → 523,7
;lidt [idtreg]
 
call init_kernel_heap
stdcall kernel_alloc, (RING0_STACK_SIZE+512) * 2
stdcall kernel_alloc, RING0_STACK_SIZE+512
mov [os_stack_seg], eax
 
lea esp, [eax+RING0_STACK_SIZE]
606,6 → 603,10
 
xor eax, eax
inc eax
mov [CURRENT_TASK], eax ;dword 1
mov [TASK_COUNT], eax ;dword 1
mov [TASK_BASE], dword TASK_DATA
mov [current_slot], SLOT_BASE+256
 
; set background
 
620,29 → 621,49
mov esi, boot_setostask
call boot_log
 
mov edx, SLOT_BASE+256
mov ebx, [os_stack_seg]
add ebx, 0x2000
call setup_os_slot
mov dword [edx], 'IDLE'
sub [edx+APPDATA.saved_esp], 4
mov eax, [edx+APPDATA.saved_esp]
mov dword [eax], idle_thread
mov ecx, IDLE_PRIORITY
call scheduler_add_thread
xor eax, eax
mov dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
mov dword [SLOT_BASE+APPDATA.exc_handler], eax
mov dword [SLOT_BASE+APPDATA.except_mask], eax
 
mov edx, SLOT_BASE+256*2
mov ebx, [os_stack_seg]
call setup_os_slot
mov dword [edx], 'OS'
xor ecx, ecx
call scheduler_add_thread
; name for OS/IDLE process
 
mov dword [CURRENT_TASK], 2
mov dword [TASK_COUNT], 2
mov dword [current_slot], SLOT_BASE + 256*2
mov dword [TASK_BASE], CURRENT_TASK + 32*2
mov dword [SLOT_BASE+256+APPDATA.app_name], dword 'OS/I'
mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
mov edi, [os_stack_seg]
mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
add edi, 0x2000-512
mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi; just for case
mov dword [SLOT_BASE+256+APPDATA.terminate_protection], 80000001h
 
mov esi, fpu_data
mov ecx, 512/4
cld
rep movsd
 
mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax
mov dword [SLOT_BASE+256+APPDATA.except_mask], eax
 
mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
mov dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
mov dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
 
mov dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
mov dword [SLOT_BASE+256+APPDATA.tls_base], eax
 
; task list
mov dword [TASK_DATA+TASKDATA.mem_start], eax; process base address
inc eax
mov dword [CURRENT_TASK], eax
mov dword [TASK_COUNT], eax
mov [current_slot], SLOT_BASE+256
mov [TASK_BASE], dword TASK_DATA
mov byte[TASK_DATA+TASKDATA.wnd_number], al ; on screen number
mov dword [TASK_DATA+TASKDATA.pid], eax ; process id number
 
mov [SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE
 
stdcall kernel_alloc, 0x10000/8
mov edi, eax
mov [network_free_ports], eax
807,8 → 828,8
 
call init_display
mov eax, [def_cursor]
mov [SLOT_BASE+APPDATA.cursor], eax
mov [SLOT_BASE+APPDATA.cursor+256], eax
mov [SLOT_BASE+APPDATA.cursor+256*2], eax
 
; PRINT CPU FREQUENCY
 
926,6 → 947,10
 
cli
 
;mov [TASK_COUNT],dword 2
push 1
pop dword [CURRENT_TASK] ; set OS task fisrt
 
; SET KEYBOARD PARAMETERS
mov al, 0xf6 ; reset keyboard, scan enabled
call kb_write
1043,7 → 1068,7
mov [timer_ticks_enable], 1 ; for cd driver
 
sti
; call change_task
call change_task
 
jmp osloop
 
1072,43 → 1097,6
 
ret
 
; in: edx -> APPDATA for OS/IDLE slot
; in: ebx = stack base
proc setup_os_slot
xor eax, eax
mov ecx, 256/4
mov edi, edx
rep stosd
 
mov dword [edx+APPDATA.pl0_stack], ebx
lea edi, [ebx+0x2000-512]
mov dword [edx+APPDATA.fpu_state], edi
mov dword [edx+APPDATA.saved_esp0], edi
mov dword [edx+APPDATA.saved_esp], edi
mov dword [edx+APPDATA.terminate_protection], 1 ; make unkillable
 
mov esi, fpu_data
mov ecx, 512/4
cld
rep movsd
 
lea eax, [edx+APP_OBJ_OFFSET]
mov dword [edx+APPDATA.fd_obj], eax
mov dword [edx+APPDATA.bk_obj], eax
 
mov dword [edx+APPDATA.cur_dir], sysdir_path
 
mov [edx + APPDATA.dir_table], sys_pgdir - OS_BASE
 
mov eax, edx
shr eax, 3
add eax, CURRENT_TASK - (SLOT_BASE shr 3)
mov [eax+TASKDATA.wnd_number], dh
mov byte [eax+TASKDATA.pid], dh
 
ret
endp
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; MAIN OS LOOP START ;
1116,13 → 1104,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 32
osloop:
mov edx, osloop_has_work?
xor ecx, ecx
call Wait_events
xor eax, eax
xchg eax, [osloop_nonperiodic_work]
test eax, eax
jz .no_periodic
; call [draw_pointer]
call __sys_draw_pointer
call window_check_events
1129,8 → 1110,8
call mouse_check_events
call checkmisc
call checkVga_N13
.no_periodic:
call stack_handler
call checkidle
call check_fdd_motor_status
call check_ATAPI_device_event
call check_lights_state
1141,47 → 1122,39
; MAIN OS LOOP END ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
proc osloop_has_work?
cmp [osloop_nonperiodic_work], 0
jnz .yes
call stack_handler_has_work?
jnz .yes
call check_fdd_motor_status_has_work?
jnz .yes
call check_ATAPI_device_event_has_work?
jnz .yes
call check_lights_state_has_work?
jnz .yes
call check_timers_has_work?
jnz .yes
.no:
xor eax, eax
align 4
checkidle:
pushad
call change_task
jmp idle_loop_entry
idle_loop:
cmp eax, [idlemem] ; eax == [timer_ticks]
jne idle_exit
rdtsc ;call _rdtsc
mov ecx, eax
hlt
rdtsc ;call _rdtsc
sub eax, ecx
add [idleuse], eax
idle_loop_entry:
mov eax, [timer_ticks]; eax = [timer_ticks]
cmp [check_idle_semaphore], 0
je idle_loop
dec [check_idle_semaphore]
idle_exit:
mov [idlemem], eax ; eax == [timer_ticks]
popad
ret
.yes:
xor eax, eax
inc eax
ret
endp
 
proc wakeup_osloop
mov [osloop_nonperiodic_work], 1
ret
endp
 
uglobal
align 4
osloop_nonperiodic_work dd ?
idlemem dd 0x0
idleuse dd 0x0
idleusesec dd 0x0
check_idle_semaphore dd 0x0
endg
 
align 4
idle_thread:
sti
idle_loop:
hlt
jmp idle_loop
 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; INCLUDED SYSTEM FILES ;
1227,7 → 1200,7
 
 
iglobal
process_number dd 0x2
process_number dd 0x1
endg
 
set_variables:
1244,7 → 1217,6
mov ax, [BOOT_VAR+BOOT_X_RES]
shr ax, 1
mov [MOUSE_X], eax
call wakeup_osloop
 
xor eax, eax
mov [BTN_ADDR], dword BUTTON_INFO ; address of button list
2035,7 → 2007,6
 
mov eax, [TASK_BASE]
mov [eax+TASKDATA.state], 3; terminate this program
call wakeup_osloop
 
waitterm: ; wait here for termination
mov ebx, 100
2069,7 → 2040,6
mov [current_cursor], esi
@@:
mov [redrawmouse_unconditional], 1
call wakeup_osloop
popfd
ret
;------------------------------------------------------------------------------
2122,7 → 2092,6
mov eax, [TASK_COUNT]
mov [SYS_SHUTDOWN], al
mov [shutdown_processes], eax
call wakeup_osloop
and dword [esp+32], 0
exit_for_anyone:
ret
2168,12 → 2137,11
;--------------------------------------
;call MEM_Heap_Lock ;guarantee that process isn't working with heap
mov [ecx], byte 3; clear possible i40's
call wakeup_osloop
;call MEM_Heap_UnLock
 
cmp edx, [application_table_owner]; clear app table stat
cmp edx, [application_table_status]; clear app table stat
jne noatsc
call unlock_application_table
and [application_table_status], 0
noatsc:
noprocessterminate:
add esp, 4
2182,7 → 2150,14
sysfn_terminate2:
;lock application_table_status mutex
.table_status:
call lock_application_table
cli
cmp [application_table_status], 0
je .stf
sti
call change_task
jmp .table_status
.stf:
call set_application_table_status
mov eax, ecx
call pid_to_slot
test eax, eax
2190,12 → 2165,12
mov ecx, eax
cli
call sysfn_terminate
call unlock_application_table
and [application_table_status], 0
sti
and dword [esp+32], 0
ret
.not_found:
call unlock_application_table
mov [application_table_status], 0
or dword [esp+32], -1
ret
;------------------------------------------------------------------------------
2244,7 → 2219,6
@@:
;-------------------------------------
mov [window_minimize], 2; restore window if minimized
call wakeup_osloop
 
movzx esi, word [WIN_STACK + ecx*2]
cmp esi, [TASK_COUNT]
2260,7 → 2234,7
ret
;------------------------------------------------------------------------------
sysfn_getidletime: ; 18.4 = GET IDLETIME
mov eax, [CURRENT_TASK+32+TASKDATA.cpu_usage]
mov eax, [idleusesec]
mov [esp+32], eax
ret
;------------------------------------------------------------------------------
2302,7 → 2276,6
;------------------------------------------------------------------------------
sysfn_minimize: ; 18.10 = minimize window
mov [window_minimize], 1
call wakeup_osloop
ret
;------------------------------------------------------------------------------
align 4
2365,7 → 2338,6
mov eax, [Screen_Max_Y]
shr eax, 1
mov [MOUSE_Y], ax
call wakeup_osloop
; ret
;* mouse centered - end code- Mario79
xor eax, eax
2410,7 → 2382,6
cmp dx, word[Screen_Max_X]
ja .end
mov [MOUSE_X], edx
call wakeup_osloop
ret
.set_mouse_button:
; cmp ecx,5 ; set mouse button features
2418,7 → 2389,6
jnz .end
mov [BTN_DOWN], dl
mov [mouse_active], 1
call wakeup_osloop
.end:
ret
;------------------------------------------------------------------------------
2878,7 → 2848,6
mov [draw_data+32 + RECT.bottom], edx
 
inc byte[REDRAW_BACKGROUND]
call wakeup_osloop
;--------------------------------------
align 4
.exit:
2905,7 → 2874,6
mov [draw_data+32 + RECT.bottom], ebx
pop ebx eax
inc byte[REDRAW_BACKGROUND]
call wakeup_osloop
ret
;------------------------------------------------------------------------------
align 4
3564,7 → 3532,6
@@:
add edx, 0x20
loop markz
call wakeup_osloop
;--------------------------------------
align 4
@@:
3716,7 → 3683,6
align 4
@@:
add byte[REDRAW_BACKGROUND], dl
call wakeup_osloop
jmp newdw8
;--------------------------------------
align 4
3738,7 → 3704,6
cmp dword [esp], 1
jne nobgrd
inc byte[REDRAW_BACKGROUND]
call wakeup_osloop
;--------------------------------------
align 4
newdw8:
4733,16 → 4698,10
mov word [msg_board_pos], 10
@@:
end if
if 0
pusha
mov al, bl
mov edx, 402h
out dx, al
popa
end if
inc ecx
and ecx, msg_board_data_size - 1
mov [msg_board_count], ecx
mov [check_idle_semaphore], 5
ret
.smbl1:
cmp eax, 2
/kernel/trunk/kernel32.inc
132,21 → 132,19
wnd_shape_scale dd ? ;+132
dd ? ;+136
mem_size dd ? ;+140
saved_box BOX ;+144
ipc_start dd ? ;+160
ipc_size dd ? ;+164
event_mask dd ? ;+168
debugger_slot dd ? ;+172
terminate_protection dd ? ;+176
keyboard_mode db ? ;+180
saved_box BOX
ipc_start dd ?
ipc_size dd ?
event_mask dd ?
debugger_slot dd ?
terminate_protection dd ?
keyboard_mode db ?
rb 3
dir_table dd ? ;+184
dbg_event_mem dd ? ;+188
dbg_regs DBG_REGS ;+192
wnd_caption dd ? ;+212
wnd_clientbox BOX ;+216
priority dd ? ;+232
in_schedule LHEAD ;+236
dir_table dd ?
dbg_event_mem dd ?
dbg_regs DBG_REGS
wnd_caption dd ?
wnd_clientbox BOX
 
ends
 
/kernel/trunk/network/stack.inc
191,12 → 191,6
mov [last_1sTick], al
ret
 
; Wakeup every tick.
proc stack_handler_has_work?
mov eax, [timer_ticks]
cmp eax, [last_1hsTick]
ret
endp
 
 
;***************************************************************************
/kernel/trunk/network/udp.inc
146,6 → 146,8
shl ecx, 8
or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
 
mov [check_idle_semaphore], 200
 
.exit:
pop eax
call freeBuff ; Discard the packet
/kernel/trunk/data32.inc
397,8 → 397,7
 
; status
hd1_status rd 1 ; 0 - free : other - pid
application_table_owner rd 1 ; 0 - free : other - pid
application_table_mutex MUTEX
application_table_status rd 1 ; 0 - free : other - pid
 
; device addresses
mididp rd 1
/kernel/trunk/gui/event.inc
165,6 → 165,7
; esi - event data (=0 => skip)
;scratched: ebx,ecx,esi,edi
call NotDummyTest ; not returned for fail !!!
mov [check_idle_semaphore], 5
or esi, esi
jz @f
lea edi, [ebx+EVENT.code]
589,7 → 590,6
cmp edx, 0xFFFF ;-ID for Minimize-Button of Form
jne .result
mov [window_minimize], 1
call wakeup_osloop
dec byte[BTN_COUNT]
jmp .loop
;--------------------------------------
/kernel/trunk/gui/window.inc
1629,7 → 1629,6
; Otherwise the user can see cursor specified by f.37.5 from another window.
; He will be really unhappy! He is terrible in rage - usually he throws stones!
mov [redrawmouse_unconditional], 1
call wakeup_osloop
; NOTE: commented out since doesn't provide necessary functionality
; anyway, to be reworked
; mov eax, [timer_ticks] ; [0xfdf0]
/kernel/trunk/hid/keyboard.inc
339,7 → 339,6
jne .noctrlaltdel
mov [ctrl_alt_del], 1
call wakeup_osloop
.noctrlaltdel:
test dl, VKEY_CONTROL ; ctrl on ?
jz @f
491,6 → 490,7
mov [KEY_COUNT], al
mov [KEY_COUNT+eax], bl
.exit.irq1:
mov [check_idle_semaphore], 5
ret
;---------------------------------------------------------------------
set_lights:
526,14 → 526,9
ret 8
 
;// mike.dld ]
proc check_lights_state_has_work?
check_lights_state:
mov al, [kb_lights]
cmp al, [old_kb_lights]
ret
endp
 
check_lights_state:
call check_lights_state_has_work?
jz .nothing
mov [old_kb_lights], al
call set_lights
/kernel/trunk/hid/mousedrv.inc
531,7 → 531,6
mov [mouse_active], 1
mov eax, [timer_ticks]
mov [mouse_timer_ticks], eax
call wakeup_osloop
ret
endp
;-----------------------------------------------------------------------------