diff --git a/kernel/branches/Kolibri-acpi/const.inc b/kernel/branches/Kolibri-acpi/const.inc index aaed486653..252a85f571 100644 --- a/kernel/branches/Kolibri-acpi/const.inc +++ b/kernel/branches/Kolibri-acpi/const.inc @@ -354,17 +354,205 @@ EVENT_EXTENDED equ 0x00000400 EV_INTR equ 1 -struct THR_DATA - rb (8192-512) -; pl0_stack - fpu_state rb 512 - tls_page rb 4096 - pdbr rb 4096 +struct SYSCALL_STACK + _eip dd ? + _edi dd ? ; +4 + _esi dd ? ; +8 + _ebp dd ? ; +12 + _esp dd ? ; +16 + _ebx dd ? ; +20 + _edx dd ? ; +24 + _ecx dd ? ; +28 + _eax dd ? ; +32 ends -virtual at (OS_BASE-sizeof.THR_DATA) - thr_data THR_DATA -end virtual +struct LHEAD + next dd ? ;next object in list + prev dd ? ;prev object in list +ends + +struct MUTEX_WAITER + list LHEAD + task dd ? + type dd ? +ends + +struct MUTEX + wait_list LHEAD + count dd ? +ends + +struct RWSEM + wait_list LHEAD + count dd ? +ends + +struct FUTEX + list LHEAD + magic dd ? + handle dd ? + destroy dd ? + + wait_list LHEAD + pointer dd ? + flags dd ? +ends + +FUTEX_INIT equ 0 +FUTEX_WAIT equ 1 +FUTEX_WAKE equ 2 + +struct PROC + list LHEAD + thr_list LHEAD + heap_lock MUTEX + heap_base rd 1 + heap_top rd 1 + mem_used rd 1 + dlls_list_ptr rd 1 + pdt_0_phys rd 1 + pdt_1_phys rd 1 + io_map_0 rd 1 + io_map_1 rd 1 + + ht_lock rd 1 + ht_free rd 1 ;htab[0] stdin + ht_next rd 1 ;htab[1] stdout + htab rd (4096-$)/4 ;htab[2] stderr + pdt_0 rd 1024 +ends + +struct DBG_REGS + dr0 dd ? + dr1 dd ? + dr2 dd ? + dr3 dd ? + dr7 dd ? +ends + +struct POINT + x dd ? + y dd ? +ends + +struct RECT + left dd ? + top dd ? + right dd ? + bottom dd ? +ends + +struct BOX + left dd ? + top dd ? + width dd ? + height dd ? +ends + +struct APPDATA + app_name rb 11 + rb 5 + + list LHEAD ;+16 + process dd ? ;+24 + fpu_state dd ? ;+28 + exc_handler dd ? ;+32 + except_mask dd ? ;+36 + pl0_stack dd ? ;+40 + cursor dd ? ;+44 + fd_ev dd ? ;+48 + bk_ev dd ? ;+52 + fd_obj dd ? ;+56 + bk_obj dd ? ;+60 + saved_esp dd ? ;+64 + io_map rd 2 ;+68 + dbg_state dd ? ;+76 + cur_dir dd ? ;+80 + wait_timeout dd ? ;+84 + saved_esp0 dd ? ;+88 + wait_begin dd ? ;+92 +++ + wait_test dd ? ;+96 +++ + wait_param dd ? ;+100 +++ + tls_base dd ? ;+104 + dd ? ;+108 + event_filter dd ? ;+112 + draw_bgr_x dd ? ;+116 + draw_bgr_y dd ? ;+120 + dd ? ;+124 + + wnd_shape dd ? ;+128 + wnd_shape_scale dd ? ;+132 + dd ? ;+136 + 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 + rb 3 + 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 +ends + +APP_OBJ_OFFSET equ 48 +APP_EV_OFFSET equ 40 + +struct TASKDATA + event_mask dd ? + pid dd ? + dw ? + state db ? + db ? + dw ? + wnd_number db ? + db ? + mem_start dd ? + counter_sum dd ? + counter_add dd ? + cpu_usage dd ? +ends + +TSTATE_RUNNING = 0 +TSTATE_RUN_SUSPENDED = 1 +TSTATE_WAIT_SUSPENDED = 2 +TSTATE_ZOMBIE = 3 +TSTATE_TERMINATING = 4 +TSTATE_WAITING = 5 +TSTATE_FREE = 9 + +; constants definition +WSTATE_NORMAL = 00000000b +WSTATE_MAXIMIZED = 00000001b +WSTATE_MINIMIZED = 00000010b +WSTATE_ROLLEDUP = 00000100b + +WSTATE_REDRAW = 00000001b +WSTATE_WNDDRAWN = 00000010b + +WSTYLE_HASCAPTION = 00010000b +WSTYLE_CLIENTRELATIVE = 00100000b + +; structures definition +struct WDATA + box BOX + cl_workarea dd ? + cl_titlebar dd ? + cl_frames dd ? + reserved db ? + fl_wstate db ? + fl_wdrawn db ? + fl_redraw db ? +ends + +label WDATA.fl_wstyle byte at WDATA.cl_workarea + 3 + struct SYS_VARS bpp dd ? @@ -382,9 +570,6 @@ struct APPOBJ ; common object header pid dd ? ; owner id ends -APP_OBJ_OFFSET equ 48 -APP_EV_OFFSET equ 40 - struct CURSOR APPOBJ base dd ? ;allocated memory hot_x dd ? ;hotspot coords @@ -480,33 +665,6 @@ struct BOOT_DATA dd ? ends -struct LHEAD - next dd ? ;next object in list - prev dd ? ;prev object in list -ends - -struct MUTEX - wait_list LHEAD - count dd ? -ends - -struct RWSEM - wait_list LHEAD - count dd ? -ends - -struct FUTEX - list LHEAD - magic dd ? - handle dd ? - destroy dd ? - - wait_list LHEAD - pointer dd ? - flags dd ? -ends - - struct display_t x dd ? y dd ? @@ -545,6 +703,13 @@ struct display_t bytes_per_pixel dd ? ends +struct DISPMODE + width dw ? + height dw ? + bpp dw ? + freq dw ? +ends + struct PCIDEV bk dd ? @@ -557,6 +722,37 @@ struct PCIDEV owner dd ? ; pointer to SRV or 0 ends +struct IDE_DATA + ProgrammingInterface dd ? + Interrupt dw ? + RegsBaseAddres dw ? + BAR0_val dw ? + BAR1_val dw ? + BAR2_val dw ? + BAR3_val dw ? + dma_hdd_channel_1 db ? + dma_hdd_channel_2 db ? +ends + +struct IDE_CACHE + pointer dd ? + size dd ? ; not use + data_pointer dd ? + system_data_size dd ? ; not use + appl_data_size dd ? ; not use + system_data dd ? + appl_data dd ? + system_sad_size dd ? + appl_sad_size dd ? + search_start dd ? + appl_search_start dd ? +ends + +struct IDE_DEVICE + UDMA_possible_modes db ? + UDMA_set_mode db ? +ends + ; The following macro assume that we are on uniprocessor machine. ; Serious work is needed for multiprocessor machines. macro spin_lock_irqsave spinlock diff --git a/kernel/branches/Kolibri-acpi/core/dll.inc b/kernel/branches/Kolibri-acpi/core/dll.inc index e4f8eaa6f8..d5bc07d1f0 100644 --- a/kernel/branches/Kolibri-acpi/core/dll.inc +++ b/kernel/branches/Kolibri-acpi/core/dll.inc @@ -1392,22 +1392,4 @@ create_object: ret -align 4 -;struct futex* __fastcall create_futex(int *ptr) -create_futex: - push ecx - mov ecx, sizeof.FUTEX - call create_object - pop ecx - test eax, eax - jz .fail - - mov [eax+FUTEX.magic], 'FUTX' - mov [eax+FUTEX.destroy], 0 - mov [eax+FUTEX.pointer], ecx - lea ecx, [eax+FUTEX.wait_list] - list_init ecx - mov [eax+FUTEX.flags], 0 -.fail: - ret diff --git a/kernel/branches/Kolibri-acpi/core/memory.inc b/kernel/branches/Kolibri-acpi/core/memory.inc index 1ecf01f279..affa85eb30 100644 --- a/kernel/branches/Kolibri-acpi/core/memory.inc +++ b/kernel/branches/Kolibri-acpi/core/memory.inc @@ -1313,10 +1313,9 @@ f68: mov [esp+32], eax ret - +iglobal align 4 -f68call: ; keep this table closer to main code - +f68call: dd f68.11 ; init_heap dd f68.12 ; user_alloc dd f68.13 ; user_free @@ -1334,7 +1333,7 @@ f68call: ; keep this table closer to main code dd f68.25 ; unmask exception dd f68.26 ; user_unmap dd f68.27 ; load_file_umode - +endg align 4 proc load_pe_driver stdcall, file:dword, cmdline:dword @@ -1447,130 +1446,6 @@ proc print_mem ret endp -FUTEX_INIT equ 0 -FUTEX_WAIT equ 1 -FUTEX_WAKE equ 2 - -align 4 -f77call: - dd f77.futex_init ;0 - dd f77.futex_wait ;1 - dd f77.futex_wake ;2 - -align 4 -sys_synchronization: -f77: - cmp ebx, FUTEX_WAKE - ja .fail - - jmp dword [f77call+ebx*4] - -.fail: - mov [esp+32], dword 0 - ret -align 4 -.futex_init: - call create_futex - test eax, eax - jz @F - mov eax, [eax+FUTEX.handle] -@@: - mov [esp+32], eax - ret - -align 4 -;ecx futex handle -;edx new value -.futex_wait: - cmp ecx, 3 - jb .epicfail - cmp ecx, (PROC.pdt_0 - PROC.htab)/4 - jae .epicfail - - mov esi, [current_process] - mov edi, [esi+PROC.htab+ecx*4] - - cmp [edi+FUTEX.magic], 'FUTX' - jne .epicfail - cmp [edi+FUTEX.handle], ecx - jne .epicfail - - mov ecx, [edi+FUTEX.pointer] - - mov eax, edx - lock cmpxchg [ecx], edx ;wait until old_value == new_value - jz .wait_slow - - mov [esp+SYSCALL_STACK._eax], 0 - ret - -.wait_slow: - pushfd - cli - - sub esp, sizeof.MUTEX_WAITER - mov ebx, [TASK_BASE] - mov [ebx+TASKDATA.state], 1 - mov [esp+MUTEX_WAITER.task], ebx - lea esi, [edi+FUTEX.wait_list] - - list_add_tail esp, esi ;esp= new waiter, esi= list head - -.again: - call change_task - - lock cmpxchg [ecx], edx - jz .again - - list_del esp - add esp, sizeof.MUTEX_WAITER - - popfd - mov [esp+SYSCALL_STACK._eax], 0 - ret - -.epicfail: - mov [esp+SYSCALL_STACK._eax], -1 - ret - -align 4 -.futex_wake: - cmp ecx, 3 - jb .epicfail - cmp ecx, (PROC.pdt_0 - PROC.htab)/4 - jae .epicfail - - mov esi, [current_process] - mov edi, [esi+PROC.htab+ecx*4] - - cmp [edi+FUTEX.magic], 'FUTX' - jne .epicfail - cmp [edi+FUTEX.handle], ecx - jne .epicfail - - xor ecx, ecx - - pushfd - cli - - lea ebx, [edi+FUTEX.wait_list] - mov esi, [edi+FUTEX.wait_list.next] -@@: - cmp esi, ebx - je @F - - mov eax, [esi+MUTEX_WAITER.task] - mov [eax+TASKDATA.state], 0 - - mov esi, [esi+MUTEX_WAITER.list.next] - inc ecx - cmp ecx, edx - jb @B -@@: - popfd - mov [esp+SYSCALL_STACK._eax], ecx - ret - diff --git a/kernel/branches/Kolibri-acpi/core/sched.inc b/kernel/branches/Kolibri-acpi/core/sched.inc index d3fac9c0c0..e935993aa0 100644 --- a/kernel/branches/Kolibri-acpi/core/sched.inc +++ b/kernel/branches/Kolibri-acpi/core/sched.inc @@ -153,246 +153,6 @@ do_change_task: ;end. -struct MUTEX_WAITER - list LHEAD - task dd ? - type dd ? -ends - -RWSEM_WAITING_FOR_WRITE equ 0 -RWSEM_WAITING_FOR_READ equ 1 - -;void __fastcall mutex_init(struct mutex *lock) - -align 4 -mutex_init: - mov [ecx+MUTEX.wait_list.next], ecx - mov [ecx+MUTEX.wait_list.prev], ecx - mov [ecx+MUTEX.count], 1 - ret - -;void __fastcall mutex_lock(struct mutex *lock) - -align 4 -mutex_lock: - - dec [ecx+MUTEX.count] - jns .done - - pushfd - cli - - sub esp, sizeof.MUTEX_WAITER - - list_add_tail esp, ecx ;esp= new waiter, ecx= list head - - mov edx, [TASK_BASE] - mov [esp+MUTEX_WAITER.task], edx - -.forever: - - mov eax, -1 - xchg eax, [ecx+MUTEX.count] - dec eax - jz @F - - mov [edx+TASKDATA.state], 1 - call change_task - jmp .forever -@@: - mov eax, ecx - list_del esp - - cmp [eax+MUTEX.wait_list.next], eax - jne @F - - mov [eax+MUTEX.count], 0 -@@: - add esp, sizeof.MUTEX_WAITER - - popfd -.done: - ret - -;void __fastcall mutex_unlock(struct mutex *lock) - -align 4 -mutex_unlock: - - pushfd - cli - - mov eax, [ecx+MUTEX.wait_list.next] - cmp eax, ecx - mov [ecx+MUTEX.count], 1 - je @F - - mov eax, [eax+MUTEX_WAITER.task] - mov [eax+TASKDATA.state], 0 -@@: - popfd - ret - - -;void __fastcall init_rwsem(struct rw_semaphore *sem) - -align 4 -init_rwsem: - mov [ecx+RWSEM.wait_list.next], ecx - mov [ecx+RWSEM.wait_list.prev], ecx - mov [ecx+RWSEM.count], 0 - ret - -;void __fastcall down_read(struct rw_semaphore *sem) - -align 4 -down_read: - pushfd - cli - - mov eax, [ecx+RWSEM.count] - test eax, eax - js @F - - cmp ecx, [ecx+RWSEM.wait_list.next] - je .ok -@@: - sub esp, sizeof.MUTEX_WAITER - - mov eax, [TASK_BASE] - mov [esp+MUTEX_WAITER.task], eax - mov [esp+MUTEX_WAITER.type], RWSEM_WAITING_FOR_READ - mov [eax+TASKDATA.state], 1 - - list_add_tail esp, ecx ;esp= new waiter, ecx= list head - - call change_task - - add esp, sizeof.MUTEX_WAITER - popfd - ret -.ok: - inc eax - mov [ecx+RWSEM.count], eax - - popfd - ret - -;void __fastcall down_write(struct rw_semaphore *sem) - -align 4 -down_write: - pushfd - cli - sub esp, sizeof.MUTEX_WAITER - - mov edx, [TASK_BASE] - mov [esp+MUTEX_WAITER.task], edx - mov [esp+MUTEX_WAITER.type], RWSEM_WAITING_FOR_WRITE - mov [edx+TASKDATA.state], 1 - - list_add_tail esp, ecx ;esp= new waiter, ecx= list head - - xor eax, eax - not eax - -.forever: - test eax, [ecx+RWSEM.count] - jz @F - - mov [edx+TASKDATA.state], 1 - call change_task - jmp .forever -@@: - mov [ecx+RWSEM.count], eax - list_del esp - - add esp, sizeof.MUTEX_WAITER - popfd - ret - -;void __fastcall up_read(struct rw_semaphore *sem) - -align 4 -up_read: - pushfd - cli - - dec [ecx+RWSEM.count] - jnz @F - - mov eax, [ecx+RWSEM.wait_list.next] - cmp eax, ecx - je @F - - mov eax, [eax+MUTEX_WAITER.task] - mov [eax+TASKDATA.state], 0 -@@: - popfd - ret - -;void __fastcall up_write(struct rw_semaphore *sem) - -align 4 -up_write: - - pushfd - cli - - mov eax, [ecx+RWSEM.wait_list.next] - mov [ecx+RWSEM.count], 0 - - cmp ecx, eax - je .done - - mov edx, [eax+MUTEX_WAITER.type] - test edx, edx - jnz .wake - - mov eax, [eax+MUTEX_WAITER.task] - mov [eax+TASKDATA.state], 0 -.done: - popfd - ret - -.wake: - push ebx - push esi - push edi - - xor esi, esi - mov edi, ecx - -.wake_list: - - mov ebx, [eax+MUTEX_WAITER.list.next] - list_del eax - mov edx, [eax+MUTEX_WAITER.task] - mov [edx+TASKDATA.state], 0 - inc esi - cmp edi, ebx - je .wake_done - - mov ecx, [ebx+MUTEX_WAITER.type] - test ecx, ecx - jz .wake_done - - mov eax, ebx - jmp .wake_list - -.wake_done: - add [edi+RWSEM.count], esi - - pop edi - pop esi - pop ebx - popfd - ret - - -purge MUTEX_WAITER -purge RWSEM_WAITING_FOR_WRITE -purge RWSEM_WAITING_FOR_READ MAX_PRIORITY = 0 ; highest, used for kernel tasks diff --git a/kernel/branches/Kolibri-acpi/core/sync.inc b/kernel/branches/Kolibri-acpi/core/sync.inc index d2b5721009..c5906efdda 100644 --- a/kernel/branches/Kolibri-acpi/core/sync.inc +++ b/kernel/branches/Kolibri-acpi/core/sync.inc @@ -5,10 +5,394 @@ ;; ;; ;; Synhronization for MenuetOS. ;; ;; Author: Halyavin Andrey, halyavin@land.ru ;; +;; ;; +;; ;; +;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $Revision$ +align 4 +;struct futex* __fastcall create_futex(int *ptr) +create_futex: + push ecx + mov ecx, sizeof.FUTEX + call create_object + pop ecx + test eax, eax + jz .fail + + mov [eax+FUTEX.magic], 'FUTX' + mov [eax+FUTEX.destroy], 0 + mov [eax+FUTEX.pointer], ecx + lea ecx, [eax+FUTEX.wait_list] + list_init ecx + mov [eax+FUTEX.flags], 0 +.fail: + ret + +iglobal +align 4 +f77call: + dd f77.futex_init ;0 + dd f77.futex_wait ;1 + dd f77.futex_wake ;2 +.end: +endg + +align 4 +sys_synchronization: +f77: + cmp ebx, (f77call.end-f77call)/4 + jae .fail + + jmp dword [f77call+ebx*4] + +.fail: + mov [esp+SYSCALL_STACK._eax], -1 + ret + + +align 4 +.futex_init: + call create_futex + test eax, eax + jz @F + mov eax, [eax+FUTEX.handle] +@@: + mov [esp+SYSCALL_STACK._eax], eax + ret + +align 4 +;ecx futex handle +;edx control value +.futex_wait: + cmp ecx, 3 + jb .epicfail + cmp ecx, (PROC.pdt_0 - PROC.htab)/4 + jae .epicfail + + mov esi, [current_process] + mov edi, [esi+PROC.htab+ecx*4] + + cmp [edi+FUTEX.magic], 'FUTX' + jne .epicfail + cmp [edi+FUTEX.handle], ecx + jne .epicfail + + mov ecx, [edi+FUTEX.pointer] + + mov eax, edx + lock cmpxchg [ecx], edx ;wait until old_value == new_value + jz .wait_slow + + mov [esp+SYSCALL_STACK._eax], 0 + ret + +.wait_slow: + pushfd + cli + + sub esp, sizeof.MUTEX_WAITER + mov ebx, [TASK_BASE] + mov [ebx+TASKDATA.state], 1 + mov [esp+MUTEX_WAITER.task], ebx + lea esi, [edi+FUTEX.wait_list] + + list_add_tail esp, esi ;esp= new waiter, esi= list head + +.again: + call change_task + + lock cmpxchg [ecx], edx + jz .again + + list_del esp + add esp, sizeof.MUTEX_WAITER + + popfd + mov [esp+SYSCALL_STACK._eax], 0 + ret + +.epicfail: + mov [esp+SYSCALL_STACK._eax], -1 + ret + +align 4 +;ecx futex handle +;edx threads count +.futex_wake: + cmp ecx, 3 + jb .epicfail + cmp ecx, (PROC.pdt_0 - PROC.htab)/4 + jae .epicfail + + mov esi, [current_process] + mov edi, [esi+PROC.htab+ecx*4] + + cmp [edi+FUTEX.magic], 'FUTX' + jne .epicfail + cmp [edi+FUTEX.handle], ecx + jne .epicfail + + xor ecx, ecx + + pushfd + cli + + lea ebx, [edi+FUTEX.wait_list] + mov esi, [edi+FUTEX.wait_list.next] +@@: + cmp esi, ebx + je @F + + mov eax, [esi+MUTEX_WAITER.task] + mov [eax+TASKDATA.state], 0 + + mov esi, [esi+MUTEX_WAITER.list.next] + inc ecx + cmp ecx, edx + jb @B +@@: + popfd + mov [esp+SYSCALL_STACK._eax], ecx + ret + +RWSEM_WAITING_FOR_WRITE equ 0 +RWSEM_WAITING_FOR_READ equ 1 + +;void __fastcall mutex_init(struct mutex *lock) + +align 4 +mutex_init: + mov [ecx+MUTEX.wait_list.next], ecx + mov [ecx+MUTEX.wait_list.prev], ecx + mov [ecx+MUTEX.count], 1 + ret + +;void __fastcall mutex_lock(struct mutex *lock) + +align 4 +mutex_lock: + + dec [ecx+MUTEX.count] + jns .done + + pushfd + cli + + sub esp, sizeof.MUTEX_WAITER + + list_add_tail esp, ecx ;esp= new waiter, ecx= list head + + mov edx, [TASK_BASE] + mov [esp+MUTEX_WAITER.task], edx + +.forever: + + mov eax, -1 + xchg eax, [ecx+MUTEX.count] + dec eax + jz @F + + mov [edx+TASKDATA.state], 1 + call change_task + jmp .forever +@@: + mov eax, ecx + list_del esp + + cmp [eax+MUTEX.wait_list.next], eax + jne @F + + mov [eax+MUTEX.count], 0 +@@: + add esp, sizeof.MUTEX_WAITER + + popfd +.done: + ret + +;void __fastcall mutex_unlock(struct mutex *lock) + +align 4 +mutex_unlock: + + pushfd + cli + + mov eax, [ecx+MUTEX.wait_list.next] + cmp eax, ecx + mov [ecx+MUTEX.count], 1 + je @F + + mov eax, [eax+MUTEX_WAITER.task] + mov [eax+TASKDATA.state], 0 +@@: + popfd + ret + + +;void __fastcall init_rwsem(struct rw_semaphore *sem) + +align 4 +init_rwsem: + mov [ecx+RWSEM.wait_list.next], ecx + mov [ecx+RWSEM.wait_list.prev], ecx + mov [ecx+RWSEM.count], 0 + ret + +;void __fastcall down_read(struct rw_semaphore *sem) + +align 4 +down_read: + pushfd + cli + + mov eax, [ecx+RWSEM.count] + test eax, eax + js @F + + cmp ecx, [ecx+RWSEM.wait_list.next] + je .ok +@@: + sub esp, sizeof.MUTEX_WAITER + + mov eax, [TASK_BASE] + mov [esp+MUTEX_WAITER.task], eax + mov [esp+MUTEX_WAITER.type], RWSEM_WAITING_FOR_READ + mov [eax+TASKDATA.state], 1 + + list_add_tail esp, ecx ;esp= new waiter, ecx= list head + + call change_task + + add esp, sizeof.MUTEX_WAITER + popfd + ret +.ok: + inc eax + mov [ecx+RWSEM.count], eax + + popfd + ret + +;void __fastcall down_write(struct rw_semaphore *sem) + +align 4 +down_write: + pushfd + cli + sub esp, sizeof.MUTEX_WAITER + + mov edx, [TASK_BASE] + mov [esp+MUTEX_WAITER.task], edx + mov [esp+MUTEX_WAITER.type], RWSEM_WAITING_FOR_WRITE + mov [edx+TASKDATA.state], 1 + + list_add_tail esp, ecx ;esp= new waiter, ecx= list head + + xor eax, eax + not eax + +.forever: + test eax, [ecx+RWSEM.count] + jz @F + + mov [edx+TASKDATA.state], 1 + call change_task + jmp .forever +@@: + mov [ecx+RWSEM.count], eax + list_del esp + + add esp, sizeof.MUTEX_WAITER + popfd + ret + +;void __fastcall up_read(struct rw_semaphore *sem) + +align 4 +up_read: + pushfd + cli + + dec [ecx+RWSEM.count] + jnz @F + + mov eax, [ecx+RWSEM.wait_list.next] + cmp eax, ecx + je @F + + mov eax, [eax+MUTEX_WAITER.task] + mov [eax+TASKDATA.state], 0 +@@: + popfd + ret + +;void __fastcall up_write(struct rw_semaphore *sem) + +align 4 +up_write: + + pushfd + cli + + mov eax, [ecx+RWSEM.wait_list.next] + mov [ecx+RWSEM.count], 0 + + cmp ecx, eax + je .done + + mov edx, [eax+MUTEX_WAITER.type] + test edx, edx + jnz .wake + + mov eax, [eax+MUTEX_WAITER.task] + mov [eax+TASKDATA.state], 0 +.done: + popfd + ret + +.wake: + push ebx + push esi + push edi + + xor esi, esi + mov edi, ecx + +.wake_list: + + mov ebx, [eax+MUTEX_WAITER.list.next] + list_del eax + mov edx, [eax+MUTEX_WAITER.task] + mov [edx+TASKDATA.state], 0 + inc esi + cmp edi, ebx + je .wake_done + + mov ecx, [ebx+MUTEX_WAITER.type] + test ecx, ecx + jz .wake_done + + mov eax, ebx + jmp .wake_list + +.wake_done: + add [edi+RWSEM.count], esi + + pop edi + pop esi + pop ebx + popfd + ret + + +purge MUTEX_WAITER +purge RWSEM_WAITING_FOR_WRITE +purge RWSEM_WAITING_FOR_READ + if ~defined sync_inc sync_inc_fix: diff --git a/kernel/branches/Kolibri-acpi/kernel32.inc b/kernel/branches/Kolibri-acpi/kernel32.inc index 92956ae758..8dbcb02e2e 100644 --- a/kernel/branches/Kolibri-acpi/kernel32.inc +++ b/kernel/branches/Kolibri-acpi/kernel32.inc @@ -5,7 +5,7 @@ ;; ;; ;; KERNEL32.INC ;; ;; ;; -;; Included 32 bit kernel files for MenuetOS ;; +;; Included 32 bit kernel files for KolibriOS ;; ;; ;; ;; This file is kept separate as it will be easier to ;; ;; maintain and compile with an automated SETUP program ;; @@ -15,206 +15,6 @@ $Revision$ -struct POINT - x dd ? - y dd ? -ends - -struct RECT - left dd ? - top dd ? - right dd ? - bottom dd ? -ends - -struct BOX - left dd ? - top dd ? - width dd ? - height dd ? -ends - -struct DISPMODE - width dw ? - height dw ? - bpp dw ? - freq dw ? -ends - -; constants definition -WSTATE_NORMAL = 00000000b -WSTATE_MAXIMIZED = 00000001b -WSTATE_MINIMIZED = 00000010b -WSTATE_ROLLEDUP = 00000100b - -WSTATE_REDRAW = 00000001b -WSTATE_WNDDRAWN = 00000010b - -WSTYLE_HASCAPTION = 00010000b -WSTYLE_CLIENTRELATIVE = 00100000b - -struct TASKDATA - event_mask dd ? - pid dd ? - dw ? - state db ? - db ? - dw ? - wnd_number db ? - db ? - mem_start dd ? - counter_sum dd ? - counter_add dd ? - cpu_usage dd ? -ends - -TSTATE_RUNNING = 0 -TSTATE_RUN_SUSPENDED = 1 -TSTATE_WAIT_SUSPENDED = 2 -TSTATE_ZOMBIE = 3 -TSTATE_TERMINATING = 4 -TSTATE_WAITING = 5 -TSTATE_FREE = 9 - -; structures definition -struct WDATA - box BOX - cl_workarea dd ? - cl_titlebar dd ? - cl_frames dd ? - reserved db ? - fl_wstate db ? - fl_wdrawn db ? - fl_redraw db ? -ends - -label WDATA.fl_wstyle byte at WDATA.cl_workarea + 3 - -struct DBG_REGS - dr0 dd ? - dr1 dd ? - dr2 dd ? - dr3 dd ? - dr7 dd ? -ends - -struct PROC - list LHEAD - thr_list LHEAD - heap_lock MUTEX - heap_base rd 1 - heap_top rd 1 - mem_used rd 1 - dlls_list_ptr rd 1 - pdt_0_phys rd 1 - pdt_1_phys rd 1 - io_map_0 rd 1 - io_map_1 rd 1 - - ht_lock rd 1 - ht_free rd 1 ;htab[0] stdin - ht_next rd 1 ;htab[1] stdout - htab rd (4096-$)/4 ;htab[2] stderr - pdt_0 rd 1024 -ends - -struct APPDATA - app_name rb 11 - rb 5 - - list LHEAD ;+16 - process dd ? ;+24 - fpu_state dd ? ;+28 - exc_handler dd ? ;+32 - except_mask dd ? ;+36 - pl0_stack dd ? ;+40 - cursor dd ? ;+44 - fd_ev dd ? ;+48 - bk_ev dd ? ;+52 - fd_obj dd ? ;+56 - bk_obj dd ? ;+60 - saved_esp dd ? ;+64 - io_map rd 2 ;+68 - dbg_state dd ? ;+76 - cur_dir dd ? ;+80 - wait_timeout dd ? ;+84 - saved_esp0 dd ? ;+88 - wait_begin dd ? ;+92 +++ - wait_test dd ? ;+96 +++ - wait_param dd ? ;+100 +++ - tls_base dd ? ;+104 - dd ? ;+108 - event_filter dd ? ;+112 - draw_bgr_x dd ? ;+116 - draw_bgr_y dd ? ;+120 - dd ? ;+124 - - wnd_shape dd ? ;+128 - wnd_shape_scale dd ? ;+132 - dd ? ;+136 - 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 - rb 3 - 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 - -ends - -struct IDE_DATA - ProgrammingInterface dd ? - Interrupt dw ? - RegsBaseAddres dw ? - BAR0_val dw ? - BAR1_val dw ? - BAR2_val dw ? - BAR3_val dw ? - dma_hdd_channel_1 db ? - dma_hdd_channel_2 db ? -ends - -struct IDE_CACHE - pointer dd ? - size dd ? ; not use - data_pointer dd ? - system_data_size dd ? ; not use - appl_data_size dd ? ; not use - system_data dd ? - appl_data dd ? - system_sad_size dd ? - appl_sad_size dd ? - search_start dd ? - appl_search_start dd ? -ends - -struct IDE_DEVICE - UDMA_possible_modes db ? - UDMA_set_mode db ? -ends - -struct SYSCALL_STACK - _eip dd ? - _edi dd ? ; +4 - _esi dd ? ; +8 - _ebp dd ? ; +12 - _esp dd ? ; +16 - _ebx dd ? ; +20 - _edx dd ? ; +24 - _ecx dd ? ; +28 - _eax dd ? ; +32 -ends - - ; Core functions include "core/sync.inc" ; macros for synhronization objects include "core/sys32.inc" ; process management