More work on using sections for memory alignment. Make bcopy32 always
[profile/ivi/syslinux.git] / ldlinux.asm
1 ; -*- fundamental -*- (asm-mode sucks)
2 ; $Id$
3 ; ****************************************************************************
4 ;
5 ;  ldlinux.asm
6 ;
7 ;  A program to boot Linux kernels off an MS-DOS formatted floppy disk.  This
8 ;  functionality is good to have for installation floppies, where it may
9 ;  be hard to find a functional Linux system to run LILO off.
10 ;
11 ;  This program allows manipulation of the disk to take place entirely
12 ;  from MS-LOSS, and can be especially useful in conjunction with the
13 ;  umsdos filesystem.
14 ;
15 ;   Copyright (C) 1994-2004  H. Peter Anvin
16 ;
17 ;  This program is free software; you can redistribute it and/or modify
18 ;  it under the terms of the GNU General Public License as published by
19 ;  the Free Software Foundation, Inc., 53 Temple Place Ste 330,
20 ;  Boston MA 02111-1307, USA; either version 2 of the License, or
21 ;  (at your option) any later version; incorporated herein by reference.
22
23 ; ****************************************************************************
24
25 %ifndef IS_MDSLINUX
26 %define IS_SYSLINUX 1
27 %endif
28 %include "macros.inc"
29 %include "config.inc"
30 %include "kernel.inc"
31 %include "bios.inc"
32 %include "tracers.inc"
33 %include "layout.inc"
34 ;
35 ; Some semi-configurable constants... change on your own risk.
36 ;
37 my_id           equ syslinux_id
38 FILENAME_MAX_LG2 equ 4                  ; log2(Max filename size Including final null)
39 FILENAME_MAX    equ 11                  ; Max mangled filename size
40 NULLFILE        equ ' '                 ; First char space == null filename
41 NULLOFFSET      equ 0                   ; Position in which to look
42 retry_count     equ 6                   ; How patient are we with the disk?
43 %assign HIGHMEM_SLOP 0                  ; Avoid this much memory near the top
44 LDLINUX_MAGIC   equ 0x3eb202fe          ; A random number to identify ourselves with
45
46 MAX_OPEN_LG2    equ 6                   ; log2(Max number of open files)
47 MAX_OPEN        equ (1 << MAX_OPEN_LG2)
48
49 SECTOR_SHIFT    equ 9
50 SECTOR_SIZE     equ (1 << SECTOR_SHIFT)
51
52 ;
53 ; This is what we need to do when idle
54 ;
55 %macro  RESET_IDLE 0
56         ; Nothing
57 %endmacro
58 %macro  DO_IDLE 0
59         ; Nothing
60 %endmacro
61
62 ;
63 ; The following structure is used for "virtual kernels"; i.e. LILO-style
64 ; option labels.  The options we permit here are `kernel' and `append
65 ; Since there is no room in the bottom 64K for all of these, we
66 ; stick them at vk_seg:0000 and copy them down before we need them.
67 ;
68                 struc vkernel
69 vk_vname:       resb FILENAME_MAX       ; Virtual name **MUST BE FIRST!**
70 vk_rname:       resb FILENAME_MAX       ; Real name
71 vk_appendlen:   resw 1
72                 alignb 4
73 vk_append:      resb max_cmd_len+1      ; Command line
74                 alignb 4
75 vk_end:         equ $                   ; Should be <= vk_size
76                 endstruc
77
78 ;
79 ; Segment assignments in the bottom 640K
80 ; Stick to the low 512K in case we're using something like M-systems flash
81 ; which load a driver into low RAM (evil!!)
82 ;
83 ; 0000h - main code/data segment (and BIOS segment)
84 ;
85 real_mode_seg   equ 4000h
86 cache_seg       equ 3000h               ; 64K area for metadata cache
87 vk_seg          equ 2000h               ; Virtual kernels
88 xfer_buf_seg    equ 1000h               ; Bounce buffer for I/O to high mem
89 comboot_seg     equ real_mode_seg       ; COMBOOT image loading zone
90
91 ;
92 ; File structure.  This holds the information for each currently open file.
93 ;
94                 struc open_file_t
95 file_sector     resd 1                  ; Sector pointer (0 = structure free)
96 file_left       resd 1                  ; Number of sectors left
97                 endstruc
98
99 %ifndef DEPEND
100 %if (open_file_t_size & (open_file_t_size-1))
101 %error "open_file_t is not a power of 2"
102 %endif
103 %endif
104
105 ; ---------------------------------------------------------------------------
106 ;   BEGIN CODE
107 ; ---------------------------------------------------------------------------
108
109 ;
110 ; Memory below this point is reserved for the BIOS and the MBR
111 ;
112                 section .earlybss
113 trackbufsize    equ 8192
114 trackbuf        resb trackbufsize       ; Track buffer goes here
115 getcbuf         resb trackbufsize
116                 ; ends at 4800h
117
118                 section .bss
119                 alignb 8
120
121                 ; Expanded superblock
122 SuperInfo       equ $
123                 resq 16                 ; The first 16 bytes expanded 8 times
124 FAT             resd 1                  ; Location of (first) FAT
125 RootDirArea     resd 1                  ; Location of root directory area
126 RootDir         resd 1                  ; Location of root directory proper
127 DataArea        resd 1                  ; Location of data area
128 RootDirSize     resd 1                  ; Root dir size in sectors
129 TotalSectors    resd 1                  ; Total number of sectors
130 EndSector       resd 1                  ; Location of filesystem end
131 ClustSize       resd 1                  ; Bytes/cluster
132 ClustMask       resd 1                  ; Sectors/cluster - 1
133 CopySuper       resb 1                  ; Distinguish .bs versus .bss
134 DriveNumber     resb 1                  ; BIOS drive number
135 ClustShift      resb 1                  ; Shift count for sectors/cluster
136 ClustByteShift  resb 1                  ; Shift count for bytes/cluster
137
138                 alignb open_file_t_size
139 Files           resb MAX_OPEN*open_file_t_size
140
141 ;
142 ; Constants for the xfer_buf_seg
143 ;
144 ; The xfer_buf_seg is also used to store message file buffers.  We
145 ; need two trackbuffers (text and graphics), plus a work buffer
146 ; for the graphics decompressor.
147 ;
148 xbs_textbuf     equ 0                   ; Also hard-coded, do not change
149 xbs_vgabuf      equ trackbufsize
150 xbs_vgatmpbuf   equ 2*trackbufsize
151
152
153                 section .text
154 ;
155 ; Some of the things that have to be saved very early are saved
156 ; "close" to the initial stack pointer offset, in order to
157 ; reduce the code size...
158 ;
159 StackBuf        equ $-44-32             ; Start the stack here (grow down - 4K)
160 PartInfo        equ StackBuf            ; Saved partition table entry
161 FloppyTable     equ PartInfo+16         ; Floppy info table (must follow PartInfo)
162 OrigFDCTabPtr   equ StackBuf-4          ; The high dword on the stack
163
164 ;
165 ; Primary entry point.  Tempting as though it may be, we can't put the
166 ; initial "cli" here; the jmp opcode in the first byte is part of the
167 ; "magic number" (using the term very loosely) for the DOS superblock.
168 ;
169 bootsec         equ $
170                 jmp short start         ; 2 bytes
171                 nop                     ; 1 byte
172 ;
173 ; "Superblock" follows -- it's in the boot sector, so it's already
174 ; loaded and ready for us
175 ;
176 bsOemName       db 'SYSLINUX'           ; The SYS command sets this, so...
177 ;
178 ; These are the fields we actually care about.  We end up expanding them
179 ; all to dword size early in the code, so generate labels for both
180 ; the expanded and unexpanded versions.
181 ;
182 %macro          superb 1
183 bx %+ %1        equ SuperInfo+($-superblock)*8+4
184 bs %+ %1        equ $
185                 zb 1
186 %endmacro
187 %macro          superw 1
188 bx %+ %1        equ SuperInfo+($-superblock)*8
189 bs %+ %1        equ $
190                 zw 1
191 %endmacro
192 %macro          superd 1
193 bx %+ %1        equ $                   ; no expansion for dwords
194 bs %+ %1        equ $
195                 zd 1
196 %endmacro
197 superblock      equ $
198                 superw BytesPerSec
199                 superb SecPerClust
200                 superw ResSectors
201                 superb FATs
202                 superw RootDirEnts
203                 superw Sectors
204                 superb Media
205                 superw FATsecs
206                 superw SecPerTrack
207                 superw Heads
208 superinfo_size  equ ($-superblock)-1    ; How much to expand
209                 superd Hidden
210                 superd HugeSectors
211                 ;
212                 ; This is as far as FAT12/16 and FAT32 are consistent
213                 ;
214                 zb 54                   ; FAT12/16 need 26 more bytes,
215                                         ; FAT32 need 54 more bytes
216 superblock_len  equ $-superblock
217
218 SecPerClust     equ bxSecPerClust
219 ;
220 ; Note we don't check the constraints above now; we did that at install
221 ; time (we hope!)
222 ;
223 start:
224                 cli                     ; No interrupts yet, please
225                 cld                     ; Copy upwards
226 ;
227 ; Set up the stack
228 ;
229                 xor ax,ax
230                 mov ss,ax
231                 mov sp,StackBuf         ; Just below BSS
232                 mov es,ax
233 ;
234 ; DS:SI may contain a partition table entry.  Preserve it for us.
235 ;
236                 mov cx,8                ; Save partition info
237                 mov di,sp
238                 rep movsw
239
240                 mov ds,ax               ; Now we can initialize DS...
241
242 ;
243 ; Now sautee the BIOS floppy info block to that it will support decent-
244 ; size transfers; the floppy block is 11 bytes and is stored in the
245 ; INT 1Eh vector (brilliant waste of resources, eh?)
246 ;
247 ; Of course, if BIOSes had been properly programmed, we wouldn't have
248 ; had to waste precious space with this code.
249 ;
250                 mov bx,fdctab
251                 lfs si,[bx]             ; FS:SI -> original fdctab
252                 push fs                 ; Save on stack in case we need to bail
253                 push si
254
255                 ; Save the old fdctab even if hard disk so the stack layout
256                 ; is the same.  The instructions above do not change the flags
257                 mov [DriveNumber],dl    ; Save drive number in DL
258                 and dl,dl               ; If floppy disk (00-7F), assume no
259                                         ; partition table
260                 js harddisk
261
262 floppy:
263                 mov cl,6                ; 12 bytes (CX == 0)
264                 ; es:di -> FloppyTable already
265                 ; This should be safe to do now, interrupts are off...
266                 mov [bx],di             ; FloppyTable
267                 mov [bx+2],ax           ; Segment 0
268                 fs rep movsw            ; Faster to move words
269                 mov cl,[bsSecPerTrack]  ; Patch the sector count
270                 mov [di-8],cl
271                 ; AX == 0 here
272                 int 13h                 ; Some BIOSes need this
273
274                 jmp short not_harddisk
275 ;
276 ; The drive number and possibly partition information was passed to us
277 ; by the BIOS or previous boot loader (MBR).  Current "best practice" is to
278 ; trust that rather than what the superblock contains.
279 ;
280 ; Would it be better to zero out bsHidden if we don't have a partition table?
281 ;
282 ; Note: di points to beyond the end of PartInfo
283 ;
284 harddisk:
285                 test byte [di-16],7Fh   ; Sanity check: "active flag" should
286                 jnz no_partition        ; be 00 or 80
287                 mov eax,[di-8]          ; Partition offset (dword)
288                 mov [bsHidden],eax
289 no_partition:
290 ;
291 ; Get disk drive parameters (don't trust the superblock.)  Don't do this for
292 ; floppy drives -- INT 13:08 on floppy drives will (may?) return info about
293 ; what the *drive* supports, not about the *media*.  Fortunately floppy disks
294 ; tend to have a fixed, well-defined geometry which is stored in the superblock.
295 ;
296                 ; DL == drive # still
297                 mov ah,08h
298                 int 13h
299                 jc no_driveparm
300                 and ah,ah
301                 jnz no_driveparm
302                 shr dx,8
303                 inc dx                  ; Contains # of heads - 1
304                 mov [bsHeads],dx
305                 and cx,3fh
306                 mov [bsSecPerTrack],cx
307 no_driveparm:
308 not_harddisk:
309 ;
310 ; Ready to enable interrupts, captain
311 ;
312                 sti
313
314
315 ;
316 ; Do we have EBIOS (EDD)?
317 ;
318 eddcheck:
319                 mov bx,55AAh
320                 mov ah,41h              ; EDD existence query
321                 mov dl,[DriveNumber]
322                 int 13h
323                 jc .noedd
324                 cmp bx,0AA55h
325                 jne .noedd
326                 test cl,1               ; Extended disk access functionality set
327                 jz .noedd
328                 ;
329                 ; We have EDD support...
330                 ;
331                 mov byte [getlinsec.jmp+1],getlinsec_ebios-(getlinsec.jmp+2)
332 .noedd:
333
334 ;
335 ; Load the first sector of LDLINUX.SYS; this used to be all proper
336 ; with parsing the superblock and root directory; it doesn't fit
337 ; together with EBIOS support, unfortunately.
338 ;
339                 mov eax,[FirstSector]   ; Sector start
340                 mov bx,ldlinux_sys      ; Where to load it
341                 call getonesec
342                 
343                 ; Some modicum of integrity checking
344                 cmp dword [ldlinux_magic],LDLINUX_MAGIC
345                 jne kaboom
346                 cmp dword [ldlinux_magic+4],HEXDATE
347                 jne kaboom
348
349                 ; Go for it...
350                 jmp ldlinux_ent
351
352 ;
353 ; kaboom: write a message and bail out.
354 ;
355 kaboom:
356                 xor si,si
357                 mov ss,si               
358                 mov sp,StackBuf-4       ; Reset stack
359                 mov ds,si               ; Reset data segment
360                 pop dword [fdctab]      ; Restore FDC table
361 .patch:         mov si,bailmsg
362                 call writestr           ; Returns with AL = 0
363                 cbw                     ; AH <- 0
364                 int 16h                 ; Wait for keypress
365                 int 19h                 ; And try once more to boot...
366 .norge:         jmp short .norge        ; If int 19h returned; this is the end
367
368 ;
369 ;
370 ; writestr: write a null-terminated string to the console
371 ;           This assumes we're on page 0.  This is only used for early
372 ;           messages, so it should be OK.
373 ;
374 writestr:
375 .loop:          lodsb
376                 and al,al
377                 jz .return
378                 mov ah,0Eh              ; Write to screen as TTY
379                 mov bx,0007h            ; Attribute
380                 int 10h
381                 jmp short .loop
382 .return:        ret
383
384 ;
385 ; xint13: wrapper for int 13h which will retry 6 times and then die,
386 ;         AND save all registers except BP
387 ;
388 xint13:
389 .again:
390                 mov bp,retry_count
391 .loop:          pushad
392                 int 13h
393                 popad
394                 jnc writestr.return
395                 dec bp
396                 jnz .loop
397 .disk_error:
398                 jmp strict near kaboom  ; Patched
399
400
401 ;
402 ; getonesec: get one disk sector
403 ;
404 getonesec:
405                 mov bp,1                ; One sector
406                 ; Fall through
407
408 ;
409 ; getlinsec: load a sequence of BP floppy sector given by the linear sector
410 ;            number in EAX into the buffer at ES:BX.  We try to optimize
411 ;            by loading up to a whole track at a time, but the user
412 ;            is responsible for not crossing a 64K boundary.
413 ;            (Yes, BP is weird for a count, but it was available...)
414 ;
415 ;            On return, BX points to the first byte after the transferred
416 ;            block.
417 ;
418 ;            This routine assumes CS == DS, and trashes most registers.
419 ;
420 ; Stylistic note: use "xchg" instead of "mov" when the source is a register
421 ; that is dead from that point; this saves space.  However, please keep
422 ; the order to dst,src to keep things sane.
423 ;
424 getlinsec:
425                 add eax,[bsHidden]              ; Add partition offset
426 .jmp:           jmp strict short getlinsec_cbios        ; This is patched
427
428 ;
429 ; getlinsec_ebios:
430 ;
431 ; getlinsec implementation for EBIOS (EDD)
432 ;
433 getlinsec_ebios:
434                 mov si,dapa                     ; Load up the DAPA
435                 mov [si+4],bx
436                 mov [si+6],es
437                 mov [si+8],eax
438 .loop:
439                 push bp                         ; Sectors left
440                 call maxtrans                   ; Enforce maximum transfer size
441 .bp_ok:
442                 mov [si+2],bp
443                 mov dl,[DriveNumber]
444                 mov ah,42h                      ; Extended Read
445                 call xint13
446                 pop bp
447                 movzx eax,word [si+2]           ; Sectors we read
448                 add [si+8],eax                  ; Advance sector pointer
449                 sub bp,ax                       ; Sectors left
450                 shl ax,9                        ; 512-byte sectors
451                 add [si+4],ax                   ; Advance buffer pointer
452                 and bp,bp
453                 jnz .loop
454                 mov eax,[si+8]                  ; Next sector
455                 mov bx,[si+4]                   ; Buffer pointer
456                 ret
457
458 ;
459 ; getlinsec_cbios:
460 ;
461 ; getlinsec implementation for legacy CBIOS
462 ;
463 getlinsec_cbios:
464 .loop:
465                 push eax
466                 push bp
467                 push bx
468
469                 movzx esi,word [bsSecPerTrack]
470                 movzx edi,word [bsHeads]
471                 ;
472                 ; Dividing by sectors to get (track,sector): we may have
473                 ; up to 2^18 tracks, so we need to use 32-bit arithmetric.
474                 ;
475                 xor edx,edx             ; Zero-extend LBA to 64 bits
476                 div esi
477                 xor cx,cx
478                 xchg cx,dx              ; CX <- sector index (0-based)
479                                         ; EDX <- 0
480                 ; eax = track #
481                 div edi                 ; Convert track to head/cyl
482                 ;
483                 ; Now we have AX = cyl, DX = head, CX = sector (0-based),
484                 ; BP = sectors to transfer, SI = bsSecPerTrack,
485                 ; ES:BX = data target
486                 ;
487
488                 call maxtrans                   ; Enforce maximum transfer size
489
490                 ; Must not cross track boundaries, so BP <= SI-CX
491                 sub si,cx
492                 cmp bp,si
493                 jna .bp_ok
494                 mov bp,si
495 .bp_ok: 
496
497                 shl ah,6                ; Because IBM was STOOPID
498                                         ; and thought 8 bits were enough
499                                         ; then thought 10 bits were enough...
500                 inc cx                  ; Sector numbers are 1-based, sigh
501                 or cl,ah
502                 mov ch,al
503                 mov dh,dl
504                 mov dl,[DriveNumber]
505                 xchg ax,bp              ; Sector to transfer count
506                 mov ah,02h              ; Read sectors
507                 call xint13
508                 movzx ecx,al
509                 shl ax,9                ; Convert sectors in AL to bytes in AX
510                 pop bx
511                 add bx,ax
512                 pop bp
513                 pop eax
514                 add eax,ecx
515                 sub bp,cx
516                 jnz .loop
517                 ret
518
519 ;
520 ; Truncate BP to MaxTransfer
521 ;
522 maxtrans:
523                 cmp bp,[MaxTransfer]
524                 jna .ok
525                 mov bp,[MaxTransfer]
526 .ok:            ret
527
528 ;
529 ; Error message on failure
530 ;
531 bailmsg:        db 'Boot failed', 0Dh, 0Ah, 0
532
533 ;
534 ; EBIOS disk address packet
535 ;
536                 align 4, db 0
537 dapa:
538                 dw 16                           ; Packet size
539 .count:         dw 0                            ; Block count
540 .off:           dw 0                            ; Offset of buffer
541 .seg:           dw 0                            ; Segment of buffer
542 .lba:           dd 0                            ; LBA (LSW)
543                 dd 0                            ; LBA (MSW)
544
545
546 %if 1
547 bs_checkpt_off  equ ($-$$)
548 %ifndef DEPEND
549 %if bs_checkpt_off > 1F8h
550 %error "Boot sector overflow"
551 %endif
552 %endif
553
554                 zb 1F8h-($-$$)
555 %endif
556 FirstSector     dd 0xDEADBEEF                   ; Location of sector 1
557 MaxTransfer     dw 0x007F                       ; Max transfer size
558 bootsignature   dw 0AA55h
559
560 ;
561 ; ===========================================================================
562 ;  End of boot sector
563 ; ===========================================================================
564 ;  Start of LDLINUX.SYS
565 ; ===========================================================================
566
567 ldlinux_sys:
568
569 syslinux_banner db 0Dh, 0Ah
570 %if IS_MDSLINUX
571                 db 'MDSLINUX '
572 %else
573                 db 'SYSLINUX '
574 %endif
575                 db version_str, ' ', date, ' ', 0
576                 db 0Dh, 0Ah, 1Ah        ; EOF if we "type" this in DOS
577
578                 align 8, db 0
579 ldlinux_magic   dd LDLINUX_MAGIC
580                 dd HEXDATE
581
582 ;
583 ; This area is patched by the installer.  It is found by looking for
584 ; LDLINUX_MAGIC, plus 8 bytes.
585 ;
586 patch_area:
587 LDLDwords       dw 0            ; Total dwords starting at ldlinux_sys
588 LDLSectors      dw 0            ; Number of sectors - (bootsec+this sec)
589 CheckSum        dd 0            ; Checksum starting at ldlinux_sys
590                                 ; value = LDLINUX_MAGIC - [sum of dwords]
591
592 ; Space for up to 64 sectors, the theoretical maximum
593 SectorPtrs      times 64 dd 0
594
595 ldlinux_ent:
596
597 ; Note that some BIOSes are buggy and run the boot sector at 07C0:0000
598 ; instead of 0000:7C00 and the like.  We don't want to add anything
599 ; more to the boot sector, so it is written to not assume a fixed
600 ; value in CS, but we don't want to deal with that anymore from now
601 ; on.
602 ;
603                 jmp 0:.next
604 .next:
605
606 ;
607 ; Tell the user we got this far
608 ;
609                 mov si,syslinux_banner
610                 call writestr
611
612 ;
613 ; Patch disk error handling
614 ;
615                 mov word [xint13.disk_error+1],do_disk_error-(xint13.disk_error+3)
616
617 ;
618 ; Now we read the rest of LDLINUX.SYS.  Don't bother loading the first
619 ; sector again, though.
620 ;
621 load_rest:
622                 mov si,SectorPtrs
623                 mov bx,7C00h+2*SECTOR_SIZE      ; Where we start loading
624                 mov cx,[LDLSectors]
625
626 .get_chunk:
627                 jcxz .done
628                 xor bp,bp
629                 lodsd                           ; First sector of this chunk
630
631                 mov edx,eax
632
633 .make_chunk:
634                 inc bp
635                 dec cx
636                 jz .chunk_ready
637                 inc edx                         ; Next linear sector
638                 cmp [esi],edx                   ; Does it match
639                 jnz .chunk_ready                ; If not, this is it
640                 add esi,4                       ; If so, add sector to chunk
641                 jmp short .make_chunk
642
643 .chunk_ready:
644                 call getlinsecsr
645                 shl bp,SECTOR_SHIFT
646                 add bx,bp
647                 jmp .get_chunk
648
649 .done:
650
651 ;
652 ; All loaded up, verify that we got what we needed.
653 ; Note: the checksum field is embedded in the checksum region, so
654 ; by the time we get to the end it should all cancel out.
655 ;
656 verify_checksum:
657                 mov si,ldlinux_sys
658                 mov cx,[LDLDwords]
659                 mov edx,-LDLINUX_MAGIC
660 .checksum:
661                 lodsd
662                 add edx,eax
663                 loop .checksum
664
665                 and edx,edx                     ; Should be zero
666                 jz all_read                     ; We're cool, go for it!
667
668 ;
669 ; Uh-oh, something went bad...
670 ;
671                 mov si,checksumerr_msg
672                 call writestr
673                 jmp kaboom
674
675 ;
676 ; -----------------------------------------------------------------------------
677 ; Subroutines that have to be in the first sector
678 ; -----------------------------------------------------------------------------
679
680 ;
681 ; getlinsecsr: save registers, call getlinsec, restore registers
682 ;
683 getlinsecsr:    pushad
684                 call getlinsec
685                 popad
686                 ret
687
688 ;
689 ; This routine captures disk errors, and tries to decide if it is
690 ; time to reduce the transfer size.
691 ;
692 do_disk_error:
693                 cmp ah,42h
694                 je .ebios
695                 shr al,1                ; Try reducing the transfer size
696                 mov [MaxTransfer],al    
697                 jz kaboom               ; If we can't, we're dead...
698                 jmp xint13              ; Try again
699 .ebios:
700                 push ax
701                 mov ax,[si+2]
702                 shr ax,1
703                 mov [MaxTransfer],ax
704                 mov [si+2],ax
705                 pop ax
706                 jmp xint13
707
708 ;
709 ; Checksum error message
710 ;
711 checksumerr_msg db 'Load error - ', 0   ; Boot failed appended
712
713 ;
714 ; Debug routine
715 ;
716 %ifdef debug
717 safedumpregs:
718                 cmp word [Debug_Magic],0D00Dh
719                 jnz nc_return
720                 jmp dumpregs
721 %endif
722
723 rl_checkpt      equ $                           ; Must be <= 8000h
724
725 rl_checkpt_off  equ ($-$$)
726 %if 0 ; ndef DEPEND
727 %if rl_checkpt_off > 400h
728 %error "Sector 1 overflow"
729 %endif
730 %endif
731
732 ; ----------------------------------------------------------------------------
733 ;  End of code and data that have to be in the first sector
734 ; ----------------------------------------------------------------------------
735
736 all_read:
737 ;
738 ; Let the user (and programmer!) know we got this far.  This used to be
739 ; in Sector 1, but makes a lot more sense here.
740 ;
741                 mov si,copyright_str
742                 call writestr
743
744
745 ;
746 ; Insane hack to expand the superblock to dwords
747 ;
748 expand_super:
749                 xor eax,eax
750                 mov si,superblock
751                 mov di,SuperInfo
752                 mov cx,superinfo_size
753 .loop:
754                 lodsw
755                 dec si
756                 stosd                           ; Store expanded word
757                 xor ah,ah
758                 stosd                           ; Store expanded byte
759                 loop .loop
760
761 ;
762 ; Compute some information about this filesystem.
763 ;
764
765 ; First, generate the map of regions
766 genfatinfo:
767                 mov edx,[bxSectors]
768                 and dx,dx
769                 jnz .have_secs
770                 mov edx,[bsHugeSectors]
771 .have_secs:
772                 mov [TotalSectors],edx
773
774                 add edx,eax
775                 mov [EndSector],edx
776
777                 mov eax,[bxResSectors]
778                 mov [FAT],eax                   ; Beginning of FAT
779                 mov edx,[bxFATsecs]
780                 and dx,dx
781                 jnz .have_fatsecs
782                 mov edx,[bootsec+36]            ; FAT32 BPB_FATsz32
783 .have_fatsecs:
784                 imul edx,[bxFATs]
785                 add eax,edx
786                 mov [RootDirArea],eax           ; Beginning of root directory
787                 mov [RootDir],eax               ; For FAT12/16 == root dir location
788
789                 mov edx,[bxRootDirEnts]
790                 add dx,SECTOR_SIZE/32-1
791                 shr dx,SECTOR_SHIFT-5
792                 mov [RootDirSize],edx
793                 add eax,edx
794                 mov [DataArea],eax              ; Beginning of data area
795
796 ; Next, generate a cluster size shift count and mask
797                 mov eax,[bxSecPerClust]
798                 bsr cx,ax
799                 mov [ClustShift],cl
800                 push cx
801                 add cl,9
802                 mov [ClustByteShift],cl
803                 pop cx
804                 dec ax
805                 mov [ClustMask],eax
806                 inc ax
807                 shl eax,9
808                 mov [ClustSize],eax
809
810 ;
811 ; FAT12, FAT16 or FAT28^H^H32?  This computation is fscking ridiculous.
812 ;
813 getfattype:
814                 mov eax,[EndSector]
815                 sub eax,[DataArea]
816                 shr eax,cl                      ; cl == ClustShift
817                 mov cl,nextcluster_fat12-(nextcluster+2)
818                 cmp eax,4085                    ; FAT12 limit
819                 jb .setsize
820                 mov cl,nextcluster_fat16-(nextcluster+2)
821                 cmp eax,65525                   ; FAT16 limit
822                 jb .setsize
823                 ;
824                 ; FAT32, root directory is a cluster chain
825                 ;
826                 mov cl,[ClustShift]
827                 mov eax,[bootsec+44]            ; Root directory cluster
828                 sub eax,2
829                 shl eax,cl
830                 add eax,[DataArea]
831                 mov [RootDir],eax
832                 mov cl,nextcluster_fat28-(nextcluster+2)
833 .setsize:
834                 mov byte [nextcluster+1],cl
835
836 ;
837 ; Common initialization code
838 ;
839 %include "cpuinit.inc"
840 %include "init.inc"
841
842 ;
843 ; Clear Files structures
844 ;
845                 mov di,Files
846                 mov cx,(MAX_OPEN*open_file_t_size)/4
847                 xor eax,eax
848                 rep stosd
849
850 ;
851 ; Initialize the metadata cache
852 ;
853                 call initcache
854
855 ;
856 ; Now, everything is "up and running"... patch kaboom for more
857 ; verbosity and using the full screen system
858 ;
859                 ; E9 = JMP NEAR
860                 mov dword [kaboom.patch],0e9h+((kaboom2-(kaboom.patch+3)) << 8)
861
862 ;
863 ; Now we're all set to start with our *real* business.  First load the
864 ; configuration file (if any) and parse it.
865 ;
866 ; In previous versions I avoided using 32-bit registers because of a
867 ; rumour some BIOSes clobbered the upper half of 32-bit registers at
868 ; random.  I figure, though, that if there are any of those still left
869 ; they probably won't be trying to install Linux on them...
870 ;
871 ; The code is still ripe with 16-bitisms, though.  Not worth the hassle
872 ; to take'm out.  In fact, we may want to put them back if we're going
873 ; to boot ELKS at some point.
874 ;
875
876 ;
877 ; Load configuration file
878 ;
879                 mov di,syslinux_cfg
880                 call open
881                 jz no_config_file
882
883 ;
884 ; Now we have the config file open.  Parse the config file and
885 ; run the user interface.
886 ;
887 %include "ui.inc"
888
889 ;
890 ; Linux kernel loading code is common.
891 ;
892 %include "runkernel.inc"
893
894 ;
895 ; COMBOOT-loading code
896 ;
897 %include "comboot.inc"
898 %include "com32.inc"
899 %include "cmdline.inc"
900
901 ;
902 ; Boot sector loading code
903 ;
904 %include "bootsect.inc"
905
906 ;
907 ; abort_check: let the user abort with <ESC> or <Ctrl-C>
908 ;
909 abort_check:
910                 call pollchar
911                 jz ac_ret1
912                 pusha
913                 call getchar
914                 cmp al,27                       ; <ESC>
915                 je ac_kill
916                 cmp al,3                        ; <Ctrl-C>
917                 jne ac_ret2
918 ac_kill:        mov si,aborted_msg
919
920 ;
921 ; abort_load: Called by various routines which wants to print a fatal
922 ;             error message and return to the command prompt.  Since this
923 ;             may happen at just about any stage of the boot process, assume
924 ;             our state is messed up, and just reset the segment registers
925 ;             and the stack forcibly.
926 ;
927 ;             SI    = offset (in _text) of error message to print
928 ;
929 abort_load:
930                 mov ax,cs                       ; Restore CS = DS = ES
931                 mov ds,ax
932                 mov es,ax
933                 cli
934                 mov sp,StackBuf-2*3             ; Reset stack
935                 mov ss,ax                       ; Just in case...
936                 sti
937                 call cwritestr                  ; Expects SI -> error msg
938 al_ok:          jmp enter_command               ; Return to command prompt
939 ;
940 ; End of abort_check
941 ;
942 ac_ret2:        popa
943 ac_ret1:        ret
944
945 ;
946 ; allocate_file: Allocate a file structure
947 ;
948 ;               If successful:
949 ;                 ZF set
950 ;                 BX = file pointer
951 ;               In unsuccessful:
952 ;                 ZF clear
953 ;
954 allocate_file:
955                 TRACER 'a'
956                 push cx
957                 mov bx,Files
958                 mov cx,MAX_OPEN
959 .check:         cmp dword [bx], byte 0
960                 je .found
961                 add bx,open_file_t_size         ; ZF = 0
962                 loop .check
963                 ; ZF = 0 if we fell out of the loop
964 .found:         pop cx
965                 ret
966
967 ;
968 ; searchdir:
969 ;            Search the root directory for a pre-mangled filename in DS:DI.
970 ;
971 ;            NOTE: This file considers finding a zero-length file an
972 ;            error.  This is so we don't have to deal with that special
973 ;            case elsewhere in the program (most loops have the test
974 ;            at the end).
975 ;
976 ;            If successful:
977 ;               ZF clear
978 ;               SI      = file pointer
979 ;               DX:AX   = file length in bytes
980 ;            If unsuccessful
981 ;               ZF set
982 ;
983
984 searchdir:
985                 call allocate_file
986                 jnz .alloc_failure
987
988                 push gs
989                 push es
990                 push ds
991                 pop es                          ; ES = DS
992
993                 mov edx,[RootDir]               ; First root directory sector
994
995 .scansector:
996                 mov eax,edx
997                 call getcachesector
998                 ; GS:SI now points to this sector
999
1000                 mov cx,SECTOR_SIZE/32           ; 32 == directory entry size
1001 .scanentry:
1002                 cmp byte [gs:si],0
1003                 jz .failure                     ; Hit directory high water mark
1004                 push cx
1005                 push si
1006                 push di
1007                 mov cx,11
1008                 gs repe cmpsb
1009                 pop di
1010                 pop si
1011                 pop cx
1012                 jz .found
1013                 add si,32
1014                 loop .scanentry
1015
1016                 call nextsector
1017                 jnc .scansector                 ; CF is set if we're at end
1018
1019                 ; If we get here, we failed
1020 .failure:
1021                 pop es
1022                 pop gs
1023 .alloc_failure:
1024                 xor ax,ax                       ; ZF <- 1
1025                 ret
1026 .found:
1027                 mov eax,[gs:si+28]              ; File size
1028                 add eax,SECTOR_SIZE-1
1029                 shr eax,SECTOR_SHIFT
1030                 jz .failure                     ; Zero-length file
1031                 mov [bx+4],eax
1032
1033                 mov cl,[ClustShift]
1034                 mov dx,[gs:si+20]               ; High cluster word
1035                 shl edx,16
1036                 mov dx,[gs:si+26]               ; Low cluster word
1037                 sub edx,2
1038                 shl edx,cl
1039                 add edx,[DataArea]
1040                 mov [bx],edx                    ; Starting sector
1041
1042                 mov eax,[gs:si+28]              ; File length again
1043                 mov dx,[gs:si+30]               ; 16-bitism, sigh
1044                 mov si,bx
1045                 and eax,eax                     ; ZF <- 0
1046
1047                 pop es
1048                 pop gs
1049                 ret
1050
1051 ;
1052 ; writechr:     Write a single character in AL to the console without
1053 ;               mangling any registers; handle video pages correctly.
1054 ;
1055 writechr:
1056                 call write_serial       ; write to serial port if needed
1057                 pushfd
1058                 pushad
1059                 mov ah,0Eh
1060                 mov bl,07h              ; attribute
1061                 mov bh,[cs:BIOS_page]   ; current page
1062                 int 10h
1063                 popad
1064                 popfd
1065                 ret
1066
1067 ;
1068 ;
1069 ; kaboom2: once everything is loaded, replace the part of kaboom
1070 ;          starting with "kaboom.patch" with this part
1071
1072 kaboom2:
1073                 mov si,err_bootfailed
1074                 call cwritestr
1075                 call getchar
1076                 call vgaclearmode
1077                 int 19h                 ; And try once more to boot...
1078 .norge:         jmp short .norge        ; If int 19h returned; this is the end
1079
1080 ;
1081 ; mangle_name: Mangle a DOS filename pointed to by DS:SI into a buffer pointed
1082 ;              to by ES:DI; ends on encountering any whitespace
1083 ;
1084
1085 mangle_name:
1086                 mov cx,11                       ; # of bytes to write
1087 mn_loop:
1088                 lodsb
1089                 cmp al,' '                      ; If control or space, end
1090                 jna mn_end
1091                 cmp al,'.'                      ; Period -> space-fill
1092                 je mn_is_period
1093                 cmp al,'a'
1094                 jb mn_not_lower
1095                 cmp al,'z'
1096                 ja mn_not_uslower
1097                 sub al,020h
1098                 jmp short mn_not_lower
1099 mn_is_period:   mov al,' '                      ; We need to space-fill
1100 mn_period_loop: cmp cx,3                        ; If <= 3 characters left
1101                 jbe mn_loop                     ; Just ignore it
1102                 stosb                           ; Otherwise, write a period
1103                 loop mn_period_loop             ; Dec CX and (always) jump
1104 mn_not_uslower: cmp al,ucase_low
1105                 jb mn_not_lower
1106                 cmp al,ucase_high
1107                 ja mn_not_lower
1108                 mov bx,ucase_tab-ucase_low
1109                 cs xlatb
1110 mn_not_lower:   stosb
1111                 loop mn_loop                    ; Don't continue if too long
1112 mn_end:
1113                 mov al,' '                      ; Space-fill name
1114                 rep stosb                       ; Doesn't do anything if CX=0
1115                 ret                             ; Done
1116
1117 ;
1118 ; Upper-case table for extended characters; this is technically code page 865,
1119 ; but code page 437 users will probably not miss not being able to use the
1120 ; cent sign in kernel images too much :-)
1121 ;
1122 ; The table only covers the range 129 to 164; the rest we can deal with.
1123 ;
1124 ucase_low       equ 129
1125 ucase_high      equ 164
1126 ucase_tab       db 154, 144, 'A', 142, 'A', 143, 128, 'EEEIII'
1127                 db 142, 143, 144, 146, 146, 'O', 153, 'OUUY', 153, 154
1128                 db 157, 156, 157, 158, 159, 'AIOU', 165
1129
1130 ;
1131 ; unmangle_name: Does the opposite of mangle_name; converts a DOS-mangled
1132 ;                filename to the conventional representation.  This is needed
1133 ;                for the BOOT_IMAGE= parameter for the kernel.
1134 ;                NOTE: A 13-byte buffer is mandatory, even if the string is
1135 ;                known to be shorter.
1136 ;
1137 ;                DS:SI -> input mangled file name
1138 ;                ES:DI -> output buffer
1139 ;
1140 ;                On return, DI points to the first byte after the output name,
1141 ;                which is set to a null byte.
1142 ;
1143 unmangle_name:
1144                 push si                 ; Save pointer to original name
1145                 mov cx,8
1146                 mov bp,di
1147 un_copy_body:   lodsb
1148                 call lower_case
1149                 stosb
1150                 cmp al,' '
1151                 jbe un_cb_space
1152                 mov bp,di               ; Position of last nonblank+1
1153 un_cb_space:    loop un_copy_body
1154                 mov di,bp
1155                 mov al,'.'              ; Don't save
1156                 stosb
1157                 mov cx,3
1158 un_copy_ext:    lodsb
1159                 call lower_case
1160                 stosb
1161                 cmp al,' '
1162                 jbe un_ce_space
1163                 mov bp,di
1164 un_ce_space:    loop un_copy_ext
1165                 mov di,bp
1166                 mov byte [es:di], 0
1167                 pop si
1168                 ret
1169
1170 ;
1171 ; lower_case: Lower case a character in AL
1172 ;
1173 lower_case:
1174                 cmp al,'A'
1175                 jb lc_ret
1176                 cmp al,'Z'
1177                 ja lc_1
1178                 or al,20h
1179                 ret
1180 lc_1:           cmp al,lcase_low
1181                 jb lc_ret
1182                 cmp al,lcase_high
1183                 ja lc_ret
1184                 push bx
1185                 mov bx,lcase_tab-lcase_low
1186                 cs xlatb
1187                 pop bx
1188 lc_ret:         ret
1189
1190 ;
1191 ; getfssec_edx: Get multiple sectors from a file
1192 ;
1193 ;       This routine makes sure the subtransfers do not cross a 64K boundary,
1194 ;       and will correct the situation if it does, UNLESS *sectors* cross
1195 ;       64K boundaries.
1196 ;
1197 ;       ES:BX   -> Buffer
1198 ;       EDX     -> Current sector number
1199 ;       CX      -> Sector count (0FFFFh = until end of file)
1200 ;                  Must not exceed the ES segment
1201 ;       Returns EDX=0, CF=1 on EOF (not necessarily error)
1202 ;       All arguments are advanced to reflect data read.
1203 ;
1204 getfssec_edx:
1205                 push ebp
1206                 push eax
1207 .getfragment:
1208                 xor ebp,ebp                     ; Fragment sector count
1209 .getseccnt:
1210                 inc bp
1211                 dec cx
1212                 jz .do_read
1213                 xor eax,eax
1214                 mov ax,es
1215                 shl ax,4
1216                 add ax,bx                       ; Now DI = how far into 64K block we are
1217                 not ax                          ; Bytes left in 64K block
1218                 inc eax
1219                 shr eax,SECTOR_SHIFT            ; Sectors left in 64K block
1220                 cmp bp,ax
1221                 jnb .do_read                    ; Unless there is at least 1 more sector room...
1222                 lea eax,[edx+1]                 ; Linearly next sector
1223                 call nextsector
1224                 jc .do_read
1225                 cmp edx,eax
1226                 jz .getseccnt
1227 .do_read:
1228                 mov eax,edx
1229                 call getlinsecsr
1230                 lea eax,[eax+ebp-1]             ; This is the last sector actually read
1231                 shl bp,9
1232                 add bx,bp                       ; Adjust buffer pointer
1233                 call nextsector
1234                 jc .eof
1235                 mov edx,eax
1236                 and cx,cx
1237                 jnz .getfragment
1238 .done:
1239                 pop eax
1240                 pop ebp
1241                 ret
1242 .eof:
1243                 xor edx,edx
1244                 stc
1245                 jmp .done
1246
1247 ;
1248 ; getfssec: Get multiple sectors from a file
1249 ;
1250 ;       Same as above, except SI is a pointer to a open_file_t
1251 ;
1252 ;       ES:BX   -> Buffer
1253 ;       DS:SI   -> Pointer to open_file_t
1254 ;       CX      -> Sector count (0FFFFh = until end of file)
1255 ;                  Must not exceed the ES segment
1256 ;       Returns CF=1 on EOF (not necessarily error)
1257 ;       All arguments are advanced to reflect data read.
1258 ;
1259 getfssec:
1260                 push edx
1261                 movzx edx,cx
1262                 cmp edx,[si+4]
1263                 jbe .sizeok
1264                 mov edx,[si+4]
1265                 mov cx,dx
1266 .sizeok:
1267                 sub [si+4],edx
1268                 mov edx,[si]
1269                 call getfssec_edx
1270                 mov [si],edx
1271                 pop edx
1272                 ret
1273
1274 ;
1275 ; nextcluster: Advance a cluster pointer in EDI to the next cluster
1276 ;              pointed at in the FAT tables.  CF=0 on return if end of file.
1277 ;
1278 nextcluster:
1279                 jmp strict short nextcluster_fat28      ; This gets patched
1280
1281 nextcluster_fat12:
1282                 push eax
1283                 push edx
1284                 push bx
1285                 push cx
1286                 push si
1287                 mov edx,edi
1288                 shr edi,1
1289                 pushf                   ; Save the shifted-out LSB (=CF)
1290                 add edx,edi
1291                 mov eax,edx
1292                 shr eax,9
1293                 call getfatsector
1294                 mov bx,dx
1295                 and bx,1FFh
1296                 mov cl,[gs:si+bx]
1297                 inc edx
1298                 mov eax,edx
1299                 shr eax,9
1300                 call getfatsector
1301                 mov bx,dx
1302                 and bx,1FFh
1303                 mov ch,[gs:si+bx]
1304                 popf
1305                 jnc .even
1306                 shr cx,4
1307 .even:          and cx,0FFFh
1308                 movzx edi,cx
1309                 cmp di,0FF0h
1310                 pop si
1311                 pop cx
1312                 pop bx
1313                 pop edx
1314                 pop eax
1315                 ret
1316
1317 ;
1318 ; FAT16 decoding routine.
1319 ;
1320 nextcluster_fat16:
1321                 push eax
1322                 push si
1323                 push bx
1324                 mov eax,edi
1325                 shr eax,SECTOR_SHIFT-1
1326                 call getfatsector
1327                 mov bx,di
1328                 add bx,bx
1329                 and bx,1FEh
1330                 movzx edi,word [gs:si+bx]
1331                 cmp di,0FFF0h
1332                 pop bx
1333                 pop si
1334                 pop eax
1335                 ret
1336 ;
1337 ; FAT28 ("FAT32") decoding routine.
1338 ;
1339 nextcluster_fat28:
1340                 push eax
1341                 push si
1342                 push bx
1343                 mov eax,edi
1344                 shr eax,SECTOR_SHIFT-2
1345                 call getfatsector
1346                 mov bx,di
1347                 add bx,bx
1348                 add bx,bx
1349                 and bx,1FCh
1350                 mov edi,dword [gs:si+bx]
1351                 and edi,0FFFFFFFh       ; 28 bits only
1352                 cmp edi,0FFFFFF0h
1353                 pop bx
1354                 pop si
1355                 pop eax
1356                 ret
1357
1358 ;
1359 ; nextsector:   Given a sector in EAX on input, return the next sector
1360 ;               of the same filesystem object, which may be the root
1361 ;               directory or a cluster chain.  Returns  EOF.
1362 ;
1363 ;               Assumes CS == DS.
1364 ;
1365 nextsector:
1366                 push edi
1367                 push edx
1368                 mov edx,[DataArea]
1369                 mov edi,eax
1370                 sub edi,edx
1371                 jae .isdata
1372
1373                 ; Root directory
1374                 inc eax
1375                 cmp eax,edx
1376                 cmc
1377                 jmp .done
1378
1379 .isdata:
1380                 not edi
1381                 test edi,[ClustMask]
1382                 jz .endcluster
1383
1384                 ; It's not the final sector in a cluster
1385                 inc eax
1386                 jmp .done
1387
1388 .endcluster:
1389                 push gs                 ; nextcluster trashes gs
1390                 push cx
1391                 not edi
1392                 mov cl,[ClustShift]
1393                 shr edi,cl
1394                 add edi,2
1395
1396                 ; Now EDI contains the cluster number
1397                 call nextcluster
1398                 cmc
1399                 jc .exit                ; There isn't anything else...
1400
1401                 ; New cluster number now in EDI
1402                 sub edi,2
1403                 shl edi,cl              ; CF <- 0, unless something is very wrong
1404                 lea eax,[edi+edx]
1405 .exit:
1406                 pop cx
1407                 pop gs
1408 .done:
1409                 pop edx
1410                 pop edi
1411                 ret
1412
1413 ;
1414 ; getfatsector: Check for a particular sector (in EAX) in the FAT cache,
1415 ;               and return a pointer in GS:SI, loading it if needed.
1416 ;
1417 ;               Assumes CS == DS.
1418 ;
1419 getfatsector:
1420                 add eax,[FAT]           ; FAT starting address
1421                 jmp getcachesector
1422
1423 ; -----------------------------------------------------------------------------
1424 ;  Common modules
1425 ; -----------------------------------------------------------------------------
1426
1427 %include "getc.inc"             ; getc et al
1428 %include "conio.inc"            ; Console I/O
1429 %include "writestr.inc"         ; String output
1430 %include "parseconfig.inc"      ; High-level config file handling
1431 %include "parsecmd.inc"         ; Low-level config file handling
1432 %include "bcopy32.inc"          ; 32-bit bcopy
1433 %include "loadhigh.inc"         ; Load a file into high memory
1434 %include "font.inc"             ; VGA font stuff
1435 %include "graphics.inc"         ; VGA graphics
1436 %include "highmem.inc"          ; High memory sizing
1437 %include "strcpy.inc"           ; strcpy()
1438 %include "cache.inc"            ; Metadata disk cache
1439
1440 ; -----------------------------------------------------------------------------
1441 ;  Begin data section
1442 ; -----------------------------------------------------------------------------
1443
1444                 section .data
1445 ;
1446 ; Lower-case table for codepage 865
1447 ;
1448 lcase_low       equ 128
1449 lcase_high      equ 165
1450 lcase_tab       db 135, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138
1451                 db 139, 140, 141, 132, 134, 130, 145, 145, 147, 148, 149
1452                 db 150, 151, 152, 148, 129, 155, 156, 155, 158, 159, 160
1453                 db 161, 162, 163, 164, 164
1454
1455 copyright_str   db ' Copyright (C) 1994-', year, ' H. Peter Anvin'
1456                 db CR, LF, 0
1457 boot_prompt     db 'boot: ', 0
1458 wipe_char       db BS, ' ', BS, 0
1459 err_notfound    db 'Could not find kernel image: ',0
1460 err_notkernel   db CR, LF, 'Invalid or corrupt kernel image.', CR, LF, 0
1461 err_noram       db 'It appears your computer has less than '
1462                 asciidec dosram_k
1463                 db 'K of low ("DOS")'
1464                 db CR, LF
1465                 db 'RAM.  Linux needs at least this amount to boot.  If you get'
1466                 db CR, LF
1467                 db 'this message in error, hold down the Ctrl key while'
1468                 db CR, LF
1469                 db 'booting, and I will take your word for it.', CR, LF, 0
1470 err_badcfg      db 'Unknown keyword in syslinux.cfg.', CR, LF, 0
1471 err_noparm      db 'Missing parameter in syslinux.cfg.', CR, LF, 0
1472 err_noinitrd    db CR, LF, 'Could not find ramdisk image: ', 0
1473 err_nohighmem   db 'Not enough memory to load specified kernel.', CR, LF, 0
1474 err_highload    db CR, LF, 'Kernel transfer failure.', CR, LF, 0
1475 err_oldkernel   db 'Cannot load a ramdisk with an old kernel image.'
1476                 db CR, LF, 0
1477 err_notdos      db ': attempted DOS system call', CR, LF, 0
1478 err_comlarge    db 'COMBOOT image too large.', CR, LF, 0
1479 err_a20         db CR, LF, 'A20 gate not responding!', CR, LF, 0
1480 err_bootfailed  db CR, LF, 'Boot failed: please change disks and press '
1481                 db 'a key to continue.', CR, LF, 0
1482 ready_msg       db 'Ready.', CR, LF, 0
1483 crlfloading_msg db CR, LF
1484 loading_msg     db 'Loading ', 0
1485 dotdot_msg      db '.'
1486 dot_msg         db '.', 0
1487 aborted_msg     db ' aborted.'                  ; Fall through to crlf_msg!
1488 crlf_msg        db CR, LF
1489 null_msg        db 0
1490 crff_msg        db CR, FF, 0
1491 syslinux_cfg    db 'SYSLINUXCFG'                ; Mangled form
1492 ConfigName      db 'syslinux.cfg',0             ; Unmangled form
1493 %if IS_MDSLINUX
1494 manifest        db 'MANIFEST   '
1495 %endif
1496 ;
1497 ; Command line options we'd like to take a look at
1498 ;
1499 ; mem= and vga= are handled as normal 32-bit integer values
1500 initrd_cmd      db 'initrd='
1501 initrd_cmd_len  equ 7
1502
1503 ;
1504 ; Config file keyword table
1505 ;
1506 %include "keywords.inc"
1507
1508 ;
1509 ; Extensions to search for (in *forward* order).
1510 ;
1511 exten_table:    db 'CBT',0              ; COMBOOT (specific)
1512                 db 'BSS',0              ; Boot Sector (add superblock)
1513                 db 'BS ',0              ; Boot Sector 
1514                 db 'COM',0              ; COMBOOT (same as DOS)
1515                 db 'C32',0              ; COM32
1516 exten_table_end:
1517                 dd 0, 0                 ; Need 8 null bytes here
1518
1519 ;
1520 ; Misc initialized (data) variables
1521 ;
1522 %ifdef debug                            ; This code for debugging only
1523 debug_magic     dw 0D00Dh               ; Debug code sentinel
1524 %endif
1525
1526                 alignb 4, db 0
1527 BufSafe         dw trackbufsize/SECTOR_SIZE     ; Clusters we can load into trackbuf
1528 BufSafeSec      dw trackbufsize/SECTOR_SIZE     ; = how many sectors?
1529 BufSafeBytes    dw trackbufsize         ; = how many bytes?
1530 EndOfGetCBuf    dw getcbuf+trackbufsize ; = getcbuf+BufSafeBytes
1531 %ifndef DEPEND
1532 %if ( trackbufsize % SECTOR_SIZE ) != 0
1533 %error trackbufsize must be a multiple of SECTOR_SIZE
1534 %endif
1535 %endif
1536
1537                 align 4, db 0           ; Pad out any unfinished dword
1538 ldlinux_end     equ $