Files
linux-kernel-module-cheat/userland/arch/x86_64/inline_asm/freestanding/linux/hello.c
Ciro Santilli 六四事件 法轮功 a90271c6af asm: start x86 intrinsics examples
Split userland/arch/<arch>/c/ into inline_asm and intrinsics, and move programs
that don't match either up.
2019-05-31 00:00:00 +00:00

34 lines
782 B
C

/* x86_64 freestanding C inline assemby Linux hello world
* https://github.com/cirosantilli/linux-kernel-module-cheat#linux-system-calls
*/
#define _XOPEN_SOURCE 700
#include <inttypes.h>
#include <sys/types.h>
ssize_t my_write(int fd, const void *buf, size_t size) {
ssize_t ret;
__asm__ __volatile__ (
"syscall"
: "=a" (ret)
: "0" (1), "D" (fd), "S" (buf), "d" (size)
: "cc", "rcx", "r11", "memory"
);
return ret;
}
void my_exit(int exit_status) {
ssize_t ret;
__asm__ __volatile__ (
"syscall"
: "=a" (ret)
: "0" (60), "D" (exit_status)
: "cc", "rcx", "r11", "memory"
);
}
void _start(void) {
char msg[] = "hello\n";
my_exit(my_write(1, msg, sizeof(msg)) != sizeof(msg));
}