mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
100 lines
4 KiB
Bash
Executable file
100 lines
4 KiB
Bash
Executable file
# automatically compute structure offsets for gcc targets in ELF format
|
|
# (C) 2018 Kai-Uwe Bloem. This work is placed in the public domain.
|
|
#
|
|
# usage: mkoffsets <output dir>
|
|
|
|
CC=${CC:-gcc}
|
|
|
|
# endianess of target (automagically determined below)
|
|
ENDIAN=
|
|
|
|
# compile with target C compiler and extract value from .rodata section
|
|
compile_rodata ()
|
|
{
|
|
$CC $CFLAGS -I .. -c /tmp/getoffs.c -o /tmp/getoffs.o || exit 1
|
|
# echo 'void dummy(void) { asm(""::"r" (&val)); }' >> /tmp/getoffs.c
|
|
# $CC $CFLAGS -I .. -nostdlib -Wl,-edummy /tmp/getoffs.c \
|
|
# -o /tmp/getoffs.o || exit 1
|
|
# find the name of the .rodata section (in case -fdata-sections is used)
|
|
rosect=$(readelf -S /tmp/getoffs.o | grep '\.rodata' |
|
|
sed 's/^[^.]*././;s/ .*//')
|
|
# read out .rodata section as hex string (should be only 4 or 8 bytes)
|
|
ro=$(readelf -x $rosect /tmp/getoffs.o | grep '0x' | cut -c14-48 |
|
|
tr -d ' \n')
|
|
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
|
|
# extract decimal value from hex string
|
|
rodata=$(printf "%d" 0x$hex)
|
|
}
|
|
|
|
# determine member offset and create #define
|
|
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 val = (char *)&p.$field - (char*)&p;" >>/tmp/getoffs.c
|
|
compile_rodata
|
|
line=$(printf "#define %-20s 0x%04x" $prefix$name $rodata)
|
|
}
|
|
|
|
CFLAGS="$CFLAGS -fno-lto"
|
|
# determine endianess
|
|
echo "const int val = 1;" >/tmp/getoffs.c
|
|
compile_rodata
|
|
ENDIAN=$(if [ "$rodata" -eq 1 ]; then echo be; else echo le; fi)
|
|
# output header
|
|
fn="${1:-.}/pico_int_offs.h"
|
|
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
|
|
get_define OFS_PMEM32x_ Pico32xMem pal_native ; echo "$line" >>$fn
|
|
|
|
get_define OFS_SH2_ SH2_ is_slave ; echo "$line" >>$fn
|
|
get_define OFS_SH2_ SH2_ p_bios ; echo "$line" >>$fn
|
|
get_define OFS_SH2_ SH2_ p_da ; echo "$line" >>$fn
|
|
get_define OFS_SH2_ SH2_ p_sdram ; echo "$line" >>$fn
|
|
get_define OFS_SH2_ SH2_ p_rom ; echo "$line" >>$fn
|
|
get_define OFS_SH2_ SH2_ p_dram ; echo "$line" >>$fn
|
|
get_define OFS_SH2_ SH2_ p_drcblk_da ; echo "$line" >>$fn
|
|
get_define OFS_SH2_ SH2_ p_drcblk_ram ; echo "$line" >>$fn
|