bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ELF header and footer


From: Danny Milosavljevic
Subject: ELF header and footer
Date: Tue, 2 Jun 2020 16:19:10 +0200

Hi,

in wip-arm, I have lib/linux/arm-mes as completely independent directory.

However, it's quite similar to lib/linux/x86-mes in content.

Summary of diff:

* lib/linux/arm-mes/elf32-footer-single-main.hex2 is identical
* lib/linux/arm-mes/elf32-header.hex2 is almost identical
* lib/linux/x86-mes/elf32-0header.hex2 is almost identical (!!)
* lib/linux/arm-mes/elf32-0hello-mes.hex2 is different-ish
* lib/linux/arm-mes/elf32-body-exit-42.hex2 is different-ish
* lib/linux/arm-mes/elf32-body-hello-mes.hex2 is different-ish
* lib/linux/arm-mes/elf32-0exit-42.hex2 is almost completely different

Diff:

diff -ru lib/linux/x86-mes/elf32-0exit-42.hex2 
lib/linux/arm-mes/elf32-0exit-42.hex2
--- lib/linux/x86-mes/elf32-0exit-42.hex2       2020-06-01 21:28:22.903358379 
+0200
+++ lib/linux/arm-mes/elf32-0exit-42.hex2       2020-06-02 00:56:17.621474322 
+0200
@@ -1,5 +1,6 @@
 ### GNU Mes --- Maxwell Equations of Software
-### Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
 ###
 ### This file is part of GNU Mes.
 ###
@@ -18,7 +19,7 @@
 
 ### Commentary:
 
-# elf32-exit-42.hex2: `exit 42' for i686-linux written in hex2 assembly,
+# elf32-exit-42.hex2: `exit 42' for arm-linux written in hex2 assembly,
 # for usage with elf32-0header.hex2.  This produces a 112-byte binary
 # (70 hex).  Inspiration was taken from GNU Gcc output of exit-42.S.
 
@@ -26,9 +27,8 @@
 
 # @60
 :ELF_text
-b8 01 00 00 00                 # mov    $1, %eax
-bb 2a 00 00 00                 # mov    $42, %ebx
-cd 80                          # int    $0x80
-f4                             # hlt
-00 00 00                       # align to @70
+01 70 a0 e3                    # mov    r7,$0x1
+2a 00 a0 e3                    # mov    r0,$0x2a
+00 00 00 ef                    # swi    0
+03 f0 20 e3                    # wfi
 :ELF_end
diff -ru lib/linux/x86-mes/elf32-0header.hex2 
lib/linux/arm-mes/elf32-0header.hex2
--- lib/linux/x86-mes/elf32-0header.hex2        2020-06-01 21:28:22.903358379 
+0200
+++ lib/linux/arm-mes/elf32-0header.hex2        2020-06-02 00:56:17.617474310 
+0200
@@ -1,5 +1,6 @@
 ### Copyright (C) 2016 Jeremiah Orians
 ### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
 ###
 ### This file is part of GNU Mes.
 ###
@@ -21,14 +22,16 @@
 # elf32-0header.hex2: Simplest 32 bit elf header in hex2.  Only a text
 # segment, no data segment, no symbol tables.
 
-# stage0's hex2 format for x86
+# stage0's hex2 format for arm
 #    !<label>          1 byte relative
 #    $<label>          2 byte address
 #    @<label>          2 byte relative
+#    ~<label>          3 byte relative
 #    &<label>          4 byte address
 #    %<label>          4 byte relative
 #    local_<label>     function-local
 #    string_<index>    string #<index>
+#    ^                 align
 
 ### Code:
 
@@ -45,14 +48,14 @@
 00 00 00 00 00 00 00           # e_ident[EI_PAD]
 
 02 00                          # e_type Indicating Executable
-03 00                          # e_machine Indicating 32bit x86
+28 00                          # e_machine Indicating 32bit arm
 01 00 00 00                    # e_version Indicating original elf
 
 &ELF_text                      # e_entry Address of the entry point
 %ELF_program_headers>ELF_base  # e_phoff Address of program header table
 00 00 00 00                    # e_shoff Address of section header table
 
-00 00 00 00                    # e_flags
+00 02 00 05                    # e_flags Indicating EABI5: 
EF_ARM_ABI_FLOAT_SOFT
 
 34 00                          # e_ehsize Indicating our 52 Byte header
 
diff -ru lib/linux/x86-mes/elf32-0hello-mes.hex2 
lib/linux/arm-mes/elf32-0hello-mes.hex2
--- lib/linux/x86-mes/elf32-0hello-mes.hex2     2020-06-01 21:28:22.903358379 
+0200
+++ lib/linux/arm-mes/elf32-0hello-mes.hex2     2020-06-02 00:56:17.617474310 
+0200
@@ -1,5 +1,6 @@
 ### GNU Mes --- Maxwell Equations of Software
 ### Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
 ###
 ### This file is part of GNU Mes.
 ###
