diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.S | 1 | ||||
-rw-r--r-- | src/cpu/irq.c | 23 | ||||
-rw-r--r-- | src/globals.S | 14 | ||||
-rw-r--r-- | src/globals.c | 27 | ||||
-rw-r--r-- | src/graphics/drawer.c | 3 | ||||
-rw-r--r-- | src/graphics/lfb.c | 33 | ||||
-rw-r--r-- | src/lib/mem.c | 25 | ||||
-rw-r--r-- | src/sys/core.c | 30 | ||||
-rw-r--r-- | src/sys/kernel.S | 15 | ||||
-rw-r--r-- | src/sys/schedule.S | 6 | ||||
-rw-r--r-- | src/sys/schedule.c | 32 | ||||
-rw-r--r-- | src/sys/timer.c | 6 | ||||
-rw-r--r-- | src/util/mutex.c | 1 | ||||
-rw-r--r-- | src/util/status.c | 16 |
14 files changed, 125 insertions, 107 deletions
@@ -6,6 +6,7 @@ _start: reset: + cpsid if // disable core0,1,2. mrc p15, #0, r1, c0, c0, #5 and r1, r1, #3 diff --git a/src/cpu/irq.c b/src/cpu/irq.c index fb73b8a..c966935 100644 --- a/src/cpu/irq.c +++ b/src/cpu/irq.c @@ -1,9 +1,9 @@ #include <cpu/irq.h> #include <drivers/uart.h> +#include <globals.h> #include <graphics/drawer.h> #include <symbols.h> #include <sys/core.h> -#include <sys/kernel.h> #include <sys/schedule.h> #include <sys/timer.h> #include <util/mutex.h> @@ -67,7 +67,7 @@ void c_irq_handler(void) } else if (data == 0x61) { cmd[off] = (char) data; off += 1; - //_start(); // Trigger reset + _start(); // Trigger reset //heap_info_u(); // Else output } else { @@ -98,12 +98,18 @@ void c_irq_handler(void) write_string(&g_Drawer, cmd); return; } + } 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 { + uart_string("Pending?"); } } else if (source & (1 << 3)) { c_timer(); return; - } else { - uart_string("Unknown Interrupt Detected!"); } return; } @@ -194,12 +200,17 @@ void c_fiq_handler(void) write_string(&g_Drawer, cmd); return; } + } 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; + *nexttime = *timer_chi + 10000; } } else if (source & (1 << 3)) { c_timer(); return; - } else { - uart_string("Unknown Interrupt Detected!"); } return; } diff --git a/src/globals.S b/src/globals.S new file mode 100644 index 0000000..68101d7 --- /dev/null +++ b/src/globals.S @@ -0,0 +1,14 @@ +.section ".bss" +.globl cntfrq +cntfrq: + .word 0 +.globl cmdidx +cmdidx: + .word 0 +.global cmd +cmd: + .space 2049 + +.section ".bss.heap" +mheap: + .space 0x100000 diff --git a/src/globals.c b/src/globals.c new file mode 100644 index 0000000..d14103d --- /dev/null +++ b/src/globals.c @@ -0,0 +1,27 @@ +#define GLOBALS_C +#include <lib/mem.h> +#include <util/mutex.h> +#include <graphics/drawer.h> +#include <sys/schedule.h> +#ifndef VERSION +char* os_info_v = "?"; +#else +char* os_info_v = VERSION; +#endif + +__attribute__((section(".bss"))) unsigned long exe_cnt; +__attribute__((section(".bss"))) struct Mutex exe_cnt_m; +__attribute__((section(".bss.mmheap"))) unsigned char rpi_heap[MAX_MM]; +__attribute__((section(".bss"))) void* rpi_heap_top; +__attribute__((section(".bss"))) unsigned long nextpid; +__attribute__((section(".bss"))) unsigned long stimel; +__attribute__((section(".bss"))) unsigned long stimeh; +__attribute__((section(".bss"))) struct Drawer g_Drawer; +__attribute__((section(".bss"))) struct Scheduler scheduler; +__attribute__((section(".bss"))) unsigned long svcsp; +__attribute__((section(".bss"))) struct cpu_context svccpu; +__attribute__((section(".bss"))) unsigned int gwidth; +__attribute__((section(".bss"))) unsigned int gheight; +__attribute__((section(".bss"))) unsigned int gpitch; +__attribute__((section(".bss"))) unsigned int gisrgb; +__attribute__((section(".bss"))) unsigned char stacks_table[MAX_THREADS]; diff --git a/src/graphics/drawer.c b/src/graphics/drawer.c index 35aea32..4445919 100644 --- a/src/graphics/drawer.c +++ b/src/graphics/drawer.c @@ -1,9 +1,6 @@ #include <graphics/drawer.h> #include <graphics/lfb.h> -#define GRAPHICS_DRAWER_C -struct Drawer g_Drawer = {.x = 0, .y = 0}; - void write_cchar(struct Drawer* d, char s, unsigned int c) { d->x %= GG_MAX_X; diff --git a/src/graphics/lfb.c b/src/graphics/lfb.c index 3ad9917..c3a3cac 100644 --- a/src/graphics/lfb.c +++ b/src/graphics/lfb.c @@ -1,11 +1,10 @@ #include <drivers/uart.h> +#include <globals.h> #include <graphics/glyphs.h> #include <graphics/lfb.h> #include <graphics/mbox.h> #include <graphics/philosopher_toad.h> -#define GRAPHICS_LFB_C -unsigned int width, height, pitch, isrgb; /* dimensions and channel order */ unsigned char *lfb; /* raw frame buffer address */ #define SCR_WIDTH 1024 @@ -64,10 +63,10 @@ void lfb_init(void) //the closest supported resolution instead if(mbox_call(MBOX_CH_PROP) && mbox[20]==32 && mbox[28]!=0) { mbox[28]&=0x3FFFFFFF; //convert GPU address to ARM address - width=mbox[5]; //get actual physical width - height=mbox[6]; //get actual physical height - pitch=mbox[33]; //get number of bytes per line - isrgb=mbox[24]; //get the actual channel order + gwidth=mbox[5]; //get actual physical width + gheight=mbox[6]; //get actual physical height + gpitch=mbox[33]; //get number of bytes per line + gisrgb=mbox[24]; //get the actual channel order lfb=(void*)((unsigned long)mbox[28]); } else { uart_string("Unable to set screen resolution to 1024x768x32\n"); @@ -77,8 +76,8 @@ void lfb_init(void) void clear_screen(void) { unsigned char *ptr=lfb; - for(unsigned int y = 0; y < height; y++) { - for(unsigned int x = 0; x < width; x++) { + for(unsigned int y = 0; y < gheight; y++) { + for(unsigned int x = 0; x < gwidth; x++) { *(unsigned int*)ptr = 0x000000; ptr += 4; } @@ -95,16 +94,16 @@ void lfb_showpicture(void) unsigned char *ptr=lfb; char *data=toad_data, pixel[4]; - ptr = lfb + (height-toad_height)*pitch + (width-toad_width)*4; + ptr = lfb + (gheight-toad_height)*gpitch + (gwidth-toad_width)*4; for(y=0;y<toad_height;y++) { for(x=0;x<toad_width;x++) { HEADER_PIXEL(data, pixel); // the image is in RGB. So if we have an RGB framebuffer, we can copy the pixels // directly, but for BGR we must swap R (pixel[0]) and B (pixel[2]) channels. - *((unsigned int*)ptr)=isrgb ? *((unsigned int *)&pixel) : (unsigned int)(pixel[0]<<16 | pixel[1]<<8 | pixel[2]); + *((unsigned int*)ptr)=gisrgb ? *((unsigned int *)&pixel) : (unsigned int)(pixel[0]<<16 | pixel[1]<<8 | pixel[2]); ptr+=4; } - ptr+=pitch-toad_width*4; + ptr+=gpitch-toad_width*4; } } @@ -112,7 +111,7 @@ void draw_cbyte(unsigned char lx, unsigned char ly, unsigned char letter, unsign { unsigned int x, y; unsigned char* ptr = lfb; - ptr += (pitch*ly*GLYPH_Y+lx*4*GLYPH_X); + ptr += (gpitch*ly*GLYPH_Y+lx*4*GLYPH_X); unsigned char ltr = (letter & 0xF) + 0x30; if (ltr > 0x39) { ltr += 7; @@ -120,13 +119,13 @@ void draw_cbyte(unsigned char lx, unsigned char ly, unsigned char letter, unsign for(y=0; y<GLYPH_Y; y++) { for(x=0; x<GLYPH_X; x++) { if((0x80 >> ((GLYPH_X-1)-x)) & glyphs[y+GLYPH_Y*(ltr)]) { - *((unsigned int*)ptr) = isrgb ? (unsigned int)((c&0xFF)<<16 | (c&0xFF00) | (c&0xFF0000)>>16) : c; + *((unsigned int*)ptr) = gisrgb ? (unsigned int)((c&0xFF)<<16 | (c&0xFF00) | (c&0xFF0000)>>16) : c; } else { *((unsigned int*)ptr) = 0x000000; } ptr += 4; } - ptr += pitch - GLYPH_X*4; + ptr += gpitch - GLYPH_X*4; } } @@ -139,18 +138,18 @@ void draw_cletter(unsigned char lx, unsigned char ly, unsigned char letter, unsi { unsigned int x, y; unsigned char* ptr = lfb; - ptr += (pitch*ly*GLYPH_Y+lx*4*GLYPH_X); + ptr += (gpitch*ly*GLYPH_Y+lx*4*GLYPH_X); unsigned char ltr = letter & 0x7F; for(y=0; y<GLYPH_Y; y++) { for(x=0; x<GLYPH_X; x++) { if((0x80 >> ((GLYPH_X-1)-x)) & glyphs[y+GLYPH_Y*(ltr)]) { - *((unsigned int*)ptr) = isrgb ? (unsigned int)((c&0xFF)<<16 | (c&0xFF00) | (c&0xFF0000)>>16) : c; + *((unsigned int*)ptr) = gisrgb ? (unsigned int)((c&0xFF)<<16 | (c&0xFF00) | (c&0xFF0000)>>16) : c; } else { *((unsigned int*)ptr) = 0x000000; } ptr += 4; } - ptr += pitch - GLYPH_X*4; + ptr += gpitch - GLYPH_X*4; } } diff --git a/src/lib/mem.c b/src/lib/mem.c index bc5f23c..82f7f45 100644 --- a/src/lib/mem.c +++ b/src/lib/mem.c @@ -1,4 +1,5 @@ #include <drivers/uart.h> +#include <globals.h> #include <lib/mem.h> void memcpyrot(unsigned char* src, struct RotBuffer* rb, unsigned int n) @@ -16,6 +17,26 @@ void memcpyrot(unsigned char* src, struct RotBuffer* rb, unsigned int n) rb->woffset = offset; } +void memshow(unsigned char* addr, unsigned int n) +{ + unsigned char temp; + for(unsigned int i = 0; i < n; i++) { + temp = addr[i] >> 4; + temp += 0x30; + if (temp > 0x39) + temp += 7; + uart_char(temp); + temp = addr[i]; + temp += 0x30; + if (temp > 0x39) + temp += 7; + uart_char(temp); + if (i+1 != n) + uart_char(0x20); + } + uart_char(0x0a); +} + void memshow32(unsigned long* addr, unsigned int n) { for(unsigned int i = 0; i < n; i++) { @@ -72,10 +93,6 @@ unsigned char memcmp32(unsigned long* a, unsigned long* b, unsigned int n) return 1; } -#define MAX_MM 0x100000 -static unsigned char rpi_heap[MAX_MM] = {0,}; -static void* rpi_heap_top = &rpi_heap; - void* malloc(unsigned char size) { diff --git a/src/sys/core.c b/src/sys/core.c index d658d90..15a403a 100644 --- a/src/sys/core.c +++ b/src/sys/core.c @@ -1,5 +1,6 @@ #include <cpu/irq.h> #include <drivers/uart.h> +#include <globals.h> #include <graphics/drawer.h> #include <graphics/lfb.h> #include <lib/mem.h> @@ -7,7 +8,6 @@ #include <lib/strings.h> #include <symbols.h> #include <sys/core.h> -#include <sys/kernel.h> #include <sys/power.h> #include <sys/schedule.h> #include <sys/timer.h> @@ -15,25 +15,19 @@ #include <util/status.h> #include <util/time.h> -#define SYS_CORE_C -#ifndef VERSION -char* os_info_v = "?"; -#else -char* os_info_v = VERSION; -#endif - void testlocal(void); // Initialize IRQs void sysinit(void) { // Clear System Globals - *(unsigned long*)exe_cnt_m.addr = 0; + exe_cnt_m.addr = &exe_cnt; exe_cnt_m.pid = NULL_PID; - cmdidx = 0; - for(int i = 0; i < 2048; i++) - cmd[i] = 0; - *(unsigned long*) SYS_TIMER_C0 = 60000000; // 60 second trigger + nextpid = SCHED_PID + 1; + rpi_heap_top = &rpi_heap; + stimeh = *(unsigned long*)SYS_TIMER_CHI; + stimel = *(unsigned long*)SYS_TIMER_CLO; + *(unsigned long*) SYS_TIMER_C0 = 60000000 + stimeh; // 6 second trigger ///... // Route GPU interrupts to Core 0 @@ -56,6 +50,8 @@ void sysinit(void) routing_core0cntv_to_core0fiq(); // Enable timer enablecntv(); + // Enable system timer + store32(SYS_TIMER_SC_M0, IRQ_ENABLE1); // Graphics Initialize lfb_init(); @@ -73,7 +69,6 @@ void sysinit(void) //add_thread(testlocal, 3); } -struct Mutex testm = {.addr = (void*)0xDEADBEEF, .pid = NULL_PID}; void testlocal1(void) { unsigned long a = 5; @@ -104,13 +99,6 @@ void testlocal(void) schedule(); } if (t->data.pid == 3) { - yield(); - yield(); - yield(); - yield(); - yield(); - yield(); - yield(); // Example /* while (uart_tx_full) { diff --git a/src/sys/kernel.S b/src/sys/kernel.S index 356cedd..d9819a2 100644 --- a/src/sys/kernel.S +++ b/src/sys/kernel.S @@ -24,18 +24,3 @@ kernel_main: 1: wfe b 1b - -.section ".data" -.globl cntfrq -cntfrq: // 32 bits - .word 0 -.globl cmdidx -cmdidx: - .word 0 -.globl cmd -cmd: - .space 2049 - -.section ".bss.heap" -mheap: - .space 0x100000 diff --git a/src/sys/schedule.S b/src/sys/schedule.S index aa33942..a46654c 100644 --- a/src/sys/schedule.S +++ b/src/sys/schedule.S @@ -91,7 +91,7 @@ schedule.current_thread_nexists: ldr r1, [r0, #0x8] // r1 = struct Thread* next_thread // Store system stack pointer - ldr r2, =syssp + ldr r2, =svcsp push {r1} ldr r1, [r2] cmp r1, #0 @@ -127,9 +127,9 @@ schedule.no_next_thread: // r1 = 0 = struct LL* current_thread_ll // No thread to run // Restore sys context - ldr r0, =syscpu + ldr r0, =svccpu str r0, [r3, #0x4] // Store context - ldr r0, =syssp + ldr r0, =svcsp ldr r1, [r0] cmp r1, #0 beq schedule.exit diff --git a/src/sys/schedule.c b/src/sys/schedule.c index 1b02476..c300ae0 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -1,29 +1,10 @@ #include <cpu/irq.h> #include <drivers/uart.h> +#include <globals.h> #include <sys/core.h> #include <sys/schedule.h> #include <util/mutex.h> -#define SYS_SCHEDULE_C -struct Scheduler scheduler = { - .tlist = { - {.prev = 0, .next = 0, .data = 0}, - {.prev = 0, .next = 0, .data = 0}, - {.prev = 0, .next = 0, .data = 0}, - {.prev = 0, .next = 0, .data = 0}, - {.prev = 0, .next = 0, .data = 0}, - {.prev = 0, .next = 0, .data = 0}, - }, - .rthread_ll = 0, - .ctx = 0, -}; -unsigned long syssp = 0; -struct cpu_context syscpu = { - .r4 = 0, .r5 = 0, .r6 = 0, .r7 = 0, - .r8 = 0, .r9 = 0, .r10 = 0, .r11 = 0, - .r12 = 0, .lr = 0, -}; - void init_scheduler(void) { for(int i = 0; i < PRIORITIES; i++) { @@ -32,11 +13,9 @@ void init_scheduler(void) scheduler.tlist[i].data = 0; } scheduler.rthread_ll = 0; - scheduler.ctx = &syscpu; + scheduler.ctx = &svccpu; } -unsigned char stacks_table[MAX_THREADS] = {0, }; - void* get_stack(void) { for (int i = 0; i < MAX_THREADS; i++) { @@ -48,7 +27,6 @@ void* get_stack(void) return 0; } -static unsigned long nextpid = 3; void add_thread(void (*thread_fxn)(void), unsigned char priority) { struct Thread* thread = (struct Thread*)malloca(sizeof(struct Thread), 4); @@ -119,7 +97,7 @@ void schedule_c(void) } else if (next_thread_ll != 0) { struct Thread* next_thread = next_thread_ll->data; - preserve_sys_stack(&syssp); + preserve_sys_stack(&svcsp); restore_stack(next_thread); scheduler.rthread_ll = next_thread_ll; scheduler.ctx = &next_thread->data.cpu_context; @@ -129,8 +107,8 @@ void schedule_c(void) restore_ctx(scheduler.ctx); asm volatile ("bx %0" :: "r"(rthread->thread)); } else { - scheduler.ctx = &syscpu; - restore_sys_stack(&syssp); + scheduler.ctx = &svccpu; + restore_sys_stack(&svcsp); restore_ctx(scheduler.ctx); } } diff --git a/src/sys/timer.c b/src/sys/timer.c index 4ccdf5d..548bf1a 100644 --- a/src/sys/timer.c +++ b/src/sys/timer.c @@ -1,17 +1,13 @@ #include <drivers/uart.h> +#include <globals.h> #include <graphics/drawer.h> #include <sys/core.h> -#include <sys/kernel.h> #include <sys/timer.h> #include <util/mutex.h> #include <util/status.h> #include <util/time.h> #include <symbols.h> -#define SYS_TIMER_C -static unsigned long exe_cnt = 0; -struct Mutex exe_cnt_m = {.addr = &exe_cnt, .pid = NULL_PID}; - void increase_counter(void) { if (lock_mutex(&exe_cnt_m, SCHED_PID) == 0) { diff --git a/src/util/mutex.c b/src/util/mutex.c index de7a515..f97760b 100644 --- a/src/util/mutex.c +++ b/src/util/mutex.c @@ -1,4 +1,5 @@ #include <cpu/atomic/swap.h> +#include <globals.h> #include <lib/mem.h> #include <sys/schedule.h> #include <util/mutex.h> diff --git a/src/util/status.c b/src/util/status.c index 7abf931..d07bf0a 100644 --- a/src/util/status.c +++ b/src/util/status.c @@ -1,4 +1,5 @@ #include <cpu.h> +#include <globals.h> #include <graphics/drawer.h> #include <graphics/lfb.h> #include <symbols.h> @@ -93,10 +94,10 @@ void status(void) // Video Status write_string(&g_Drawer, "\nVIDEO: "); write_cstring(&g_Drawer, "Enabled ", 0x00FF00); - write_10(&g_Drawer, width); + write_10(&g_Drawer, gwidth); write_string(&g_Drawer, "x"); - write_10(&g_Drawer, height); - if(isrgb) { + write_10(&g_Drawer, gheight); + if(gisrgb) { write_string(&g_Drawer, " RGB"); } else { write_string(&g_Drawer, " BGR"); @@ -162,13 +163,16 @@ void status(void) "and %0, %0, #3" : "=r"(coren) :: "cc"); write_string(&g_Drawer, "Status Updated by Core #"); write_10(&g_Drawer, coren); - write_string(&g_Drawer, "\nSys Timer Status: "); - coren = *(unsigned long*)SYS_TIMER_CS; + write_string(&g_Drawer, "\nSys Timer Status "); + coren = *(volatile unsigned long*)SYS_TIMER_CS; write_10(&g_Drawer, coren); - write_string(&g_Drawer, " : "); + write_string(&g_Drawer, ":"); unsigned long long tval = get_time(); write_hex32(&g_Drawer, (tval >> 32)); write_hex32(&g_Drawer, tval); + write_string(&g_Drawer, ":"); + coren = *(volatile unsigned long*)SYS_TIMER_C0; + write_10(&g_Drawer, coren); write_char(&g_Drawer, '\n'); write_10(&g_Drawer, ((unsigned long)tval)/1000000); |