]>
Commit | Line | Data |
---|---|---|
656419f9 RC |
1 | #!/bin/sh\r |
2 | ###\r | |
3 | # @file\r | |
4 | # Shell script to assemble and dump the fake Int10h handler from NASM source to\r | |
5 | # a C array.\r | |
6 | #\r | |
7 | # Copyright (C) 2020, Rebecca Cran <rebecca@bsdio.com>\r | |
8 | # Copyright (C) 2014, Red Hat, Inc.\r | |
9 | # Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
10 | #\r | |
11 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
12 | #\r | |
13 | ###\r | |
14 | \r | |
15 | set -e -u\r | |
16 | \r | |
17 | STEM=$(dirname -- "$0")/$(basename -- "$0" .sh)\r | |
18 | \r | |
19 | #\r | |
20 | # Install exit handler -- remove temporary files.\r | |
21 | #\r | |
22 | exit_handler()\r | |
23 | {\r | |
24 | rm -f -- "$STEM".bin "$STEM".disasm "$STEM".offsets "$STEM".insns \\r | |
25 | "$STEM".bytes\r | |
26 | }\r | |
27 | trap exit_handler EXIT\r | |
28 | \r | |
29 | #\r | |
30 | # Assemble the source file.\r | |
31 | #\r | |
32 | nasm -o "$STEM".bin -- "$STEM".asm\r | |
33 | \r | |
34 | #\r | |
35 | # Disassemble it, in order to get a binary dump associated with the source.\r | |
36 | # (ndisasm doesn't recognize the "--" end-of-options delimiter.)\r | |
37 | #\r | |
38 | ndisasm "$STEM".bin >"$STEM".disasm\r | |
39 | \r | |
40 | #\r | |
41 | # Create three files, each with one column of the disassembly.\r | |
42 | #\r | |
43 | # The first column contains the offsets, and it starts the comment.\r | |
44 | #\r | |
45 | cut -c 1-8 -- "$STEM".disasm \\r | |
46 | | sed -e 's,^, /* ,' >"$STEM".offsets\r | |
47 | \r | |
48 | #\r | |
49 | # The second column contains the assembly-language instructions, and it closes\r | |
50 | # the comment. We first pad it to 30 characters.\r | |
51 | #\r | |
52 | cut -c 29- -- "$STEM".disasm \\r | |
53 | | sed -e 's,$, ,' \\r | |
54 | -e 's,^\(.\{30\}\).*$,\1 */,' >"$STEM".insns\r | |
55 | \r | |
56 | #\r | |
57 | # The third column contains the bytes corresponding to the instruction,\r | |
58 | # represented as C integer constants. First strip trailing whitespace from the\r | |
59 | # middle column of the input disassembly, then process pairs of nibbles.\r | |
60 | #\r | |
61 | cut -c 11-28 -- "$STEM".disasm \\r | |
62 | | sed -e 's, \+$,,' -e 's/\(..\)/ 0x\1,/g' | sed 's/0x ,//g' >"$STEM".bytes\r | |
63 | \r | |
64 | #\r | |
65 | # Write the output file, recombining the columns. The output should have CRLF\r | |
66 | # line endings.\r | |
67 | #\r | |
68 | {\r | |
69 | printf '//\n'\r | |
70 | printf '// THIS FILE WAS GENERATED BY "%s". DO NOT EDIT.\n' \\r | |
71 | "$(basename -- "$0")"\r | |
72 | printf '//\n'\r | |
73 | printf '#ifndef _VBE_SHIM_H_\n'\r | |
74 | printf '#define _VBE_SHIM_H_\n'\r | |
75 | printf 'STATIC CONST UINT8 mVbeShim[] = {\n'\r | |
76 | paste -d ' ' -- "$STEM".offsets "$STEM".insns "$STEM".bytes\r | |
77 | printf '};\n'\r | |
78 | printf '#endif\n'\r | |
79 | } \\r | |
80 | | unix2dos >"$STEM".h\r |