aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--include/sys/schedule.h12
-rw-r--r--src/sys/core.c3
-rw-r--r--src/sys/schedule.S13
-rw-r--r--src/sys/schedule.c5
5 files changed, 21 insertions, 16 deletions
diff --git a/README.md b/README.md
index 30725e1..1ccde4a 100644
--- a/README.md
+++ b/README.md
@@ -11,3 +11,7 @@ https://wiki.osdev.org/ARM_RaspberryPi
https://elinux.org/RPi_Framebuffer
https://github.com/bztsrc/raspi3-tutorial
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials
+
+## Todo
+Implement Scheduler for IRQ
+Fix mutex with scheduler
diff --git a/include/sys/schedule.h b/include/sys/schedule.h
index c3c748b..e10018c 100644
--- a/include/sys/schedule.h
+++ b/include/sys/schedule.h
@@ -6,12 +6,12 @@
#include <sys/core.h>
enum ThreadStatus {
- THREAD_READY,
- THREAD_WAITING,
- THREAD_WAITING_FOR_MUTEX,
- THREAD_STACK_ERROR,
- THREAD_RUNNING,
- THREAD_FINISHED,
+ THREAD_READY = 0,
+ THREAD_RUNNING = 1,
+ THREAD_WAITING = 2,
+ THREAD_WAITING_FOR_MUTEX = 3,
+ THREAD_FINISHED = 4,
+ THREAD_STACK_ERROR = 5,
};
struct cpu_context {
diff --git a/src/sys/core.c b/src/sys/core.c
index 302e629..384add5 100644
--- a/src/sys/core.c
+++ b/src/sys/core.c
@@ -62,7 +62,7 @@ void sysinit(void)
add_thread(testlocal, 0);
add_thread(testlocal, 5);
add_thread(testlocal, 8);
- delay(0x20000000);
+ //delay(0x20000000);
schedule();
}
@@ -96,7 +96,6 @@ void testlocal(void)
} else if (t->data.pid == 5) {
add_thread(testlocal1, 1);
schedule();
- sched_info();
}
uart_string("Done!\n");
}
diff --git a/src/sys/schedule.S b/src/sys/schedule.S
index 18130d0..302c4d8 100644
--- a/src/sys/schedule.S
+++ b/src/sys/schedule.S
@@ -1,10 +1,9 @@
.section .text
.globl schedule
+// TODO: Implement Scheduler for IRQ
+
// Implemented the scheduler in Assembly since the C defined was messing around with the program stacks
// This way, I can be confident that the stacks will be unchanged
-//
-// TODO: Mark threads as READY and RUNNING
-//
schedule:
ldr r3, =scheduler
// r3 = struct Scheduler*
@@ -38,12 +37,17 @@ schedule.current_thread_exists:
// Next is not the same as the current
// Preserve stack of current
ldr r2, [r1, #0x8] // struct Thread* current
+ mov r1, #0 // THREAD_READY
+ strh r1, [r2, #0x0e]
str sp, [r2, #0x4] // void* stack // Preserve stack
// Preserve program counter of current
str lr, [r2, #0x0] // void* thread // Preserve pc
ldr r2, [r0, #0x8] // struct Thread* next
// Set new stack pointer
ldr sp, [r2, #0x4]
+ // Set the thread as running
+ mov r1, #1 // THREAD_RUNNING
+ strh r1, [r2, #0x0e] // unsigned short status
add r2, r2, #0x18
// Set new running thread
str r0, [r3, #0x0] // struct LL* next_thread_ll // Set new running thread
@@ -71,6 +75,9 @@ schedule.dont_overwrite_sys_stack:
ldr sp, [r1, #0x4] // void* stack
// Store the running thread ll entry
str r0, [r3, #0x0] // struct LL* rthread_ll
+ ldr r2, [r0, #0x8] // struct Thread* thread
+ mov r0, #1 // THREAD_RUNNING
+ strh r0, [r2, #0x0e]
// Set context
add r1, r1, #0x18 // struct cpu_context*
str r1, [r3, #0x4] // store to scheduler.ctx
diff --git a/src/sys/schedule.c b/src/sys/schedule.c
index 4b071c3..7dc2205 100644
--- a/src/sys/schedule.c
+++ b/src/sys/schedule.c
@@ -156,15 +156,11 @@ void cleanup(void)
scheduler.rthread_ll = 0;
}
// Schedule next thread
- //uart_string("Scheduling from cleanup!\n");
- //sched_info();
- //schedule();
schedule();
}
void sched_info(void)
{
- disableirq();
uart_string("Scheduler Information\n");
for(unsigned long i = 0; i < PRIORITIES; i++) {
struct LL* ll = scheduler.tlist[i].next;
@@ -186,5 +182,4 @@ void sched_info(void)
}
uart_char('\n');
}
- enableirq();
}