mirror of
https://github.com/brain-hackers/lab
synced 2025-10-15 12:48:39 +09:00
Add x1 experiments
This commit is contained in:
10
x1/Makefile
Normal file
10
x1/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
CROSS_COMPILE:=arm-linux-gnueabi-
|
||||
AS:=$(CROSS_COMPILE)as
|
||||
|
||||
.PHONY:
|
||||
all: return.bin mrc.bin
|
||||
|
||||
%.bin: %.S
|
||||
@$(AS) $<
|
||||
@./extract.py a.out $@
|
||||
@rm -f a.out
|
16
x1/README.md
Normal file
16
x1/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
#### Code
|
||||
- `mrc.S` Read SCTLR (MMU etc.) and return
|
||||
- `return.S` Return immediately
|
||||
- `extract.py` Extract .text
|
||||
|
||||
|
||||
#### Build
|
||||
```sh
|
||||
pip3 install pyelftools
|
||||
make all
|
||||
```
|
||||
|
||||
#### Run
|
||||
- Create a directory `/path/to/sd/APP/foo`
|
||||
- Create index.din `touch /path/to/sd/APP/foo/index.din`
|
||||
- Copy and rename the raw executable `cp foo.bin /path/to/sd/APP/foo/AppMain.bin`
|
27
x1/extract.py
Executable file
27
x1/extract.py
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
from elftools.elf.elffile import ELFFile # pip install pyelftools
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
print(f'Usage: {sys.argv[0]} in.elf out.bin')
|
||||
sys.exit(1)
|
||||
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
extract(ELFFile(f))
|
||||
|
||||
|
||||
def extract(elf):
|
||||
text = elf.get_section_by_name('.text')
|
||||
if text is None:
|
||||
print('Input ELF has no .text section', file=sys.stderr)
|
||||
|
||||
with open(sys.argv[2], 'wb') as f:
|
||||
f.write(text.data())
|
||||
|
||||
print(f'Successfully extracted the .text section to "{sys.argv[2]}"')
|
||||
|
||||
|
||||
main()
|
7
x1/mrc.S
Normal file
7
x1/mrc.S
Normal file
@@ -0,0 +1,7 @@
|
||||
.text
|
||||
.align 2
|
||||
.global _start
|
||||
|
||||
_start:
|
||||
mrc p15, 0, r10, c1, c0, 0
|
||||
mov pc, lr
|
6
x1/return.S
Normal file
6
x1/return.S
Normal file
@@ -0,0 +1,6 @@
|
||||
.text
|
||||
.align 2
|
||||
.global _start
|
||||
|
||||
_start:
|
||||
mov pc, lr
|
Reference in New Issue
Block a user