wok view linux/stuff/linux-header-2.6.37.u @ rev 11514

kino: update bdeps
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Dec 23 10:13:02 2011 +0100 (2011-12-23)
parents
children
line source
1 --- linux-2.6.30.6/arch/x86/boot/header.S
2 +++ linux-2.6.30.6/arch/x86/boot/header.S
3 @@ -6,7 +6,7 @@
4 * Based on bootsect.S and setup.S
5 * modified by more people than can be counted
6 *
7 - * Rewritten as a common file by H. Peter Anvin (Apr 2007)
8 + * Rewritten Pascal Bellard (Nov 2009)
9 *
10 * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment
11 * addresses must be multiplied by 16 to obtain their respective linear
12 @@ -27,6 +27,8 @@
14 BOOTSEG = 0x07C0 /* original address of boot-sector */
15 SYSSEG = 0x1000 /* historical load address >> 4 */
16 +INITSEG = 0x9000 /* boot address >> 4 */
17 +SETUPSEG = 0x9020 /* setup address >> 4 */
19 #ifndef SVGA_MODE
20 #define SVGA_MODE ASK_VGA
21 @@ -40,53 +42,412 @@
22 #define ROOT_RDONLY 1
23 #endif
25 +/* some extra features */
26 +#define EDIT_CMDLINE on hotkey
27 +#define SHOW_REGS show int13 status & parameters
28 +
29 .code16
30 .section ".bstext", "ax"
32 .global bootsect_start
33 bootsect_start:
34 + cld # assume nothing
35 +stacktop = 0x9E00 # in 0x8000 .. 0xA000
36 +zeroed = 48+10 # gdt + zeroed registers
37 + movw $stacktop-12-zeroed, %di # stacktop is an arbitrary value >=
38 + # length of bootsect + length of
39 + # setup + room for stack;
40 + # 12 is disk parm size.
41 + pushw $INITSEG
42 + popw %es # %es = INITSEG
43 +
44 + pushw %es
45 + popw %ss # %ss and %es already contain INITSEG
46 + movw %di, %sp # put stack at INITSEG:stacktop-...
47 +
48 +# Many BIOS's default disk parameter tables will not recognize
49 +# multi-sector reads beyond the maximum sector number specified
50 +# in the default diskette parameter tables - this may mean 7
51 +# sectors in some cases.
52 +#
53 +# Since single sector reads are slow and out of the question,
54 +# we must take care of this by creating new parameter tables
55 +# (for the first disk) in RAM. We can set the maximum sector
56 +# count to 36 - the most we will encounter on an ED 2.88.
57 +#
58 +# High doesn't hurt. Low does. Let's use the max: 63
59 +#
60 +# Segments are as follows: %es = %ss = INITSEG,
61 +
62 + xorw %ax, %ax # %ax = 0
63 + movw $zeroed/2, %cx # clear gdt + offset, %ds, limits
64 + rep # don't worry about cld
65 + stosw # already done above
66 + popw %bx # offset = 0
67 + popw %ds # %ds = 0
68 + popw %gs # %gs = 0
69 +
70 + movb setup_sects+0x7C00, %al # read bootsector + setup (%ds = 0)
71 + incw %ax
72 +
73 + pushw %es
74 + pushw %di # %ds:%bx+0x78 is parameter table address
75 + ldsw 0x78(%bx), %si # %ds:%si is source
76 + movb $6, %cl # copy 12 bytes
77 + rep # don't worry about cld
78 + movsw # already done above
79 + popl %gs:0x78(%bx) # update parameter table address
80 + pushw %es
81 + popw %ds # now %ds = %es = %ss = INITSEG
82 + movb $63, 0x4-12(%di) # patch sector count, %di = stacktop
83 + cli
84 +
85 + xchg %ax, %di # sector count
86 + popw %ax # limits = 0
87 + incw %cx # cylinder 0, sector 1
88 + call read_first_sectors # read setup
89 +
90 +offset_version = 0xE
91 + movw $0x200,%si
92 + addw offset_version(%si),%si # starting protocol 2.00, Kernel 1.3.73
93 + call putstr # show which kernel we are loading
94 +
95 +# The cmdline can be entered and modifed at boot time.
96 +# Only characters before the cursor are passed to the kernel.
97 + popw %bx # clear %bx
98 + orw cmd_line_ptr, %bx
99 + jz nocmdline
100 + pushw %bx
101 + incw %di
102 + call read_sectors
103 + popw %si
104 + call putstr
105 +#ifdef EDIT_CMDLINE
106 +cmdlp:
107 + movb $0x20, %al # clear end of line
108 + int $0x10 # with Space
109 + movb $8, %al # and BackSpace
110 + int $0x10
111 + decw %si
112 +cmdget:
113 + call wait4key
114 + cmpb $8, %al # BackSpace ?
115 + je cmdbs
116 + movb %al, (%si) # store char
117 + lodsw # %si += 2
118 +cmdbs:
119 +#if 1
120 + cmpw %si,cmd_line_ptr
121 + je cmdget
122 +#endif
123 + call putc # set %ah and %bx
124 + cmpb $10, %al # Enter ?
125 + jne cmdlp
126 + movb %bh,-2(%si) # set end of string and remove CR
127 +endcmdline:
128 +#endif
129 +nocmdline:
131 - # Normalize the start address
132 - ljmp $BOOTSEG, $start2
133 -
134 -start2:
135 - movw %cs, %ax
136 - movw %ax, %ds
137 - movw %ax, %es
138 - movw %ax, %ss
139 - xorw %sp, %sp
140 - sti
141 - cld
142 -
143 - movw $bugger_off_msg, %si
144 +# This routine loads the system at address SYSSEG, making sure
145 +# no 64kB boundaries are crossed. We try to load it as fast as
146 +# possible, loading whole tracks whenever we can.
147 +
148 +ramdisk_image = 0x0218
149 +ramdisk_size = 0x021C
150 + movw %sp, %si # for bootsect_gdt
151 + decw 16(%si) # bootsect_src = 64Kb
152 + decw 24(%si) # bootsect_dst = 64Kb
153 + movw $syssize, %di
154 +type_of_loader = 0x210
155 +loadflags = 0x211
156 +heap_end_ptr = 0x224
157 +ksyssize = 500
158 + orw $0x80FF, type_of_loader-ksyssize(%di) # loader type = 0xFF
159 + movw $stacktop-0x200, heap_end_ptr-ksyssize(%di)
160 + movb $0x10, %al # destination = 0x100000
161 + movb $5, %cl
162 +initrdlp:
163 + decw %ax
164 + movb $0x93,%ah
165 + movw %ax, 28(%si) # bootsect_dst_base+2
166 + movb $(SYSSEG/4096), %al # source = SYSSEG
167 + movw %ax, 20(%si) # bootsect_src_base+2
168 + cbw
169 + cwde
170 + shlw %cl, %ax
171 + decw %ax
172 + addl (%di),%eax
173 + shrl %cl, %eax
174 +syslp:
175 + pushw $SYSSEG
176 + popw %es
177 + movw $128,%di # 64Kb
178 + subw %di, %ax # max 32M > int 15 limit
179 + pushf
180 + jnc not_last
181 + addw %ax, %di
182 +not_last:
183 + xorw %bx, %bx # clear %bx
184 + pushw %ax
185 +#if defined(SHOW_REGS)
186 + pushw %si
187 + call read_sectors
188 + popw %si
189 +#else
190 + call read_sectors
191 +#endif
192 + movw $0x8000, %cx # full 64K
193 + movb $0x87, %ah
194 + incb 28(%si) # bootsect_dst_base+2
195 + int $0x15 # max 16M
196 + popw %ax
197 + popf
198 + ja syslp
199 + movw ramdisk_image+2,%ax
200 + movw $ramdisk_size,%di
201 + movb $9, %cl
202 + cmpb %al,28(%si)
203 + jb initrdlp
204 +
205 +# This procedure turns off the floppy drive motor, so
206 +# that we enter the kernel in a known state, and
207 +# don't have to worry about it later.
208 +
209 +#if 1
210 +kill_motor:
211 + xchgw %ax, %bx # reset FDC
212 + int $0x13
213 +#else
214 +kill_motor:
215 + movw $0x3f2, %dx
216 + xchgw %ax, %bx
217 + outb %al, %dx
218 +#endif
220 -msg_loop:
221 - lodsb
222 - andb %al, %al
223 - jz bs_die
224 - movb $0xe, %ah
225 - movw $7, %bx
226 +# After that (everything loaded), we jump to the setup-routine
227 +# loaded directly after the bootblock:
228 +# Segments are as follows: %ds = %ss = INITSEG
229 +
230 + ljmp $SETUPSEG, $0
231 +
232 +# read_sectors reads %di sectors into %es:0 buffer.
233 +# %es:0 is updated to the next memory location.
234 +# First, sectors are read sector by sector until
235 +# sector per track count is known. Then they are
236 +# read track by track.
237 +# Assume no error on first track.
238 +
239 +#define FLOPPY_CYLINDERS 80 /* 80 cylinders minimum */
240 +#define FLOPPY_HEADS 2 /* 2 heads minimum */
241 +#define FLOPPY_SECTORS 18 /* 18 sectors minimum */
242 +
243 +#ifdef SHOW_REGS
244 +print_loop:
245 + movb $0x6 + 'A' - 1, %al
246 + subb %cl, %al
247 + movw $regs, %si # caller %si is saved
248 + call putcs # putc(%al) + putstr(%si)
249 +# it will print out all of the registers.
250 + popw %bp # load word into %si
251 + jmp print_all # print %bp (status)
252 +#endif
253 +check_limits:
254 +#ifndef SHOW_REGS
255 + popw %dx
256 +#endif
257 + cmpb $FLOPPY_SECTORS+1, %cl # 18 sectors minimum
258 + jb check_head
259 + cmpb %al, %cl # max sector known ?
260 + ja next_head # no -> store it
261 +check_head:
262 + cmpb $FLOPPY_HEADS, %dh # 2 heads minimum
263 + jb check_cylinder
264 + cmpb %ah, %dh # max head known ?
265 + ja next_cylinder # no -> store it
266 +check_cylinder:
267 + pushaw
268 +#ifdef SHOW_REGS
269 + cmpw $0x600,%bp # disk changed ?
270 + je reset_floppy
271 + pushw %es # print %es (named EX)
272 + pushw %dx # print %dx
273 + pushw %cx # print %cx
274 + pushw %bx # print %bx
275 + xchgw %ax, %si
276 + movb $2,%ah
277 + pushw %ax # print %ax
278 + movb $6,%cl
279 +print_all:
280 + movb $4, %ch # 4 hex digits
281 +print_digit:
282 + rolw $4, %bp # rotate to use low 4 bits
283 + movb $0x0f, %al
284 + andw %bp, %ax # %al = mask for nybble
285 + addb $0x90, %al # convert %al to ascii hex
286 + daa # in only four instructions!
287 + adcb $0x40, %al
288 + daa
289 + call putc # set %ah and %bx
290 + decb %ch
291 + jnz print_digit
292 + movb $0x20, %al # SPACE
293 int $0x10
294 - jmp msg_loop
295 -
296 -bs_die:
297 - # Allow the user to press a key, then reboot
298 - xorw %ax, %ax
299 + loop print_loop
300 + call wait
301 + cbw # %ah = 0
302 +reset_floppy:
303 +#else
304 + cbw # %ah = 0
305 +#endif
306 + int $0x13 # reset controler
307 + popaw
308 +read_sectorslp:
309 + pushw %dx # some bios break dx...
310 + pushw %ax # limits
311 + subb %cl, %al # sectors remaining in track
312 + ja tolastsect
313 + movb $1, %al # 1 sector mini
314 +tolastsect:
315 + cbw
316 + cmpw %di, %ax
317 + jb more1trk
318 + movw %di, %ax # sectors to read
319 +more1trk:
320 + pushw %ax # save context
321 + movb $2, %ah # cmd: read chs
322 + int $0x13
323 +#ifdef SHOW_REGS
324 + xchgw %ax, %bp # status
325 +#endif
326 +# ifdef SHOW_REGS
327 + popw %si # save %ax
328 + popw %ax # limits
329 + popw %dx
330 +# else
331 + popw %dx # save %ax
332 + popw %ax # limits
333 +# endif
334 + jc check_limits
335 + xchgw %ax, %bp
336 +# ifdef SHOW_REGS
337 +update_regs:
338 + incw %cx # next sector
339 + movw %cx, %fs
340 + addb $2,%bh # next location
341 + decw %di # update sector counter
342 + jz putcdot
343 + decw %si
344 + jnz update_regs
345 +# else
346 + addw %dx,%cx # next sector
347 + addb %dl,%bh
348 + addb %dl,%bh # next location
349 + subw %dx,%di # update sector counter
350 + popw %dx
351 + jz putcdot
352 +# endif
353 +read_sectors:
354 + movw %fs, %cx
355 + xchgw %ax, %bp
356 + cmpb %al,%cl # reach sector limit ?
357 + jne bdendlp
358 +next_head:
359 + movb %cl,%al
360 + incb %dh # next head
361 + movb $1,%cl # first sector
362 + cmpb %ah, %dh # reach head limit ?
363 + jne bdendlp
364 +next_cylinder:
365 + movb %dh,%ah
366 +# NOTE : support 256 cylinders max
367 + incb %ch # next cylinder
368 +read_first_sectors:
369 + movb $0,%dh # first head
370 +cylinder_count = 496
371 + cmpb $FLOPPY_CYLINDERS,%ch # reach cylinder limit ?
372 + jb bdendlp
373 + cmpb cylinder_count, %ch
374 + jb bdendlp
375 +next_floppy:
376 + movb $0,%ch # first cylinder
377 + pushaw
378 + movw $swap_floppy,%si
379 + incb 12(%si)
380 + pushw %bx
381 + call putstr
382 + popw %bx
383 +waitfloppy:
384 + call wait
385 + jne waitfloppydone
386 + pushw %dx # some bios break dx...
387 + cbw
388 + int $0x13 # reset FDC
389 + movw $0x201,%ax
390 +# cwd
391 +# movw $1,%cx
392 + int $0x13 # read first sector
393 + popw %dx
394 + rclb $1,%ah # floppy changed 06=>0D no error 00
395 + cmpb -2(%si), %ah # 0D then 00
396 + jne waitfloppy # no => try again
397 + incw %si
398 + orb %ah,%ah # was 00 ?
399 + jne waitfloppy
400 +waitfloppydone:
401 + popaw
402 +bdendlp:
403 + jmp read_sectorslp
404 +
405 +putcdot:
406 + pushw %ss
407 + popw %es # restore es
408 + movb $0x2e+3, %al # loading... message 2e = .
409 +putclf:
410 + subb $3, %al
411 +putc:
412 + movb $0xe, %ah
413 + movw $7, %bx # one dot each 64k
414 + int $0x10
415 + cmp $0xd, %al # CR ?
416 + je putclf
417 + ret
418 +
419 +putstr:
420 + movb $0xd, %al # CR
421 +putcs:
422 + call putc
423 + lodsb
424 + orb %al,%al # end of string is \0
425 + jnz putcs
426 + ret
427 +
428 +clock = 0x46C
429 +wait:
430 +wait4key:
431 + movw $clock, %di
432 +#define DELAY 5
433 + movb $(DELAY*182)/10,%cl
434 + addb %gs:(%di),%cl
435 +waitkbd:
436 + movw $0x10D, %ax # test keyboard, timeout => CR
437 + cmpb %gs:(%di),%cl
438 + je waitdone
439 int $0x16
440 - int $0x19
441 + jz waitkbd
442 + cbw
443 + int $0x16 # eat char
444 + movw %di, %gs # disable timeout
445 + incw %di # clear Z
446 +waitdone:
447 + ret
449 - # int 0x19 should never return. In case it does anyway,
450 - # invoke the BIOS reset code...
451 - ljmp $0xf000,$0xfff0
452 -
453 - .section ".bsdata", "a"
454 -bugger_off_msg:
455 - .ascii "Direct booting from floppy is no longer supported.\r\n"
456 - .ascii "Please use a boot loader program instead.\r\n"
457 - .ascii "\n"
458 - .ascii "Remove disk and press any key to reboot . . .\r\n"
459 - .byte 0
460 +#ifdef SHOW_REGS
461 +regs: .asciz "X:"
462 +#endif
464 +swap_floppy: .ascii "Insert disk 1"
465 + .ascii "."
466 + .byte 7,13,0
468 # Kernel attributes; used by setup. This is part 1 of the
469 # header, from the old boot sector.