Created
October 5, 2019 21:51
-
-
Save benmezger/b06d99c29a9205c6f3403c887e3c5767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
switch_to_process(process_t *proc) | |
{ | |
/* Set the entry point in MEPC */ | |
asm volatile("csrw mepc, %0" ::"r"(proc->entrypoint)); | |
asm volatile("mv ra, %0" ::"r"(proc->regf->ra)); | |
asm volatile("mv sp, %0" ::"r"(proc->regf->sp)); | |
asm volatile("mv a0, %0" ::"r"(proc)); | |
asm volatile("mret"); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
..... | |
if (!(kcontext->user_context = malloc(sizeof(uctxt_t *)))) { | |
log_fatal("Error allocating memory for user context"); | |
} | |
kcontext->user_context->regf = create_regf(1000); | |
kcontext->user_context->total_procs = 0; | |
_init_timer_intrp(kcontext); | |
log_info("Droping to user-mode"); | |
drop_to_mode( | |
PRIVILEGE_USER, kcontext->user_context, user_mode_entrypoint); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
kexcep_timer_handler(int id, void *data) | |
{ | |
kctxt_t *kcontext = (kctxt_t *)data; | |
disable_timer(kcontext->timer_intrid); | |
sched(kcontext, kcontext->user_context->total_procs); | |
metal_cpu_set_mtimecmp( | |
kcontext->cpu, metal_cpu_get_mtime(kcontext->cpu) + RTC_FREQ); | |
log_warn( | |
"[kexcep_timer_handler] | Exception | Timer interrupt %p | id %d | mtime %ld | timebase %ld", | |
kcontext->timer_intr, id, metal_cpu_get_mtime(kcontext->cpu), | |
metal_cpu_get_timebase(kcontext->cpu)); | |
enable_timer(kcontext->timer_intrid); | |
// return_from_excp(kctxt->cpu, id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
process_a(void *data) | |
{ | |
for (;;) { | |
printf("Hello, from Process A"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment