From 55253760e5aa9cdb571ddf4bc8e1588e1e73ac14 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Thu, 26 Jan 2017 00:44:23 +0100 Subject: [PATCH] thunks: Adjust build system for ARM thunk .h "make headers" (which in turn invokes "make -C thunks/" should now build the include files via awk, avoiding the need for ruby. Signed-off-by: Bernhard Nortmann --- Makefile | 5 +++++ thunks/Makefile | 32 ++++++++++++++++++++++++++++++++ thunks/fel-to-spl-thunk.h | 13 +++++++++++++ thunks/objdump_to_h.awk | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 thunks/Makefile create mode 100644 thunks/objdump_to_h.awk diff --git a/Makefile b/Makefile index 27882be..be8ad4b 100644 --- a/Makefile +++ b/Makefile @@ -176,6 +176,11 @@ boot_head_sun5i.elf: boot_head.S boot_head.lds sunxi-bootinfo: bootinfo.c +# "preprocessed" .h files for inclusion of ARM thunk code +headers: + make -C thunks/ CROSS_COMPILE=$(CROSS_COMPILE) + + # target tools TARGET_CFLAGS = $(DEFAULT_CFLAGS) -static $(CFLAGS) sunxi-meminfo: meminfo.c diff --git a/thunks/Makefile b/thunks/Makefile new file mode 100644 index 0000000..1e1f612 --- /dev/null +++ b/thunks/Makefile @@ -0,0 +1,32 @@ +# +# build "preprocessed" .h files for inclusion of ARM scratch code +# + +SPL_THUNK := fel-to-spl-thunk.h +THUNKS := sid_read_root.h + +all: $(SPL_THUNK) $(THUNKS) +# clean up object files afterwards + rm -f *.o + +# This empty prerequisite enforces a rebuild of all the headers on every run +FORCE: + +# If not specified explicitly: try to guess a suitable ARM toolchain prefix +PATH_DIRS := $(shell echo $$PATH | sed -e 's/:/ /g') +CROSS_COMPILE ?= $(shell find $(PATH_DIRS) -executable -name 'arm*-gcc' -printf '%f\t' | cut -f 1 | sed -e 's/-gcc/-/') + +AS := $(CROSS_COMPILE)as +OBJDUMP := $(CROSS_COMPILE)objdump + +AWK_O_TO_H := awk -f objdump_to_h.awk + +# The SPL thunk requires a different output format. The "style" variable for +# awk controls this, and causes the htole32() conversion to be omitted. +fel-to-spl-thunk.h: fel-to-spl-thunk.S FORCE + $(AS) -o $(subst .S,.o,$<) $< + $(OBJDUMP) -d $(subst .S,.o,$<) | $(AWK_O_TO_H) -v style=old > $@ + +$(THUNKS): %.h: %.S FORCE + $(AS) -o $(subst .S,.o,$<) $< + $(OBJDUMP) -d $(subst .S,.o,$<) | $(AWK_O_TO_H) > $@ diff --git a/thunks/fel-to-spl-thunk.h b/thunks/fel-to-spl-thunk.h index 636bb81..286ba53 100644 --- a/thunks/fel-to-spl-thunk.h +++ b/thunks/fel-to-spl-thunk.h @@ -1,4 +1,6 @@ + /* : */ 0xea000015, /* 0: b 5c */ + /* : */ 0xe1a00000, /* 4: nop */ 0xe1a00000, /* 8: nop */ 0xe1a00000, /* c: nop */ @@ -7,13 +9,17 @@ 0xe1a00000, /* 18: nop */ 0xe1a00000, /* 1c: nop */ 0xe1a00000, /* 20: nop */ + /* : */ 0xe1a00000, /* 24: nop */ + /* : */ 0xe28f40dc, /* 28: add r4, pc, #220 */ + /* : */ 0xe4940004, /* 2c: ldr r0, [r4], #4 */ 0xe4941004, /* 30: ldr r1, [r4], #4 */ 0xe4946004, /* 34: ldr r6, [r4], #4 */ 0xe3560000, /* 38: cmp r6, #0 */ 0x012fff1e, /* 3c: bxeq lr */ + /* : */ 0xe5902000, /* 40: ldr r2, [r0] */ 0xe5913000, /* 44: ldr r3, [r1] */ 0xe2566004, /* 48: subs r6, r6, #4 */ @@ -21,6 +27,7 @@ 0xe4803004, /* 50: str r3, [r0], #4 */ 0x1afffff9, /* 54: bne 40 */ 0xeafffff3, /* 58: b 2c */ + /* : */ 0xe59f80a4, /* 5c: ldr r8, [pc, #164] */ 0xe24f0044, /* 60: sub r0, pc, #68 */ 0xe520d004, /* 64: str sp, [r0, #-4]! */ @@ -34,10 +41,12 @@ 0xe1120003, /* 84: tst r2, r3 */ 0x1a000012, /* 88: bne d8 */ 0xebffffe5, /* 8c: bl 28 */ + /* : */ 0xe3067c39, /* 90: movw r7, #27705 */ 0xe3457f0a, /* 94: movt r7, #24330 */ 0xe1a00008, /* 98: mov r0, r8 */ 0xe5905010, /* 9c: ldr r5, [r0, #16] */ + /* : */ 0xe4902004, /* a0: ldr r2, [r0], #4 */ 0xe2555004, /* a4: subs r5, r5, #4 */ 0xe0877002, /* a8: add r7, r7, r2 */ @@ -52,14 +61,18 @@ 0xf57ff06f, /* cc: isb sy */ 0xe12fff38, /* d0: blx r8 */ 0xea000006, /* d4: b f4 */ + /* : */ 0xe3032f2e, /* d8: movw r2, #16174 */ 0xe3432f3f, /* dc: movt r2, #16191 */ 0xe5882008, /* e0: str r2, [r8, #8] */ 0xea000003, /* e4: b f8 */ + /* : */ 0xe304222e, /* e8: movw r2, #16942 */ 0xe3442441, /* ec: movt r2, #17473 */ 0xe5882008, /* f0: str r2, [r8, #8] */ + /* : */ 0xebffffcb, /* f4: bl 28 */ + /* : */ 0xe8bd4004, /* f8: pop {r2, lr} */ 0xe121f002, /* fc: msr CPSR_c, r2 */ 0xe59dd000, /* 100: ldr sp, [sp] */ diff --git a/thunks/objdump_to_h.awk b/thunks/objdump_to_h.awk new file mode 100644 index 0000000..bab0a35 --- /dev/null +++ b/thunks/objdump_to_h.awk @@ -0,0 +1,33 @@ +# labels +/[[:xdigit:]]+ <\w+>:/ { + # (Note: using $0 instead of $2 would also include the address) + if (style=="old") + printf "\t/* %s */\n", $2 + else + printf "\t\t/* %s */\n", $2 +} + +# disassembly lines +/[[:xdigit:]]+:/ { + if (style=="old") + printf "\t0x%s, /* %9s %-10s", $2, $1, $3 + else + printf "\t\thtole32(0x%s), /* %5s %-5s", $2, $1, $3 + + for (i = 4; i <= NF; i++) + if ($i == ";") { + # strip comment (anything after and including ';') + NF = i - 1 + break + } + # clear $1 to $3, which re-calculates $0 (= remainder of line) + $3 = "" + $2 = "" + $1 = "" + gsub("^\\s+", "") # strip leading whitespace + + if (style=="old") + printf " %-28s */\n", $0 + else + printf " %-23s */\n", $0 +}