Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better indication for beginning of first segment #1

Open
HKhademian opened this issue Jun 18, 2022 · 0 comments
Open

Better indication for beginning of first segment #1

HKhademian opened this issue Jun 18, 2022 · 0 comments

Comments

@HKhademian
Copy link

Hi, I watched your amazing stream about this project.
I noticed that if the entry point was not at the beginning of code segment (by setting entry <label>) the current impelemention do not detect the correct beggining of Machine code. like:

format ELF64 executable 3

SYS_write = 1
SYS_exit = 60
STDOUT = 1

segment readable executable

; <-------- original entry point

; these must not be executed ,
; (but the elf.js parser must shows them in result console as first machine code bytes)
syscall
syscall
syscall

print: ; rsi=str.ptr  rdx=str.size
    mov rax, SYS_write
    mov rdi, STDOUT
    syscall
    ret

exit: ; rdi=retcode
    mov rax, SYS_exit
    syscall
    ret

entry main   ;   <-------- change of entry point of the program
main:
    mov rsi, hello
    mov rdx, hello_sz
    call print

    mov rdi, 0
    call exit

    ret ; UNREACHABLE

segment readable writable
hello: db "Hello, World!", 10
hello_sz = $-hello

now if I run the elf.js parse routine,
It doesn't show repeated syscall bytecode and it gives me:
Ehdr.e_entry = 4194513
Phdrs[0].p_vaddr = 4194304

4194513-4194304 = 209
but the correct offset for beginning of the machine code must remains 64(ElfH)+2*56(ProgH)=176

I think because this project may lead to porth development, it's better to use a better way to detect start of the machine code (separate it from entry point), OR just keep in mind to not change entry point from the start of the segment to other addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant