refractoring of EVENT, and so on

git-svn-id: svn://kolibrios.org@1055 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Galkov 2009-03-28 18:36:41 +00:00
parent 361dc65fd3
commit 3be0aa5c21
11 changed files with 3355 additions and 3697 deletions

View File

@ -468,9 +468,10 @@ struc EVENT
.id dd ? ;event uid
.state dd ? ;internal flags
.code dd ?
rd 5
rd 6
.size = $ - .magic
.codesize = $ - .code
}
EVENT_SIZE equ 52
virtual at 0
EVENT EVENT
@ -687,4 +688,3 @@ end virtual
virtual at 0
CSYM COFF_SYM
end virtual

View File

@ -126,11 +126,11 @@ kernel_export:
dd szGetPid , get_pid
dd szCreateObject , create_kernel_object
dd szDestroyObject , destroy_kernel_object
dd szCreateEvent , create_event
dd szRaiseEvent , raise_event
dd szWaitEvent , wait_event
dd szDestroyEvent , destroy_event
dd szClearEvent , clear_event
dd szCreateEvent , create_event ;see EVENT.inc for specification
dd szRaiseEvent , raise_event ;see EVENT.inc for specification
dd szWaitEvent , wait_event ;see EVENT.inc for specification
dd szDestroyEvent , destroy_event ;see EVENT.inc for specification
dd szClearEvent , clear_event ;see EVENT.inc for specification
dd szLoadCursor , load_cursor ;stdcall
@ -143,7 +143,7 @@ kernel_export:
dd szSysMsgBoardChar , sys_msg_board
dd szGetCurrentTask , get_curr_task
dd szLoadFile , load_file ;retval eax, ebx
dd szSendEvent , send_event
dd szSendEvent , send_event ;see EVENT.inc for specification
dd szSetMouseData , set_mouse_data ;stdcall
dd szSleep , delay_ms
dd szGetTimerTicks , get_timer_ticks
@ -160,4 +160,3 @@ exp_lfb:
dd 0 ;terminator, must be zero
endg

View File

@ -1051,7 +1051,8 @@ f68:
.14:
cmp ebx, OS_BASE
jae .fail
stdcall get_event_ex, ebx, ecx
mov edi,ebx
call get_event_ex
mov [esp+36], eax
ret
.15:

View File

