From c9c3f239c8b6554b3b9b8ba4a5bff68232f9e916 Mon Sep 17 00:00:00 2001 From: janis Date: Fri, 5 Jun 2026 08:15:21 +0200 Subject: [PATCH] fixes --- stages/hex1/elf.asm | 12 +++++++----- stages/hex1/elf.in | 29 ++++++++++++++++------------- stages/hex1/hex1.in | 7 +++++-- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/stages/hex1/elf.asm b/stages/hex1/elf.asm index bd74c85..fff163d 100644 --- a/stages/hex1/elf.asm +++ b/stages/hex1/elf.asm @@ -36,15 +36,15 @@ fsize: mov rax, [rsi + 48] ; st_size ret -;; rdi: dst -;; rsi: src +;; rdi: src +;; rsi: dst ;; rdx: len memcpy: .memcpy_loop: test rdx, rdx jz .memcpy_done - mov al, byte [rsi] - mov byte [rdi], al + mov al, byte [rdi] + mov byte [rsi], al inc rsi inc rdi dec rdx @@ -62,6 +62,7 @@ memcpy: ;; +0x1010 argc: u32 ;; +0x1018 argv: *const *const u8 +global _start _start: mov eax, dword [rsp] ; argc lea rbx, [rsp + 8] ; argv @@ -98,7 +99,7 @@ _start: ;; copy program header to scratch space mov rdi, 0x400040 - mov rsi, [r15 + 0x40] + lea rsi, [r15 + 0x40] mov rdx, 0x38 call memcpy @@ -110,6 +111,7 @@ _start: ;; write e_entry to point at 0x40 + 0x38 + in_size - 5 sub rax, 5 + add rax, 0x400000 mov dword [r15 + 24], eax ; write e_entry ;; write Ehdr and Phdr to output file diff --git a/stages/hex1/elf.in b/stages/hex1/elf.in index dbf9d0d..1dd7c73 100644 --- a/stages/hex1/elf.in +++ b/stages/hex1/elf.in @@ -20,8 +20,8 @@ 3e 00 ; e_version: u32 = EV_CURRENT 01 00 00 00 -; e_entry: u64 = 0x400078 -78 00 40 00 00 00 00 00 +; e_entry: u64 = 0x400078 + 0x5c +d4 00 40 00 00 00 00 00 ; e_phoff: u64 = 0x40 40 00 00 00 00 00 00 00 ; e_shoff: u64 = 0x0 @@ -54,9 +54,9 @@ ; p_paddr: u64 = 0x0 00 00 00 00 00 00 00 00 ; p_filesz: u64 = 0x167 -67 01 00 00 00 00 00 00 +ef 01 00 00 00 00 00 00 ; p_memsz: u64 = 0x167 -67 01 00 00 00 00 00 00 +ef 01 00 00 00 00 00 00 ; p_align: u64 = 0x1000 00 10 00 00 00 00 00 00 ; End of program header @@ -118,16 +118,16 @@ e8 f1 ff ff ff 48 8b 46 30 ; ret c3 - +; ; @memcpy: ; test rdx, rdx 48 85 d2 ; jz 'memcpy_exit 74 0f -; mov al, byte [rsi] -8a 06 -; mov byte [rdi], al -88 07 +; mov al, byte [rdi] +8a 07 +; mov byte [rsi], al +88 06 ; inc rsi 48 ff c6 ; inc rdi @@ -199,8 +199,8 @@ e8 6b ff ff ff ; ; mov edi, 0x400040 bf 40 00 40 00 -; mov rsi, [r15+0x40] -49 8b 77 40 +; lea rsi, [r15+0x40] +49 8d 77 40 ; mov edx, 0x38 (size) ba 38 00 00 00 ; call 'memcpy @@ -217,6 +217,8 @@ b8 78 00 00 00 ; ; sub rax, 5 48 83 e8 05 +; add rax, 0x400000 +48 05 00 00 40 00 ; mov dword [r15+0x18], eax (store file end - 5) 41 89 47 18 ; @@ -244,7 +246,7 @@ b8 00 00 00 00 ; test rax, rax 48 85 c0 ; jle 'die -0f 8e c0 fe ff ff +0f 8e ba fe ff ff ; ; mov dword [r15+0x1000], eax (store bytes read) 41 89 87 00 10 00 00 @@ -263,4 +265,5 @@ b8 01 00 00 00 ; jz 'write_loop 74 b5 ; call 'die -e8 8f fe ff ff \ No newline at end of file +e8 89 fe ff ff +; end \ No newline at end of file diff --git a/stages/hex1/hex1.in b/stages/hex1/hex1.in index 7c2ae4f..d2d0706 100644 --- a/stages/hex1/hex1.in +++ b/stages/hex1/hex1.in @@ -200,7 +200,7 @@ e8 d8 ff ff ff ; jnz 'skip_line_read (+414) 0f 85 f3 ff ff ff ; call 'rd_buf (+419) -e8 cd ff ff ff +e8 cb ff ff ff ; ret c3 ; @@ -400,7 +400,7 @@ e9 cf ff ff ff ; lea rdi, [r15+0x6004] 49 8d bf 04 60 00 00 ; call 'push_lbl (+770) -e8 3d fd ff ff +e8 3b fd ff ff ; ret c3 ; @not_label: (+771) @@ -463,3 +463,6 @@ e8 57 fe ff ff e8 80 ff ff ff ; jmp 'main_loop (+910) e9 ec ff ff ff +; jmp 'main +e9 a2 ff ff ff +; end \ No newline at end of file