]>
git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/ResetVector/Vtf0/Tools/FixupForRawSection.py
2 # Apply fixup to VTF binary image for FFS Raw section
4 # Copyright (c) 2008, Intel Corporation
6 # All rights reserved. This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 filename
= sys
.argv
[1]
19 if filename
.lower().find('ia32') >= 0:
20 d
= open(sys
.argv
[1], 'rb').read()
21 c
= ((len(d
) + 4 + 7) & ~
7) - 4
24 f
= open(sys
.argv
[1], 'wb')
29 from struct
import pack
32 PAGE_READ_WRITE
= 0x02
33 PAGE_USER_SUPERVISOR
= 0x04
34 PAGE_WRITE_THROUGH
= 0x08
35 PAGE_CACHE_DISABLE
= 0x010
44 c
= ((len(s
) + 0xfff) & ~
0xfff) - len(s
)
45 return ('\x90' * c
) + s
47 def PageDirectoryEntries4GbOf2MbPages(baseAddress
):
50 for i
in range(0x800):
52 baseAddress
+ long(i
<< 21) +
63 def PageDirectoryPointerTable4GbOf2MbPages(pdeBase
):
65 for i
in range(0x200):
77 def PageMapLevel4Table4GbOf2MbPages(pdptBase
):
79 for i
in range(0x200):
91 def First4GbPageEntries(topAddress
):
92 PDE
= PageDirectoryEntries4GbOf2MbPages(0L)
93 pml4tBase
= topAddress
- 0x1000
94 pdptBase
= pml4tBase
- 0x1000
95 pdeBase
= pdptBase
- len(PDE
)
96 PDPT
= PageDirectoryPointerTable4GbOf2MbPages(pdeBase
)
97 PML4T
= PageMapLevel4Table4GbOf2MbPages(pdptBase
)
98 return PDE
+ PDPT
+ PML4T
100 def AlignAndAddPageTables():
101 d
= open(sys
.argv
[1], 'rb').read()
103 topAddress
= 0x100000000 - len(code
)
104 d
= ('\x90' * 4) + First4GbPageEntries(topAddress
) + code
105 f
= open(sys
.argv
[1], 'wb')
109 AlignAndAddPageTables()