mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
ARMv5: Update to mutex files in userspace
This commit is contained in:
42
conts/libl4/src/arch/arm/v5/mutex.S
Normal file
42
conts/libl4/src/arch/arm/v5/mutex.S
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Bahadir Balban
|
||||
*/
|
||||
#include <l4lib/arch/arm/asm.h>
|
||||
#include <l4lib/mutex.h>
|
||||
|
||||
/*
|
||||
* These use the same lock word for both being granted
|
||||
* exclusive access to the word, and for storing lock values.
|
||||
*/
|
||||
|
||||
BEGIN_PROC(__l4_mutex_lock)
|
||||
mov r2, #-2
|
||||
1:
|
||||
swp r1, r2, [r0]
|
||||
cmp r1, r2
|
||||
beq 1b
|
||||
|
||||
@ Grabbed the lock,
|
||||
add r1, r1, #1 @ now increment its value
|
||||
str r1, [r0] @ Store and finish
|
||||
cmp r1, #L4_MUTEX_LOCKED @ Have we locked it?
|
||||
moveq r0, #L4_MUTEX_SUCCESS
|
||||
movne r0, #L4_MUTEX_CONTENDED
|
||||
mov pc, lr
|
||||
END_PROC(__l4_mutex_lock)
|
||||
|
||||
|
||||
BEGIN_PROC(__l4_mutex_unlock)
|
||||
mov r2, #-2
|
||||
mov r1, #L4_MUTEX_UNLOCKED
|
||||
1:
|
||||
swp r3, r2, [r0]
|
||||
cmp r3, r2
|
||||
beq 1b
|
||||
|
||||
@ Grabbed the lock
|
||||
str r1, [r0] @ Now store unlocked value and finish
|
||||
mov r0, r3 @ Get the value of contenders
|
||||
mov pc, lr
|
||||
END_PROC(__l4_mutex_unlock)
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2010 B Labs Ltd.
|
||||
* Author: Bahadir Balban
|
||||
*/
|
||||
|
||||
#include L4LIB_INC_ARCH(asm.h)
|
||||
#include <l4lib/mutex.h>
|
||||
#include <l4lib/types.h>
|
||||
#include INC_SUBARCH(irq.h)
|
||||
#include L4LIB_INC_ARCH(syslib.h) /* for BUG/BUG_ON, */
|
||||
|
||||
/*
|
||||
* NOTES:
|
||||
*
|
||||
* Recap on swp:
|
||||
*
|
||||
* swp rx, ry, [rz]
|
||||
*
|
||||
* In one instruction:
|
||||
*
|
||||
* 1) Stores the value in ry into location pointed by rz.
|
||||
* 2) Loads the value in the location of rz into rx.
|
||||
* By doing so, in one instruction one can attempt to lock
|
||||
* a word, and discover whether it was already locked.
|
||||
*
|
||||
* Why use tid of thread to lock mutex instead of
|
||||
* a single lock value?
|
||||
*
|
||||
* Because in one atomic instruction, not only the locking attempt
|
||||
* should be able to indicate whether it is locked, but also
|
||||
* the contentions. A unified lock value would not be sufficient.
|
||||
* The only way to indicate a contended lock is to store the
|
||||
* unique TID of the locker.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Any non-negative value that is a potential TID
|
||||
* (including 0) means mutex is locked.
|
||||
*/
|
||||
|
||||
|
||||
int __l4_mutex_lock(void *m, l4id_t tid)
|
||||
{
|
||||
unsigned int tmp;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"swp %0, %1, [%2]"
|
||||
: "=r" (tmp)
|
||||
: "r"(tid), "r" (m)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
if (tmp == L4_MUTEX_UNLOCKED)
|
||||
return L4_MUTEX_SUCCESS;
|
||||
|
||||
return L4_MUTEX_CONTENDED;
|
||||
}
|
||||
|
||||
|
||||
int __l4_mutex_unlock(void *m, l4id_t tid)
|
||||
{
|
||||
unsigned int tmp, tmp2 = L4_MUTEX_UNLOCKED;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"swp %0, %1, [%2]"
|
||||
: "=r" (tmp)
|
||||
: "r" (tmp2), "r"(m)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
BUG_ON(tmp == L4_MUTEX_UNLOCKED);
|
||||
|
||||
if (tmp == tid)
|
||||
return L4_MUTEX_SUCCESS;
|
||||
|
||||
return L4_MUTEX_CONTENDED;
|
||||
}
|
||||
|
||||
u8 l4_atomic_dest_readb(unsigned long *location)
|
||||
{
|
||||
#if 0
|
||||
unsigned int tmp;
|
||||
__asm__ __volatile__ (
|
||||
"swpb r0, r2, [r1] \n"
|
||||
: "=r"(tmp)
|
||||
: "r"(location), "r"(0)
|
||||
: "memory"
|
||||
);
|
||||
return (u8)tmp;
|
||||
#endif
|
||||
|
||||
unsigned int tmp;
|
||||
// unsigned long state;
|
||||
// irq_local_disable_save(&state);
|
||||
|
||||
tmp = *location;
|
||||
*location = 0;
|
||||
|
||||
//irq_local_restore(state);
|
||||
|
||||
return (u8)tmp;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user