; Now actually load the file...
pop si ; File handle
mov bx,100h ; Load at <seg>:0100h
- mov cx,[ClustPerMoby] ; Absolute maximum # of clusters
+ mov cx,0FF00h >> SECTOR_SHIFT
+ ; Absolute maximum # of sectors
call getfssec
; And invoke the program...
jz .err
mov P_AX,ax
mov P_HAX,dx
- mov ax,[ClustSize]
- mov P_CX,ax
+ mov P_CX,SECTOR_SIZE
mov P_SI,si
clc
ret
pushf
mov [FBytes1],ax
mov [FBytes2],dx
- add ax,[ClustSize]
- adc dx,byte 0
- sub ax,byte 1
- sbb dx,byte 0
- div word [ClustSize]
- mov [FClust],ax ; Number of clusters
+ mov eax,[FBytes]
+ add eax,SECTOR_SIZE-1
+ shr eax,SECTOR_SHIFT
+ mov [FSectors],eax ; Number of sectors
mov [FNextClust],si ; Cluster pointer
mov ax,[EndOfGetCBuf] ; Pointer at end of buffer ->
mov [FPtr],ax ; nothing loaded yet
cmp si,[EndOfGetCBuf]
jb getc_loaded
; Buffer empty -- load another set
- mov cx,[FClust]
- cmp cx,[BufSafe]
+ mov ecx,[FSectors]
+ cmp ecx,trackbufsize >> SECTOR_SHIFT
jna getc_oksize
- mov cx,[BufSafe]
-getc_oksize: sub [FClust],cx ; Reduce remaining clusters
+ mov ecx,trackbufsize >> SECTOR_SHIFT
+getc_oksize: sub [FSectors],ecx ; Reduce remaining clusters
mov si,[FNextClust]
push es ; ES may be != DS, save old ES
push ds
%assign HIGHMEM_SLOP 128*1024 ; Avoid this much memory near the top
MAX_OPEN_LG2 equ 6 ; log2(Max number of open files)
MAX_OPEN equ (1 << MAX_OPEN_LG2)
-SECTORSIZE_LG2 equ 11 ; 2048 bytes/sector (El Torito requirement)
-SECTORSIZE equ (1 << SECTORSIZE_LG2)
+SECTOR_SHIFT equ 11 ; 2048 bytes/sector (El Torito requirement)
+SECTOR_SIZE equ (1 << SECTOR_SHIFT)
;
; This is what we need to do when idle
KernelSize resd 1 ; Size of kernel (bytes)
SavedSSSP resd 1 ; Our SS:SP while running a COMBOOT image
PMESP resd 1 ; Protected-mode ESP
+FSectors resd 1 ; Number of sectors in getc file
RootDir resb dir_t_size ; Root directory
CurDir resb dir_t_size ; Current directory
-KernelClust resd 1 ; Kernel size in clusters
+KernelSects resd 1 ; Kernel size in clusters
InitStack resd 1 ; Initial stack pointer (SS:SP)
FirstSecSum resd 1 ; Checksum of bytes 64-2048
ImageDwords resd 1 ; isolinux.bin size, dwords
FBytes equ $ ; Used by open/getc
FBytes1 resw 1
FBytes2 resw 1
-FClust resw 1 ; Number of clusters in open/getc file
FNextClust resw 1 ; Pointer to next cluster in d:o
FPtr resw 1 ; Pointer to next char in buffer
CmdOptPtr resw 1 ; Pointer to first option on cmd line
;
initial_csum: xor edi,edi
mov si,_start1
- mov cx,(SECTORSIZE-64) >> 2
+ mov cx,(SECTOR_SIZE-64) >> 2
.loop: lodsd
add edi,eax
loop .loop
found_file:
; Set up boot file sizes
mov eax,[bi_length]
- sub eax,SECTORSIZE-3
+ sub eax,SECTOR_SIZE-3
shr eax,2 ; bytes->dwords
mov [ImageDwords],eax ; boot file dwords
add eax,(2047 >> 2)
movzx eax,word [si+2] ; Sectors we read
add [si+8],eax ; Advance sector pointer
sub bp,ax ; Sectors left
- shl ax,SECTORSIZE_LG2-4 ; 2048-byte sectors -> segment
+ shl ax,SECTOR_SHIFT-4 ; 2048-byte sectors -> segment
add [si+6],ax ; Advance buffer pointer
and bp,bp
jnz .loop
mov eax,[trackbuf+156+10]
mov [RootDir+dir_len],eax
mov [CurDir+dir_len],eax
- add eax,SECTORSIZE-1
- shr eax,SECTORSIZE_LG2
+ add eax,SECTOR_SIZE-1
+ shr eax,SECTOR_SHIFT
mov [RootDir+dir_clust],eax
mov [CurDir+dir_clust],eax
.next_sector:
; Advance to the beginning of next sector
- lea ax,[si+SECTORSIZE-1]
- and ax,~(SECTORSIZE-1)
+ lea ax,[si+SECTOR_SIZE-1]
+ and ax,~(SECTOR_SIZE-1)
sub ax,si
jmp short .not_file ; We still need to do length checks
mov [bx+file_sector],eax
mov eax,[si+10] ; Data length
push eax
- add eax,SECTORSIZE-1
- shr eax,SECTORSIZE_LG2
+ add eax,SECTOR_SIZE-1
+ shr eax,SECTOR_SHIFT
mov [bx+file_left],eax
pop eax
mov edx,eax
; **** BIOS expects our "sector size" to be.
;
alignb 4, db 0
-ClustSize dd SECTORSIZE ; Bytes/cluster
-ClustPerMoby dd 65536/SECTORSIZE ; Clusters per 64K
-SecPerClust dw 1 ; Same as bsSecPerClust, but a word
-BufSafe dw trackbufsize/SECTORSIZE ; Clusters we can load into trackbuf
-BufSafeSec dw trackbufsize/SECTORSIZE ; = how many sectors?
+BufSafe dw trackbufsize/SECTOR_SIZE ; Clusters we can load into trackbuf
+BufSafeSec dw trackbufsize/SECTOR_SIZE ; = how many sectors?
BufSafeBytes dw trackbufsize ; = how many bytes?
EndOfGetCBuf dw getcbuf+trackbufsize ; = getcbuf+BufSafeBytes
%ifndef DEPEND
-%if ( trackbufsize % SECTORSIZE ) != 0
-%error trackbufsize must be a multiple of SECTORSIZE
+%if ( trackbufsize % SECTOR_SIZE ) != 0
+%error trackbufsize must be a multiple of SECTOR_SIZE
%endif
%endif
resq 16 ; The first 16 bytes expanded 8 times
FAT resd 1 ; Location of (first) FAT
-RootDir resd 1 ; Location of root directory
+RootDirArea resd 1 ; Location of root directory area
+RootDir resd 1 ; Location of root directory proper
DataArea resd 1 ; Location of data area
RootDirSize resd 1 ; Root dir size in sectors
TotalSectors resd 1 ; Total number of sectors
KernelSize resd 1 ; Size of kernel (bytes)
SavedSSSP resd 1 ; Our SS:SP while running a COMBOOT image
PMESP resd 1 ; Protected-mode ESP
+FSectors resd 1 ; Number of sectors in getc file
ClustPerMoby resd 1 ; Clusters per 64K
ClustSize resd 1 ; Bytes/cluster
ClustMask resd 1 ; Sectors/cluster - 1
FBytes2 resw 1
DirBlocksLeft resw 1 ; Ditto
RunLinClust resw 1 ; Cluster # for LDLINUX.SYS
-BufSafe resw 1 ; Clusters we can load into trackbuf
-BufSafeSec resw 1 ; = how many sectors?
-BufSafeBytes resw 1 ; = how many bytes?
-EndOfGetCBuf resw 1 ; = getcbuf+BufSafeBytes
-KernelClust resw 1 ; Kernel size in clusters
-FClust resw 1 ; Number of clusters in open/getc file
+KernelSects resw 1 ; Kernel size in clusters
FNextClust resw 1 ; Pointer to next cluster in d:o
FPtr resw 1 ; Pointer to next char in buffer
CmdOptPtr resw 1 ; Pointer to first option on cmd line
.have_fatsecs:
imul edx,[bxFATs]
add eax,edx
- mov [RootDir],eax ; Beginning of root directory
+ mov [RootDirArea],eax ; Beginning of root directory
+ mov [RootDir],eax ; For FAT12/16 == root dir location
mov edx,[bxRootDirEnts]
add dx,512-32
mov cl,nextcluster_fat16-(nextcluster+2)
cmp eax,65525 ; FAT16 limit
jb .setsize
+ ;
+ ; FAT32, root directory is a cluster chain
+ ;
+ mov cl,[ClustShift]
+ mov eax,[bootsec+44] ; Root directory cluster
+ sub eax,2
+ shl eax,cl
+ add eax,[DataArea]
+ mov [RootDir],eax
mov cl,nextcluster_fat28-(nextcluster+2)
.setsize:
mov byte [nextcluster+1],cl
jc .do_read
cmp edx,eax
jz .getseccnt
-
.do_read:
mov eax,edx
call getlinsecsr
pop eax
pop ebp
ret
-
.eof:
xor edx,edx
stc
VGAFontSize dw 16 ; Defaults to 16 byte font
UserFont db 0 ; Using a user-specified font
ScrollAttribute db 07h ; White on black (for text mode)
+
+ alignb 4, db 0
+BufSafe dw trackbufsize/SECTOR_SIZE ; Clusters we can load into trackbuf
+BufSafeSec dw trackbufsize/SECTOR_SIZE ; = how many sectors?
+BufSafeBytes dw trackbufsize ; = how many bytes?
+EndOfGetCBuf dw getcbuf+trackbufsize ; = getcbuf+BufSafeBytes
+%ifndef DEPEND
+%if ( trackbufsize % SECTOR_SIZE ) != 0
+%error trackbufsize must be a multiple of SECTOR_SIZE
+%endif
+%endif
;
; Stuff for the command line; we do some trickery here with equ to avoid
; tons of zeros appended to our file and wasting space
jna .size_ok
mov eax,(1 << 16)
.size_ok:
- xor edx,edx
push eax ; <B> Bytes transferred this chunk
- div dword [ClustSize] ; Convert to clusters
- ; Round up...
- add edx,byte -1 ; Sets CF if EDX >= 1
- adc eax,byte 0 ; Add 1 to EAX if CF set
+ add eax,SECTOR_SIZE-1
+ shr eax,SECTOR_SHIFT ; Convert to sectors
- ; Now (e)ax contains the number of clusters to get
+ ; Now (e)ax contains the number of sectors to get
push edi ; <C> Target buffer
mov cx,ax
xor bx,bx ; ES:0
TFTP_BLOCKSIZE equ (1 << TFTP_BLOCKSIZE_LG2)
%assign USE_PXE_PROVIDED_STACK 1 ; Use stack provided by PXE?
+SECTOR_SHIFT equ TFTP_BLOCKSIZE_LG2
+SECTOR_SIZE equ TFTP_BLOCKSIZE
+
;
; This is what we need to do when idle
;
KernelSize resd 1 ; Size of kernel (bytes)
SavedSSSP resd 1 ; Our SS:SP while running a COMBOOT image
PMESP resd 1 ; Protected-mode ESP
+FSectors resd 1 ; Number of sectors in getc file
InitStack resd 1 ; Pointer to reset stack
RebootTime resd 1 ; Reboot timeout, if set by option
-KernelClust resd 1 ; Kernel size in clusters
+KernelSects resd 1 ; Kernel size in clusters
StrucPtr resd 1 ; Pointer to PXENV+ or !PXE structure
FBytes equ $ ; Used by open/getc
FBytes1 resw 1
FBytes2 resw 1
-FClust resw 1 ; Number of clusters in open/getc file
FNextClust resw 1 ; Pointer to next cluster in d:o
FPtr resw 1 ; Pointer to next char in buffer
CmdOptPtr resw 1 ; Pointer to first option on cmd line
; Variables that are uninitialized in SYSLINUX but initialized here
;
alignb 4, db 0
-ClustSize dd TFTP_BLOCKSIZE ; Bytes/cluster
-ClustPerMoby dd 65536/TFTP_BLOCKSIZE ; Clusters per 64K
-SecPerClust dw TFTP_BLOCKSIZE/512 ; Same as bsSecPerClust, but a word
BufSafe dw trackbufsize/TFTP_BLOCKSIZE ; Clusters we can load into trackbuf
BufSafeSec dw trackbufsize/512 ; = how many sectors?
BufSafeBytes dw trackbufsize ; = how many bytes?
shl edx,16 ; register for the kernel size
or eax,edx
mov [KernelSize],eax
- xor edx,edx
- div dword [ClustSize] ; # of clusters total
- ; Round up...
- add edx,byte -1 ; Sets CF if EDX >= 1
- adc eax,byte 0 ; Add 1 to EAX if CF set
- mov [KernelClust],eax
+ add eax,SECTOR_SIZE-1
+ shr eax,SECTOR_SHIFT
+ mov [KernelSects],eax ; Total sectors in kernel
;
; Now, if we transfer these straight, we'll hit 64K boundaries. Hence we
; If we have larger than 32K clusters, yes, we're hosed.
;
call abort_check ; Check for abort key
- mov ecx,[ClustPerMoby]
- shr ecx,1 ; Half a moby
- cmp ecx,[KernelClust]
+ mov ecx,8000h >> SECTOR_SHIFT ; Half a moby (32K)
+ cmp ecx,[KernelSects]
jna .normalkernel
- mov ecx,[KernelClust]
+ mov ecx,[KernelSects]
.normalkernel:
- sub [KernelClust],ecx
+ sub [KernelSects],ecx
xor bx,bx
pop si ; Cluster pointer on stack
call getfssec