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 | #
|
---|
10 | # SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
11 | #
|
---|
12 | ###
|
---|
13 |
|
---|
14 | set -e -u
|
---|
15 |
|
---|
16 | STEM=$(dirname -- "$0")/$(basename -- "$0" .sh)
|
---|
17 |
|
---|
18 | #
|
---|
19 | # Install exit handler -- remove temporary files.
|
---|
20 | #
|
---|
21 | exit_handler()
|
---|
22 | {
|
---|
23 | rm -f -- "$STEM".bin "$STEM".disasm "$STEM".offsets "$STEM".insns \
|
---|
24 | "$STEM".bytes
|
---|
25 | }
|
---|
26 | trap exit_handler EXIT
|
---|
27 |
|
---|
28 | #
|
---|
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>.)
|
---|
32 | #
|
---|
33 | nasm -o "$STEM".bin "$STEM".asm
|
---|
34 |
|
---|
35 | #
|
---|
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>.)
|
---|
39 | #
|
---|
40 | ndisasm "$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 | #
|
---|
47 | cut -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 | #
|
---|
54 | cut -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 | #
|
---|
63 | cut -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
|
---|