From: kub Date: Fri, 22 Mar 2019 19:17:08 +0000 (+0100) Subject: substituted tool to obtain target structure offsets (for asm) X-Git-Tag: v2.00~879 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=122afd9d37fa6b0ce7b9dfc369c8a907c590f34d;p=picodrive.git substituted tool to obtain target structure offsets (for asm) --- diff --git a/Makefile b/Makefile index ddbd71a1..a46c2a43 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ asm_ym2612 ?= 1 asm_misc ?= 1 asm_cdmemory ?= 1 asm_mix ?= 1 +asm_32xdraw ?= 0 # currently defunct else # if not arm use_fame ?= 1 use_cz80 ?= 1 @@ -194,10 +195,10 @@ LDFLAGS += -Wl,-Map=$(TARGET).map endif -target_: $(TARGET) +target_: pico/pico_int_o32.h $(TARGET) clean: - $(RM) $(TARGET) $(OBJS) + $(RM) $(TARGET) $(OBJS) pico/pico_int_o32.h $(RM) -r .opk_data $(TARGET): $(OBJS) @@ -210,8 +211,8 @@ endif pprof: platform/linux/pprof.c $(CC) $(CFLAGS) -O2 -ggdb -DPPROF -DPPROF_TOOL -I../../ -I. $^ -o $@ $(LDFLAGS) $(LDLIBS) -tools/textfilter: tools/textfilter.c - make -C tools/ textfilter +pico/pico_int_o32.h:: tools/mkoffsets.sh + make -C tools/ XCC="$(CC)" XCFLAGS="$(CFLAGS)" .s.o: $(CC) $(CFLAGS) -c $< -o $@ diff --git a/pico/pico_int_o32.h b/pico/pico_int_o32.h deleted file mode 100644 index 25c64f43..00000000 --- a/pico/pico_int_o32.h +++ /dev/null @@ -1,28 +0,0 @@ -/* autogenerated by tools/mkoffsets, do not edit */ -#define OFS_Pico_video_reg 0x0000 -#define OFS_Pico_m_rotate 0x0040 -#define OFS_Pico_m_z80Run 0x0041 -#define OFS_Pico_m_dirtyPal 0x0046 -#define OFS_Pico_m_hardware 0x0047 -#define OFS_Pico_m_z80_reset 0x004f -#define OFS_Pico_m_sram_reg 0x0049 -#define OFS_Pico_sv 0x008c -#define OFS_Pico_sv_data 0x008c -#define OFS_Pico_sv_start 0x0090 -#define OFS_Pico_sv_end 0x0094 -#define OFS_Pico_sv_flags 0x0098 -#define OFS_Pico_rom 0x033c -#define OFS_Pico_romsize 0x0340 -#define OFS_EST_DrawScanline 0x00 -#define OFS_EST_rendstatus 0x04 -#define OFS_EST_DrawLineDest 0x08 -#define OFS_EST_HighCol 0x0c -#define OFS_EST_HighPreSpr 0x10 -#define OFS_EST_Pico 0x14 -#define OFS_EST_PicoMem_vram 0x18 -#define OFS_EST_PicoMem_cram 0x1c -#define OFS_EST_PicoOpt 0x20 -#define OFS_EST_Draw2FB 0x24 -#define OFS_EST_HighPal 0x28 -#define OFS_PMEM_vram 0x10000 -#define OFS_PMEM_vsram 0x22100 diff --git a/tools/Makefile b/tools/Makefile index 28b748d4..752cd6b2 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,13 +1,10 @@ -CFLAGS = -Wall -ggdb - -TARGETS = amalgamate textfilter mkoffsets +TARGETS = amalgamate textfilter OBJS = $(addsuffix .o,$(TARGETS)) all: $(TARGETS) + CC="$(XCC)" CFLAGS="$(XCFLAGS)" ./mkoffsets.sh ../pico clean: $(RM) $(TARGETS) $(OBJS) -mkoffsets: CFLAGS += -m32 -I.. - .PHONY: clean all diff --git a/tools/mkoffsets.sh b/tools/mkoffsets.sh new file mode 100755 index 00000000..60088f21 --- /dev/null +++ b/tools/mkoffsets.sh @@ -0,0 +1,82 @@ +# usage: mkoffsets +# automatically compute structure offsets for gcc targets in ELF format + +CC=${CC:-gcc} + +# endianess of target (automagically determined below) +ENDIAN= + +compile_rodata () +{ + $CC $CFLAGS -I .. -c /tmp/getoffs.c -o /tmp/getoffs.o || exit 1 + rosect=$(readelf -S /tmp/getoffs.o | grep '\.rodata' | + sed 's/^[^.]*././;s/ .*//') + objcopy --dump-section $rosect=/tmp/getoffs.ro /tmp/getoffs.o || exit 1 + ro=$(xxd -ps /tmp/getoffs.ro) + if [ "$ENDIAN" = "le" ]; then + # swap needed for le target + hex="" + for b in $(echo $ro | sed 's/\([0-9a-f]\{2\}\)/\1 /g'); do + hex=$b$hex; + done + else + hex=$ro + fi + rodata=$(printf "%d" 0x$hex) +} + +get_define () # prefix struct member member... +{ + prefix=$1; shift + struct=$1; shift + field=$(echo $* | sed 's/ /./g') + name=$(echo $* | sed 's/ /_/g') + echo '#include "pico/pico_int.h"' > /tmp/getoffs.c + echo "static const struct $struct p;" >> /tmp/getoffs.c + echo "const int offs = (char *)&p.$field - (char*)&p;" >>/tmp/getoffs.c + compile_rodata + line=$(printf "#define %-20s 0x%04x" $prefix$name $rodata) +} + +# determine endianess +echo "const int one = 1;" >/tmp/getoffs.c +compile_rodata +ENDIAN=$(if [ "$rodata" -eq 1 ]; then echo be; else echo le; fi) +# determine output file +echo "const int vsz = sizeof(void *);" >/tmp/getoffs.c +compile_rodata +fn="${1:-.}/pico_int_o$((8*$rodata)).h" +# output header +echo "/* autogenerated by mkoffset.sh, do not edit */" >$fn +echo "/* target endianess: $ENDIAN, compiled with: $CC $CFLAGS */" >>$fn +# output offsets +get_define OFS_Pico_ Pico video reg ; echo "$line" >>$fn +get_define OFS_Pico_ Pico m rotate ; echo "$line" >>$fn +get_define OFS_Pico_ Pico m z80Run ; echo "$line" >>$fn +get_define OFS_Pico_ Pico m dirtyPal ; echo "$line" >>$fn +get_define OFS_Pico_ Pico m hardware ; echo "$line" >>$fn +get_define OFS_Pico_ Pico m z80_reset ; echo "$line" >>$fn +get_define OFS_Pico_ Pico m sram_reg ; echo "$line" >>$fn +get_define OFS_Pico_ Pico sv ; echo "$line" >>$fn +get_define OFS_Pico_ Pico sv data ; echo "$line" >>$fn +get_define OFS_Pico_ Pico sv start ; echo "$line" >>$fn +get_define OFS_Pico_ Pico sv end ; echo "$line" >>$fn +get_define OFS_Pico_ Pico sv flags ; echo "$line" >>$fn +get_define OFS_Pico_ Pico rom ; echo "$line" >>$fn +get_define OFS_Pico_ Pico romsize ; echo "$line" >>$fn +get_define OFS_Pico_ Pico est ; echo "$line" >>$fn + +get_define OFS_EST_ PicoEState DrawScanline ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState rendstatus ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState DrawLineDest ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState HighCol ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState HighPreSpr ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState Pico ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState PicoMem_vram ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState PicoMem_cram ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState PicoOpt ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState Draw2FB ; echo "$line" >>$fn +get_define OFS_EST_ PicoEState HighPal ; echo "$line" >>$fn + +get_define OFS_PMEM_ PicoMem vram ; echo "$line" >>$fn +get_define OFS_PMEM_ PicoMem vsram ; echo "$line" >>$fn