Compare commits
No commits in common. "6902b49be2d3f27091cfbb91cd41ea5d34c51c1a" and "ff71a50db7f057350405535ef8d08f7460aac832" have entirely different histories.
6902b49be2
...
ff71a50db7
4
Makefile
4
Makefile
@ -25,8 +25,8 @@ bldtst_llvm: buildtest.c arch/*.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
|
||||
|
||||
bldtst_aarch64: buildtest.c arch/aarch64.c
|
||||
bldtst_aarch64: buildtest.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 arch/mips.c
|
||||
bldtst_mips32: buildtest.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,45 +14,19 @@ void exit(int8_t status){
|
||||
|
||||
intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
||||
intptr_t n_written = 0;
|
||||
//register int32_t fd_w asm("w0") = fd;
|
||||
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, #64\n" // Syscall number for 'write' is 64 in AArch64
|
||||
"svc #0\n" // Make syscall
|
||||
"mov %0, x0\n" // Store return value in n_written
|
||||
// Output operands
|
||||
: "=r"(n_written)
|
||||
// Input operands
|
||||
: "r"((int64_t)fd), "r" (buf), "r"(size)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x2", "x8"
|
||||
"mov x0, %2\n"
|
||||
"mov x1, %0\n"
|
||||
"mov x2, %1\n"
|
||||
"mov x8, #64\n"
|
||||
"svc #0\n"
|
||||
: //TODO: n_written
|
||||
: "r" (buf), "r"(size), "r"(fd)
|
||||
: "x0", "x8" // Clobbered registers
|
||||
);
|
||||
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_CLEARTID 0x200000
|
||||
uint32_t fork(){
|
||||
|
||||
@ -3,12 +3,8 @@
|
||||
|
||||
|
||||
int main() {
|
||||
// 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
|
||||
char msg[17] = {' '};
|
||||
msg[16] = '\n';
|
||||
@ -25,7 +21,7 @@ int main() {
|
||||
if(pid == 0) return 0;
|
||||
//TODO: wait on child to remove zombie process
|
||||
|
||||
#if defined(__x86_64__) || defined(__aarch64__)
|
||||
#if defined(__x86_64__)
|
||||
// Test the read syscall
|
||||
#define INPUT_BUFFER_LEN 4096
|
||||
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user