| 1 |
#!/bin/sh - |
| 2 |
# |
| 3 |
# This file is simply an example of what can be done using the new binary |
| 4 |
# and symbol table output functions. It produces a byte array with the |
| 5 |
# symbols in the object as array references within it. |
| 6 |
# |
| 7 |
# The output is a Linux OMAGIC binary created by ld86 -N, this means the |
| 8 |
# object can be linked directly to C-functions created by the same GCC that |
| 9 |
# compiled ld86. |
| 10 |
# |
| 11 |
# Use it in a makefile: |
| 12 |
# |
| 13 |
# .s86.o: |
| 14 |
# as86_to_data $*.s86 $*.o $(AS86FLAGS) |
| 15 |
# |
| 16 |
|
| 17 |
[ $# -lt 2 ] && { |
| 18 |
echo "Usage: `basename $0` infile outfile [as86 opts]" 1>&2 |
| 19 |
exit 1 |
| 20 |
} |
| 21 |
|
| 22 |
trap "rm -f _$$.* ; exit 99" 1 2 3 15 |
| 23 |
|
| 24 |
LIBDIR='%%LIBDIR%%' # Set by make install |
| 25 |
[ -d "$LIBDIR" ] || LIBDIR='%%BINDIR%%' |
| 26 |
[ -d "$LIBDIR" ] || LIBDIR=/usr/bin |
| 27 |
|
| 28 |
IFILE="$1" |
| 29 |
OFILE="$2" |
| 30 |
|
| 31 |
shift ; shift |
| 32 |
RV=0 |
| 33 |
|
| 34 |
$LIBDIR/as86 "$@" "$IFILE" -b _$$.bin -s _$$.sym || RV=$? |
| 35 |
|
| 36 |
[ "$RV" = 0 ] && { |
| 37 |
( |
| 38 |
cat _$$.sym |
| 39 |
echo %%%% |
| 40 |
od -v -t uC _$$.bin |
| 41 |
echo %%%% |
| 42 |
) | \ |
| 43 |
awk > _$$.v ' BEGIN{ |
| 44 |
startaddr=""; |
| 45 |
printf ".text\n.data\n"; |
| 46 |
} |
| 47 |
/^%%%%$/ { flg++; |
| 48 |
next; |
| 49 |
} |
| 50 |
flg==0 { |
| 51 |
if(NF == 0) next; |
| 52 |
if( substr($2,1,4) == "0000" ) $2=substr($2,5); |
| 53 |
if( $1 == "+" && $4 == "$start" ) |
| 54 |
{ |
| 55 |
if( $2 != "0000" ) startaddr=" - $" $2; |
| 56 |
} |
| 57 |
else if( substr($3, 1, 1) == "E" && $4 != "start" && $4 != "size" && $4 != "data" ) |
| 58 |
{ |
| 59 |
printf "export _%s\n", $4 |
| 60 |
printf "_%s = * + $%s%s\n\n", $4, $2, startaddr; |
| 61 |
} |
| 62 |
next; |
| 63 |
} |
| 64 |
flg==1 { |
| 65 |
if(NF <= 1) next; |
| 66 |
printf " .byte "; |
| 67 |
for(i=2;i<NF;i++) printf("%3d,", $i); |
| 68 |
printf("%3d", $NF); |
| 69 |
printf "\n"; |
| 70 |
} |
| 71 |
' |
| 72 |
RV=$? |
| 73 |
} |
| 74 |
|
| 75 |
[ "$RV" = 0 ] || { rm -f _$$.* ; exit $RV ; } |
| 76 |
|
| 77 |
# If you want to see the assembler. |
| 78 |
# cp _$$.v `basename $2 .o`.asm |
| 79 |
|
| 80 |
$LIBDIR/as86 -o _$$.o86 _$$.v || RV=$? |
| 81 |
|
| 82 |
[ "$RV" = 0 ] || { rm -f _$$.* ; exit $RV ; } |
| 83 |
|
| 84 |
$LIBDIR/ld86 -r -N _$$.o86 -o _$$.o || RV=$? |
| 85 |
|
| 86 |
[ "$RV" = 0 ] || { rm -f _$$.* ; exit $RV ; } |
| 87 |
|
| 88 |
if [ "X$OFILE" = "X-" ] |
| 89 |
then cat _$$.o |
| 90 |
else mv -f _$$.o "$OFILE" || RV=$? |
| 91 |
fi |
| 92 |
|
| 93 |
rm -f _$$.* |
| 94 |
exit $RV |