]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuVideoDxe/VbeShim.sh
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / QemuVideoDxe / VbeShim.sh
CommitLineData
90803342
LE
1#!/bin/sh
2###
3# @file
4# Shell script to assemble and dump the fake Int10h handler from NASM source to
5# a C array.
6#
7# Copyright (C) 2014, Red Hat, Inc.
8# Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
9#
b26f0cf9 10# SPDX-License-Identifier: BSD-2-Clause-Patent
90803342
LE
11#
12###
13
14set -e -u
15
16STEM=$(dirname -- "$0")/$(basename -- "$0" .sh)
17
18#
19# Install exit handler -- remove temporary files.
20#
21exit_handler()
22{
23 rm -f -- "$STEM".bin "$STEM".disasm "$STEM".offsets "$STEM".insns \
24 "$STEM".bytes
25}
26trap exit_handler EXIT
27
28#
29# Assemble the source file.
12e4043b
LE
30# (nasm doesn't recognize the "--" end-of-options delimiter;
31# <https://bugzilla.nasm.us/show_bug.cgi?id=3392829>.)
90803342 32#
12e4043b 33nasm -o "$STEM".bin "$STEM".asm
90803342
LE
34
35#
36# Disassemble it, in order to get a binary dump associated with the source.
12e4043b
LE
37# (ndisasm doesn't recognize the "--" end-of-options delimiter;
38# <https://bugzilla.nasm.us/show_bug.cgi?id=3392829>.)
90803342
LE
39#
40ndisasm "$STEM".bin >"$STEM".disasm
41
42#
43# Create three files, each with one column of the disassembly.
44#
45# The first column contains the offsets, and it starts the comment.
46#
47cut -c 1-8 -- "$STEM".disasm \
48| sed -e 's,^, /* ,' >"$STEM".offsets
49
50#
51# The second column contains the assembly-language instructions, and it closes
52# the comment. We first pad it to 30 characters.
53#
54cut -c 29- -- "$STEM".disasm \
55| sed -e 's,$, ,' \
56 -e 's,^\(.\{30\}\).*$,\1 */,' >"$STEM".insns
57
58#
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.
62#
63cut -c 11-28 -- "$STEM".disasm \
64| sed -e 's, \+$,,' -e 's/\(..\)/ 0x\1,/g' >"$STEM".bytes
65
66#
67# Write the output file, recombining the columns. The output should have CRLF
68# line endings.
69#
70{
71 printf '//\n'
72 printf '// THIS FILE WAS GENERATED BY "%s". DO NOT EDIT.\n' \
73 "$(basename -- "$0")"
74 printf '//\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
79 printf '};\n'
80 printf '#endif\n'
81} \
82| unix2dos >"$STEM".h