Changeset 58609 in vbox
- Timestamp:
- Nov 6, 2015 3:31:37 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 103983
- Location:
- trunk/src/VBox/ValidationKit/bootsectors/bs3kit
- Files:
-
- 5 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
r58593 r58609 36 36 VBOX_PATH_BS3KIT_SRC = $(VBOX_PATH_VALIDATIONKIT_SRC)/bootsectors/bs3kit 37 37 38 # Boot Sector post-link tool used below. 39 BLDPROGS += VBoxBs3Linker 40 VBoxBs3Linker_TEMPLATE = VBoxBldProg 41 VBoxBs3Linker_SOURCES = $(VBOX_PATH_BS3KIT_SRC)/VBoxBs3Linker.cpp 42 38 43 # Dummy CP "linker" tool. 39 44 TOOL_VBoxBsCpLd = Dummy copy linker. … … 62 67 TEMPLATE_VBoxBS3KitImg_ASTOOL = NASM 63 68 TEMPLATE_VBoxBS3KitImg_ASFLAGS := -f obj -g -w+orphan-labels 64 TEMPLATE_VBoxBS3KitImg_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__69 TEMPLATE_VBoxBS3KitImg_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS ARCH_BITS=16 __NASM__ 65 70 TEMPLATE_VBoxBS3KitImg_ARTOOL = OPENWATCOM-16 66 71 TEMPLATE_VBoxBS3KitImg_CTOOL = OPENWATCOM-16 … … 91 96 segment BS3DATA32 \ 92 97 segment DATA32 98 TEMPLATE_VBoxBS3KitImg_DEPS = \ 99 $(bs3-bootsector_1_TARGET) \ 100 $(VBoxBs3Linker_1_TARGET) 101 TEMPLATE_VBoxBS3KitImg_POST_CMDS = $(if $(eq $(tool_do),LINK_LIBRARY)\ 102 ,,$(QUIET)$(MV_EXT) -f -- "$(out)" "$(out).tmp" \ 103 $$(NLTAB)$(QUIET)$(VBoxBs3Linker_1_TARGET) -o $(out) $(bs3-bootsector_1_TARGET) $(out).tmp \ 104 $$(NLTAB)$(QUIET)$(RM_EXT) -f -- "$(out).tmp") 105 93 106 TEMPLATE_VBoxBS3KitImg_LIBS = \ 94 95 96 107 $(PATH_OBJ)/bs3kit-common-16/bs3kit-common-16.lib \ 108 $(PATH_OBJ)/bs3kit-common-32/bs3kit-common-32.lib \ 109 $(PATH_OBJ)/bs3kit-common-64/bs3kit-common-64.lib 97 110 98 111 # BS3Kit template for 32-bit code. … … 101 114 TEMPLATE_VBoxBS3KitImg32_ASTOOL = NASM 102 115 TEMPLATE_VBoxBS3KitImg32_ASFLAGS := -f obj -g --allow-64bit-code-anywhere -w+orphan-labels 103 TEMPLATE_VBoxBS3KitImg32_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__116 TEMPLATE_VBoxBS3KitImg32_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS ARCH_BITS=32 __NASM__ 104 117 TEMPLATE_VBoxBS3KitImg32_ARTOOL = OPENWATCOM 105 118 TEMPLATE_VBoxBS3KitImg32_CTOOL = OPENWATCOM … … 115 128 TEMPLATE_VBoxBS3KitImg64_ASTOOL = NASM 116 129 TEMPLATE_VBoxBS3KitImg64_ASFLAGS := -f obj -g --allow-64bit-code-anywhere -w+orphan-labels 117 TEMPLATE_VBoxBS3KitImg64_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__130 TEMPLATE_VBoxBS3KitImg64_ASDEFS = ASM_FORMAT_OMF RT_NOINC_SEGMENTS ARCH_BITS=64 __NASM__ 118 131 TEMPLATE_VBoxBS3KitImg64_ARTOOL = OPENWATCOM 119 132 TEMPLATE_VBoxBS3KitImg64_INCS = $(VBOX_PATH_BS3KIT_SRC) . … … 130 143 TEMPLATE_VBoxBS3KitBS_ASTOOL = YASM 131 144 TEMPLATE_VBoxBS3KitBS_ASFLAGS := -f bin --mapfile 132 TEMPLATE_VBoxBS3KitBS_ASDEFS = ASM_FORMAT_BIN RT_NOINC_SEGMENTS __YASM__145 TEMPLATE_VBoxBS3KitBS_ASDEFS = ASM_FORMAT_BIN RT_NOINC_SEGMENTS ARCH_BITS=16 __YASM__ 133 146 TEMPLATE_VBoxBS3KitBS_INCS = $(VBOX_PATH_BS3KIT_SRC) . 134 147 TEMPLATE_VBoxBS3KitBS_LDTOOL = VBoxBsCpLd -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3Linker.cpp
r58603 r58609 1 1 /* $Id$ */ 2 2 /** @file 3 * VirtualBox Validation Kit - Boot Sector 2"linker".3 * VirtualBox Validation Kit - Boot Sector 3 "linker". 4 4 */ 5 5 … … 33 33 #include <stdlib.h> 34 34 #include <iprt/types.h> 35 #include <iprt/assert.h> 36 37 38 /********************************************************************************************************************************* 39 * Structures and Typedefs * 40 *********************************************************************************************************************************/ 41 #pragma pack(1) 42 typedef struct BS3BOOTSECTOR 43 { 44 uint8_t abJmp[3]; 45 char abOemId[8]; 46 /** @name EBPB, DOS 4.0 style. 47 * @{ */ 48 uint16_t cBytesPerSector; /**< 00bh */ 49 uint8_t cSectorsPerCluster; /**< 00dh */ 50 uint16_t cReservedSectors; /**< 00eh */ 51 uint8_t cFATs; /**< 010h */ 52 uint16_t cRootDirEntries; /**< 011h */ 53 uint16_t cTotalSectors; /**< 013h */ 54 uint8_t bMediaDescriptor; /**< 015h */ 55 uint16_t cSectorsPerFAT; /**< 016h */ 56 uint16_t cPhysSectorsPerTrack; /**< 018h */ 57 uint16_t cHeads; /**< 01ah */ 58 uint32_t cHiddentSectors; /**< 01ch */ 59 uint32_t cLargeTotalSectors; /**< 020h - We (ab)use this to indicate the number of sectors to load. */ 60 uint8_t bBootDrv; /**< 024h */ 61 uint8_t bFlagsEtc; /**< 025h */ 62 uint8_t bExtendedSignature; /**< 026h */ 63 uint32_t dwSerialNumber; /**< 027h */ 64 char abLabel[11]; /**< 02bh */ 65 char abFSType[8]; /**< 036h */ 66 /** @} */ 67 } BS3BOOTSECTOR; 68 #pragma pack() 69 typedef BS3BOOTSECTOR *PBS3BOOTSECTOR; 70 71 AssertCompileMemberOffset(BS3BOOTSECTOR, cLargeTotalSectors, 0x20); 72 AssertCompileMemberOffset(BS3BOOTSECTOR, abLabel, 0x2b); 73 AssertCompileMemberOffset(BS3BOOTSECTOR, abFSType, 0x36); 74 75 #define BS3_OEMID "BS3Kit\n\n" 76 #define BS3_FSTYPE "RawCode\n" 77 #define BS3_LABEL "VirtualBox\n" 78 #define BS3_MAX_SIZE UINT32_C(491520) /* 480KB */ 35 79 36 80 37 81 int main(int argc, char **argv) 38 82 { 39 const char *pszOutput = NULL; 40 const char **papszInputs = (const char **)calloc(argc, sizeof(const char *)); 41 unsigned cInputs = 0; 83 const char *pszOutput = NULL; 84 struct BS3LNKINPUT 85 { 86 const char *pszFile; 87 FILE *pFile; 88 uint32_t cbFile; 89 } *paInputs = (struct BS3LNKINPUT *)calloc(sizeof(paInputs[0]), argc); 90 unsigned cInputs = 0; 91 uint32_t cSectors = 0; 42 92 43 93 /* … … 62 112 { 63 113 fprintf(stderr, "syntax errro: Unknown options '%s'\n", pszOpt); 64 free(pa pszInputs);114 free(paInputs); 65 115 return 2; 66 116 } … … 111 161 } 112 162 else 113 papszInputs[cInputs++] = argv[i]; 163 { 164 /* 165 * Add to input file collection. 166 */ 167 paInputs[cInputs].pszFile = argv[i]; 168 #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) 169 FILE *pFile = fopen(paInputs[cInputs].pszFile, "rb"); 170 #else 171 FILE *pFile = fopen(paInputs[cInputs].pszFile, "r"); 172 #endif 173 if (pFile) 174 { 175 if (fseek(pFile, 0, SEEK_END) == 0) 176 { 177 paInputs[cInputs].cbFile = (uint32_t)ftell(pFile); 178 if (fseek(pFile, 0, SEEK_SET) == 0) 179 { 180 if (cInputs != 0 || paInputs[cInputs].cbFile == 512) 181 { 182 cSectors += RT_ALIGN_32(paInputs[cInputs].cbFile, 512) / 512; 183 if (cSectors <= BS3_MAX_SIZE / 512) 184 { 185 if (cSectors > 0) 186 { 187 paInputs[cInputs].pFile = pFile; 188 pFile = NULL; 189 } 190 else 191 fprintf(stderr, "error: empty input file: '%s'\n", paInputs[cInputs].pszFile); 192 } 193 else 194 fprintf(stderr, "error: input is too big: %u bytes, %u sectors (max %u bytes, %u sectors)\n" 195 "info: detected loading '%s'\n", 196 cSectors * 512, cSectors, BS3_MAX_SIZE, BS3_MAX_SIZE / 512, 197 paInputs[cInputs].pszFile); 198 } 199 else 200 fprintf(stderr, "error: first input file (%s) must be exactly 512 bytes\n", paInputs[cInputs].pszFile); 201 } 202 else 203 fprintf(stderr, "error: seeking to start of '%s' failed\n", paInputs[cInputs].pszFile); 204 } 205 else 206 fprintf(stderr, "error: seeking to end of '%s' failed\n", paInputs[cInputs].pszFile); 207 } 208 else 209 fprintf(stderr, "error: Failed to open input file '%s' for reading\n", paInputs[cInputs].pszFile); 210 if (pFile) 211 return 1; 212 cInputs++; 213 } 114 214 } 115 215 … … 124 224 return 2; 125 225 } 126 127 226 128 227 /* … … 146 245 for (unsigned i = 0; i < cInputs && rcExit == 0; i++) 147 246 { 148 #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) 149 FILE *pInput = fopen(papszInputs[i], "rb"); 150 #else 151 FILE *pInput = fopen(papszInputs[i], "r"); 152 #endif 153 if (pInput) 247 uint8_t abBuf[4096]; /* Must be multiple of 512! */ 248 uint32_t cbToRead = paInputs[i].cbFile; 249 while (cbToRead > 0) 154 250 { 155 for (;;) 156 { 157 /* Read a block from the input file. */ 158 uint8_t abBuf[4096]; 159 size_t cbRead = fread(abBuf, sizeof(uint8_t), 4096, pInput); 160 if (!cbRead || ferror(pInput)) 161 break; 162 163 /* Padd the end of the file if necessary. */ 164 if (cbRead != 4096 && !feof(pInput)) 165 { 166 fprintf(stderr, "error: fread returned %u bytes, but we're not at the end of the file yet...\n", 167 (unsigned)cbRead); 168 rcExit = 1; 169 break; 170 } 171 if ((cbRead & 0x1ff) != 0) 172 { 173 memset(&abBuf[cbRead], 0, 4096 - cbRead); 174 cbRead = (cbRead + 0x1ff) & ~0x1ffU; 175 } 176 177 /* Write the block to the output file. */ 178 if (fwrite(abBuf, sizeof(uint8_t), cbRead, pOutput) == cbRead) 179 off += cbRead; 251 /* Read a block from the input file. */ 252 uint32_t const cbThisRead = RT_MIN(cbToRead, sizeof(abBuf)); 253 size_t cbRead = fread(abBuf, sizeof(uint8_t), cbThisRead, paInputs[i].pFile); 254 if (cbRead != cbThisRead) 255 { 256 fprintf(stderr, "error: Error reading '%s' (got %d bytes, wanted %u).\n", 257 paInputs[i].pszFile, (int)cbRead, (unsigned)cbThisRead); 258 rcExit = 1; 259 break; 260 } 261 cbToRead -= cbThisRead; 262 263 /* Padd the end of the file if necessary. */ 264 if ((cbRead & 0x1ff) != 0) 265 { 266 memset(&abBuf[cbRead], 0, 4096 - cbRead); 267 cbRead = (cbRead + 0x1ff) & ~0x1ffU; 268 } 269 270 /* Patch the BPB of the first file. */ 271 if (off == 0) 272 { 273 PBS3BOOTSECTOR pBs = (PBS3BOOTSECTOR)&abBuf[0]; 274 if ( memcmp(pBs->abLabel, RT_STR_TUPLE(BS3_LABEL)) == 0 275 && memcmp(pBs->abFSType, RT_STR_TUPLE(BS3_FSTYPE)) == 0 276 && memcmp(pBs->abOemId, RT_STR_TUPLE(BS3_OEMID)) == 0) 277 pBs->cLargeTotalSectors = cSectors; 180 278 else 181 279 { 182 fprintf(stderr, "error: fwrite failed\n");280 fprintf(stderr, "error: Didn't find magic strings in the first file (%s).\n", paInputs[i].pszFile); 183 281 rcExit = 1; 184 break;185 282 } 186 283 } 187 284 188 if (ferror(pInput)) 189 { 190 fprintf(stderr, "error: Error reading '%s'.\n", papszInputs[i]); 285 /* Write the block to the output file. */ 286 if (fwrite(abBuf, sizeof(uint8_t), cbRead, pOutput) == cbRead) 287 off += cbRead; 288 else 289 { 290 fprintf(stderr, "error: fwrite failed\n"); 191 291 rcExit = 1; 192 }193 fclose(pInput);292 break; 293 } 194 294 } 195 else 295 296 if (ferror(paInputs[i].pFile)) 196 297 { 197 fprintf(stderr, "error: Failed to open '%s' for reading.\n", papszInputs[i]);298 fprintf(stderr, "error: Error reading '%s'.\n", paInputs[i]); 198 299 rcExit = 1; 199 300 } 200 301 } 302 303 /* Close the input files. */ 304 for (unsigned i = 0; i < cInputs && rcExit == 0; i++) 305 fclose(paInputs[i].pFile); 306 free(paInputs); 201 307 202 308 /* Finally, close the output file (can fail because of buffered data). */ -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-bootsector.asm
r58588 r58609 53 53 db 0ah ; Should be nop, but this looks better. 54 54 g_OemId: ; 003h 55 db 'BS3Kit', 0ah 55 db 'BS3Kit', 0ah, 0ah 56 56 57 57 ; -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-rm.asm
r58594 r58609 57 57 BITS 16 58 58 GLOBALNAME start 59 mov ax, BS3DATA16 60 mov es, ax 61 mov ds, ax 59 62 call NAME(Main_rm) 60 63 call NAME(Bs3Shutdown_p16) -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-shutdown.c
r58594 r58609 1 2 /* Just a sample. */ 1 3 void Main_rm(void) 2 4 { 3 for (;;)4 { }5 // for (;;) 6 // { } 5 7 return; 6 8 } -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac
r58593 r58609 28 28 %define ___bs3kit_mac___ 29 29 30 ; 31 ; Before we can include anything, we need to override NAME and switch section. 32 ; If we don't do the latter we end up with an unused 'text' section. 33 ; 34 35 ;; @name Segment definitions. 36 ;; @{ 37 %macro BS3_BEGIN_TEXT16 0 38 %ifndef BS3_BEGIN_TEXT16_NOT_FIRST 39 %define BS3_BEGIN_TEXT16_NOT_FIRST 40 %ifdef ASM_FORMAT_ELF 41 section BS3TEXT16 align=1 progbits alloc exec nowrite 42 %else 43 section BS3TEXT16 align=1 CLASS=CODE16 PUBLIC USE16 44 %endif 45 46 %else 47 section BS3TEXT16 48 %endif 49 %endmacro 50 51 %macro BS3_BEGIN_DATA16 0 52 %ifndef BS3_BEGIN_DATA16_NOT_FIRST 53 %define BS3_BEGIN_DATA16_NOT_FIRST 54 %ifdef ASM_FORMAT_ELF 55 section BS3DATA16 align=2 progbits alloc noexec write 56 %else 57 section BS3DATA16 align=2 CLASS=FAR_DATA PUBLIC USE16 58 %endif 59 %else 60 section BS3DATA16 61 %endif 62 %endmacro 63 64 %macro BS3_BEGIN_TEXT32 0 65 %ifndef BS3_BEGIN_TEXT32_NOT_FIRST 66 %define BS3_BEGIN_TEXT32_NOT_FIRST 67 %ifdef ASM_FORMAT_ELF 68 section BS3TEXT32 align=1 progbits alloc exec nowrite 69 %else 70 section BS3TEXT32 align=1 CLASS=CODE32 PUBLIC USE32 71 %endif 72 %else 73 section BS3TEXT32 74 %endif 75 %endmacro 76 77 %macro BS3_BEGIN_DATA32 0 78 %ifndef BS3_BEGIN_DATA32_NOT_FIRST 79 %define BS3_BEGIN_DATA32_NOT_FIRST 80 %ifdef ASM_FORMAT_ELF 81 section BS3DATA32 align=16 progbits alloc noexec write 82 %else 83 section BS3DATA32 align=16 CLASS=DATA32 PUBLIC USE32 84 %endif 85 %else 86 section BS3DATA32 87 %endif 88 %endmacro 89 90 %macro BS3_BEGIN_TEXT64 0 91 %ifndef BS3_BEGIN_TEXT64_NOT_FIRST 92 %define BS3_BEGIN_TEXT64_NOT_FIRST 93 %ifdef ASM_FORMAT_ELF 94 section BS3TEXT64 align=1 progbits alloc exec nowrite 95 %else 96 section BS3TEXT64 align=1 CLASS=CODE64 PUBLIC USE32 97 %endif 98 %else 99 section BS3TEXT64 100 %endif 101 %endmacro 102 103 %macro BS3_BEGIN_DATA64 0 104 %ifndef BS3_BEGIN_DATA64_NOT_FIRST 105 %define BS3_BEGIN_DATA64_NOT_FIRST 106 %ifdef ASM_FORMAT_ELF 107 section BS3DATA64 align=16 progbits alloc noexec write 108 %else 109 section BS3DATA64 align=16 CLASS=DATA64 PUBLIC USE32 110 %endif 111 %else 112 section BS3DATA64 113 %endif 114 %endmacro 115 116 ;; Default text section. 117 %macro BS3_BEGIN_DEFAULT_TEXT 0 118 %if ARCH_BITS == 16 119 BS3_BEGIN_TEXT16 120 %elif ARCH_BITS == 32 121 BS3_BEGIN_TEXT32 122 %elif ARCH_BITS == 64 123 BS3_BEGIN_TEXT64 124 %else 125 %error "ARCH_BITS must be defined as either 16, 32, or 64!" 126 INVALID_ARCH_BITS 127 %endif 128 %endmacro 129 130 ;; @} 131 132 133 ; 134 ; Now, ditch the default 'text' section and define our own NAME macro. 135 ; 136 %ifndef ASM_FORMAT_BIN 137 BS3_BEGIN_DEFAULT_TEXT 138 BS3_BEGIN_DEFAULT_TEXT ; stupid nasm automagically repeats the segment attributes. 139 %endif 30 140 31 141 ;; When using watcom + OMF, we're using __cdecl by default, which … … 34 144 %define NAME(name) _ %+ NAME_OVERLOAD(name) 35 145 %endif 146 147 148 ; 149 ; Include the standard headers from iprt. 150 ; 36 151 37 152 … … 141 256 142 257 143 ;; @name Segment definitions.144 ;; @{145 %macro BS3_BEGIN_TEXT16 0146 %ifndef BS3_BEGIN_TEXT16_NOT_FIRST147 %define BS3_BEGIN_TEXT16_NOT_FIRST148 %ifdef ASM_FORMAT_ELF149 section BS3TEXT16 align=1 progbits alloc exec nowrite150 %else151 section BS3TEXT16 align=1 CLASS=CODE16 PUBLIC USE16152 %endif153 154 %else155 section BS3TEXT16156 %endif157 %endmacro158 159 %macro BS3_BEGIN_DATA16 0160 %ifndef BS3_BEGIN_DATA16_NOT_FIRST161 %define BS3_BEGIN_DATA16_NOT_FIRST162 %ifdef ASM_FORMAT_ELF163 section BS3DATA16 align=2 progbits alloc noexec write164 %else165 section BS3DATA16 align=2 CLASS=FAR_DATA PUBLIC USE16166 %endif167 %else168 section BS3DATA16169 %endif170 %endmacro171 172 %macro BS3_BEGIN_TEXT32 0173 %ifndef BS3_BEGIN_TEXT32_NOT_FIRST174 %define BS3_BEGIN_TEXT32_NOT_FIRST175 %ifdef ASM_FORMAT_ELF176 section BS3TEXT32 align=1 progbits alloc exec nowrite177 %else178 section BS3TEXT32 align=1 CLASS=CODE32 PUBLIC USE32179 %endif180 %else181 section BS3TEXT32182 %endif183 %endmacro184 185 %macro BS3_BEGIN_DATA32 0186 %ifndef BS3_BEGIN_DATA32_NOT_FIRST187 %define BS3_BEGIN_DATA32_NOT_FIRST188 %ifdef ASM_FORMAT_ELF189 section BS3DATA32 align=16 progbits alloc noexec write190 %else191 section BS3DATA32 align=16 CLASS=DATA32 PUBLIC USE32192 %endif193 %else194 section BS3DATA32195 %endif196 %endmacro197 198 %macro BS3_BEGIN_TEXT64 0199 %ifndef BS3_BEGIN_TEXT64_NOT_FIRST200 %define BS3_BEGIN_TEXT64_NOT_FIRST201 %ifdef ASM_FORMAT_ELF202 section BS3TEXT64 align=1 progbits alloc exec nowrite203 %else204 section BS3TEXT64 align=1 CLASS=CODE64 PUBLIC USE32205 %endif206 %else207 section BS3TEXT64208 %endif209 %endmacro210 211 %macro BS3_BEGIN_DATA64 0212 %ifndef BS3_BEGIN_DATA64_NOT_FIRST213 %define BS3_BEGIN_DATA64_NOT_FIRST214 %ifdef ASM_FORMAT_ELF215 section BS3DATA64 align=16 progbits alloc noexec write216 %else217 section BS3DATA64 align=16 CLASS=DATA64 PUBLIC USE32218 %endif219 %else220 section BS3DATA64221 %endif222 %endmacro223 224 ;; @}225 226 258 %endif 227 259
Note:
See TracChangeset
for help on using the changeset viewer.