47 lines
951 B
C
47 lines
951 B
C
#include "int.h"
|
|
#include "sys.h"
|
|
|
|
|
|
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';
|
|
for(int i = 0; i < 16; ++i) {
|
|
char nibble = (pid >> ((15 - i) * 4)) & 0xf;
|
|
char c;
|
|
if (nibble > 9) {c = nibble + '7';}
|
|
else {c = nibble + '0';}
|
|
msg[i] = c;
|
|
}
|
|
write(STDIO, msg, 17);
|
|
|
|
// Child process exits
|
|
if(pid == 0) return 0;
|
|
//TODO: wait on child to remove zombie process
|
|
|
|
// Test the read syscall
|
|
#define INPUT_BUFFER_LEN 4096
|
|
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
|
write(STDIO, "Enter some text:", 16);
|
|
intptr_t n_read = read(STDIO, input_buffer, INPUT_BUFFER_LEN);
|
|
write(STDIO, input_buffer, n_read);
|
|
|
|
return 69;
|
|
}
|
|
|
|
void __libc_start_main() {exit(main());}
|
|
|
|
void _start() {
|
|
__libc_start_main();
|
|
}
|
|
|
|
void __start() {
|
|
_start();
|
|
}
|