aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cpu.h10
-rw-r--r--include/cpu/atomic/swap.h2
-rw-r--r--include/globals.h27
-rw-r--r--include/graphics/drawer.h4
-rw-r--r--include/graphics/lfb.h4
-rw-r--r--include/lib/mem.h2
-rw-r--r--include/sys/core.h4
-rw-r--r--include/sys/kernel.h8
-rw-r--r--include/sys/schedule.h12
-rw-r--r--include/sys/timer.h4
-rw-r--r--linker.ld1
-rw-r--r--src/boot.S1
-rw-r--r--src/cpu/irq.c23
-rw-r--r--src/globals.S14
-rw-r--r--src/globals.c27
-rw-r--r--src/graphics/drawer.c3
-rw-r--r--src/graphics/lfb.c33
-rw-r--r--src/lib/mem.c25
-rw-r--r--src/sys/core.c30
-rw-r--r--src/sys/kernel.S15
-rw-r--r--src/sys/schedule.S6
-rw-r--r--src/sys/schedule.c32
-rw-r--r--src/sys/timer.c6
-rw-r--r--src/util/mutex.c1
-rw-r--r--src/util/status.c16
25 files changed, 159 insertions, 151 deletions
diff --git a/include/cpu.h b/include/cpu.h
index eb2cdc0..68638a5 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -1,6 +1,8 @@
#ifndef CPU_H
#define CPU_H
+extern void _start(void);
+
static inline unsigned long getmode(void)
{
unsigned long mode;
@@ -10,13 +12,7 @@ static inline unsigned long getmode(void)
static inline void setsvc(void)
{
- unsigned long mode;
- asm volatile (
- "mrs %0, cpsr\n"
- "bic %0, %0, #0x1F\n"
- "orr %0, %0, #0x13\n"
- "msr cpsr_c, %0"
- : "=r"(mode));
+ asm volatile ( "cps #0x13" );
}
static inline void setmode(unsigned long mode)
diff --git a/include/cpu/atomic/swap.h b/include/cpu/atomic/swap.h
index 32717fb..ebaaa1d 100644
--- a/include/cpu/atomic/swap.h
+++ b/include/cpu/atomic/swap.h
@@ -1,6 +1,6 @@
#ifndef CPU_ATOMIC_SWAP_A_H
#define CPU_ATOMIC_SWAP_A_H
-#include "../../util/mutex.h"
+#include <util/mutex.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
diff --git a/include/globals.h b/include/globals.h
new file mode 100644
index 0000000..0b3eaed
--- /dev/null
+++ b/include/globals.h
@@ -0,0 +1,27 @@
+#ifndef GLOBALS_H
+#define GLOBALS_H
+#include <lib/mem.h>
+#include <sys/schedule.h>
+
+#ifndef GLOBALS_C
+extern unsigned long cntfrq;
+extern unsigned long cmdidx;
+extern char cmd[2048];
+
+extern char* os_info_v;
+extern unsigned long exe_cnt;
+extern struct Mutex exe_cnt_m;
+extern unsigned char rpi_heap[MAX_MM];
+extern void* rpi_heap_top;
+extern unsigned long nextpid;
+extern unsigned long stimel;
+extern unsigned long stimeh;
+extern struct Drawer g_Drawer;
+extern struct Scheduler scheduler;
+extern unsigned long svcsp;
+extern struct cpu_context svccpu;
+extern unsigned int gwidth, gheight, gpitch, gisrgb;
+extern unsigned char stacks_table[MAX_THREADS];
+#endif
+
+#endif
diff --git a/include/graphics/drawer.h b/include/graphics/drawer.h
index 6d97163..67abca0 100644
--- a/include/graphics/drawer.h
+++ b/include/graphics/drawer.h
@@ -6,10 +6,6 @@ struct Drawer {
unsigned int y;
};
-#ifndef GRAPHICS_DRAWER_C
-extern struct Drawer g_Drawer;
-#endif
-
void write_cchar(struct Drawer* d, char s, unsigned int c);
void write_char(struct Drawer* d, char s);
diff --git a/include/graphics/lfb.h b/include/graphics/lfb.h
index a4eef2e..a151a5f 100644
--- a/include/graphics/lfb.h
+++ b/include/graphics/lfb.h
@@ -4,10 +4,6 @@
#define GG_MAX_X 128
#define GG_MAX_Y 46
-#ifndef GRAPHICS_LFB_C
-extern unsigned int width, height, pitch, isrgb; /* dimensions and channel order */
-#endif
-
void lfb_init(void);
void lfb_showpicture(void);
diff --git a/include/lib/mem.h b/include/lib/mem.h
index 529ecea..ea1be5d 100644
--- a/include/lib/mem.h
+++ b/include/lib/mem.h
@@ -6,6 +6,7 @@
#define MEM_BASE_SIZE 2
#define MEM_META_SIZE 3
#define NULL 0
+#define MAX_MM 0x100000
struct MemTab {
unsigned char size;
@@ -20,6 +21,7 @@ struct RotBuffer {
unsigned int woffset;
};
+void memshow(unsigned char* addr, unsigned int n);
void memset(unsigned char* dest, unsigned char value, unsigned int n);
void memcpy(unsigned char* src, unsigned char* dest, unsigned int n);
unsigned char memcmp(unsigned char* a, unsigned char* b, unsigned int n);
diff --git a/include/sys/core.h b/include/sys/core.h
index eb1f1e6..c68d8de 100644
--- a/include/sys/core.h
+++ b/include/sys/core.h
@@ -1,10 +1,6 @@
#ifndef SYS_CORE_H
#define SYS_CORE_H
-#ifndef SYS_CORE_C
-extern char* os_info_v;
-#endif
-
static inline unsigned long load32(unsigned long addr)
{
return *(volatile unsigned long*)addr;
diff --git a/include/sys/kernel.h b/include/sys/kernel.h
deleted file mode 100644
index e724513..0000000
--- a/include/sys/kernel.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef SYS_KERNEL_H
-#define SYS_KERNEL_H
-
-extern unsigned long cntfrq;
-extern unsigned long cmdidx;
-extern char cmd[2048];
-
-#endif
diff --git a/include/sys/schedule.h b/include/sys/schedule.h
index 58c7312..e1cde57 100644
--- a/include/sys/schedule.h
+++ b/include/sys/schedule.h
@@ -53,11 +53,6 @@ struct Scheduler {
struct LL tlist[PRIORITIES];
};
-#ifndef SYS_SCHEDULE_C
-#define SYS_SCHEDULE_C
-extern struct Scheduler scheduler;
-#endif
-
void init_scheduler(void);
void add_thread(void (*thread_fxn)(void), unsigned char priority);
extern void schedule(void);
@@ -67,13 +62,6 @@ void cleanup(void);
void sched_info(void);
struct LL* get_next_thread(void);
-static inline void yield(void)
-{
- struct Thread* t = scheduler.rthread_ll->data;
- t->data.status = THREAD_WAITING;
- schedule();
-}
-
static inline void preserve_stack(struct Thread* thread)
{
// Get current mode
diff --git a/include/sys/timer.h b/include/sys/timer.h
index f11fd17..7120c18 100644
--- a/include/sys/timer.h
+++ b/include/sys/timer.h
@@ -4,10 +4,6 @@
/// Cycles Per Second
#define CPS 100
-#ifndef SYS_TIMER_C
-extern struct Mutex exe_cnt_m;
-#endif
-
void c_timer(void);
#endif
diff --git a/linker.ld b/linker.ld
index 58da7ca..2cacec0 100644
--- a/linker.ld
+++ b/linker.ld
@@ -30,6 +30,7 @@ SECTIONS
{
bss = .;
*(.bss*)
+ KEEP(*(.bss.mmheap))
KEEP(*(.bss.heap))
}
. = ALIGN(4096); /* align to page size */
diff --git a/src/boot.S b/src/boot.S
index 0b09baa..42e991a 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -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);