diff --git a/drivers/ddk/core.S b/drivers/ddk/core.S index 4f5b143286..3c5bb03dad 100644 --- a/drivers/ddk/core.S +++ b/drivers/ddk/core.S @@ -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 diff --git a/drivers/include/syscall.h b/drivers/include/syscall.h index c935795ad8..fac26a727f 100644 --- a/drivers/include/syscall.h +++ b/drivers/include/syscall.h @@ -25,8 +25,10 @@ u32_t drvEntry(int, char *)__asm__("_drvEntry"); /////////////////////////////////////////////////////////////////////////////// -#define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport)) -#define IMPORT __attribute__ ((dllimport)) +#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"); /////////////////////////////////////////////////////////////////////////////// diff --git a/kernel/trunk/core/peload.inc b/kernel/trunk/core/peload.inc index d85ec4d887..d1d40e6c0c 100644 --- a/kernel/trunk/core/peload.inc +++ b/kernel/trunk/core/peload.inc @@ -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', \ diff --git a/kernel/trunk/core/sched.inc b/kernel/trunk/core/sched.inc index c77f7e1b16..00b4551bca 100644 --- a/kernel/trunk/core/sched.inc +++ b/kernel/trunk/core/sched.inc @@ -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 ? diff --git a/kernel/trunk/kernel32.inc b/kernel/trunk/kernel32.inc index 071f655345..b0707c178c 100644 --- a/kernel/trunk/kernel32.inc +++ b/kernel/trunk/kernel32.inc @@ -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