ff2578473f08da312bbbf373d701accda4a5456a
[akaros.git] / kern / arch / i386 / process.c
1 #include <arch/arch.h>
2 #include <arch/trap.h>
3 #include <process.h>
4 #include <smp.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <assert.h>
8
9 void __startcore(trapframe_t *tf)
10 {
11         uint32_t coreid = core_id();
12         struct proc *p_to_run = per_cpu_info[coreid].p_to_run;
13         trapframe_t local_tf, *tf_to_pop = per_cpu_info[coreid].tf_to_pop;
14
15         /* EOI - we received the interrupt.  probably no issues with receiving
16          * further interrupts in this function.  need to do this before
17          * proc_startcore.  incidentally, interrupts are off in this handler
18          * anyways, since it's set up as an interrupt gate for now. */
19         lapic_send_eoi();
20
21         printk("Startcore on core %d\n", coreid);
22         assert(p_to_run);
23         // TODO: handle silly state (HSS)
24         if (!tf_to_pop) {
25                 tf_to_pop = &local_tf;
26                 memset(tf_to_pop, 0, sizeof(*tf_to_pop));
27                 env_init_trapframe(tf_to_pop);
28                 // Note the init_tf sets tf_to_pop->tf_esp = USTACKTOP;
29                 tf_to_pop->tf_regs.reg_eax = 1;
30                 tf_to_pop->tf_eip = p_to_run->env_entry;
31         }
32         proc_startcore(p_to_run, tf_to_pop);
33 }
34
35