diff --git a/code/os/02-memanagement/page.c b/code/os/02-memanagement/page.c index b0f19246df37c9c11358c3cd039bb36e1a2b1a5f..fddddd40d02ef5a0d90cfccc35e53205c241f7b7 100644 --- a/code/os/02-memanagement/page.c +++ b/code/os/02-memanagement/page.c @@ -117,8 +117,8 @@ void *page_alloc(int npages) * meet a free page, continue to check if following * (npages - 1) pages are also unallocated. */ - struct Page *page_j = page_i; - for (int j = i; j < (i + npages); j++) { + struct Page *page_j = page_i+1; + for (int j = i+1; j < (i + npages); j++) { if (!_is_free(page_j)) { found = 0; break; diff --git a/code/os/03-contextswitch/entry.S b/code/os/03-contextswitch/entry.S index e952564bf60f1d4153370bd2a837d89ed88b7b99..d4b5818bd9fdc51b0efd32332f8cdd2782885a2f 100644 --- a/code/os/03-contextswitch/entry.S +++ b/code/os/03-contextswitch/entry.S @@ -89,8 +89,9 @@ .align 4 switch_to: csrrw t6, mscratch, t6 # swap t6 and mscratch - beqz t6, 1f # Notice: previous task may be NULL - reg_save t6 # save context of prev task + beqz t6, 1f # Notice: if this is the first time to run, t6 will be NULL, + # because after sched_init, mscratch is NULL + reg_save t6 # save context of current task # Save the actual t6 register, which we swapped into # mscratch diff --git a/code/os/04-multitask/sched.c b/code/os/04-multitask/sched.c index 85259df39672240de0cec02f809b3771d5ec4160..1bb3bfd1df19c14818bd51e9f45f57dff4f538c6 100644 --- a/code/os/04-multitask/sched.c +++ b/code/os/04-multitask/sched.c @@ -43,7 +43,7 @@ void schedule() /* * DESCRIPTION * Create a task. - * - start_routin: task routune entry + * - start_routin: task routine entry * RETURN VALUE * 0: success * -1: if error occured