Load raw C binary + docs
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
bits 64
|
||||
global _start
|
||||
extern main
|
||||
|
||||
section .text
|
||||
|
||||
; Begin the program with main() function
|
||||
_start:
|
||||
call main
|
||||
|
||||
; Exit the program by exit() syscall
|
||||
.exit:
|
||||
mov rdi, rax ; put the value of "return X;" (rax) as arg1 (error_code)
|
||||
mov rax, 60 ; sys_exit
|
||||
int 0x80
|
||||
|
||||
.loop:
|
||||
jmp .loop
|
||||
@@ -0,0 +1,22 @@
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x400000;
|
||||
|
||||
.text : {
|
||||
*(.text*)
|
||||
}
|
||||
|
||||
.rodata : {
|
||||
*(.rodata*)
|
||||
}
|
||||
|
||||
.data : {
|
||||
*(.data*)
|
||||
}
|
||||
|
||||
.bss : {
|
||||
*(.bss*)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
// 3 because 3 arguments to the call, get it??
|
||||
static inline long syscall3(long n, long a, long b, long c) {
|
||||
long ret;
|
||||
|
||||
__asm__ volatile (
|
||||
"int $0x80"
|
||||
: "=a"(ret)
|
||||
: "a"(n), "D"(a), "S"(b), "d"(c)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void write(int fd, const char* buf, long len) {
|
||||
syscall3(1, fd, (long)buf, len);
|
||||
}
|
||||
|
||||
static inline void exit(int code) {
|
||||
__asm__ volatile (
|
||||
"int $0x80"
|
||||
:
|
||||
: "a"(60), "D"(code)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
for (;;);
|
||||
}
|
||||
Reference in New Issue
Block a user