From 55d3481671736d0944115e55be5e4506cf496161 Mon Sep 17 00:00:00 2001 From: hpa Date: Thu, 16 Dec 2004 06:17:23 +0000 Subject: [PATCH] More cleanups; try to get rid of the now-obsolete definition of "cluster" as the minimum block --- comboot.inc | 6 +++--- getc.inc | 18 ++++++++---------- isolinux.asm | 37 +++++++++++++++++-------------------- ldlinux.asm | 36 ++++++++++++++++++++++++++---------- loadhigh.inc | 9 +++------ pxelinux.asm | 10 +++++----- runkernel.inc | 18 +++++++----------- 7 files changed, 69 insertions(+), 65 deletions(-) diff --git a/comboot.inc b/comboot.inc index f3aec3b..af34686 100644 --- a/comboot.inc +++ b/comboot.inc @@ -125,7 +125,8 @@ is_comboot_image: ; Now actually load the file... pop si ; File handle mov bx,100h ; Load at :0100h - mov cx,[ClustPerMoby] ; Absolute maximum # of clusters + mov cx,0FF00h >> SECTOR_SHIFT + ; Absolute maximum # of sectors call getfssec ; And invoke the program... @@ -420,8 +421,7 @@ comapi_open: 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 diff --git a/getc.inc b/getc.inc index 4ec9757..6fd2406 100644 --- a/getc.inc +++ b/getc.inc @@ -38,12 +38,10 @@ openfd: 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 @@ -58,11 +56,11 @@ getc: 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 diff --git a/isolinux.asm b/isolinux.asm index 14d5d58..ad181b6 100644 --- a/isolinux.asm +++ b/isolinux.asm @@ -37,8 +37,8 @@ retry_count equ 6 ; How patient are we with the BIOS? %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 @@ -161,16 +161,16 @@ RamdiskMax resd 1 ; Highest address for a ramdisk 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 @@ -277,7 +277,7 @@ _start1: mov [cs:InitStack],sp ; Save initial stack pointer ; 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 @@ -363,7 +363,7 @@ set_file: 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) @@ -696,7 +696,7 @@ getlinsec: 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 @@ -967,8 +967,8 @@ get_fs_structures: 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 @@ -1359,8 +1359,8 @@ searchdir_iso: .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 @@ -1374,8 +1374,8 @@ searchdir_iso: 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 @@ -1739,16 +1739,13 @@ dsp_dummy: db 0 ; Scratch, safe to overwrite ; **** 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 diff --git a/ldlinux.asm b/ldlinux.asm index 79d668c..54ece59 100644 --- a/ldlinux.asm +++ b/ldlinux.asm @@ -144,7 +144,8 @@ SuperInfo equ $ 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 @@ -160,6 +161,7 @@ RamdiskMax resd 1 ; Highest address for a ramdisk 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 @@ -171,12 +173,7 @@ FBytes1 resw 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 @@ -890,7 +887,8 @@ genfatinfo: .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 @@ -926,6 +924,15 @@ getfattype: 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 @@ -1302,7 +1309,6 @@ getfssec_edx: jc .do_read cmp edx,eax jz .getseccnt - .do_read: mov eax,edx call getlinsecsr @@ -1318,7 +1324,6 @@ getfssec_edx: pop eax pop ebp ret - .eof: xor edx,edx stc @@ -1651,6 +1656,17 @@ SerialPort dw 0 ; Serial port base (or 0 for no serial port) 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 diff --git a/loadhigh.inc b/loadhigh.inc index a8e8603..b7caec4 100644 --- a/loadhigh.inc +++ b/loadhigh.inc @@ -54,14 +54,11 @@ load_high: jna .size_ok mov eax,(1 << 16) .size_ok: - xor edx,edx push eax ; 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 ; Target buffer mov cx,ax xor bx,bx ; ES:0 diff --git a/pxelinux.asm b/pxelinux.asm index 3070077..6ccab7d 100644 --- a/pxelinux.asm +++ b/pxelinux.asm @@ -52,6 +52,9 @@ TFTP_BLOCKSIZE_LG2 equ 9 ; log2(bytes/block) 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 ; @@ -246,14 +249,14 @@ RamdiskMax resd 1 ; Highest address for a ramdisk 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 @@ -2536,9 +2539,6 @@ ServerPort dw TFTP_PORT ; TFTP server port ; 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? diff --git a/runkernel.inc b/runkernel.inc index 7728ccd..64dd463 100644 --- a/runkernel.inc +++ b/runkernel.inc @@ -64,12 +64,9 @@ kernel_sane: push ax 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 @@ -84,13 +81,12 @@ kernel_sane: push ax ; 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 -- 2.7.4