fc80a1539899e5550e7e7b05b6de76b378f23826
[external/syslinux.git] / core / diskfs.inc
1 ; -*- fundamental -*- (asm-mode sucks)
2 ; -----------------------------------------------------------------------
3 ;   
4 ;   Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
5 ;   Copyright 2009-2011 Intel Corporation; author: H. Peter Anvin
6 ;
7 ;   This program is free software; you can redistribute it and/or modify
8 ;   it under the terms of the GNU General Public License as published by
9 ;   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
10 ;   Boston MA 02110-1301, USA; either version 2 of the License, or
11 ;   (at your option) any later version; incorporated herein by reference.
12 ;
13 ; -----------------------------------------------------------------------
14
15 ;
16 ; diskfs.inc
17 ;
18 ; Common code for conventional disk-based filesystems
19 ;
20
21 ;
22 ; Some semi-configurable constants... change on your own risk.
23 ;
24 NULLFILE        equ 0                   ; Null character == empty filename
25 NULLOFFSET      equ 0                   ; Position in which to look
26 retry_count     equ 16                  ; How patient are we with the disk?
27 %assign HIGHMEM_SLOP 0                  ; Avoid this much memory near the top
28 LDLINUX_MAGIC   equ 0x3eb202fe          ; A random number to identify ourselves with
29
30 ; This indicates the general format of the last few bytes in the boot sector
31 BS_MAGIC_VER    equ 0x1b << 9
32
33 SECTOR_SHIFT    equ 9
34 SECTOR_SIZE     equ (1 << SECTOR_SHIFT)
35
36 ;
37 ; The following structure is used for "virtual kernels"; i.e. LILO-style
38 ; option labels.  The options we permit here are `kernel' and `append
39 ; Since there is no room in the bottom 64K for all of these, we
40 ; stick them in high memory and copy them down before we need them.
41 ;
42                 struc vkernel
43 vk_vname:       resb FILENAME_MAX       ; Virtual name **MUST BE FIRST!**
44 vk_rname:       resb FILENAME_MAX       ; Real name
45 vk_appendlen:   resw 1
46 vk_type:        resb 1                  ; Type of file
47                 alignb 4
48 vk_append:      resb max_cmd_len+1      ; Command line
49                 alignb 4
50 vk_end:         equ $                   ; Should be <= vk_size
51                 endstruc
52
53
54
55 ; ---------------------------------------------------------------------------
56 ;   BEGIN CODE
57 ; ---------------------------------------------------------------------------
58
59 ;
60 ; Memory below this point is reserved for the BIOS and the MBR
61 ;
62                 section .earlybss
63                 global trackbuf
64 trackbufsize    equ 8192
65 trackbuf        resb trackbufsize       ; Track buffer goes here
66                 ; ends at 2800h
67
68 ;
69 ; Common bootstrap code for disk-based derivatives
70 ;
71 %include "diskstart.inc"
72
73
74 ;
75 ; Now, everything is "up and running"... patch kaboom for more
76 ; verbosity and using the full screen system
77 ;
78                 ; E9 = JMP NEAR
79                 mov di,kaboom.patch
80                 mov al,0e9h
81                 stosb
82                 mov ax,kaboom2-2
83                 sub ax,di
84                 stosw
85
86 ;
87 ; Now we're all set to start with our *real* business.  First load the
88 ; configuration file (if any) and parse it.
89 ;
90 ; In previous versions I avoided using 32-bit registers because of a
91 ; rumour some BIOSes clobbered the upper half of 32-bit registers at
92 ; random.  I figure, though, that if there are any of those still left
93 ; they probably won't be trying to install Linux on them...
94 ;
95 ; The code is still ripe with 16-bitisms, though.  Not worth the hassle
96 ; to take'm out.  In fact, we may want to put them back if we're going
97 ; to boot ELKS at some point.
98 ;
99
100 ;
101 ; Load configuration file
102 ;
103                 pm_call pm_load_config
104                 jz no_config_file
105
106 ;
107 ; Now we have the config file open.  Parse the config file and
108 ; run the user interface.
109 ;
110 %include "ui.inc"
111
112 ;
113 ;
114 ; kaboom2: once everything is loaded, replace the part of kaboom
115 ;          starting with "kaboom.patch" with this part
116
117 kaboom2:
118                 mov si,err_bootfailed
119                 call writestr
120                 cmp byte [kaboom.again+1],18h   ; INT 18h version?
121                 je .int18
122                 call getchar
123                 call vgaclearmode
124                 int 19h                 ; And try once more to boot...
125 .norge:         jmp short .norge        ; If int 19h returned; this is the end
126 .int18:
127                 call vgaclearmode
128                 int 18h
129 .noreg:         jmp short .noreg        ; Nynorsk
130
131 ; -----------------------------------------------------------------------------
132 ;  Common modules
133 ; -----------------------------------------------------------------------------
134
135 %include "common.inc"           ; Universal modules
136 %include "plaincon.inc"         ; writechr
137 %include "writestr.inc"         ; String output
138 %include "writehex.inc"         ; Hexadecimal output
139 %include "localboot.inc"        ; Disk-based local boot
140
141 ; -----------------------------------------------------------------------------
142 ;  Begin data section
143 ; -----------------------------------------------------------------------------
144
145                 section .data16
146 copyright_str   db ' Copyright (C) 1994-'
147                 asciidec YEAR
148                 db ' H. Peter Anvin et al', CR, LF, 0
149 err_bootfailed  db CR, LF, 'Boot failed: please change disks and press '
150                 db 'a key to continue.', CR, LF, 0
151
152 ;
153 ; Config file keyword table
154 ;
155 %include "keywords.inc"
156
157 ;
158 ; Extensions to search for (in *forward* order).
159 ;
160                 alignz 4
161 exten_table:    db '.cbt'               ; COMBOOT (specific)
162 %if IS_SYSLINUX
163                 db '.bss'               ; Boot sector (add superblock)
164 %endif
165                 db '.bs', 0             ; Boot sector
166                 db '.com'               ; COMBOOT (same as DOS)
167                 db '.c32'               ; COM32
168 exten_table_end:
169                 dd 0, 0                 ; Need 8 null bytes here
170
171 ;
172 ; Misc initialized (data) variables
173 ;
174 %ifdef debug                            ; This code for debugging only
175 debug_magic     dw 0D00Dh               ; Debug code sentinel
176 %endif