%if 0

lDebug iniload/boot interfacing structs and macros

Copyright (C) 2008-2025 E. 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


	struc BS
bsJump:	resb 3
bsOEM:	resb 8
bsBPB:
	endstruc

	struc EBPB		;        BPB sec
bpbBytesPerSector:	resw 1	; offset 00h 0Bh
bpbSectorsPerCluster:	resb 1	; offset 02h 0Dh
bpbReservedSectors:	resw 1	; offset 03h 0Eh
bpbNumFATs:		resb 1	; offset 05h 10h
bpbNumRootDirEnts:	resw 1	; offset 06h 11h -- 0 for FAT32
bpbTotalSectors:	resw 1	; offset 08h 13h
bpbMediaID:		resb 1	; offset 0Ah 15h
bpbSectorsPerFAT:	resw 1	; offset 0Bh 16h -- 0 for FAT32
bpbCHSSectors:		resw 1	; offset 0Dh 18h
bpbCHSHeads:		resw 1	; offset 0Fh 1Ah
bpbHiddenSectors:	resd 1	; offset 11h 1Ch
bpbTotalSectorsLarge:	resd 1	; offset 15h 20h
bpbNew:				; offset 19h 24h

ebpbSectorsPerFATLarge:	resd 1	; offset 19h 24h
ebpbFSFlags:		resw 1	; offset 1Dh 28h
ebpbFSVersion:		resw 1	; offset 1Fh 2Ah
ebpbRootCluster:	resd 1	; offset 21h 2Ch
ebpbFSINFOSector:	resw 1	; offset 25h 30h
ebpbBackupSector:	resw 1	; offset 27h 32h
ebpbReserved:		resb 12	; offset 29h 34h
ebpbNew:			; offset 35h 40h
	endstruc

	struc BPBN		; ofs B16 S16 B32 S32
bpbnBootUnit:		resb 1	; 00h 19h 24h 35h 40h
			resb 1	; 01h 1Ah 25h 36h 41h
bpbnExtBPBSignature:	resb 1	; 02h 1Bh 26h 37h 42h -- 29h for valid BPBN
bpbnSerialNumber:	resd 1	; 03h 1Ch 27h 38h 43h
bpbnVolumeLabel:	resb 11	; 07h 20h 2Bh 3Ch 47h
bpbnFilesystemID:	resb 8	; 12h 2Bh 36h 47h 52h
	endstruc		; 1Ah 33h 3Eh 4Fh 5Ah

	struc DIRENTRY
deName:		resb 8
deExt:		resb 3
deAttrib:	resb 1
dePlusSize:	resb 1
		resb 7
deClusterHigh:	resw 1
deTime:		resw 1
deDate:		resw 1
deClusterLow:	resw 1
deSize:		resd 1
	endstruc

ATTR_READONLY	equ 1
ATTR_HIDDEN	equ 2
ATTR_SYSTEM	equ 4
ATTR_VOLLABEL	equ 8
ATTR_DIRECTORY	equ 10h
ATTR_ARCHIVE	equ 20h

lsvclSignature		equ "CL"
lsvclBufferLength	equ 256

	struc LOADSTACKVARS, -10h
lsvFirstCluster:	resd 1
lsvFATSector:		resd 1
lsvFATSeg:		resw 1
lsvLoadSeg:		resw 1
lsvDataStart:		resd 1
	endstruc

	struc LOADDATA, LOADSTACKVARS - 10h
ldMemoryTop:	resw 1
ldLoadTop:	resw 1
ldSectorSeg:	resw 1
ldFATType:	resb 1
ldFlags:
ldHasLBA:	resb 1
ldClusterSize:	resw 1
ldParaPerSector:resw 1
ldDirCluster:			; dword
ldLoadingSeg:		; word
ldQueryPatchValue:	; word
lsvCommandLine:		; word
.start:		equ $ - lsvclBufferLength
.signature:	resw 1
ldLoadUntilSeg:		; word
lsvExtra:		; word
.partition:	resb 1	; byte
.flags:		resb 1	; byte
	endstruc

ldhlfPreserveLoader	equ 4

lsvefNoDataStart	equ 1
lsvefPartitionNumber	equ 2
lsvefPreserveLoader	equ 4

%if lsvefPreserveLoader != ldhlfPreserveLoader
 %error Unexpected flag values
%endif

	struc LOADCMDLINE, LOADDATA - lsvclBufferLength
ldCommandLine:
.start:		resb lsvclBufferLength
	endstruc

ldfHasLBA:	equ 1
ldfFATInvalid:	equ 2
ldfFATBuffered:	equ 4
ldfDataBuffered: equ 8

	struc LOADDATA2, LOADDATA - 10h
ldRootSector:		resd 1
ldEntriesPerSector:	resw 1
ldDataSegment:		; word
ldLastAvailableSector:	resw 1
ldDataSector:		; dword
ldParasLeft:		resw 1
ldParasDone:		resw 1
	endstruc

	struc LOADDATA3, LOADDATA2 - 10h
ldMaxCluster:		resd 1
ldFileSize:		resd 1
ldCurrentCluster:	resd 1
ldCurrentSeek:		resd 1
	endstruc

	struc LOADERIMAGEIDENT
liiSignature:		resb 4		; "NLDR"
liiVersion:		resb 2		; "00"
liiChecksum:		resw 1		; word sum of first 8 words = 0
liiAmountParagraphs:	resw 1
liiReserved:		resw 3
liiEntryQuerySize:	resw 1		; 0 if not supported
		; INP:	cs => NLDR image ident
		;	ip = this word field content
		;	ax = 60h
		; OUT:	ax => behind memory requested (should be >= 60h)
		; CHG:	es, ds, di, si, bx, cx, dx
		; STT:	far called, UP, EI
liiEntryRelocate:	resw 1		; 0 if not supported
		; INP:	cs => NLDR image ident
		;	ip = this word field content
		;	ax = 60h
		; OUT:	ax => relocated NLDR segment (usually 60h)
		; CHG:	es, ds, di, si, bx, cx, dx
		; STT:	far called, UP, EI
liiEntryDebug:		resw 1		; 0 if not supported
		; INP:	es = ds = cs = ss => relocated NLDR
		;	ip = this word field content
		;	sp = next word field content
		; STT:	running as debuggee, UP, EI
liiStackPointer:	resw 1
	endstruc

	struc LBAPACKET
lpSize:		resw 1
lpCount:	resw 1
lpBuffer:	resd 1
lpSector:	resq 1
	endstruc

	struc PARTINFO
piBoot:		resb 1
piStartCHS:	resb 3
piType:		resb 1
piEndCHS:	resb 3
piStart:	resd 1
piLength:	resd 1
	endstruc

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


		; Flags of load_unit_flags
lufForceCHS:		equ 1
lufForceLBA:		equ 2
lufForceGeometry:	equ 4
luf_mask_writable equ lufForceCHS | lufForceLBA | lufForceGeometry
