porting: arm scaffold WIP

This commit is contained in:
Jan Nieuwenhuizen 2019-03-07 21:24:50 +01:00
parent b314c66b3b
commit 37149aa84d
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
9 changed files with 328 additions and 94 deletions

46
lib/arm-mes-gcc/exit-42.S Normal file
View File

@ -0,0 +1,46 @@
/*
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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: */
/* Using gdb, esp. GUD in GNU Emacs is recommended
M-x gdb-display-disassembly-buffer
M-x gdb-display-io-buffer
set disassemble-next-line on
break _start
run
info registers
si
p/x $r0
RET
...
*/
/** Code: */
SYS_exit = 1 /* Linux syscall: exit. */
.globl _start /* Magic linker symbol: --entry-address. */
.text /* Program text. */
_start:
mov r7,$SYS_exit /* System call function: exit, in r7. */
mov r0,$42 /* First parameter: exit status, in r0. */
swi 0 /* Call system. */
wfi /* Should not be reached. */

View File

@ -0,0 +1,58 @@
/*
* GNU Mes --- Maxwell Equations of Software
* Copyright © 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: */
/* Using gdb, esp. GUD in GNU Emacs is recommended
M-x gdb-display-disassembly-buffer
M-x gdb-display-io-buffer
set disassemble-next-line on
break _start
run
info registers
si
p/x $r0
RET
...
*/
/** Code: */
SYS_exit = 1 /* Linux syscalls. */
SYS_write = 4
stdout = 1 /* File discriptor */
.globl _start /* Magic linker symbol: --entry-address. */
.text /* Program text. */
_start:
mov r7, $SYS_write /* System call function: write, in r7. */
mov r0, $stdout /* 1st parameter: file descriptor, in r0. */
add r1, pc, $(hello - here - 4) /* 2nd parameter: address, in r1. */
here:
mov r2, $(bye-hello) /* 3rd parameter: byte count r2. */
swi 0 /* Call system. */
mov r7,$SYS_exit /* System call function: exit, in r7. */
mov r0,$0 /* 1st parameter: exit status, in r0. */
swi 0 /* Call system. */
wfi /* Should not be reached. */
hello: .ascii "Hello, GNU Mes!\n"
bye:

View File

@ -1,27 +0,0 @@
### 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 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 arm
### !<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>
:ELF_end

View File

@ -0,0 +1,34 @@
### GNU Mes --- Maxwell Equations of Software
### 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.
###
### 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:
# 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.
### Code:
# @60
:ELF_text
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

View File

@ -1,31 +1,39 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 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 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.
### This file is part of GNU Mes.
###
### stage0 is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### 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 stage0. If not, see <http://www.gnu.org/licenses/>.
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
### stage0's hex2 format for arm
### !<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>
### Commentary:
### elf32-header-exit-42.hex2: 32 bit elf header in hex2 for `exit 42'
# 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 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:
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
@ -39,8 +47,6 @@
00 00 00 00 00 00 00 # e_ident[EI_PAD]
# Row 2 in od:
02 00 # e_type Indicating Executable
28 00 # e_machine Indicating 32bit arm
01 00 00 00 # e_version Indicating original elf
@ -78,4 +84,5 @@
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
01 00 00 00 # ph_align
# @60
:ELF_text

View File

@ -0,0 +1,50 @@
### 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.
###
### 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:
# 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.
### Code:
# @60
:ELF_text
# print <hello>
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
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
: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

View File

@ -1,49 +1,48 @@
### Copyright (C) 2017 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 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.
### This file is part of GNU Mes.
###
### stage0 is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### 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 stage0. If not, see <http://www.gnu.org/licenses/>.
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
### stage0's hex2 format for arm
### !<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>
### Commentary:
### elf32-body-exit-42.hex2: 32 bit elf body in hex2 for `exit 42'
# 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.
# This ELF binary contains a symbol table, which means that objdump and
# gdb can be used to inspect and debug.
### Code:
# @200
:ELF_text
:_start
# exit(42)
~main ea # b main
00 00 00
^~main eb # bl main
00 00 00 00
00 00 00 00
00 00 00 00
# @210
:main
42 00 a0 e3 # mov $42 -> %r0
01 70 a0 e3 # mov $0x1 -> %r7
00 00 00 ef # swi 0
00 00 00 00
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
65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # "exit42 data here"
65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # exit42 data here"
00

View File

@ -0,0 +1,59 @@
### 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.
###
### 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:
# 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
# gdb can be used to inspect and debug.
### Code:
# @200
:ELF_text
:_start
^~main eb # bl main
00 00 00 00
00 00 00 00
00 00 00 00
# @210
:main
# print <hello>
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
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
: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

View File

@ -1,31 +1,39 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 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 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.
### This file is part of GNU Mes.
###
### stage0 is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### 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 stage0. If not, see <http://www.gnu.org/licenses/>.
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
### stage0's hex2 format for arm
### !<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>
### Commentary:
### elf32-header-exit-42.hex2: 32 bit elf header in hex2 for `exit 42'
# elf32-header.hex2: 32 bit elf header in hex2, with text segment, data
# segment and symbol tables.
# 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:
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number