VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-linker.h@ 103068

Last change on this file since 103068 was 102285, checked in by vboxsync, 14 months ago

bs3kit: Implemented 16-bit prot segment setup for high-dlls, defaulting to ring-0 code with conforming as an option. bugref:10371

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/* $Id: bs3kit-linker.h 102285 2023-11-24 02:37:50Z vboxsync $ */
2/** @file
3 * BS3Kit - Linker related structures and defines.
4 */
5
6/*
7 * Copyright (C) 2007-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef BS3KIT_INCLUDED_bs3kit_linker_h
38#define BS3KIT_INCLUDED_bs3kit_linker_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#pragma pack(1)
44typedef struct BS3BOOTSECTOR
45{
46 uint8_t abJmp[3];
47 char abOemId[8];
48 /** @name EBPB, DOS 4.0 style.
49 * @{ */
50 uint16_t cBytesPerSector; /**< 00bh */
51 uint8_t cSectorsPerCluster; /**< 00dh */
52 uint16_t cReservedSectors; /**< 00eh */
53 uint8_t cFATs; /**< 010h */
54 uint16_t cRootDirEntries; /**< 011h */
55 uint16_t cTotalSectors; /**< 013h - We (ab)use this for the checksum length in sectors. */
56 uint8_t bMediaDescriptor; /**< 015h */
57 uint16_t cSectorsPerFAT; /**< 016h */
58 uint16_t cPhysSectorsPerTrack; /**< 018h */
59 uint16_t cHeads; /**< 01ah */
60 uint32_t cHiddentSectors; /**< 01ch */
61 uint32_t cLargeTotalSectors; /**< 020h - We (ab)use this to indicate the number of sectors to load. */
62 uint8_t bBootDrv; /**< 024h */
63 uint8_t bFlagsEtc; /**< 025h */
64 uint8_t bExtendedSignature; /**< 026h */
65 uint32_t dwSerialNumber; /**< 027h - We (ab)use this for the base image checksum. */
66 char abLabel[11]; /**< 02bh */
67 char abFSType[8]; /**< 036h */
68 /** @} */
69} BS3BOOTSECTOR;
70#pragma pack()
71typedef BS3BOOTSECTOR *PBS3BOOTSECTOR;
72
73AssertCompileMemberOffset(BS3BOOTSECTOR, cLargeTotalSectors, 0x20);
74AssertCompileMemberOffset(BS3BOOTSECTOR, abLabel, 0x2b);
75AssertCompileMemberOffset(BS3BOOTSECTOR, abFSType, 0x36);
76
77#define BS3_OEMID "BS3Kit\n\n"
78#define BS3_FSTYPE "RawCode\n"
79#define BS3_LABEL "VirtualBox\n"
80#define BS3_MAX_SIZE UINT32_C(491520) /* 480KB */
81
82
83/** The default address to start load high DLLs at.
84 * We start at 8MB to make sure the start is 16-bit tiled addressable, that we
85 * can load high DLLs on 286es, and to avoid using up the upper/tiled memory. */
86#define BS3HIGHDLL_LOAD_ADDRESS ( _8M )
87
88/**
89 * High DLL table entry.
90 * These are found at the end of the base image.
91 */
92typedef struct BS3HIGHDLLENTRY
93{
94 char achMagic[8]; /**< BS3HIGHDLLENTRY_MAGIC */
95 uint32_t uLoadAddr; /**< The load address. Set by the linker. */
96 uint32_t cbLoaded; /**< The number of bytes when loaded. */
97 uint32_t offInImage; /**< Byte offset in the linked image blob. */
98 uint32_t cbInImage; /**< The number of bytes to load from the linked image blob. */
99 uint32_t cImports; /**< Number of imports. */
100 int32_t offImports; /**< Relative address (to entry start) of the import table. */
101 uint32_t cExports; /**< Number of exports. */
102 int32_t offExports; /**< Relative address (to entry start) of the export table. */
103 uint32_t cSegments; /**< Number of segments. */
104 int32_t offSegments; /**< Relative address (to entry start) of the segment table. */
105 uint32_t cbStrings; /**< Size of the string table in bytes. */
106 int32_t offStrings; /**< Relative address (to entry start) of the string table. */
107 uint32_t offFilename; /**< String table offset of the DLL name (sans path, with extension). */
108 uint32_t uChecksum; /**< Simple checksum of all the on-disk image bits. */
109} BS3HIGHDLLENTRY;
110/** Magic value for BS3HIGHDLLENTRY. */
111#define BS3HIGHDLLENTRY_MAGIC "HighDLL"
112
113typedef struct BS3HIGHDLLIMPORTENTRY
114{
115 uint16_t offName;
116 uint16_t uSeg;
117 uint32_t offSeg; /**< We'll see... */
118 uint32_t offFlat;
119} BS3HIGHDLLIMPORTENTRY;
120
121typedef struct BS3HIGHDLLEXPORTENTRY
122{
123 uint32_t offFlat; /**< The flat address. This can be accessed as 32-bit and 64-bit - g_pfnSymbol. */
124 uint32_t offFlatZeroHigh; /**< Zero high dword in case of 64-bit use. */
125 uint32_t offSeg; /**< Segmented address: offset part - g_fpfn48Symbol. */
126 uint16_t idxSel; /**< Segmented address: selector part. */
127 uint16_t offName; /**< The string table offset. */
128} BS3HIGHDLLEXPORTENTRY;
129
130typedef struct BS3HIGHDLLSEGMENT
131{
132 uint32_t uAddr;
133 uint32_t cb;
134 uint16_t idxSel;
135 uint16_t fFlags;
136} BS3HIGHDLLSEGMENT;
137typedef BS3HIGHDLLSEGMENT RT_FAR *PBS3HIGHDLLSEGMENT;
138/** @name BS3HIGHDLLSEGMENT_F_XXX - segment flags.
139 * @{ */
140#define BS3HIGHDLLSEGMENT_F_EXEC 0x0001
141#define BS3HIGHDLLSEGMENT_F_16BIT 0x0002
142#define BS3HIGHDLLSEGMENT_F_32BIT 0x0004
143#define BS3HIGHDLLSEGMENT_F_64BIT 0x0008
144#define BS3HIGHDLLSEGMENT_F_CONFORMING 0x0010
145/** @} */
146
147
148/** @name High DLL selector ranges.
149 * @{ */
150#define BS3_SEL_HIGH16_CS_FIRST 0x2908
151#define BS3_SEL_HIGH16_CS_COUNT 0x18
152#define BS3_SEL_HIGH16_DS_FIRST 0x29c8
153#define BS3_SEL_HIGH16_DS_COUNT 0x08
154#define BS3_SEL_HIGH32_CS 0x0118
155#define BS3_SEL_HIGH32_DS 0x0120
156#define BS3_SEL_HIGH64_CS 0x0130
157#define BS3_SEL_HIGH64_DS 0x0138
158#ifdef BS3KIT_INCLUDED_bs3kit_h
159AssertCompile(BS3_SEL_HIGH16_CS_00 == BS3_SEL_HIGH16_CS_FIRST);
160AssertCompile(BS3_SEL_HIGH16_DS_00 == BS3_SEL_HIGH16_DS_FIRST);
161AssertCompile(BS3_SEL_HIGH32_CS == BS3_SEL_R0_CS32);
162AssertCompile(BS3_SEL_HIGH32_DS == BS3_SEL_R0_DS32);
163AssertCompile(BS3_SEL_HIGH64_CS == BS3_SEL_R0_CS64);
164AssertCompile(BS3_SEL_HIGH64_DS == BS3_SEL_R0_DS64);
165#endif
166/** @} */
167
168
169/** Initial value for Bs3CalcChecksum. */
170#define BS3_CALC_CHECKSUM_INITIAL_VALUE 1
171
172/**
173 * Calculates an Adler-32 checksum.
174 */
175DECLINLINE(uint32_t) Bs3CalcChecksum(uint32_t uChecksum, uint8_t const RT_FAR *pbSrc, size_t cbSrc)
176{
177 uint32_t uA = RT_LO_U16(uChecksum);
178 uint32_t uB = RT_HI_U16(uChecksum);
179
180 while (cbSrc-- > 0)
181 {
182 uA = (uA + *pbSrc++) % 0xfff1;
183 uB = (uA + uB) % 0xfff1;
184 }
185
186 return RT_MAKE_U32(uA, uB);
187}
188
189#endif /* !BS3KIT_INCLUDED_bs3kit_linker_h */
190
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette