stage0: Add stage0 hex2 gdb header and footer example.

* stage0/elf32-header-exit-42.hex2: New file.
* stage0/elf32-footer-exit-42.hex2: New file.
This commit is contained in:
Jan Nieuwenhuizen 2017-06-18 21:06:27 +02:00
parent 77dfdd44b7
commit 3b82abdfa5
4 changed files with 426 additions and 0 deletions

View file

@ -0,0 +1,85 @@
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### This file is part of stage0.
###
### 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.
###
### stage0 is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### 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
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### local_<label> function-local
### string_<index> string #<index>
### elf32-body-exit-42.hex2: 32 bit elf body in hex2 for `exit 42'
# @80
:ELF_text
:_start
# exit(42)
bb 2a 00 00 00 # mov $42,%ebx
b8 01 00 00 00 # mov $0x1,%eax
cd 80 # int $0x80
00 00 00 00
# @90
:main
c9 # RET
00 00 00
00 00 00 00
00 00 00 00
00 00 00 00
# @a0
:ELF_data
65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # exit42 data here"
#@ b0
:ELF_str
00 # 0
5f 73 74 61 72 74 00 # _start
6d 61 69 6e 00 # main
00 00 00
#@ c0
:ELF_sym
00 00 00 00 # st-name
00 00 00 00 # st-offset: &_start - BaseAddress
00 00 00 00 # st-len : &main - _start
00 # st-info = stt-func= 2
00 # st-other
01 00 # st-shndx: 1
# _start
01 00 00 00 # st-name
&_start
10 00 00 00 # st-len : &main - _start
02 # st-info = stt-func= 2
00 # st-other
01 00 # st-shndx: 1
# main
08 00 00 00 # st-name
&main
10 00 00 00 # st-len : &ELF_data - main
02 # st-info = stt-func= 2
00 # st-other
01 00 # st-shndx: 1

View file

@ -0,0 +1,168 @@
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### This file is part of stage0.
###
### 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.
###
### stage0 is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### 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
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### local_<label> function-local
### string_<index> string #<index>
### elf32-footer-exit-42.hex2: 32 bit elf footer in hex2 for `exit 42'
# @f0
:ELF_comment
4d 45 53 00 # MES
00 00 00 00
00 00 00 00 # align
00 00 00 00 # align
# @100
:ELF_shstr
00
:ELF_shstr__text
2e 74 65 78 74 00 # .text
:ELF_shstr__data
2e 64 61 74 61 00 # .data
:ELF_shstr__comment
2e 63 6f 6d 6d 65 6e 74 00 #.comment
:ELF_shstr__shstrtab
2e 73 68 73 74 72 74 61 62 00 #.shstrtab
:ELF_shstr__symtab
2e 73 79 6d 74 61 62 00 #.symtab
:ELF_shstr__strtab
2e 73 74 72 74 61 62 00 #.strtab
# @130
bb bb bb bb
bb bb bb bb
bb bb bb bb
bb bb bb bb
# @140
:ELF_sections_headers
00 00 00 00 # sh_name
00 00 00 00 # sh_type
00 00 00 00 # sh_flags
00 00 00 00 # sh_addr
00 00 00 00 # sh_offset
00 00 00 00 # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
## FIXME: M0 for calculations?
:ELF_section_header_text
#@ELF_shstr__text - @ELF_shstr # sh_name
01 00 00 00 # sh_name
01 00 00 00 # sh_type = SHT_PROGBITS = 1
06 00 00 00 # sh_flags = SHF-ALLOC|SHF-EXEC =2 | 4 = 6
#&ELF_base # sh_addr
&ELF_text # sh_addr
#@ELF_text - @ELF_base # sh_addr
80 00 00 00 # sh_offset
#@ELF_data - @ELF_text # sh_length
10 00 00 00 # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_data
#@ELF_shstr__data - @ELF_shstr # sh_name
07 00 00 00 # sh_name
01 00 00 00 # sh_type = SHT_PROGBITS = 1
03 00 00 00 # sh_flags = SHF-WRITE|SHF-ALLOC = 1 | 2 = 3
#&ELF_base # sh_addr
&ELF_data # sh_addr
#@ELF_data - @ELF_base # sh_addr
a0 00 00 00 # sh_offset
#@ELF_comment - @ELF_data # sh_length
10 00 00 00 # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_comment
#@ELF_shstr__comment - @ELF_shstr # sh_name
0d 00 00 00 # sh_name
01 00 00 00 # sh_type = SHT_PROGBITS = 1
00 00 00 00 # sh_flags
#&ELF_base # sh_addr
&ELF_comment # sh_addr
00 01 00 00 # sh_offset
00 00 00 00 # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_shstr
#@ELF_shstr__shstr - @ELF_shstr # sh_name
16 00 00 00 # sh_name
03 00 00 00 # sh_type: str-sht-strtab
00 00 00 00 # sh_flags
#&ELF_base # sh_addr
&ELF_shstr # sh_addr
00 01 00 00 # sh_offset
30 00 00 00 # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
:ELF_section_header_sym
#@ELF_shstr__sym - @ELF_shstr # sh_name
20 00 00 00 # sh_name
02 00 00 00 # sh_type: str-sht-symtab
00 00 00 00 # sh_flags
#&ELF_base # sh_addr
&ELF_sym # sh_addr
c0 00 00 00 # sh_offset
30 00 00 00 # sh_length
06 00 00 00 # sh_link:6
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
10 00 00 00 # sh_entsize
:ELF_section_header_str
#@ELF_shstr__str - @ELF_shstr # sh_name
28 00 00 00 # sh_name
03 00 00 00 # sh_type: str-sht-strtab
00 00 00 00 # sh_flags
#&ELF_base # sh_addr
&ELF_str # sh_addr
b0 00 00 00 # sh_offset
10 00 00 00 # sh_length
00 00 00 00 # sh_link
00 00 00 00 # sh_info
01 00 00 00 # sh_1?
00 00 00 00 # sh_entsize
00 00 00 00
00 00 00 00
:ELF_end
00

