aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-01-23 12:59:27 -0700
committerChristian Cunningham <cc@localhost>2022-01-23 12:59:27 -0700
commit5bb02975ac5f541245af9b4f6c0be4ffaa2d8463 (patch)
tree6e101458a5d763cb3fd66d7dc0baeef409a81d47
parentbb09366a7cafeb8ab91b55b98f15934f0f512d47 (diff)
Draw Exception info to screen
-rw-r--r--include/graphics/lfb.h3
-rw-r--r--include/sys/schedule.h1
-rw-r--r--src/boot.S76
-rw-r--r--src/cpu/irq.c27
-rw-r--r--src/graphics/lfb.c20
-rw-r--r--src/sys/core.c11
-rw-r--r--src/sys/schedule.c20
-rw-r--r--src/util/status.c5
8 files changed, 107 insertions, 56 deletions
diff --git a/include/graphics/lfb.h b/include/graphics/lfb.h
index a151a5f..b21e12b 100644
--- a/include/graphics/lfb.h
+++ b/include/graphics/lfb.h
@@ -9,6 +9,9 @@ void lfb_showpicture(void);
void clear_screen(void);
+void draw_cpixel(unsigned long lx, unsigned long ly, unsigned int c);
+void draw_cbox(unsigned long lx, unsigned long ly, unsigned char dx, unsigned char dy, unsigned int c);
+
void draw_cbyte(unsigned char lx, unsigned char ly, unsigned char letter, unsigned int c);
void draw_byte(unsigned char lx, unsigned char ly, unsigned char letter);
diff --git a/include/sys/schedule.h b/include/sys/schedule.h
index 53475de..d28ea6d 100644
--- a/include/sys/schedule.h
+++ b/include/sys/schedule.h
@@ -53,6 +53,7 @@ struct Scheduler {
void init_scheduler(void);
void add_thread(void* pc, void* arg, unsigned char priority);
+void draw_stacks(void);
void uart_scheduler(void);
struct Thread* next_thread(void);
/// TODO: ENSURE IRQ/ FIQ entry switches
diff --git a/src/boot.S b/src/boot.S
index 3664cc4..4690c0c 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -104,19 +104,26 @@ io_halt:
undefined:
stmfd sp!, {r0-r12,lr}
- ldr r0, [lr, #-4]
- push {r0}
- ldr r0, =undefined_msg
- bl uart_string
- pop {r0}
- bl uart_hex
- ldr r0, =undefined_at
- bl uart_string
+ ldr r4, [lr, #-4]
+ mov r0, #0
+ mov r1, #17
+ ldr r2, =undefined_msg
+ bl draw_string
+ mov r0, #18
+ mov r1, #17
+ mov r2, r4
+ bl draw_hex32
+ mov r0, #27
+ mov r1, #17
+ ldr r2, =undefined_at
+ bl draw_string
// Output lr
mov r1, #0x1000
ldr r0, [r1, #-4]
- sub r0, #4
- bl uart_hexn
+ sub r2, r0, #4
+ mov r0, #31
+ mov r1, #17
+ bl draw_hex32
// Skip instruction for now
// In future,
// ldmfd sp!, {r0-r12,lr} // Note the lack of ^ since subs will handle it
@@ -126,12 +133,6 @@ svc:
stmfd sp!, {r0-r12,lr}
ldr r0, [lr, #-4]
bic r0, #0xFF000000
- /// push {r0}
- /// ldr r0, =svc_msg
- /// bl uart_string
- /// ldr r0, [sp]
- /// bl uart_hexn
- /// pop {r0}
// SVC #0 returns to supervisor mode
// TODO: Make supervisor mode return to a specific location
// (rather than to a user location) such as the kernel loop
@@ -163,27 +164,38 @@ svc:
io_halt_prefetch:
stmfd sp!, {r0-r12,lr}
mov r4, lr
- ldr r0, =prefetch_msg
- bl uart_string
- mov r0, r4
- bl uart_hexn
+ mov r0, #0
+ mov r1, #16
+ ldr r2, =prefetch_msg
+ bl draw_string
+ // Output return address
+ mov r0, #17
+ mov r1, #16
+ mov r2, r4
+ bl draw_hex32
ldmfd sp!, {r0-r12,lr}
subs pc, lr, #4
io_halt_data:
stmfd sp!, {r0-r12,lr}
- ldr r0, =data_msg
- bl uart_string
+ mov r4, lr
+ mov r0, #0
+ mov r1, #15
+ ldr r2, =data_msg
+ bl draw_string
// Output return address
- mov r1, #0x800
- ldr r0, [r1, #-4]
- sub r0, #8
- bl uart_hexn
+ mov r0, #13
+ mov r1, #15
+ mov r2, r4
+ sub r2, #8
+ bl draw_hex32
+ mov r0, #22
+ mov r1, #15
+ ldr r2, [r4, #-8]
+ bl draw_hex32
ldmfd sp!, {r0-r12,lr}
subs pc, lr, #4 // Should be 8 once I can actually handle the abort
fiq:
stmfd sp!, {r0-r12,lr}
- //ldr r0, =fiq_msg
- //bl uart_string
bl c_fiq_handler
cmp r0, #1
bne 1f
@@ -220,9 +232,9 @@ irq_handler: .word irq
fiq_handler: .word fiq
.section .data
-undefined_msg: .asciz "Undefined Handler\nUNDEF "
-undefined_at: .asciz " @ 0x"
+undefined_msg: .asciz "Undefined Handler"
+undefined_at: .asciz "@ 0x"
svc_msg: .asciz "SVC Handler #"
-prefetch_msg: .asciz "Prefetch Handler\n"
-data_msg: .asciz "Data Handler\n"
+prefetch_msg: .asciz "Prefetch Handler"
+data_msg: .asciz "Data Handler"
fiq_msg: .asciz "FIQ\n"
diff --git a/src/cpu/irq.c b/src/cpu/irq.c
index 830c1ba..2697797 100644
--- a/src/cpu/irq.c
+++ b/src/cpu/irq.c
@@ -20,7 +20,17 @@ void c_irq_handler(void)
if(load32(IRQ_PENDING2) & (1 << 25)) {
if(load32(UART0_MIS) & (1<<4)) {
unsigned long data = load32(UART0_DR);
- // Ctrl+Tab to toggle timer
+ {
+ unsigned int x = g_Drawer.x;
+ unsigned int y = g_Drawer.y;
+ g_Drawer.x = 0;
+ g_Drawer.y = 14;
+ write_hex32(&g_Drawer, data);
+ g_Drawer.x = x;
+ g_Drawer.y = y;
+ }
+
+ // Ctrl+T to toggle timer
if(data == 0x14) {
unsigned long timer_status;
asm volatile("mrc p15, 0, %0, c14, c3, 1" : "=r"(timer_status));
@@ -40,6 +50,9 @@ void c_irq_handler(void)
}
g_Drawer.x = x;
g_Drawer.y = y;
+ // Ctrl+R to reset
+ } else if(data == 0x12) {
+ _start();
} else {
unsigned long off = cmdidx;
if (off < 2048) {
@@ -68,22 +81,11 @@ void c_irq_handler(void)
} else if (data == 0x61) {
cmd[off] = (char) data;
off += 1;
- //_start(); // Trigger reset
add_thread(localtest, 0, 0);
- //heap_info_u();
} else if (data == 0x62) {
cmd[off] = (char) data;
off += 1;
- //_start(); // Trigger reset
- uart_scheduler();
- //heap_info_u();
- } else if (data == 0x63) {
- cmd[off] = (char) data;
- off += 1;
- //_start(); // Trigger reset
- //uart_scheduler();
heap_info();
- //heap_info_u();
// Else output
} else {
cmd[off] = (char) data;
@@ -243,5 +245,4 @@ unsigned long c_fiq_handler(void)
void localtest(void)
{
- uart_char('.');
}
diff --git a/src/graphics/lfb.c b/src/graphics/lfb.c
index c3a3cac..20053bc 100644
--- a/src/graphics/lfb.c
+++ b/src/graphics/lfb.c
@@ -107,6 +107,26 @@ void lfb_showpicture(void)
}
}
+void draw_cpixel(unsigned long lx, unsigned long ly, unsigned int c)
+{
+ unsigned char* ptr = lfb;
+ ptr += (gpitch*ly+lx*4);
+ *((unsigned int*)ptr) = gisrgb ? (unsigned int)((c&0xFF)<<16 | (c&0xFF00) | (c&0xFF0000)>>16) : c;
+}
+
+void draw_cbox(unsigned long lx, unsigned long ly, unsigned char dx, unsigned char dy, unsigned int c)
+{
+ unsigned char* ptr = lfb;
+ ptr += (gpitch*ly+lx*4);
+ for(int y = 0; y < dy; y++) {
+ for(int x = 0; x < dx; x++) {
+ *((unsigned int*)ptr) = gisrgb ? (unsigned int)((c&0xFF)<<16 | (c&0xFF00) | (c&0xFF0000)>>16) : c;
+ ptr += 4;
+ }
+ ptr += gpitch - dx*4;
+ }
+}
+
void draw_cbyte(unsigned char lx, unsigned char ly, unsigned char letter, unsigned int c)
{
unsigned int x, y;
diff --git a/src/sys/core.c b/src/sys/core.c
index 4a44e96..d84770d 100644
--- a/src/sys/core.c
+++ b/src/sys/core.c
@@ -71,26 +71,17 @@ void sysinit(void)
add_thread(testlocal, 0, 3);
add_thread(testlocal, 0, 5);
add_thread(testnew, 0, 4);
- uart_scheduler();
}
void testlocal(void)
{
- uart_string("Ran thread!\n");
- if (scheduler.rthread->pid == 4) {
- add_thread(testlocal, 0, 0);
- //uart_scheduler();
- }
- uart_hexn((unsigned long)getsp());
- uart_string("Exiting thread!\n");
+ draw_stacks();
}
void testnew(void)
{
- uart_string("Ran special\n");
add_thread(testlocal, 0, 0);
usr_schedule();
- uart_string("Finish special!\n");
}
void __attribute__((naked)) usr_schedule(void)
diff --git a/src/sys/schedule.c b/src/sys/schedule.c
index ea5b465..ebf60bc 100644
--- a/src/sys/schedule.c
+++ b/src/sys/schedule.c
@@ -1,4 +1,5 @@
#include <globals.h>
+#include <graphics/lfb.h>
#include <drivers/uart.h>
#include <sys/schedule.h>
#include <util/mutex.h>
@@ -48,6 +49,25 @@ struct RStack get_stack(void)
return r;
}
+void draw_stacks(void)
+{
+ unsigned long ioff = 0;
+ unsigned long yoff = 320;
+#define STACK_DRAW_WIDTH 32
+#define STACK_DRAW_SIZE 3
+ for(int i = 0; i < MAX_THREADS; i++) {
+ if(stacks_table[i])
+ draw_cbox(ioff, yoff, STACK_DRAW_SIZE, STACK_DRAW_SIZE, 0xFFFFFF);
+ else
+ draw_cbox(ioff, yoff, STACK_DRAW_SIZE, STACK_DRAW_SIZE, 0x000000);
+ ioff += STACK_DRAW_SIZE;
+ if(ioff % STACK_DRAW_WIDTH == 0) {
+ yoff += STACK_DRAW_SIZE;
+ ioff = 0;
+ }
+ }
+}
+
void add_thread(void* pc, void* arg, unsigned char priority)
{
//void* sp = get_stack();
diff --git a/src/util/status.c b/src/util/status.c
index 460e3b0..bb6dd68 100644
--- a/src/util/status.c
+++ b/src/util/status.c
@@ -4,6 +4,7 @@
#include <graphics/lfb.h>
#include <symbols.h>
#include <sys/core.h>
+#include <sys/schedule.h>
#include <sys/timer.h>
#include <util/mutex.h>
#include <util/status.h>
@@ -71,7 +72,7 @@ void status(void)
} */
// Commands
- write_string(&g_Drawer, "\nMonitor: Ctrl-A m Exit: Ctrl-A x Timer: Ctrl-T");
+ write_string(&g_Drawer, "\nMonitor: Ctrl-A m Exit: Ctrl-A x Timer: Ctrl-T Restart: Ctrl-R");
// GPU IRQ Statuses
write_string(&g_Drawer, "\n");
@@ -178,4 +179,6 @@ void status(void)
g_Drawer.x = x;
g_Drawer.y = y;
+
+ draw_stacks();
}