67 lines
2.0 KiB
C
67 lines
2.0 KiB
C
long print(const void *buf, long count) {
|
|
#if defined(__x86_64__)
|
|
asm volatile (
|
|
"syscall"
|
|
:
|
|
: "a"(1), "D"(1), "S"(buf), "d"(count) // RDI, RSI, RDX are used in x86-64 for write args
|
|
: "rcx", "r11", "memory"
|
|
);
|
|
#elif defined(__aarch64__)
|
|
asm ( "mov x0, #1\n" // Move the exit status into register x0
|
|
"mov x1, %0\n" // Syscall number for 'exit' is 93 in AArch64
|
|
"mov x2, %1\n" // Syscall number for 'exit' is 93 in AArch64
|
|
"mov x8, #64\n" // Syscall number for 'exit' is 93 in AArch64
|
|
"svc #0\n" // Make the syscall
|
|
: // No output operands
|
|
: "r" (buf), "r"(count) // Input operand: status
|
|
: "x0", "x8" // Clobbered registers
|
|
);
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
void exit(int status) {
|
|
#if defined(__x86_64__)
|
|
asm volatile(
|
|
"syscall"
|
|
:
|
|
: "a"(60), "D"(status)
|
|
:
|
|
);
|
|
#elif defined(__aarch64__)
|
|
asm ( "mov x0, %0\n" // Move the exit status into register x0
|
|
"mov x8, #93\n" // Syscall number for 'exit' is 93 in AArch64
|
|
"svc #0\n" // Make the syscall
|
|
: // No output operands
|
|
: "r" ((long)status) // Input operand: status
|
|
: "x0", "x8" // Clobbered registers
|
|
);
|
|
#endif
|
|
for(;;);
|
|
}
|
|
|
|
|
|
int main() {
|
|
//void _start() {
|
|
char *msg = "Hello World!\n";
|
|
print(msg, 13);
|
|
return 69;
|
|
}
|
|
void __libc_start_main() {exit(main());}
|
|
/*
|
|
#if defined(__x86_64__)
|
|
printf("Compiled for x86_64 architecture\n");
|
|
#elif defined(__i386__)
|
|
printf("Compiled for x86 architecture\n");
|
|
#elif defined(__arm__)
|
|
printf("Compiled for ARM architecture\n");
|
|
#elif defined(__aarch64__)
|
|
printf("Compiled for ARM64 architecture\n");
|
|
#elif defined(__mips__)
|
|
printf("Compiled for ARM architecture\n");
|
|
#else
|
|
printf("Unknown architecture\n");
|
|
#endif
|
|
*/
|
|
|