summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-07-13 18:38:33 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-07-13 18:38:33 +0200
commit85c9255ab4f56a8c88a3b1910f1d792ea76def16 (patch)
tree0f897daffee71706304a3d710c5e146deb39dca2
parentde116cec9ce8a250a5c9f8c5953c85dac7779d89 (diff)
downloadbxgen-85c9255ab4f56a8c88a3b1910f1d792ea76def16.zip
Update asm example
-rwxr-xr-xbxgen.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/bxgen.c b/bxgen.c
index 95a3e03..d64f6b2 100755
--- a/bxgen.c
+++ b/bxgen.c
@@ -1046,6 +1046,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
//
// Online assembler
// https://defuse.ca/online-x86-assembler.htm
+ // https://shell-storm.org/online/Online-Assembler-and-Disassembler/
BX_ASSERT(pool != NULL && pool->entities != NULL);
BX_ASSERT(pool->entities[unit].is_enabled);
@@ -1089,11 +1090,10 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
#define WRITE_4(x) io_write( io_out, 4, &(u32) { x }, io_user_data )
#define WRITE_8(x) io_write( io_out, 8, &(u64) { x }, io_user_data )
- u8 code[16] = {
- 0xb8, // mov rax
- 0x3c, 0, 0, 0, // 60 // exit
- 0x48, 0x31, 0xff, // xor rdx, rdx // rdx = 0
- 0x0f, 0x05, // syscall
+ u8 code[32] = {
+ 0xb8, 0x3c, 0x00, 0x00, 0x00, // mov eax, 60
+ 0xbf, 0x2a, 0x00, 0x00, 0x00, // mov edi, 42
+ 0x0f, 0x05, // syscall
};
u64 code_offset = bx_align(ELF_HEADER_SIZE + ELF_PROGRAM_HEADER_SIZE, X86_64_ALIGNMENT);
@@ -2078,7 +2078,7 @@ void bx_assert(b8 condition, c8 const *message, u32 line, c8 const *file) {
fflush(stdout);
fprintf(stderr, "\r\x1b[31mASSERTION:\x1b[37m `\x1b[33m%s\x1b[37m` is false in \x1b[36m%s:%d\x1b[37m\n", message, file, line);
- abort();
+ exit(-1);
}
// IO dispatch procedure
@@ -2281,6 +2281,10 @@ int main(int argc, char **argv) {
printf("Writing ELF x86_64 executable...\n");
u_elf_x86_64(u, "test_foo");
+ i32 ret = system("./test_foo");
+
+ BX_ASSERT(WEXITSTATUS(ret) == 42);
+
printf("\nBye!\n");
return 0;
}