-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.c
More file actions
43 lines (33 loc) · 883 Bytes
/
user.c
File metadata and controls
43 lines (33 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "user.h"
extern char __stack_top[];
__attribute__((section(".text.start")))
__attribute__((naked))
void start(void) {
__asm__ __volatile__(
"mv sp, %[stack_top] \n"
"call main \n"
"call exit \n"
:
: [stack_top] "r" (__stack_top)
);
}
int syscall(int sysno, int arg0, int arg1, int arg2)
{
register int a0 __asm__("a0") = arg0;
register int a1 __asm__("a1") = arg1;
register int a2 __asm__("a2") = arg2;
register int a3 __asm__("a3") = sysno;
__asm__ __volatile__("ecall"
: "=r"(a0)
: "r"(a0), "r"(a1), "r"(a2), "r"(a3)
: "memory");
return a0;
}
void putchar(char ch) {
syscall(SYS_PUTCHAR, ch, 0, 0);
}
__attribute__((noreturn))
void exit(void) {
syscall(SYS_EXIT, 0, 0, 0);
for (;;);
}