linux-like kernel mutexes

git-svn-id: svn://kolibrios.org@1434 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2010-03-17 17:42:57 +00:00
parent 47a917da42
commit 2e1f635004
5 changed files with 143 additions and 2 deletions

View File

@ -22,6 +22,10 @@
.global _MapIoMem
.global _MutexInit
.global _MutexLock
.global _MutexUnlock
.global _PciApi
.global _PciRead16
.global _PciRead32
@ -32,6 +36,7 @@
.global _RegService
.global _SetMouseData
.global _SetScreen
.global _SysMsgBoardStr
@ -55,6 +60,10 @@
.def _MapIoMem; .scl 2; .type 32; .endef
.def _MutexInit; .scl 2; .type 32; .endef
.def _MutexLock; .scl 2; .type 32; .endef
.def _MutexUnlock; .scl 2; .type 32; .endef
.def _PciApi; .scl 2; .type 32; .endef
.def _PciRead16; .scl 2; .type 32; .endef
.def _PciRead32; .scl 2; .type 32; .endef
@ -66,6 +75,7 @@
.def _RegService; .scl 2; .type 32; .endef
.def _SetScreen; .scl 2; .type 32; .endef
.def _SetMouseData; .scl 2; .type 32; .endef
.def _SysMsgBoardStr; .scl 2; .type 32; .endef
@ -89,6 +99,10 @@ _KernelFree:
_MapIoMem:
_MutexInit:
_MutexLock:
_MutexUnlock:
_PciApi:
_PciRead16:
_PciRead32:
@ -99,6 +113,7 @@ _PciWrite8:
_RegService:
_SetMouseData:
_SetScreen:
_SysMsgBoardStr:
ret
@ -125,6 +140,10 @@ _SysMsgBoardStr:
.ascii " -export:MapIoMem" # stdcall
.ascii " -export:MutexInit" # fastcall
.ascii " -export:MutexLock" # fastcall
.ascii " -export:MutexUnlock" # fastcall
.ascii " -export:PciApi" #
.ascii " -export:PciRead16" # stdcall
.ascii " -export:PciRead32" # stdcall
@ -135,6 +154,7 @@ _SysMsgBoardStr:
.ascii " -export:RegService" # stdcall
.ascii " -export:SetMouseData" # stdcall
.ascii " -export:SetScreen" # stdcall
.ascii " -export:SysMsgBoardStr" # stdcall

View File

@ -26,6 +26,8 @@ u32_t drvEntry(int, char *)__asm__("_drvEntry");
///////////////////////////////////////////////////////////////////////////////
#define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
#define FASTCALL __attribute__ ((fastcall)) __attribute__ ((dllimport))
#define IMPORT __attribute__ ((dllimport))
///////////////////////////////////////////////////////////////////////////////
@ -61,6 +63,9 @@ u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
int STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
void FASTCALL MutexInit(struct mutex*)__asm__("MutexInit");
void FASTCALL MutexLock(struct mutex*)__asm__("MutexLock");
void FASTCALL MutexUnlock(struct mutex*)__asm__("MutexUnlock");
///////////////////////////////////////////////////////////////////////////////

View File

@ -293,6 +293,10 @@ __exports:
free, 'Kfree', \
map_io_mem, 'MapIoMem', \ ; stdcall
get_pg_addr, 'GetPgAddr', \ ; eax
\
mutex_init, 'MutexInit', \ ; gcc fastcall
mutex_lock, 'MutexLock', \ ; gcc fastcall
mutex_unlock, 'MutexUnlock', \ ; gcc fastcall
\
get_display, 'GetDisplay', \
set_screen, 'SetScreen', \

View File

@ -217,7 +217,108 @@ do_change_task:
@@: ret
;end.
struc MUTEX_WAITER
{
.next rd 1
.prev rd 1
.task rd 1
.sizeof:
};
virtual at 0
MUTEX_WAITER MUTEX_WAITER
end virtual
;void __fastcall mutex_init(struct mutex *lock)
align 4
mutex_init:
lea eax, [ecx+MUTEX.next]
mov [ecx+MUTEX.count],1
mov [ecx+MUTEX.next], eax
mov [ecx+MUTEX.prev], eax
ret
;void __fastcall mutex_lock(struct mutex *lock)
align 4
mutex_lock:
dec [ecx+MUTEX.count]
jns .done
pushfd
cli
push esi
sub esp, MUTEX_WAITER.sizeof
mov eax, [ecx+MUTEX.prev]
lea esi, [ecx+MUTEX.next]
mov [ecx+MUTEX.prev], esp
mov [esp+MUTEX_WAITER.next], esi
mov [esp+MUTEX_WAITER.prev], eax
mov [eax], esp
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 edx, [esp+MUTEX_WAITER.next]
mov eax, [esp+MUTEX_WAITER.prev]
mov [eax+MUTEX_WAITER.next], edx
cmp [ecx+MUTEX.next], esi
mov [edx+MUTEX_WAITER.prev], eax
jne @F
mov [ecx+MUTEX.count], 0
@@:
add esp, MUTEX_WAITER.sizeof
pop esi
popfd
.done:
ret
;void __fastcall mutex_unlock(struct mutex *lock)
align 4
mutex_unlock:
pushfd
cli
lea eax, [ecx+MUTEX.next]
cmp eax, [ecx+MUTEX.next]
mov [ecx+MUTEX.count], 1
je @F
mov eax, [eax+MUTEX_WAITER.task]
mov [eax+TASKDATA.state], 0
@@:
popfd
ret
purge MUTEX_WAITER
if 0
struc TIMER
{
.next dd ?

View File

@ -194,6 +194,17 @@ end virtual
;// mike.dld, 2006-29-01 ]
struc MUTEX
{
.count rd 1
.next rd 1
.prev rd 1
}
virtual at 0
MUTEX MUTEX
end virtual
; Core functions
include "core/sync.inc" ; macros for synhronization objects