04208f9d61288122baa4fb05adad9fe99726e01b
[akaros.git] / kern / arch / sparc / process.c
1 #include <arch/arch.h>
2 #include <arch/trap.h>
3 #include <arch/frontend.h>
4 #include <process.h>
5 #include <pmap.h>
6 #include <smp.h>
7
8 #include <string.h>
9 #include <assert.h>
10 #include <stdio.h>
11
12 #ifdef __SHARC__
13 #pragma nosharc
14 #endif
15
16 // architecture-specific process initialization code
17 void
18 proc_init_arch(struct proc *SAFE p)
19 {
20         pid_t parent_id = p->ppid, id = p->pid;
21         int32_t errno;
22         if(frontend_syscall(parent_id,RAMP_SYSCALL_proc_init,id,0,0,0,&errno))
23                 panic("Front-end server couldn't initialize new process!");
24 }
25
26 // architecture-specific process termination code
27 void
28 proc_free_arch(struct proc *SAFE p)
29 {
30         int32_t errno;
31         if(frontend_syscall(0,RAMP_SYSCALL_proc_free,p->pid,0,0,0,&errno))
32                 panic("Front-end server couldn't free process!");
33 }
34
35 void
36 proc_set_program_counter(trapframe_t *tf, uintptr_t pc)
37 {
38         tf->pc = pc;
39         tf->npc = pc+4;
40 }
41
42 void
43 proc_init_trapframe(trapframe_t *tf, uint32_t vcoreid)
44 {
45         extern char trap_table;
46
47         memset(tf,0,sizeof(*tf));
48         tf->gpr[14] = USTACKTOP-96;
49         tf->psr = PSR_S; // but PS = 0
50
51         // unused
52         //tf->wim = 0;
53         //tf->tbr = (uint32_t)&trap_table;
54
55         proc_set_tfcoreid(tf,vcoreid);
56 }
57
58 void proc_set_tfcoreid(trapframe_t *tf, uint32_t id)
59 {
60         tf->asr13 = id;
61 }
62
63 /* For cases that we won't return from a syscall via the normal path, and need
64  * to set the syscall return value in the registers manually.  Like in a syscall
65  * moving to RUNNING_M */
66 void proc_set_syscall_retval(trapframe_t *SAFE tf, intreg_t value)
67 {
68         tf->gpr[8] = value;
69 }