-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.c
More file actions
31 lines (23 loc) · 928 Bytes
/
Copy pathuser.c
File metadata and controls
31 lines (23 loc) · 928 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
#include "user.h"
extern char __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;
/* trigger the kernel (external call instruction )*/
__asm__ __volatile__("ecall" : "=r"(a0) : "r"(a0), "r"(a1), "r"(a2), "r"(a3) : "memory");
return a0;
}
__attribute__((noreturn)) void exit(void) {
syscall(SYS_EXIT, 0, 0, 0);
for (;;)
;
}
void putchar(char c) { syscall(SYS_PUTCHAR, c, 0, 0); }
int getchar(void) { return syscall(SYS_GETCHAR, 0, 0, 0); }
__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));
}