Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
75b33ae8f1 Modify to make work on Aarch64 2026-07-04 13:55:04 +01:00
325c449616 Copy from original x86 version 2026-06-17 21:40:57 +01:00
8 changed files with 220 additions and 0 deletions

3
programs/aarch64/return-42/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
out.txt
out.hex
out

View file

@ -0,0 +1,76 @@
# ELF Header Setup
# ================
# 64 Bytes of Data Total
# ELF Identifier
# --------------
# 16 Bytes of setup
# Magic Numbers - EI_MAG[0-3]
7f 45 4c 46
# File Class - EI_CLASS - 64 Bit
02
# Data Encoding - EI_DATA - Little Endian
01
# File Version - EI_VERSION - Version 1
01
# Target ABI - EI_OSABI - Zero for static executables
00
# Target ABI Version - EI_ABIVERSION - Zero for static executables
00
# EI_PAD - 7 Padded Bytes
00 00 00 00 00 00 00
# Rest of the Header
# ------------------
# File Type - e_type - Executable binary
02 00
# Architecture - e_machine - Aarch 64 Architecture
b7 00
# Version Spec - e_version - Version 1
01 00 00 00
# Entry Point Location - e_entry
# 64 Bytes + 56 Bytes program header = 120 bytes
78 00 40 00 00 00 00 00
# Program Header Offset - e_phoff
# Right after this header which is 64 Bytes
40 00 00 00 00 00 00 00
# Section Header Table Offset - e_shoff
# 64 + 56 + 12 + 16
94 00 00 00 00 00 00 00
# Processor Flags - e_flags - No flags set
00 00 00 00
# ELF Header Size - e_ehsize - 64 Bytes
40 00
# Program Header Entry Size - e_phentsize - 56 Bytes
38 00
# Program Header Count - e_phnum - 1 Header
01 00
# Section Header Entry Size - e_shentsize - 64 Bytes
40 00
# Section Header Count - e_shnum
# Set to 3 based on example
03 00
##Section Header String Table Index - e_shstrndx
# Set to 2 based on example
02 00

View file

@ -0,0 +1,37 @@
# Program header - 56 bytes
# =========================
# p_type - loadable segment
01 00 00 00
# p_flags - read and execute
05 00 00 00
# p_offset - load the entire program from the beginning
# this will then include the ELF header and program header as well
# could offset by the ELF and program header I guess
# but leave it for now
00 00 00 00 00 00 00 00
# p_vaddr - virtual memory load position
# this is a common place. Needs to be page aligned
00 00 40 00 00 00 00 00
# p_paddr - physical memory load position
# not really used as far as i can tell - set to same as p_vaddr
00 00 40 00 00 00 00 00
# p_filesz - size of the file to load
# This is to the end of the .text section, which for us is just
# the program size, ELF header, and program header
# so 64 + 56 + 12 = 132 = 0x84
84 00 00 00 00 00 00 00
# p_memsz - size of the file once loaded into memory
# For us this is the same as above for now
84 00 00 00 00 00 00 00
# p_align - something to do with alignment, p_offset and p_vaddr
# need more reading on that
00 00 20 00 00 00 00 00

View file

@ -0,0 +1,14 @@
# Program Code - 12 bytes
# ============
# mov w8 #93
# d2 80 0b a8
a8 0b 80 d2
# mov x0 #42
# d2 80 05 40
40 05 80 d2
# svc #0
# d4 00 00 01
01 00 00 d4

View file

@ -0,0 +1,3 @@
# String table. ".shstrab\0.text\0" -- 16 bytes
2e 73 68 73 74 72 74 61 62 00 2e 74 65 78 74 00

View file

@ -0,0 +1,29 @@
# Section header table, section 0 -- null -- 64 bytes
# 0x0A = offset to the name of the section in the string table
00 00 00 00
# 1 = type: null
00 00 00 00
# flags = executable | occupies memory
00 00 00 00 00 00 00 00
# address in virtual memory of this section
00 00 00 00 00 00 00 00
# offset in the file of this section (start of program code)
00 00 00 00 00 00 00 00
# size of this section in the file: 16 bytes
00 00 00 00 00 00 00 00
# sh_link -- not used for this section
00 00 00 00 00 00 00 00
# 0x01 = alignment code: default??
00 00 00 00 00 00 00 00
# sh_entsize: not used
00 00 00 00 00 00 00 00

View file

@ -0,0 +1,29 @@
# Section header table, section 1 -- program text -- 64 bytes
# 0x0A = offset to the name of the section in the string table
0a 00 00 00
# 1 = type: program data
01 00 00 00
# flags = executable | occupies memory
06 00 00 00 00 00 00 00
# address in virtual memory of this section
78 00 40 00 00 00 00 00
# offset in the file of this section (start of program code)
78 00 00 00 00 00 00 00
# size of this section in the file: 16 bytes
0c 00 00 00 00 00 00 00
# sh_link -- not used for this section
00 00 00 00 00 00 00 00
# 0x01 = alignment code: default??
01 00 00 00 00 00 00 00
# sh_entsize: not used
00 00 00 00 00 00 00 00

View file

@ -0,0 +1,29 @@
# Section header table, section 2 -- string table
# 0x0 = offset to the name of the section in the string table
00 00 00 00
# 3 = type: string table
03 00 00 00
# 0x0 = flags
00 00 00 00 00 00 00 00
# 0x0 = address in virtual memory (not used)
00 00 00 00 00 00 00 00
# 0xB0 = offset in the file of this section (start of string table)
b0 00 00 00 00 00 00 00
# 0x10 = size of this section in the file: 16 bytes
10 00 00 00 00 00 00 00
# sh_link -- not used for this section
00 00 00 00 00 00 00 00
# 0x01 = alignment code: default??
01 00 00 00 00 00 00 00
# sh_entsize: not used
00 00 00 00 00 00 00 00