Compare commits
No commits in common. "f4b2c5477b741a0d0313e7ff8865c934deb79366" and "80d5606a81c5fe1d28705ce789c9acf66be0f479" have entirely different histories.
f4b2c5477b
...
80d5606a81
16
Makefile
16
Makefile
@ -1,20 +1,20 @@
|
||||
all: print print_x64 print_aarch64 print_mips32
|
||||
|
||||
clean:
|
||||
if test -f print; then rm print; fi
|
||||
if test -f print_x64; then rm print_x64; fi
|
||||
if test -f print_aarch64; then rm print_aarch64; fi
|
||||
if test -f print_mips32; then rm print_mips32; fi
|
||||
rm print
|
||||
rm print_x64
|
||||
rm print_aarch64
|
||||
rm print_mips32
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
print:
|
||||
gcc -static -nostdlib -fno-stack-protector -o print print.c
|
||||
gcc -static -nostdlib -o print print.c
|
||||
print_x64: print.c
|
||||
clang --target=x86_64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o print_x64 print.c
|
||||
clang --target=x86_64-linux-gnu -nostdlib -static -fuse-ld=lld -o print_x64 print.c
|
||||
|
||||
print_aarch64: print.c
|
||||
clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o print_aarch64 print.c
|
||||
clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -o print_aarch64 print.c
|
||||
|
||||
print_mips32: print.c
|
||||
clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -fno-pic -o print_mips32 print.c
|
||||
clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-pic -o print_mips32 print.c
|
||||
|
||||
38
print.c
38
print.c
@ -30,9 +30,9 @@ long print(const void *buf, long count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__aarch64__)
|
||||
#define CLONE_CHILD_SETTID 0x1000000
|
||||
#define CLONE_CHILD_CLEARTID 0x200000
|
||||
#if defined(__aarch64__)
|
||||
long int fork() {
|
||||
long int rtn;
|
||||
long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID;
|
||||
@ -42,8 +42,8 @@ long int fork() {
|
||||
"mov x0, %1\n" // clone flags
|
||||
"mov x1, #0\n" // child stack pointer
|
||||
"mov x2, #0\n" // parent_tidptr
|
||||
"mov x3, #0\n" // tls
|
||||
"mov x4, #0\n" // child_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
|
||||
@ -55,34 +55,6 @@ long int fork() {
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
#elif defined(__x86_64__)
|
||||
long int fork() {
|
||||
long int rtn;
|
||||
/*
|
||||
long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID;
|
||||
asm volatile(
|
||||
"movq %%rax, 56\n" // syscall number for 'clone' is 56 for x86-64
|
||||
"movq %%rdi, %1\n" // clone flags
|
||||
"movq %%rsi, 0\n" // child stack pointer
|
||||
"movq %%rdx, 0\n" // parent tidptr
|
||||
"movq %%r10, 0\n" // child tidptr
|
||||
"movq %%r8, 0\n" // tls
|
||||
"syscall\n" // syscall
|
||||
"movq %0, %%rax\n" // save return value
|
||||
: "=r"(rtn)
|
||||
: "r"(flags)
|
||||
: "rax", "rdi", "rsi", "rdx", "r10", "r8", "r9", "r10", "r11"
|
||||
);
|
||||
*/
|
||||
asm volatile(
|
||||
"syscall\n" // syscall
|
||||
"movq %0, %%rax\n" // save return value
|
||||
: "=r"(rtn)
|
||||
: "a"(57)
|
||||
:
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
#endif
|
||||
|
||||
void exit(int status) {
|
||||
@ -115,7 +87,7 @@ void exit(int status) {
|
||||
|
||||
|
||||
int main() {
|
||||
#if defined(__x86_64__) || defined(__aarch64__)
|
||||
#if defined(__aarch64__)
|
||||
long int pid = fork();
|
||||
char msg[17] = {' '};
|
||||
msg[16] = '\n';
|
||||
@ -127,7 +99,7 @@ int main() {
|
||||
msg[i] = c;
|
||||
}
|
||||
print(msg, 17);
|
||||
#else
|
||||
#elif
|
||||
char *msg = "Hello World!\n";
|
||||
print(msg, 13);
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user