feat: add aarch64 bin0
This commit is contained in:
parent
4d3fb33dec
commit
5875797b18
12 changed files with 189 additions and 1 deletions
19
bin0/aarch64-linux/README.md
Normal file
19
bin0/aarch64-linux/README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Bin0 for aarch64-linux
|
||||||
|
|
||||||
|
- 32 bit words
|
||||||
|
- little endian
|
||||||
|
|
||||||
|
This is compatible with:
|
||||||
|
|
||||||
|
- armv7l
|
||||||
|
- powerpc64le
|
||||||
|
- riscv32
|
||||||
|
- riscv64
|
||||||
|
|
||||||
|
## Syscalls of interest
|
||||||
|
|
||||||
|
- `exit` - 93
|
||||||
|
- `read` - 63
|
||||||
|
- `write` - 64
|
||||||
|
- `openat` - 56
|
||||||
|
|
BIN
bin0/aarch64-linux/bin0
Executable file
BIN
bin0/aarch64-linux/bin0
Executable file
Binary file not shown.
BIN
bin0/aarch64-linux/bin0.2
Executable file
BIN
bin0/aarch64-linux/bin0.2
Executable file
Binary file not shown.
65
bin0/aarch64-linux/bin0.S
Normal file
65
bin0/aarch64-linux/bin0.S
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
.section .text
|
||||||
|
.global _start
|
||||||
|
|
||||||
|
_start:
|
||||||
|
ldr x0, [sp] // Get argc
|
||||||
|
cmp x0, #3 // Check if argc is 3
|
||||||
|
blt exit // exit otherwise
|
||||||
|
|
||||||
|
mov x0, #-100 // AT_FDCWD
|
||||||
|
ldr x1, [sp, 16] // First argument
|
||||||
|
mov x2, #0 // O_RDONLY
|
||||||
|
mov x3, #0 // no mode
|
||||||
|
mov x8, #56 // openat
|
||||||
|
svc #0
|
||||||
|
cmp x0, #0 // Check if openat succeeded
|
||||||
|
blt exit // exit otherwise
|
||||||
|
mov x9, x0 // Save fd
|
||||||
|
|
||||||
|
mov x0, #-100 // AT_FDCWD
|
||||||
|
ldr x1, [sp, 24] // Second argument
|
||||||
|
mov x2, #577 // O_TRUNC | O_CREAT | O_WRONLY
|
||||||
|
mov x3, #493 // rwxr-xr-x
|
||||||
|
mov x8, #56 // openat
|
||||||
|
svc #0
|
||||||
|
cmp x0, #0 // Check if openat succeeded
|
||||||
|
blt exit // exit otherwise
|
||||||
|
mov x10, x0 // Save fd
|
||||||
|
|
||||||
|
.Lloop_init:
|
||||||
|
mov x11, #0 // load accumulator
|
||||||
|
mov x12, #32 // Counter
|
||||||
|
.Lread_loop:
|
||||||
|
mov x0, x9 // source fd
|
||||||
|
mov x1, sp // destination buffer
|
||||||
|
mov x2, #1 // size
|
||||||
|
mov x8, #63 // read
|
||||||
|
svc #0
|
||||||
|
cmp x0, #0 // Check if read succeeded
|
||||||
|
ble exit // exit otherwise
|
||||||
|
|
||||||
|
// read the byte
|
||||||
|
ldrb w0, [sp]
|
||||||
|
and w0, w0, #0xFE // clear the bottom bit
|
||||||
|
cmp w0, #0x30 // Check if the byte is a number
|
||||||
|
bne .Lread_loop // if not, loop again
|
||||||
|
|
||||||
|
ldrb w0, [sp]
|
||||||
|
and w0, w0, #1 // get the bottom bit
|
||||||
|
orr w11, w0, w11, lsl #1 // add the bit to the accumulator
|
||||||
|
subs x12, x12, #1 // decrement counter
|
||||||
|
bne .Lread_loop // we haven’t finished looping
|
||||||
|
|
||||||
|
str w11, [sp] // store the accumulator
|
||||||
|
mov x0, x10 // destination fd
|
||||||
|
mov x1, sp // source buffer
|
||||||
|
mov x2, #4 // size
|
||||||
|
mov x8, #64 // write
|
||||||
|
svc #0
|
||||||
|
cmp x0, #0 // Check if write succeeded
|
||||||
|
blt exit // exit otherwise
|
||||||
|
b .Lloop_init
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mov x8, #93
|
||||||
|
svc #0
|
96
bin0/aarch64-linux/bin0.bin0
Normal file
96
bin0/aarch64-linux/bin0.bin0
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
01000110 01001100 01000101 01111111 # ELF Magic
|
||||||
|
00000000 00000001 00000001 00000010 # 32 bit little endian elf
|
||||||
|
00000000000000000000000000000000
|
||||||
|
00000000000000000000000000000000 # padding
|
||||||
|
0000000010110111 0000000000000010 # ARM64 ELF
|
||||||
|
00000000000000000000000000000001 # original version ELF
|
||||||
|
00000000001000000000000001111000
|
||||||
|
00000000000000000000000000000000 # Entrypoint
|
||||||
|
00000000000000000000000001000000
|
||||||
|
00000000000000000000000000000000 # Program header table position
|
||||||
|
00000000000000000000000000000000
|
||||||
|
00000000000000000000000000000000 # Section Header table position
|
||||||
|
00000000000000000000000000000000 # Flags
|
||||||
|
0000000000111000 0000000001000000 # Header size, size of one ph entry
|
||||||
|
0000000001000000 0000000000000001 # One program header, section header size
|
||||||
|
0000000000000000 0000000000000000 # no section headers, no section name section
|
||||||
|
|
||||||
|
00000000000000000000000000000001 # PT_LOAD
|
||||||
|
00000000000000000000000000000111 # rwx
|
||||||
|
00000000000000000000000000000000
|
||||||
|
00000000000000000000000000000000 # Load from zero
|
||||||
|
00000000001000000000000000000000
|
||||||
|
00000000000000000000000000000000 # Load at 2MB
|
||||||
|
00000000001000000000000000000000
|
||||||
|
00000000000000000000000000000000 # same but physical address
|
||||||
|
00000000000000000000000100111100
|
||||||
|
00000000000000000000000000000000 # filesz
|
||||||
|
00000000000000000000000100111100
|
||||||
|
00000000000000000000000000000000 # memsz
|
||||||
|
00000000000000000000000000000100
|
||||||
|
00000000000000000000000000000000 # Align
|
||||||
|
#.section .text
|
||||||
|
#.global _start
|
||||||
|
#
|
||||||
|
#_start:
|
||||||
|
11 111 0 01 01 0 00000000000 11111 00000 # ldr xO, [sp] // Get argc
|
||||||
|
0 1 1 100010 0 000000000011 00000 11111 # cmp xO, #3 // Check if argc is 3
|
||||||
|
0101010 0 0000000000000101110 0 1011 # blt exit // exit otherwise
|
||||||
|
#
|
||||||
|
1 00 100101 00 0000000001100011 00000 # mov xO, #-lOO // AT_FDCWD
|
||||||
|
11 111 0 01 01 0 00000000010 11111 00001 # ldr xl, [sp, l6] // First argument
|
||||||
|
1 10 100101 00 0000000000000000 00010 # mov x2, #O // O_RDONLY
|
||||||
|
1 10 100101 00 0000000000000000 00011 # mov x3, #O // no mode
|
||||||
|
1 10 100101 00 0000000000111000 01000 # mov x8, #56 // openat
|
||||||
|
11010100 000 0000000000000000 000 01 # svc #O
|
||||||
|
1 1 1 100010 0 000000000000 00000 11111 # cmp xO, #O // Check if openat succeeded
|
||||||
|
0101010 0 0000000000000100110 0 1011 # blt exit // exit otherwise
|
||||||
|
1 01 01010 00 0 00000 000000 11111 01001 # mov x9, xO // Save fd
|
||||||
|
#
|
||||||
|
1 00 100101 00 0000000001100011 00000 # mov xO, #-lOO // AT_FDCWD
|
||||||
|
11 111 0 01 01 0 00000000011 11111 00001 # ldr xl, [sp, 24] // Second argument
|
||||||
|
1 10 100101 00 0000001001000001 00010 # mov x2, #577 // O_TRUNC | O_CREAT | O_WRONLY
|
||||||
|
1 10 100101 00 0000000111101101 00011 # mov x3, #493 // rwxr-xr-x
|
||||||
|
1 10 100101 00 0000000000111000 01000 # mov x8, #56 // openat
|
||||||
|
11010100 000 0000000000000000 000 01 # svc #O
|
||||||
|
1 1 1 100010 0 000000000000 00000 11111 # cmp xO, #O // Check if openat succeeded
|
||||||
|
0101010 0 0000000000000011101 0 1011 # blt exit // exit otherwise
|
||||||
|
1 01 01010 00 0 00000 000000 11111 01010 # mov xlO, xO // Save fd
|
||||||
|
#
|
||||||
|
#.Lloop_init:
|
||||||
|
1 10 100101 00 0000000000000000 01011 # mov xll, #O // load accumulator
|
||||||
|
1 10 100101 00 0000000000100000 01100 # mov xl2, #32 // Counter
|
||||||
|
#.Lread_loop:
|
||||||
|
1 01 01010 00 0 01001 000000 11111 00000 # mov xO, x9 // source fd
|
||||||
|
1 0 0 100010 0 000000000000 11111 00001 # mov xl, sp // destination buffer
|
||||||
|
1 10 100101 00 0000000000000001 00010 # mov x2, #l // size
|
||||||
|
1 10 100101 00 0000000000111111 01000 # mov x8, #63 // read
|
||||||
|
11010100 000 0000000000000000 000 01 # svc #O
|
||||||
|
1 1 1 100010 0 000000000000 00000 11111 # cmp xO, #O // Check if read succeessful
|
||||||
|
0101010 0 0000000000000010011 0 1101 # ble exit // exit otherwise
|
||||||
|
#
|
||||||
|
# // read the byte
|
||||||
|
00 111 0 01 01 0 00000000000 11111 00000 # ldrb wO, [sp]
|
||||||
|
0 00 100100 0 011111 000110 00000 00000 # and wO, wO, #OxFE // clear the bottom bit
|
||||||
|
0 1 1 100010 0 000000110000 00000 11111 # cmp wO, #Ox3O // Check if the byte is a number
|
||||||
|
0101010 0 1111111111111110110 0 0001 # bne .Lread_loop // if not, loop again
|
||||||
|
#
|
||||||
|
00 111 0 01 01 0 00000000000 11111 00000 # ldrb wO, [sp]
|
||||||
|
0 00 100100 0 000000 000000 00000 00000 # and wO, wO, #l // get the bottom bit
|
||||||
|
0 01 01010 00 0 01011 000001 00000 01011 # orr wll, wO, wll, lsl #l // add the bit to the accumulator
|
||||||
|
1 1 1 100010 0 000000000001 01100 01100 # subs xl2, xl2, #l // decrement counter
|
||||||
|
0101010 0 1111111111111110001 0 0001 # bne .Lread_loop // we haven’t finished looping
|
||||||
|
#
|
||||||
|
10 111 0 01 00 0 00000000000 11111 01011 # str wll, [sp] // store the accumulator
|
||||||
|
1 01 01010 00 0 01010 000000 11111 00000 # mov xO, xlO // destination fd
|
||||||
|
1 0 0 100010 0 000000000000 11111 00001 # mov xl, sp // source buffer
|
||||||
|
1 10 100101 00 0000000000000100 00010 # mov x2, #4 // size
|
||||||
|
1 10 100101 00 0000000001000000 01000 # mov x8, #64 // write
|
||||||
|
11010100 000 0000000000000000 000 01 # svc #O
|
||||||
|
1 1 1 100010 0 000000000000 00000 11111 # cmp xO, #O // Check if read succeessful
|
||||||
|
0101010 0 0000000000000000010 0 1011 # blt exit // exit otherwise
|
||||||
|
0 00101 11111111111111111111100110 # b .Lloop_init
|
||||||
|
#
|
||||||
|
#exit:
|
||||||
|
1 10 100101 00 0000000001011101 01000 # mov x8, #93
|
||||||
|
11010100 000 0000000000000000 000 01 # svc #O
|
|
@ -1,4 +1,7 @@
|
||||||
system: { self, nixpkgs, ... } @ args: with self.lib.${system}; with nixpkgs.lib; if lists.any (s: system == s) [ "armv7l-linux" ] then
|
system: { self, nixpkgs, ... } @ args: with self.lib.${system}; with nixpkgs.lib; if lists.any (s: system == s) [
|
||||||
|
"armv7l-linux"
|
||||||
|
"aarch64-linux"
|
||||||
|
] then
|
||||||
rec {
|
rec {
|
||||||
bin0-bin = baseDerivation {
|
bin0-bin = baseDerivation {
|
||||||
name = "bin0-bin";
|
name = "bin0-bin";
|
||||||
|
|
BIN
prebuilt/aarch64-linux/busybox
Executable file
BIN
prebuilt/aarch64-linux/busybox
Executable file
Binary file not shown.
1
prebuilt/aarch64-linux/cp
Symbolic link
1
prebuilt/aarch64-linux/cp
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
busybox
|
1
prebuilt/aarch64-linux/dirname
Symbolic link
1
prebuilt/aarch64-linux/dirname
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
busybox
|
1
prebuilt/aarch64-linux/echo
Symbolic link
1
prebuilt/aarch64-linux/echo
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
busybox
|
1
prebuilt/aarch64-linux/mkdir
Symbolic link
1
prebuilt/aarch64-linux/mkdir
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
busybox
|
1
prebuilt/aarch64-linux/mv
Symbolic link
1
prebuilt/aarch64-linux/mv
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
busybox
|
Loading…
Reference in a new issue