summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/Scripts/LauterbachT32/EfiLoadDxe.cmm
blob: 1605a9b478df76ff82edcea3ac1816f23fd84a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
;
; Copyright (c) 2011, Hewlett-Packard Company. All rights reserved.<BR>
; 
; SPDX-License-Identifier: BSD-2-Clause-Patent
; 

  LOCAL &maxmem &systbl &memsize
  
  &memsize=0x20000000   ; default to 512MB
  
  gosub FindSystemTable &memsize
  ENTRY &systbl
  
  if &systbl!=0
  (
    print "found system table at &systbl"
    gosub FindDebugInfo &systbl
  )
  else
  (
    print "ERROR: system table not found, check memory size"
  )
  enddo

FindSystemTable:
  LOCAL   &TopOfRam &offset
  ENTRY   &TopOfRam
  
  print "FindSystemTable"
  print "top of mem is &TopOfRam$"
  
  &offset=&TopOfRam
  
  ; align to highest 4MB boundary
  &offset=&offset&0xFFC00000
  
  ; start at top and look on 4MB boundaries for system table ptr structure
  while &offset>0
  (
    ; low signature match
    if Data.Long(a:&offset)==0x20494249
    (
      ; high signature match
      if Data.Long(a:&offset+4)==0x54535953
      (
        ; less than 4GB?
        if Data.Long(a:&offset+0x0c)==0
        (
          ; less than top of ram?
          if Data.Long(a:&offset+8)<&TopOfRam
          (
            return Data.Long(a:&offset+8)
          )
        )
      )
    )
   
    if &offset<0x400000
    (
      return 0
    )
    &offset=&offset-0x400000
  )
  
  return 0


FindDebugInfo:
  LOCAL   &SystemTable &CfgTableEntries &ConfigTable &i &offset &dbghdr &dbgentries &dbgptr &dbginfo &loadedimg
  ENTRY   &SystemTable
  
  print "FindDebugInfo"
  
  &dbgentries=0
  &CfgTableEntries=Data.Long(a:&SystemTable+0x40)
  &ConfigTable=Data.Long(a:&SystemTable+0x44)
  
  print "config table is at &ConfigTable (&CfgTableEntries entries)"
  
  ; now search for debug info entry with guid 49152E77-1ADA-4764-B7A2-7AFEFED95E8B
  ;	0x49152E77	0x47641ADA	0xFE7AA2B7	0x8B5ED9FE
  &i=0
  while &i<&CfgTableEntries
  (
    &offset=&ConfigTable+(&i*0x14)
    if Data.Long(a:&offset)==0x49152E77
    (
      if Data.Long(a:&offset+4)==0x47641ADA
      (
        if Data.Long(a:&offset+8)==0xFE7AA2B7
        (
          if Data.Long(a:&offset+0xc)==0x8B5ED9FE
          (
            &dbghdr=Data.Long(a:&offset+0x10)
            &dbgentries=Data.Long(a:&dbghdr+4)
            &dbgptr=Data.Long(a:&dbghdr+8)
          )
        )
      )
    )
    
    &i=&i+1
  )
  
  if &dbgentries==0
  (
    print "no debug entries found"
    return
  )
  
  print "debug table at &dbgptr (&dbgentries entries)"
  
  symbol.reset
  
  &i=0
  while &i<&dbgentries
  (
    &dbginfo=Data.Long(a:&dbgptr+(&i*4))
    if &dbginfo!=0
    (
      if Data.Long(a:&dbginfo)==1 ; normal debug info type
      (
        &loadedimg=Data.Long(a:&dbginfo+4)
        do EfiProcessPeImage Data.Long(a:&loadedimg+0x20)
      )
    )
    &i=&i+1
  )
  return