diff options
author | Christian Cunningham <cc@localhost> | 2022-01-06 16:02:43 -0800 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-01-06 16:02:43 -0800 |
commit | 159ba190d626f049512c3ebda70772c03e6737a7 (patch) | |
tree | f6479695fe328d3770cf8ac5b836ffccb908a6a7 /src/sys | |
parent | a61201b8047ebe278cfb281723a4bf6c82556472 (diff) |
Scheduling
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/schedule.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/sys/schedule.c b/src/sys/schedule.c index bde12bc..1bb02c2 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -84,14 +84,21 @@ struct LL* get_next_thread(void) unsigned long syssp = 0; void schedule(void) { + // Preserve current process's registers + // in the current stack + asm volatile ("push {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}"); + // Get current thread struct LL* current_thread_ll = scheduler.rthread_ll; + // Get next thread struct LL* next_thread_ll = get_next_thread(); + + // If there is a current thread if (current_thread_ll) { + // If we are switching the thread if (current_thread_ll != next_thread_ll) { // Context switch struct Thread* current_thread = current_thread_ll->data; struct Thread* next_thread = next_thread_ll->data; - //preserveregs(current_thread); preservestack(current_thread); preservepc(current_thread); restorestack(next_thread); @@ -109,8 +116,11 @@ void schedule(void) } if (scheduler.rthread_ll) { struct Thread* rthread = scheduler.rthread_ll->data; + // Restore process's registers + asm volatile ("pop {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}"); // Run the thread - i.e. jump to the pc - rthread->thread(); + asm volatile ("blx lr"); + //rthread->thread(); // Remove the currently running thread after completion remove_running_thread(); // Schedule the next thread |