removed pdclib, strange things were happening..., user shell kinda works now
This commit is contained in:
37
rocklibc/src/syscall.c
Normal file
37
rocklibc/src/syscall.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <syscall.h>
|
||||
|
||||
static inline int syscall1(int num, uint32_t arg1) {
|
||||
int ret;
|
||||
asm volatile (
|
||||
"int $0x80"
|
||||
: "=a"(ret)
|
||||
: "a"(num), "b"(arg1)
|
||||
: "memory"
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* A generic wrapper for a system call with 3 arguments */
|
||||
static inline int syscall3(int num, uint32_t arg1, uint32_t arg2, uint32_t arg3) {
|
||||
int ret;
|
||||
asm volatile (
|
||||
"int $0x80"
|
||||
: "=a"(ret)
|
||||
: "a"(num), "b"(arg1), "c"(arg2), "d"(arg3)
|
||||
: "memory"
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void exit(int status) {
|
||||
syscall1(SYS_EXIT, (uint32_t)status);
|
||||
while(1);
|
||||
}
|
||||
|
||||
int write(int fd, const void* buf, size_t cnt) {
|
||||
return syscall3(SYS_WRITE, (uint32_t)fd, (uint32_t)buf, (uint32_t)cnt);
|
||||
}
|
||||
|
||||
int read(int fd, void* buf, size_t cnt) {
|
||||
return syscall3(SYS_READ, (uint32_t)fd, (uint32_t)buf, (uint32_t)cnt);
|
||||
}
|
||||
Reference in New Issue
Block a user