diff options
-rw-r--r-- | src/cpu/atomic/swap.a.h | 9 | ||||
-rw-r--r-- | src/cpu/irq.c | 17 | ||||
-rw-r--r-- | src/sys/timer.c | 2 | ||||
-rw-r--r-- | src/sys/timer.h | 2 | ||||
-rw-r--r-- | src/util/mutex.c | 7 |
5 files changed, 31 insertions, 6 deletions
diff --git a/src/cpu/atomic/swap.a.h b/src/cpu/atomic/swap.a.h index 63dd50b..1ca2a52 100644 --- a/src/cpu/atomic/swap.a.h +++ b/src/cpu/atomic/swap.a.h @@ -1,7 +1,12 @@ +#include "../../util/mutex.h" + #ifndef CPU_ATOMIC_SWAP_A_H #define CPU_ATOMIC_SWAP_A_H /// https://stackoverflow.com/questions/16329123/use-of-strexeq-instead-of-strex-for-spinlock-implementation-in-arm +/// https://elixir.bootlin.com/linux/v4.9/source/arch/arm/include/asm/spinlock.h +/// https://elixir.bootlin.com/linux/v4.9/source/arch/arm/include/asm/spinlock_types.h#L23 +/// https://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/3_Processes.html static inline void atm_lock(unsigned long pid, unsigned long* addr) { unsigned long tmp, current_lock_value; @@ -18,8 +23,8 @@ static inline void atm_lock(unsigned long pid, unsigned long* addr) { : "cc"); } -static inline void atm_unlock(unsigned long* addr) { - unsigned long cleared = 0; +static inline void atm_release(unsigned long* addr) { + unsigned long cleared = NULL_PID; asm volatile( " dmb\n" " str %0, [%1]\n" diff --git a/src/cpu/irq.c b/src/cpu/irq.c index 0a1e080..adba7a7 100644 --- a/src/cpu/irq.c +++ b/src/cpu/irq.c @@ -3,6 +3,7 @@ #include "../sys/timer.h" #include "../drivers/uart.a.h" #include "../drivers/uart.h" +#include "../util/mutex.h" #include "../util/time.h" extern unsigned long cmdidx; @@ -42,12 +43,14 @@ void c_irq_handler(void) { } else { unsigned long off = cmdidx; if (off < 2048) { + // Newline Case if (data == 0x0D) { off = 0; cmd[0] = 0x0; //uart_char(0x0a); uart_char(data); uart_string("\033[?25l> \033[0K\033[?25h"); + // Backspace Case } else if (data == 0x08 || data == 0x7F) { if (off > 0) { off -= 1; @@ -56,6 +59,19 @@ void c_irq_handler(void) { uart_char((unsigned char)data); uart_char(0x20); uart_char((unsigned char)data); + // Lock Case + } else if (data == 0x6C) { + uart_char((unsigned char)data); + cmd[off] = (char) data; + off += 1; + lock_mutex(&exe_cnt_m, SCHED_PID); + // Release Case + } else if (data == 0x72) { + uart_char((unsigned char)data); + cmd[off] = (char) data; + off += 1; + release_mutex(&exe_cnt_m, SCHED_PID); + // Else output } else { uart_char((unsigned char)data); cmd[off] = (char) data; @@ -95,6 +111,7 @@ void c_irq_handler(void) { c_timer(); //enable_irq(); enableirq(); + return; } return; } diff --git a/src/sys/timer.c b/src/sys/timer.c index f4013d4..9df7b33 100644 --- a/src/sys/timer.c +++ b/src/sys/timer.c @@ -5,7 +5,7 @@ #include "../drivers/uart.a.h" #include "../drivers/uart.h" -#define TIMER_C +#define SYS_TIMER_C extern char* os_info_v; unsigned long exe_cnt = 0; diff --git a/src/sys/timer.h b/src/sys/timer.h index 4774ed4..76fc015 100644 --- a/src/sys/timer.h +++ b/src/sys/timer.h @@ -1,7 +1,7 @@ #ifndef SYS_TIMER_H #define SYS_TIMER_H -#ifndef TIMER_C +#ifndef SYS_TIMER_C extern struct Mutex exe_cnt_m; #endif diff --git a/src/util/mutex.c b/src/util/mutex.c index 86ffcf5..98dc849 100644 --- a/src/util/mutex.c +++ b/src/util/mutex.c @@ -1,8 +1,10 @@ #include "../util/mutex.h" +#include "../cpu/atomic/swap.a.h" unsigned char lock_mutex(struct Mutex* m, unsigned long pid) { if (m->pid == NULL_PID) { - m->pid = pid; + //m->pid = pid; + atm_lock(pid, &m->pid); return 0; } return 1; @@ -13,7 +15,8 @@ unsigned char lock_mutex(struct Mutex* m, unsigned long pid) { // mutex's pid lock unsigned char release_mutex(struct Mutex* m, unsigned long pid) { if (m->pid == pid) { - m->pid = NULL_PID; + //m->pid = NULL_PID; + atm_release(&m->pid); return 0; } return 1; |