aboutsummaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2021-12-19 21:06:09 -0800
committerChristian Cunningham <cc@localhost>2021-12-19 21:06:09 -0800
commit0924065511087d9ef3cf84183029ce8e834ff84a (patch)
tree63b1236a636f6315bc0d2bef4fcc599456479a18 /src/cpu
parent43db8c57ebe496bea03d66e2ddd0aa6bc298738c (diff)
Configured atomic swap
Diffstat (limited to 'src/cpu')
-rw-r--r--src/cpu/atomic/swap.a.h9
-rw-r--r--src/cpu/irq.c17
2 files changed, 24 insertions, 2 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;
}