From 1b180d2f15e9b726e6e9dde5601f41fa48c1c044 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Mon, 3 Jan 2022 20:10:10 -0800 Subject: Ensured Aligned Mutexes --- src/util/mutex.c | 9 +++++++++ src/util/mutex.h | 1 + src/util/status.c | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+) (limited to 'src/util') diff --git a/src/util/mutex.c b/src/util/mutex.c index 2637a6c..1763de2 100644 --- a/src/util/mutex.c +++ b/src/util/mutex.c @@ -1,4 +1,5 @@ #include "../cpu/atomic/swap.h" +#include "../lib/mem.h" #include "../util/mutex.h" unsigned char lock_mutex(struct Mutex* m, unsigned long pid) @@ -21,3 +22,11 @@ unsigned char release_mutex(struct Mutex* m, unsigned long pid) } return 1; } + +struct Mutex* create_mutex(void* addr) +{ + // Ensure aligned to word - Important for Atomic Swap + struct Mutex* m = (struct Mutex*)malloca(sizeof(struct Mutex), 4); + m->addr = addr; + return m; +} diff --git a/src/util/mutex.h b/src/util/mutex.h index 283be53..524a461 100644 --- a/src/util/mutex.h +++ b/src/util/mutex.h @@ -12,5 +12,6 @@ struct Mutex { unsigned char lock_mutex(struct Mutex*, unsigned long); unsigned char release_mutex(struct Mutex*, unsigned long); +struct Mutex* create_mutex(void* addr); #endif diff --git a/src/util/status.c b/src/util/status.c index c4a7c80..1ac08e8 100644 --- a/src/util/status.c +++ b/src/util/status.c @@ -123,6 +123,28 @@ void status(void) } write_cchar(&g_Drawer, '!', 0xFF00FF); } + + g_Drawer.x = 0; + g_Drawer.y = 9; + for(int i = 0; i < 128; i++) + write_char(&g_Drawer, ' '); + g_Drawer.x = 0; + g_Drawer.y = 9; + /* + struct Q* q = scheduler.tasks->next; + while (q != 0) { + struct Task* t = q->data; + write_hex32(&g_Drawer, (unsigned long)t->task); + write_char(&g_Drawer, ' '); + q = q->next; + } + write_char(&g_Drawer, '\n'); + */ + + unsigned long sp; + asm volatile ("mov %0, sp": "=r"(sp)); + write_hex32(&g_Drawer, sp); + g_Drawer.x = x; g_Drawer.y = y; } -- cgit v1.2.1