@@ -18,7 +19,7 @@
 
 ### Commentary:
 
-# elf32-0hello-mes.hex2: `Hello, GNU Mes!' for i686-linux written in
+# elf32-0hello-mes.hex2: `Hello, GNU Mes!' for arm-linux written in
 # hex2 assembly, for usage with elf32-0header.hex2.  This produces a
 # 160-byte binary (a0 hex).  Inspiration was taken from GNU Gcc output
 # of hello-mes.S.
@@ -27,22 +28,18 @@
 
 # @60
 :ELF_text
-
                                # print <hello>
-b8 04 00 00 00                 # mov    $4,%eax
-bb 00 00 00 00                 # mov    $1,%ebx
-b9 &hello                      # mov    $hello,%ecx
-ba %bye>hello                  # mov    $(bye-hello),%edx
-cd 80                          # int    $0x80
+04 70 a0 e3                    # mov    r7, #4
+01 00 a0 e3                    # mov    r0, #1
+!hello 10 8f e2                # add    r1, pc, $(hello - pc)
+!bye>hello 20 a0 e3            # mov    r2, $(bye-hello)
+00 00 00 ef                    # swi    0
 
                                # exit 0
-b8 01 00 00 00                 # mov    $1,%eax
-bb 00 00 00 00                 # mov    $0,%ebx
-cd 80                          # int    $0x80
-f4                             # hlt
-
-00 00 00 00 00 00 00 00 00 00  # align to @90
-00 00 00
+01 70 a0 e3                    # mov    r7, #1
+00 00 a0 e3                    # mov    r0, #0
+00 00 00 ef                    # swi    0
+03 f0 20 e3                    # wfi
 
 # @90
 :ELF_data
diff -ru lib/linux/x86-mes/elf32-body-exit-42.hex2 
lib/linux/arm-mes/elf32-body-exit-42.hex2
--- lib/linux/x86-mes/elf32-body-exit-42.hex2   2020-06-01 21:28:22.903358379 
+0200
+++ lib/linux/arm-mes/elf32-body-exit-42.hex2   2020-06-02 00:56:17.613474298 
+0200
@@ -1,5 +1,5 @@
-### GNU Mes --- Maxwell Equations of Software
-### Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
 ###
 ### This file is part of GNU Mes.
 ###
@@ -18,7 +18,7 @@
 
 ### Commentary:
 
-# elf32-body-exit-42.hex2: `exit 42' for i686-linux written in hex2
+# elf32-body-exit-42.hex2: `exit 42' for arm-linux written in hex2
 # assembly, for usage with generic elf32-header.hex2 and
 # elf32-footer-single-main.hex.
 
@@ -30,19 +30,17 @@
 # @200
 :ELF_text
 :_start
-e8 %main                       # call   +11 <main>
-00 00 00
+^~main eb                      # bl main
+00 00 00 00
 00 00 00 00
 00 00 00 00
 
 # @210
 :main
-bb 2a 00 00 00                 # mov    $42,%ebx
-b8 01 00 00 00                 # mov    $0x1,%eax
-cd 80                          # int    $0x80
-f4                             # hlt
-
-00 00 00                       # align
+01 70 a0 e3                    # mov    r7,$0x1
+2a 00 a0 e3                    # mov    r0,$0x2a
+00 00 00 ef                    # swi    0
+03 f0 20 e3                    # wfi
 
 # @220
 :ELF_data
diff -ru lib/linux/x86-mes/elf32-body-hello-mes.hex2 
lib/linux/arm-mes/elf32-body-hello-mes.hex2
--- lib/linux/x86-mes/elf32-body-hello-mes.hex2 2020-06-01 21:28:22.903358379 
+0200
+++ lib/linux/arm-mes/elf32-body-hello-mes.hex2 2020-06-02 00:56:17.613474298 
+0200
@@ -1,5 +1,5 @@
-### GNU Mes --- Maxwell Equations of Software
-### Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
 ###
 ### This file is part of GNU Mes.
 ###
@@ -18,11 +18,11 @@
 
 ### Commentary:
 
-# elf32-body-hello-mes.hex2: `Hello, GNU Mes!' for i686-linux written in
-# hex2 assembly, for usage with generic elf32-header.hex2 and
+# elf32-body-hello-mes.hex2: `exit 42' for arm-linux written in hex2
+# assembly, for usage with generic elf32-header.hex2 and
 # elf32-footer-single-main.hex.
 
-# This ELF binary contains a symbol table which means that objdump and
+# This ELF binary contains a symbol table, which means that objdump and
 # gdb can be used to inspect and debug.
 
 ### Code:
