Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: aout.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | \ aout.fth 2.4 97/01/23 | |
43 | \ Copyright 1985-1990 Bradley Forthware | |
44 | ||
45 | \ Support for reading "a.out" (linker) files | |
46 | \ This is system-dependent; this version is correct for Sun Microsystems' | |
47 | \ implementation of 4.2 BSD. Other systems may be more or less different | |
48 | \ For instance, Masscomp splits the a_magic field into 2 16-bit words. | |
49 | \ System V uses a "common object file format" which is much different. | |
50 | ||
51 | decimal | |
52 | headerless | |
53 | struct \ "a.out-header" structure - a.out header | |
54 | 0 field a_magicword \ Alias for the next 4 bytes as a whole | |
55 | /c field a_toolversion | |
56 | /c field a_machtype | |
57 | /w field a_magic | |
58 | /l field a_text | |
59 | /l field a_data | |
60 | /l field a_bss | |
61 | /l field a_syms | |
62 | /l field a_entry | |
63 | /l field a_trsize | |
64 | /l field a_drsize | |
65 | constant /a.out-header | |
66 | /a.out-header buffer: a.out-header | |
67 | ||
68 | \ Words which return the size in bytes of various components of the a.out file | |
69 | ||
70 | : /text ( -- size-of-text-segment ) a.out-header a_text l@ ; | |
71 | : /data ( -- size-of-data-segment ) a.out-header a_data l@ ; | |
72 | : /bss ( -- size-of-bss-segment ) a.out-header a_bss l@ ; | |
73 | : /syms ( -- size-of-symbol-table ) a.out-header a_syms l@ ; | |
74 | : /reloc ( -- size-of-relocation ) a.out-header a_trsize l@ | |
75 | a.out-header a_drsize l@ + ; | |
76 | : entry-adr ( -- load-address ) a.out-header a_entry l@ ; | |
77 | ||
78 | \ Words which return the offset from the start of the a.out file of various | |
79 | \ components of the a.out file | |
80 | ||
81 | : text0 ( -- file-address-of-text ) /a.out-header ; | |
82 | : data0 ( -- file-address-of-data ) text0 /text + ; | |
83 | : reloc0 ( -- file-address-of-relocation ) data0 /data + ; | |
84 | : syms0 ( -- file-address-of-symbols ) reloc0 /reloc + ; | |
85 | : string0 ( -- file-address-of-strings ) syms0 /syms + ; | |
86 | ||
87 | : ?magic ( -- ) | |
88 | a.out-header a_magic w@ h# 107 <> | |
89 | abort" Magic number is not (octal) 407" | |
90 | ; | |
91 | : read-header ( -- ) | |
92 | a.out-header 4 ifd @ fgets 4 <> abort" Can't read the magic number" | |
93 | ?magic | |
94 | a.out-header 4 + /a.out-header 4 - ifd @ fgets | |
95 | /a.out-header 4 - <> abort" Can't read header" | |
96 | ; | |
97 | headers |