Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: elfdbg64.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: @(#)elfdbg64.fth 1.2 95/09/14 | |
43 | purpose: | |
44 | copyright: Copyright 1991-1994 Sun Microsystems, Inc. All Rights Reserved | |
45 | ||
46 | headerless | |
47 | : get-s64hdr ( filebase index -- ) | |
48 | e64_shentsize * e64_shoff + + | |
49 | elf64-sheader e64_shentsize move | |
50 | ; | |
51 | ||
52 | : >elf64-st_name ( sym-entry -- cstr ) st64_name l@ strings + ; | |
53 | : >elf64-st_value ( sym-entry -- symbol-address ) st64_value x@ ; | |
54 | : >elf64-st_info ( sym-entry -- valid-sym? ) st64_info c@ h# 0f and 1 2 between ; | |
55 | ||
56 | headers | |
57 | : init-elf64syms ( filebase -- filebase ) | |
58 | 0 to strings 0 to /strings | |
59 | 0 to symbols 0 to /symbols | |
60 | e64_shnum 0 ?do | |
61 | \ ." symtab " i . cr | |
62 | dup i get-s64hdr | |
63 | sh64_type SHT_SYMTAB = sh64_link 1- i = and if | |
64 | sh64_offset is symbols | |
65 | \ symbols . cr | |
66 | sh64_size is /symbols | |
67 | \ /symbols . cr | |
68 | leave | |
69 | then | |
70 | loop ( filebase ) | |
71 | symbols if | |
72 | e64_shnum sh64_link ?do | |
73 | \ ." strtab " i . cr | |
74 | dup sh64_link get-s64hdr | |
75 | sh64_type SHT_STRTAB = if | |
76 | strings 0= if | |
77 | sh64_offset is strings | |
78 | sh64_size is /strings | |
79 | else | |
80 | strings /strings + sh64_offset = if | |
81 | sh64_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 | ['] >elf64-st_name is >string | |
100 | ['] >elf64-st_value is >value | |
101 | ['] >elf64-st_info is >sym_type | |
102 | /elf64-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-elf64? ( -- is-elf? ) | |
114 | true | |
115 | e64_magicword h# 7f454c46 = and | |
116 | e64_class ELFCLASS64 = and | |
117 | ; | |
118 | : get-p64hdr ( filebase index -- ) | |
119 | e64_phentsize * e64_phoff + + | |
120 | elf64-pheader e64_phentsize move | |
121 | ; | |
122 | : get-elf64hdr ( base -- ) | |
123 | elf64-header /elf64-header 0 fill ( filebase ) | |
124 | dup elf64-header /elf64-header move ( filebase ) | |
125 | ; | |
126 | : init-elf64load ( filebase -- filebase ) | |
127 | e64_phnum 0 ?do ( filebase ) | |
128 | dup i get-p64hdr | |
129 | p64_type PT_LOAD = if | |
130 | \ Move it into the correct vaddr. | |
131 | dup p64_offset + p64_vaddr p64_filesz move | |
132 | p64_memsz p64_filesz > if | |
133 | \ Zero out the BSS section. | |
134 | p64_vaddr p64_filesz + p64_memsz p64_filesz - erase | |
135 | then | |
136 | then | |
137 | loop ( filebase ) | |
138 | ; | |
139 | : adjust-elf64-header ( filebase -- entry-point true | false ) | |
140 | get-elf64hdr is-elf64? 0= if drop false exit then | |
141 | ||
142 | init-elf64syms ( filebase ) | |
143 | init-elf64load ( filebase ) | |
144 | drop e64_entry true ( entry true ) | |
145 | ; | |
146 | ||
147 | headers |