aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cpu/irq.c11
-rw-r--r--src/lib/mem.c73
-rw-r--r--src/lib/mem.h2
-rw-r--r--src/sys/core.c7
-rw-r--r--src/sys/schedule.c83
-rw-r--r--src/sys/schedule.flat.c32
-rw-r--r--src/sys/schedule.h35
-rw-r--r--src/sys/schedule.ll.c13
-rw-r--r--src/sys/schedule.q.c49
-rw-r--r--src/util/mutex.c9
-rw-r--r--src/util/mutex.h1
-rw-r--r--src/util/status.c22
12 files changed, 124 insertions, 213 deletions
diff --git a/src/cpu/irq.c b/src/cpu/irq.c
index 874e764..dbd4c10 100644
--- a/src/cpu/irq.c
+++ b/src/cpu/irq.c
@@ -4,11 +4,14 @@
#include "../sys/core.h"
#include "../sys/timer.h"
#include "../util/mutex.h"
+#include "../util/status.h"
#include "../util/time.h"
extern unsigned long cmdidx;
extern char cmd[2048];
+void localtest(void);
+
void c_irq_handler(void)
{
disableirq();
@@ -61,6 +64,10 @@ void c_irq_handler(void)
cmd[off] = (char) data;
off += 1;
release_mutex(&exe_cnt_m, SYS_PID);
+ // New Task Case
+ } else if (data == 0x61) {
+ cmd[off] = (char) data;
+ off += 1;
// Else output
} else {
cmd[off] = (char) data;
@@ -99,3 +106,7 @@ void c_irq_handler(void)
}
return;
}
+
+void localtest(void)
+{
+}
diff --git a/src/lib/mem.c b/src/lib/mem.c
index 296e096..d738305 100644
--- a/src/lib/mem.c
+++ b/src/lib/mem.c
@@ -64,6 +64,45 @@ void* malloc(unsigned char size)
return (void*)&mem[i+2];
}
+void* malloca(unsigned char size, unsigned char amnt)
+{
+ unsigned char* mem = (unsigned char*)rpi_heap;
+ unsigned long i = 0;
+ // TODO: Use Null PID
+ while(1) {
+ unsigned long diff = (unsigned long)mem + i + 2;
+ diff %= amnt;
+ diff = amnt - diff;
+ if((mem[i] == size) && mem[i+1]==0) {
+ if(diff == 0) {
+ mem[i] = size;
+ mem[i+1] = 1;
+ return (void*)&mem[i+2];
+ }
+ } else if (mem[i] == 0) {
+ if(diff == 0 || diff == amnt) {
+ mem[i] = size;
+ mem[i+1] = 1;
+ rpi_heap_top = (void*)&mem[i+2+size];
+ return (void*)&mem[i+2];
+ } else {
+ if(diff <= 2) {
+ diff += amnt;
+ }
+ mem[i] = diff-2;
+ mem[i+1] = 0;
+ i += diff;
+ mem[i] = size;
+ mem[i+1] = 1;
+ rpi_heap_top = (void*)&mem[i+2+size];
+ return (void*)&mem[i+2];
+ }
+ }
+
+ i += mem[i]+2;
+ }
+}
+
void free(void* memloc)
{
// Don't try to free memory outside of heap
@@ -122,3 +161,37 @@ void heap_info(void)
}
uart_char('\n');
}
+
+void heap_info_u(void)
+{
+ unsigned char* base = rpi_heap;
+ while ((void*)base < rpi_heap_top) {
+ unsigned char size = *base;
+ if(base[1] == 0) {
+ base += size + 2;
+ continue;
+ }
+ uart_hex((unsigned long)(base+2));
+ uart_string(" Size: ");
+ uart_10(size);
+ uart_string("\n");
+ static char* data = "00 \0";
+ static unsigned char temp = 0;
+ for(unsigned int i = 0; i < size; i++) {
+ temp = (base[2+i]>>4)&0xF;
+ if(temp > 9)
+ temp += 7;
+ temp += 0x30;
+ data[0] = temp;
+ temp = (base[2+i])&0xF;
+ if(temp > 9)
+ temp += 7;
+ temp += 0x30;
+ data[1] = temp;
+ uart_string(data);
+ }
+ uart_char('\n');
+ base += size + 2;
+ }
+ uart_char('\n');
+}
diff --git a/src/lib/mem.h b/src/lib/mem.h
index ec1402f..5c5cc94 100644
--- a/src/lib/mem.h
+++ b/src/lib/mem.h
@@ -15,9 +15,11 @@ void memcpy32(unsigned long* src, unsigned long* dest, unsigned int n);
unsigned char memcmp32(unsigned long* a, unsigned long* b, unsigned int n);
void* malloc(unsigned char size);
+void* malloca(unsigned char size, unsigned char amnt);
void free(void* memloc);
void* heap_base(void);
void* heap_top(void);
void heap_info(void);
+void heap_info_u(void);
#endif
diff --git a/src/sys/core.c b/src/sys/core.c
index fbe0536..8d37a88 100644
--- a/src/sys/core.c
+++ b/src/sys/core.c
@@ -8,7 +8,6 @@
#include "../lib/strings.h"
#include "../sys/core.h"
#include "../sys/power.h"
-#include "../sys/schedule.h"
#include "../sys/timer.h"
#include "../util/mutex.h"
#include "../util/status.h"
@@ -51,4 +50,10 @@ void sysinit(void)
enablefiq();
// Start Scheduler
+ unsigned long count1 = -5;
+ struct Mutex* m = create_mutex(&count1);
+ if (lock_mutex(m, SYS_PID) == 0) {
+ uart_hex(*(unsigned long*)m->addr);
+ release_mutex(m, SYS_PID);
+ }
}
diff --git a/src/sys/schedule.c b/src/sys/schedule.c
deleted file mode 100644
index 8cf2780..0000000
--- a/src/sys/schedule.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "../sys/schedule.h"
-#include "../lib/ll.h"
-#include "../lib/q.h"
-
-#ifdef IGNORE
-#ifdef FLAT
-static struct Task* task_list[256];
-
-static struct Scheduler scheduler = {
- .tasks = task_list,
-};
-
-static unsigned int ntask_i = 0;
-
-void add_task(struct Task* t)
-{
- scheduler.tasks[ntask_i] = t;
- ntask_i += 1;
- if (ntask_i > 256) {
- ntask_i = 0;
- }
-}
-
-unsigned int get_task_length(void)
-{
- return ntask_i;
-}
-
-void execute_task(void)
-{
- if (scheduler.tasks[ntask_i-1] != 0)
- scheduler.tasks[ntask_i-1]->task();
-}
-#elseif LL
-static struct LL bl = {
- .prev = 0,
- .next = 0,
-};
-static struct Scheduler scheduler = {
- .tasks = &bl,
-};
-#else
-static struct Q_base bq = {
- .next = 0,
- .last = 0,
-};
-static struct Scheduler scheduler = {
- .tasks = &bq,
-};
-
-void add_task(struct Task* t)
-{
- pushq(scheduler.tasks, t);
-}
-
-unsigned int get_task_length(void)
-{
- unsigned int length = 0;
- if (scheduler.tasks->last == 0)
- return length;
- else if (scheduler.tasks->next == scheduler.tasks->last)
- return 1;
- else {
- struct Q* q = scheduler.tasks->next;
- length += 1;
- while (q->next != 0) {
- q = q->next;
- length += 1;
- }
- return length;
- }
-}
-
-void execute_task(void)
-{
- if (scheduler.tasks->last != 0) {
- struct Task* tsk = (struct Task*)scheduler.tasks->next->data;
- (tsk->task)();
- popq(scheduler.tasks);
- }
-}
-#endif
-#endif
diff --git a/src/sys/schedule.flat.c b/src/sys/schedule.flat.c
deleted file mode 100644
index 6eb0d14..0000000
--- a/src/sys/schedule.flat.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifdef FLAT
-
-#include "../sys/schedule.h"
-static struct Task* task_list[256];
-
-static struct Scheduler scheduler = {
- .tasks = task_list,
-};
-
-static unsigned int ntask_i = 0;
-
-void add_task(struct Task* t)
-{
- scheduler.tasks[ntask_i] = t;
- ntask_i += 1;
- if (ntask_i > 256) {
- ntask_i = 0;
- }
-}
-
-unsigned int get_task_length(void)
-{
- return ntask_i;
-}
-
-void execute_task(void)
-{
- if (scheduler.tasks[ntask_i-1] != 0)
- scheduler.tasks[ntask_i-1]->task();
-}
-
-#endif
diff --git a/src/sys/schedule.h b/src/sys/schedule.h
deleted file mode 100644
index c8e938d..0000000
--- a/src/sys/schedule.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef SYS_SCHEDULE_H
-#define SYS_SCHEDULE_H
-
-#define STACK_SIZE 0x1000
-struct TaskMemory {
- unsigned long reg[16];
- unsigned char stack[STACK_SIZE];
-};
-
-struct Task {
- unsigned char priority;
- void (*task)(void);
-};
-
-#ifdef FLAT
-struct Scheduler {
- struct Task** tasks;
-};
-#elseif LL
-#include "../lib/ll.h"
-struct Scheduler {
- struct LL* tasks;
-};
-#else
-#include "../lib/q.h"
-struct Scheduler {
- struct Q_base* tasks;
-};
-#endif
-
-void add_fxn(void (*task)(void), unsigned char priority);
-unsigned int get_task_length(void);
-void execute_task(void);
-
-#endif
diff --git a/src/sys/schedule.ll.c b/src/sys/schedule.ll.c
deleted file mode 100644
index d9ab954..0000000
--- a/src/sys/schedule.ll.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifdef LL
-
-#include "../sys/schedule.h"
-#include "../lib/ll.h"
-static struct LL bl = {
- .prev = 0,
- .next = 0,
-};
-static struct Scheduler scheduler = {
- .tasks = &bl,
-};
-
-#endif
diff --git a/src/sys/schedule.q.c b/src/sys/schedule.q.c
deleted file mode 100644
index 88488da..0000000
--- a/src/sys/schedule.q.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#if !(defined(LL) || defined(FLAT))
-#include "../sys/schedule.h"
-#include "../lib/q.h"
-#include "../lib/mem.h"
-
-static struct Q_base bq = {
- .next = 0,
- .last = 0,
-};
-static struct Scheduler scheduler = {
- .tasks = &bq,
-};
-
-void add_fxn(void (*task)(void), unsigned char priority)
-{
- struct Task* t = (struct Task*)malloc(sizeof(struct Task));
- t->priority = priority;
- t->task = task;
- pushq(scheduler.tasks, t);
-}
-
-unsigned int get_task_length(void)
-{
- unsigned int length = 0;
- if (scheduler.tasks->last == 0)
- return length;
- else if (scheduler.tasks->next == scheduler.tasks->last)
- return 1;
- else {
- struct Q* q = scheduler.tasks->next;
- length += 1;
- while (q->next != 0) {
- q = q->next;
- length += 1;
- }
- return length;
- }
-}
-
-void execute_task(void)
-{
- if (scheduler.tasks->last != 0) {
- struct Task* tsk = (struct Task*)scheduler.tasks->next->data;
- (tsk->task)();
- popq(scheduler.tasks);
- }
-}
-
-#endif
diff --git a/src/util/mutex.c b/src/util/mutex.c
index 2637a6c..1763de2 100644
--- a/src/util/mutex.c
+++ b/src/util/mutex.c
@@ -1,4 +1,5 @@
#include "../cpu/atomic/swap.h"
+#include "../lib/mem.h"
#include "../util/mutex.h"
unsigned char lock_mutex(struct Mutex* m, unsigned long pid)
@@ -21,3 +22,11 @@ unsigned char release_mutex(struct Mutex* m, unsigned long pid)
}
return 1;
}
+
+struct Mutex* create_mutex(void* addr)
+{
+ // Ensure aligned to word - Important for Atomic Swap
+ struct Mutex* m = (struct Mutex*)malloca(sizeof(struct Mutex), 4);
+ m->addr = addr;
+ return m;
+}
diff --git a/src/util/mutex.h b/src/util/mutex.h
index 283be53..524a461 100644
--- a/src/util/mutex.h
+++ b/src/util/mutex.h
@@ -12,5 +12,6 @@ struct Mutex {
unsigned char lock_mutex(struct Mutex*, unsigned long);
unsigned char release_mutex(struct Mutex*, unsigned long);
+struct Mutex* create_mutex(void* addr);
#endif
diff --git a/src/util/status.c b/src/util/status.c
index c4a7c80..1ac08e8 100644
--- a/src/util/status.c
+++ b/src/util/status.c
@@ -123,6 +123,28 @@ void status(void)
}
write_cchar(&g_Drawer, '!', 0xFF00FF);
}
+
+ g_Drawer.x = 0;
+ g_Drawer.y = 9;
+ for(int i = 0; i < 128; i++)
+ write_char(&g_Drawer, ' ');
+ g_Drawer.x = 0;
+ g_Drawer.y = 9;
+ /*
+ struct Q* q = scheduler.tasks->next;
+ while (q != 0) {
+ struct Task* t = q->data;
+ write_hex32(&g_Drawer, (unsigned long)t->task);
+ write_char(&g_Drawer, ' ');
+ q = q->next;
+ }
+ write_char(&g_Drawer, '\n');
+ */
+
+ unsigned long sp;
+ asm volatile ("mov %0, sp": "=r"(sp));
+ write_hex32(&g_Drawer, sp);
+
g_Drawer.x = x;
g_Drawer.y = y;
}