@ -16,74 +16,35 @@ $Revision$
align 32
irq0:
pushad
mov ax, app_data ;
mov ds, ax
Mov ds, ax, app_data
mov es, ax
; cmp dword[CURRENT_TASK], 1
; jnz @f
; mov eax, [esp + 32]
; cmp eax, idle_loop + 1
; jz @f
; DEBUGF 1, "K : OOOPS! EAX = 0x%x\n", eax
; @@:
inc dword [timer_ticks]
inc [timer_ticks]
mov eax, [timer_ticks]
call playNote ; <<<--- Speaker driver
cmp eax,[next_usage_update]
sub eax,[next_usage_update]
cmp eax,100
jb .nocounter
add eax,100
mov [next_usage_update],eax
add [next_usage_update],100
call updatecputimes
.nocounter:
cmp [DONT_SWITCH], byte 1
jne .change_task
.nocounter:
mov al,0x20 ; send End Of Interrupt signal
mov dx,0x20
out dx,al
mov [DONT_SWITCH], byte 0
popad
iretd
.change_task:
call update_counters
out 0x20,al
btr dword[DONT_SWITCH], 0
jc .return
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
jz .return ; if there is only one running process
call do_change_task
.return:
.return:
popad
; popfd
iretd
align 4
change_task:
pushfd
cli
pushad
call update_counters
if 0
; \begin{Mario79}
; \begin{Mario79} ; <- must be refractoried, if used...
cmp [dma_task_switched], 1
jne .find_next_task
mov [dma_task_switched], 0
@ -96,195 +57,152 @@ if 0
jmp @f
.find_next_task:
; \end{Mario79}
end if
call find_next_task
test eax, eax ; the same task -> skip switch
jnz .return
@@:
mov [DONT_SWITCH],byte 1
jz .return ; the same task -> skip switch
@@: mov byte[DONT_SWITCH], 1
call do_change_task
.return:
.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 ?
align 4
; far_jump:
; .offs dd ?
; .sel dw ?
context_counter dd 0 ;noname & halyavin
next_usage_update dd 0
timer_ticks dd 0
; prev_slot dd ?
; event_sched dd ?
endg
align 4
update_counters:
mov edi, [TASK_BASE]
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
rdtsc
sub eax, ebx
add eax, [edi+TASKDATA.counter_sum] ; counter sum
mov [edi+TASKDATA.counter_sum], eax
ret
; Find next task to execute
; result: ebx = number of the selected task
; 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
find_next_task:
mov ebx, [CURRENT_TASK]
mov edi, [TASK_BASE]
mov [prev_slot], ebx
.waiting_for_termination:
.waiting_for_reuse:
.waiting_for_event:
.suspended:
cmp ebx, [TASK_COUNT]
jb @f
mov edi, CURRENT_TASK
xor ebx, ebx
@@:
add edi,0x20
inc ebx
mov al, byte [edi+TASKDATA.state]
test al, al
jz .found
cmp al, 1
jz .suspended
cmp al, 2
jz .suspended
cmp al, 3
je .waiting_for_termination
cmp al, 4
je .waiting_for_termination
cmp al, 9
je .waiting_for_reuse
mov [CURRENT_TASK],ebx
mov [TASK_BASE],edi
cmp al, 5
jne .noevents
call get_event_for_app
test eax, eax
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
@@:
mov [event_sched], eax
mov [edi+TASKDATA.state], byte 0
.noevents:
.found:
mov [CURRENT_TASK],ebx
mov [TASK_BASE],edi
rdtsc ;call _rdtsc
mov [edi+TASKDATA.counter_add],eax
mov esi, [prev_slot]
xor eax, eax
cmp ebx, esi
sete al
ret
; param
; ebx = incoming task
; esi = outcomig task
do_change_task:
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]
cmp eax, [esi+APPDATA.dir_table]
je @F
mov cr3, eax
@@:
mov eax, [ebx+APPDATA.saved_esp0]
mov [tss._esp0], eax
mov ax, graph_data
mov gs, ax
mov eax, [CURRENT_TASK]
cmp eax, [fpu_owner]
clts ;clear a task switch flag
je @F
;and set it again if the owner
mov ecx, cr0 ;of a fpu has changed
or ecx, CR0_TS
mov cr0, ecx
@@:
inc [context_counter] ;noname & halyavin
test [ebx+APPDATA.dbg_state], 1
jnz @F
sub eax, [edi+TASKDATA.counter_add] ; time stamp counter add
add [edi+TASKDATA.counter_sum], eax ; counter sum
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
align 4
updatecputimes:
xor eax,eax
xchg eax,[idleuse]
mov [idleusesec],eax
mov ecx, [TASK_COUNT]
mov edi, TASK_DATA
.newupdate:
xor eax,eax
xchg eax,[edi+TASKDATA.counter_sum]
mov [edi+TASKDATA.cpu_usage],eax
add edi,0x20
loop .newupdate
ret
align 4
updatecputimes:
mov eax,[idleuse]
mov [idleusesec],eax
mov [idleuse],dword 0
mov ecx, [TASK_COUNT]
mov edi, TASK_DATA
.newupdate:
mov ebx,[edi+TASKDATA.counter_sum]
mov [edi+TASKDATA.cpu_usage],ebx
mov [edi+TASKDATA.counter_sum],dword 0
add edi,0x20
dec ecx
jnz .newupdate
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
align 4
do_change_task:
;param:
; ebx = address of the APPDATA for incoming task (new)
;warning:
; [CURRENT_TASK] and [TASK_BASE] must be changed before (e.g. in find_next_task)
; [current_slot] is the outcoming (old), and set here to a new value (ebx)
;scratched: eax,ecx,esi
mov esi,ebx
xchg esi,[current_slot]
; set new stack after saving old
mov [esi+APPDATA.saved_esp], esp
mov esp, [ebx+APPDATA.saved_esp]
; set new thread io-map
Mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)],eax,[ebx+APPDATA.io_map]
Mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)],eax,[ebx+APPDATA.io_map+4]
; set new thread memory-map
mov ecx, APPDATA.dir_table
mov eax, [ebx+ecx] ;offset>0x7F
cmp eax, [esi+ecx] ;offset>0x7F
je @f
mov cr3, eax
@@: ; set tss.esp0
Mov [tss._esp0],eax,[ebx+APPDATA.saved_esp0]
; set gs selector unconditionally
Mov gs,ax,graph_data
; set CR0.TS
cmp bh, byte[fpu_owner] ;bh == incoming task (new)
clts ;clear a task switch flag
je @f
mov eax, cr0 ;and set it again if the owner
or eax, CR0_TS ;of a fpu has changed
mov cr0, eax
@@: ; set context_counter (only for user pleasure ???)
inc [context_counter] ;noname & halyavin
; set debug-registers, if it's necessary
test byte[ebx+APPDATA.dbg_state], 1
jz @f
xor eax, eax
mov dr6, eax
lea esi,[ebx+ecx+APPDATA.dbg_regs-APPDATA.dir_table] ;offset>0x7F
cld
macro lodsReg [reg] {
lodsd
mov reg,eax
} lodsReg dr0, dr1, dr2, dr3, dr7
purge lodsReg
@@: ret
;end.
if 0
struc TIMER
{
.next dd ?
@ -293,14 +211,6 @@ struc TIMER
.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)
@ -310,12 +220,11 @@ NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1
rdy_head rd 16
align 4
pick_task:
xor eax, eax
.pick:
.pick:
mov ebx, [rdy_head+eax*4]
test ebx, ebx
jz .next
@ -324,13 +233,12 @@ pick_task:
test [ebx+flags.billable]
jz @F
mov [bill_task], ebx
@@:
@@:
ret
.next:
.next:
inc eax
jmp .pick
; param
; eax= task
;
@ -338,7 +246,6 @@ pick_task:
; eax= task
; ebx= queue
; ecx= front if 1 or back if 0
align 4
shed:
cmp [eax+.tics_left], 0 ;signed compare
@ -351,12 +258,11 @@ shed:
cmp ebx, (IDLE_PRIORITY-1)
je @F
inc ebx
@@:
@@:
ret
; param
; eax= task
align 4
enqueue:
call shed ;eax
@ -367,7 +273,7 @@ enqueue:
mov [rdy_tail+ebx*4], eax
mov [eax+.next_ready], 0
jmp .pick
@@:
@@:
test ecx, ecx
jz .back
@ -375,14 +281,13 @@ enqueue:
mov [eax+.next_ready], ecx
mov [rdy_head+ebx*4], eax
jmp .pick
.back:
.back:
mov ecx, [rdy_tail+ebx*4]
mov [ecx+.next_ready], eax
mov [rdy_tail+ebx*4], eax
mov [eax+.next_ready], 0
.pick:
.pick:
call pick_proc ;select next task
ret
end if

