aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-03-24 18:52:56 -0700
committerChristian Cunningham <cc@localhost>2022-03-24 18:52:56 -0700
commit7753da66d7d72f441dadd76f357fd5ceb50e7c8f (patch)
treec79cee644108ecb65952eff2104127a19e72d0c4
parent78493b1d441ef888910cf958a16f260bc3c1a7bd (diff)
Modularize Userspace
-rw-r--r--include/cpu.h24
-rw-r--r--include/usr/string.h6
-rw-r--r--include/usr/timed.h7
-rw-r--r--include/usr/uart.h6
-rw-r--r--kernel/cpu/irq.c8
-rw-r--r--kernel/exceptions/svc.S15
-rw-r--r--kernel/sys/core.c25
-rw-r--r--usr/main.c90
-rw-r--r--usr/string.c19
-rw-r--r--usr/timed.c43
-rw-r--r--usr/uart.c22
11 files changed, 159 insertions, 106 deletions
diff --git a/include/cpu.h b/include/cpu.h
index 43eeed3..d16beb5 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -88,16 +88,18 @@ static inline void* getirqstack(void)
asm volatile("svc #" syscall_h_expand_and_quote(sys_n) ::"r"(r0): "memory"); \
}
-#define SYS_YIELD 0
-#define SYS_TIME 1
-#define SYS_SCHED 2
-#define SYS_YIELD_HIGH 2
-#define SYS_ADD_THREAD 3
-#define SYS_LOCK 4
-#define SYS_UNLOCK 5
-#define SYS_SEMAPHORE_P 6
-#define SYS_SEMAPHORE_V 7
-#define SYS_SEMAPHORE_IV 8
-#define SYS_TIME_2 9
+#define SYS_YIELD 0x00000
+#define SYS_TIME 0x00001
+#define SYS_SCHED 0x00002
+#define SYS_YIELD_HIGH 0x00002
+#define SYS_ADD_THREAD 0x00003
+#define SYS_LOCK 0x00004
+#define SYS_UNLOCK 0x00005
+#define SYS_SEMAPHORE_P 0x00006
+#define SYS_SEMAPHORE_V 0x00007
+#define SYS_SEMAPHORE_IV 0x00008
+#define SYS_TIME_2 0x00009
+#define SYS_ENABLE_CNTV 0x0000A
+#define SYS_DISABLE_CNTV 0x0000B
#endif
diff --git a/include/usr/string.h b/include/usr/string.h
new file mode 100644
index 0000000..7da44a8
--- /dev/null
+++ b/include/usr/string.h
@@ -0,0 +1,6 @@
+#ifndef USR_STRING_H
+#define USR_STRING_H
+
+char* ulong_to_string(unsigned long value, char* data);
+
+#endif
diff --git a/include/usr/timed.h b/include/usr/timed.h
new file mode 100644
index 0000000..f3f941a
--- /dev/null
+++ b/include/usr/timed.h
@@ -0,0 +1,7 @@
+#ifndef USR_TIMED_H
+#define USR_TIMED_H
+
+void loop(void);
+void loopt(void);
+
+#endif
diff --git a/include/usr/uart.h b/include/usr/uart.h
new file mode 100644
index 0000000..2214012
--- /dev/null
+++ b/include/usr/uart.h
@@ -0,0 +1,6 @@
+#ifndef USR_UART_H
+#define USR_UART_H
+
+void handle_data(unsigned char data);
+
+#endif
diff --git a/kernel/cpu/irq.c b/kernel/cpu/irq.c
index 0bc8221..ae29379 100644
--- a/kernel/cpu/irq.c
+++ b/kernel/cpu/irq.c
@@ -136,6 +136,10 @@ void subscribe_irq(unsigned long irq_num, void* handler, void* handler_info)
store32(SYS_TIMER_SC_M3, IRQ_ENABLE1);
*(volatile unsigned long*)SYS_TIMER_C3 = *(volatile unsigned long*)SYS_TIMER_CHI + *(unsigned long*)handler_info;
break;
+ case LOCAL_TIMER_IRQ:
+ store32(0x80, CORE0_TIMER_IRQCNTL);
+ sys0(SYS_ENABLE_CNTV);
+ break;
}
}
@@ -161,5 +165,9 @@ void unsubscribe_irq(unsigned long irq_num)
case SYS_TIMER_3_IRQ:
store32(SYS_TIMER_SC_M3, IRQ_DISABLE1);
break;
+ case LOCAL_TIMER_IRQ:
+ store32(0x00, CORE0_TIMER_IRQCNTL);
+ sys0(SYS_DISABLE_CNTV);
+ break;
}
}
diff --git a/kernel/exceptions/svc.S b/kernel/exceptions/svc.S
index a24bac9..75a0cf1 100644
--- a/kernel/exceptions/svc.S
+++ b/kernel/exceptions/svc.S
@@ -11,7 +11,7 @@ svc:
adrle r3, svc_table_1
ldrle pc, [r3, r0, LSL #2]
sub r0, #8
- cmp r0, #7
+ cmp r0, #3
bgt svc_exit
//// Jump to the appropriate Call
adr r3, svc_table_2
@@ -128,6 +128,17 @@ svc_000009: // SYS_TIME_2
mrc p15, 0, r0, c9, c13, 0
str r0, [sp, #0]
b svc_exit
+svc_00000A: // SYS_CNTV_ENABLE
+ ldr r0, =cntfrq
+ ldr r0, [r0]
+ mcr p15, 0, r0, c14, c3, 0
+ mov r0, #1
+ mcr p15, 0, r0, c14, c3, 1
+ b svc_exit
+svc_00000B: // SYS_CNTV_DISABLE
+ mov r0, #0
+ mcr p15, 0, r0, c14, c3, 1
+ b svc_exit
svc_exit:
ldmfd sp!, {r0-r12,pc}^
@@ -143,3 +154,5 @@ svc_table_1:
svc_table_2:
.word svc_000008
.word svc_000009
+ .word svc_00000A
+ .word svc_00000B
diff --git a/kernel/sys/core.c b/kernel/sys/core.c
index 7f42d6e..4812b00 100644
--- a/kernel/sys/core.c
+++ b/kernel/sys/core.c
@@ -18,32 +18,15 @@
// Initialize IRQs
void sysinit(void)
{
- // Initialize System Globals
- //stimeh = *(unsigned long*)SYS_TIMER_CHI;
- //stimel = *(unsigned long*)SYS_TIMER_CLO;
- //*(unsigned long*) SYS_TIMER_C0 = 2000000 + stimeh; // 2 second trigger
+ // Get the frequency
+ cntfrq = read_cntfrq();
+
+ // Initialize UART
uart_init();
- ///...
// Route GPU interrupts to Core 0
store32(0x00, GPU_INTERRUPTS_ROUTING);
- //// Mask Overrun of UART0
- //store32(1<<4, UART0_IMSC);
- //// Enable UART GPU IRQ
- //store32(1<<25, IRQ_ENABLE2);
- //// Enable Timer
- ////// Get the frequency
- //cntfrq = read_cntfrq();
- //// Clear cntv interrupt and set next 1 second timer
- //write_cntv_tval(cntfrq);
- //// Route timer to core0 fiq
- //routing_core0cntv_to_core0fiq();
- //// Enable timer
- //enablecntv();
- //// Enable system timer
- //store32(SYS_TIMER_SC_M0, IRQ_ENABLE1);
-
// Graphics Initialize
lfb_init();
lfb_showpicture();
diff --git a/usr/main.c b/usr/main.c
index b6cfee3..56ddbcb 100644
--- a/usr/main.c
+++ b/usr/main.c
@@ -1,79 +1,9 @@
-#include <graphics/lfb.h>
#include <globals.h>
#include <symbols.h>
#include <sys/schedule.h>
-#include <util/time.h>
-
-void loop(void);
-
-void handle_data(unsigned char data)
-{
- // Newline Case
- if (data == 0x0D) {
- // Backspace Case
- } else if (data == 0x08 || data == 0x7F) {
- } else if (data == 0x61) {
- add_thread(uart_scheduler, 0, 2);
- } else if (data == 0x62) {
- //add_thread(test_entry, 0, 2);
- }
- // Draw it on the screen
- {
- draw_chex32(0, 9, data, 0xAA00FF);
- }
-}
-
-char* ulong_to_string(unsigned long value, char* data)
-{
- unsigned long t = value;
- unsigned long c;
- char* dptr = data + 10;
- for (int i = 0; i <= 10; i++) {
- c = t%10;
- *dptr = 0x30 + (c&0xF);
- t /= 10;
- if (t==0)
- break;
- dptr -= 1;
- if (i == 5) {
- *dptr = '.';
- dptr -= 1;
- }
- }
- return dptr;
-}
-
-void loop(void)
-{
- static char str[13];
- static unsigned long previous = 0;
- char* start;
- unsigned long current = *(volatile unsigned long*)SYS_TIMER_CHI;
- start = ulong_to_string(current, str);
- draw_string(0, 10, " ");
- draw_string(0, 10, start);
- start = ulong_to_string(previous, str);
- draw_string(0, 11, " ");
- draw_string(0, 11, start);
- start = ulong_to_string(nextpid, str);
- draw_string(0, 12, " ");
- draw_string(0, 12, start);
- previous++;
- wait_msec(3000);
- add_thread(loop, 0, 3);
-}
-
-void loopt(void)
-{
- static char str[13];
- static char cnt = 18;
- draw_string(0, 14, ulong_to_string(*(volatile unsigned long*)SYS_TIMER_CHI, str));
- cnt--;
- if (cnt == 2)
- unsubscribe_irq(SYS_TIMER_1_IRQ);
- if (cnt == 0)
- unsubscribe_irq(SYS_TIMER_0_IRQ);
-}
+#include <usr/string.h>
+#include <usr/timed.h>
+#include <usr/uart.h>
static struct SysTimerInfo stime_0 = {
.tick_rate = 5000000,
@@ -82,6 +12,12 @@ static struct SysTimerInfo stime_0 = {
};
static struct SysTimerInfo stime_1 = {
+ .tick_rate = 700000,
+ .priority = 0,
+ .arg = 0,
+};
+
+static struct SysTimerInfo stime_2 = {
.tick_rate = 300000,
.priority = 0,
.arg = 0,
@@ -91,10 +27,18 @@ static struct UartInfo UART_INFO = {
.priority = 2,
};
+static struct SysTimerInfo stime_3 = {
+ .tick_rate = 70000,
+ .priority = 0,
+ .arg = 0,
+};
+
void main(void)
{
subscribe_irq(UART_IRQ, handle_data, &UART_INFO);
subscribe_irq(SYS_TIMER_0_IRQ, loopt, &stime_0);
subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1);
+ subscribe_irq(SYS_TIMER_2_IRQ, loopt, &stime_2);
+ subscribe_irq(SYS_TIMER_3_IRQ, loopt, &stime_3);
add_thread(loop, 0, 0);
}
diff --git a/usr/string.c b/usr/string.c
new file mode 100644
index 0000000..8c94900
--- /dev/null
+++ b/usr/string.c
@@ -0,0 +1,19 @@
+char* ulong_to_string(unsigned long value, char* data)
+{
+ unsigned long t = value;
+ unsigned long c;
+ char* dptr = data + 10;
+ for (int i = 0; i <= 10; i++) {
+ c = t%10;
+ *dptr = 0x30 + (c&0xF);
+ t /= 10;
+ if (t==0)
+ break;
+ dptr -= 1;
+ if (i == 5) {
+ *dptr = '.';
+ dptr -= 1;
+ }
+ }
+ return dptr;
+}
diff --git a/usr/timed.c b/usr/timed.c
new file mode 100644
index 0000000..9247acf
--- /dev/null
+++ b/usr/timed.c
@@ -0,0 +1,43 @@
+#define USR_TIMED_C
+#include <globals.h>
+#include <graphics/lfb.h>
+#include <symbols.h>
+#include <usr/string.h>
+#include <usr/timed.h>
+#include <util/time.h>
+
+void loop(void)
+{
+ static char str[13];
+ static unsigned long previous = 0;
+ char* start;
+ unsigned long current = *(volatile unsigned long*)SYS_TIMER_CHI;
+ start = ulong_to_string(current, str);
+ draw_string(0, 10, " ");
+ draw_string(0, 10, start);
+ start = ulong_to_string(previous, str);
+ draw_string(0, 11, " ");
+ draw_string(0, 11, start);
+ start = ulong_to_string(nextpid, str);
+ draw_string(0, 12, " ");
+ draw_string(0, 12, start);
+ previous++;
+ wait_msec(3000);
+ add_thread(loop, 0, 3);
+}
+
+void loopt(void)
+{
+ static char str[13];
+ static char cnt = 18;
+ draw_string(0, 14, ulong_to_string(*(volatile unsigned long*)SYS_TIMER_CHI, str));
+ cnt--;
+ if (cnt == 6)
+ unsubscribe_irq(SYS_TIMER_3_IRQ);
+ if (cnt == 4)
+ unsubscribe_irq(SYS_TIMER_2_IRQ);
+ else if (cnt == 2)
+ unsubscribe_irq(SYS_TIMER_1_IRQ);
+ else if (cnt == 0)
+ unsubscribe_irq(SYS_TIMER_0_IRQ);
+}
diff --git a/usr/uart.c b/usr/uart.c
new file mode 100644
index 0000000..8782a74
--- /dev/null
+++ b/usr/uart.c
@@ -0,0 +1,22 @@
+#define USR_UART_C
+#include <graphics/lfb.h>
+#include <sys/schedule.h>
+#include <usr/string.h>
+#include <usr/uart.h>
+
+void handle_data(unsigned char data)
+{
+ // Newline Case
+ if (data == 0x0D) {
+ // Backspace Case
+ } else if (data == 0x08 || data == 0x7F) {
+ } else if (data == 0x61) {
+ add_thread(uart_scheduler, 0, 2);
+ } else if (data == 0x62) {
+ //add_thread(test_entry, 0, 2);
+ }
+ // Draw it on the screen
+ {
+ draw_chex32(0, 9, data, 0xAA00FF);
+ }
+}