Home | History | Annotate | Download | only in Debugger_scripts
      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   ;Create AREA to display the symbols we are loading.
     22   AREA.Reset
     23   AREA.Create SYMBOL 300. 100.
     24   AREA.View SYMBOL
     25   AREA.Select SYMBOL
     26   SYS.Option BE OFF
     27  
     28   ;Added based on suggestion from Lauterbach support.
     29   MMU.TABLEWALK ON
     30   MMU.ON
     31 
     32   ;Load symbols.
     33   GOSUB load_symbols &ram_start &ram_size
     34 
     35   ;Open some windows and enable semihosting.
     36   TOOLBAR ON
     37   STATUSBAR ON
     38   WINPAGE.RESET
     39    
     40   WINCLEAR
     41   WINPOS 0.0 17.0 72. 13. 0. 0. W000
     42   SYStem
     43    
     44   WINPOS 0.0 0.0 110. 55. 13. 1. W001
     45   WINTABS 10. 10. 25. 62.
     46   Data.List
     47    
     48   WINPAGE.SELECT P000
     49 
     50   //Enable semihosting
     51   System.Option.BigEndian OFF
     52 
     53   tronchip.set swi on		// ARM9/10/11 variant
     54 
     55   // configure and open semihosting channel
     56   winpos 50% 50% 50% 50%
     57   term.heapinfo 0 0x20000 0x30000 0x20000
     58   term.method armswi
     59   term.mode string
     60   term.gate
     61 
     62   WINPOS 115.0 0. 70. 35. 0. 1. W002
     63   Var.Local %HEX
     64   
     65   WINPOS 115.10 45. 48. 9. 0. 0. W003
     66   Register
     67     
     68   END
     69 
     70 find_system_table:
     71   ENTRY &mem_start &mem_size
     72   &mem_ptr=&mem_start+&mem_size
     73   RPT    
     74   (
     75     &mem_ptr=&mem_ptr-0x400000  // 4 MB
     76     &word1=Data.LONG(D:&mem_ptr)
     77     &word2=Data.LONG(D:&mem_ptr+0x04)
     78     IF &word1==0x20494249
     79     (
     80       IF &word2==0x54535953
     81       (
     82         &result=Data.LONG(D:&mem_ptr+0x08)
     83         RETURN &result
     84       )
     85     )
     86   )
     87   WHILE &mem_ptr>&mem_start
     88   &result=0
     89   RETURN &result
     90 
     91 compare_guid:
     92   ENTRY &guid
     93   IF Data.LONG(D:&guid)==0x49152E77
     94   (
     95     IF Data.LONG(D:&guid+0x04)==0x47641ADA
     96     (
     97       IF Data.LONG(D:&guid+0x08)==0xFE7AA2B7
     98       (
     99         IF Data.LONG(D:&guid+0x0C)==0x8B5ED9FE
    100         (
    101           RETURN 0
    102         )
    103       )
    104     )
    105   )
    106   RETURN 1  
    107 
    108 find_debug_info_table_header:
    109   ENTRY &system_table
    110   &config_table_entries=Data.LONG(D:&system_table+0x40)
    111   &config_table_pointer=Data.LONG(D:&system_table+0x44)
    112   RPT &config_table_entries
    113   (
    114     GOSUB compare_guid &config_table_pointer
    115     ENTRY &result
    116     IF &result==0
    117     (
    118       &result=Data.LONG(D:&config_table_pointer+0x10)
    119       RETURN &result
    120     )  
    121     &config_table_pointer=&config_table_pointer+0x14
    122   )
    123   RETURN 0;
    124 
    125 valid_pe_header:
    126   ENTRY &header
    127   IF Data.BYTE(D:&header+0x00)==0x4D
    128   (
    129     IF Data.BYTE(D:&header+0x01)==0x5A
    130     (
    131       IF Data.BYTE(D:&header+0x80)==0x50
    132       (
    133         IF Data.BYTE(D:&header+0x81)==0x45
    134         (
    135           RETURN 1
    136         )
    137       )
    138     )
    139   )
    140   RETURN 0
    141 
    142 get_file_string:
    143   ENTRY &stringOffset
    144 
    145   local &string
    146 
    147   &more_string=data.string(d:&stringOffset)
    148 
    149   if (string.len("&more_string")>=128.)
    150   (
    151     &string="&string"+"&more_string"
    152     &stringOffset=&stringOffset+string.len("&more_string")
    153 
    154     //Get remaining file string
    155     GOSUB get_file_string &stringOffset
    156     ENTRY &more_string
    157     &string="&string"+"&more_string"
    158   )
    159   else
    160   (
    161     &string="&string"+"&more_string"
    162     &more_string=""
    163   )
    164   RETURN &string
    165  
    166 load_symbol_file:
    167   ENTRY &header &load_address
    168   GOSUB valid_pe_header &header
    169   ENTRY &result
    170  
    171   IF &result==1
    172   (
    173     &debugOffset=Data.LONG(D:&header+0x0128)
    174     &stringOffset=&header+&debugOffset+0x002C
    175     
    176     GOSUB get_file_string &stringOffset
    177     ENTRY &filestring
    178         
    179     PRINT "&filestring 0x" &load_address
    180     TDIAG Data.load.elf &filestring &load_address /nocode /noclear
    181   )
    182   RETURN
    183 
    184 pe_headersize:
    185   ENTRY &header;
    186   RETURN Data.LONG(D:&header+0x00AC)
    187 
    188 load_symbols:
    189   ENTRY &mem_start &mem_size
    190   GOSUB find_system_table &mem_start &mem_size
    191   ENTRY &system_table
    192   GOSUB find_debug_info_table_header &system_table
    193   ENTRY &debug_info_table_header
    194   &debug_info_table=Data.LONG(D:&debug_info_table_header+0x08)
    195   &debug_info_table_size=Data.LONG(D:&debug_info_table_header+0x04)
    196   &index=0
    197   RPT &debug_info_table_size
    198   (
    199     &debug_image_info=Data.LONG(D:&debug_info_table+&index)
    200     IF &debug_image_info==0
    201       RETURN        
    202     &loaded_image_protocol=Data.LONG(D:&debug_image_info+0x04);
    203     &image_base=Data.LONG(D:&loaded_image_protocol+0x20);
    204     GOSUB pe_headersize &image_base
    205     ENTRY &header_size
    206     &image_load_address=&image_base+&header_size
    207     GOSUB load_symbol_file &image_base &image_load_address
    208     &index=&index+0x4
    209   )
    210     
    211   RETURN
    212