@@ -30,34 +30,30 @@
 # @200
 :ELF_text
 :_start
-e8 %main                       # call   +11 <main>
-00 00 00
+^~main eb                      # bl main
+00 00 00 00
 00 00 00 00
 00 00 00 00
 
 # @210
 :main
                                # print <hello>
-b8 04 00 00 00                 # mov    $4, %eax
-bb 00 00 00 00                 # mov    $1, %ebx
-b9 &hello                      # mov    $hello,%ecx
-ba %bye>hello                  # mov    $(bye-hello),%edx
-cd 80                          # int    $0x80
+04 70 a0 e3                    # mov    r7, #4
+01 00 a0 e3                    # mov    r0, #1
+!hello 10 8f e2                # add    r1, pc, $(hello - pc)
+!bye>hello 20 a0 e3            # mov    r2, $(bye-hello)
+00 00 00 ef                    # swi    0
 
                                # exit 0
-b8 01 00 00 00                 # mov    $0x1,%eax
-bb 00 00 00 00                 # mov    $0,%ebx
-cd 80                          # int    $0x80
-f4                             # hlt
-
-00 00 00 00 00 00 00 00 00 00  # align to @240
-00 00 00
+01 70 a0 e3                    # mov    r7, #1
+00 00 a0 e3                    # mov    r0, #0
+00 00 00 ef                    # swi    0
+03 f0 20 e3                    # wfi
 
-# @240
+# @90
 :ELF_data
 :hello
 48 65 6c 6c 6f 2c 20 47        # Hello, G
 4e 55 20 4d 65 73 21 0a        # NU Mes!\n
-
 :bye
-00
+:ELF_end
diff -ru lib/linux/x86-mes/elf32-footer-single-main.hex2 
lib/linux/arm-mes/elf32-footer-single-main.hex2
--- lib/linux/x86-mes/elf32-footer-single-main.hex2     2020-06-01 
21:28:22.903358379 +0200
+++ lib/linux/arm-mes/elf32-footer-single-main.hex2     2020-06-02 
00:56:17.609474286 +0200
@@ -1,7 +1,8 @@
 ### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
 ### This file is part of stage0.
 ###
-### stage0 is free software: you can redistribute it and/or modify
+### stage0 is free software: you an redistribute it and/or modify
 ### it under the terms of the GNU General Public License as published by
 ### the Free Software Foundation, either version 3 of the License, or
 ### (at your option) any later version.
@@ -14,7 +15,7 @@
 ### You should have received a copy of the GNU General Public License
 ### along with stage0.  If not, see <http://www.gnu.org/licenses/>.
 
-### stage0's hex2 format for x86
+### stage0's hex2 format for arm
 ###    !<label>          1 byte relative
 ###    $<label>          2 byte address
 ###    @<label>          2 byte relative
diff -ru lib/linux/x86-mes/elf32-header.hex2 lib/linux/arm-mes/elf32-header.hex2
--- lib/linux/x86-mes/elf32-header.hex2 2020-06-01 21:28:22.903358379 +0200
+++ lib/linux/arm-mes/elf32-header.hex2 2020-06-02 00:56:17.609474286 +0200
@@ -1,5 +1,6 @@
 ### Copyright (C) 2016 Jeremiah Orians
 ### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
 ###
 ### This file is part of GNU Mes.
 ###
@@ -21,14 +22,16 @@
 # elf32-header.hex2: 32 bit elf header in hex2, with text segment, data
 # segment and symbol tables.
 
-# stage0's hex2 format for x86
+# stage0's hex2 format for arm
 #    !<label>          1 byte relative
 #    $<label>          2 byte address
 #    @<label>          2 byte relative
+#    ~<label>          3 byte relative
 #    &<label>          4 byte address
 #    %<label>          4 byte relative
 #    local_<label>     function-local
 #    string_<index>    string #<index>
+#    ^                 align
 
 ### Code:
 
@@ -45,14 +48,14 @@
 00 00 00 00 00 00 00           # e_ident[EI_PAD]
 
 02 00                          # e_type Indicating Executable
-03 00                          # e_machine Indicating 32bit x86
+28 00                          # e_machine Indicating 32bit arm
 01 00 00 00                    # e_version Indicating original elf
 
 &ELF_text                      # e_entry Address of the entry point
 %ELF_program_headers>ELF_base  # e_phoff Address of program header table
 %ELF_section_headers>ELF_base  # e_shoff Address of section header table
 
-00 00 00 00                    # e_flags
+00 02 00 05                    # e_flags Indicating EABI5: 
EF_ARM_ABI_FLOAT_SOFT
 
 34 00                          # e_ehsize Indicating our 52 Byte header

Do we want to share stuff between those, or is it too much work for too little 
gain?

Attachment: pgp52OVw5GuBD.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]