diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2010-01-10 04:07:19 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2010-01-10 04:07:19 +0000 |
commit | 228ad5a9f1a5db64df3c670fecd1b37f469c6ccb (patch) | |
tree | a432c9aa01d1695f4e030ffbcef8f4c9d9e418fe /sys | |
parent | 3b19757bd89e2d656d732c7d9b54e46472ea7f98 (diff) |
GCC doesn't respect the aligned attribute for automatic variables. So
having mutexes on the stack, like dlg@ added recently to the scsi code,
doesn't work on hppa. So instead of relying on mutexes being properly
alligned just reserve 4 words and use the one that has the proper alignment.
ok miod@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/hppa/hppa/mutex.c | 26 | ||||
-rw-r--r-- | sys/arch/hppa/include/mutex.h | 16 |
2 files changed, 22 insertions, 20 deletions
diff --git a/sys/arch/hppa/hppa/mutex.c b/sys/arch/hppa/hppa/mutex.c index 2378f832add..be337c0c1b5 100644 --- a/sys/arch/hppa/hppa/mutex.c +++ b/sys/arch/hppa/hppa/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.6 2009/12/29 15:01:59 jsing Exp $ */ +/* $OpenBSD: mutex.c,v 1.7 2010/01/10 04:07:18 kettenis Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -36,29 +36,26 @@ static inline int try_lock(struct mutex *mtx) { + volatile int *lock = (int *)(((vaddr_t)mtx->mtx_lock + 0xf) & ~0xf); volatile register_t ret = 0; -#ifdef DIAGNOSTIC - if (((u_int32_t)(&mtx->mtx_lock) & 0xf) != 0) { - db_printf("mtx_lock is not 16-byte aligned\n"); - Debugger(); - } -#endif - /* Note: lock must be 16-byte aligned. */ asm volatile ( "ldcws 0(%2), %0" - : "=&r" (ret), "+m" (mtx->mtx_lock) - : "r" (&mtx->mtx_lock) + : "=&r" (ret), "+m" (lock) + : "r" (lock) ); - + return ret; } void mtx_init(struct mutex *mtx, int wantipl) { - mtx->mtx_lock = MUTEX_UNLOCKED; + mtx->mtx_lock[0] = 1; + mtx->mtx_lock[1] = 1; + mtx->mtx_lock[2] = 1; + mtx->mtx_lock[3] = 1; mtx->mtx_wantipl = wantipl; mtx->mtx_oldipl = IPL_NONE; } @@ -105,7 +102,10 @@ void mtx_leave(struct mutex *mtx) { MUTEX_ASSERT_LOCKED(mtx); - mtx->mtx_lock = MUTEX_UNLOCKED; + mtx->mtx_lock[0] = 1; + mtx->mtx_lock[1] = 1; + mtx->mtx_lock[2] = 1; + mtx->mtx_lock[3] = 1; if (mtx->mtx_wantipl != IPL_NONE) splx(mtx->mtx_oldipl); mtx->mtx_owner = NULL; diff --git a/sys/arch/hppa/include/mutex.h b/sys/arch/hppa/include/mutex.h index 6bea7b9b110..f5b9d51327c 100644 --- a/sys/arch/hppa/include/mutex.h +++ b/sys/arch/hppa/include/mutex.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.h,v 1.3 2009/12/29 15:01:59 jsing Exp $ */ +/* $OpenBSD: mutex.h,v 1.4 2010/01/10 04:07:18 kettenis Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -28,16 +28,16 @@ #ifndef _MACHINE_MUTEX_H_ #define _MACHINE_MUTEX_H_ -#define MUTEX_LOCKED 0 -#define MUTEX_UNLOCKED 1 +#define MUTEX_LOCKED { 0, 0, 0, 0 } +#define MUTEX_UNLOCKED { 1, 1, 1, 1 } /* Note: mtx_lock must be 16-byte aligned. */ struct mutex { - volatile int mtx_lock; + volatile int mtx_lock[4]; int mtx_wantipl; int mtx_oldipl; void *mtx_owner; -} __attribute__ ((__aligned__(16))); +}; void mtx_init(struct mutex *, int); @@ -45,12 +45,14 @@ void mtx_init(struct mutex *, int); #ifdef DIAGNOSTIC #define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_lock != MUTEX_LOCKED) \ + if ((mtx)->mtx_lock[0] == 1 && (mtx)->mtx_lock[1] == 1 && \ + (mtx)->mtx_lock[2] == 1 && (mtx)->mtx_lock[3] == 1) \ panic("mutex %p not held in %s", (mtx), __func__); \ } while (0) #define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_lock != MUTEX_UNLOCKED) \ + if ((mtx)->mtx_lock[0] != 1 && (mtx)->mtx_lock[1] != 1 && \ + (mtx)->mtx_lock[2] != 1 && (mtx)->mtx_lock[3] != 1) \ panic("mutex %p held in %s", (mtx), __func__); \ } while (0) #else |