Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/conf Use shell arithmetic as much as possible a...



details:   https://anonhg.NetBSD.org/src/rev/bbafa20c8520
branches:  trunk
changeset: 522527:bbafa20c8520
user:      skrll <skrll%NetBSD.org@localhost>
date:      Wed Feb 20 21:54:08 2002 +0000

description:
Use shell arithmetic as much as possible and reduce the number of times
that awk is used to one.

No functional change.

diffstat:

 sys/arch/arm/conf/elf2aout.sh |  62 ++++++++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 26 deletions(-)

diffs (94 lines):

diff -r a5e99c8d88c7 -r bbafa20c8520 sys/arch/arm/conf/elf2aout.sh
--- a/sys/arch/arm/conf/elf2aout.sh     Wed Feb 20 21:42:35 2002 +0000
+++ b/sys/arch/arm/conf/elf2aout.sh     Wed Feb 20 21:54:08 2002 +0000
@@ -1,5 +1,6 @@
 #!/bin/sh
-# $NetBSD: elf2aout.sh,v 1.2 2002/02/09 11:53:58 chris Exp $
+# $NetBSD: elf2aout.sh,v 1.3 2002/02/20 21:54:08 skrll Exp $
+#
 # Shell script to convert an ARM ELF kernel into a bootable a.out kernel by
 # changing the header block on the kernel, and shuffling bits around in the
 # file.  Care has to be taken with the sections as they need to be page
@@ -9,14 +10,16 @@
 # XXX bugs lurking in BFD prevent it from doing so.
 
 AWKPROG='\
-function r(v) { return sprintf("%d", ((v + 4095) / 4096)) * 4096 } \
 function x(v) { printf "%c%c%c\0", v, v / 256, v / 65536 } \
 { \
         printf "\0\217\01\013"; \
-        x(r($1)); \
-        x(r($2 + 32768 - (r($1) - $1))); \
+        x($1); \
+        x($2); \
         x($3); \
-        printf "\0\0\0\0\040\0\0\360\0\0\0\0\0\0\0\0" \
+        printf "\0\0\0\0"; \
+        printf "\040\0\0\360"; \
+        printf "\0\0\0\0"; \
+        printf "\0\0\0\0" \
 }'
 
 infile=${1}
@@ -27,33 +30,40 @@
 ${OBJCOPY} -O binary -j .text ${infile} ${infile}.text || exit 1
 ${OBJCOPY} -O binary -j .data ${infile} ${infile}.data || exit 1
 
-TEXT=`${SIZE} ${infile} | tail +2 | awk '
-function r(v) { return sprintf("%d", ((v + 4095) / 4096)) * 4096 }
-{print r($1)}'`
-echo TEXT = $TEXT
+set -- `${SIZE} ${infile} | tail +2`
+TEXT=$1
+DATA=$2
+BSS=$3
 
-TPAD=`${SIZE} ${infile} | tail +2 | awk '
-       function r(v) { return sprintf("%d", ((v + 4095) / 4096)) * 4096 }
-       {print r($1) - $1}'`
-       echo TPAD = $TPAD
+TALIGN=$(( (($TEXT + 4095) / 4096) * 4096 ))
+DALIGN=$(( (($DATA + 4095) / 4096) * 4096 ))
+BALIGN=$(( (($BSS + 4095) / 4096) * 4096 ))
+
+TPAD=$(( $TALIGN - $TEXT ))
+DPAD=$(( $DALIGN - $DATA ))
+BPAD=$(( $BALIGN - $BSS ))
+
+DTMP=$(( $DATA + 32768 - $TPAD ))
 
-DATA=`${SIZE} ${infile} | tail +2 | awk '
-function r(v) { return sprintf("%d", ((v + 4095) / 4096)) * 4096 }
-{print r($2 + 32768 - (r($1) - $1))}'`
-echo DATA = $DATA
+TDPAD=32768
+DBPAD=$(( ((($DTMP + 4095) / 4096) * 4096) - $DTMP ))
+
+echo TEXT      = $TEXT
+echo TPAD      = $TPAD
+echo TDPAD     = $TDPAD
 
-DPAD=`${SIZE} ${infile} | tail +2 | awk '
-function r(v) { return sprintf("%d", ((v + 4095) / 4096)) * 4096 }
-{print r($2 + 32768 - (r($1) - $1)) - ($2 + 32768 - (r($1) - $1))}'`
-echo DPAD = $DPAD
+echo DATA      = $DATA
+echo DPAD      = $DPAD
+echo DBPAD     = $DBPAD
 
-cp -f ${infile} ${infile}.elf
-(${SIZE} ${infile}.elf | tail +2 | awk "${AWKPROG}" ; \
-  cat ${infile}.text ; dd if=/dev/zero bs=32k count=1; cat ${infile}.data; dd if=/dev/zero bs=$DPAD count=1 \
+(
+       echo $TALIGN $DTMP $BSS | awk "${AWKPROG}"; \
+       cat ${infile}.text; \
+       dd if=/dev/zero bs=$TDPAD count=1; \
+       cat ${infile}.data; \
+       dd if=/dev/zero bs=$DBPAD count=1 \
 ) > ${outfile}
 
-rm ${infile}.elf
-
 ${SIZE} ${outfile}
 chmod 755 ${outfile}
 



Home | Main Index | Thread Index | Old Index