[29] | 1 | // AiR-BOOT (c) Copyright 1998-2009 M. Kiewitz
|
---|
| 2 | //
|
---|
| 3 | // This file is part of AiR-BOOT
|
---|
| 4 | //
|
---|
| 5 | // AiR-BOOT is free software: you can redistribute it and/or modify it under
|
---|
| 6 | // the terms of the GNU General Public License as published by the Free
|
---|
| 7 | // Software Foundation, either version 3 of the License, or (at your option)
|
---|
| 8 | // any later version.
|
---|
| 9 | //
|
---|
| 10 | // AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
| 11 | // WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 12 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
---|
| 13 | // details.
|
---|
| 14 | //
|
---|
| 15 | // You should have received a copy of the GNU General Public License along with
|
---|
| 16 | // AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 17 | //
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 |
|
---|
[60] | 21 | #include "install.h"
|
---|
[29] | 22 |
|
---|
[30] | 23 |
|
---|
| 24 |
|
---|
[29] | 25 | // ============================================================================
|
---|
| 26 | // Variables
|
---|
| 27 | // ============================================================================
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
[47] | 31 | //CHAR Track0[SECTOR_COUNT * BYTES_PER_SECTOR]; // current track 0 from harddrive
|
---|
| 32 | //CHAR Bootcode[SECTOR_COUNT * BYTES_PER_SECTOR]; // bootcode image from airboot.bin
|
---|
[29] | 33 |
|
---|
[46] | 34 | /*
|
---|
| 35 | // With the addition of the C DOS-version, a static buffer for both
|
---|
[47] | 36 | // Track0 and Bootcode would overflow the DGROUP segment. (>64kB)
|
---|
| 37 | // Placing the buffers in another segment does not work with Open Watcom v1.9.
|
---|
| 38 | // While the buffers are BSS and should be in segments like FAR_BSS,
|
---|
| 39 | // Open Watcom places the buffers in FAR_DATA and produces a bloated DOS
|
---|
| 40 | // executable. Using the same source and then building an OS/2 v1.x
|
---|
| 41 | // executable does not produce a bloated .EXE, eventhough the segments are
|
---|
| 42 | // called FAR_DATA and in the middle of the image.
|
---|
| 43 | // Microsoft C v6.0 displays the same behavior; DOS bloated, OS/2 v1.x ok.
|
---|
| 44 | // An interesting feat is that when building an OS/2 v1.x executable and then
|
---|
| 45 | // binding that to produce a FAPI executable does not produce a bloated .EXE
|
---|
[46] | 46 | //
|
---|
[47] | 47 | // Also, when experimenting with segments and #pragma data_seg(), some
|
---|
[46] | 48 | // strange behavior was observed.
|
---|
| 49 | // WCC:
|
---|
| 50 | // Explicitly naming a segment and class for the static buffers caused
|
---|
[47] | 51 | // wcc to keep generating it's default SS: based addressing, eventhough
|
---|
| 52 | // the segments are not part of DGROUP.
|
---|
| 53 | // Only the -zu flag corrects this. (DS!=SS)
|
---|
[46] | 54 | // WPP:
|
---|
| 55 | // C++ wpp used correct addressing but the segment class in the #pragma
|
---|
| 56 | // was not honored and the segment name got mangled.
|
---|
| 57 | //
|
---|
| 58 | // In both cases the volatile (transient) data would occupy space in the
|
---|
[47] | 59 | // disk-image.
|
---|
[46] | 60 | // The only way seems to be putting the buffers in a separate segment using
|
---|
| 61 | // pragma's, using wcc with the -zu flag and use the wlink ORDER directive
|
---|
| 62 | // to place the FAR BSS data above the stack acompanied by a NOEMIT modifier.
|
---|
| 63 | // For this all the class names of the previous segments must be included
|
---|
[47] | 64 | // in the wlink ORDER directive which would make the link phase dependend
|
---|
[46] | 65 | // on segment names. This solution does not work for wpp because it mangles
|
---|
| 66 | // the segment name and overrides the custom class name to FAR_DATA.
|
---|
| 67 | //
|
---|
| 68 | // So, these buffers are now dynamically allocated.
|
---|
| 69 | */
|
---|
| 70 | PCHAR Track0 = NULL; // Buffer for Track0 from harddisk.
|
---|
| 71 | PCHAR Bootcode = NULL; // Buffer for AIRBOOT.BIN image.
|
---|
[30] | 72 |
|
---|
[46] | 73 | UCHAR Bootcode_LanguageID = ' ';
|
---|
| 74 | USHORT Bootcode_Version = 0;
|
---|
| 75 | USHORT Bootcode_ConfigVersion = 0;
|
---|
[29] | 76 |
|
---|
[46] | 77 | UCHAR Status_Code = STATUS_NOTINSTALLED;
|
---|
| 78 | UCHAR Status_Config = STATUS_NOTINSTALLED;
|
---|
| 79 | USHORT Installed_CodeVersion = 0;
|
---|
| 80 | USHORT Installed_ConfigVersion = 0;
|
---|
| 81 | UCHAR Installed_LanguageID = ' ';
|
---|
[29] | 82 |
|
---|
[46] | 83 | BOOL Option_ForceCode = FALSE;
|
---|
| 84 | BOOL Option_ForceConfig = FALSE;
|
---|
| 85 | BOOL Option_Silent = FALSE;
|
---|
[48] | 86 | BOOL Option_CID = FALSE;
|
---|
[46] | 87 |
|
---|
| 88 | BOOL Install_Code = FALSE;
|
---|
| 89 | BOOL Install_Config = FALSE;
|
---|
| 90 | BOOL Install_IsCorrupt = FALSE;
|
---|
| 91 |
|
---|
[48] | 92 | //USHORT StatusCode = 0;
|
---|
[46] | 93 | PSZ ImpossibleCause = NULL;
|
---|
| 94 |
|
---|
[47] | 95 | CHAR TempHidPartTable[45 * 34];
|
---|
[46] | 96 |
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 |
|
---|
[29] | 100 | // ============================================================================
|
---|
[46] | 101 | // Kidnapped bitfield functions needed to access the packed hideparttable
|
---|
| 102 | // ============================================================================
|
---|
| 103 |
|
---|
| 104 | /*
|
---|
| 105 | // Pragma's could be used to interface with the bitfield functions, but I was
|
---|
| 106 | // not in the mood to examine how they behave when conditions like calling
|
---|
| 107 | // convention, memory model, optimization, etc. are changed. Especially
|
---|
| 108 | // optimization generates very different code depending on the -o flags so
|
---|
| 109 | // it felt a bit 'fragile' to me to use them without further analysis.
|
---|
| 110 | // So I opted for the 'easy way' of some small prolog code to pass the
|
---|
| 111 | // parameters to the correct registers required by the core bitfield functions.
|
---|
| 112 | */
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | //~ #ifdef __386__
|
---|
| 116 | //~ #pragma aux __airboot "*___" parm caller [EBX] [EDX] [ECX] [EAX ESI EDI] value [AL];
|
---|
| 117 | //~ #else
|
---|
| 118 | //~ #pragma aux __airboot "*___" parm caller [DI BX] [DX] [CX] [AX SI] value [AL];
|
---|
| 119 | //~ #endif
|
---|
| 120 | //~ #pragma aux (__airboot) get_bitfield;
|
---|
| 121 | //~ #pragma aux (__airboot) set_bitfield;
|
---|
| 122 |
|
---|
| 123 | /* Prototypes */
|
---|
| 124 | void bf_test();
|
---|
| 125 | char get_bitfield(char* buffer, char index, char fieldwidth);
|
---|
| 126 | char set_bitfield(char* buffer, char index, char fieldwidth, char value);
|
---|
| 127 |
|
---|
| 128 | //~ #ifdef __386__
|
---|
| 129 | //~ #pragma aux get_bitfield parm [EBX] [ECX] [EDX] value [AL];
|
---|
| 130 | //~ #pragma aux set_bitfield parm [EBX] [ECX] [EDX] [EAX];
|
---|
| 131 | //~ #else
|
---|
| 132 | //~ #pragma aux get_bitfield value [DL];
|
---|
| 133 | //~ #pragma aux set_bitfield parm [BX] [CX] [DX] [AX];
|
---|
| 134 | //~ #endif
|
---|
| 135 |
|
---|
[48] | 136 | void DumpTrack0();
|
---|
[46] | 137 |
|
---|
| 138 | // In 32-bit mode EBX is used and in 16-bit mode BX, so we abstract it's name.
|
---|
| 139 | // The rest of the bitfield code uses 16-bit registers because I kidnapped
|
---|
| 140 | // it from AiR-BOOT.
|
---|
| 141 | #define dataptr16 "BX"
|
---|
| 142 | #define dataptr32 "EBX"
|
---|
| 143 | #ifdef __386__
|
---|
| 144 | #define dataptr dataptr32
|
---|
| 145 | #else
|
---|
| 146 | #define dataptr dataptr16
|
---|
| 147 | #endif
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | /*
|
---|
| 153 | // ----------------------------------------------------------------------------
|
---|
| 154 | // bf_test -- Test function to analyse code generation
|
---|
| 155 | // ----------------------------------------------------------------------------
|
---|
| 156 | */
|
---|
| 157 | void bf_test() {
|
---|
| 158 | char* b1 = Track0;
|
---|
| 159 | char* b2 = Bootcode;
|
---|
| 160 | char i1 = 0x11;
|
---|
| 161 | char i2 = 0x12;
|
---|
| 162 | char v1 = 0x83;
|
---|
| 163 | char v2 = 0x84;
|
---|
| 164 | char rv1 = 0xf8;
|
---|
| 165 | char rv2 = 0xf9;
|
---|
| 166 |
|
---|
| 167 | rv1 = get_bitfield(b1, i1, 6);
|
---|
| 168 | rv2 = set_bitfield(b2, i2, 6, v1+v2);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | /*
|
---|
| 172 | // ----------------------------------------------------------------------------
|
---|
| 173 | // do_bf_test -- Simple function to test the bitfield functions
|
---|
| 174 | // ----------------------------------------------------------------------------
|
---|
| 175 | */
|
---|
| 176 | void do_bf_test() {
|
---|
| 177 | char buf[512];
|
---|
| 178 | int i;
|
---|
| 179 |
|
---|
| 180 | for (i=0; i<100; i++) {
|
---|
| 181 | set_bitfield(buf, i, 6, i);
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | set_bitfield(buf, 18, 6, 255);
|
---|
| 185 | set_bitfield(buf, 21, 6, 255);
|
---|
| 186 | set_bitfield(buf, 33, 6, 255);
|
---|
| 187 | set_bitfield(buf, 37, 6, 255);
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 | for (i=0; i<100; i++) {
|
---|
| 191 | printf("index: %02d, value: %02d\n", i, get_bitfield(buf, i, 6));
|
---|
| 192 | }
|
---|
| 193 | return;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | /*
|
---|
| 198 | // ----------------------------------------------------------------------------
|
---|
| 199 | // get_bitfield -- Get a n-bit wide bitfield at index i from a buffer in memory
|
---|
| 200 | // ----------------------------------------------------------------------------
|
---|
| 201 | // This is code kidnapped from AiR-BOOT and used here to handle the packed
|
---|
| 202 | // hideparttable. A 'record' in the hideparttable is 34 bytes long and it
|
---|
| 203 | // can store 45 partition numbers using 6-bits per partition number.
|
---|
[47] | 204 | // Bitfield widths from 1 to 8 are supported and the maximum buffersize is
|
---|
[46] | 205 | // 256 bytes.
|
---|
| 206 | */
|
---|
| 207 | char get_bitfield(char* buffer, char index, char fieldwidth) {
|
---|
[48] | 208 |
|
---|
[47] | 209 | char rv = 0;
|
---|
[46] | 210 | // These are used to break-up the far pointer in large-data model 16-bit
|
---|
| 211 | // code so the buffer can be addressed correctly.
|
---|
| 212 | // In 32-bit flat mode they will have no effect and in 32-bit large-data
|
---|
| 213 | // mode (imaginary) they can handle the buffer being in a seperate segment.
|
---|
| 214 | unsigned dseg = _FP_SEG(buffer);
|
---|
| 215 | unsigned dptr = _FP_OFF(buffer);
|
---|
| 216 |
|
---|
| 217 | // Prolog code.
|
---|
| 218 | // Handle data-segment and parameters.
|
---|
| 219 | _asm {
|
---|
| 220 | push ds ; Save DS from caller.
|
---|
| 221 | push dseg ; Setup DS to
|
---|
| 222 | pop ds ; address our segment. (When 16-bit large data-model)
|
---|
| 223 |
|
---|
| 224 | mov dl, index ; Index to bitfield in DL.
|
---|
| 225 | mov dh, fieldwidth ; Width of bitfield in DH.
|
---|
| 226 | mov dataptr, dptr ; Pointer in [E]BX.
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 |
|
---|
| 230 | // This is practically a verbatim copy of the core routine from CONV.ASM.
|
---|
| 231 | // Only a slight modification with regard to [E]BX addressing is made
|
---|
| 232 | // so it can also function in 32-bit mode.
|
---|
| 233 | _asm {
|
---|
| 234 |
|
---|
| 235 | ; IN: DL = Index to store bitfield
|
---|
| 236 | ; DH = Bitfield width (1-8)
|
---|
| 237 | ; [E]BX = Pointer to bitfield array
|
---|
| 238 | ; OUT: AL = Value of requested bitfield
|
---|
| 239 | ; AH = Mask value
|
---|
| 240 |
|
---|
| 241 | ; Normalize bit-width in DH.
|
---|
| 242 | dec dh ; Decrement bitfield width to mask invalid values.
|
---|
| 243 | and dh,07h ; Only 3 bits are significant to determine width.
|
---|
| 244 | mov cl,dh ; Save for later use to calculate mask.
|
---|
| 245 | inc dh ; Put back to normalized value.
|
---|
| 246 |
|
---|
| 247 | ; Calculate corresponding AND-mask in CH.
|
---|
| 248 | mov ch,2 ; Were going to shift 2...
|
---|
| 249 | shl ch,cl ; to obtain the mask corresponding...
|
---|
| 250 | dec ch ; to the bitfield width.
|
---|
| 251 |
|
---|
| 252 | ; Calculate byte-index.
|
---|
| 253 | mov al,dl ; Index in AL.
|
---|
| 254 | inc al ; Increment for calculations.
|
---|
| 255 | mul dh ; Multiply by bitfield width to get bits.
|
---|
| 256 | mov cl,8 ; Nr. of bits in a byte.
|
---|
| 257 | div cl ; Divide to get byte index.
|
---|
| 258 |
|
---|
| 259 | ; Advance pointer to byte-index.
|
---|
| 260 | add bl,al ; Advance pointer...
|
---|
| 261 | adc bh,0 ; to byte index.
|
---|
| 262 |
|
---|
| 263 | ; We have to 'carry on' to the high word of EBX if in 32-bit mode.
|
---|
| 264 | #ifdef __386__
|
---|
| 265 | pushf ; Save the possible carry from the last addition.
|
---|
| 266 | ror ebx,16 ; Get high word of EBX in BX.
|
---|
| 267 | popf ; Restore possible carry.
|
---|
| 268 | adc bx,0 ; Add it and...
|
---|
| 269 | rol ebx,16 ; move back to have a valid 32-bit pointer again.
|
---|
| 270 | #endif
|
---|
| 271 |
|
---|
| 272 | ; Determine if we need 1 or 2 byte access to extract the bitfield.
|
---|
| 273 | mov cl,ah ; Get remainder in CL.
|
---|
| 274 | sub cl,dh ; Substract bitfield width to get shift-count.
|
---|
| 275 | mov ah,0 ; Prepare upper=0 when field spans no byte bound.
|
---|
| 276 | ; Don't change to xor ah,ah or any CY will be lost.
|
---|
| 277 |
|
---|
| 278 | ; Jump if the bitfield does not span byte boundaries.
|
---|
| 279 | ; (Remainder - bitfield width >= 0)
|
---|
| 280 | jae CONV_GetBitfieldValue_nospan
|
---|
| 281 |
|
---|
| 282 | ; Bit-field spans byte boundaries, so adjust shift-count
|
---|
| 283 | ; and use AH to get first part of bitfield.
|
---|
| 284 | add cl,8 ; Adjust shift-count.
|
---|
| 285 | mov ah,[dataptr] ; Get byte into AH instead.
|
---|
| 286 | dec dataptr ; Adjust pointer to load rest of bitfield.
|
---|
| 287 |
|
---|
| 288 | CONV_GetBitfieldValue_nospan:
|
---|
| 289 | mov al,[dataptr] ; Load (rest of) bitfield into AL.
|
---|
| 290 | shr ax,cl ; Shift bitfield to the right.
|
---|
| 291 | mov ah,ch ; Get mask in AH.
|
---|
| 292 | and al,ah ; Mask value.
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | // Epilog code.
|
---|
| 297 | // Restore caller's DS.
|
---|
[47] | 298 | // Store return value.
|
---|
[46] | 299 | _asm {
|
---|
| 300 | pop ds
|
---|
[47] | 301 | mov [rv],al
|
---|
[46] | 302 | }
|
---|
| 303 |
|
---|
[47] | 304 | return rv;
|
---|
[46] | 305 | }
|
---|
| 306 |
|
---|
| 307 |
|
---|
| 308 | /*
|
---|
| 309 | // ----------------------------------------------------------------------------
|
---|
| 310 | // set_bitfield -- Set a n-bit wide bitfield at index i in a buffer in memory
|
---|
| 311 | // ----------------------------------------------------------------------------
|
---|
| 312 | // This is code kidnapped from AiR-BOOT and used here to handle the packed
|
---|
| 313 | // hideparttable. A 'record' in the hideparttable is 34 bytes long and it
|
---|
| 314 | // can store 45 partition numbers using 6-bits per partition number.
|
---|
[47] | 315 | // Bitfield widths from 1 to 8 are supported and the maximum buffersize is
|
---|
[46] | 316 | // 256 bytes.
|
---|
| 317 | */
|
---|
| 318 | char set_bitfield(char* buffer, char index, char fieldwidth, char value) {
|
---|
| 319 |
|
---|
[48] | 320 |
|
---|
[46] | 321 | // These are used to break-up the far pointer in large-data model 16-bit
|
---|
| 322 | // code so the buffer can be addressed correctly.
|
---|
| 323 | // In 32-bit flat mode they will have no effect and in 32-bit large-data
|
---|
| 324 | // mode (imaginary) they can handle the buffer being in a seperate segment.
|
---|
| 325 | unsigned dseg = _FP_SEG(buffer);
|
---|
| 326 | unsigned dptr = _FP_OFF(buffer);
|
---|
| 327 |
|
---|
| 328 | // Prolog code.
|
---|
| 329 | // Handle data-segment and parameters.
|
---|
| 330 | _asm {
|
---|
| 331 | push ds ; Save DS from caller.
|
---|
| 332 | push dseg ; Setup DS to
|
---|
| 333 | pop ds ; address our segment. (When 16-bit large data-model)
|
---|
| 334 |
|
---|
| 335 | mov dl, index ; Index to bitfield in DL.
|
---|
| 336 | mov dh, fieldwidth ; Width of bitfield in DH.
|
---|
| 337 | mov dataptr, dptr ; Pointer in [E]BX.
|
---|
| 338 | mov al, value ; Value we want to poke in AL.
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 |
|
---|
| 342 | // This is practically a verbatim copy of the core routine from CONV.ASM.
|
---|
| 343 | // Only a slight modification with regard to [E]BX addressing is made
|
---|
| 344 | // so it can also function in 32-bit mode.
|
---|
| 345 | _asm {
|
---|
| 346 |
|
---|
| 347 | ; IN: AL = Value to store
|
---|
| 348 | ; DL = Index to store bitfield
|
---|
| 349 | ; DH = Bitfield width (1-8)
|
---|
| 350 | ; [E]BX = Pointer to bitfield array
|
---|
| 351 | ; OUT: AL = Value of stored bitfield
|
---|
| 352 | ; AH = Mask value
|
---|
| 353 |
|
---|
| 354 | ; Push value for later use.
|
---|
| 355 | push ax
|
---|
| 356 |
|
---|
| 357 | ; Normalize bit-width in DH.
|
---|
| 358 | dec dh ; Decrement bitfield width to mask invalid values.
|
---|
| 359 | and dh,07h ; Only 3 bits are significant to determine width.
|
---|
| 360 | mov cl,dh ; Save for later use to calculate mask.
|
---|
| 361 | inc dh ; Put back to normalized value.
|
---|
| 362 |
|
---|
| 363 | ; Calculate corresponding AND-mask in CH.
|
---|
| 364 | mov ch,2 ; Were going to shift 2...
|
---|
| 365 | shl ch,cl ; to obtain the mask corresponding...
|
---|
| 366 | dec ch ; to the bitfield width.
|
---|
| 367 |
|
---|
| 368 | ; Calculate byte-index.
|
---|
| 369 | mov al,dl ; Index in AL.
|
---|
| 370 | inc al ; Increment for calculations.
|
---|
| 371 | mul dh ; Multiply by bitfield width to get bits.
|
---|
| 372 | mov cl,8 ; Nr. of bits in a byte.
|
---|
| 373 | div cl ; Divide to get byte index.
|
---|
| 374 |
|
---|
| 375 | ; Advance pointer to byte-index.
|
---|
| 376 | add bl,al ; Advance pointer...
|
---|
| 377 | adc bh,0 ; to byte index.
|
---|
| 378 |
|
---|
| 379 | ; We have to 'carry on' to the high word of EBX if in 32-bit mode.
|
---|
| 380 | #ifdef __386__
|
---|
| 381 | pushf ; Save the possible carry from the last addition.
|
---|
| 382 | ror ebx,16 ; Get high word of EBX in BX.
|
---|
| 383 | popf ; Restore possible carry.
|
---|
| 384 | adc bx,0 ; Add it and...
|
---|
| 385 | rol ebx,16 ; move back to have a valid 32-bit pointer again.
|
---|
| 386 | #endif
|
---|
| 387 |
|
---|
| 388 | ; Determine if we need 1 or 2 byte access to extract the bitfield.
|
---|
| 389 | mov cl,ah ; Get remainder in CL.
|
---|
| 390 | sub cl,dh ; Substract bitfield width to get shift-count.
|
---|
| 391 |
|
---|
| 392 | ; Restore value to poke.
|
---|
| 393 | pop ax
|
---|
| 394 |
|
---|
| 395 |
|
---|
| 396 | ; Jump if the bitfield does not span byte boundaries.
|
---|
| 397 | ; (Remainder - bitfield width >= 0)
|
---|
| 398 | jae CONV_SetBitfieldValue_nospan
|
---|
| 399 |
|
---|
| 400 | ; Bit-field spans byte boundaries, so adjust shift-count
|
---|
| 401 | ; and use 16-bit access.
|
---|
| 402 | add cl,8 ; Adjust shift-count.
|
---|
| 403 |
|
---|
| 404 | ; Merge the bitfield to the array.
|
---|
| 405 | push cx ; Save mask (CH) and shift-count (CL).
|
---|
| 406 | push ax ; Save value to store.
|
---|
| 407 | xor ah,ah ; Clear upper byte so we can shift in it.
|
---|
| 408 | and al,ch ; Mask value.
|
---|
| 409 | shl ax,cl ; Move the bitfield to the proper location.
|
---|
| 410 | mov dh,[dataptr] ; Get 1st part of bitfield from array.
|
---|
| 411 | dec dataptr ; Adjust pointer.
|
---|
| 412 | mov dl,[dataptr] ; Get 2nd part of bitfield from array.
|
---|
| 413 | push bx ; We need BX so save it.
|
---|
| 414 | xor bh,bh ; Clear upper byte so we can shift in it.
|
---|
| 415 | mov bl,ch ; Put mask in BL.
|
---|
| 416 | shl bx,cl ; Shift mask to proper location.
|
---|
| 417 | not bx ; Complement it to mask-out the required bitfield.
|
---|
| 418 | and dx,bx ; Mask-out the required bitfield.
|
---|
| 419 | pop bx ; Restore pointer.
|
---|
| 420 | or ax,dx ; Merge the bitfields.
|
---|
| 421 | mov [dataptr],al ; Store lower byte.
|
---|
| 422 | inc dataptr ; Adjust pointer.
|
---|
| 423 | mov [dataptr],ah ; Store upper byte.
|
---|
| 424 | pop ax ; Restore value.
|
---|
| 425 | pop cx ; Restore mask and shift-count.
|
---|
| 426 |
|
---|
| 427 | ; Done.
|
---|
| 428 | jmp CONV_SetBitfieldValue_end
|
---|
| 429 |
|
---|
| 430 | CONV_SetBitfieldValue_nospan:
|
---|
| 431 | ; Merge the bitfield to the array.
|
---|
| 432 | push cx ; Save mask (CH) and shift-count (CL).
|
---|
| 433 | push ax ; Save value to store.
|
---|
| 434 | and al,ch ; Mask value.
|
---|
| 435 | shl al,cl ; Move the bitfield to the proper location.
|
---|
| 436 | mov dl,[dataptr] ; Get byte containing bitfield.
|
---|
| 437 | shl ch,cl ; Shift mask to proper location.
|
---|
| 438 | not ch ; Complement it to mask-out the required bitfield.
|
---|
| 439 | and dl,ch ; Mask-out the required bitfield.
|
---|
| 440 | or al,dl ; Merge the bitfields.
|
---|
| 441 | mov [dataptr],al ; Store byte containing bitfield.
|
---|
| 442 | pop ax ; Restore value.
|
---|
| 443 | pop cx ; Restore mask and shift-count.
|
---|
| 444 |
|
---|
| 445 | CONV_SetBitfieldValue_end:
|
---|
| 446 | mov ah,ch ; Get mask in AH.
|
---|
| 447 | and al,ah ; Mask value.
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | // Epilog code.
|
---|
| 451 | // Restore caller's DS.
|
---|
| 452 | _asm {
|
---|
| 453 | pop ds
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | return value;
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 |
|
---|
| 460 |
|
---|
| 461 |
|
---|
| 462 |
|
---|
| 463 |
|
---|
| 464 |
|
---|
| 465 |
|
---|
| 466 | // ============================================================================
|
---|
[29] | 467 | // Platform-specific helper functions
|
---|
| 468 | // ============================================================================
|
---|
| 469 |
|
---|
[46] | 470 |
|
---|
| 471 | /*
|
---|
| 472 | // Helper functions -- DOS implementation.
|
---|
| 473 | */
|
---|
| 474 | #ifdef PLATFORM_DOS
|
---|
| 475 | USHORT CountHarddrives (void) {
|
---|
| 476 | USHORT NumDrives = 0;
|
---|
[48] | 477 |
|
---|
[47] | 478 | /* Return the byte at 0040:0075 that contains the nr. of harddisks */
|
---|
| 479 | _asm {
|
---|
| 480 | push es ; We use ES to address the 40h segment.
|
---|
| 481 | mov ax,40h ; Segment address of DOS BIOS DATA.
|
---|
| 482 | mov es,ax ; Make ES address it.
|
---|
| 483 | xor ax,ax ; Clear AX to receive return value.
|
---|
| 484 | mov al,es:[0075h] ; Nr. of harddisks in AL.
|
---|
| 485 | pop es ; Restore ES.
|
---|
| 486 | mov [NumDrives],ax ; Return this value.
|
---|
| 487 | }
|
---|
[46] | 488 | return NumDrives;
|
---|
[29] | 489 | }
|
---|
| 490 |
|
---|
[48] | 491 | /*
|
---|
| 492 | // On DOS this geometry check uses the INT13X value for sectors per track.
|
---|
| 493 | // On OS/2 the DosDevIOCtl call uses a SPT value from the formatted disk,
|
---|
| 494 | // irrespective of the physical geometry.
|
---|
| 495 | */
|
---|
[47] | 496 | BOOL HarddriveCheckGeometry (void) {
|
---|
| 497 | BOOL rv = FALSE;
|
---|
[48] | 498 |
|
---|
[47] | 499 | _asm {
|
---|
| 500 | ; According to Ralf Brown ES:DI=0000:0000 to avoid BIOS quirks.
|
---|
| 501 | push es
|
---|
| 502 | push di
|
---|
| 503 | xor di,di
|
---|
| 504 | mov es,di
|
---|
[30] | 505 |
|
---|
[47] | 506 | ; Get the disk parameters using normal (non-I13X) access.
|
---|
| 507 | mov ah,08h ; Get Disk Parameters.
|
---|
| 508 | mov dl,80h ; Boot Disk.
|
---|
| 509 | int 13h ; Transfer to BIOS.
|
---|
[29] | 510 |
|
---|
[47] | 511 | ; Check for errors
|
---|
| 512 | mov dx,0 ; Assume error.
|
---|
| 513 | jc end ; CY if error.
|
---|
| 514 | test ah,ah ; Double check for return-status.
|
---|
| 515 | jnz end ; AH non-zero if error.
|
---|
[46] | 516 |
|
---|
[47] | 517 | ; Check sectors per track to be above 62
|
---|
| 518 | and cl,00111111b ; Mask sectors.
|
---|
| 519 | cmp cl,SECTOR_COUNT ; Compare with max. AiR-BOOT sectors.
|
---|
| 520 | jbe end ; SECTOR_COUNT or less is not enough.
|
---|
[46] | 521 |
|
---|
[47] | 522 | inc dx ; Set to no error.
|
---|
| 523 |
|
---|
| 524 | end:
|
---|
| 525 | mov ax,dx ; Status to AX.
|
---|
| 526 |
|
---|
[48] | 527 | ; Store in return value.
|
---|
[47] | 528 | mov word ptr [rv],ax
|
---|
| 529 |
|
---|
| 530 | ; Restore ES:DI
|
---|
| 531 | pop di
|
---|
| 532 | pop es
|
---|
| 533 | }
|
---|
| 534 | return rv;
|
---|
[29] | 535 | }
|
---|
| 536 |
|
---|
[47] | 537 |
|
---|
| 538 |
|
---|
[46] | 539 | BOOL Track0Load (void) {
|
---|
| 540 | BOOL Success = FALSE;
|
---|
[29] | 541 |
|
---|
[47] | 542 | _asm {
|
---|
| 543 |
|
---|
| 544 | push es ; ES is used to point to loadbuffer.
|
---|
| 545 |
|
---|
| 546 | ; Load the complete AiR-BOOT image from Track0.
|
---|
| 547 | mov ah,02h ; Read sectors from disk.
|
---|
| 548 | mov al,SECTOR_COUNT ; Number of sectors to read.
|
---|
| 549 | mov cx,1 ; Cyl 0, Sector 1.
|
---|
| 550 | mov dh,0 ; Head 0.
|
---|
| 551 | mov dl,80h ; Boot Disk.
|
---|
| 552 | les bx,[Track0] ; Buffer in ES:BX.
|
---|
| 553 | int 13h ; Transfer to BIOS.
|
---|
| 554 |
|
---|
| 555 | ; Check for errors
|
---|
| 556 | mov dx,0 ; Assume error.
|
---|
| 557 | jc end ; CY if error.
|
---|
| 558 | test ah,ah ; Double check status in AH.
|
---|
| 559 | jnz end ; AH non-zero if error.
|
---|
| 560 |
|
---|
| 561 | inc dx ; Set to no error.
|
---|
| 562 |
|
---|
| 563 | end:
|
---|
| 564 | mov ax,dx ; Status to AX.
|
---|
| 565 |
|
---|
[48] | 566 | ; Store in return value.
|
---|
[47] | 567 | mov word ptr [Success],ax
|
---|
| 568 |
|
---|
| 569 | ; Restore ES.
|
---|
| 570 | pop es
|
---|
| 571 | }
|
---|
| 572 |
|
---|
[46] | 573 | return Success;
|
---|
[29] | 574 | }
|
---|
| 575 |
|
---|
[46] | 576 | BOOL Track0Write (void) {
|
---|
| 577 | BOOL Success = FALSE;
|
---|
[29] | 578 |
|
---|
[47] | 579 | _asm {
|
---|
| 580 |
|
---|
| 581 | push es ; ES is used to point to savebuffer.
|
---|
| 582 |
|
---|
| 583 | ; Save the complete AiR-BOOT image to Track0.
|
---|
| 584 | mov ah,03h ; Write sectors to disk.
|
---|
| 585 | mov al,SECTOR_COUNT ; Number of sectors to write.
|
---|
| 586 | mov cx,1 ; Cyl 0, Sector 1.
|
---|
| 587 | mov dh,0 ; Head 0.
|
---|
| 588 | mov dl,80h ; Boot Disk.
|
---|
| 589 | les bx,[Track0] ; Buffer in ES:BX.
|
---|
| 590 | int 13h ; Transfer to BIOS.
|
---|
| 591 |
|
---|
| 592 | ; Check for errors
|
---|
| 593 | mov dx,0 ; Assume error.
|
---|
| 594 | jc end ; CY if error.
|
---|
| 595 | test ah,ah ; Double check status in AH.
|
---|
| 596 | jnz end ; AH non-zero if error.
|
---|
| 597 |
|
---|
| 598 | inc dx ; Set to no error.
|
---|
| 599 |
|
---|
| 600 | end:
|
---|
| 601 | mov ax,dx ; Status to AX.
|
---|
| 602 |
|
---|
[48] | 603 | ; Store in return value.
|
---|
[47] | 604 | mov word ptr [Success],ax
|
---|
| 605 |
|
---|
| 606 | ; Restore ES.
|
---|
| 607 | pop es
|
---|
| 608 | }
|
---|
| 609 |
|
---|
[46] | 610 | return Success;
|
---|
| 611 | }
|
---|
[29] | 612 |
|
---|
[46] | 613 | void RebootSystem (void) {
|
---|
[47] | 614 | _asm {
|
---|
| 615 | ; 65 * 65536 = 4259840 us = 4.2 sec.
|
---|
| 616 | mov ax,8600h ; BIOS Wait.
|
---|
| 617 | xor dx,dx ; Micro seconds Low.
|
---|
| 618 | mov cx,65 ; Micro seconds High.
|
---|
| 619 | int 15h ; Transfer to BIOS.
|
---|
[46] | 620 |
|
---|
[47] | 621 | //~ ; Try reboot via keyboard.
|
---|
| 622 | //~ mov al,0feh
|
---|
| 623 | //~ out 64h,al
|
---|
| 624 |
|
---|
| 625 | ; Otherwise jump to F000:FFF0.
|
---|
| 626 | db 0EAh
|
---|
| 627 | dw 0FFF0h
|
---|
| 628 | dw 0F000h
|
---|
| 629 | }
|
---|
| 630 | return;
|
---|
[29] | 631 | }
|
---|
| 632 |
|
---|
[46] | 633 | #endif
|
---|
[29] | 634 |
|
---|
| 635 |
|
---|
| 636 |
|
---|
[46] | 637 | /*
|
---|
| 638 | // Helper functions -- OS/2 implementation.
|
---|
| 639 | */
|
---|
| 640 | #ifdef PLATFORM_OS2
|
---|
| 641 | USHORT CountHarddrives (void) {
|
---|
| 642 | USHORT NumDrives = 0;
|
---|
| 643 | if (DosPhysicalDisk(INFO_COUNT_PARTITIONABLE_DISKS, &NumDrives, sizeof(NumDrives),NULL, 0) != 0)
|
---|
| 644 | return 0;
|
---|
| 645 | return NumDrives;
|
---|
| 646 | }
|
---|
[29] | 647 |
|
---|
[46] | 648 | USHORT OS2_GetIOCTLHandle () {
|
---|
| 649 | USHORT IOCTLHandle = 0;
|
---|
| 650 | if (DosPhysicalDisk(INFO_GETIOCTLHANDLE, &IOCTLHandle, sizeof(IOCTLHandle),"1:" , 3) != 0)
|
---|
| 651 | return 0;
|
---|
| 652 | return IOCTLHandle;
|
---|
[29] | 653 | }
|
---|
| 654 |
|
---|
[46] | 655 | void OS2_FreeIOCTLHandle (USHORT IOCTLHandle) {
|
---|
| 656 | DosPhysicalDisk(INFO_FREEIOCTLHANDLE, NULL, 0, &IOCTLHandle, sizeof(IOCTLHandle));
|
---|
| 657 | return;
|
---|
| 658 | }
|
---|
[29] | 659 |
|
---|
[46] | 660 | // Special feature for OS/2, finds out boot drive letter and sends this
|
---|
| 661 | // information to AiR-BOOT, so that it's able to set that information
|
---|
| 662 | // during boot phase. Otherwise the user would have to set this.
|
---|
| 663 | UCHAR AutoDriveLetter = ' ';
|
---|
| 664 | ULONG AutoDriveLetterSerial = 0;
|
---|
[29] | 665 |
|
---|
[46] | 666 | void OS2_GetBootAutoDriveLetter (void) {
|
---|
| 667 | ULONG BootDrive;
|
---|
| 668 | struct {
|
---|
| 669 | ULONG ulVSN;
|
---|
| 670 | VOLUMELABEL vol;
|
---|
| 671 | } InfoLevel2;
|
---|
| 672 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &BootDrive, sizeof(BootDrive));
|
---|
| 673 | // BootDrive - 1-A:, 2-B:, 3-C:
|
---|
| 674 | if ((BootDrive>2) & (!DosQueryFSInfo(BootDrive, FSIL_VOLSER, (PVOID)(&InfoLevel2), sizeof(InfoLevel2)))) {
|
---|
| 675 | AutoDriveLetter = (UCHAR) BootDrive+0x7D;
|
---|
| 676 | AutoDriveLetterSerial = InfoLevel2.ulVSN;
|
---|
| 677 | if (!Option_CID) {
|
---|
| 678 | printf("%X\n", InfoLevel2.ulVSN);
|
---|
| 679 | }
|
---|
| 680 | }
|
---|
| 681 | }
|
---|
[29] | 682 |
|
---|
[48] | 683 | /*
|
---|
| 684 | // On DOS this geometry check uses the INT13X value for sectors per track.
|
---|
| 685 | // On OS/2 the DosDevIOCtl call uses a SPT value from the formatted disk,
|
---|
| 686 | // irrespective of the physical geometry.
|
---|
| 687 | */
|
---|
[46] | 688 | BOOL HarddriveCheckGeometry (void) {
|
---|
| 689 | USHORT IOCTLHandle;
|
---|
| 690 | USHORT SectorsPerTrack = 0;
|
---|
| 691 | DEVICEPARAMETERBLOCK DeviceParmBlock;
|
---|
| 692 | ULONG ulDataLength;
|
---|
[29] | 693 |
|
---|
[46] | 694 | IOCTLHandle = OS2_GetIOCTLHandle();
|
---|
[29] | 695 |
|
---|
[46] | 696 | if (!DosDevIOCtl(IOCTLHandle, IOCTL_PHYSICALDISK, PDSK_GETPHYSDEVICEPARAMS, NULL, 0, NULL, &DeviceParmBlock, sizeof(DeviceParmBlock), &ulDataLength))
|
---|
| 697 | SectorsPerTrack = DeviceParmBlock.cSectorsPerTrack;
|
---|
| 698 | OS2_FreeIOCTLHandle (IOCTLHandle);
|
---|
[47] | 699 | //if (SectorsPerTrack > 61) return TRUE;
|
---|
| 700 | if (SectorsPerTrack > SECTOR_COUNT) return TRUE;
|
---|
[46] | 701 | // OS/2 is only able to support 512-byte/sector media, so we dont need to check this
|
---|
| 702 | return FALSE;
|
---|
[29] | 703 | }
|
---|
| 704 |
|
---|
[46] | 705 | BOOL Track0Load (void) {
|
---|
| 706 | USHORT IOCTLHandle;
|
---|
| 707 | ULONG TrackLayoutLen = sizeof(TRACKLAYOUT)+sizeof(ULONG)*(SECTOR_COUNT-1);
|
---|
| 708 | TRACKLAYOUT *TrackLayoutPtr = (TRACKLAYOUT*) malloc(TrackLayoutLen);
|
---|
| 709 | ULONG cbParms = sizeof(TrackLayoutPtr);
|
---|
| 710 | ULONG cbData = BYTES_PER_SECTOR;
|
---|
| 711 | int i;
|
---|
| 712 | BOOL Success = FALSE;
|
---|
[29] | 713 |
|
---|
[46] | 714 | IOCTLHandle = OS2_GetIOCTLHandle();
|
---|
[29] | 715 |
|
---|
[46] | 716 | TrackLayoutPtr->bCommand = 0x01;
|
---|
| 717 | TrackLayoutPtr->usHead = 0;
|
---|
| 718 | TrackLayoutPtr->usCylinder = 0;
|
---|
| 719 | TrackLayoutPtr->usFirstSector = 0;
|
---|
| 720 | TrackLayoutPtr->cSectors = SECTOR_COUNT;
|
---|
| 721 |
|
---|
| 722 | for (i=0; i<SECTOR_COUNT; i++) {
|
---|
| 723 | TrackLayoutPtr->TrackTable[i].usSectorNumber = i+1;
|
---|
| 724 | TrackLayoutPtr->TrackTable[i].usSectorSize = BYTES_PER_SECTOR;
|
---|
| 725 | }
|
---|
| 726 |
|
---|
| 727 | if (!DosDevIOCtl(IOCTLHandle, IOCTL_PHYSICALDISK, PDSK_READPHYSTRACK,
|
---|
| 728 | TrackLayoutPtr, cbParms, &cbParms, Track0, cbData, &cbData))
|
---|
| 729 | Success = TRUE;
|
---|
| 730 |
|
---|
| 731 | OS2_FreeIOCTLHandle (IOCTLHandle);
|
---|
| 732 | free (TrackLayoutPtr);
|
---|
| 733 | return Success;
|
---|
[29] | 734 | }
|
---|
[46] | 735 |
|
---|
| 736 | BOOL Track0Write (void) {
|
---|
| 737 | USHORT IOCTLHandle;
|
---|
| 738 | ULONG TrackLayoutLen = sizeof(TRACKLAYOUT)+sizeof(ULONG)*(SECTOR_COUNT-1);
|
---|
| 739 | TRACKLAYOUT *TrackLayoutPtr = (TRACKLAYOUT*) malloc(TrackLayoutLen);
|
---|
| 740 | ULONG cbParms = sizeof(TrackLayoutPtr);
|
---|
| 741 | ULONG cbData = BYTES_PER_SECTOR;
|
---|
| 742 | INT i;
|
---|
| 743 | BOOL Success = FALSE;
|
---|
| 744 |
|
---|
| 745 | IOCTLHandle = OS2_GetIOCTLHandle();
|
---|
| 746 |
|
---|
| 747 |
|
---|
| 748 | TrackLayoutPtr->bCommand = 0x01;
|
---|
| 749 | TrackLayoutPtr->usHead = 0;
|
---|
| 750 | TrackLayoutPtr->usCylinder = 0;
|
---|
| 751 | TrackLayoutPtr->usFirstSector = 0;
|
---|
| 752 | TrackLayoutPtr->cSectors = SECTOR_COUNT;
|
---|
| 753 |
|
---|
| 754 | for (i=0; i<SECTOR_COUNT; i++) {
|
---|
| 755 | TrackLayoutPtr->TrackTable[i].usSectorNumber = i+1;
|
---|
| 756 | TrackLayoutPtr->TrackTable[i].usSectorSize = BYTES_PER_SECTOR;
|
---|
| 757 | }
|
---|
| 758 |
|
---|
| 759 | if (!DosDevIOCtl(IOCTLHandle, IOCTL_PHYSICALDISK, PDSK_WRITEPHYSTRACK,
|
---|
| 760 | TrackLayoutPtr, cbParms, &cbParms, Track0, cbData, &cbData))
|
---|
| 761 | Success = TRUE;
|
---|
| 762 |
|
---|
| 763 | OS2_FreeIOCTLHandle (IOCTLHandle);
|
---|
| 764 | free (TrackLayoutPtr);
|
---|
| 765 | return Success;
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | #define CATEGORY_DOSSYS 0xD5
|
---|
| 769 | #define FUNCTION_REBOOT 0xAB
|
---|
| 770 |
|
---|
| 771 | void RebootSystem (void) {
|
---|
| 772 | HFILE DosHandle;
|
---|
| 773 | ULONG DosOpenAction;
|
---|
| 774 |
|
---|
| 775 | DosSleep (2000);
|
---|
| 776 | if (!DosOpen("DOS$", &DosHandle, &DosOpenAction, 0, FILE_NORMAL, FILE_OPEN, OPEN_ACCESS_READWRITE|OPEN_SHARE_DENYNONE, NULL)) {
|
---|
| 777 | DosDevIOCtl(DosHandle, CATEGORY_DOSSYS, FUNCTION_REBOOT, NULL, 0, NULL, NULL, 0, NULL);
|
---|
| 778 | DosSleep (60000);
|
---|
| 779 | }
|
---|
| 780 | DosClose(DosHandle);
|
---|
| 781 | }
|
---|
[29] | 782 | #endif
|
---|
| 783 |
|
---|
[46] | 784 |
|
---|
| 785 |
|
---|
| 786 |
|
---|
| 787 | /*
|
---|
| 788 | // Helper functions -- Win32 implementation.
|
---|
| 789 | */
|
---|
| 790 | #ifdef PLATFORM_WINNT
|
---|
| 791 | // Checks, if we are under NT
|
---|
| 792 | BOOL CheckWindowsVersion (void) {
|
---|
| 793 | OSVERSIONINFO Version;
|
---|
| 794 | Version.dwOSVersionInfoSize = sizeof(Version);
|
---|
| 795 | GetVersionEx(&Version);
|
---|
| 796 | if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
---|
| 797 | return TRUE;
|
---|
| 798 | if (!Option_CID) {
|
---|
| 799 | printf(" - This installer is for WindowsNT family only.\n");
|
---|
| 800 | printf(" Please use DOS installer for Windows9x.\n");
|
---|
| 801 | }
|
---|
| 802 | return FALSE;
|
---|
[29] | 803 | }
|
---|
| 804 |
|
---|
| 805 |
|
---|
[46] | 806 | HANDLE WINNT_GetIOCTLHandle (void) {
|
---|
| 807 | return CreateFile("\\\\.\\physicaldrive0", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
|
---|
[29] | 808 | }
|
---|
| 809 |
|
---|
[46] | 810 | void WINNT_FreeIOCTLHandle (HANDLE IOCTLHandle) {
|
---|
| 811 | CloseHandle(IOCTLHandle);
|
---|
[29] | 812 | }
|
---|
[30] | 813 |
|
---|
[46] | 814 | USHORT CountHarddrives (void) {
|
---|
| 815 | return 1;
|
---|
[29] | 816 | }
|
---|
| 817 |
|
---|
[46] | 818 | BOOL HarddriveCheckGeometry (void) {
|
---|
| 819 | HANDLE IOCTLHandle;
|
---|
| 820 | DISK_GEOMETRY Geometry;
|
---|
| 821 | USHORT SectorsPerTrack = 0;
|
---|
| 822 | DWORD Dummy;
|
---|
[29] | 823 |
|
---|
[46] | 824 | IOCTLHandle = WINNT_GetIOCTLHandle();
|
---|
| 825 | if (DeviceIoControl(IOCTLHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &Geometry, sizeof(Geometry), &Dummy, NULL))
|
---|
| 826 | SectorsPerTrack = (USHORT) Geometry.SectorsPerTrack;
|
---|
| 827 | WINNT_FreeIOCTLHandle(IOCTLHandle);
|
---|
| 828 | //if (SectorsPerTrack > 61) return TRUE; // >60 should also be ok for normal image (60 for image 1 for lvm)
|
---|
| 829 | if (SectorsPerTrack > SECTOR_COUNT)
|
---|
| 830 | return TRUE; // Note: This is 1 sector smaller than above !!
|
---|
| 831 |
|
---|
| 832 | return FALSE;
|
---|
[29] | 833 | }
|
---|
| 834 |
|
---|
[46] | 835 | BOOL Track0Load (void) {
|
---|
| 836 | HANDLE IOCTLHandle;
|
---|
| 837 | DWORD BytesRead = 0;
|
---|
| 838 | BOOL Success = FALSE;
|
---|
[29] | 839 |
|
---|
[46] | 840 | IOCTLHandle = WINNT_GetIOCTLHandle();
|
---|
| 841 | SetFilePointer(IOCTLHandle, 0, 0, FILE_BEGIN);
|
---|
| 842 | if (ReadFile(IOCTLHandle, Track0, SECTOR_COUNT * BYTES_PER_SECTOR, &BytesRead, NULL))
|
---|
| 843 | Success = TRUE;
|
---|
| 844 | WINNT_FreeIOCTLHandle(IOCTLHandle);
|
---|
| 845 | return Success;
|
---|
[29] | 846 | }
|
---|
| 847 |
|
---|
[46] | 848 | BOOL Track0Write (void) {
|
---|
| 849 | HANDLE IOCTLHandle;
|
---|
| 850 | DWORD BytesWritten = 0;
|
---|
| 851 | BOOL Success = FALSE;
|
---|
[29] | 852 |
|
---|
[46] | 853 | IOCTLHandle = WINNT_GetIOCTLHandle();
|
---|
| 854 | SetFilePointer(IOCTLHandle, 0, 0, FILE_BEGIN);
|
---|
| 855 | if (WriteFile(IOCTLHandle, Track0, SECTOR_COUNT * BYTES_PER_SECTOR, &BytesWritten, NULL))
|
---|
| 856 | Success = TRUE;
|
---|
| 857 | WINNT_FreeIOCTLHandle(IOCTLHandle);
|
---|
| 858 | return Success;
|
---|
[29] | 859 | }
|
---|
| 860 |
|
---|
[46] | 861 | void RebootSystem (void) {
|
---|
| 862 | HANDLE token;
|
---|
| 863 | TOKEN_PRIVILEGES tokenpriv;
|
---|
| 864 | OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token);
|
---|
| 865 | LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tokenpriv.Privileges[0].Luid);
|
---|
| 866 | tokenpriv.PrivilegeCount = 1;
|
---|
| 867 | tokenpriv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
---|
| 868 | AdjustTokenPrivileges(token, FALSE, &tokenpriv, 0, NULL, 0);
|
---|
| 869 | ExitWindowsEx(EWX_REBOOT, 0);
|
---|
[29] | 870 | }
|
---|
| 871 | #endif
|
---|
| 872 |
|
---|
[46] | 873 |
|
---|
| 874 | /*
|
---|
| 875 | // Helper functions -- Linux implementation.
|
---|
| 876 | */
|
---|
| 877 | #ifdef PLATFORM_LINUX
|
---|
| 878 | USHORT CountHarddrives (void) {
|
---|
| 879 | USHORT NumDrives = 0;
|
---|
| 880 | // Implement !
|
---|
| 881 | return NumDrives;
|
---|
| 882 | }
|
---|
| 883 |
|
---|
| 884 | BOOL HarddriveCheckGeometry (void) {
|
---|
| 885 |
|
---|
| 886 | // Implement !
|
---|
| 887 | return FALSE;
|
---|
| 888 | }
|
---|
| 889 |
|
---|
| 890 | BOOL Track0Load (void) {
|
---|
| 891 | BOOL Success = FALSE;
|
---|
| 892 |
|
---|
| 893 | // Implement !
|
---|
| 894 | return Success;
|
---|
| 895 | }
|
---|
| 896 |
|
---|
| 897 | BOOL Track0Write (void) {
|
---|
| 898 | BOOL Success = FALSE;
|
---|
| 899 |
|
---|
| 900 | // Implement !
|
---|
| 901 | return Success;
|
---|
| 902 | }
|
---|
| 903 |
|
---|
| 904 | void RebootSystem (void) {
|
---|
| 905 |
|
---|
| 906 | // Implement !
|
---|
| 907 | }
|
---|
| 908 |
|
---|
| 909 | #endif
|
---|
| 910 |
|
---|
| 911 |
|
---|
| 912 |
|
---|
| 913 |
|
---|
| 914 |
|
---|
| 915 | // ============================================================================
|
---|
| 916 | // Common Code
|
---|
| 917 | // ============================================================================
|
---|
| 918 |
|
---|
| 919 |
|
---|
[29] | 920 | USHORT GetChecksumOfSector (USHORT Checksum, PCHAR SectorPtr) {
|
---|
[46] | 921 | PUSHORT TempPtr = (PUSHORT)SectorPtr;
|
---|
| 922 | USHORT i;
|
---|
| 923 | for (i=0; i<256; i++) {
|
---|
| 924 | Checksum = *TempPtr ^ 0xBABE ^ Checksum;
|
---|
| 925 | TempPtr++;
|
---|
[29] | 926 | }
|
---|
[46] | 927 | if (Checksum==0)
|
---|
| 928 | Checksum = 1;
|
---|
| 929 | return Checksum;
|
---|
| 930 | }
|
---|
[29] | 931 |
|
---|
| 932 | // Loads airboot.bin into memory (if possible) and sets some variables
|
---|
| 933 | // also makes sure that airboot.bin has correct length
|
---|
| 934 | BOOL LoadBootcodeFromFile (void) {
|
---|
[46] | 935 | FILE *FileHandle = NULL;
|
---|
| 936 | ULONG BootcodeSize = 0;
|
---|
[29] | 937 |
|
---|
[46] | 938 | // Try to open file...
|
---|
| 939 | FileHandle = fopen(IMAGE_NAME, "rb");
|
---|
| 940 | if (!FileHandle) {
|
---|
| 941 | if (!Option_CID) {
|
---|
| 942 | printf("%s not found\n", IMAGE_NAME);
|
---|
| 943 | }
|
---|
| 944 | return FALSE;
|
---|
[29] | 945 | }
|
---|
[46] | 946 |
|
---|
| 947 | // Seek to end of file to determine image size...
|
---|
| 948 | fseek (FileHandle, 0, SEEK_END);
|
---|
| 949 | BootcodeSize = ftell(FileHandle);
|
---|
[47] | 950 | if (BootcodeSize!=IMAGE_SIZE && BootcodeSize!=IMAGE_SIZE_60SECS) {
|
---|
[46] | 951 | fclose (FileHandle);
|
---|
| 952 | if (!Option_CID) {
|
---|
| 953 | printf("Invalid %sn\n", IMAGE_NAME);
|
---|
| 954 | }
|
---|
| 955 | return FALSE;
|
---|
[29] | 956 | }
|
---|
| 957 |
|
---|
[46] | 958 | // Read whole file into memory...
|
---|
| 959 | fseek (FileHandle, 0, SEEK_SET);
|
---|
| 960 | fread (Bootcode, 1, IMAGE_SIZE, FileHandle);
|
---|
| 961 | fclose (FileHandle);
|
---|
[29] | 962 |
|
---|
[46] | 963 | // Extract language and version info...
|
---|
| 964 | Bootcode_Version = (Bootcode[13] << 8) | Bootcode[14];
|
---|
| 965 | Bootcode_LanguageID = Bootcode[15];
|
---|
| 966 | Bootcode_ConfigVersion = (Bootcode[0x6C0D] << 8) | Bootcode[0x6C0E];
|
---|
| 967 | return TRUE;
|
---|
| 968 | }
|
---|
[29] | 969 |
|
---|
[30] | 970 | /**
|
---|
| 971 | * Check MBR and AB signatures.
|
---|
| 972 | * Also check code sectors if AB is installed.
|
---|
| 973 | * Set global status accordingly.
|
---|
| 974 | */
|
---|
[29] | 975 | void Status_CheckCode (void) {
|
---|
[46] | 976 | USHORT TotalCodeSectorsUsed = 0;
|
---|
| 977 | USHORT Checksum = 0;
|
---|
| 978 | PCHAR SectorPtr = NULL;
|
---|
[29] | 979 |
|
---|
[46] | 980 | if (Status_Code==STATUS_IMPOSSIBLE)
|
---|
| 981 | return;
|
---|
| 982 | // EZ-Setup check!
|
---|
| 983 | Status_Code = STATUS_NOTINSTALLED;
|
---|
| 984 | if ((Track0[0x1FE]!=0x55) || (Track0[0x1FF]!=0xAA))
|
---|
| 985 | return; // No MBR signature found, so not installed
|
---|
| 986 | if (strncmp(&Track0[2], "AiRBOOT", 7)!=0)
|
---|
| 987 | return; // No AiR-BOOT signature found, so not installed
|
---|
| 988 | // MBR and AiR-BOOT signature found...
|
---|
| 989 | TotalCodeSectorsUsed = Track0[0x10]; // 34h/52 in v1.06
|
---|
| 990 | SectorPtr = &Track0[1 * BYTES_PER_SECTOR]; // Start at sector 2
|
---|
| 991 | // Calculate checksum of code-sectors
|
---|
| 992 | while (TotalCodeSectorsUsed>0) {
|
---|
| 993 | Checksum = GetChecksumOfSector(Checksum, SectorPtr);
|
---|
| 994 | SectorPtr += BYTES_PER_SECTOR;
|
---|
| 995 | TotalCodeSectorsUsed--;
|
---|
[29] | 996 | }
|
---|
[54] | 997 | if (Checksum!=*(PUSHORT) &Track0[0x11]) {
|
---|
[46] | 998 | Status_Code = STATUS_CORRUPT;
|
---|
| 999 | return; // Bad checksum for code
|
---|
[29] | 1000 | }
|
---|
[46] | 1001 | // Checksum fine...
|
---|
| 1002 | Installed_LanguageID = Track0[0x0F];
|
---|
| 1003 | Installed_CodeVersion = (Track0[0x0D] << 8) | Track0[0x0E];
|
---|
[54] | 1004 | if (Installed_CodeVersion < Bootcode_Version)
|
---|
[46] | 1005 | Status_Code = STATUS_INSTALLEDMGU; // Do upgrade
|
---|
| 1006 | else
|
---|
| 1007 | Status_Code = STATUS_INSTALLED; // Same version installed
|
---|
[29] | 1008 |
|
---|
[46] | 1009 | return;
|
---|
| 1010 | }
|
---|
[30] | 1011 |
|
---|
[46] | 1012 |
|
---|
[29] | 1013 | void Status_CheckConfig (void) {
|
---|
[46] | 1014 | PCHAR ConfigSectorPtr = &Track0[CONFIG_OFFSET]; // Config sector offset hard-coded !
|
---|
| 1015 | PCHAR SectorPtr = NULL;
|
---|
| 1016 | USHORT Checksum = 0;
|
---|
| 1017 | USHORT ConfigChecksum = 0;
|
---|
| 1018 | USHORT SectorCount = 0;
|
---|
[29] | 1019 |
|
---|
[46] | 1020 | /*
|
---|
| 1021 | // Note that the 'AiRCFG-TABLE' string includes the invisible 0xAD char.
|
---|
| 1022 | */
|
---|
[238] | 1023 | if (strncmp(ConfigSectorPtr, "AiRCFG-TABLE\xad", 13)==0) {
|
---|
[46] | 1024 | // AiR-BOOT signature found...
|
---|
| 1025 | SectorPtr = &Track0[54 * BYTES_PER_SECTOR]; // Start at sector 55
|
---|
| 1026 | ConfigChecksum = *(PUSHORT)&Track0[54 * BYTES_PER_SECTOR + 20];
|
---|
| 1027 | // Remove checksum
|
---|
| 1028 | *(PUSHORT)&Track0[54 * BYTES_PER_SECTOR + 20] = 0; // Config sector secnum hard-coded !
|
---|
[30] | 1029 |
|
---|
[46] | 1030 | /*
|
---|
| 1031 | // Rousseau: # Keep compatible with v1.07 CRC #
|
---|
| 1032 | // AB v1.07 had bugs in writing the wrong number of AB config sectors.
|
---|
| 1033 | // This is fixed in v1.0.8 but the CRC has to be calculated the "v1.07 way"
|
---|
| 1034 | // otherwise v1.07 SET(A)BOOT and INSTALL2.EXE will think the AB config
|
---|
| 1035 | // is corrupted.
|
---|
| 1036 | // So the CRC is calculated over 5 sectors instead of 7.
|
---|
| 1037 | */
|
---|
| 1038 | SectorCount = 5;
|
---|
[31] | 1039 |
|
---|
[46] | 1040 | while (SectorCount>0) {
|
---|
| 1041 | Checksum = GetChecksumOfSector(Checksum, SectorPtr);
|
---|
| 1042 | SectorPtr += BYTES_PER_SECTOR;
|
---|
| 1043 | SectorCount--;
|
---|
| 1044 | }
|
---|
| 1045 | // Restore checksum
|
---|
[54] | 1046 | *(PUSHORT) &Track0[54 * BYTES_PER_SECTOR + 20] = ConfigChecksum; // Config sector secnum hard-coded !
|
---|
| 1047 | if (Checksum != ConfigChecksum) {
|
---|
[46] | 1048 | Status_Config = STATUS_CORRUPT;
|
---|
| 1049 | return;
|
---|
| 1050 | }
|
---|
| 1051 | // Checksum fine
|
---|
| 1052 | Installed_ConfigVersion = (Track0[54 * BYTES_PER_SECTOR + 0x0D] << 8) | Track0[54 * BYTES_PER_SECTOR + 0x0E];
|
---|
[54] | 1053 | if (Installed_ConfigVersion >= Bootcode_ConfigVersion) {
|
---|
[46] | 1054 | Status_Config = STATUS_INSTALLED;
|
---|
| 1055 | return;
|
---|
| 1056 | }
|
---|
| 1057 | Status_Config = STATUS_INSTALLEDMGU;
|
---|
[51] | 1058 |
|
---|
| 1059 | // Abort if unknown installed config version.
|
---|
[54] | 1060 | if ((Installed_ConfigVersion > 0x110)) {
|
---|
[51] | 1061 | if (!Option_CID) {
|
---|
| 1062 | printf("\n");
|
---|
| 1063 | printf("Configuration version of installed AiR-BOOT not supported by this installer !\n");
|
---|
| 1064 | printf("\n");
|
---|
| 1065 | }
|
---|
| 1066 | exit(1);
|
---|
| 1067 | }
|
---|
| 1068 |
|
---|
| 1069 | // Abort if unknown to-install config version.
|
---|
[54] | 1070 | if ((Bootcode_ConfigVersion > 0x110)) {
|
---|
[51] | 1071 | if (!Option_CID) {
|
---|
| 1072 | printf("\n");
|
---|
| 1073 | printf("Configuration version of new AiR-BOOT.BIN not supported by this installer !\n");
|
---|
| 1074 | printf("\n");
|
---|
| 1075 | }
|
---|
| 1076 | exit(1);
|
---|
| 1077 | }
|
---|
| 1078 |
|
---|
| 1079 |
|
---|
[46] | 1080 | // Those upgrades will copy useful configuration data to the image config
|
---|
[54] | 1081 | // If new configuration data was added, those spaces are not overwritten
|
---|
[46] | 1082 | // Sector 60 (MBR-BackUp) *MUST BE* copied, otherwise it would be lost.
|
---|
| 1083 | // Rousseau: Upgrade from v0.27
|
---|
[54] | 1084 | if (Installed_ConfigVersion <= 0x27) {
|
---|
[46] | 1085 | // UPGRADE v0.27 and prior versions
|
---|
[29] | 1086 |
|
---|
[46] | 1087 | // Sector 55
|
---|
| 1088 | // Changes: Offset 69 length 75 - Linux command line
|
---|
| 1089 | // Offset 144 length 1 - Linux kernel partition
|
---|
| 1090 | // Offset 145 Length 11 - Default kernel name
|
---|
| 1091 | // Offset 156 Length 1 - Kernel name terminator 1
|
---|
| 1092 | // Offset 157 Length 11 - Last kernel name
|
---|
| 1093 | // Offset 168 Length 1 - Kernel name terminator 2
|
---|
| 1094 | // Offset 169 Length 1 - Ext. partition M$-hack enable
|
---|
| 1095 | // -> Total-length 101
|
---|
| 1096 | // Offset 432 Length 34 - New IPT entry (BIOS continued)
|
---|
| 1097 | memcpy(&Bootcode[54 * BYTES_PER_SECTOR + 16], &Track0[54 * BYTES_PER_SECTOR + 16], 69 - 16); // CHECKEN !!
|
---|
| 1098 | memcpy(&Bootcode[54 * BYTES_PER_SECTOR + 466], &Track0[54 * BYTES_PER_SECTOR + 466], 46); // CHECKEN !!
|
---|
| 1099 | // Sector 56-57 no changes
|
---|
| 1100 | memcpy(&Bootcode[55*512], &Track0[55 * BYTES_PER_SECTOR], 1024);
|
---|
| 1101 | // Sector 58-59
|
---|
| 1102 | // Changes: Offset 900 Length 30 - Logical driveletter table
|
---|
| 1103 | memcpy(&Bootcode[57 * BYTES_PER_SECTOR], &Track0[57 * BYTES_PER_SECTOR], 900); // AANPASSEN 900 !!
|
---|
| 1104 | // Sector 60 copy unmodified
|
---|
| 1105 | memcpy(&Bootcode[59 * BYTES_PER_SECTOR], &Track0[59 * BYTES_PER_SECTOR], BYTES_PER_SECTOR); // CHECKEN !!
|
---|
| 1106 | return;
|
---|
| 1107 | }
|
---|
| 1108 | // Rousseau: Upgrade from v0.91
|
---|
[54] | 1109 | if (Installed_ConfigVersion <= 0x91) {
|
---|
[46] | 1110 | // UPGRADE v0.91 and prior versions
|
---|
| 1111 | // Sector 55-57 no changes
|
---|
| 1112 | memcpy(&Bootcode[54 * BYTES_PER_SECTOR + 16], &Track0[54 * BYTES_PER_SECTOR + 16], BYTES_PER_SECTOR + 1024 - 16); // CHACKEN !!
|
---|
| 1113 | // Sector 58-59
|
---|
| 1114 | // Changes: Offset 900 Length 30 - Logical driveletter table
|
---|
| 1115 | memcpy(&Bootcode[57 * BYTES_PER_SECTOR], &Track0[57 * BYTES_PER_SECTOR], 900); // AANPASSEN 900 !!
|
---|
| 1116 | // Sector 60/62 copy unmodified
|
---|
| 1117 | memcpy(&Bootcode[59 * BYTES_PER_SECTOR], &Track0[59 * BYTES_PER_SECTOR], BYTES_PER_SECTOR);
|
---|
| 1118 | return;
|
---|
| 1119 | }
|
---|
[30] | 1120 |
|
---|
[46] | 1121 |
|
---|
[47] | 1122 | // UPGRADE to v1.06 format.
|
---|
| 1123 | // We don't need to "upgrade" the configuration to move to v1.06, we simply copy it over.
|
---|
| 1124 | // From Sector 55, 6 sectors in total but never header/version.
|
---|
[46] | 1125 | // Rousseau: We copy two more sectors (8 in total) in the extended (45 partition) version.
|
---|
| 1126 | switch (IMAGE_SIZE) {
|
---|
| 1127 | case IMAGE_SIZE_60SECS: {
|
---|
| 1128 | memcpy(&Bootcode[54 * BYTES_PER_SECTOR + 16], &Track0[54 * BYTES_PER_SECTOR + 16], BYTES_PER_SECTOR * 6 - 16);
|
---|
| 1129 | break;
|
---|
| 1130 | }
|
---|
| 1131 | case IMAGE_SIZE_62SECS: {
|
---|
| 1132 | memcpy(&Bootcode[54 * BYTES_PER_SECTOR + 16], &Track0[54 * BYTES_PER_SECTOR + 16], BYTES_PER_SECTOR * 8 - 16);
|
---|
| 1133 | break;
|
---|
| 1134 | }
|
---|
| 1135 | }
|
---|
[47] | 1136 |
|
---|
| 1137 | /*
|
---|
| 1138 | // Convert v1.06 hideparttable (30x30) to the v1.07 (30x45) format.
|
---|
[54] | 1139 | // Also copy drive-letters to either v1.07 or v1.0.8+ location.
|
---|
[47] | 1140 | */
|
---|
| 1141 | if ((Installed_ConfigVersion == 0x102) && (Bootcode_ConfigVersion >= 0x107)) {
|
---|
| 1142 | int i,j;
|
---|
| 1143 | char c;
|
---|
| 1144 | //printf("Converting 1.06 -> 1.07 hidepart");
|
---|
[51] | 1145 | // Copy old hide-part table to new location.
|
---|
[47] | 1146 | memcpy(&Bootcode[0x7400], &Track0[0x7200], 900);
|
---|
[51] | 1147 | // Setup temporary table.
|
---|
[47] | 1148 | memset(TempHidPartTable, 0xff, 45 * 34);
|
---|
[51] | 1149 | // Copy old hide-part table to temporary table.
|
---|
[47] | 1150 | for (i=0; i<30; i++) {
|
---|
| 1151 | for (j=0; j<30; j++) {
|
---|
| 1152 | c = Bootcode[0x7400+i*30+j];
|
---|
| 1153 | TempHidPartTable[i*45+j] = c;
|
---|
| 1154 | }
|
---|
| 1155 | }
|
---|
[51] | 1156 | // Copy temporary table to final v1.07 location.
|
---|
[47] | 1157 | memcpy(&Bootcode[0x7400], TempHidPartTable, 30 * 45);
|
---|
[51] | 1158 |
|
---|
| 1159 | // Clear drive-letters if version being installed is v1.07.
|
---|
| 1160 | if (Bootcode_ConfigVersion == 0x107) {
|
---|
| 1161 | memset(&Bootcode[0x7946], 0, 45);
|
---|
| 1162 | }
|
---|
| 1163 |
|
---|
[54] | 1164 | // Copy over drive-letters from v1.06 location to v1.08+ location.
|
---|
| 1165 | if ((Bootcode_ConfigVersion >= 0x108) && (Bootcode_ConfigVersion <= 0x110)) {
|
---|
[51] | 1166 | memset(&Bootcode[0x6cb0], 0, 45);
|
---|
| 1167 | memcpy(&Bootcode[0x6cb0], &Track0[0x7584], 30);
|
---|
| 1168 | }
|
---|
[47] | 1169 | }
|
---|
| 1170 |
|
---|
| 1171 | /*
|
---|
| 1172 | // Convert v1.07 hideparttable (30x45) to a packed v1.0.8+ (45x45) format.
|
---|
| 1173 | */
|
---|
[54] | 1174 | if ((Installed_ConfigVersion < 0x108) && (Bootcode_ConfigVersion <= 0x110)) {
|
---|
[47] | 1175 | int i,j;
|
---|
| 1176 | char c;
|
---|
| 1177 | //printf("Converting to 1.08 packed hidepart");
|
---|
[51] | 1178 | // Setup temporary table.
|
---|
[47] | 1179 | memset(TempHidPartTable, 0xff, 45 * 34);
|
---|
[51] | 1180 |
|
---|
| 1181 | // Copy old hide-part table to temporary table.
|
---|
[47] | 1182 | // Unpacked table is 30 rows with 45 columns per row.
|
---|
| 1183 | // Packed table is 45 rows with 45 columns per row packed in 34 bytes.
|
---|
| 1184 | for (i=0; i<30; i++) {
|
---|
| 1185 | for (j=0; j<45; j++) {
|
---|
| 1186 | c = Bootcode[0x7400+i*45+j]; // Get unpacked value
|
---|
| 1187 | c = set_bitfield(&TempHidPartTable[i*34], j, 6, c); // Store 6-bit packed value
|
---|
| 1188 | }
|
---|
| 1189 | }
|
---|
[54] | 1190 | // Copy temporary table to final v1.0.8+ location (packed format)
|
---|
[47] | 1191 | memcpy(&Bootcode[0x7400], TempHidPartTable, 45 * 34);
|
---|
[51] | 1192 | // Show LVM Drive Letters.
|
---|
| 1193 | Bootcode[0x6c17] = 1;
|
---|
[47] | 1194 | }
|
---|
| 1195 |
|
---|
[46] | 1196 | return;
|
---|
[29] | 1197 | }
|
---|
[47] | 1198 | // MKW:
|
---|
[46] | 1199 | // Check for prior v0.26 signature
|
---|
| 1200 | // not supported in C version anymore
|
---|
[47] | 1201 | // Don't have this version here for testing and I can't risk breaking
|
---|
| 1202 | // configuration
|
---|
[46] | 1203 | return;
|
---|
| 1204 | }
|
---|
[29] | 1205 |
|
---|
| 1206 | // Checks partition table for valid data
|
---|
[30] | 1207 | BOOL Virus_CheckThisMBR (PCHAR MBRptr) { // Rousseau: adjusted this function
|
---|
[46] | 1208 | USHORT PartitionNo;
|
---|
| 1209 | ////ULONG CHSStart, CHSEnd;
|
---|
[29] | 1210 |
|
---|
[46] | 1211 | //printf("DEBUG: Virus_CheckThisMBR\n");
|
---|
[30] | 1212 |
|
---|
[46] | 1213 | if (*(PUSHORT)(MBRptr + BYTES_PER_SECTOR - 2)!=0x0AA55)
|
---|
| 1214 | return FALSE;
|
---|
[30] | 1215 |
|
---|
[46] | 1216 | //printf("DEBUG: Virus_CheckThisMBR - Checking Partitions\n");
|
---|
[30] | 1217 |
|
---|
[46] | 1218 | MBRptr += 446;
|
---|
| 1219 | for (PartitionNo=0; PartitionNo<4; PartitionNo++) {
|
---|
| 1220 | if (*(MBRptr+4) != 0) {
|
---|
| 1221 | /*
|
---|
| 1222 | // Rousseau 2011-02-04: ## Check for GPT ##
|
---|
| 1223 | */
|
---|
| 1224 | if (*(MBRptr+4) == GPT) {
|
---|
| 1225 | if (!Option_CID) {
|
---|
| 1226 | printf("ERROR: This drive is partitioned with the modern GPT layout.\n");
|
---|
| 1227 | printf(" AiR-BOOT is currently unable to handle GPT partitioned drives.\n");
|
---|
| 1228 | printf(" Installation aborted, no changes made.\n");
|
---|
| 1229 | }
|
---|
| 1230 | exit(2);
|
---|
[30] | 1231 | }
|
---|
| 1232 |
|
---|
[46] | 1233 | /*
|
---|
| 1234 | // Rousseau: 2011-05-05
|
---|
| 1235 | // Last minute change to have AB install on a disk
|
---|
| 1236 | // with nopartitions on the it. (check !)
|
---|
| 1237 | // It still checks for GPT but will skip the check below.
|
---|
| 1238 | */
|
---|
| 1239 | continue;
|
---|
[30] | 1240 |
|
---|
[46] | 1241 | //printf("DEBUG: Virus_CheckThisMBR - Partition: %d\n", PartitionNo);
|
---|
| 1242 | // Partition-type defined, analyse partition data
|
---|
| 1243 | ////CHSStart = (*(MBRptr+3) | ((*(MBRptr+2) >> 6) << 8)) << 16; // Cylinder
|
---|
| 1244 | ////CHSStart |= (*(MBRptr+2) & 0x3F) | ((*(MBRptr+1) << 8)); // Sector / Head
|
---|
| 1245 | //printf("DEBUG: Virus_CheckThisMBR - CHSStart: %d\n", CHSStart); // 3F MASK CHECKEN !!
|
---|
[29] | 1246 |
|
---|
[46] | 1247 | ////CHSEnd = (*(MBRptr+7) | ((*(MBRptr+6) >> 6) << 8)) << 16; // Cylinder
|
---|
| 1248 | ////CHSEnd |= (*(MBRptr+6) & 0x3F) | ((*(MBRptr+5) << 8)); // Sector / Head
|
---|
| 1249 | //printf("DEBUG: Virus_CheckThisMBR - CHSEnd: %d\n", CHSEnd);
|
---|
[29] | 1250 |
|
---|
[30] | 1251 |
|
---|
[46] | 1252 | /*
|
---|
| 1253 | // Rousseau 2011-02-03: ## Changed below from < to <= ##
|
---|
| 1254 | // When a partition is above 1024x255x63 (8GiB) the start and end of the partition
|
---|
| 1255 | // in the MBR is the same (1024/255/63) to indicate extended CHS-values.
|
---|
| 1256 | // This made the installer see this as a non-valid entry.
|
---|
| 1257 | // Fixme: This could use some further optimazation like checking if CHS is really 1024/255/63
|
---|
| 1258 | // to exclude truly faulty partition-entries.
|
---|
| 1259 | // Also depends on conventions: IBM,MS,Partition Magic,...
|
---|
| 1260 | */
|
---|
| 1261 | /*if (CHSStart<CHSEnd) {*/
|
---|
| 1262 | ////if (CHSStart<=CHSEnd) {
|
---|
| 1263 | //// if (*(PULONG)(MBRptr+12)!=0) // Absolute length > 0?
|
---|
| 1264 | //// return TRUE;
|
---|
| 1265 | ////}
|
---|
| 1266 | }
|
---|
| 1267 | // Go to next partition
|
---|
| 1268 | MBRptr += 16;
|
---|
[29] | 1269 | }
|
---|
[46] | 1270 | // No partitions defined/no valid partitions found
|
---|
| 1271 | // Rousseau: Still return TRUE (OK)
|
---|
| 1272 | //return FALSE;
|
---|
| 1273 | return TRUE;
|
---|
| 1274 | }
|
---|
[29] | 1275 |
|
---|
| 1276 | BOOL Virus_CheckCurrentMBR (void) {
|
---|
[46] | 1277 | return Virus_CheckThisMBR((PCHAR) Track0);
|
---|
| 1278 | }
|
---|
[29] | 1279 |
|
---|
| 1280 | BOOL Virus_CheckForBackUpMBR (void) {
|
---|
[46] | 1281 | BOOL bMbrBackup = FALSE;
|
---|
[29] | 1282 |
|
---|
[46] | 1283 | // All versions above v1.06 have expanded tables so the MBR-backup
|
---|
| 1284 | // is located 2 sectors higher in the track0 image.
|
---|
[54] | 1285 | if (Installed_ConfigVersion <= 0x0106)
|
---|
[46] | 1286 | bMbrBackup = Virus_CheckThisMBR((PCHAR) &Track0[59 * BYTES_PER_SECTOR]);
|
---|
| 1287 | else
|
---|
| 1288 | bMbrBackup = Virus_CheckThisMBR((PCHAR) &Track0[61 * BYTES_PER_SECTOR]);
|
---|
| 1289 |
|
---|
| 1290 | return bMbrBackup;
|
---|
| 1291 | }
|
---|
| 1292 |
|
---|
[29] | 1293 | BOOL Virus_CheckForStealth (void) {
|
---|
[46] | 1294 | PCHAR CurPtr = (PCHAR) Track0;
|
---|
| 1295 | USHORT i;
|
---|
[29] | 1296 |
|
---|
[46] | 1297 | for (i=0; i<511; i++) {
|
---|
[54] | 1298 | if (*(PUSHORT)CurPtr == 0x13CD) return FALSE;
|
---|
[46] | 1299 | CurPtr++;
|
---|
[29] | 1300 | }
|
---|
[46] | 1301 | // No CD13h found? possible stealth
|
---|
| 1302 | return TRUE;
|
---|
| 1303 | }
|
---|
[29] | 1304 |
|
---|
| 1305 | // Copies backup MBR into current MBR on current memory copy of track 0
|
---|
[30] | 1306 | // Rousseau: Two sectors higher in the extended version.
|
---|
[29] | 1307 | void Virus_CopyBackUpMBR (void) {
|
---|
[46] | 1308 | switch (IMAGE_SIZE) {
|
---|
| 1309 | case IMAGE_SIZE_60SECS: {
|
---|
| 1310 | memcpy(Track0, &Track0[59 * BYTES_PER_SECTOR], BYTES_PER_SECTOR); // sector 60
|
---|
| 1311 | break;
|
---|
| 1312 | }
|
---|
| 1313 | case IMAGE_SIZE_62SECS: {
|
---|
| 1314 | memcpy(Track0, &Track0[61 * BYTES_PER_SECTOR], BYTES_PER_SECTOR); // sector 62
|
---|
| 1315 | break;
|
---|
| 1316 | }
|
---|
| 1317 | }
|
---|
| 1318 | }
|
---|
[29] | 1319 |
|
---|
| 1320 | void Status_PrintF (ULONG Status, USHORT Version) {
|
---|
[46] | 1321 | switch (Status) {
|
---|
| 1322 | case STATUS_NOTINSTALLED: {
|
---|
| 1323 | if (!Option_CID) {
|
---|
| 1324 | printf("not installed\n");
|
---|
| 1325 | }
|
---|
| 1326 | break;
|
---|
| 1327 | }
|
---|
| 1328 | case STATUS_CORRUPT: {
|
---|
| 1329 | if (!Option_CID) {
|
---|
| 1330 | printf("not intact\n");
|
---|
| 1331 | }
|
---|
| 1332 | break;
|
---|
| 1333 | }
|
---|
| 1334 | case STATUS_INSTALLED:
|
---|
| 1335 | case STATUS_INSTALLEDMGU:
|
---|
| 1336 | if (!Option_CID) {
|
---|
| 1337 | printf("intact (v%x.%1d.%1d)", Version>>8, (Version & 0x0F0)>>4, Version & 0x0F);
|
---|
| 1338 | }
|
---|
| 1339 | if (Status==STATUS_INSTALLEDMGU)
|
---|
| 1340 | if (!Option_CID) {
|
---|
| 1341 | printf(", but may be updated");
|
---|
[47] | 1342 | }
|
---|
| 1343 | if (!Option_CID) {
|
---|
[46] | 1344 | printf("\n");
|
---|
[47] | 1345 | }
|
---|
[46] | 1346 | break;
|
---|
[47] | 1347 |
|
---|
[46] | 1348 | case STATUS_IMPOSSIBLE:
|
---|
| 1349 | if (!Option_CID) {
|
---|
[47] | 1350 | printf(ImpossibleCause);
|
---|
[46] | 1351 | }
|
---|
| 1352 | break;
|
---|
[29] | 1353 | }
|
---|
[46] | 1354 | }
|
---|
[29] | 1355 |
|
---|
| 1356 | void Language_PrintF(UCHAR LanguageID) {
|
---|
[46] | 1357 | if (Option_CID)
|
---|
| 1358 | return;
|
---|
| 1359 | switch (LanguageID) {
|
---|
| 1360 | case 'E': printf("english"); break;
|
---|
| 1361 | case 'N': printf("dutch"); break; // Changed from 'D' to 'N'
|
---|
| 1362 | case 'G': printf("german"); break;
|
---|
| 1363 | case 'F': printf("french"); break;
|
---|
| 1364 | case 'I': printf("italian"); break;
|
---|
| 1365 | case 'R': printf("russian"); break;
|
---|
| 1366 | case 'S': printf("swedish"); break;
|
---|
[238] | 1367 | case 0xa5: printf("spanish"); break;
|
---|
[46] | 1368 | default: printf("unknown");
|
---|
[29] | 1369 | }
|
---|
[46] | 1370 | }
|
---|
[29] | 1371 |
|
---|
| 1372 | // Doesn't actually write code/config, but writes it to track0 memory
|
---|
| 1373 | void Install_WriteCode (void) {
|
---|
[46] | 1374 | USHORT TotalCodeSectorsUsed = 0;
|
---|
| 1375 | USHORT SectorCount = 0;
|
---|
| 1376 | USHORT Checksum = 0;
|
---|
| 1377 | PCHAR SectorPtr = NULL;
|
---|
[29] | 1378 |
|
---|
[46] | 1379 | // Calculate checksum for code...
|
---|
| 1380 | TotalCodeSectorsUsed = Bootcode[0x10]; // SECTORS USED CHECKEN !! (34h / 52d in v1.06)
|
---|
| 1381 | SectorPtr = &Bootcode[1 * BYTES_PER_SECTOR]; // Start at sector 2
|
---|
| 1382 | SectorCount = TotalCodeSectorsUsed;
|
---|
| 1383 | while (SectorCount>0) {
|
---|
| 1384 | Checksum = GetChecksumOfSector(Checksum, SectorPtr);
|
---|
| 1385 | SectorPtr += BYTES_PER_SECTOR;
|
---|
| 1386 | SectorCount--;
|
---|
[29] | 1387 | }
|
---|
[46] | 1388 | *(PUSHORT)&Bootcode[0x11] = Checksum;
|
---|
[29] | 1389 |
|
---|
[46] | 1390 | // Copy MBR till offset 0x1B8 (Windows NT hdd signature location)
|
---|
| 1391 | memcpy(Track0, Bootcode, 0x1B8);
|
---|
[29] | 1392 |
|
---|
[46] | 1393 | // Copy over code sectors...
|
---|
| 1394 | memcpy(&Track0[BYTES_PER_SECTOR], &Bootcode[BYTES_PER_SECTOR], TotalCodeSectorsUsed * BYTES_PER_SECTOR);
|
---|
| 1395 | }
|
---|
[29] | 1396 |
|
---|
| 1397 | void Install_WriteConfig (void) {
|
---|
[46] | 1398 | USHORT SectorCount = 0;
|
---|
| 1399 | USHORT Checksum = 0;
|
---|
| 1400 | PCHAR SectorPtr = NULL;
|
---|
[29] | 1401 |
|
---|
[46] | 1402 | #ifdef PLATFORM_OS2
|
---|
| 1403 | if (AutoDriveLetter!=0) {
|
---|
| 1404 | // Add DriveLetter Automatic veriables, if set
|
---|
| 1405 | Bootcode[54 * BYTES_PER_SECTOR + 0x1AB] = AutoDriveLetter; // CHECKEN !
|
---|
| 1406 | *(PULONG)&Bootcode[54 * BYTES_PER_SECTOR + 0x1AC] = AutoDriveLetterSerial;
|
---|
| 1407 | }
|
---|
| 1408 | #endif
|
---|
[29] | 1409 |
|
---|
[46] | 1410 | // Delete current checksum
|
---|
| 1411 | *(PUSHORT)&Bootcode[54 * BYTES_PER_SECTOR + 20] = 0;
|
---|
[29] | 1412 |
|
---|
[46] | 1413 | SectorPtr = &Bootcode[54 * BYTES_PER_SECTOR]; // Start at sector 55
|
---|
[31] | 1414 |
|
---|
[46] | 1415 | /*
|
---|
| 1416 | // Rousseau: # Keep compatible with v1.07 CRC #
|
---|
| 1417 | // AB v1.07 had bugs in writing the wrong number of AB config sectors.
|
---|
[54] | 1418 | // This is fixed in v1.0.8+ but the CRC has to be calculated the "v1.07 way"
|
---|
[46] | 1419 | // otherwise v1.07 SET(A)BOOT and AIRBOOT2.EXE will think the AB config
|
---|
| 1420 | // is corrupted.
|
---|
| 1421 | // So the CRC is calculated over 5 sectors instead of 7.
|
---|
| 1422 | */
|
---|
| 1423 | SectorCount = 5;
|
---|
[31] | 1424 |
|
---|
[46] | 1425 | while (SectorCount>0) {
|
---|
| 1426 | Checksum = GetChecksumOfSector(Checksum, SectorPtr);
|
---|
| 1427 | SectorPtr += BYTES_PER_SECTOR;
|
---|
| 1428 | SectorCount--;
|
---|
[29] | 1429 | }
|
---|
[46] | 1430 | *(PUSHORT)&Bootcode[54 * BYTES_PER_SECTOR + 20] = Checksum;
|
---|
[29] | 1431 |
|
---|
[46] | 1432 | // Copy configuration sectors
|
---|
| 1433 | // Rousseau: Two more sectors for extended version.
|
---|
| 1434 | switch (IMAGE_SIZE) {
|
---|
| 1435 | case IMAGE_SIZE_60SECS: {
|
---|
| 1436 | memcpy(&Track0[54 * BYTES_PER_SECTOR], &Bootcode[54 * BYTES_PER_SECTOR], 6 * BYTES_PER_SECTOR);
|
---|
| 1437 | break;
|
---|
| 1438 | }
|
---|
| 1439 | case IMAGE_SIZE_62SECS: {
|
---|
| 1440 | memcpy(&Track0[54 * BYTES_PER_SECTOR], &Bootcode[54 * BYTES_PER_SECTOR], 8 * BYTES_PER_SECTOR);
|
---|
| 1441 | break;
|
---|
| 1442 | }
|
---|
| 1443 | }
|
---|
[29] | 1444 |
|
---|
[46] | 1445 | return;
|
---|
| 1446 | }
|
---|
| 1447 |
|
---|
| 1448 |
|
---|
[48] | 1449 | void DumpTrack0() {
|
---|
| 1450 | int i,j;
|
---|
| 1451 | for (i=27; i<32; i++) {
|
---|
| 1452 | for (j=0; j<16; j++) {
|
---|
| 1453 | printf("%02X",Track0[i*16+j]);
|
---|
| 1454 | }
|
---|
| 1455 | printf("\n");
|
---|
| 1456 | }
|
---|
| 1457 | }
|
---|
[46] | 1458 |
|
---|
[48] | 1459 |
|
---|
| 1460 |
|
---|
| 1461 |
|
---|
[47] | 1462 | void DoDebug() {
|
---|
| 1463 | USHORT t0codv = 0;
|
---|
| 1464 | USHORT t0cfgv = 0;
|
---|
| 1465 | USHORT bccodv = 0;
|
---|
| 1466 | USHORT bccfgv = 0;
|
---|
[46] | 1467 |
|
---|
[47] | 1468 | //do_bf_test();
|
---|
[46] | 1469 |
|
---|
[47] | 1470 | printf("\nHardisks : %d\n", CountHarddrives());
|
---|
| 1471 | printf("\nGEO : %d\n", HarddriveCheckGeometry());
|
---|
| 1472 | printf("\nTrack0 : %d\n", Track0Load());
|
---|
| 1473 | printf("\nBootcode : %d\n", LoadBootcodeFromFile());
|
---|
[46] | 1474 |
|
---|
[47] | 1475 |
|
---|
| 1476 | // Dump Track0
|
---|
[48] | 1477 | DumpTrack0();
|
---|
[47] | 1478 | printf("\n\n");
|
---|
| 1479 | // Dump Bootcode
|
---|
[48] | 1480 | //~ {
|
---|
| 1481 | //~ int i;
|
---|
| 1482 | //~ for (i=0; i<512; i++) {
|
---|
| 1483 | //~ printf("%02X",Bootcode[i]);
|
---|
| 1484 | //~ }
|
---|
| 1485 | //~ }
|
---|
| 1486 | //~ printf("\n\n");
|
---|
[47] | 1487 |
|
---|
| 1488 | t0codv = Track0[13] << 8 | Track0[14];
|
---|
| 1489 | printf("t0codv : %04X\n", t0codv);
|
---|
| 1490 |
|
---|
| 1491 | t0cfgv = Track0[0x6c00+13] << 8 | Track0[0x6c00+14];
|
---|
| 1492 | printf("t0cfgv : %04X\n", t0cfgv);
|
---|
| 1493 |
|
---|
| 1494 | bccodv = Bootcode[13] << 8 | Bootcode[14];
|
---|
| 1495 | printf("bccodv : %04X\n", bccodv);
|
---|
| 1496 |
|
---|
| 1497 | bccfgv = Bootcode[0x6c00+13] << 8 | Bootcode[0x6c00+14];
|
---|
| 1498 | printf("bccfgv : %04X\n", bccfgv);
|
---|
| 1499 |
|
---|
| 1500 | return;
|
---|
| 1501 |
|
---|
| 1502 | }
|
---|
| 1503 |
|
---|
| 1504 |
|
---|
[46] | 1505 | // ============================================================================
|
---|
| 1506 | // Main Entrypoint
|
---|
| 1507 | // ============================================================================
|
---|
| 1508 |
|
---|
| 1509 |
|
---|
| 1510 |
|
---|
[29] | 1511 | #define MAXCMDPARMLEN 11
|
---|
| 1512 |
|
---|
| 1513 | int main (int argc, char **argv) {
|
---|
[46] | 1514 | ULONG CurArgument = 0;
|
---|
| 1515 | size_t ArgumentLen = 0;
|
---|
| 1516 | PCHAR StartPos = 0;
|
---|
| 1517 | UCHAR UserKey = ' ';
|
---|
| 1518 | BOOL ExitOnly = FALSE;
|
---|
| 1519 | CHAR TempSpace[MAXCMDPARMLEN+1];
|
---|
[29] | 1520 |
|
---|
[46] | 1521 |
|
---|
[48] | 1522 | // Check commandline parameters
|
---|
| 1523 | CurArgument = 1;
|
---|
| 1524 | while (CurArgument<argc) {
|
---|
| 1525 | StartPos = argv[CurArgument];
|
---|
| 1526 | ArgumentLen = strlen(StartPos);
|
---|
| 1527 |
|
---|
| 1528 | if (((*StartPos=='-') || (*StartPos=='/')) && (ArgumentLen>1)) {
|
---|
| 1529 | StartPos++; ArgumentLen--;
|
---|
| 1530 | if (ArgumentLen>MAXCMDPARMLEN)
|
---|
| 1531 | ArgumentLen = MAXCMDPARMLEN;
|
---|
| 1532 | strncpy((char *) TempSpace, StartPos, ArgumentLen);
|
---|
| 1533 | TempSpace[ArgumentLen] = 0;
|
---|
| 1534 | StartPos = (PCHAR) TempSpace;
|
---|
| 1535 | while (*StartPos!=0) {
|
---|
| 1536 | *StartPos = tolower(*StartPos); StartPos++;
|
---|
| 1537 | }
|
---|
| 1538 | if (strcmp((char *) TempSpace, "forcecode")==0) Option_ForceCode = TRUE;
|
---|
| 1539 | if (strcmp((char *) TempSpace, "forceconfig")==0) Option_ForceConfig = TRUE;
|
---|
| 1540 | if (strcmp((char *) TempSpace, "silent")==0) Option_Silent = TRUE;
|
---|
| 1541 | if (strcmp((char *) TempSpace, "cid")==0) Option_CID = TRUE;
|
---|
| 1542 | }
|
---|
| 1543 | CurArgument++;
|
---|
| 1544 | }
|
---|
| 1545 |
|
---|
| 1546 |
|
---|
| 1547 | // Only support /cid on OS/2 for the moment.
|
---|
| 1548 | // The DOS code behaves quirky with /cid and Win32 is not tested at all.
|
---|
| 1549 | #ifndef PLATFORM_OS2
|
---|
| 1550 | Option_CID = FALSE;
|
---|
| 1551 | #endif
|
---|
| 1552 |
|
---|
| 1553 | if (Option_CID) {
|
---|
| 1554 | Option_Silent = TRUE;
|
---|
| 1555 | }
|
---|
| 1556 |
|
---|
| 1557 |
|
---|
[47] | 1558 | // Show header.
|
---|
| 1559 | if (!Option_CID) {
|
---|
| 1560 | printf("AiR-BOOT Installer v%s.%s.%s for %s\n",
|
---|
| 1561 | BLDLVL_MAJOR_VERSION,
|
---|
| 1562 | BLDLVL_MIDDLE_VERSION,
|
---|
| 1563 | BLDLVL_MINOR_VERSION,
|
---|
| 1564 | PLATFORM_NAME);
|
---|
| 1565 | printf(" - (c) Copyright 1998-2012 by Martin Kiewitz.\n");
|
---|
| 1566 | printf("\n-> ...Please wait... <-\n");
|
---|
| 1567 | }
|
---|
[46] | 1568 |
|
---|
[48] | 1569 |
|
---|
[60] | 1570 | // Allocate buffers for Track0 and 'airboot.bin'.
|
---|
[46] | 1571 | Track0 = malloc(SECTOR_COUNT * BYTES_PER_SECTOR);
|
---|
| 1572 | Bootcode = malloc(SECTOR_COUNT * BYTES_PER_SECTOR);
|
---|
[29] | 1573 |
|
---|
[48] | 1574 |
|
---|
[46] | 1575 | // Exit of allocation failed.
|
---|
| 1576 | if (!(Track0 && Bootcode)) {
|
---|
| 1577 | if (!Option_CID) {
|
---|
| 1578 | printf("- Unable to allocate enough memory, operation aborted!\n");
|
---|
| 1579 | }
|
---|
| 1580 | exit(4);
|
---|
[29] | 1581 | }
|
---|
| 1582 |
|
---|
[30] | 1583 |
|
---|
[47] | 1584 | //~ DoDebug();
|
---|
| 1585 | //~ exit(0);
|
---|
[29] | 1586 |
|
---|
| 1587 |
|
---|
[46] | 1588 | #ifdef PLATFORM_WINNT
|
---|
| 1589 | if (CheckWindowsVersion()==FALSE)
|
---|
| 1590 | return 1;
|
---|
| 1591 | #endif
|
---|
| 1592 |
|
---|
| 1593 | if (CountHarddrives()==0) {
|
---|
| 1594 | if (!Option_CID) {
|
---|
| 1595 | printf(" - No physical drives found on this system. Install impossible.\n");
|
---|
| 1596 | }
|
---|
| 1597 | return 3; // Rouseau: changed from 1 to 3
|
---|
[29] | 1598 | }
|
---|
| 1599 |
|
---|
[46] | 1600 | if (!Option_CID) {
|
---|
| 1601 | printf(" - Loading bootcode from file...");
|
---|
| 1602 | }
|
---|
[29] | 1603 |
|
---|
[46] | 1604 | if (LoadBootcodeFromFile()==FALSE)
|
---|
| 1605 | return 1;
|
---|
[29] | 1606 |
|
---|
[46] | 1607 | if (!Option_CID) {
|
---|
| 1608 | printf("ok\n");
|
---|
| 1609 | }
|
---|
[30] | 1610 |
|
---|
[46] | 1611 | if (!Option_CID) {
|
---|
| 1612 | printf(" - Loading MBR from harddisc...");
|
---|
| 1613 | }
|
---|
[48] | 1614 |
|
---|
| 1615 |
|
---|
| 1616 | if (!Track0Load()) {
|
---|
| 1617 | if (!Option_CID) {
|
---|
| 1618 | printf("LOAD ERROR!\n");
|
---|
[46] | 1619 | }
|
---|
[48] | 1620 | return 1;
|
---|
[46] | 1621 | }
|
---|
| 1622 | else {
|
---|
[48] | 1623 | if (!Option_CID) {
|
---|
| 1624 | printf("ok\n");
|
---|
[46] | 1625 | }
|
---|
| 1626 | }
|
---|
| 1627 |
|
---|
[48] | 1628 | if (!HarddriveCheckGeometry()) {
|
---|
| 1629 | // No EZ-SETUP check here, because we are under 32-bit OS and this
|
---|
| 1630 | // wouldn't make any sense
|
---|
| 1631 | //printf("\nDEBUG: STATUS_IMPOSSIBLE\n");
|
---|
| 1632 | Status_Code = STATUS_IMPOSSIBLE;
|
---|
| 1633 | ImpossibleCause = "unable to install\n Your harddisc does not have at least 63 sectors per track.";
|
---|
[46] | 1634 | }
|
---|
| 1635 |
|
---|
| 1636 |
|
---|
| 1637 | if (!Option_CID) {
|
---|
| 1638 | printf("\n-> ...Current Status... <-\n");
|
---|
| 1639 | }
|
---|
| 1640 |
|
---|
| 1641 | Status_CheckCode();
|
---|
| 1642 | if (!Option_CID) {
|
---|
| 1643 | printf(" - AiR-BOOT is ");
|
---|
| 1644 | }
|
---|
| 1645 | Status_PrintF(Status_Code, Installed_CodeVersion);
|
---|
[48] | 1646 | if (Status_Code==STATUS_IMPOSSIBLE)
|
---|
[46] | 1647 | return 1;
|
---|
| 1648 | Status_CheckConfig();
|
---|
| 1649 | if (!Option_CID) {
|
---|
| 1650 | printf(" - Configuration is ");
|
---|
| 1651 | }
|
---|
| 1652 | Status_PrintF(Status_Config, Installed_ConfigVersion);
|
---|
| 1653 | // Display language as well, if code installed
|
---|
| 1654 | if ((Status_Code==STATUS_INSTALLED) || (Status_Code==STATUS_INSTALLEDMGU)) {
|
---|
| 1655 | if (!Option_CID) {
|
---|
| 1656 | printf(" - Language is ");
|
---|
| 1657 | }
|
---|
| 1658 | Language_PrintF(Installed_LanguageID);
|
---|
| 1659 | if (!Option_CID) {
|
---|
| 1660 | printf("\n");
|
---|
| 1661 | }
|
---|
| 1662 | }
|
---|
| 1663 |
|
---|
| 1664 | // =============================================================
|
---|
| 1665 | // PRE-CHECKING, WHAT WE ARE SUPPOSED TO DO...
|
---|
| 1666 | // =============================================================
|
---|
| 1667 | if ((Option_ForceCode) || (Status_Code!=STATUS_INSTALLED) || (Installed_LanguageID!=Bootcode_LanguageID))
|
---|
| 1668 | Install_Code = TRUE; // If LanguageID different or not installed
|
---|
| 1669 | if ((Option_ForceConfig) || (Status_Config!=STATUS_INSTALLED))
|
---|
| 1670 | Install_Config = TRUE; // If not installed
|
---|
| 1671 |
|
---|
| 1672 | if ((Status_Code==STATUS_CORRUPT) || (Status_Config==STATUS_CORRUPT))
|
---|
| 1673 | Install_IsCorrupt = TRUE; // If anything is corrupt
|
---|
| 1674 |
|
---|
| 1675 | // =============================================================
|
---|
| 1676 | // VIRUS
|
---|
| 1677 | // =============================================================
|
---|
| 1678 | // If-Table
|
---|
| 1679 | // ---------
|
---|
| 1680 | // Code==not installed, Config=not installed -> Check MBR
|
---|
| 1681 | // Code==installed, config==installed -> Check MBR (-> Virus?)
|
---|
| 1682 | // Code==not installed, config==installed -> (-> Virus?)
|
---|
| 1683 | // Code==installed, config==not installed -> Check MBR (-> Virus?)
|
---|
| 1684 |
|
---|
| 1685 | //printf("DEBUG: Status_Code: %d, Status_Config: %d\n", Status_Code, Status_Config); // Rousseau: DEBUG
|
---|
| 1686 |
|
---|
| 1687 | if ((Status_Code==STATUS_NOTINSTALLED) & (Status_Config==STATUS_NOTINSTALLED)) {
|
---|
| 1688 | // Nothing installed, so check MBR, if squashed...
|
---|
| 1689 | if (!Virus_CheckCurrentMBR()) {
|
---|
[30] | 1690 | if (!Option_CID) {
|
---|
[46] | 1691 | printf("\n\n");
|
---|
| 1692 | printf("AiR-BOOT detected that the data on your harddisc got damaged.\n");
|
---|
| 1693 | printf("If you had AiR-BOOT installed before: the corruption killed AiR-BOOT completly!\n");
|
---|
| 1694 | printf("Installation halted.\n");
|
---|
[30] | 1695 | }
|
---|
[46] | 1696 | return 255; // Rousseau: changed from 1 to 255
|
---|
| 1697 | }
|
---|
| 1698 | //printf("DEBUG: Installing...\n"); // Rousseau: DEBUG
|
---|
| 1699 | }
|
---|
| 1700 | else {
|
---|
| 1701 | if ((Status_Code==STATUS_NOTINSTALLED) | (!Virus_CheckCurrentMBR())) {
|
---|
| 1702 | // Code not installed, but Config or MBR squashed...
|
---|
| 1703 | // -> Virus proposed, check for backup (if available)
|
---|
[30] | 1704 | if (!Option_CID) {
|
---|
[46] | 1705 | printf("\n\n");
|
---|
| 1706 | printf("-> ...!ATTENTION!... <-\n");
|
---|
[30] | 1707 | }
|
---|
[46] | 1708 | if (Virus_CheckForStealth())
|
---|
[30] | 1709 | if (!Option_CID) {
|
---|
[46] | 1710 | printf("Your system GOT infected by a stealth-virus (or your MBR got trashed).\n");
|
---|
| 1711 | }
|
---|
| 1712 | else
|
---|
| 1713 | if (!Option_CID) {
|
---|
| 1714 | printf("Probably your system was infected by a virus.\n");
|
---|
| 1715 | printf("Repairing AiR-BOOT will normally squash the virus.\n");
|
---|
| 1716 | printf("But to be sure it's gone, you should check your harddisc using a virus-scanner.\n");
|
---|
| 1717 | }
|
---|
| 1718 |
|
---|
| 1719 | if (!Virus_CheckCurrentMBR()) {
|
---|
| 1720 | // MBR squashed, so check backup and display message
|
---|
| 1721 | if (!Option_CID) {
|
---|
| 1722 | printf("\n");
|
---|
| 1723 | printf("AiR-BOOT detected that the virus has broken your partition-table.\n");
|
---|
| 1724 | }
|
---|
| 1725 | if (Virus_CheckForBackUpMBR()) {
|
---|
| 1726 | if (!Option_CID) {
|
---|
| 1727 | printf("Good news: AiR-BOOT has found a (hopefully) functional backup.\n");
|
---|
| 1728 | printf("Shall I use this backup, instead of the current active one? (Y/N)\n");
|
---|
| 1729 | }
|
---|
| 1730 | // User selection, Y/N, if he wants to restore MBR
|
---|
| 1731 | // *NOT* CID (silent) able
|
---|
| 1732 | do {
|
---|
| 1733 | UserKey = getch() | 0x20;
|
---|
| 1734 | } while (!((UserKey=='y') | (UserKey=='n')));
|
---|
| 1735 | if (UserKey=='y')
|
---|
| 1736 | Virus_CopyBackUpMBR();
|
---|
| 1737 | }
|
---|
| 1738 | else {
|
---|
| 1739 | if (!Option_CID) {
|
---|
| 1740 | printf("Sadly the virus also broke AiR-BOOT's backup. You will have to help yourself.\n");
|
---|
| 1741 | }
|
---|
| 1742 | }
|
---|
| 1743 | }
|
---|
| 1744 | }
|
---|
[29] | 1745 | }
|
---|
| 1746 |
|
---|
| 1747 |
|
---|
| 1748 |
|
---|
[46] | 1749 | // =============================================================
|
---|
| 1750 | // MAIN-MENU
|
---|
| 1751 | // =============================================================
|
---|
| 1752 | if (!Option_CID) {
|
---|
| 1753 | printf("\n-> ...Please press... <-\n");
|
---|
| 1754 | }
|
---|
[29] | 1755 |
|
---|
[46] | 1756 | if (!Option_CID) {
|
---|
| 1757 | if (Install_IsCorrupt)
|
---|
| 1758 | printf(" <R> - Repair AiR-BOOT ");
|
---|
| 1759 | else
|
---|
| 1760 | if (Status_Code==STATUS_NOTINSTALLED)
|
---|
| 1761 | printf(" <A> - Add AiR-BOOT ");
|
---|
| 1762 | else
|
---|
| 1763 | printf(" <U> - Update/Change AiR-BOOT to ");
|
---|
| 1764 |
|
---|
| 1765 | printf("'v%x.%1d.%1d/", Bootcode_Version>>8, (Bootcode_Version & 0x0F0)>>4, Bootcode_Version & 0x0F);
|
---|
| 1766 | Language_PrintF(Bootcode_LanguageID);
|
---|
| 1767 | printf("' on current system\n");
|
---|
| 1768 |
|
---|
| 1769 | printf(" <D> - Delete AiR-BOOT from current system\n");
|
---|
| 1770 | printf(" <Q> - Quit without any change\n");
|
---|
[29] | 1771 | }
|
---|
| 1772 |
|
---|
[48] | 1773 |
|
---|
| 1774 |
|
---|
[46] | 1775 | if (Option_Silent || Option_CID) {
|
---|
| 1776 | // Silent operation? Always add AiR-BOOT then
|
---|
| 1777 | UserKey = 'a';
|
---|
| 1778 | }
|
---|
| 1779 | else {
|
---|
| 1780 | do {
|
---|
| 1781 | UserKey = getch() | 0x20;
|
---|
| 1782 | } while (!((UserKey=='a') || (UserKey=='r') || (UserKey=='u') || (UserKey=='d') || (UserKey=='q')));
|
---|
| 1783 | }
|
---|
| 1784 |
|
---|
| 1785 | if (!Option_CID) {
|
---|
| 1786 | printf("\n\n\n-------------------------------------------------------------------------------\n");
|
---|
| 1787 | }
|
---|
| 1788 |
|
---|
| 1789 | switch (UserKey) {
|
---|
| 1790 | case 'a':
|
---|
| 1791 | case 'r':
|
---|
| 1792 | case 'u': {
|
---|
| 1793 | if (Install_Code || Install_Config) {
|
---|
| 1794 | if (!Option_CID) {
|
---|
| 1795 | printf("Add/Repair/Update AiR-BOOT in progress...\n");
|
---|
| 1796 | }
|
---|
| 1797 | #ifdef PLATFORM_OS2
|
---|
| 1798 | OS2_GetBootAutoDriveLetter();
|
---|
| 1799 | #endif
|
---|
| 1800 | if (Install_Code) {
|
---|
| 1801 | if (!Option_CID) {
|
---|
[238] | 1802 | printf(" \xfe Writing AiR-BOOT code...");
|
---|
[46] | 1803 | }
|
---|
[48] | 1804 | //~ DumpTrack0();
|
---|
[46] | 1805 | Install_WriteCode();
|
---|
[48] | 1806 | //~ DumpTrack0();
|
---|
[46] | 1807 | if (!Option_CID) {
|
---|
| 1808 | printf("ok\n");
|
---|
| 1809 | }
|
---|
| 1810 | }
|
---|
| 1811 | if (Install_Config) {
|
---|
| 1812 | if (!Option_CID) {
|
---|
[238] | 1813 | printf(" \xfe Writing AiR-BOOT configuration...");
|
---|
[46] | 1814 | }
|
---|
| 1815 | Install_WriteConfig();
|
---|
| 1816 | if (!Option_CID) {
|
---|
| 1817 | printf("ok\n");
|
---|
| 1818 | }
|
---|
| 1819 | }
|
---|
| 1820 |
|
---|
[48] | 1821 |
|
---|
[46] | 1822 | if (!Track0Write()) {
|
---|
| 1823 | if (!Option_CID) {
|
---|
| 1824 | printf("SAVE ERROR!\n");
|
---|
| 1825 | }
|
---|
| 1826 | return 1;
|
---|
| 1827 | }
|
---|
[48] | 1828 |
|
---|
[46] | 1829 | if (!Option_CID) {
|
---|
| 1830 | printf("\n");
|
---|
| 1831 | printf("Your copy of AiR-BOOT is now fully functional.\n");
|
---|
| 1832 | if (!Option_Silent) {
|
---|
| 1833 | printf("Please hit ESC to exit AiR-BOOT installer or ENTER to reboot your system...\n");
|
---|
| 1834 | }
|
---|
| 1835 | }
|
---|
| 1836 | if (Option_Silent || Option_CID) {
|
---|
| 1837 | // Silent operation? Always reboot system (shall we do this really?)
|
---|
| 1838 | // No, otherwise installing from MiniLVM will reboot the system
|
---|
| 1839 | // which is not what the user would expect.
|
---|
| 1840 | //UserKey = 0x0D;
|
---|
| 1841 | UserKey = 0x1B;
|
---|
| 1842 | }
|
---|
| 1843 | else {
|
---|
| 1844 | do {
|
---|
| 1845 | UserKey = getch(); // React on ENTER or ESC
|
---|
| 1846 | } while (!((UserKey==0x0D) || (UserKey==0x1B)));
|
---|
| 1847 | }
|
---|
[67] | 1848 | if (UserKey==0x0D) { // ENTER reboots system... (if not in OS/2 install mode)
|
---|
[46] | 1849 |
|
---|
| 1850 | /*
|
---|
| 1851 | // Rousseau: ## Disable Reboot when installing eComStation ##
|
---|
| 1852 | // In the install-environment, the MEMDRIVE env-var is defined.
|
---|
| 1853 | // So, only reboot if this env-var is not defined.
|
---|
| 1854 | */
|
---|
| 1855 | if (!getenv("MEMDRIVE")) {
|
---|
| 1856 | if (!Option_CID) {
|
---|
| 1857 | printf("Now rebooting system...\n");
|
---|
| 1858 | }
|
---|
| 1859 | RebootSystem();
|
---|
| 1860 | }
|
---|
| 1861 | ExitOnly = TRUE;
|
---|
| 1862 | }
|
---|
[30] | 1863 | }
|
---|
[46] | 1864 | else {
|
---|
| 1865 | if (!Option_CID) {
|
---|
[238] | 1866 | printf(" \xfe All components of AiR-BOOT are intact and up-to-date. Nothing to do.\n");
|
---|
[46] | 1867 | }
|
---|
| 1868 | ExitOnly = TRUE;
|
---|
[30] | 1869 | }
|
---|
[46] | 1870 | break;
|
---|
| 1871 | }
|
---|
| 1872 | case 'd': {
|
---|
[30] | 1873 | if (!Option_CID) {
|
---|
[238] | 1874 | printf(" \xfe Removing AiR-BOOT automatically is not possible at this time.\n");
|
---|
[30] | 1875 | }
|
---|
[46] | 1876 | #ifdef PLATFORM_OS2
|
---|
[30] | 1877 | if (!Option_CID) {
|
---|
[46] | 1878 | printf(" You may remove AiR-BOOT manually by entering \"FDISK /MBR\" or \"LVM /NEWMBR:1\"\n");
|
---|
| 1879 | printf(" in commandline.\n");
|
---|
[30] | 1880 | }
|
---|
[46] | 1881 | #endif
|
---|
| 1882 | #ifdef PLATFORM_WINNT
|
---|
[30] | 1883 | if (!Option_CID) {
|
---|
[46] | 1884 | printf(" You may remove AiR-BOOT manually by entering \"FDISK /MBR\" in commandline.\n");
|
---|
[30] | 1885 | }
|
---|
[46] | 1886 | #endif
|
---|
[30] | 1887 | ExitOnly = TRUE;
|
---|
[46] | 1888 | break;
|
---|
[29] | 1889 | }
|
---|
[46] | 1890 | default:
|
---|
| 1891 | break;
|
---|
[29] | 1892 | }
|
---|
| 1893 |
|
---|
[36] | 1894 | if (ExitOnly) {
|
---|
| 1895 | if (!(Option_CID || Option_Silent)) {
|
---|
| 1896 | printf("\n");
|
---|
| 1897 | printf("Please hit ENTER to exit AiR-BOOT installer...\n");
|
---|
| 1898 | while (getch()!=0x0D);
|
---|
| 1899 | }
|
---|
[29] | 1900 | }
|
---|
[46] | 1901 |
|
---|
| 1902 | // Free the buffer memory.
|
---|
| 1903 | if (Track0) free(Track0);
|
---|
| 1904 | if (Bootcode) free(Bootcode);
|
---|
| 1905 |
|
---|
[29] | 1906 | return 0;
|
---|
[46] | 1907 | }
|
---|