From a1ff34dbca41a1574f64ef515739da50f8a1950a Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Thu, 4 Mar 2021 06:15:54 +0900 Subject: [PATCH] Add x1 C example / improve extract.py to extract all sections after .text --- x1/Makefile | 12 +++++++++++- x1/c/main.bin | Bin 0 -> 1064 bytes x1/c/main.c | 14 ++++++++++++++ x1/c/start.S | 7 +++++++ x1/extract.py | 6 ++++-- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 x1/c/main.bin create mode 100644 x1/c/main.c create mode 100644 x1/c/start.S diff --git a/x1/Makefile b/x1/Makefile index 9a4bf0a..792b07d 100644 --- a/x1/Makefile +++ b/x1/Makefile @@ -1,10 +1,20 @@ CROSS_COMPILE:=arm-linux-gnueabihf- AS:=$(CROSS_COMPILE)as +CC:=$(CROSS_COMPILE)gcc .PHONY: -all: return.bin mrc.bin +all: return.bin mrc.bin c/main.bin + +.PHONY: +clean: + @rm -f *.bin */*.bin %.bin: %.S @$(AS) $< @./extract.py a.out $@ @rm -f a.out + +c/main.bin: + @$(CC) -nostdlib -static -fPIC -mcpu=cortex-a7 c/start.S c/main.c + @./extract.py a.out $@ + #@rm -f a.out diff --git a/x1/c/main.bin b/x1/c/main.bin new file mode 100644 index 0000000000000000000000000000000000000000..74bbb377e61b97c7339460c7e3253ed25fcc81c6 GIT binary patch literal 1064 zcma)4O=}Zj5T188ZEeV5TOx`EiJF5Jvnj3Gq8^eaHHr!%et}4KH@n!yWH)5rfMqYe z_zUd+s0R-PDSFU9;9c+}dQh|{F$aBSlQ*Qng9GzE^UORm?|zI?E`BAV-^SM7m#tUN zU($|oBd)!+%KIOxu|=o*R_4>(cVlPahe!)xY{eU5Ikx&Z`#8({pO;>&efvmnvMYO6 zAOA|loq8DquX(Ljn12vsc zzfRNXnaUwCtEE%(sjN6Gj_60lF)b%fi3M>^tLf1F%eF}*X?=*hBd#TRL#X<}2|A?? zjMHgq*f~h2=;xm~glZmUHqHD!5dT z)Mz+S)QF_rm5s)bd4W5MlSEkr{2arR@M^cYqrz3PS0bPlBH5^!%1v z^j$Kg_e_%64U++8GiPflEkr!7r_Zsk7`1qE;MU#b`GBuC)dR&(Wxu--xrTYs4_J(}` literal 0 HcmV?d00001 diff --git a/x1/c/main.c b/x1/c/main.c new file mode 100644 index 0000000..04205a4 --- /dev/null +++ b/x1/c/main.c @@ -0,0 +1,14 @@ +void main() { + char *str = "Hello World"; + int aa = 1234; + int i; + for (i=0; i<999; i++) { + asm volatile( + "mrc p15, 0, r10, c1, c0, 0\n" + "bic r10, #1\n" + "mcr p15, 0, r10, c1, c0, 0\n" + : "=r" (aa) + ); + aa += 1; + } +} diff --git a/x1/c/start.S b/x1/c/start.S new file mode 100644 index 0000000..99f2d08 --- /dev/null +++ b/x1/c/start.S @@ -0,0 +1,7 @@ +.align 2 +.global _start + +_start: + push {r4, lr} + bl main + pop {r4, pc} diff --git a/x1/extract.py b/x1/extract.py index dc05a13..6d0c609 100755 --- a/x1/extract.py +++ b/x1/extract.py @@ -19,9 +19,11 @@ def extract(elf): print('Input ELF has no .text section', file=sys.stderr) with open(sys.argv[2], 'wb') as f: - f.write(text.data()) + elf.stream.seek(0) + elf.stream.read(text.header.sh_offset) + f.write(elf.stream.read()) - print(f'Successfully extracted the .text section to "{sys.argv[2]}"') + print(f'Successfully extracted the necessary sections to "{sys.argv[2]}"') main()