%if 0 2019, by C. Masloch Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument. DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. %endif %include "lmacros3.mac" defaulting sectalign off numdef SPI, 2880 ; sectors per image numdef CHS_SECTORS, 63 ; CHS geometry field for sectors numdef CHS_HEADS, 255 ; CHS geometry field for heads numdef MBR, 1 gendef MBR_PART_TYPE, fat12 numdef MBR_GAP_SIZE_SECTORS, (1024 * 1024 * 1024 * 2 * 2 - 1) ptEmpty: equ 0 ptFAT12: equ 1 ptFAT16_16BIT_CHS: equ 4 ptExtendedCHS: equ 5 ptFAT16_CHS: equ 6 ptFAT32_CHS: equ 0Bh ptFAT32: equ 0Ch ptFAT16: equ 0Eh ptExtended: equ 0Fh ptLinux: equ 83h ptExtendedLinux: equ 85h %if _MBR %ifidni _MBR_PART_TYPE, fat12 %assign _MBR_PART_TYPE ptFAT12 %elifidni _MBR_PART_TYPE, fat16_16bit_chs %assign _MBR_PART_TYPE ptFAT16_16BIT_CHS %elifidni _MBR_PART_TYPE, fat16_chs %assign _MBR_PART_TYPE ptFAT16_CHS %elifidni _MBR_PART_TYPE, fat32_chs %assign _MBR_PART_TYPE ptFAT32_CHS %elifidni _MBR_PART_TYPE, fat32 %assign _MBR_PART_TYPE ptFAT32 %elifidni _MBR_PART_TYPE, fat16 %assign _MBR_PART_TYPE ptFAT16 %endif %assign _MBR_PART_TYPE _MBR_PART_TYPE %ifnnum _MBR_PART_TYPE %error Invalid partition type specified %endif %if _MBR_PART_TYPE == 0 %error Invalid partition type specified %endif %endif struc PARTINFO_CHS_TUPLE pictHead: resb 1 pictSectorLow6: pictCylinderHigh2: resb 1 pictCylinderLow8: resb 1 endstruc %macro chs_tuple 1.nolist %assign %%sector (%1) % _CHS_SECTORS %assign %%i (%1) / _CHS_SECTORS %assign %%head %%i % _CHS_HEADS %assign %%cylinder %%i / _CHS_HEADS %if %%cylinder >= 1024 %assign %%cylinder 1023 %endif istruc PARTINFO_CHS_TUPLE at pictHead, db %%head at pictSectorLow6 at pictCylinderHigh2, db (%%sector + 1) | ((%%cylinder >> (8 - 6)) & 0C0h) at pictCylinderLow8, db (%%cylinder & 0FFh) iend %endmacro struc PARTINFO piBoot: resb 1 piStartCHS: resb 3 ; PARTINFO_CHS_TUPLE piType: resb 1 piEndCHS: resb 3 ; PARTINFO_CHS_TUPLE piStart: resd 1 piLength: resd 1 endstruc %define STARTSFOLLOWS start=0 %if _MBR CYLINDERS equ (_MBR_GAP_SIZE_SECTORS + _SPI + _CHS_HEADS * _CHS_SECTORS - 1) \ / (_CHS_HEADS * _CHS_SECTORS) addsection mbr, STARTSFOLLOWS vstart=7C00h %define STARTSFOLLOWS follows=mbr mbr_start: cli cld xor ax, ax mov es, ax mov ds, ax mov ss, ax mov sp, 7C00h sti mov si, mbr_message @@: lodsb test al, al jz @F mov ah, 0Eh mov bh, [462h] mov bl, 7 int 10h jmp @B @@: xor ax, ax int 13h xor ax, ax int 16h int 19h mbr_message: db "Unable to boot, MBR loader not written.",13,10 db 13,10 db "Press any key to reboot.",13,10 db 0 times (512 - 2 - 4 * 16) - ($ - $$) db 0 %assign TOTAL_MBR_SECTORS CYLINDERS * _CHS_HEADS * _CHS_SECTORS mbr_partition_table: istruc PARTINFO at piBoot, db 80h ; active primary partition at piStartCHS chs_tuple _MBR_GAP_SIZE_SECTORS at piType, db _MBR_PART_TYPE at piEndCHS chs_tuple (TOTAL_MBR_SECTORS - 1) at piStart, dd _MBR_GAP_SIZE_SECTORS at piLength, dd TOTAL_MBR_SECTORS - _MBR_GAP_SIZE_SECTORS iend times (512 - 2) - ($ - $$) db 0 mbr_signature: dw 0AA55h %endif