[gforth] / gforth / comp-i.fs  

gforth: gforth/comp-i.fs


1 : anton 1.1 \ Compare nonrelocatable images and produce a relocatable image
2 :    
3 : anton 1.3 \ Copyright (C) 1996,1997,1998 Free Software Foundation, Inc.
4 : anton 1.1
5 :     \ This file is part of Gforth.
6 :    
7 :     \ Gforth is free software; you can redistribute it and/or
8 :     \ modify it under the terms of the GNU General Public License
9 :     \ as published by the Free Software Foundation; either version 2
10 :     \ of the License, or (at your option) any later version.
11 :    
12 :     \ This program is distributed in the hope that it will be useful,
13 :     \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14 :     \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 :     \ GNU General Public License for more details.
16 :    
17 :     \ You should have received a copy of the GNU General Public License
18 :     \ along with this program; if not, write to the Free Software
19 : anton 1.5 \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 : anton 1.1
21 :     s" address-unit-bits" environment? drop constant bits/au
22 :     6 constant dodoes-tag
23 :    
24 :     : write-cell { w^ w file-id -- ior }
25 :     \ write a cell to the file
26 :     w cell file-id write-file ;
27 :    
28 :     : th ( addr1 n -- addr2 )
29 :     cells + ;
30 :    
31 : anton 1.7 : bset ( bmask c-addr -- )
32 :     tuck c@ or swap c! ;
33 :    
34 : anton 1.1 : set-bit { u addr -- }
35 :     \ set bit u in bit-vector addr
36 :     u bits/au /mod
37 :     >r 1 bits/au 1- rot - lshift
38 : anton 1.7 r> addr + bset ;
39 : anton 1.1
40 :     : compare-images { image1 image2 reloc-bits size file-id -- }
41 :     \G compares image1 and image2 (of size cells) and sets reloc-bits.
42 :     \G offset is the difference for relocated addresses
43 :     \ this definition is certainly to long and too complex, but is
44 :     \ hard to factor.
45 :     image1 @ image2 @ over - { dbase doffset }
46 :     doffset 0= abort" images have the same dictionary base address"
47 :     ." data offset=" doffset . cr
48 :     image1 cell+ @ image2 cell+ @ over - { cbase coffset }
49 :     coffset 0=
50 :     if
51 :     ." images have the same code base address; producing only a data-relocatable image" cr
52 :     else
53 : pazsan 1.2 coffset abs 22 cells <> abort" images produced by different engines"
54 : anton 1.1 ." code offset=" coffset . cr
55 :     0 image1 cell+ ! 0 image2 cell+ !
56 :     endif
57 :     size 0
58 :     u+do
59 :     image1 i th @ image2 i th @ { cell1 cell2 }
60 :     cell1 doffset + cell2 =
61 :     if
62 :     cell1 dbase - file-id write-cell throw
63 :     i reloc-bits set-bit
64 :     else
65 :     coffset 0<> cell1 coffset + cell2 = and
66 :     if
67 :     cell1 cbase - cell / { tag }
68 :     tag dodoes-tag =
69 :     if
70 :     \ make sure that the next cell will not be tagged
71 :     dbase negate image1 i 1+ th +!
72 :     dbase doffset + negate image2 i 1+ th +!
73 :     endif
74 :     -2 tag - file-id write-cell throw
75 :     i reloc-bits set-bit
76 :     else
77 :     cell1 file-id write-cell throw
78 :     cell1 cell2 <>
79 :     if
80 :     0 i th 9 u.r cell1 17 u.r cell2 17 u.r cr
81 :     endif
82 :     endif
83 :     endif
84 :     loop ;
85 :    
86 :     : comp-image ( "image-file1" "image-file2" "new-image" -- )
87 :     name slurp-file { image1 size1 }
88 : pazsan 1.4 image1 size1 s" Gforth2" search 0= abort" not a Gforth image"
89 : anton 1.1 drop 8 + image1 - { header-offset }
90 :     size1 aligned size1 <> abort" unaligned image size"
91 : anton 1.8 image1 header-offset + 2 cells + @ header-offset + size1 <> abort" header gives wrong size"
92 : anton 1.1 name slurp-file { image2 size2 }
93 :     size1 size2 <> abort" image sizes differ"
94 :     name ( "new-image" ) w/o bin create-file throw { outfile }
95 :     size1 header-offset - 1- cell / bits/au / 1+ { reloc-size }
96 :     reloc-size allocate throw { reloc-bits }
97 :     reloc-bits reloc-size erase
98 :     image1 header-offset outfile write-file throw
99 :     base @ hex
100 :     image1 header-offset + image2 header-offset + reloc-bits
101 :     size1 header-offset - aligned cell / outfile compare-images
102 :     base !
103 :     reloc-bits reloc-size outfile write-file throw
104 :     outfile close-file throw ;
105 :    
106 :    

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help