Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: elfdebug.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 | id: @(#)elfdebug.fth 1.5 95/09/14 | |
43 | purpose: | |
44 | copyright: Copyright 1991-1994 Sun Microsystems, Inc. All Rights Reserved | |
45 | ||
46 | headerless | |
47 | : get-s32hdr ( filebase index -- ) | |
48 | e32_shentsize * e32_shoff + + | |
49 | elf32-sheader e32_shentsize move | |
50 | ; | |
51 | ||
52 | : >elf32-st_name ( sym-entry -- cstr ) st32_name l@ strings + ; | |
53 | : >elf32-st_value ( sym-entry -- symbol-address ) st32_value l@ ; | |
54 | : >elf32-st_info ( sym-entry -- valid-sym? ) st32_info c@ h# 0f and 1 2 between ; | |
55 | ||
56 | headers | |
57 | : init-elf32syms ( filebase -- filebase ) | |
58 | 0 to strings 0 to /strings | |
59 | 0 to symbols 0 to /symbols | |
60 | e32_shnum 0 ?do | |
61 | \ ." symtab " i . cr | |
62 | dup i get-s32hdr | |
63 | sh32_type SHT_SYMTAB = sh32_link 1- i = and if | |
64 | sh32_offset is symbols | |
65 | \ symbols . cr | |
66 | sh32_size is /symbols | |
67 | \ /symbols . cr | |
68 | leave | |
69 | then | |
70 | loop ( filebase ) | |
71 | symbols if | |
72 | e32_shnum sh32_link ?do | |
73 | \ ." strtab " i . cr | |
74 | dup sh32_link get-s32hdr | |
75 | sh32_type SHT_STRTAB = if | |
76 | strings 0= if | |
77 | sh32_offset is strings | |
78 | sh32_size is /strings | |
79 | else | |
80 | strings /strings + sh32_offset = if | |
81 | sh32_size /strings + to /strings | |
82 | else | |
83 | leave | |
84 | then | |
85 | then | |
86 | then | |
87 | loop | |
88 | then ( filebase ) | |
89 | strings if | |
90 | \ ." symbols " symbols . /symbols . cr | |
91 | \ ." strings " strings . /strings . cr | |
92 | strings over + over symbols + ( filebase strbase symbase ) | |
93 | /symbols /strings + allocate-symtab ( filebase strbase symbase addr ) | |
94 | tuck /symbols move ( filebase strbase addr ) | |
95 | dup to symbols ( filebase strbase addr ) | |
96 | /symbols + ( filebase strbase addr' ) | |
97 | tuck /strings move ( filebase addr' ) | |
98 | to strings | |
99 | ['] >elf32-st_name is >string | |
100 | ['] >elf32-st_value is >value | |
101 | ['] >elf32-st_info is >sym_type | |
102 | /elf32-symbol to /symtab-entry | |
103 | ['] $sym-handle-literal? is $handle-literal? | |
104 | else | |
105 | 0 to strings 0 to /strings | |
106 | 0 to symbols 0 to /symbols | |
107 | then ( filebase ) | |
108 | ; | |
109 | ||
110 | ||
111 | headerless | |
112 | \ h# 7f454c46 \x7fELF | |
113 | : is-elf32? ( -- is-elf? ) | |
114 | true | |
115 | e32_magicword h# 7f454c46 = and | |
116 | e32_class ELFCLASS32 = and | |
117 | ; | |
118 | : get-p32hdr ( filebase index -- ) | |
119 | e32_phentsize * e32_phoff + + | |
120 | elf32-pheader e32_phentsize move | |
121 | ; | |
122 | : get-elf32hdr ( base -- ) | |
123 | elf32-header /elf32-header 0 fill ( filebase ) | |
124 | dup elf32-header /elf32-header move ( filebase ) | |
125 | ; | |
126 | : init-elf32load ( filebase -- filebase ) | |
127 | e32_phnum 0 ?do ( filebase ) | |
128 | dup i get-p32hdr | |
129 | p32_type PT_LOAD = if | |
130 | \ Move it into the correct vaddr. | |
131 | dup p32_offset + p32_vaddr p32_filesz move | |
132 | p32_memsz p32_filesz > if | |
133 | \ Zero out the BSS section. | |
134 | p32_vaddr p32_filesz + p32_memsz p32_filesz - erase | |
135 | then | |
136 | then | |
137 | loop ( filebase ) | |
138 | ; | |
139 | : adjust-elf32-header ( filebase -- entry-point true | false ) | |
140 | get-elf32hdr is-elf32? 0= if drop false exit then | |
141 | ||
142 | init-elf32syms ( filebase ) | |
143 | init-elf32load ( filebase ) | |
144 | drop e32_entry true ( entry true ) | |
145 | ; | |
146 | ||
147 | headers |