View File

@ -16,27 +16,11 @@ cross_order:
mov ecx, edx
mov edx, esi
mov esi, edi
mov edi, [esp+28 + 4]
and edi,0xff
movzx edi, byte[esp+28 + 4]
call dword [servetable+edi*4]
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SYSTEM CALL ENTRY ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 16
i40:
pushad
cld
movzx eax, al
call dword [servetable2 + eax * 4]
popad
iretd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SYSENTER ENTRY ;;
@ -68,6 +52,21 @@ sysenter_entry:
pop edx
sysexit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SYSTEM CALL ENTRY ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 16
i40:
pushad
cld
movzx eax, al
call dword [servetable2 + eax * 4]
popad
iretd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SYSCALL ENTRY ;;
@ -95,6 +94,7 @@ syscall_entry:
mov ecx, [ss:esp+4]
pop esp
sysret
iglobal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SYSTEM FUNCTIONS TABLE ;;
@ -175,7 +175,6 @@ iglobal
dd sys_debug_services ; 69-Debug
dd file_system_lfn ; 70-Common file system interface, version 2
dd syscall_windowsettings ; 71-Window settings
dd sys_sendwindowmsg ; 72-Send window message
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NEW SYSTEM FUNCTIONS TABLE ;;
@ -255,7 +254,7 @@ iglobal
dd cross_order ; 69-Debug
dd cross_order ; 70-Common file system interface, version 2
dd cross_order ; 71-Window settings
dd cross_order ; 72-Send window message
dd sys_sendwindowmsg ; 72-Send window message
times 255 - ( ($-servetable2) /4 ) dd undefined_syscall
dd sys_end ; -1-end application

View File

@ -945,12 +945,12 @@ v86_irq2:
mov cx, [eax*4+2]
mov word [esi-v86_regs.size+v86_regs.cs], cx
and byte [esi-v86_regs.size+v86_regs.eflags+1], not 3
push ebx
; push ebx
call update_counters
pop ebx
sub ebx, SLOT_BASE
shr ebx, 8
mov esi, [CURRENT_TASK]
; pop ebx
; sub ebx, SLOT_BASE
; shr ebx, 8
; mov esi, [CURRENT_TASK]
call do_change_task
popad
iretd