View file

@ -0,0 +1,87 @@
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### This file is part of stage0.
###
### 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.
###
### stage0 is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### 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
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### local_<label> function-local
### string_<index> string #<index>
### elf32-header-exit-42.hex2: 32 bit elf header in hex2 for `exit 42'
:ELF_base
## ELF Header
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
01 # e_ident[EI_CLASS] Indicating 32 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
00 # e_ident[EI_OSABI] Set at 0 because none cares
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
03 00 # e_machine Indicating AMD64
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
34 00 00 00 # e_phoff Address of program header table
#&ELF_section_headers - &ELF_base # e_phoff Address of program header table
40 01 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
34 00 # e_ehsize Indicating our 52 Byte header
20 00 # e_phentsize size of a program header table
02 00 # e_phnum number of entries in program table
28 00 # e_shentsize size of a section header table
07 00 # e_shnum number of entries in section table
04 00 # e_shstrndx index of the section names
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
00 03 00 00 # ph_filesz
00 03 00 00 # ph_memsz
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
01 00 00 00 # ph_align
# @54
:ELF_program_header__data
01 00 00 00 # ph_type: PT-LOAD = 1
00 00 00 00 # ph_offset
&ELF_base # ph_vaddr
&ELF_base # ph_physaddr
ff ff 00 00 # ph_filesz
ff ff 00 00 # ph_memsz
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
01 00 00 00 # ph_align
# @74
00 00 00 00
00 00 00 00
00 00 00 00

86
stage0/elf32.hex3 Normal file
View file

@ -0,0 +1,86 @@
;;; -*-scheme-*-
;;; Copyright (C) 2016 Jeremiah Orians
;;; Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
;;; This file is part of stage0.
;;;
;;; 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.
;;;
;;; stage0 is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with stage0. If not, see <http://www.gnu.org/licenses/>.
;;; elf32.hex3: 32 bit elf header in hex3
;; ELF Header
("*elf-header*"
#X7F #x45 #X4C #x46 ; e_ident[EI_MAG0-3] ELF's magic number
#x01 ; e_ident[EI_CLASS] Indicating 32 bit
#x01 ; e_ident[EI_DATA] Indicating little endianness
#x01 ; e_ident[EI_VERSION] Indicating original elf
#x00 ; e_ident[EI_OSABI] Set at 0 because none cares
#x00 ; e_ident[EI_ABIVERSION] See above
#x00 #x00 #x00 #x00 #x00 #x00 #x00 ; e_ident[EI_PAD]
#x02 #x00 ; e_type Indicating Executable
#x03 #x00 ; e_machine Indicating AMD64
#x01 #x00 #x00 #x00 ; e_version Indicating original elf
#x54 #x80 #x04 #x08 ; e_entry Address of the entry point
#x34 #x00 #x00 #x00 ; e_phoff Address of program header table
#x00 #x00 #x00 #x00 ; e_shoff Address of section header table
#x00 #x00 #x00 #x00 ; e_flags
#x34 #x00 ; e_ehsize Indicating our 52 Byte header
#x20 #x00 ; e_phentsize size of a program header table
#x01 #x00 ; e_phnum number of entries in program table
#x00 #x00 ; e_shentsize size of a section header table
#x00 #x00 ; e_shnum number of entries in section table
#x00 #x00 ; e_shstrndx index of the section names
;; Program Header
#x01 #x00 #x00 #x00 ; p_type
#x00 #x00 #x00 #x00 ; p_offset
#x00 #x80 #x04 #x08 ; p_vaddr
#x00 #x80 #x04 #x08 ; p_physaddr
;; FIXME!
;;#x60 #x00 #x00 #x00 ; p_filesz
;;#x60 #x00 #x00 #x00 ; p_memsz
;#x65 #x01 #x00 #x00 ; p_filesz
;#x65 #x01 #x00 #x00 ; p_memsz
#xff #xff #x00 #x00 ; p_filesz
#xff #xff #x00 #x00 ; p_memsz
#x07 #x00 #x00 #x00 ; p_flags
#x01 #x00 #x00 #x00 ; alignment
;; _start
; exit (42) -- works!
;#xbb #x2a #x00 #x00 #x00 ; mov $42,%ebx
;#xb8 #x01 #x00 #x00 #x00 ; mov $0x1,%eax
;#xcd #x80 ; int $0x80
)
("shstr" 0
#\. #\t #\e #\x #\t 0
#\. #\d #\a #\t #\a 0
#\. #\c #\o #\m #\m #\e #\n #\t 0
#\. #\s #\h #\s #\t #\r #\t #\a #\b 0
#\. #\s #\y #\m #\t #\a #\b 0
#\. #\s #\t #\r #\t #\a #\b 0)