Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fxlin/p1-kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
fxlin committed Feb 27, 2024
2 parents b197521 + ba68f2f commit 913b72f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/exp4b/src/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ el1_irq:
ret_from_fork:
bl schedule_tail
mov x0, x20
blr x19 //should never return
blr x19 // goes to a task's body. should never return. what if it returns?

.globl err_hang
err_hang: b err_hang
2 changes: 1 addition & 1 deletion src/exp4b/src/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int copy_process(unsigned long fn, unsigned long arg)

p->cpu_context.x19 = fn;
p->cpu_context.x20 = arg;
p->cpu_context.pc = (unsigned long)ret_from_fork;
p->cpu_context.pc = (unsigned long)ret_from_fork; // entry.S
p->cpu_context.sp = (unsigned long)p + THREAD_SIZE;
int pid = nr_tasks++;
task[pid] = p;
Expand Down
3 changes: 3 additions & 0 deletions src/exp5/src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ void kernel_process(){
if (err < 0) {
printf("Error while moving process to user mode\n\r");
}
// this func is called from ret_from_fork (entry.S). after returning, it goes back to
// ret_from_fork and does kernel_exit there. hence, pt_regs populated by move_to_user_mode()
// will take effect.
}

void kernel_main(void)
Expand Down
10 changes: 7 additions & 3 deletions src/exp5/src/sched.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ cpu_switch_to:
mov x10, #THREAD_CPU_CONTEXT
add x8, x0, x10
mov x9, sp

// below: all callee-saved registers are stored in the order, in which they are defined in `cpu_context` structure
stp x19, x20, [x8], #16 // store callee-saved registers
stp x21, x22, [x8], #16
stp x23, x24, [x8], #16
stp x25, x26, [x8], #16
stp x27, x28, [x8], #16
stp x29, x9, [x8], #16
str x30, [x8]
add x8, x1, x10
str x30, [x8] // save LR (x30) to cpu_context.pc, pointing to where this function is called from

add x8, x1, x10 // calculate the address of the next task's `cpu_contex`

ldp x19, x20, [x8], #16 // restore callee-saved registers
ldp x21, x22, [x8], #16
ldp x23, x24, [x8], #16
ldp x25, x26, [x8], #16
ldp x27, x28, [x8], #16
ldp x29, x9, [x8], #16
ldr x30, [x8]
ldr x30, [x8] // load cpu_context.pc to x30 == LR
mov sp, x9
ret

Expand Down

0 comments on commit 913b72f

Please sign in to comment.