Skip to content

Commit f9af74b

Browse files
committed
[FREELDR] Adapt the bootsectors for the future base address change (reactos#7785)
1 parent afb96ac commit f9af74b

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

boot/freeldr/bootsect/btrfs.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ FreeLdrFound:
386386
//mov dh, 0 // Load boot partition into DH (not needed, FreeLbr detects it itself)
387387

388388
/* Transfer execution to the bootloader */
389-
ljmp16 0, FREELDR_BASE
389+
ljmp16 FREELDR_BASE / 16, 0
390390

391391

392392
// Insert chunk into chunk map (located at DS:[CHUNK_MAP_OFFSET])

boot/freeldr/bootsect/fat.S

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ DataAreaStartLow = 4
4848
BiosCHSDriveSizeHigh = 6
4949
BiosCHSDriveSizeLow = 8
5050
BiosCHSDriveSize = 8
51-
ReadSectorsOffset = 10
52-
ReadClusterOffset = 12
53-
PutCharsOffset = 14
54-
BootSectorStackTop = HEX(7c00) - 16
51+
ReadSectorsOffset = 12
52+
ReadClusterOffset = 16
53+
PutCharsOffset = 20
54+
BootSectorStackTop = HEX(7c00) - 22
5555

5656

5757
// org 7c00h
@@ -218,17 +218,22 @@ FoundFreeLoader:
218218

219219
// Save the addresses of needed functions so
220220
// the helper code will know where to call them.
221-
mov word ptr [bp-ReadSectorsOffset], offset ReadSectors // Save the address of ReadSectors
222-
mov word ptr [bp-ReadClusterOffset], offset ReadCluster // Save the address of ReadCluster
223-
mov word ptr [bp-PutCharsOffset], offset PutChars // Save the address of PutChars
221+
xor bx, bx
222+
mov word ptr [bp-(ReadSectorsOffset-2)], bx // Save the segment of ReadSectors
223+
mov word ptr [bp-(ReadClusterOffset-2)], bx // Save the segment of ReadCluster
224+
mov word ptr [bp-(PutCharsOffset-2)], bx // Save the segment of PutChars
225+
mov word ptr [bp-ReadSectorsOffset], offset ReadSectors // Save the address of ReadSectors
226+
mov word ptr [bp-ReadClusterOffset], offset ReadCluster // Save the address of ReadCluster
227+
mov word ptr [bp-PutCharsOffset], offset PutChars // Save the address of PutChars
228+
mov byte ptr [PatchedRet], HEX(CB) // Patch 'ret' with 'retf'
224229

225230
// Now AX has start cluster of FreeLoader and we
226231
// have loaded the helper code in the first 512 bytes
227232
// of FreeLoader to 0000:F800. Now transfer control
228233
// to the helper code. Skip the first three bytes
229234
// because they contain a jump instruction to skip
230235
// over the helper code in the FreeLoader image.
231-
ljmp16 0, FREELDR_BASE + 3
236+
ljmp16 FREELDR_BASE / 16, 3
232237

233238

234239

@@ -249,13 +254,11 @@ Reboot:
249254
PutChars:
250255
lodsb
251256
or al,al
252-
jz short Done
257+
jz PatchedRet
253258
mov ah, HEX(0e)
254259
mov bx, 7
255260
int HEX(10)
256261
jmp short PutChars
257-
Done:
258-
ret
259262

260263
// Displays a bad boot message
261264
// And reboots
@@ -265,7 +268,6 @@ BadBoot:
265268

266269
jmp short Reboot
267270

268-
269271
// Reads cluster number in AX into [ES:0000]
270272
ReadCluster:
271273
// StartSector = ((Cluster - 2) * SectorsPerCluster) + ReservedSectors + HiddenSectors;
@@ -354,7 +356,7 @@ ReadSectorsLBALoop:
354356

355357
loop ReadSectorsLBALoop // Read next sector
356358

357-
ret
359+
jmp PatchedRet
358360

359361

360362
// Reads logical sectors into [ES:BX]
@@ -403,11 +405,12 @@ NoCarryCHS:
403405
// Increment read buffer for next sector
404406
loop ReadSectorsCHSLoop // Read next sector
405407

408+
PatchedRet:
406409
ret
407410

408-
409411
msgDiskError:
410-
.ascii "Disk error", CR, LF, NUL
412+
// .ascii "Disk error", CR, LF, NUL
413+
.ascii "ERR", CR, LF, NUL
411414
msgFreeLdr:
412415
.ascii "Ldr not found", CR, LF, NUL
413416
// Sorry, need the space...

boot/freeldr/bootsect/fat32.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ LoadFileDone:
425425
mov dh, byte ptr ds:[BootPartition] // Load boot partition into DH
426426

427427
/* Transfer execution to the bootloader */
428-
ljmp16 0, FREELDR_BASE
428+
ljmp16 FREELDR_BASE / 16, 0
429429

430430
// Returns the FAT entry for a given cluster number
431431
// On entry EAX has cluster number

boot/freeldr/bootsect/faty.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ main:
400400

401401
/* Now the complete freeldr imag is loaded.
402402
Jump to the realmode entry point. */
403-
ljmp16 0, FREELDR_BASE
403+
ljmp16 FREELDR_BASE / 16, 0
404404

405405

406406

boot/freeldr/bootsect/isoboot.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ found_drive:
303303

304304
.jump_to_freeldr:
305305
// Transfer execution to the bootloader.
306-
ljmp16 0, FREELDR_BASE
306+
ljmp16 FREELDR_BASE / 16, 0
307307

308308

309309
/* FUNCTIONS *****************************************************************/

boot/freeldr/bootsect/ntfs.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ StartSearch:
417417

418418
mov dl, byte ptr [BootDrive]
419419
mov dh, byte ptr [BootPartition]
420-
ljmp16 0, FREELDR_BASE
420+
ljmp16 FREELDR_BASE / 16, 0
421421

422422
// Error message if Freeldr is compressed, encrypted or sparse
423423
CompressedFreeldr:

boot/freeldr/bootsect/pc98/fat12fdd.S

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ DataAreaStartLow = 4
2525
BiosCHSDriveSizeHigh = 6
2626
BiosCHSDriveSizeLow = 8
2727
BiosCHSDriveSize = 8
28-
ReadSectorsOffset = 10
29-
ReadClusterOffset = 12
30-
PutCharsOffset = 14
31-
BootSectorStackTop = HEX(7C00) - 16
28+
ReadSectorsOffset = 12
29+
ReadClusterOffset = 16
30+
PutCharsOffset = 20
31+
BootSectorStackTop = HEX(7C00) - 22
3232

3333
if 0
3434
.macro DEBUG_STOP
@@ -244,9 +244,14 @@ FoundFreeLoader:
244244
* Save the addresses of needed functions so
245245
* the helper code will know where to call them
246246
*/
247-
mov word ptr [bp - ReadSectorsOffset], offset ReadSectors // Save the address of ReadSectors
248-
mov word ptr [bp - ReadClusterOffset], offset ReadCluster // Save the address of ReadCluster
249-
mov word ptr [bp - PutCharsOffset], offset PrintString // Save the address of PrintString
247+
xor bx, bx
248+
mov word ptr [bp-(ReadSectorsOffset-2)], bx // Save the segment of ReadSectors
249+
mov word ptr [bp-(ReadClusterOffset-2)], bx // Save the segment of ReadCluster
250+
mov word ptr [bp-(PutCharsOffset-2)], bx // Save the segment of PrintString
251+
mov word ptr [bp-ReadSectorsOffset], offset ReadSectors // Save the address of ReadSectors
252+
mov word ptr [bp-ReadClusterOffset], offset ReadCluster // Save the address of ReadCluster
253+
mov word ptr [bp-PutCharsOffset], offset PrintString // Save the address of PrintString
254+
mov byte ptr [PatchedRet], HEX(CB) // Patch 'ret' with 'retf'
250255

251256
/*
252257
* Now AX has start cluster of FreeLoader and we
@@ -256,7 +261,7 @@ FoundFreeLoader:
256261
* because they contain a jump instruction to skip
257262
* over the helper code in the FreeLoader image
258263
*/
259-
ljmp16 0, FREELDR_BASE + 3
264+
ljmp16 FREELDR_BASE / 16, 3
260265

261266
/*
262267
* Reads cluster number in AX into [ES:BX]
@@ -347,7 +352,7 @@ ReadSectors:
347352
pop bx
348353
loop .ReadSectorsLoop // Increment read buffer for next sector, read next sector
349354

350-
ret
355+
jmp PatchedRet
351356

352357
/*
353358
* Prints a character
@@ -385,7 +390,7 @@ PrintString:
385390
lodsb // Get a single char from a ptr
386391

387392
or al, al
388-
jz short .PrintEnd // Found NULL
393+
jz short PatchedRet // Found NULL
389394

390395
cmp al, HEX(0D)
391396
jz short .PrintStringHandleCR // Found CR
@@ -403,7 +408,7 @@ PrintString:
403408
inc si // Skip the next LF character
404409
jmp short PrintString
405410

406-
.PrintEnd:
411+
PatchedRet:
407412
ret
408413

409414
if 0
@@ -479,7 +484,8 @@ msgDiskError:
479484
msgNotFoundError:
480485
.ascii "NFE", CR, LF, NUL
481486
msgAnyKey:
482-
.ascii "Press any key", NUL
487+
// .ascii "Press any key", NUL
488+
.ascii "Press key", NULL
483489
filename:
484490
.ascii "FREELDR SYS"
485491

0 commit comments

Comments
 (0)