diff options
author | Christian Cunningham <cc@localhost> | 2022-02-19 13:40:17 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-02-19 13:40:17 -0700 |
commit | 9de5e07bc3920d4b03903eb5b78847973075059b (patch) | |
tree | cd0c23664beccb4c53f532650d94b722dec5f453 /src | |
parent | 5419a7174ef491427797196903c35ce921129f27 (diff) |
Added comments and cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/cpu/irq.c | 19 | ||||
-rw-r--r-- | src/drivers/uart.c | 5 | ||||
-rw-r--r-- | src/exceptions/svc.S | 3 | ||||
-rw-r--r-- | src/sys/kernel.S | 5 | ||||
-rw-r--r-- | src/sys/schedule.c | 2 | ||||
-rw-r--r-- | src/util/status.c | 8 |
6 files changed, 27 insertions, 15 deletions
diff --git a/src/cpu/irq.c b/src/cpu/irq.c index 442c834..125c3a6 100644 --- a/src/cpu/irq.c +++ b/src/cpu/irq.c @@ -15,10 +15,15 @@ void handle_data(unsigned char); void c_irq_handler(void) { unsigned long source = load32(CORE0_IRQ_SOURCE); + // Check if GPU Interrupt if (source & (1 << 8)) { + // Check if UART Interrupt if(load32(IRQ_PENDING2) & (1 << 25)) { + // Check if UART Interrupt is Masked if(load32(UART0_MIS) & (1<<4)) { + // Get the UART data unsigned long data = load32(UART0_DR); + // Draw it on the screen { unsigned int x = g_Drawer.x; unsigned int y = g_Drawer.y; @@ -29,6 +34,7 @@ void c_irq_handler(void) g_Drawer.y = y; } + // Handle the recieved data // Ctrl+T to toggle timer if(data == 0x14) { unsigned long timer_status; @@ -50,19 +56,25 @@ void c_irq_handler(void) } g_Drawer.x = x; g_Drawer.y = y; - } else { + } + // Add task to handle the data + else { add_thread(handle_data, (void*)data, 1); } return; } - } else if (*(unsigned long*)SYS_TIMER_CS == SYS_TIMER_SC_M0) { + } + // Check if System Time Compare 0 Triggered the Interrupt + else if (*(unsigned long*)SYS_TIMER_CS == SYS_TIMER_SC_M0) { volatile unsigned long* timer_cs = (unsigned long*)SYS_TIMER_CS; volatile unsigned long* timer_chi = (unsigned long*)SYS_TIMER_CHI; volatile unsigned long* nexttime = (unsigned long*)SYS_TIMER_C0; *timer_cs = SYS_TIMER_SC_M0; *nexttime = *timer_chi + 60000000; } - } else if (source & (1 << 3)) { + } + // Check if CNTV triggered the interrupt + else if (source & (1 << 3)) { c_timer(); return; } @@ -73,6 +85,7 @@ static unsigned long counter = 0; unsigned long c_fiq_handler(void) { unsigned long source = load32(CORE0_FIQ_SOURCE); + // Check if CNTV triggered the interrupt if (source & (1 << 3)) { c_timer(); counter++; diff --git a/src/drivers/uart.c b/src/drivers/uart.c index 41ce10e..d6bb92b 100644 --- a/src/drivers/uart.c +++ b/src/drivers/uart.c @@ -5,7 +5,7 @@ #include <sys/schedule.h> #include <symbols.h> -#define UART_BUFFER_SIZE 0x100 +#define UART_BUFFER_SIZE 0x400 struct UartBuffer { char buffer[UART_BUFFER_SIZE]; unsigned long roffset; @@ -52,7 +52,8 @@ void* uart_print(char* s) ubuffer.woffset %= UART_BUFFER_SIZE; ptr += 1; } - add_thread(uart_flush, 0, 5); + // Low priority flush run whenever + add_thread(uart_flush, 0, PRIORITIES-1); return 0; } diff --git a/src/exceptions/svc.S b/src/exceptions/svc.S index cffa09c..c23df82 100644 --- a/src/exceptions/svc.S +++ b/src/exceptions/svc.S @@ -82,6 +82,3 @@ svc_000005: // Release Lock b svc_exit svc_exit: ldmfd sp!, {r0-r12,pc}^ - -.section .data -svc_msg: .asciz "SVC Handler #" diff --git a/src/sys/kernel.S b/src/sys/kernel.S index 90e1c4f..3ffc6a5 100644 --- a/src/sys/kernel.S +++ b/src/sys/kernel.S @@ -4,10 +4,7 @@ kernel_main: ///https://wiki.osdev.org/ARM_Paging // Query the ID_MMFR0 register - mrc p15, 0, r2, c0, c1, 4 - mov r0, #0 - mov r1, #7 - bl draw_hex32 + mrc p15, 0, r0, c0, c1, 4 bl sysinit // Intentional undefined instruction // .word 0xf7f0a000 diff --git a/src/sys/schedule.c b/src/sys/schedule.c index dd59891..347b91a 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -42,8 +42,10 @@ void init_scheduler(void) struct RStack get_stack(void) { struct RStack r = {.sp = 0, .idx = -1}; + // Find an available stack for (int i = 0; i < MAX_THREADS; i++) { if (stacks_table[i] == 0) { + // Mark unavailable stacks_table[i] = 1; r.idx = i; r.sp = (void*)0x20000000 - STACK_SIZE*i; diff --git a/src/util/status.c b/src/util/status.c index 614581e..1d3894b 100644 --- a/src/util/status.c +++ b/src/util/status.c @@ -100,6 +100,7 @@ void status(void) write_string(&g_Drawer, " BGR"); } + // Core Stacks g_Drawer.x = 0; g_Drawer.y = 5; write_string(&g_Drawer, "SVC IRQ FIQ User/SYS\n"); @@ -107,7 +108,6 @@ void status(void) write_char(&g_Drawer, ' '); g_Drawer.x = 0; g_Drawer.y = 6; - unsigned long sp = (unsigned long)getsvcstack(); write_hex32(&g_Drawer, sp); write_char(&g_Drawer, ' '); @@ -120,12 +120,16 @@ void status(void) sp = (unsigned long)getsysstack(); write_hex32(&g_Drawer, sp); write_char(&g_Drawer, '\n'); + + // Report Core that updated status unsigned long coren; asm volatile ( "mrc p15, #0, %0, c0, c0, #5\n" "and %0, %0, #3" : "=r"(coren) :: "cc"); write_string(&g_Drawer, "Status Updated by Core #"); write_10(&g_Drawer, coren); + + // Report Sys Timer Stataus write_string(&g_Drawer, "\nSys Timer Status "); coren = *(volatile unsigned long*)SYS_TIMER_CS; write_10(&g_Drawer, coren); @@ -142,6 +146,4 @@ void status(void) g_Drawer.x = x; g_Drawer.y = y; - - draw_stacks(); } |