Compare commits
3 Commits
ff71a50db7
...
6902b49be2
| Author | SHA1 | Date | |
|---|---|---|---|
| 6902b49be2 | |||
| c2d03d048a | |||
| d37d65b500 |
4
Makefile
4
Makefile
@ -25,8 +25,8 @@ bldtst_llvm: buildtest.c arch/*.c
|
|||||||
bldtst_x64: buildtest.c arch/x86_64.c
|
bldtst_x64: buildtest.c arch/x86_64.c
|
||||||
clang --target=x86_64-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -o bldtst_x64 buildtest.c arch/x86_64.c
|
clang --target=x86_64-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -o bldtst_x64 buildtest.c arch/x86_64.c
|
||||||
|
|
||||||
bldtst_aarch64: buildtest.c
|
bldtst_aarch64: buildtest.c arch/aarch64.c
|
||||||
clang --target=aarch64-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -o bldtst_aarch64 buildtest.c arch/aarch64.c
|
clang --target=aarch64-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -o bldtst_aarch64 buildtest.c arch/aarch64.c
|
||||||
|
|
||||||
bldtst_mips32: buildtest.c
|
bldtst_mips32: buildtest.c arch/mips.c
|
||||||
clang --target=mips-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -fno-pic -o bldtst_mips32 buildtest.c arch/mips.c
|
clang --target=mips-linux-gnu -nostdlib -Wno-incompatible-library-redeclaration -static -fuse-ld=lld -fno-stack-protector -fno-pic -o bldtst_mips32 buildtest.c arch/mips.c
|
||||||
|
|||||||
@ -14,19 +14,45 @@ void exit(int8_t status){
|
|||||||
|
|
||||||
intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
||||||
intptr_t n_written = 0;
|
intptr_t n_written = 0;
|
||||||
|
//register int32_t fd_w asm("w0") = fd;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"mov x0, %2\n"
|
// Assembly Instructions
|
||||||
"mov x1, %0\n"
|
"mov x0, %1\n" // Set x0 to value of fd
|
||||||
"mov x2, %1\n"
|
"mov x1, %2\n" // Set x1 to value of buf
|
||||||
"mov x8, #64\n"
|
"mov x2, %3\n" // Set x2 to value of size
|
||||||
"svc #0\n"
|
"mov x8, #64\n" // Syscall number for 'write' is 64 in AArch64
|
||||||
: //TODO: n_written
|
"svc #0\n" // Make syscall
|
||||||
: "r" (buf), "r"(size), "r"(fd)
|
"mov %0, x0\n" // Store return value in n_written
|
||||||
: "x0", "x8" // Clobbered registers
|
// Output operands
|
||||||
|
: "=r"(n_written)
|
||||||
|
// Input operands
|
||||||
|
: "r"((int64_t)fd), "r" (buf), "r"(size)
|
||||||
|
// Clobbered registers
|
||||||
|
: "x0", "x1", "x2", "x8"
|
||||||
);
|
);
|
||||||
return n_written;
|
return n_written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intptr_t read(int32_t fd, const void* buf, intptr_t size){
|
||||||
|
intptr_t n_read = 0;
|
||||||
|
asm volatile(
|
||||||
|
// Assembly Instructions
|
||||||
|
"mov x0, %1\n" // Set x0 to value of fd
|
||||||
|
"mov x1, %2\n" // Set x1 to value of buf
|
||||||
|
"mov x2, %3\n" // Set x2 to value of size
|
||||||
|
"mov x8, #63\n" // Syscall number for 'read' is 63 in AArch64
|
||||||
|
"svc #0\n" // Make syscall
|
||||||
|
"mov %0, x0\n" // Store return value in n_read
|
||||||
|
// Output operands
|
||||||
|
: "=r"(n_read)
|
||||||
|
// Input operands
|
||||||
|
: "r"((int64_t)fd), "r" (buf), "r"(size)
|
||||||
|
// Clobbered registers
|
||||||
|
: "x0", "x1", "x2", "x8"
|
||||||
|
);
|
||||||
|
return n_read;
|
||||||
|
}
|
||||||
|
|
||||||
#define CLONE_CHILD_SETTID 0x1000000
|
#define CLONE_CHILD_SETTID 0x1000000
|
||||||
#define CLONE_CHILD_CLEARTID 0x200000
|
#define CLONE_CHILD_CLEARTID 0x200000
|
||||||
uint32_t fork(){
|
uint32_t fork(){
|
||||||
|
|||||||
@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
uint64_t pid = fork();
|
// Test the write syscall
|
||||||
|
intptr_t n = write(STDIO, "Hello\n", 6);
|
||||||
|
if(n != 6) return n;
|
||||||
|
|
||||||
|
// Test the fork syscall
|
||||||
|
uint64_t pid = fork();
|
||||||
// Print the pid in hex
|
// Print the pid in hex
|
||||||
char msg[17] = {' '};
|
char msg[17] = {' '};
|
||||||
msg[16] = '\n';
|
msg[16] = '\n';
|
||||||
@ -21,7 +25,7 @@ int main() {
|
|||||||
if(pid == 0) return 0;
|
if(pid == 0) return 0;
|
||||||
//TODO: wait on child to remove zombie process
|
//TODO: wait on child to remove zombie process
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__) || defined(__aarch64__)
|
||||||
// Test the read syscall
|
// Test the read syscall
|
||||||
#define INPUT_BUFFER_LEN 4096
|
#define INPUT_BUFFER_LEN 4096
|
||||||
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
||||||
|
|||||||
2
sys.h
2
sys.h
@ -6,7 +6,7 @@ void exit(int8_t status);
|
|||||||
#define STDIO 1
|
#define STDIO 1
|
||||||
#define STDERR 2
|
#define STDERR 2
|
||||||
intptr_t write(int32_t fd, const void* buf, intptr_t size);
|
intptr_t write(int32_t fd, const void* buf, intptr_t size);
|
||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__) || defined(__aarch64__)
|
||||||
intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user