]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuVideoDxe/VbeShim.sh
NetworkPkg: Move Network library header file from MdeModulePkg to NetworkPkg
[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.
30#
31nasm -o "$STEM".bin -- "$STEM".asm
32
33#
34# Disassemble it, in order to get a binary dump associated with the source.
35# (ndisasm doesn't recognize the "--" end-of-options delimiter.)
36#
37ndisasm "$STEM".bin >"$STEM".disasm
38
39#
40# Create three files, each with one column of the disassembly.
41#
42# The first column contains the offsets, and it starts the comment.
43#
44cut -c 1-8 -- "$STEM".disasm \
45| sed -e 's,^, /* ,' >"$STEM".offsets
46
47#
48# The second column contains the assembly-language instructions, and it closes
49# the comment. We first pad it to 30 characters.
50#
51cut -c 29- -- "$STEM".disasm \
52| sed -e 's,$, ,' \
53 -e 's,^\(.\{30\}\).*$,\1 */,' >"$STEM".insns
54
55#
56# The third column contains the bytes corresponding to the instruction,
57# represented as C integer constants. First strip trailing whitespace from the
58# middle column of the input disassembly, then process pairs of nibbles.
59#
60cut -c 11-28 -- "$STEM".disasm \
61| sed -e 's, \+$,,' -e 's/\(..\)/ 0x\1,/g' >"$STEM".bytes
62
63#
64# Write the output file, recombining the columns. The output should have CRLF
65# line endings.
66#
67{
68 printf '//\n'
69 printf '// THIS FILE WAS GENERATED BY "%s". DO NOT EDIT.\n' \
70 "$(basename -- "$0")"
71 printf '//\n'
72 printf '#ifndef _VBE_SHIM_H_\n'
73 printf '#define _VBE_SHIM_H_\n'
74 printf 'STATIC CONST UINT8 mVbeShim[] = {\n'
75 paste -d ' ' -- "$STEM".offsets "$STEM".insns "$STEM".bytes
76 printf '};\n'
77 printf '#endif\n'
78} \
79| unix2dos >"$STEM".h