direct-io.hg

view tools/misc/mbootpack/setup.S @ 7477:5a7baecb1c70

Fix an issue for passing arguement from control panel to deivce model
for some arguemnt like 'localtime', 'isa', device model need an argument
"-localtime", instead of "-localtime 1"
Signed-off-by: Xiaofeng Ling <xiaofeng.ling@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun Oct 23 16:51:47 2005 +0100 (2005-10-23)
parents 445b12a7221a
children
line source
1 /*
2 * bootsect.S
3 *
4 * This is setup.S from the linux 2.6.9 source code,
5 * with heavy cuts and changes for mbootpack
6 * November 2004 Tim Deegan <tjd21@cl.cam.ac.uk>
7 *
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
23 *
24 * $Id: setup.S,v 1.4 2005/03/23 10:39:03 tjd21 Exp $
25 *
26 */
28 #include "mbootpack.h"
30 /*
31 * setup.S Copyright (C) 1991, 1992 Linus Torvalds
32 *
33 * setup.s is responsible for getting the system data from the BIOS,
34 * and putting them into the appropriate places in system memory.
35 * both setup.s and system has been loaded by the bootblock.
36 *
37 * This code asks the bios for memory/disk/other parameters, and
38 * puts them in a "safe" place: 0x90000-0x901FF, ie where the
39 * boot-block used to be. It is then up to the protected mode
40 * system to read them from there before the area is overwritten
41 * for buffer-blocks.
42 *
43 * Move PS/2 aux init code to psaux.c
44 * (troyer@saifr00.cfsat.Honeywell.COM) 03Oct92
45 *
46 * some changes and additional features by Christoph Niemann,
47 * March 1993/June 1994 (Christoph.Niemann@linux.org)
48 *
49 * add APM BIOS checking by Stephen Rothwell, May 1994
50 * (sfr@canb.auug.org.au)
51 *
52 * High load stuff, initrd support and position independency
53 * by Hans Lermen & Werner Almesberger, February 1996
54 * <lermen@elserv.ffm.fgan.de>, <almesber@lrc.epfl.ch>
55 *
56 * Video handling moved to video.S by Martin Mares, March 1996
57 * <mj@k332.feld.cvut.cz>
58 *
59 * Extended memory detection scheme retwiddled by orc@pell.chi.il.us (david
60 * parsons) to avoid loadlin confusion, July 1997
61 *
62 * Transcribed from Intel (as86) -> AT&T (gas) by Chris Noe, May 1999.
63 * <stiker@northlink.com>
64 *
65 * Fix to work around buggy BIOSes which dont use carry bit correctly
66 * and/or report extended memory in CX/DX for e801h memory size detection
67 * call. As a result the kernel got wrong figures. The int15/e801h docs
68 * from Ralf Brown interrupt list seem to indicate AX/BX should be used
69 * anyway. So to avoid breaking many machines (presumably there was a reason
70 * to orginally use CX/DX instead of AX/BX), we do a kludge to see
71 * if CX/DX have been changed in the e801 call and if so use AX/BX .
72 * Michael Miller, April 2001 <michaelm@mjmm.org>
73 *
74 * New A20 code ported from SYSLINUX by H. Peter Anvin. AMD Elan bugfixes
75 * by Robert Schwebel, December 2001 <robert@schwebel.de>
76 */
78 /*
79 #include <linux/config.h>
80 #include <asm/segment.h>
81 #include <linux/version.h>
82 #include <linux/compile.h>
83 #include <asm/boot.h>
84 #include <asm/e820.h>
85 #include <asm/page.h>
86 */
88 /* Definitions that should have come from these includes */
89 #define DEF_INITSEG 0x9000
90 #define DEF_SYSSEG 0x1000
91 #define DEF_SETUPSEG 0x9020
92 #define DEF_SYSSIZE 0x7F00
93 #define NORMAL_VGA 0xffff
94 #define EXTENDED_VGA 0xfffe
95 #define ASK_VGA 0xfffd
96 #define GDT_ENTRY_BOOT_CS 2
97 #define __BOOT_CS (GDT_ENTRY_BOOT_CS * 8)
98 #define GDT_ENTRY_BOOT_DS (GDT_ENTRY_BOOT_CS + 1)
99 #define __BOOT_DS (GDT_ENTRY_BOOT_DS * 8)
100 #define __PAGE_OFFSET (0xC0000000)
101 #define E820MAP 0x2d0 /* our map */
102 #define E820MAX 32 /* number of entries in E820MAP */
103 #define E820NR 0x1e8 /* # entries in E820MAP */
104 #define E820_RAM 1
105 #define E820_RESERVED 2
106 #define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */
107 #define E820_NVS 4
108 #define __BIG_KERNEL__
111 /* Signature words to ensure LILO loaded us right */
112 #define SIG1 0xAA55
113 #define SIG2 0x5A5A
115 INITSEG = DEF_INITSEG # 0x9000, we move boot here, out of the way
116 SYSSEG = DEF_SYSSEG # 0x1000, system loaded at 0x10000 (65536).
117 SETUPSEG = DEF_SETUPSEG # 0x9020, this is the current segment
118 # ... and the former contents of CS
120 DELTA_INITSEG = SETUPSEG - INITSEG # 0x0020
122 .code16
123 .globl _start, begtext, begdata, begbss, endtext, enddata, endbss
125 .text
126 begtext:
127 .data
128 begdata:
129 .bss
130 begbss:
131 .text
133 _start:
134 start:
135 jmp trampoline
137 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
139 .ascii "HdrS" # header signature
140 .word 0x0203 # header version number (>= 0x0105)
141 # or else old loadlin-1.5 will fail)
142 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
143 start_sys_seg: .word SYSSEG
144 .word kernel_version # pointing to kernel version string
145 # above section of header is compatible
146 # with loadlin-1.5 (header v1.5). Don't
147 # change it.
149 type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
150 # Bootlin, SYSLX, bootsect...)
151 # See Documentation/i386/boot.txt for
152 # assigned ids
154 # flags, unused bits must be zero (RFU) bit within loadflags
155 loadflags:
156 LOADED_HIGH = 1 # If set, the kernel is loaded high
157 CAN_USE_HEAP = 0x80 # If set, the loader also has set
158 # heap_end_ptr to tell how much
159 # space behind setup.S can be used for
160 # heap purposes.
161 # Only the loader knows what is free
162 #ifndef __BIG_KERNEL__
163 .byte 0
164 #else
165 .byte LOADED_HIGH
166 #endif
168 setup_move_size: .word 0x8000 # size to move, when setup is not
169 # loaded at 0x90000. We will move setup
170 # to 0x90000 then just before jumping
171 # into the kernel. However, only the
172 # loader knows how much data behind
173 # us also needs to be loaded.
175 /* N.B. these next addresses are entirely ignored by this code -- it
176 * assumes it was loaded with the 32bit code at 0x100000, and doesn't
177 * touch the ramdisk. */
178 code32_start: # here loaders can put a different
179 # start address for 32-bit code.
180 #ifndef __BIG_KERNEL__
181 .long 0x1000 # 0x1000 = default for zImage
182 #else
183 .long 0x100000 # 0x100000 = default for big kernel
184 #endif
186 ramdisk_image: .long 0 # address of loaded ramdisk image
187 # Here the loader puts the 32-bit
188 # address where it loaded the image.
189 # This only will be read by the kernel.
191 ramdisk_size: .long 0 # its size in bytes
193 bootsect_kludge:
194 .long 0 # obsolete
196 heap_end_ptr: .word modelist+1024 # (Header version 0x0201 or later)
197 # space from here (exclusive) down to
198 # end of setup code can be used by setup
199 # for local heap purposes.
201 pad1: .word 0
202 cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
203 # If nonzero, a 32-bit pointer
204 # to the kernel command line.
205 # The command line should be
206 # located between the start of
207 # setup and the end of low
208 # memory (0xa0000), or it may
209 # get overwritten before it
210 # gets read. If this field is
211 # used, there is no longer
212 # anything magical about the
213 # 0x90000 segment; the setup
214 # can be located anywhere in
215 # low memory 0x10000 or higher.
217 ramdisk_max: .long (-__PAGE_OFFSET-(512 << 20)-1) & 0x7fffffff
218 # (Header version 0x0203 or later)
219 # The highest safe address for
220 # the contents of an initrd
222 /* Add more known locations: the image builder will overwrite
223 * these with the entry point and MBI location for the multiboot kernel.
224 * These offsets *must* match the definitions in buildimage.c */
226 entry_address: .long 0 # This will be offset 0x30 (0x230 from b'sect)
227 mbi_address: .long 0 # This will be offset 0x34
229 /* Storage space for the size of memory */
230 highmem_size: .long 0
232 trampoline: call start_of_setup
233 .space 1024
234 # End of setup header #####################################################
236 start_of_setup:
237 # Bootlin depends on this being done early
238 movw $0x01500, %ax
239 movb $0x81, %dl
240 int $0x13
242 #ifdef SAFE_RESET_DISK_CONTROLLER
243 # Reset the disk controller.
244 movw $0x0000, %ax
245 movb $0x80, %dl
246 int $0x13
247 #endif
249 # Set %ds = %cs, we know that SETUPSEG = %cs at this point
250 movw %cs, %ax # aka SETUPSEG
251 movw %ax, %ds
253 # Check signature at end of setup
254 cmpw $SIG1, setup_sig1
255 jne bad_sig
257 cmpw $SIG2, setup_sig2
258 jne bad_sig
260 jmp good_sig1
262 # Routine to print asciiz string at ds:si
263 prtstr:
264 lodsb
265 andb %al, %al
266 jz fin
268 call prtchr
269 jmp prtstr
271 fin: ret
273 # Space printing
274 prtsp2: call prtspc # Print double space
275 prtspc: movb $0x20, %al # Print single space (note: fall-thru)
277 # Part of above routine, this one just prints ascii al
278 prtchr: pushw %ax
279 pushw %cx
280 movw $7,%bx
281 movw $0x01, %cx
282 movb $0x0e, %ah
283 int $0x10
284 popw %cx
285 popw %ax
286 ret
288 beep: movb $0x07, %al
289 jmp prtchr
291 no_sig_mess: .string "No setup signature found ..."
293 good_sig1:
294 jmp good_sig
296 # We now have to find the rest of the setup code/data
297 bad_sig:
298 movw %cs, %ax # SETUPSEG
299 subw $DELTA_INITSEG, %ax # INITSEG
300 movw %ax, %ds
301 xorb %bh, %bh
302 movb (497), %bl # get setup sect from bootsect
303 subw $4, %bx # LILO loads 4 sectors of setup
304 shlw $8, %bx # convert to words (1sect=2^8 words)
305 movw %bx, %cx
306 shrw $3, %bx # convert to segment
307 addw $SYSSEG, %bx
308 movw %bx, %cs:start_sys_seg
309 # Move rest of setup code/data to here
310 movw $2048, %di # four sectors loaded by LILO
311 subw %si, %si
312 pushw %cs
313 popw %es
314 movw $SYSSEG, %ax
315 movw %ax, %ds
316 rep
317 movsw
318 movw %cs, %ax # aka SETUPSEG
319 movw %ax, %ds
320 cmpw $SIG1, setup_sig1
321 jne no_sig
323 cmpw $SIG2, setup_sig2
324 jne no_sig
326 jmp good_sig
328 no_sig:
329 lea no_sig_mess, %si
330 call prtstr
332 no_sig_loop:
333 hlt
334 jmp no_sig_loop
336 mb_hello_mess1:
337 .string "mboot"
339 good_sig:
340 lea mb_hello_mess1, %si
341 call prtstr
343 movw %cs, %ax # aka SETUPSEG
344 subw $DELTA_INITSEG, %ax # aka INITSEG
345 movw %ax, %ds
346 # Check if an old loader tries to load a big-kernel
347 testb $LOADED_HIGH, %cs:loadflags # Do we have a big kernel?
348 jz loader_ok # No, no danger for old loaders.
350 cmpb $0, %cs:type_of_loader # Do we have a loader that
351 # can deal with us?
352 jnz loader_ok # Yes, continue.
354 pushw %cs # No, we have an old loader,
355 popw %ds # die.
356 lea loader_panic_mess, %si
357 call prtstr
359 jmp no_sig_loop
361 loader_panic_mess: .string "Wrong loader, giving up..."
363 loader_ok:
365 # Get memory size (extended mem, kB)
367 /* We'll be storing this in highmem_size, to be copied to the mbi */
369 # Try three different memory detection schemes. First, try
370 # e820h, which lets us assemble a memory map, then try e801h,
371 # which returns a 32-bit memory size, and finally 88h, which
372 # returns 0-64m
374 xorl %edx, %edx
375 xorl %eax, %eax
376 movl %eax, (0x1e0)
377 movl %eax, highmem_size
378 movb %al, (E820NR)
380 # method E820H:
381 # the memory map from hell. e820h returns memory classified into
382 # a whole bunch of different types, and allows memory holes and
383 # everything. We scan through this memory map and build a list
384 # of the first 32 memory areas, which we return at [E820MAP].
385 # This is documented at http://www.acpi.info/, in the ACPI 2.0 specification.
387 #define SMAP 0x534d4150
389 meme820:
390 xorl %ebx, %ebx # continuation counter
391 movw $E820MAP, %di # point into the whitelist
392 # so we can have the bios
393 # directly write into it.
395 jmpe820:
396 movl $0x0000e820, %eax # e820, upper word zeroed
397 movl $SMAP, %edx # ascii 'SMAP'
398 movl $20, %ecx # size of the e820rec
399 pushw %ds # data record.
400 popw %es
401 int $0x15 # make the call
402 jc bail820 # fall to e801 if it fails
404 cmpl $SMAP, %eax # check the return is `SMAP'
405 jne bail820 # fall to e801 if it fails
407 # cmpl $1, 16(%di) # is this usable memory?
408 # jne again820
410 # If this is usable memory, we save it by simply advancing %di by
411 # sizeof(e820rec).
412 #
413 good820:
414 movb (E820NR), %al # up to 32 entries
415 cmpb $E820MAX, %al
416 jnl bail820
418 incb (E820NR)
419 movw %di, %ax
420 addw $20, %ax
421 movw %ax, %di
422 again820:
423 cmpl $0, %ebx # check to see if
424 jne jmpe820 # %ebx is set to EOF
426 /* Multiboot spec says high mem should be the address of the first
427 * upper memory hole, minus 1 MB */
428 xorl %ebx, %ebx
429 xorl %ecx, %ecx
430 xorl %edx, %edx
431 movw $E820MAP, %di # Start at the beginning
432 calc_highmem_loop:
433 cmpl $1, 16(%di) # is it usable memory?
434 jnz calc_highmem_next
435 cmpl $0, 4(%di) # is base < 4GB?
436 jnz calc_highmem_next
437 cmpl $0x100000, 0(%di) # is base <= 1MB?
438 jg calc_highmem_next
439 movl 8(%di), %ecx # Calculate base+length
440 shrl $10, %ecx # in kilobytes
441 movl 12(%di), %edx
442 shll $22, %edx
443 orl %edx, %ecx
444 movl 0(%di), %edx
445 shrl $10, %edx
446 addl %edx, %ecx
447 subl $1024, %ecx # - 1 MB
448 cmpl %cs:highmem_size, %ecx
449 jl calc_highmem_next
450 movl %ecx, %cs:highmem_size
451 calc_highmem_next:
452 add $1, %bl
453 add $20, %di
454 cmp %bl, (E820NR)
455 je calc_highmem_done
456 jmp calc_highmem_loop
457 calc_highmem_done:
459 bail820:
461 # method E801H:
462 # memory size is in 1k chunksizes, to avoid confusing loadlin.
464 meme801:
465 stc # fix to work around buggy
466 xorw %cx,%cx # BIOSes which dont clear/set
467 xorw %dx,%dx # carry on pass/error of
468 # e801h memory size call
469 # or merely pass cx,dx though
470 # without changing them.
471 movw $0xe801, %ax
472 int $0x15
473 jc mem88
475 cmpw $0x0, %cx # Kludge to handle BIOSes
476 jne e801usecxdx # which report their extended
477 cmpw $0x0, %dx # memory in AX/BX rather than
478 jne e801usecxdx # CX/DX. The spec I have read
479 movw %ax, %cx # seems to indicate AX/BX
480 movw %bx, %dx # are more reasonable anyway...
482 e801usecxdx:
483 andl $0xffff, %edx # clear sign extend
484 shll $6, %edx # and go from 64k to 1k chunks
485 andl $0xffff, %ecx # clear sign extend
486 addl %ecx, %edx
488 cmpl %cs:highmem_size, %edx # store extended mem size
489 jl mem88 # if it's bigger than
490 movl %edx, %cs:highmem_size # what we already have
492 # Ye Olde Traditional Methode. Returns the memory size (up to 16mb or
493 # 64mb, depending on the bios) in ax.
494 mem88:
495 movb $0x88, %ah
496 int $0x15
498 andl $0xffff, %eax # clear sign extend
499 cmpl %cs:highmem_size, %eax # store extended mem size
500 jl have_memsize # if it's bigger than
501 movl %eax, %cs:highmem_size # what we already have
503 have_memsize:
505 /* Culled: HDD probes, APM, speedstep */
507 # Now we want to move to protected mode ...
508 cmpw $0, %cs:realmode_swtch
509 jz rmodeswtch_normal
511 lcall *%cs:realmode_swtch
513 jmp rmodeswtch_end
515 rmodeswtch_normal:
516 pushw %cs
517 call default_switch
519 rmodeswtch_end:
521 /* Culled: code to take the 32bit entry address from the loader */
522 /* Culled: code to relocate non-bzImage kernels */
524 # then we load the segment descriptors
525 movw %cs, %ax # aka SETUPSEG
526 movw %ax, %ds
528 # Check whether we need to be downward compatible with version <=201
529 cmpl $0, cmd_line_ptr
530 jne end_move_self # loader uses version >=202 features
531 cmpb $0x20, type_of_loader
532 je end_move_self # bootsect loader, we know of it
534 # Boot loader doesnt support boot protocol version 2.02.
535 # If we have our code not at 0x90000, we need to move it there now.
536 # We also then need to move the params behind it (commandline)
537 # Because we would overwrite the code on the current IP, we move
538 # it in two steps, jumping high after the first one.
539 movw %cs, %ax
540 cmpw $SETUPSEG, %ax
541 je end_move_self
543 cli # make sure we really have
544 # interrupts disabled !
545 # because after this the stack
546 # should not be used
547 subw $DELTA_INITSEG, %ax # aka INITSEG
548 movw %ss, %dx
549 cmpw %ax, %dx
550 jb move_self_1
552 addw $INITSEG, %dx
553 subw %ax, %dx # this will go into %ss after
554 # the move
555 move_self_1:
556 movw %ax, %ds
557 movw $INITSEG, %ax # real INITSEG
558 movw %ax, %es
559 movw %cs:setup_move_size, %cx
560 std # we have to move up, so we use
561 # direction down because the
562 # areas may overlap
563 movw %cx, %di
564 decw %di
565 movw %di, %si
566 subw $move_self_here+0x200, %cx
567 rep
568 movsb
569 ljmp $SETUPSEG, $move_self_here
571 move_self_here:
572 movw $move_self_here+0x200, %cx
573 rep
574 movsb
575 movw $SETUPSEG, %ax
576 movw %ax, %ds
577 movw %dx, %ss
578 end_move_self: # now we are at the right place
580 #
581 # Enable A20. This is at the very best an annoying procedure.
582 # A20 code ported from SYSLINUX 1.52-1.63 by H. Peter Anvin.
583 # AMD Elan bug fix by Robert Schwebel.
584 #
586 #if defined(CONFIG_X86_ELAN)
587 movb $0x02, %al # alternate A20 gate
588 outb %al, $0x92 # this works on SC410/SC520
589 a20_elan_wait:
590 call a20_test
591 jz a20_elan_wait
592 jmp a20_done
593 #endif
596 A20_TEST_LOOPS = 32 # Iterations per wait
597 A20_ENABLE_LOOPS = 255 # Total loops to try
600 #ifndef CONFIG_X86_VOYAGER
601 a20_try_loop:
603 # First, see if we are on a system with no A20 gate.
604 a20_none:
605 call a20_test
606 jnz a20_done
608 # Next, try the BIOS (INT 0x15, AX=0x2401)
609 a20_bios:
610 movw $0x2401, %ax
611 pushfl # Be paranoid about flags
612 int $0x15
613 popfl
615 call a20_test
616 jnz a20_done
618 # Try enabling A20 through the keyboard controller
619 #endif /* CONFIG_X86_VOYAGER */
620 a20_kbc:
621 call empty_8042
623 #ifndef CONFIG_X86_VOYAGER
624 call a20_test # Just in case the BIOS worked
625 jnz a20_done # but had a delayed reaction.
626 #endif
628 movb $0xD1, %al # command write
629 outb %al, $0x64
630 call empty_8042
632 movb $0xDF, %al # A20 on
633 outb %al, $0x60
634 call empty_8042
636 #ifndef CONFIG_X86_VOYAGER
637 # Wait until a20 really *is* enabled; it can take a fair amount of
638 # time on certain systems; Toshiba Tecras are known to have this
639 # problem.
640 a20_kbc_wait:
641 xorw %cx, %cx
642 a20_kbc_wait_loop:
643 call a20_test
644 jnz a20_done
645 loop a20_kbc_wait_loop
647 # Final attempt: use "configuration port A"
648 a20_fast:
649 inb $0x92, %al # Configuration Port A
650 orb $0x02, %al # "fast A20" version
651 andb $0xFE, %al # don't accidentally reset
652 outb %al, $0x92
654 # Wait for configuration port A to take effect
655 a20_fast_wait:
656 xorw %cx, %cx
657 a20_fast_wait_loop:
658 call a20_test
659 jnz a20_done
660 loop a20_fast_wait_loop
662 # A20 is still not responding. Try frobbing it again.
663 #
664 decb (a20_tries)
665 jnz a20_try_loop
667 movw $a20_err_msg, %si
668 call prtstr
670 a20_die:
671 hlt
672 jmp a20_die
674 a20_tries:
675 .byte A20_ENABLE_LOOPS
677 a20_err_msg:
678 .ascii "linux: fatal error: A20 gate not responding!"
679 .byte 13, 10, 0
681 # If we get here, all is good
682 a20_done:
685 #endif /* CONFIG_X86_VOYAGER */
687 /* Another print, to show protected mode and A20 are OK */
689 jmp mb_hello_mess2_end
690 mb_hello_mess2:
691 .string "pack "
692 mb_hello_mess2_end:
693 lea mb_hello_mess2, %si
694 call prtstr
696 # set up gdt and idt
697 /* lidt idt_48 # load idt with 0,0 */
698 /* Multiboot kernels must set up their own IDT: leave this for now,
699 * so we can print diagnostics */
701 xorl %eax, %eax # Compute gdt_base
702 movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
703 shll $4, %eax
704 addl $gdt, %eax
705 movl %eax, (gdt_48+2)
706 lgdt gdt_48 # load gdt with whatever is
707 # appropriate
709 # make sure any possible coprocessor is properly reset..
710 xorw %ax, %ax
711 outb %al, $0xf0
712 call delay
714 outb %al, $0xf1
715 call delay
718 # well, that went ok, I hope. Now we mask all interrupts - the rest
719 # is done in init_IRQ().
720 movb $0xFF, %al # mask all interrupts for now
721 outb %al, $0xA1
722 call delay
724 movb $0xFB, %al # mask all irq's but irq2 which
725 outb %al, $0x21 # is cascaded
727 # Well, that certainly wasn't fun :-(. Hopefully it works, and we don't
728 # need no steenking BIOS anyway (except for the initial loading :-).
729 # The BIOS-routine wants lots of unnecessary data, and it's less
730 # "interesting" anyway. This is how REAL programmers do it.
732 /* Tailor the jump below so the target is the 32bit trampoline code */
734 xorl %eax, %eax # Calculate
735 movw %cs, %ax # the linear
736 shll $4, %eax # address of
737 addl $trampoline32, %eax # %cs:trampoline32
738 movl %eax, %cs:code32 # Stick it into the jmpi
740 /* Load a 32-bit pointer to the entry address into %ecx */
741 xorl %ecx, %ecx # Calculate
742 movw %cs, %cx # the linear
743 shll $4, %ecx # address of
744 addl $entry_address, %ecx # %cs:entry_address
746 # Well, now's the time to actually move into protected mode.
748 lea mb_ready_mess, %si
749 call prtstr
751 /* May as well load this IDT now */
752 lidt idt_48
754 xorl %eax, %eax
755 movw $1, %ax # protected mode (PE) bit
756 lmsw %ax # This is it!
757 jmp flush_instr
758 flush_instr:
760 /* Set up segment registers */
761 movw $__BOOT_DS, %dx
762 movw %dx, %ds
763 movw %dx, %es
764 movw %dx, %fs
765 movw %dx, %gs
766 movw %dx, %ss
768 /* Trampoline expects this in %eax */
769 movl %ecx, %eax
771 /* Jump to the 32-bit trampoline */
773 # NOTE: For high loaded big kernels we need a
774 # jmpi 0x100000,__BOOT_CS
775 #
776 # but we yet haven't reloaded the CS register, so the default size
777 # of the target offset still is 16 bit.
778 # However, using an operand prefix (0x66), the CPU will properly
779 # take our 48 bit far pointer. (INTeL 80386 Programmer's Reference
780 # Manual, Mixing 16-bit and 32-bit code, page 16-6)
782 .byte 0x66, 0xea # prefix + jmpi-opcode
783 code32: .long 0x1000 # will be set to trampoline32
784 # by code above.
785 .word __BOOT_CS
787 # Here's a bunch of information about your current kernel..
789 kernel_version: .string "mbootpack changeling bzImage"
790 mb_ready_mess:
791 .ascii MBOOTPACK_VERSION_STRING
792 .ascii "\r\n"
793 .byte 0
795 # This is the default real mode switch routine.
796 # to be called just before protected mode transition
797 default_switch:
798 cli # no interrupts allowed !
799 movb $0x80, %al # disable NMI for bootup
800 # sequence
801 outb %al, $0x70
802 lret
805 #ifndef CONFIG_X86_VOYAGER
806 # This routine tests whether or not A20 is enabled. If so, it
807 # exits with zf = 0.
808 #
809 # The memory address used, 0x200, is the int $0x80 vector, which
810 # should be safe.
812 A20_TEST_ADDR = 4*0x80
814 a20_test:
815 pushw %cx
816 pushw %ax
817 xorw %cx, %cx
818 movw %cx, %fs # Low memory
819 decw %cx
820 movw %cx, %gs # High memory area
821 movw $A20_TEST_LOOPS, %cx
822 movw %fs:(A20_TEST_ADDR), %ax
823 pushw %ax
824 a20_test_wait:
825 incw %ax
826 movw %ax, %fs:(A20_TEST_ADDR)
827 call delay # Serialize and make delay constant
828 cmpw %gs:(A20_TEST_ADDR+0x10), %ax
829 loope a20_test_wait
831 popw %fs:(A20_TEST_ADDR)
832 popw %ax
833 popw %cx
834 ret
836 #endif /* CONFIG_X86_VOYAGER */
838 # This routine checks that the keyboard command queue is empty
839 # (after emptying the output buffers)
840 #
841 # Some machines have delusions that the keyboard buffer is always full
842 # with no keyboard attached...
843 #
844 # If there is no keyboard controller, we will usually get 0xff
845 # to all the reads. With each IO taking a microsecond and
846 # a timeout of 100,000 iterations, this can take about half a
847 # second ("delay" == outb to port 0x80). That should be ok,
848 # and should also be plenty of time for a real keyboard controller
849 # to empty.
850 #
852 empty_8042:
853 pushl %ecx
854 movl $100000, %ecx
856 empty_8042_loop:
857 decl %ecx
858 jz empty_8042_end_loop
860 call delay
862 inb $0x64, %al # 8042 status port
863 testb $1, %al # output buffer?
864 jz no_output
866 call delay
867 inb $0x60, %al # read it
868 jmp empty_8042_loop
870 no_output:
871 testb $2, %al # is input buffer full?
872 jnz empty_8042_loop # yes - loop
873 empty_8042_end_loop:
874 popl %ecx
875 ret
877 # Read the cmos clock. Return the seconds in al
878 gettime:
879 pushw %cx
880 movb $0x02, %ah
881 int $0x1a
882 movb %dh, %al # %dh contains the seconds
883 andb $0x0f, %al
884 movb %dh, %ah
885 movb $0x04, %cl
886 shrb %cl, %ah
887 aad
888 popw %cx
889 ret
891 # Delay is needed after doing I/O
892 delay:
893 outb %al,$0x80
894 ret
896 # Descriptor tables
897 #
898 # NOTE: The intel manual says gdt should be sixteen bytes aligned for
899 # efficiency reasons. However, there are machines which are known not
900 # to boot with misaligned GDTs, so alter this at your peril! If you alter
901 # GDT_ENTRY_BOOT_CS (in asm/segment.h) remember to leave at least two
902 # empty GDT entries (one for NULL and one reserved).
903 #
904 # NOTE: On some CPUs, the GDT must be 8 byte aligned. This is
905 # true for the Voyager Quad CPU card which will not boot without
906 # This directive. 16 byte aligment is recommended by intel.
907 #
910 /* The boot-time code segment is set at the jmpi above */
911 /* Dont change this without checking everything still matches */
913 .align 16
914 gdt:
915 .fill GDT_ENTRY_BOOT_CS,8,0
917 .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
918 .word 0 # base address = 0
919 .word 0x9A00 # code read/exec
920 .word 0x00CF # granularity = 4096, 386
921 # (+5th nibble of limit)
923 .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
924 .word 0 # base address = 0
925 .word 0x9200 # data read/write
926 .word 0x00CF # granularity = 4096, 386
927 # (+5th nibble of limit)
928 gdt_end:
929 .align 4
931 .word 0 # alignment byte
932 idt_48:
933 .word 0 # idt limit = 0
934 .word 0, 0 # idt base = 0L
936 .word 0 # alignment byte
937 gdt_48:
938 .word gdt_end - gdt - 1 # gdt limit
939 .word 0, 0 # gdt base (filled in later)
941 # Include video setup & detection code
943 /* #include "video.S" */
945 .code32
946 trampoline32:
947 /* Here, %eax = 32-bit pointer to entry_address */
949 /* Check if the bootloader gave us a (non-empty) command line */
950 movl -8(%eax), %ebx # cmd_line_ptr
951 cmpl $0, %ebx
952 je no_cmd_line
953 cmpb $0, 0(%ebx)
954 je no_cmd_line
956 /* Find the MBI command line */
957 movl %eax, %ecx # &entry_address
958 addl $(begtext-entry_address), %ecx # --> start of setup
959 subl $0x9200, %ecx # --> reloc offset
960 movl %ecx, %esi # (copy offset)
961 movl %ecx, %ebx # (copy offset)
962 addl 4(%eax), %ecx # --> current addr of MBI
963 addl 16(%ecx), %ebx # --> cur. addr of MB cmdline
965 /* Overwrite the built-in MBI kernel command line */
966 movl -8(%eax), %ecx
967 movl $0, %edi
969 /* Give the kernel a 'self' word, that linux doesn't get */
970 movw $0x202E, 0(%ebx) # '. '
971 addl $0x2, %ebx
973 cmd_line_copy:
974 movb (%ecx, %edi), %dl
975 movb %dl, (%ebx, %edi)
976 inc %edi
977 cmp $CMD_LINE_SPACE-3, %edi
978 je cmd_line_copy_end
980 cmpb $0x0, %dl
981 jne cmd_line_copy
982 cmd_line_copy_end:
983 movb $0x0, (%ebx, %edi)
984 subl $0x2, %ebx
986 /* Look for '--' in the kernel command line */
987 cmd_line_scan:
988 inc %ebx
989 cmpb $0x0, 0(%ebx)
990 je no_cmd_line
991 cmpl $0x202D2D20, 0(%ebx) # ' -- '
992 jne cmd_line_scan
994 /* Found it: terminate kernel's command line */
995 movb $0x0, 0(%ebx)
996 inc %ebx
997 /* Relocate address to where it will be moved to */
998 subl %esi, %ebx
1000 /* Is there a module 0? */
1001 movl %esi, %ecx # Reloc offset
1002 addl 4(%eax), %ecx # --> current addr of MBI
1003 cmpl $0x0, 20(%ecx) # (check module count)
1004 je no_cmd_line
1005 /* Overwrite module 0's command line */
1006 movl %esi, %edx # Reloc offset
1007 addl 24(%ecx), %edx # --> cur. add. of Module 0
1008 movl %ebx, 8(%edx) # --> blat mod. 0's cmdline
1009 no_cmd_line:
1012 /* Relocate the MBI from after the setup code to its proper home
1013 * between the MBI pointer and 0xa000 */
1014 movl %eax, %ecx # &entry_address
1015 addl $(begtext-entry_address), %ecx # --> start of setup
1016 subl $0x9200, %ecx # --> reloc offset
1017 addl 4(%eax), %ecx # --> current addr of MBI
1019 movl $0xa000, %ebx # End of MBI
1020 subl 4(%eax), %ebx # --> size of MBI
1021 movl %ebx, %edi
1023 movl 4(%eax), %ebx # Destination of MBI
1025 mbi_copy:
1026 dec %edi
1027 movb (%ecx, %edi), %dl
1028 movb %dl, (%ebx, %edi)
1029 cmp $0x0, %edi
1030 jne mbi_copy
1032 /* Copy memory size into MBI structure */
1033 movl 4(%eax), %ebx # MBI pointer
1034 movl 8(%eax), %ecx # highmem_size
1035 movl %ecx, 8(%ebx) # --> mbi.mem_upper
1036 movl $0x280, %ecx
1037 movl %ecx, 4(%ebx) # --> mbi.mem_lower
1038 /* Set the MB_INFO_MEMORY bit */
1039 orl $1, 0(%ebx)
1041 /* Recover the MBI pointer into %ebx */
1042 movl 4(%eax), %ebx # MBI pointer
1043 /* Extract the load address into %ecx */
1044 movl 0(%eax), %ecx
1045 /* Let the kernel know we're a multiboot loader */
1046 movl $0x2BADB002, %eax
1047 /* Jump to the kernel address supplied */
1048 jmp *%ecx
1050 # Setup signature -- must be last
1051 setup_sig1: .word SIG1
1052 setup_sig2: .word SIG2
1054 # After this point, there is some free space which is used by the video mode
1055 # handling code to store the temporary mode table (not used by the kernel).
1057 modelist:
1059 .text
1060 endtext:
1061 .data
1062 enddata:
1063 .bss
1064 endbss: