]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuVideoDxe/VbeShim.sh
4 # Shell script to assemble and dump the fake Int10h handler from NASM source to
7 # Copyright (C) 2014, Red Hat, Inc.
8 # Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
10 # SPDX-License-Identifier: BSD-2-Clause-Patent
16 STEM
=$
(dirname -- "$0")/$
(basename -- "$0" .sh
)
19 # Install exit handler -- remove temporary files.
23 rm -f -- "$STEM".bin
"$STEM".disasm
"$STEM".offsets
"$STEM".insns \
26 trap exit_handler EXIT
29 # Assemble the source file.
30 # (nasm doesn't recognize the "--" end-of-options delimiter;
31 # <https://bugzilla.nasm.us/show_bug.cgi?id=3392829>.)
33 nasm
-o "$STEM".bin
"$STEM".asm
36 # Disassemble it, in order to get a binary dump associated with the source.
37 # (ndisasm doesn't recognize the "--" end-of-options delimiter;
38 # <https://bugzilla.nasm.us/show_bug.cgi?id=3392829>.)
40 ndisasm
"$STEM".bin
>"$STEM".disasm
43 # Create three files, each with one column of the disassembly.
45 # The first column contains the offsets, and it starts the comment.
47 cut
-c 1-8 -- "$STEM".disasm \
48 |
sed -e 's,^, /* ,' >"$STEM".offsets
51 # The second column contains the assembly-language instructions, and it closes
52 # the comment. We first pad it to 30 characters.
54 cut
-c 29- -- "$STEM".disasm \
56 -e 's,^\(.\{30\}\).*$,\1 */,' >"$STEM".insns
59 # The third column contains the bytes corresponding to the instruction,
60 # represented as C integer constants. First strip trailing whitespace from the
61 # middle column of the input disassembly, then process pairs of nibbles.
63 cut
-c 11-28 -- "$STEM".disasm \
64 |
sed -e 's, \+$,,' -e 's/\(..\)/ 0x\1,/g' >"$STEM".bytes
67 # Write the output file, recombining the columns. The output should have CRLF
72 printf '// THIS FILE WAS GENERATED BY "%s". DO NOT EDIT.\n' \
75 printf '#ifndef _VBE_SHIM_H_\n'
76 printf '#define _VBE_SHIM_H_\n'
77 printf 'STATIC CONST UINT8 mVbeShim[] = {\n'
78 paste -d ' ' -- "$STEM".offsets
"$STEM".insns
"$STEM".bytes