wrote a shell but have an error will debug tomorrow

This commit is contained in:
2025-07-29 21:48:16 +03:00
parent bc9fa4eac7
commit cfffd14b4b
7 changed files with 86 additions and 22 deletions

21
user.c
View File

@@ -1,13 +1,32 @@
#include "user.h"
#include "common.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;
__asm__ __volatile__("ecall"
: "=r"(a0)
: "r"(a0), "r"(a1), "r"(a2), "r"(a3)
: "memory");
return a0;
}
__attribute__((noreturn)) void exit(void) {
for(;;);
}
void putchar(char ch) {
// TODO
syscall(SYS_PUTCHAR, ch, 0, 0);
}
int getchar(void) {
return syscall(SYS_GETCHAR, 0, 0, 0);
}
__attribute__((section(".text.start")))