aboutsummaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-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
5 files changed, 18 insertions, 71 deletions
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) {