1 ; -*- fundamental -*- (asm-mode sucks)
2 ; ****************************************************************************
6 ; A program to boot Linux kernels off an MS-DOS formatted floppy disk. This
7 ; functionality is good to have for installation floppies, where it may
8 ; be hard to find a functional Linux system to run LILO off.
10 ; This program allows manipulation of the disk to take place entirely
11 ; from MS-LOSS, and can be especially useful in conjunction with the
14 ; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
15 ; Copyright 2009 Intel Corporation; author: H. Peter Anvin
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.
23 ; ****************************************************************************
31 ; Some semi-configurable constants... change on your own risk.
34 FILENAME_MAX_LG2 equ 6 ; log2(Max filename size Including final null)
35 FILENAME_MAX equ (1<<FILENAME_MAX_LG2) ; Max mangled filename size
36 NULLFILE equ 0 ; First char space == null filename
37 NULLOFFSET equ 0 ; Position in which to look
38 retry_count equ 16 ; How patient are we with the disk?
39 %assign HIGHMEM_SLOP 0 ; Avoid this much memory near the top
40 LDLINUX_MAGIC equ 0x3eb202fe ; A random number to identify ourselves with
42 MAX_OPEN_LG2 equ 6 ; log2(Max number of open files)
43 MAX_OPEN equ (1 << MAX_OPEN_LG2)
46 SECTOR_SIZE equ (1 << SECTOR_SHIFT)
49 DIRENT_SIZE equ (1 << DIRENT_SHIFT)
51 ROOT_DIR_WORD equ 0x002F
54 ; The following structure is used for "virtual kernels"; i.e. LILO-style
55 ; option labels. The options we permit here are `kernel' and `append
56 ; Since there is no room in the bottom 64K for all of these, we
57 ; stick them in high memory and copy them down before we need them.
60 vk_vname: resb FILENAME_MAX ; Virtual name **MUST BE FIRST!**
61 vk_rname: resb FILENAME_MAX ; Real name
63 vk_type: resb 1 ; Type of file
65 vk_append: resb max_cmd_len+1 ; Command line
67 vk_end: equ $ ; Should be <= vk_size
71 ; File structure. This holds the information for each currently open file.
74 file_sector resd 1 ; Sector pointer (0 = structure free)
75 file_bytesleft resd 1 ; Number of bytes left
76 file_left resd 1 ; Number of sectors left
81 ; Structure for codepage files
84 .magic resd 2 ; 8-byte magic number
85 .reserved resd 6 ; Reserved for future use
86 .uppercase resb 256 ; Internal upper-case table
87 .unicode resw 256 ; Unicode matching table
88 .unicode_alt resw 256 ; Alternate Unicode matching table
92 %if (open_file_t_size & (open_file_t_size-1))
93 %error "open_file_t is not a power of 2"
97 ; ---------------------------------------------------------------------------
99 ; ---------------------------------------------------------------------------
102 ; Memory below this point is reserved for the BIOS and the MBR
105 trackbufsize equ 8192
106 trackbuf resb trackbufsize ; Track buffer goes here
111 FAT resd 1 ; Location of (first) FAT
112 RootDirArea resd 1 ; Location of root directory area
113 RootDir resd 1 ; Location of root directory proper
114 DataArea resd 1 ; Location of data area
115 RootDirSize resd 1 ; Root dir size in sectors
116 TotalSectors resd 1 ; Total number of sectors
117 ClustSize resd 1 ; Bytes/cluster
118 ClustMask resd 1 ; Sectors/cluster - 1
119 CopySuper resb 1 ; Distinguish .bs versus .bss
120 ClustShift resb 1 ; Shift count for sectors/cluster
121 ClustByteShift resb 1 ; Shift count for bytes/cluster
123 ; global syslinux_cfg_buffer
124 ;syslinux_cfg_buffer resb 28 ; the syslinux config file name buffer, used by vfat_load_config
126 alignb open_file_t_size
128 Files resb MAX_OPEN*open_file_t_size
131 ; Common bootstrap code for disk-based derivatives
133 %include "diskstart.inc"
138 ; Now, everything is "up and running"... patch kaboom for more
139 ; verbosity and using the full screen system
150 ; Now we're all set to start with our *real* business. First load the
151 ; configuration file (if any) and parse it.
153 ; In previous versions I avoided using 32-bit registers because of a
154 ; rumour some BIOSes clobbered the upper half of 32-bit registers at
155 ; random. I figure, though, that if there are any of those still left
156 ; they probably won't be trying to install Linux on them...
158 ; The code is still ripe with 16-bitisms, though. Not worth the hassle
159 ; to take'm out. In fact, we may want to put them back if we're going
160 ; to boot ELKS at some point.
164 ; Load configuration file
170 ; Now we have the config file open. Parse the config file and
171 ; run the user interface.
179 ; Deallocates a directory structure (pointer in SI)
185 mov dword [si],0 ; First dword == file_sector
193 ; kaboom2: once everything is loaded, replace the part of kaboom
194 ; starting with "kaboom.patch" with this part
197 mov si,err_bootfailed
199 cmp byte [kaboom.again+1],18h ; INT 18h version?
203 int 19h ; And try once more to boot...
204 .norge: jmp short .norge ; If int 19h returned; this is the end
208 .noreg: jmp short .noreg ; Nynorsk
213 ; unmangle_name: Does the opposite of mangle_name; converts a DOS-mangled
214 ; filename to the conventional representation. This is needed
215 ; for the BOOT_IMAGE= parameter for the kernel.
216 ; NOTE: A 13-byte buffer is mandatory, even if the string is
217 ; known to be shorter.
219 ; DS:SI -> input mangled file name
220 ; ES:DI -> output buffer
222 ; On return, DI points to the first byte after the output name,
223 ; which is set to a null byte.
225 unmangle_name: call strcpy
226 dec di ; Point to final null byte
231 ; -----------------------------------------------------------------------------
233 ; -----------------------------------------------------------------------------
235 %include "common.inc" ; Universal modules
236 %include "plaincon.inc" ; writechr
237 %include "writestr.inc" ; String output
238 %include "writehex.inc" ; Hexadecimal output
239 %include "localboot.inc" ; Disk-based local boot
241 ; -----------------------------------------------------------------------------
243 ; -----------------------------------------------------------------------------
246 copyright_str db ' Copyright (C) 1994-'
248 db ' H. Peter Anvin et al', CR, LF, 0
249 err_bootfailed db CR, LF, 'Boot failed: please change disks and press '
250 db 'a key to continue.', CR, LF, 0
251 syslinux_cfg1 db '/boot' ; /boot/syslinux/syslinux.cfg
252 syslinux_cfg2 db '/syslinux' ; /syslinux/syslinux.cfg
253 syslinux_cfg3 db '/' ; /syslinux.cfg
254 config_name db 'syslinux.cfg', 0 ; syslinux.cfg
257 ; Config file keyword table
259 %include "keywords.inc"
262 ; Extensions to search for (in *forward* order).
264 exten_table: db '.cbt' ; COMBOOT (specific)
265 db '.bss' ; Boot Sector (add superblock)
266 db '.bs', 0 ; Boot Sector
267 db '.com' ; COMBOOT (same as DOS)
270 dd 0, 0 ; Need 8 null bytes here
273 ; Misc initialized (data) variables
275 %ifdef debug ; This code for debugging only
276 debug_magic dw 0D00Dh ; Debug code sentinel
280 BufSafe dw trackbufsize/SECTOR_SIZE ; Clusters we can load into trackbuf
281 BufSafeBytes dw trackbufsize ; = how many bytes?
283 %if ( trackbufsize % SECTOR_SIZE ) != 0
284 %error trackbufsize must be a multiple of SECTOR_SIZE