From 549099384589fcbca3f7bc2f9b60473708f22e82 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 15 Jul 2019 16:39:13 -0700 Subject: [PATCH] 5406 Bugfix eight: incorrect segment count in ELF header. The generated examples/ex1 is still not right. But it has the second segment now. Or almost all of it. Final byte is missing for some reason. --- subx/apps/survey | Bin 40460 -> 40460 bytes subx/apps/survey.subx | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/subx/apps/survey b/subx/apps/survey index 62ee325e6ee7b45ef0ed5ec49ae4f93bc2662d8a..93e7afc1c3237b330234a0eeeea3273bc9b9f9b6 100755 GIT binary patch delta 15 WcmeC#!_>2fX#;l*qrhUG7$*QOX$1-Z delta 15 WcmeC#!_>2fX#;l*qrzgI7$*QOxdj>k diff --git a/subx/apps/survey.subx b/subx/apps/survey.subx index 0a167132..58de2b66 100644 --- a/subx/apps/survey.subx +++ b/subx/apps/survey.subx @@ -2619,7 +2619,7 @@ $emit-headers:end: emit-elf-header: # out : (address buffered-file), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info}) # pseudocode # *Elf_e_entry = get(labels, "Entry")->address - # *Elf_e_phnum = segments->write / 20 # size of a row + # *Elf_e_phnum = segments->write / 16 # size of a row # emit-hex-array(out, Elf_header) # # . prolog @@ -2645,13 +2645,13 @@ emit-elf-header: # out : (address buffered-file), segments : (address stream {s 8b/copy 1/mod/*+disp8 0/rm32/EAX . . . 0/r32/EAX 8/disp8 . # copy *(EAX+8) to EAX # . *Elf_e_entry = EAX 89/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/EAX Elf_e_entry/disp32 # copy EAX to *Elf_e_entry - # *Elf_e_phnum = segments->write / 0x20 + # *Elf_e_phnum = segments->write / 0x10 # . EAX = segments 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 0xc/disp8 . # copy *(EBP+12) to EAX # . len/EAX = segments->write 8b/copy 0/mod/indirect 0/rm32/EAX . . . 0/r32/EAX . . # copy *EAX to EAX - # . EAX = len / 0x20 (destroying EDX) - b9/copy-to-ECX 0x20/imm32 + # . EAX = len / 0x10 (destroying EDX) + b9/copy-to-ECX 0x10/imm32 31/xor 3/mod/direct 2/rm32/EDX . . . 2/r32/EDX . . # clear EDX f7 7/subop/idiv 3/mod/direct 1/rm32/ECX . . . . . . # divide EDX:EAX by ECX, storing quotient in EAX and remainder in EDX # . *Elf_e_phnum = EAX