From 8ef75d449668b08b17f1dc7b5c12104230c11ebb Mon Sep 17 00:00:00 2001 From: "Rustem Gimadutdinov (rgimad)" Date: Fri, 18 Jun 2021 08:26:02 +0000 Subject: [PATCH] [KERNEL] #4 Preparing to merge legacy TASKDATA into APPDATA: - use thread state constants instead of hardcoded values - other small style fixes git-svn-id: svn://kolibrios.org@8874 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/const.inc | 24 ++++++++++++++---------- kernel/trunk/core/memory.inc | 2 +- kernel/trunk/core/sched.inc | 2 +- kernel/trunk/core/sync.inc | 16 ++++++++-------- kernel/trunk/core/sys32.inc | 10 +++++----- kernel/trunk/core/taskman.inc | 9 ++++----- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/kernel/trunk/const.inc b/kernel/trunk/const.inc index d9138d178a..3636518ae3 100644 --- a/kernel/trunk/const.inc +++ b/kernel/trunk/const.inc @@ -479,6 +479,8 @@ struct BOX height dd ? ends +; Fields, marked as R now not used, but will be used soon, +; when legacy TASKDATA structure will be deleted struct APPDATA app_name rb 11 rb 5 @@ -504,21 +506,21 @@ struct APPDATA wait_test dd ? ;+96 +++ wait_param dd ? ;+100 +++ tls_base dd ? ;+104 - event_mask dd ? ;+108 ; stores event types allowed for task - tid dd ? ;+112 ; thread id + event_mask dd ? ;+108 ; R stores event types allowed for task + tid dd ? ;+112 ; R thread id draw_bgr_x dd ? ;+116 draw_bgr_y dd ? ;+120 - state db ? ;+124 ; thread state + state db ? ;+124 ; R thread state db ? ;+125 dw ? ;+126 wnd_shape dd ? ;+128 wnd_shape_scale dd ? ;+132 - mem_start dd ? ;+136 ;; - counter_sum dd ? ;+140 ;; + mem_start dd ? ;+136 ; R + counter_sum dd ? ;+140 ; R saved_box BOX ;+144 ipc_start dd ? ;+160 ipc_size dd ? ;+164 - occurred_events dd ? ;+168 ; mask which accumulates occurred events + occurred_events dd ? ;+168 ; mask which accumulates occurred events debugger_slot dd ? ;+172 terminate_protection dd ? ;+176 keyboard_mode db ? ;+180 @@ -531,8 +533,8 @@ struct APPDATA wnd_clientbox BOX ;+216 priority dd ? ;+232 in_schedule LHEAD ;+236 - counter_add dd ? ;+244 ;; - cpu_usage dd ? ;+248 ;; + counter_add dd ? ;+244 ; R + cpu_usage dd ? ;+248 ; R dd ? ;+252 ends @@ -557,6 +559,7 @@ struct TASKDATA cpu_usage dd ? ;+28 ends +; Thread states: TSTATE_RUNNING = 0 TSTATE_RUN_SUSPENDED = 1 TSTATE_WAIT_SUSPENDED = 2 @@ -565,7 +568,7 @@ TSTATE_TERMINATING = 4 TSTATE_WAITING = 5 TSTATE_FREE = 9 -; constants definition +; Window constants: WSTATE_NORMAL = 00000000b WSTATE_MAXIMIZED = 00000001b WSTATE_MINIMIZED = 00000010b @@ -581,7 +584,8 @@ ZPOS_DESKTOP = -2 ZPOS_ALWAYS_BACK = -1 ZPOS_NORMAL = 0 ZPOS_ALWAYS_TOP = 1 ;ZPOS_ALWAYS_TOP is always last and has max number! -; structures definition + +; Window structure: struct WDATA box BOX cl_workarea dd ? diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 7f156c9a8b..405bb69ac9 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -1008,7 +1008,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword mov dword [edi+4], ebx mov eax, [TASK_BASE] - mov eax, [eax+0x04] ;eax - our PID + mov eax, [eax+TASKDATA.pid] ;eax - our PID add edi, edx mov [edi], eax mov ecx, [msg_size] diff --git a/kernel/trunk/core/sched.inc b/kernel/trunk/core/sched.inc index a613bee6c7..2b1d94b05e 100644 --- a/kernel/trunk/core/sched.inc +++ b/kernel/trunk/core/sched.inc @@ -309,7 +309,7 @@ proc find_next_task xor eax, eax @@: mov [ebx+APPDATA.wait_param], eax ; retval for wait - mov [edi+TASKDATA.state], 0 + mov [edi+TASKDATA.state], TSTATE_RUNNING .task_found: mov [scheduler_current+ecx*4], ebx ; If we have selected a thread with higher priority diff --git a/kernel/trunk/core/sync.inc b/kernel/trunk/core/sync.inc index ec48cc3d86..a6c41f0397 100644 --- a/kernel/trunk/core/sync.inc +++ b/kernel/trunk/core/sync.inc @@ -48,7 +48,7 @@ mutex_lock: dec eax jz @F - mov [edx+TASKDATA.state], 1 + mov [edx+TASKDATA.state], TSTATE_RUN_SUSPENDED call change_task jmp .forever @@: @@ -80,7 +80,7 @@ mutex_unlock: je @F mov eax, [eax+MUTEX_WAITER.task] - mov [eax+TASKDATA.state], 0 + mov [eax+TASKDATA.state], TSTATE_RUNNING @@: popfd ret @@ -114,7 +114,7 @@ down_read: mov eax, [TASK_BASE] mov [esp+MUTEX_WAITER.task], eax mov [esp+MUTEX_WAITER.type], RWSEM_WAITING_FOR_READ - mov [eax+TASKDATA.state], 1 + mov [eax+TASKDATA.state], TSTATE_RUN_SUSPENDED list_add_tail esp, ecx ;esp= new waiter, ecx= list head @@ -141,7 +141,7 @@ down_write: mov edx, [TASK_BASE] mov [esp+MUTEX_WAITER.task], edx mov [esp+MUTEX_WAITER.type], RWSEM_WAITING_FOR_WRITE - mov [edx+TASKDATA.state], 1 + mov [edx+TASKDATA.state], TSTATE_RUN_SUSPENDED list_add_tail esp, ecx ;esp= new waiter, ecx= list head @@ -152,7 +152,7 @@ down_write: test eax, [ecx+RWSEM.count] jz @F - mov [edx+TASKDATA.state], 1 + mov [edx+TASKDATA.state], TSTATE_RUN_SUSPENDED call change_task jmp .forever @@: @@ -178,7 +178,7 @@ up_read: je @F mov eax, [eax+MUTEX_WAITER.task] - mov [eax+TASKDATA.state], 0 + mov [eax+TASKDATA.state], TSTATE_RUNNING @@: popfd ret @@ -202,7 +202,7 @@ up_write: jnz .wake mov eax, [eax+MUTEX_WAITER.task] - mov [eax+TASKDATA.state], 0 + mov [eax+TASKDATA.state], TSTATE_RUNNING .done: popfd ret @@ -220,7 +220,7 @@ up_write: mov ebx, [eax+MUTEX_WAITER.list.next] list_del eax mov edx, [eax+MUTEX_WAITER.task] - mov [edx+TASKDATA.state], 0 + mov [edx+TASKDATA.state], TSTATE_RUNNING inc esi cmp edi, ebx je .wake_done diff --git a/kernel/trunk/core/sys32.inc b/kernel/trunk/core/sys32.inc index d8e36810f9..10249fa0d2 100644 --- a/kernel/trunk/core/sys32.inc +++ b/kernel/trunk/core/sys32.inc @@ -152,7 +152,7 @@ exc_c: ; exceptions (all but 7th - #NM) ; not debuggee => say error and terminate call show_error_parameters sti - mov [edx + TASKDATA.state], byte 4 ; terminate + mov [edx + TASKDATA.state], TSTATE_TERMINATING ; terminate call wakeup_osloop call change_task ; If we're here, then the main OS thread has crashed before initializing IDLE thread. @@ -187,7 +187,7 @@ exc_c: ; exceptions (all but 7th - #NM) call debugger_notify ;; only ONE using, inline ??? SEE: core/debug.inc add esp, 12 mov edx, [TASK_BASE] - mov byte [edx+TASKDATA.state], 1 ; suspended + mov [edx+TASKDATA.state], TSTATE_RUN_SUSPENDED ; suspended call change_task ; SEE: core/shed.inc restore_ring3_context iretd @@ -419,7 +419,7 @@ destroy_thread: jnz @F pop esi shl esi, BSF sizeof.TASKDATA - mov [TASK_TABLE+esi+TASKDATA.state], 9 + mov [TASK_TABLE+esi+TASKDATA.state], TSTATE_FREE ret @@: push edx ;save .process @@ -639,7 +639,7 @@ destroy_thread: lea esi, [WIN_POS+eax*2] movzx edi, word [esi] ; edi = process shl edi, BSF sizeof.TASKDATA - cmp [TASK_TABLE + edi + TASKDATA.state], byte 9 ; skip dead slots + cmp [TASK_TABLE + edi + TASKDATA.state], TSTATE_FREE ; skip free slots je .check_next_window add edi, window_data ; \begin{diamond}[19.09.2006] @@ -714,7 +714,7 @@ destroy_thread: popa mov edi, esi ; do not run this process slot shl edi, BSF sizeof.TASKDATA - mov [edi+TASK_TABLE + TASKDATA.state], byte 9 + mov [edi+TASK_TABLE + TASKDATA.state], TSTATE_FREE ; debugger test - terminate all debuggees mov eax, 2 mov ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot diff --git a/kernel/trunk/core/taskman.inc b/kernel/trunk/core/taskman.inc index 45eede3310..7d9385e41c 100644 --- a/kernel/trunk/core/taskman.inc +++ b/kernel/trunk/core/taskman.inc @@ -493,13 +493,12 @@ pid_to_slot: .loop: ;ecx = offset of current process info entry ;ebx = maximum permitted offset - ; state 9 means "not used" - cmp byte [TASK_TABLE+ecx+TASKDATA.state], TSTATE_FREE + cmp [TASK_TABLE+ecx+TASKDATA.state], TSTATE_FREE jz .endloop ;skip empty slots cmp [TASK_TABLE+ecx+TASKDATA.pid], eax;check PID jz .pid_found .endloop: - add ecx, 32 + add ecx, sizeof.TASKDATA cmp ecx, ebx jle .loop @@ -895,7 +894,7 @@ common_app_entry: cmp [ebx+APPDATA.debugger_slot], 0 je .exit mov eax, [TASK_BASE] - mov [eax+TASKDATA.state], 1 + mov [eax+TASKDATA.state], TSTATE_RUN_SUSPENDED call change_task .exit: popad @@ -987,7 +986,7 @@ proc set_app_params stdcall,slot:dword, params:dword, flags:dword inc dword [process_number] mov eax, [process_number] - mov [ebx+4], eax ;set PID + mov [ebx+TASKDATA.pid], eax ;set PID ;set draw data to full screen xor eax, eax