View File

@ -292,7 +292,6 @@ irq15read rd 16
irq_tab rd 16
mem_block_map rb 512
event_map rb 64
mem_block_list rd 64
large_block_list rd 31
mem_block_mask rd 2
@ -315,10 +314,6 @@ mst MEM_STATE
page_start rd 1
page_end rd 1
events rd 1
event_start rd 1
event_end rd 1
event_uid rd 1
sys_page_map rd 1
os_stack_seg rd 1
@ -471,4 +466,3 @@ BiosDiskCaches rb 80h*(cache_ide1-cache_ide0)
BiosDiskPartitions rd 80h
IncludeUGlobals

File diff suppressed because it is too large Load Diff

View File

@ -725,11 +725,11 @@ no_lib_load:
mov esi,boot_tsc
call boot_log
cli
call _rdtsc
rdtsc ;call _rdtsc
mov ecx,eax
mov esi,250 ; wait 1/4 a second
call delay_ms
call _rdtsc
rdtsc ;call _rdtsc
sti
sub eax,ecx
shl eax,2
@ -1013,57 +1013,27 @@ osloop:
checkidle:
pushad
cmp [check_idle_semaphore],0
jne no_idle_state
mov ebx,[timer_ticks]
call change_task
mov eax,[idlemem]
mov ebx,[timer_ticks] ;[0xfdf0]
cmp eax,ebx
jnz idle_exit
call _rdtsc
mov ecx,eax
jmp idle_loop_entry
idle_loop:
cmp ebx,[timer_ticks]
jne idle_exit
rdtsc ;call _rdtsc
mov ecx,eax
hlt
cmp [check_idle_semaphore],0
jne idle_loop_exit
mov eax,[timer_ticks] ;[0xfdf0]
cmp ebx,eax
jz idle_loop
idle_loop_exit:
mov [idlemem],eax
call _rdtsc
rdtsc ;call _rdtsc
sub eax,ecx
mov ebx,[idleuse]
add ebx,eax
mov [idleuse],ebx
popad
ret
idle_exit:
mov ebx,[timer_ticks] ;[0xfdf0]
mov [idlemem],ebx
call change_task
popad
ret
no_idle_state:
add [idleuse],eax
idle_loop_entry:
cmp [check_idle_semaphore],0
je idle_loop
dec [check_idle_semaphore]
mov ebx,[timer_ticks] ;[0xfdf0]
mov [idlemem],ebx
call change_task
idle_exit:
popad
ret
uglobal
idlemem dd 0x0
idleuse dd 0x0
idleusesec dd 0x0
check_idle_semaphore dd 0x0
@ -1167,7 +1137,6 @@ set_variables:
mov [BTN_ADDR],dword BUTTON_INFO ; address of button list
;!! IP 04.02.2005:
mov [next_usage_update], 100
mov byte [DONT_SWITCH], 0 ; change task if possible
ret
@ -4669,7 +4638,7 @@ setmouse: ; set mousepicture -pointer
ret
if used _rdtsc
_rdtsc:
bt [cpu_caps], CAPS_TSC
jnc ret_rdtsc
@ -4679,6 +4648,7 @@ _rdtsc:
mov edx,0xffffffff
mov eax,0xffffffff
ret
end if
rerouteirqs:
@ -5621,4 +5591,3 @@ __REV__ = __REV
uglobals_size = $ - endofcode
diff16 "end of kernel code",0,$

View File

@ -121,7 +121,7 @@ struc APPDATA
db 5 dup(?)
.fpu_state dd ? ;+16
.ev_count dd ? ;+20
.ev_count_ dd ? ;unused ;+20
.fpu_handler dd ? ;+24
.sse_handler dd ? ;+28
.pl0_stack dd ? ;unused ;+32
@ -138,8 +138,10 @@ struc APPDATA
.cur_dir dd ? ;+80
.wait_timeout dd ? ;+84
.saved_esp0 dd ? ;+88
db 36 dup(?) ;+92
.wait_begin dd ? ;+92 +++
.wait_test dd ? ;+96 +++
.wait_param dd ? ;+100 +++
db 24 dup(?) ;+104
.wnd_shape dd ? ;+128
.wnd_shape_scale dd ? ;+132

View File

@ -98,3 +98,9 @@ if ~ f eq
end if
}
; \end{diamond}[29.09.2006]
macro Mov op1,op2,op3 ; op1 = op2 = op3
{
mov op2,op3
mov op1,op2
}