Add fork support for AARCH64
This commit is contained in:
parent
927556418c
commit
13a0750394
42
print.c
42
print.c
@ -30,6 +30,33 @@ long print(const void *buf, long count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__aarch64__)
|
||||
#define CLONE_CHILD_SETTID 0x1000000
|
||||
#define CLONE_CHILD_CLEARTID 0x200000
|
||||
long int fork() {
|
||||
long int rtn;
|
||||
long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID;
|
||||
asm volatile (
|
||||
// Assembly Instructions
|
||||
"mov x8, #220\n" // Syscall number for 'clone' is 220 in AArch64
|
||||
"mov x0, %1\n" // clone flags
|
||||
"mov x1, #0\n" // child stack pointer
|
||||
"mov x2, #0\n" // parent_tidptr
|
||||
"mov x3, #0\n" // child_tidptr
|
||||
"mov x4, #0\n" // tls
|
||||
"svc #0\n" // Make the syscall
|
||||
"mov %0, x0\n" // save return value
|
||||
// Output operands
|
||||
: "=r" (rtn)
|
||||
// Input operand
|
||||
: "r" (flags)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x2", "x3", "x4", "x8"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
#endif
|
||||
|
||||
void exit(int status) {
|
||||
#if defined(__x86_64__)
|
||||
asm volatile(
|
||||
@ -60,9 +87,22 @@ void exit(int status) {
|
||||
|
||||
|
||||
int main() {
|
||||
//void _start() {
|
||||
#if defined(__aarch64__)
|
||||
long int pid = fork();
|
||||
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;
|
||||
}
|
||||
print(msg, 17);
|
||||
#elif
|
||||
char *msg = "Hello World!\n";
|
||||
print(msg, 13);
|
||||
#endif
|
||||
return 69;
|
||||
}
|
||||
void __libc_start_main() {exit(main());}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user