rems-project / rmem

rmem public repo
Other
40 stars 9 forks source link

How to prepare ELF files to run with rmem? #5

Closed db7 closed 5 years ago

db7 commented 5 years ago

We'd like to try some small ELF files with the tool, so I started with a NOP instruction.

It looks like this:

% aarch64-linux-gnu-objdump -D nop.elf

nop.elf:     file format elf64-littleaarch64

Disassembly of section .text.boot:

0000000000080000 <main>:
   80000:   d503201f    nop

When I run that with flat or flatOpt, the tool terminates with an exception because it tries to fetch the next instruction, but there is none.

Unhandled exceptions 1
1     :>thread 0 instruction 0:2: illegal fetch address exception: 0x0000000000080004 via ""

Executing in the interactive mode, I could see that the NOP instruction was executed as expected.

So, how to properly build an ELF file to run with the tool? I'm sorry if that is a very basic question, but I could not find any specific instructions to do that.

db7 commented 5 years ago

Adding a ret as last instruction solved the issue.

PeterSewell commented 5 years ago

We should add some documentation to the help page in any case, including (if it's not already there) the compiler flags to make a standalone binary.

On Fri, 11 Oct 2019 at 12:59, Diogo Behrens notifications@github.com wrote:

Adding a ret as last instruction solved the issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rems-project/rmem/issues/5?email_source=notifications&email_token=ABFMZZQNAWXDC47JLZ2BJI3QOBTDFA5CNFSM4I7XX5D2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA7YRVY#issuecomment-541034711, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFMZZQ3TMIYZQTKI5I7E5DQOBTDFANCNFSM4I7XX5DQ .

db7 commented 5 years ago

That would be very helpful. Also how to start threads. It seems I got it now with this code:

_start:

// start a second thread
        ldr x0,=main
        .word 0xd50bb003

// both threads get here
main:
        ldr x1,=var
        ldr w2,[x1]
        sub w2,w2,#1
        str w2,[x1]
        ret

.section ".data"
var:
    .word 0xDEADBEEF
    .word 0x00000000

But I am not sure whether that is the right way.