From 397630f9ffd836c9ac939ad4d40093cd640ab1a1 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sat, 27 Sep 2025 00:00:00 +0000 Subject: [PATCH 1/8] [CONT_SWITCH] cpec (current process execution context) register --- kernel/process/context_switch.S | 5 ++++- kernel/process/scheduler.c | 14 ++++++++------ kernel/process/syscall.c | 1 + kernel/process/syscall.h | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/kernel/process/context_switch.S b/kernel/process/context_switch.S index e03b73cb..30c76dd0 100644 --- a/kernel/process/context_switch.S +++ b/kernel/process/context_switch.S @@ -1,7 +1,8 @@ .global save_context save_context: - // x0: pointer to process_t + ldr x0, =cpec + ldr x0, [x0] // Save general-purpose registers x1-x30 (excluding x0 which holds the pointer) stp x1, x2, [x0, #(8 * 0)] stp x3, x4, [x0, #(8 * 2)] @@ -37,6 +38,8 @@ save_pc_interrupt: .global restore_context restore_context: + ldr x0, =cpec + ldr x0, [x0] // Restore general-purpose registers ldp x1, x2, [x0, #(8 * 0)] ldp x3, x4, [x0, #(8 * 2)] diff --git a/kernel/process/scheduler.c b/kernel/process/scheduler.c index 0062c847..5b495e38 100644 --- a/kernel/process/scheduler.c +++ b/kernel/process/scheduler.c @@ -15,9 +15,9 @@ #include "memory/mmu.h" #include "process/syscall.h" -extern void save_context(process_t* proc); -extern void save_pc_interrupt(process_t* proc); -extern void restore_context(process_t* proc); +extern void save_context(uintptr_t ptr); +extern void save_pc_interrupt(uintptr_t ptr); +extern void restore_context(uintptr_t ptr); //TODO: use queues, eliminate the max procs limitation process_t processes[MAX_PROCS]; @@ -49,11 +49,11 @@ typedef struct proc_open_file { void* proc_page; void save_context_registers(){ - save_context(&processes[current_proc]); + save_context(cpec); } void save_return_address_interrupt(){ - save_pc_interrupt(&processes[current_proc]); + save_pc_interrupt(cpec); } void switch_proc(ProcSwitchReason reason) { @@ -66,6 +66,7 @@ void switch_proc(ProcSwitchReason reason) { } current_proc = next_proc; + cpec = (uintptr_t)&processes[current_proc]; timer_reset(processes[current_proc].priority); process_restore(); } @@ -76,7 +77,7 @@ void save_syscall_return(uint64_t value){ void process_restore(){ syscall_depth--; - restore_context(&processes[current_proc]); + restore_context(cpec); } bool start_scheduler(){ @@ -159,6 +160,7 @@ void reset_process(process_t *proc){ void init_main_process(){ proc_page = palloc(0x1000, MEM_PRIV_KERNEL, MEM_RW, false); process_t* proc = &processes[0]; + cpec = (uintptr_t)&processes[0]; proc->id = next_proc_index++; proc->state = BLOCKED; proc->heap = (uintptr_t)palloc(0x1000, MEM_PRIV_KERNEL, MEM_RW, false); diff --git a/kernel/process/syscall.c b/kernel/process/syscall.c index c3491513..7c541586 100644 --- a/kernel/process/syscall.c +++ b/kernel/process/syscall.c @@ -21,6 +21,7 @@ #include "bin/bin_mod.h" int syscall_depth = 0; +uintptr_t cpec; //TODO: What happens if we pass another process' data in here? //TODO: make indexmap in c and it can be used here diff --git a/kernel/process/syscall.h b/kernel/process/syscall.h index 42515e59..61c24fdc 100644 --- a/kernel/process/syscall.h +++ b/kernel/process/syscall.h @@ -2,4 +2,5 @@ #include "types.h" -extern int syscall_depth; \ No newline at end of file +extern int syscall_depth; +extern uintptr_t cpec; \ No newline at end of file From 60a9c09d3a5e633ef4bdd004cc4bb950ff5d8bb7 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 28 Sep 2025 00:00:00 +0000 Subject: [PATCH 2/8] [CONT_SWITCH] saving to cpec --- kernel/Makefile | 1 + kernel/exceptions/exception_vectors_as.S | 5 ++++ kernel/exceptions/irq.c | 1 - kernel/process/context.inc | 28 +++++++++++++++++++++ kernel/process/context_switch.S | 31 ------------------------ kernel/process/scheduler.c | 5 ---- kernel/process/scheduler.h | 1 - kernel/process/syscall.c | 1 - kernel/process/syscall_as.S | 5 ++++ shared/Makefile | 2 +- 10 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 kernel/process/context.inc diff --git a/kernel/Makefile b/kernel/Makefile index eb2511d8..00f5d147 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -50,5 +50,6 @@ $(BUILD_DIR)/%.o: %.cpp clean: $(RM) $(CLEAN_OBJS) $(CLEAN_DEPS) $(ELF) $(TARGET) + $(RM) -r $(BUILD_DIR) -include $(DEP) diff --git a/kernel/exceptions/exception_vectors_as.S b/kernel/exceptions/exception_vectors_as.S index ac68f059..4021ed7e 100644 --- a/kernel/exceptions/exception_vectors_as.S +++ b/kernel/exceptions/exception_vectors_as.S @@ -1,3 +1,5 @@ +#include "process/context.inc" + .section .vectors, "a", %progbits .align 11 .global exception_vectors @@ -58,5 +60,8 @@ irq_el1_asm_handler: mov x16, x3 mov x13, x29 mov x12, x30 + + save_ctx + b irq_el1_handler eret \ No newline at end of file diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index 7936e841..5166b083 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -73,7 +73,6 @@ void disable_interrupt(){ } void irq_el1_handler() { - save_context_registers(); save_return_address_interrupt(); syscall_depth++; uint32_t irq; diff --git a/kernel/process/context.inc b/kernel/process/context.inc new file mode 100644 index 00000000..39f405b4 --- /dev/null +++ b/kernel/process/context.inc @@ -0,0 +1,28 @@ +.macro save_ctx +ldr x0, =cpec +ldr x0, [x0] +// Save general-purpose registers x1-x30 (excluding x0 which holds the pointer) +stp x1, x2, [x0, #(8 * 0)] +stp x3, x4, [x0, #(8 * 2)] +stp x5, x6, [x0, #(8 * 4)] +stp x7, x8, [x0, #(8 * 6)] +stp x9, x10, [x0, #(8 * 8)] +stp x11, x12, [x0, #(8 * 10)] +stp x13, x14, [x0, #(8 * 12)] +stp x15, x16, [x0, #(8 * 14)] +stp x17, x18, [x0, #(8 * 16)] +stp x19, x20, [x0, #(8 * 18)] +stp x21, x22, [x0, #(8 * 20)] +stp x23, x24, [x0, #(8 * 22)] +stp x25, x26, [x0, #(8 * 24)] +stp x27, x28, [x0, #(8 * 26)] +stp x29, x30, [x0, #(8 * 28)] + +// SP +str x11, [x0, #(8 * 31)] + +//Status bits +and x10, x10, 0xFFF +str x10, [x0, #(8 * 33)] + +.endm \ No newline at end of file diff --git a/kernel/process/context_switch.S b/kernel/process/context_switch.S index 30c76dd0..8e21879a 100644 --- a/kernel/process/context_switch.S +++ b/kernel/process/context_switch.S @@ -1,34 +1,3 @@ -.global save_context -save_context: - - ldr x0, =cpec - ldr x0, [x0] - // Save general-purpose registers x1-x30 (excluding x0 which holds the pointer) - stp x1, x2, [x0, #(8 * 0)] - stp x3, x4, [x0, #(8 * 2)] - stp x5, x6, [x0, #(8 * 4)] - stp x7, x8, [x0, #(8 * 6)] - stp x9, x10, [x0, #(8 * 8)] - stp x11, x12, [x0, #(8 * 10)] - stp x13, x14, [x0, #(8 * 12)] - stp x15, x16, [x0, #(8 * 14)] - stp x17, x18, [x0, #(8 * 16)] - stp x19, x20, [x0, #(8 * 18)] - stp x21, x22, [x0, #(8 * 20)] - stp x23, x24, [x0, #(8 * 22)] - stp x25, x26, [x0, #(8 * 24)] - stp x27, x28, [x0, #(8 * 26)] - stp x29, x30, [x0, #(8 * 28)] - - // SP - str x11, [x0, #(8 * 31)] - - //Status bits - and x10, x10, 0xFFF - str x10, [x0, #(8 * 33)] - - ret - .global save_pc_interrupt save_pc_interrupt: mrs x1, elr_el1 diff --git a/kernel/process/scheduler.c b/kernel/process/scheduler.c index 5b495e38..8cd539df 100644 --- a/kernel/process/scheduler.c +++ b/kernel/process/scheduler.c @@ -15,7 +15,6 @@ #include "memory/mmu.h" #include "process/syscall.h" -extern void save_context(uintptr_t ptr); extern void save_pc_interrupt(uintptr_t ptr); extern void restore_context(uintptr_t ptr); @@ -48,10 +47,6 @@ typedef struct proc_open_file { void* proc_page; -void save_context_registers(){ - save_context(cpec); -} - void save_return_address_interrupt(){ save_pc_interrupt(cpec); } diff --git a/kernel/process/scheduler.h b/kernel/process/scheduler.h index b62267d0..8ea84f2e 100644 --- a/kernel/process/scheduler.h +++ b/kernel/process/scheduler.h @@ -18,7 +18,6 @@ typedef enum { void switch_proc(ProcSwitchReason reason); bool start_scheduler(); -void save_context_registers(); void save_return_address_interrupt(); void init_main_process(); process_t* init_process(); diff --git a/kernel/process/syscall.c b/kernel/process/syscall.c index 7c541586..b464164c 100644 --- a/kernel/process/syscall.c +++ b/kernel/process/syscall.c @@ -261,7 +261,6 @@ void coredump(uint64_t esr, uint64_t elr, uint64_t far){ } void sync_el0_handler_c(){ - save_context_registers(); save_return_address_interrupt(); syscall_depth++; diff --git a/kernel/process/syscall_as.S b/kernel/process/syscall_as.S index b6399480..49fbe891 100644 --- a/kernel/process/syscall_as.S +++ b/kernel/process/syscall_as.S @@ -1,3 +1,5 @@ +#include "context.inc" + .global sync_el0_handler_as //TODO: Rethink the registers used to be sequential both here and in context_switch and exception_vectors_as @@ -29,5 +31,8 @@ sync_el0_handler_as: mov x16, x3 mov x13, x29 mov x12, x30 + + save_ctx + b sync_el0_handler_c eret \ No newline at end of file diff --git a/shared/Makefile b/shared/Makefile index 96d80111..593e7db5 100644 --- a/shared/Makefile +++ b/shared/Makefile @@ -40,8 +40,8 @@ $(BUILD_DIR)/%.o: %.cpp @mkdir -p $(dir $@) $(VCXX) $(CXXFLAGS) -c -MMD -MP $< -o $@ -# Might want to also delete the directories created inside BUILD_DIR clean: $(RM) $(CLEAN_OBJS) $(CLEAN_DEPS) $(TARGET) + $(RM) -r $(BUILD_DIR) -include $(DEP) From 2afb4e764422959a21c527aa9bf66493ac99a4c7 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 28 Sep 2025 00:00:00 +0000 Subject: [PATCH 3/8] [CONT_SWITCH] unifying context switch functions --- kernel/exceptions/exception_vectors_as.S | 37 ++++++---------------- kernel/process/{context.inc => context.S} | 28 +++++++++++++++++ kernel/process/syscall_as.S | 38 ----------------------- 3 files changed, 37 insertions(+), 66 deletions(-) rename kernel/process/{context.inc => context.S} (57%) delete mode 100644 kernel/process/syscall_as.S diff --git a/kernel/exceptions/exception_vectors_as.S b/kernel/exceptions/exception_vectors_as.S index 4021ed7e..cb59d9d5 100644 --- a/kernel/exceptions/exception_vectors_as.S +++ b/kernel/exceptions/exception_vectors_as.S @@ -1,4 +1,4 @@ -#include "process/context.inc" +#include "process/context.S" .section .vectors, "a", %progbits .align 11 @@ -33,35 +33,16 @@ exception_vectors: .global irq_el1_asm_handler irq_el1_asm_handler: - msr daifset, #2 - mrs x10, spsr_el1 - lsr x18, x10, #2 - and x18, x18, #0b11 - - cmp x18, #1 - b.eq 1f - cmp x18, #0 - b.eq 2f - - b 3f + save_ctx -1: mov x11, sp - b 3f + b irq_el1_handler + eret -2: mrs x11, sp_el0 - ldr x18, =ksp - //TODO: in order to ensure we don't ovewrite any stack data, save it to its own global variable - mov sp, x18 +.global sync_el0_handler_as -3: - mov x15, x0 - mov x14, x1 - mov x9, x2 - mov x16, x3 - mov x13, x29 - mov x12, x30 +//TODO: Rethink the registers used to be sequential both here and in context_switch and exception_vectors_as +sync_el0_handler_as: + save_ctx - save_ctx - - b irq_el1_handler + b sync_el0_handler_c eret \ No newline at end of file diff --git a/kernel/process/context.inc b/kernel/process/context.S similarity index 57% rename from kernel/process/context.inc rename to kernel/process/context.S index 39f405b4..cd73d8a9 100644 --- a/kernel/process/context.inc +++ b/kernel/process/context.S @@ -1,4 +1,32 @@ .macro save_ctx +msr daifset, #2 + mrs x10, spsr_el1 + lsr x18, x10, #2 + and x18, x18, #0b11 + + cmp x18, #1 + b.eq 1f + cmp x18, #0 + b.eq 2f + + b 3f + +1: mov x11, sp + b 3f + +2: mrs x11, sp_el0 + ldr x18, =ksp + //TODO: in order to ensure we don't ovewrite any stack data, save it to its own global variable + mov sp, x18 + +3: + mov x15, x0 + mov x14, x1 + mov x9, x2 + mov x16, x3 + mov x13, x29 + mov x12, x30 + ldr x0, =cpec ldr x0, [x0] // Save general-purpose registers x1-x30 (excluding x0 which holds the pointer) diff --git a/kernel/process/syscall_as.S b/kernel/process/syscall_as.S deleted file mode 100644 index 49fbe891..00000000 --- a/kernel/process/syscall_as.S +++ /dev/null @@ -1,38 +0,0 @@ -#include "context.inc" - -.global sync_el0_handler_as - -//TODO: Rethink the registers used to be sequential both here and in context_switch and exception_vectors_as -sync_el0_handler_as: - msr daifset, #2 - mrs x10, spsr_el1 - lsr x18, x10, #2 - and x18, x18, #0b11 - - cmp x18, #1 - b.eq 1f - cmp x18, #0 - b.eq 2f - - b 3f - -1: mov x11, sp - b 3f - -2: mrs x11, sp_el0 - ldr x18, =ksp - //TODO: in order to ensure we don't ovewrite any stack data, save it to its own global variable - mov sp, x18 - -3: - mov x15, x0 - mov x14, x1 - mov x9, x2 - mov x16, x3 - mov x13, x29 - mov x12, x30 - - save_ctx - - b sync_el0_handler_c - eret \ No newline at end of file From cd88a3661163859029838ba93274a26fec2310f4 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 28 Sep 2025 00:00:00 +0000 Subject: [PATCH 4/8] [CONT_SWITCH] renamed file --- kernel/exceptions/exception_vectors_as.S | 3 +-- kernel/process/{context.S => context_save.S} | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename kernel/process/{context.S => context_save.S} (100%) diff --git a/kernel/exceptions/exception_vectors_as.S b/kernel/exceptions/exception_vectors_as.S index cb59d9d5..e22f7e77 100644 --- a/kernel/exceptions/exception_vectors_as.S +++ b/kernel/exceptions/exception_vectors_as.S @@ -1,4 +1,4 @@ -#include "process/context.S" +#include "process/context_save.S" .section .vectors, "a", %progbits .align 11 @@ -39,7 +39,6 @@ irq_el1_asm_handler: eret .global sync_el0_handler_as - //TODO: Rethink the registers used to be sequential both here and in context_switch and exception_vectors_as sync_el0_handler_as: save_ctx diff --git a/kernel/process/context.S b/kernel/process/context_save.S similarity index 100% rename from kernel/process/context.S rename to kernel/process/context_save.S From 99bd8d39bf20d113dbb17b32837e134d64e65eec Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 28 Sep 2025 00:00:00 +0000 Subject: [PATCH 5/8] [CONT_SWITCH] unmapping x1,2,3,29,30, unmasking status bits --- kernel/process/context_save.S | 6 ------ kernel/process/context_switch.S | 4 ---- kernel/process/process.h | 6 +++--- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/kernel/process/context_save.S b/kernel/process/context_save.S index cd73d8a9..48ff9ce9 100644 --- a/kernel/process/context_save.S +++ b/kernel/process/context_save.S @@ -21,11 +21,6 @@ msr daifset, #2 3: mov x15, x0 - mov x14, x1 - mov x9, x2 - mov x16, x3 - mov x13, x29 - mov x12, x30 ldr x0, =cpec ldr x0, [x0] @@ -50,7 +45,6 @@ stp x29, x30, [x0, #(8 * 28)] str x11, [x0, #(8 * 31)] //Status bits -and x10, x10, 0xFFF str x10, [x0, #(8 * 33)] .endm \ No newline at end of file diff --git a/kernel/process/context_switch.S b/kernel/process/context_switch.S index 8e21879a..d8d965fd 100644 --- a/kernel/process/context_switch.S +++ b/kernel/process/context_switch.S @@ -50,9 +50,5 @@ restore_context: msr elr_el1, x11 mov x0, x15 - mov x1, x14 - mov x30, x12 - mov x2, x9 - mov x3, x16 eret \ No newline at end of file diff --git a/kernel/process/process.h b/kernel/process/process.h index 28d964fb..ff8da5cd 100644 --- a/kernel/process/process.h +++ b/kernel/process/process.h @@ -63,9 +63,9 @@ typedef struct { //Helper functions for accessing registers mapped to scratch regs #define PROC_X0 regs[14] -#define PROC_X1 regs[13] -#define PROC_X2 regs[8] -#define PROC_X3 regs[15] +#define PROC_X1 regs[0] +#define PROC_X2 regs[1] +#define PROC_X3 regs[2] #define PROC_X4 regs[3] // #define PROC_FP regs[12] // #define PROC_LR regs[11] From db98117635e4994f7766f8111c5cfa26073d5311 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 28 Sep 2025 00:00:00 +0000 Subject: [PATCH 6/8] [CONT_SWITCH] restore matching save --- kernel/process/context_save.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/process/context_save.S b/kernel/process/context_save.S index 48ff9ce9..c5c579cd 100644 --- a/kernel/process/context_save.S +++ b/kernel/process/context_save.S @@ -11,10 +11,10 @@ msr daifset, #2 b 3f -1: mov x11, sp +1: mov x16, sp b 3f -2: mrs x11, sp_el0 +2: mrs x16, sp_el0 ldr x18, =ksp //TODO: in order to ensure we don't ovewrite any stack data, save it to its own global variable mov sp, x18 @@ -42,7 +42,7 @@ stp x27, x28, [x0, #(8 * 26)] stp x29, x30, [x0, #(8 * 28)] // SP -str x11, [x0, #(8 * 31)] +str x16, [x0, #(8 * 31)] //Status bits str x10, [x0, #(8 * 33)] From 63059e6dee4f4522aa0d4a915b2b9c905da770f9 Mon Sep 17 00:00:00 2001 From: Diego Ferrari Date: Sun, 28 Sep 2025 00:00:00 +0000 Subject: [PATCH 7/8] [CONT_SWITCH] only overwriting x17, x18 --- kernel/process/context_save.S | 51 ++++++++++++------------ kernel/process/context_switch.S | 69 +++++++++++++++++---------------- kernel/process/process.h | 10 ++--- 3 files changed, 67 insertions(+), 63 deletions(-) diff --git a/kernel/process/context_save.S b/kernel/process/context_save.S index c5c579cd..53338073 100644 --- a/kernel/process/context_save.S +++ b/kernel/process/context_save.S @@ -1,7 +1,7 @@ .macro save_ctx msr daifset, #2 - mrs x10, spsr_el1 - lsr x18, x10, #2 + mrs x18, spsr_el1 + lsr x18, x18, #2 and x18, x18, #0b11 cmp x18, #1 @@ -11,40 +11,41 @@ msr daifset, #2 b 3f -1: mov x16, sp +1: mov x17, sp b 3f -2: mrs x16, sp_el0 +2: mrs x17, sp_el0 ldr x18, =ksp //TODO: in order to ensure we don't ovewrite any stack data, save it to its own global variable mov sp, x18 3: - mov x15, x0 -ldr x0, =cpec -ldr x0, [x0] -// Save general-purpose registers x1-x30 (excluding x0 which holds the pointer) -stp x1, x2, [x0, #(8 * 0)] -stp x3, x4, [x0, #(8 * 2)] -stp x5, x6, [x0, #(8 * 4)] -stp x7, x8, [x0, #(8 * 6)] -stp x9, x10, [x0, #(8 * 8)] -stp x11, x12, [x0, #(8 * 10)] -stp x13, x14, [x0, #(8 * 12)] -stp x15, x16, [x0, #(8 * 14)] -stp x17, x18, [x0, #(8 * 16)] -stp x19, x20, [x0, #(8 * 18)] -stp x21, x22, [x0, #(8 * 20)] -stp x23, x24, [x0, #(8 * 22)] -stp x25, x26, [x0, #(8 * 24)] -stp x27, x28, [x0, #(8 * 26)] -stp x29, x30, [x0, #(8 * 28)] +ldr x18, =cpec +ldr x18, [x18] +// Save general-purpose registers x1-x30 +stp x0, x1, [x18, #(8 * 0)] +stp x2, x3, [x18, #(8 * 2)] +stp x4, x5, [x18, #(8 * 4)] +stp x6, x7, [x18, #(8 * 6)] +stp x8, x9, [x18, #(8 * 8)] +stp x10, x11, [x18, #(8 * 10)] +stp x12, x13, [x18, #(8 * 12)] +stp x14, x15, [x18, #(8 * 14)] +str x16, [x18, #(8 * 16)] +str x19, [x18, #(8 * 19)] +stp x20, x21, [x18, #(8 * 20)] +stp x22, x23, [x18, #(8 * 22)] +stp x24, x25, [x18, #(8 * 24)] +stp x26, x27, [x18, #(8 * 26)] +stp x28, x29, [x18, #(8 * 28)] +str x30, [x18,#(8 * 30)] // SP -str x16, [x0, #(8 * 31)] +str x17, [x18, #(8 * 31)] //Status bits -str x10, [x0, #(8 * 33)] +mrs x17, spsr_el1 +str x17, [x18, #(8 * 33)] .endm \ No newline at end of file diff --git a/kernel/process/context_switch.S b/kernel/process/context_switch.S index d8d965fd..39eaa0d6 100644 --- a/kernel/process/context_switch.S +++ b/kernel/process/context_switch.S @@ -7,48 +7,51 @@ save_pc_interrupt: .global restore_context restore_context: - ldr x0, =cpec - ldr x0, [x0] + ldr x18, =cpec + ldr x18, [x18] // Restore general-purpose registers - ldp x1, x2, [x0, #(8 * 0)] - ldp x3, x4, [x0, #(8 * 2)] - ldp x5, x6, [x0, #(8 * 4)] - ldp x7, x8, [x0, #(8 * 6)] - ldp x9, x10, [x0, #(8 * 8)] - ldp x11, x12, [x0, #(8 * 10)] - ldp x13, x14, [x0, #(8 * 12)] - ldp x15, x16, [x0, #(8 * 14)] - ldp x17, x18, [x0, #(8 * 16)] - ldp x19, x20, [x0, #(8 * 18)] - ldp x21, x22, [x0, #(8 * 20)] - ldp x23, x24, [x0, #(8 * 22)] - ldp x25, x26, [x0, #(8 * 24)] - ldp x27, x28, [x0, #(8 * 26)] - ldp x29, x30, [x0, #(8 * 28)] - - ldr x11, [x0, #(8 * 31)] - ldr x10, [x0, #(8 * 33)] - msr spsr_el1, x10 - lsr x18, x10, #2 - and x18, x18, #0b11 - - cmp x18, #1 + ldp x0, x1, [x18, #(8 * 0)] + ldp x2, x3, [x18, #(8 * 2)] + ldp x4, x5, [x18, #(8 * 4)] + ldp x6, x7, [x18, #(8 * 6)] + ldp x8, x9, [x18, #(8 * 8)] + ldp x10, x11, [x18, #(8 * 10)] + ldp x12, x13, [x18, #(8 * 12)] + ldp x14, x15, [x18, #(8 * 14)] + ldr x16, [x18, #(8 * 16)] + ldr x19, [x18, #(8 * 19)] + ldp x20, x21, [x18, #(8 * 20)] + ldp x22, x23, [x18, #(8 * 22)] + ldp x24, x25, [x18, #(8 * 24)] + ldp x26, x27, [x18, #(8 * 26)] + ldp x28, x29, [x18, #(8 * 28)] + ldr x30, [x18, #(8 * 30)] + + ldr x17, [x18, #(8 * 33)] + msr spsr_el1, x17 + lsr x17, x17, #2 + and x17, x17, #0b11 + + cmp x17, #1 b.eq 1f - cmp x18, #0 + cmp x17, #0 b.eq 2f b 3f -1: mov sp, x11 +1: ldr x17, [x18, #(8 * 31)] + mov sp, x17 b 3f -2: msr sp_el0, x11 +2: ldr x17, [x18, #(8 * 31)] + msr sp_el0, x17 3: - mov x29, x11 - ldr x11, [x0, #(8 * 32)] - msr elr_el1, x11 - - mov x0, x15 + mov x29, x17 + ldr x17, [x18, #(8 * 32)] + msr elr_el1, x17 + + mov x17, #0 + mov x18, #0 eret \ No newline at end of file diff --git a/kernel/process/process.h b/kernel/process/process.h index ff8da5cd..1ce05785 100644 --- a/kernel/process/process.h +++ b/kernel/process/process.h @@ -62,11 +62,11 @@ typedef struct { } process_t; //Helper functions for accessing registers mapped to scratch regs -#define PROC_X0 regs[14] -#define PROC_X1 regs[0] -#define PROC_X2 regs[1] -#define PROC_X3 regs[2] -#define PROC_X4 regs[3] +#define PROC_X0 regs[0] +#define PROC_X1 regs[1] +#define PROC_X2 regs[2] +#define PROC_X3 regs[3] +#define PROC_X4 regs[4] // #define PROC_FP regs[12] // #define PROC_LR regs[11] // #define PROC_SP regs[10] From 987dcf2724ae0785142dd1ddfcea8b2db9d8bf09 Mon Sep 17 00:00:00 2001 From: dif Date: Sun, 28 Sep 2025 00:00:00 +0000 Subject: [PATCH 8/8] [CI] including fs --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08abd0dc..466cbe5e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,4 +60,4 @@ jobs: shared/libshared.a shared/*.h shared/**/*.h - fs/redos/user/*.elf \ No newline at end of file + fs/* \ No newline at end of file