aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-02-13 17:13:17 -0700
committerChristian Cunningham <cc@localhost>2022-02-13 17:13:17 -0700
commita0d6941b2ef689302dce37d1a864fd4213a0a559 (patch)
tree10376ed4d35fb6d89a4fb0bb2cb1c4228ddb6d98 /src
parent22b2957d4610f201bd2d365d42de285478093c01 (diff)
Implement generic lock
Diffstat (limited to 'src')
-rw-r--r--src/exceptions/svc.S14
-rw-r--r--src/tests/test.c10
-rw-r--r--src/util/lock.c9
3 files changed, 20 insertions, 13 deletions
diff --git a/src/exceptions/svc.S b/src/exceptions/svc.S
index dc1a351..cffa09c 100644
--- a/src/exceptions/svc.S
+++ b/src/exceptions/svc.S
@@ -50,12 +50,11 @@ svc_000003: // Clean task stack
sub r2, #1
str r2, [r3]
b svc_exit
-svc_000004: // Lock Mutex (usr_r0 = struct Mutex*)
+svc_000004: // Lock Lock (usr_r0 = struct Lock*)
ldr r3, =scheduler
ldr r2, [r3, #0] // struct Thread* rthread
ldr r1, [r2, #0x10] // unsigned long pid
- ldr r0, [sp, #0] // struct Mutex* m
- add r0, #4 // Point to pid
+ ldr r0, [sp, #0] // struct Lock* m
1: clrex
ldrex r2, [r0, #0]
cmp r2, #0
@@ -66,20 +65,17 @@ svc_000004: // Lock Mutex (usr_r0 = struct Mutex*)
dmb
b svc_exit
svc_000004_delay_mutex:
- // r0 = struct Mutex* m
- sub r0, #4
+ // r0 = struct Lock* m
bl sched_mutex_yield
ldmfd sp!, {r0-r12,lr}
b schedule
-svc_000005: // Release Mutex
- ldr r0, [sp, #0] // struct Mutex* m
- add r0, #4
+svc_000005: // Release Lock
+ ldr r0, [sp, #0] // struct Lock* m
mov r1, #0
dmb
str r1, [r0, #0]
dsb
sev
- sub r0, #4
bl sched_mutex_resurrect
ldmfd sp!, {r0-r12,lr}
b schedule
diff --git a/src/tests/test.c b/src/tests/test.c
index 8b01706..40e2679 100644
--- a/src/tests/test.c
+++ b/src/tests/test.c
@@ -5,6 +5,7 @@
#include <sys/core.h>
#include <sys/schedule.h>
#include <util/mutex.h>
+#include <util/lock.h>
extern void atest(void);
void btest(void);
@@ -33,26 +34,27 @@ void test_entry(void)
}
static struct Mutex testm = {.addr = 0, .pid = 0};
+//static struct Lock testm = {.pid = 0};
void ctest1(void)
{
uart_string("1 Started\n");
- sys1(4, &testm);
+ sys1(SYS_LOCK, &testm);
uart_string("1 Finished\n");
}
void ctest2(void)
{
uart_string("2 Started\n");
- sys1(4, &testm);
+ sys1(SYS_LOCK, &testm);
uart_string("2 Finished\n");
- sys1(5, &testm);
+ sys1(SYS_UNLOCK, &testm);
}
void ctest3(void)
{
uart_string("3 Started\n");
- sys1(5, &testm);
+ sys1(SYS_UNLOCK, &testm);
uart_string("3 Finished\n");
}
diff --git a/src/util/lock.c b/src/util/lock.c
new file mode 100644
index 0000000..2a7d35e
--- /dev/null
+++ b/src/util/lock.c
@@ -0,0 +1,9 @@
+#include <util/lock.h>
+#include <lib/kmem.h>
+
+struct Lock* create_lock(void)
+{
+ struct Lock* l = (struct Lock*)kmalloc(sizeof(struct Lock));
+ l->pid = 0;
+ return l;
+}