lib: Make Linux scaffold work for RISC-V64.
* lib/linux/riscv64-mes-gcc/exit-42.S, lib/linux/riscv64-mes-gcc/hello-mes.S, lib/linux/riscv64-mes/elf64-0exit-42.hex2, lib/linux/riscv64-mes/elf64-0header.hex2, lib/linux/riscv64-mes/elf64-0hello-mes.hex2, lib/linux/riscv64-mes/elf64-body-exit-42.hex2, lib/linux/riscv64-mes/elf64-body-hello-mes.hex2, lib/linux/riscv64-mes/elf64-footer-single-main.hex2, lib/linux/riscv64-mes/elf64-header.hex2: New files. Makes basic scaffold pass on RISC-V64.
This commit is contained in:
parent
bf5e8b245e
commit
2848cf6a18
31
lib/linux/riscv64-mes-gcc/exit-42.S
Normal file
31
lib/linux/riscv64-mes-gcc/exit-42.S
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can 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.
|
||||||
|
*
|
||||||
|
* GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Code: */
|
||||||
|
|
||||||
|
SYS_exit = 93 /* Linux syscalls. */
|
||||||
|
.globl _start /* Magic linker symbol: --entry-address. */
|
||||||
|
|
||||||
|
.text /* Program text. */
|
||||||
|
_start:
|
||||||
|
li a7, SYS_exit /* System call function: exit, in a7. */
|
||||||
|
li a0, 42 /* 1st parameter: exit status, in a0. */
|
||||||
|
ecall /* Call system. */
|
||||||
|
wfi /* Should not be reached. */
|
45
lib/linux/riscv64-mes-gcc/hello-mes.S
Normal file
45
lib/linux/riscv64-mes-gcc/hello-mes.S
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can 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.
|
||||||
|
*
|
||||||
|
* GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Code: */
|
||||||
|
|
||||||
|
SYS_exit = 93 /* Linux syscalls. */
|
||||||
|
SYS_write = 64
|
||||||
|
stdout = 1 /* File descriptor */
|
||||||
|
.globl _start /* Magic linker symbol: --entry-address. */
|
||||||
|
|
||||||
|
.text /* Program text. */
|
||||||
|
hello: .ascii "Hello, GNU Mes!\n"
|
||||||
|
bye:
|
||||||
|
.equ string_size, (bye - hello)
|
||||||
|
|
||||||
|
_start:
|
||||||
|
li a7, SYS_write /* System call function: write, in a7. */
|
||||||
|
li a0, stdout /* 1st parameter: file descriptor, in a0. */
|
||||||
|
.equ string_offset, (hello - .)
|
||||||
|
auipc a1, 0 /* Load pc for pc-relative address */
|
||||||
|
addi a1, a1, string_offset /* 2nd parameter: address, in a1. */
|
||||||
|
li a2, string_size /* 3rd parameter: byte count a2. */
|
||||||
|
ecall /* Call system. */
|
||||||
|
|
||||||
|
li a7, SYS_exit /* System call function: exit, in a7. */
|
||||||
|
li a0, 0 /* 1st parameter: exit status, in a0. */
|
||||||
|
ecall /* Call system. */
|
||||||
|
wfi /* Should not be reached. */
|
34
lib/linux/riscv64-mes/elf64-0exit-42.hex2
Normal file
34
lib/linux/riscv64-mes/elf64-0exit-42.hex2
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
### GNU Mes --- Maxwell Equations of Software
|
||||||
|
### Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||||
|
###
|
||||||
|
### This file is part of GNU Mes.
|
||||||
|
###
|
||||||
|
### GNU Mes is free software; you can 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.
|
||||||
|
###
|
||||||
|
### GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
### Commentary:
|
||||||
|
|
||||||
|
# elf64-exit-42.hex2: `exit 42' for riscv64-linux written in hex2
|
||||||
|
# assembly, for usage with elf64-0header.hex2. This produces a 160-byte
|
||||||
|
# binary (a0 hex). Inspiration was taken from GNU Gcc output of
|
||||||
|
# exit-42.S.
|
||||||
|
|
||||||
|
### Code:
|
||||||
|
|
||||||
|
# @80
|
||||||
|
:ELF_text
|
||||||
|
93 08 d0 05 # li a7,93
|
||||||
|
13 05 a0 02 # li a0,42
|
||||||
|
73 00 00 00 # ecall
|
||||||
|
73 00 50 10 # wfi
|
||||||
|
:ELF_end
|
84
lib/linux/riscv64-mes/elf64-0header.hex2
Normal file
84
lib/linux/riscv64-mes/elf64-0header.hex2
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
### Copyright (C) 2016 Jeremiah Orians
|
||||||
|
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
### Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||||
|
###
|
||||||
|
### This file is part of GNU Mes.
|
||||||
|
###
|
||||||
|
### GNU Mes is free software; you can 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.
|
||||||
|
###
|
||||||
|
### GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
### Commentary:
|
||||||
|
|
||||||
|
# elf64-0header.hex2: Simplest 64 bit elf header in hex2. Only a text
|
||||||
|
# segment, no data segment, no symbol tables.
|
||||||
|
|
||||||
|
# stage0's hex2 format for riscv64
|
||||||
|
# !<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>
|
||||||
|
|
||||||
|
### Code:
|
||||||
|
|
||||||
|
:ELF_base
|
||||||
|
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
|
||||||
|
|
||||||
|
02 # e_ident[EI_CLASS] Indicating 64 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
|
||||||
|
F3 00 # e_machine Indicating RV64
|
||||||
|
01 00 00 00 # e_version Indicating original elf
|
||||||
|
|
||||||
|
&ELF_text 00 00 00 00 # e_entry Address of the entry point
|
||||||
|
%ELF_program_headers>ELF_base # e_phoff Address of program header table
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
00 00 00 00 00 00 00 00 # e_shoff Address of section header table
|
||||||
|
|
||||||
|
00 00 00 00 # e_flags
|
||||||
|
|
||||||
|
40 00 # e_ehsize Indicating our 64 Byte header
|
||||||
|
|
||||||
|
38 00 # e_phentsize size of a program header table
|
||||||
|
01 00 # e_phnum number of entries in program table
|
||||||
|
|
||||||
|
00 00 # e_shentsize size of a section header table
|
||||||
|
00 00 # e_shnum number of entries in section table
|
||||||
|
|
||||||
|
00 00 # e_shstrndx index of the section names
|
||||||
|
|
||||||
|
# @40
|
||||||
|
:ELF_program_headers
|
||||||
|
:ELF_program_header__text
|
||||||
|
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||||
|
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||||
|
00 00 00 00 00 00 00 00 # p_offset
|
||||||
|
&ELF_base 00 00 00 00 # ph_vaddr
|
||||||
|
&ELF_base 00 00 00 00 # ph_physaddr
|
||||||
|
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
|
||||||
|
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
|
||||||
|
01 00 00 00 00 00 00 00 # ph_align
|
||||||
|
|
||||||
|
00 00 00 00 00 00 00 00 # align to @80
|
||||||
|
# @80
|
||||||
|
:ELF_text
|
59
lib/linux/riscv64-mes/elf64-0hello-mes.hex2
Normal file
59
lib/linux/riscv64-mes/elf64-0hello-mes.hex2
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
### GNU Mes --- Maxwell Equations of Software
|
||||||
|
### Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
###
|
||||||
|
### This file is part of GNU Mes.
|
||||||
|
###
|
||||||
|
### GNU Mes is free software; you can 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.
|
||||||
|
###
|
||||||
|
### GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
### Commentary:
|
||||||
|
|
||||||
|
# elf64-hello-mes.hex2: `Hello, GNU Mes!' for x86_64-linux written in
|
||||||
|
# hex2 assembly, for usage with elf64-0header.hex2. This produces a
|
||||||
|
# 224-byte binary (e0 hex). Inspiration was taken from GNU Gcc output
|
||||||
|
# of hello-mes.S.
|
||||||
|
|
||||||
|
### Code:
|
||||||
|
|
||||||
|
# @80
|
||||||
|
:ELF_text
|
||||||
|
# print <hello>
|
||||||
|
93 08 00 04 # li a7,64 (sys_write)
|
||||||
|
13 05 10 00 # li a0,1
|
||||||
|
97 05 00 00 # auipc a1,0x0
|
||||||
|
83 e5 c5 00 # lwu a1,12(a1) # addr
|
||||||
|
6f 00 80 00 # j 10
|
||||||
|
&hello
|
||||||
|
|
||||||
|
17 06 00 00 # auipc a2,0x0
|
||||||
|
03 66 c6 00 # lwu a2,12(a2) # addr
|
||||||
|
6f 00 80 00 # j 10
|
||||||
|
%bye>hello
|
||||||
|
|
||||||
|
13 06 00 01 # li a2,$0x13 (sys_write)
|
||||||
|
73 00 00 00 # ecall sys_write
|
||||||
|
93 08 d0 05 # li a7,$0x114 (sys_exit)
|
||||||
|
13 05 00 00 # li a0,0
|
||||||
|
73 00 00 00 # ecall sys_exit
|
||||||
|
73 00 50 10 # wfi
|
||||||
|
|
||||||
|
00 00 00 00 00 00 00 00
|
||||||
|
00 00 00 00 00 00 00 00 # align to @d0
|
||||||
|
|
||||||
|
# @d0
|
||||||
|
: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
|
||||||
|
:ELF_end
|
53
lib/linux/riscv64-mes/elf64-body-exit-42.hex2
Normal file
53
lib/linux/riscv64-mes/elf64-body-exit-42.hex2
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
### GNU Mes --- Maxwell Equations of Software
|
||||||
|
### Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
### Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||||
|
###
|
||||||
|
### This file is part of GNU Mes.
|
||||||
|
###
|
||||||
|
### GNU Mes is free software; you can 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.
|
||||||
|
###
|
||||||
|
### GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
### Commentary:
|
||||||
|
|
||||||
|
# elf64-body-exit-42.hex2: `exit 42' for x86_64-linux written in hex2
|
||||||
|
# assembly, for usage with generic elf64-header.hex2 and
|
||||||
|
# elf64-footer-single-main.hex.
|
||||||
|
|
||||||
|
# This ELF binary contains a symbol table, which means that objdump and
|
||||||
|
# gdb can be used to inspect and debug.
|
||||||
|
|
||||||
|
### Code:
|
||||||
|
|
||||||
|
# @300
|
||||||
|
:ELF_text
|
||||||
|
:_start
|
||||||
|
# exit(42)
|
||||||
|
97 02 00 00 # auipc t0,0x0
|
||||||
|
83 e2 c2 00 # ld t0,12(t0) # main
|
||||||
|
e7 80 02 00 # jalr t0
|
||||||
|
&main
|
||||||
|
|
||||||
|
# @310
|
||||||
|
:main
|
||||||
|
93 08 d0 05 # li a7,93
|
||||||
|
13 05 a0 02 # li a0,42
|
||||||
|
73 00 00 00 # ecall
|
||||||
|
73 00 50 10 # wfi
|
||||||
|
|
||||||
|
00 00 00 00 00 00 00 00
|
||||||
|
00 00 00 00 00 00 00 00 # align to 330
|
||||||
|
|
||||||
|
# @330
|
||||||
|
:ELF_data
|
||||||
|
65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # exit42 data here"
|
||||||
|
00
|
70
lib/linux/riscv64-mes/elf64-body-hello-mes.hex2
Normal file
70
lib/linux/riscv64-mes/elf64-body-hello-mes.hex2
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
### GNU Mes --- Maxwell Equations of Software
|
||||||
|
### Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
###
|
||||||
|
### This file is part of GNU Mes.
|
||||||
|
###
|
||||||
|
### GNU Mes is free software; you can 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.
|
||||||
|
###
|
||||||
|
### GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
### Commentary:
|
||||||
|
|
||||||
|
# elf64-body-hello-mes.hex2: `Hello, GNU Mes!' for x86_64-linux written
|
||||||
|
# in hex2 assembly, for usage with generic elf64-header.hex2 and
|
||||||
|
# elf64-footer-single-main.hex.
|
||||||
|
|
||||||
|
# This ELF binary contains a symbol table which means that objdump and
|
||||||
|
# gdb can be used to inspect and debug.
|
||||||
|
|
||||||
|
### Code:
|
||||||
|
|
||||||
|
# @300
|
||||||
|
:ELF_text
|
||||||
|
:_start
|
||||||
|
# exit(42)
|
||||||
|
97 02 00 00 # auipc t0,0x0
|
||||||
|
83 e2 c2 00 # ld t0,12(t0) # main
|
||||||
|
e7 80 02 00 # jalr t0
|
||||||
|
&main
|
||||||
|
|
||||||
|
# @310
|
||||||
|
:main
|
||||||
|
# print <hello>
|
||||||
|
93 08 00 04 # li a7,$0x93 (sys_write)
|
||||||
|
13 05 10 00 # li a0,$0x13
|
||||||
|
97 05 00 00 # auipc a1,0x0
|
||||||
|
83 e5 c5 00 # lwu a1,12(a1) # addr
|
||||||
|
6f 00 80 00 # j 10
|
||||||
|
&hello
|
||||||
|
|
||||||
|
17 06 00 00 # auipc a2,0x0
|
||||||
|
03 66 c6 00 # lwu a2,12(a2) # addr
|
||||||
|
6f 00 80 00 # j 10
|
||||||
|
%bye>hello
|
||||||
|
|
||||||
|
13 06 00 01 # li a2,16
|
||||||
|
73 00 00 00 # ecall sys_write
|
||||||
|
93 08 d0 05 # li a7,93 (sys_exit)
|
||||||
|
13 05 00 00 # li a0,0
|
||||||
|
73 00 00 00 # ecall sys_exit
|
||||||
|
73 00 50 10 # wfi
|
||||||
|
|
||||||
|
00 00 00 00 00 00 00 00
|
||||||
|
00 00 00 00 00 00 00 00 # align to @360
|
||||||
|
|
||||||
|
# @360
|
||||||
|
: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
|
||||||
|
:ELF_end
|
62
lib/linux/riscv64-mes/elf64-footer-single-main.hex2
Normal file
62
lib/linux/riscv64-mes/elf64-footer-single-main.hex2
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
### This file is part of stage0.
|
||||||
|
###
|
||||||
|
### stage0 is free software: you can 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_64
|
||||||
|
### !<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>
|
||||||
|
|
||||||
|
# @230
|
||||||
|
|
||||||
|
:ELF_str
|
||||||
|
00 # 0
|
||||||
|
:ELF_str__start
|
||||||
|
5f 73 74 61 72 74 00 # _start
|
||||||
|
:ELF_str__main
|
||||||
|
6d 61 69 6e 00 # main
|
||||||
|
|
||||||
|
00 00 00
|
||||||
|
|
||||||
|
# @370
|
||||||
|
:ELF_sym
|
||||||
|
00 00 00 00 # st-name
|
||||||
|
00 # st-info = stt-func= 2
|
||||||
|
00 # st-other
|
||||||
|
01 00 # st-shndx: 1
|
||||||
|
00 00 00 00 00 00 00 00 # st-offset: &_start - BaseAddress
|
||||||
|
00 00 00 00 00 00 00 00 # st-len : &main - _start
|
||||||
|
|
||||||
|
# _start
|
||||||
|
%ELF_str__start>ELF_str # st-name
|
||||||
|
02 # st-info = stt-func= 2
|
||||||
|
00 # st-other
|
||||||
|
01 00 # st-shndx: 1
|
||||||
|
&_start 00 00 00 00
|
||||||
|
10 00 00 00 00 00 00 00 # st-len : &main - _start
|
||||||
|
|
||||||
|
# main
|
||||||
|
%ELF_str__main>ELF_str # st-name
|
||||||
|
02 # st-info = stt-func= 2
|
||||||
|
00 # st-other
|
||||||
|
01 00 # st-shndx: 1
|
||||||
|
&main 00 00 00 00
|
||||||
|
10 00 00 00 00 00 00 00 # st-len : &ELF_data - main
|
||||||
|
|
||||||
|
:ELF_end
|
241
lib/linux/riscv64-mes/elf64-header.hex2
Normal file
241
lib/linux/riscv64-mes/elf64-header.hex2
Normal file
|
@ -0,0 +1,241 @@
|
||||||
|
### Copyright (C) 2016 Jeremiah Orians
|
||||||
|
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
### Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||||
|
###
|
||||||
|
### This file is part of GNU Mes.
|
||||||
|
###
|
||||||
|
### GNU Mes is free software; you can 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.
|
||||||
|
###
|
||||||
|
### GNU Mes 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
### Commentary:
|
||||||
|
|
||||||
|
# elf64-header.hex2: 64 bit elf header in hex2, with text segment, data
|
||||||
|
# segment and symbol tables.
|
||||||
|
|
||||||
|
# stage0's hex2 format for riscv64
|
||||||
|
# !<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>
|
||||||
|
|
||||||
|
### Code:
|
||||||
|
|
||||||
|
:ELF_base
|
||||||
|
7F 45 4c 46 # e_ident[EI_MAG0-3] ELF's magic number
|
||||||
|
|
||||||
|
02 # e_ident[EI_CLASS] Indicating 64 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]
|
||||||
|
|
||||||
|
# 0x10
|
||||||
|
02 00 # e_type Indicating Executable
|
||||||
|
f3 00 # e_machine Indicating AMD64
|
||||||
|
01 00 00 00 # e_version Indicating original elf
|
||||||
|
|
||||||
|
# 0x18
|
||||||
|
&ELF_text 00 00 00 00 # e_entry Address of the entry point
|
||||||
|
%ELF_program_headers>ELF_base # e_phoff Address of program header table
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
%ELF_section_headers>ELF_base # e_shoff Address of section header table
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
00 00 00 00 # e_flags
|
||||||
|
|
||||||
|
40 00 # e_ehsize Indicating our 64 Byte header
|
||||||
|
|
||||||
|
38 00 # e_phentsize size of a program header table
|
||||||
|
01 00 # e_phnum number of entries in program table
|
||||||
|
|
||||||
|
40 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
|
||||||
|
|
||||||
|
# @40
|
||||||
|
:ELF_program_headers
|
||||||
|
:ELF_program_header__text
|
||||||
|
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||||
|
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||||
|
00 00 00 00 00 00 00 00 # p_offset
|
||||||
|
&ELF_base 00 00 00 00 # ph_vaddr
|
||||||
|
&ELF_base 00 00 00 00 # ph_physaddr
|
||||||
|
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
|
||||||
|
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
|
||||||
|
01 00 00 00 00 00 00 00 # ph_align
|
||||||
|
|
||||||
|
|
||||||
|
# @60
|
||||||
|
#:ELF_program_header__data # NOT USED
|
||||||
|
# FIXME: linux 4.17 does not allow this overlap
|
||||||
|
# Uhuuh, elf segment at 0000000001000000
|
||||||
|
# requested but the memory is mapped already
|
||||||
|
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||||
|
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||||
|
00 00 00 00 00 00 00 00 # ph_offset
|
||||||
|
&ELF_base 00 00 00 00 # ph_vaddr
|
||||||
|
&ELF_base 00 00 00 00 # ph_physaddr
|
||||||
|
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
|
||||||
|
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
|
||||||
|
01 00 00 00 00 00 00 00 # ph_align
|
||||||
|
|
||||||
|
# @b0
|
||||||
|
:ELF_comment
|
||||||
|
4d 45 53 00 # MES
|
||||||
|
00 00 00 00 # align
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
# @c0
|
||||||
|
4d 45 53 00 # MES
|
||||||
|
00 00 00 00 # align
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
# @d0
|
||||||
|
: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__shstr
|
||||||
|
2e 73 68 73 74 72 74 61 62 00 # .shstrtab
|
||||||
|
:ELF_shstr__sym
|
||||||
|
2e 73 79 6d 74 61 62 00 # .symtab
|
||||||
|
:ELF_shstr__str
|
||||||
|
2e 73 74 72 74 61 62 00 # .strtab
|
||||||
|
|
||||||
|
# @100
|
||||||
|
|
||||||
|
:ELF_section_headers
|
||||||
|
00 00 00 00 # sh_name
|
||||||
|
00 00 00 00 # sh_type
|
||||||
|
00 00 00 00 00 00 00 00 # sh_flags
|
||||||
|
00 00 00 00 00 00 00 00 # sh_addr
|
||||||
|
00 00 00 00 00 00 00 00 # sh_offset
|
||||||
|
00 00 00 00 00 00 00 00 # sh_length
|
||||||
|
00 00 00 00 # sh_link
|
||||||
|
00 00 00 00 # sh_info
|
||||||
|
00 00 00 00 00 00 00 00 # sh_1?
|
||||||
|
00 00 00 00 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_type = SHT_PROGBITS = 1
|
||||||
|
06 00 00 00 00 00 00 00 # sh_flags = SHF-ALLOC|SHF-EXEC =2 | 4 = 6
|
||||||
|
&ELF_text 00 00 00 00 # sh_addr
|
||||||
|
%ELF_text>ELF_base 00 00 00 00 # sh_offset
|
||||||
|
%ELF_data>ELF_text 00 00 00 00 # sh_length
|
||||||
|
00 00 00 00 # sh_link
|
||||||
|
00 00 00 00 # sh_info
|
||||||
|
01 00 00 00 00 00 00 00 # sh_1?
|
||||||
|
00 00 00 00 00 00 00 00 # sh_entsize
|
||||||
|
|
||||||
|
:ELF_section_header_data
|
||||||
|
%ELF_shstr__data>ELF_shstr # sh_name
|
||||||
|
01 00 00 00 # sh_type = SHT_PROGBITS = 1
|
||||||
|
03 00 00 00 00 00 00 00 # sh_flags = SHF-WRITE|SHF-ALLOC = 1 | 2 = 3
|
||||||
|
&ELF_data 00 00 00 00 # sh_addr
|
||||||
|
%ELF_data>ELF_base 00 00 00 00 # sh_offset
|
||||||
|
%ELF_sym>ELF_data 00 00 00 00 # sh_length
|
||||||
|
00 00 00 00 # sh_link
|
||||||
|
00 00 00 00 # sh_info
|
||||||
|
01 00 00 00 00 00 00 00 # sh_1?
|
||||||
|
00 00 00 00 00 00 00 00 # sh_entsize
|
||||||
|
|
||||||
|
:ELF_section_header_comment
|
||||||
|
%ELF_shstr__comment>ELF_shstr # sh_name
|
||||||
|
01 00 00 00 # sh_type = SHT_PROGBITS = 1
|
||||||
|
00 00 00 00 00 00 00 00 # sh_flags
|
||||||
|
&ELF_comment 00 00 00 00 # sh_addr
|
||||||
|
%ELF_comment>ELF_base 00 00 00 00 # sh_offset
|
||||||
|
%ELF_shstr>ELF_comment 00 00 00 00 # sh_length
|
||||||
|
00 00 00 00 # sh_link
|
||||||
|
00 00 00 00 # sh_info
|
||||||
|
01 00 00 00 00 00 00 00 # sh_1?
|
||||||
|
00 00 00 00 00 00 00 00 # sh_entsize
|
||||||
|
|
||||||
|
:ELF_section_header_shstr
|
||||||
|
%ELF_shstr__shstr>ELF_shstr # sh_name
|
||||||
|
03 00 00 00 # sh_type: str-sht-strtab
|
||||||
|
00 00 00 00 00 00 00 00 # sh_flags
|
||||||
|
&ELF_shstr 00 00 00 00 # sh_addr
|
||||||
|
%ELF_shstr>ELF_base 00 00 00 00 # sh_offset
|
||||||
|
%ELF_section_headers>ELF_shstr 00 00 00 00 # sh_length
|
||||||
|
00 00 00 00 # sh_link
|
||||||
|
00 00 00 00 # sh_info
|
||||||
|
01 00 00 00 00 00 00 00 # sh_1?
|
||||||
|
00 00 00 00 00 00 00 00 # sh_entsize
|
||||||
|
|
||||||
|
:ELF_section_header_sym
|
||||||
|
%ELF_shstr__sym>ELF_shstr # sh_name
|
||||||
|
02 00 00 00 # sh_type: str-sht-symtab
|
||||||
|
00 00 00 00 00 00 00 00 # sh_flags
|
||||||
|
&ELF_sym 00 00 00 00 # sh_addr
|
||||||
|
%ELF_sym>ELF_base 00 00 00 00 # sh_offset
|
||||||
|
%ELF_end>ELF_sym 00 00 00 00 # sh_length
|
||||||
|
06 00 00 00 # sh_link:6
|
||||||
|
03 00 00 00 # sh_info (=number of entries)
|
||||||
|
01 00 00 00 00 00 00 00 # sh_1?
|
||||||
|
18 00 00 00 00 00 00 00 # sh_entsize
|
||||||
|
|
||||||
|
:ELF_section_header_str
|
||||||
|
%ELF_shstr__str>ELF_shstr # sh_name
|
||||||
|
03 00 00 00 # sh_type: str-sht-strtab
|
||||||
|
00 00 00 00 00 00 00 00 # sh_flags
|
||||||
|
&ELF_str 00 00 00 00 # sh_addr
|
||||||
|
%ELF_str>ELF_base 00 00 00 00 # sh_offset
|
||||||
|
%ELF_sym>ELF_str 00 00 00 00 # sh_length
|
||||||
|
00 00 00 00 # sh_link
|
||||||
|
00 00 00 00 # sh_info
|
||||||
|
01 00 00 00 00 00 00 00 # sh_1?
|
||||||
|
00 00 00 00 00 00 00 00 # sh_entsize
|
||||||
|
|
||||||
|
# @2c0
|
||||||
|
00 00 00 00 # align
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
# @2d0
|
||||||
|
00 00 00 00 # align
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
# @2e0
|
||||||
|
00 00 00 00 # align
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
# @2f0
|
||||||
|
00 00 00 00 # align
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
00 00 00 00
|
||||||
|
|
||||||
|
# @300
|
||||||
|
:ELF_text
|
|
@ -64,7 +64,7 @@ mes_environment (int argc, char **argv)
|
||||||
arch = "x86_64";
|
arch = "x86_64";
|
||||||
#elif __riscv_xlen == 32
|
#elif __riscv_xlen == 32
|
||||||
arch = "riscv32";
|
arch = "riscv32";
|
||||||
#elif __riscv_xlen == 64
|
#elif __riscv_xlen == 64
|
||||||
arch = "riscv64";
|
arch = "riscv64";
|
||||||
#else
|
#else
|
||||||
#error arch not supported
|
#error arch not supported
|
||||||
|
|
Loading…
Reference in a new issue