1// 2// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> 3// 4// This program and the accompanying materials 5// are licensed and made available under the terms and conditions of the BSD License 6// which accompanies this distribution. The full text of the license may be found at 7// http://opensource.org/licenses/bsd-license.php 8// 9// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11// 12 13 ENTRY &ram_start &ram_size 14 15 ;If system is running then stop the execution so we can load symbols. 16 break 17 18 ;Reset all windows 19 WINPAGE.RESET 20 21 AREA.Reset 22 AREA.Create SYMBOL 300. 100. 23 AREA.View SYMBOL 24 AREA.Select SYMBOL 25 SYS.Option BE OFF 26 27 ; Added based on suggestion from Lauterbach support. 28 MMU.TABLEWALK ON 29 MMU.ON 30 31 GOSUB load_symbols &ram_start &ram_size 32 33 ;Open some windows. 34 WINPOS 83.125 29.063 48. 9. 0. 0. W003 35 Register 36 37 WINPOS 83.25 10. 48. 9. 0. 1. W002 38 Var.Local 39 40 END 41 42find_system_table: 43 ENTRY &mem_start &mem_size 44 &mem_ptr=&mem_start+&mem_size 45 RPT 46 ( 47 &mem_ptr=&mem_ptr-0x400000 // 4 MB 48 &word1=Data.LONG(D:&mem_ptr) 49 &word2=Data.LONG(D:&mem_ptr+0x04) 50 IF &word1==0x20494249 51 ( 52 IF &word2==0x54535953 53 ( 54 &result=Data.LONG(D:&mem_ptr+0x08) 55 RETURN &result 56 ) 57 ) 58 ) 59 WHILE &mem_ptr>&mem_start 60 &result=0 61 RETURN &result 62 63compare_guid: 64 ENTRY &guid 65 IF Data.LONG(D:&guid)==0x49152E77 66 ( 67 IF Data.LONG(D:&guid+0x04)==0x47641ADA 68 ( 69 IF Data.LONG(D:&guid+0x08)==0xFE7AA2B7 70 ( 71 IF Data.LONG(D:&guid+0x0C)==0x8B5ED9FE 72 ( 73 RETURN 0 74 ) 75 ) 76 ) 77 ) 78 RETURN 1 79 80find_debug_info_table_header: 81 ENTRY &system_table 82 &config_table_entries=Data.LONG(D:&system_table+0x40) 83 &config_table_pointer=Data.LONG(D:&system_table+0x44) 84 RPT &config_table_entries 85 ( 86 GOSUB compare_guid &config_table_pointer 87 ENTRY &result 88 IF &result==0 89 ( 90 &result=Data.LONG(D:&config_table_pointer+0x10) 91 RETURN &result 92 ) 93 &config_table_pointer=&config_table_pointer+0x14 94 ) 95 RETURN 0; 96 97valid_pe_header: 98 ENTRY &header 99 IF Data.BYTE(D:&header+0x00)==0x4D 100 ( 101 IF Data.BYTE(D:&header+0x01)==0x5A 102 ( 103 IF Data.BYTE(D:&header+0x80)==0x50 104 ( 105 IF Data.BYTE(D:&header+0x81)==0x45 106 ( 107 RETURN 1 108 ) 109 ) 110 ) 111 ) 112 RETURN 0 113 114get_file_string: 115 ENTRY &stringOffset 116 117 local &string 118 119 &more_string=data.string(d:&stringOffset) 120 121 if (string.len("&more_string")>=128.) 122 ( 123 &string="&string"+"&more_string" 124 &stringOffset=&stringOffset+string.len("&more_string") 125 126 //Get remaining file string 127 GOSUB get_file_string &stringOffset 128 ENTRY &more_string 129 &string="&string"+"&more_string" 130 ) 131 else 132 ( 133 &string="&string"+"&more_string" 134 &more_string="" 135 ) 136 RETURN &string 137 138load_symbol_file: 139 ENTRY &header &load_address 140 GOSUB valid_pe_header &header 141 ENTRY &result 142 143 IF &result==1 144 ( 145 &debugOffset=Data.LONG(D:&header+0x0128) 146 &stringOffset=&header+&debugOffset+0x002C 147 148 &stringOffset=&stringOffset+11. 149 150 GOSUB get_file_string &stringOffset 151 ENTRY &filestring 152 153 &filestring="c:"+"&filestring" 154 155 PRINT "&filestring 0x" &load_address 156 Data.load.elf &filestring &load_address /nocode /noclear 157 ) 158 RETURN 159 160pe_headersize: 161 ENTRY &header; 162 RETURN Data.LONG(D:&header+0x00AC) 163 164load_symbols: 165 ENTRY &mem_start &mem_size 166 GOSUB find_system_table &mem_start &mem_size 167 ENTRY &system_table 168 GOSUB find_debug_info_table_header &system_table 169 ENTRY &debug_info_table_header 170 &debug_info_table=Data.LONG(D:&debug_info_table_header+0x08) 171 &debug_info_table_size=Data.LONG(D:&debug_info_table_header+0x04) 172 &index=0 173 RPT &debug_info_table_size 174 ( 175 &debug_image_info=Data.LONG(D:&debug_info_table+&index) 176 IF &debug_image_info==0 177 RETURN 178 &loaded_image_protocol=Data.LONG(D:&debug_image_info+0x04); 179 &image_base=Data.LONG(D:&loaded_image_protocol+0x20); 180 GOSUB pe_headersize &image_base 181 ENTRY &header_size 182 &image_load_address=&image_base+&header_size 183 GOSUB load_symbol_file &image_base &image_load_address 184 &index=&index+0x4 185 ) 186 187 RETURN 188