aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86_64/boot/setup.S
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/x86_64/boot/setup.S
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/x86_64/boot/setup.S')
-rw-r--r--arch/x86_64/boot/setup.S867
1 files changed, 867 insertions, 0 deletions
diff --git a/arch/x86_64/boot/setup.S b/arch/x86_64/boot/setup.S
new file mode 100644
index 000000000000..3e838be9dbe7
--- /dev/null
+++ b/arch/x86_64/boot/setup.S
@@ -0,0 +1,867 @@
1/*
2 * setup.S Copyright (C) 1991, 1992 Linus Torvalds
3 *
4 * setup.s is responsible for getting the system data from the BIOS,
5 * and putting them into the appropriate places in system memory.
6 * both setup.s and system has been loaded by the bootblock.
7 *
8 * This code asks the bios for memory/disk/other parameters, and
9 * puts them in a "safe" place: 0x90000-0x901FF, ie where the
10 * boot-block used to be. It is then up to the protected mode
11 * system to read them from there before the area is overwritten
12 * for buffer-blocks.
13 *
14 * Move PS/2 aux init code to psaux.c
15 * (troyer@saifr00.cfsat.Honeywell.COM) 03Oct92
16 *
17 * some changes and additional features by Christoph Niemann,
18 * March 1993/June 1994 (Christoph.Niemann@linux.org)
19 *
20 * add APM BIOS checking by Stephen Rothwell, May 1994
21 * (sfr@canb.auug.org.au)
22 *
23 * High load stuff, initrd support and position independency
24 * by Hans Lermen & Werner Almesberger, February 1996
25 * <lermen@elserv.ffm.fgan.de>, <almesber@lrc.epfl.ch>
26 *
27 * Video handling moved to video.S by Martin Mares, March 1996
28 * <mj@k332.feld.cvut.cz>
29 *
30 * Extended memory detection scheme retwiddled by orc@pell.chi.il.us (david
31 * parsons) to avoid loadlin confusion, July 1997
32 *
33 * Transcribed from Intel (as86) -> AT&T (gas) by Chris Noe, May 1999.
34 * <stiker@northlink.com>
35 *
36 * Fix to work around buggy BIOSes which dont use carry bit correctly
37 * and/or report extended memory in CX/DX for e801h memory size detection
38 * call. As a result the kernel got wrong figures. The int15/e801h docs
39 * from Ralf Brown interrupt list seem to indicate AX/BX should be used
40 * anyway. So to avoid breaking many machines (presumably there was a reason
41 * to orginally use CX/DX instead of AX/BX), we do a kludge to see
42 * if CX/DX have been changed in the e801 call and if so use AX/BX .
43 * Michael Miller, April 2001 <michaelm@mjmm.org>
44 *
45 * Added long mode checking and SSE force. March 2003, Andi Kleen.
46 */
47
48#include <linux/config.h>
49#include <asm/segment.h>
50#include <linux/version.h>
51#include <linux/compile.h>
52#include <asm/boot.h>
53#include <asm/e820.h>
54#include <asm/page.h>
55
56/* Signature words to ensure LILO loaded us right */
57#define SIG1 0xAA55
58#define SIG2 0x5A5A
59
60INITSEG = DEF_INITSEG # 0x9000, we move boot here, out of the way
61SYSSEG = DEF_SYSSEG # 0x1000, system loaded at 0x10000 (65536).
62SETUPSEG = DEF_SETUPSEG # 0x9020, this is the current segment
63 # ... and the former contents of CS
64
65DELTA_INITSEG = SETUPSEG - INITSEG # 0x0020
66
67.code16
68.globl begtext, begdata, begbss, endtext, enddata, endbss
69
70.text
71begtext:
72.data
73begdata:
74.bss
75begbss:
76.text
77
78start:
79 jmp trampoline
80
81# This is the setup header, and it must start at %cs:2 (old 0x9020:2)
82
83 .ascii "HdrS" # header signature
84 .word 0x0203 # header version number (>= 0x0105)
85 # or else old loadlin-1.5 will fail)
86realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
87start_sys_seg: .word SYSSEG
88 .word kernel_version # pointing to kernel version string
89 # above section of header is compatible
90 # with loadlin-1.5 (header v1.5). Don't
91 # change it.
92
93type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
94 # Bootlin, SYSLX, bootsect...)
95 # See Documentation/i386/boot.txt for
96 # assigned ids
97
98# flags, unused bits must be zero (RFU) bit within loadflags
99loadflags:
100LOADED_HIGH = 1 # If set, the kernel is loaded high
101CAN_USE_HEAP = 0x80 # If set, the loader also has set
102 # heap_end_ptr to tell how much
103 # space behind setup.S can be used for
104 # heap purposes.
105 # Only the loader knows what is free
106#ifndef __BIG_KERNEL__
107 .byte 0
108#else
109 .byte LOADED_HIGH
110#endif
111
112setup_move_size: .word 0x8000 # size to move, when setup is not
113 # loaded at 0x90000. We will move setup
114 # to 0x90000 then just before jumping
115 # into the kernel. However, only the
116 # loader knows how much data behind
117 # us also needs to be loaded.
118
119code32_start: # here loaders can put a different
120 # start address for 32-bit code.
121#ifndef __BIG_KERNEL__
122 .long 0x1000 # 0x1000 = default for zImage
123#else
124 .long 0x100000 # 0x100000 = default for big kernel
125#endif
126
127ramdisk_image: .long 0 # address of loaded ramdisk image
128 # Here the loader puts the 32-bit
129 # address where it loaded the image.
130 # This only will be read by the kernel.
131
132ramdisk_size: .long 0 # its size in bytes
133
134bootsect_kludge:
135 .long 0 # obsolete
136
137heap_end_ptr: .word modelist+1024 # (Header version 0x0201 or later)
138 # space from here (exclusive) down to
139 # end of setup code can be used by setup
140 # for local heap purposes.
141
142pad1: .word 0
143cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
144 # If nonzero, a 32-bit pointer
145 # to the kernel command line.
146 # The command line should be
147 # located between the start of
148 # setup and the end of low
149 # memory (0xa0000), or it may
150 # get overwritten before it
151 # gets read. If this field is
152 # used, there is no longer
153 # anything magical about the
154 # 0x90000 segment; the setup
155 # can be located anywhere in
156 # low memory 0x10000 or higher.
157
158ramdisk_max: .long 0xffffffff
159
160trampoline: call start_of_setup
161 .align 16
162 # The offset at this point is 0x240
163 .space (0x7ff-0x240+1) # E820 & EDD space (ending at 0x7ff)
164# End of setup header #####################################################
165
166start_of_setup:
167# Bootlin depends on this being done early
168 movw $0x01500, %ax
169 movb $0x81, %dl
170 int $0x13
171
172#ifdef SAFE_RESET_DISK_CONTROLLER
173# Reset the disk controller.
174 movw $0x0000, %ax
175 movb $0x80, %dl
176 int $0x13
177#endif
178
179# Set %ds = %cs, we know that SETUPSEG = %cs at this point
180 movw %cs, %ax # aka SETUPSEG
181 movw %ax, %ds
182# Check signature at end of setup
183 cmpw $SIG1, setup_sig1
184 jne bad_sig
185
186 cmpw $SIG2, setup_sig2
187 jne bad_sig
188
189 jmp good_sig1
190
191# Routine to print asciiz string at ds:si
192prtstr:
193 lodsb
194 andb %al, %al
195 jz fin
196
197 call prtchr
198 jmp prtstr
199
200fin: ret
201
202# Space printing
203prtsp2: call prtspc # Print double space
204prtspc: movb $0x20, %al # Print single space (note: fall-thru)
205
206prtchr:
207 pushw %ax
208 pushw %cx
209 movw $0007,%bx
210 movw $0x01, %cx
211 movb $0x0e, %ah
212 int $0x10
213 popw %cx
214 popw %ax
215 ret
216
217beep: movb $0x07, %al
218 jmp prtchr
219
220no_sig_mess: .string "No setup signature found ..."
221
222good_sig1:
223 jmp good_sig
224
225# We now have to find the rest of the setup code/data
226bad_sig:
227 movw %cs, %ax # SETUPSEG
228 subw $DELTA_INITSEG, %ax # INITSEG
229 movw %ax, %ds
230 xorb %bh, %bh
231 movb (497), %bl # get setup sect from bootsect
232 subw $4, %bx # LILO loads 4 sectors of setup
233 shlw $8, %bx # convert to words (1sect=2^8 words)
234 movw %bx, %cx
235 shrw $3, %bx # convert to segment
236 addw $SYSSEG, %bx
237 movw %bx, %cs:start_sys_seg
238# Move rest of setup code/data to here
239 movw $2048, %di # four sectors loaded by LILO
240 subw %si, %si
241 movw %cs, %ax # aka SETUPSEG
242 movw %ax, %es
243 movw $SYSSEG, %ax
244 movw %ax, %ds
245 rep
246 movsw
247 movw %cs, %ax # aka SETUPSEG
248 movw %ax, %ds
249 cmpw $SIG1, setup_sig1
250 jne no_sig
251
252 cmpw $SIG2, setup_sig2
253 jne no_sig
254
255 jmp good_sig
256
257no_sig:
258 lea no_sig_mess, %si
259 call prtstr
260
261no_sig_loop:
262 jmp no_sig_loop
263
264good_sig:
265 movw %cs, %ax # aka SETUPSEG
266 subw $DELTA_INITSEG, %ax # aka INITSEG
267 movw %ax, %ds
268# Check if an old loader tries to load a big-kernel
269 testb $LOADED_HIGH, %cs:loadflags # Do we have a big kernel?
270 jz loader_ok # No, no danger for old loaders.
271
272 cmpb $0, %cs:type_of_loader # Do we have a loader that
273 # can deal with us?
274 jnz loader_ok # Yes, continue.
275
276 pushw %cs # No, we have an old loader,
277 popw %ds # die.
278 lea loader_panic_mess, %si
279 call prtstr
280
281 jmp no_sig_loop
282
283loader_panic_mess: .string "Wrong loader, giving up..."
284
285loader_ok:
286 /* check for long mode. */
287 /* we have to do this before the VESA setup, otherwise the user
288 can't see the error message. */
289
290 pushw %ds
291 movw %cs,%ax
292 movw %ax,%ds
293
294 /* minimum CPUID flags for x86-64 */
295 /* see http://www.x86-64.org/lists/discuss/msg02971.html */
296#define SSE_MASK ((1<<25)|(1<<26))
297#define REQUIRED_MASK1 ((1<<0)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<8)|\
298 (1<<13)|(1<<15)|(1<<24))
299#define REQUIRED_MASK2 (1<<29)
300
301 pushfl /* standard way to check for cpuid */
302 popl %eax
303 movl %eax,%ebx
304 xorl $0x200000,%eax
305 pushl %eax
306 popfl
307 pushfl
308 popl %eax
309 cmpl %eax,%ebx
310 jz no_longmode /* cpu has no cpuid */
311 movl $0x0,%eax
312 cpuid
313 cmpl $0x1,%eax
314 jb no_longmode /* no cpuid 1 */
315 xor %di,%di
316 cmpl $0x68747541,%ebx /* AuthenticAMD */
317 jnz noamd
318 cmpl $0x69746e65,%edx
319 jnz noamd
320 cmpl $0x444d4163,%ecx
321 jnz noamd
322 mov $1,%di /* cpu is from AMD */
323noamd:
324 movl $0x1,%eax
325 cpuid
326 andl $REQUIRED_MASK1,%edx
327 xorl $REQUIRED_MASK1,%edx
328 jnz no_longmode
329 movl $0x80000000,%eax
330 cpuid
331 cmpl $0x80000001,%eax
332 jb no_longmode /* no extended cpuid */
333 movl $0x80000001,%eax
334 cpuid
335 andl $REQUIRED_MASK2,%edx
336 xorl $REQUIRED_MASK2,%edx
337 jnz no_longmode
338sse_test:
339 movl $1,%eax
340 cpuid
341 andl $SSE_MASK,%edx
342 cmpl $SSE_MASK,%edx
343 je sse_ok
344 test %di,%di
345 jz no_longmode /* only try to force SSE on AMD */
346 movl $0xc0010015,%ecx /* HWCR */
347 rdmsr
348 btr $15,%eax /* enable SSE */
349 wrmsr
350 xor %di,%di /* don't loop */
351 jmp sse_test /* try again */
352no_longmode:
353 call beep
354 lea long_mode_panic,%si
355 call prtstr
356no_longmode_loop:
357 jmp no_longmode_loop
358long_mode_panic:
359 .string "Your CPU does not support long mode. Use a 32bit distribution."
360 .byte 0
361
362sse_ok:
363 popw %ds
364
365# tell BIOS we want to go to long mode
366 movl $0xec00,%eax # declare target operating mode
367 movl $2,%ebx # long mode
368 int $0x15
369
370# Get memory size (extended mem, kB)
371
372 xorl %eax, %eax
373 movl %eax, (0x1e0)
374#ifndef STANDARD_MEMORY_BIOS_CALL
375 movb %al, (E820NR)
376# Try three different memory detection schemes. First, try
377# e820h, which lets us assemble a memory map, then try e801h,
378# which returns a 32-bit memory size, and finally 88h, which
379# returns 0-64m
380
381# method E820H:
382# the memory map from hell. e820h returns memory classified into
383# a whole bunch of different types, and allows memory holes and
384# everything. We scan through this memory map and build a list
385# of the first 32 memory areas, which we return at [E820MAP].
386# This is documented at http://www.teleport.com/~acpi/acpihtml/topic245.htm
387
388#define SMAP 0x534d4150
389
390meme820:
391 xorl %ebx, %ebx # continuation counter
392 movw $E820MAP, %di # point into the whitelist
393 # so we can have the bios
394 # directly write into it.
395
396jmpe820:
397 movl $0x0000e820, %eax # e820, upper word zeroed
398 movl $SMAP, %edx # ascii 'SMAP'
399 movl $20, %ecx # size of the e820rec
400 pushw %ds # data record.
401 popw %es
402 int $0x15 # make the call
403 jc bail820 # fall to e801 if it fails
404
405 cmpl $SMAP, %eax # check the return is `SMAP'
406 jne bail820 # fall to e801 if it fails
407
408# cmpl $1, 16(%di) # is this usable memory?
409# jne again820
410
411 # If this is usable memory, we save it by simply advancing %di by
412 # sizeof(e820rec).
413 #
414good820:
415 movb (E820NR), %al # up to 32 entries
416 cmpb $E820MAX, %al
417 jnl bail820
418
419 incb (E820NR)
420 movw %di, %ax
421 addw $20, %ax
422 movw %ax, %di
423again820:
424 cmpl $0, %ebx # check to see if
425 jne jmpe820 # %ebx is set to EOF
426bail820:
427
428
429# method E801H:
430# memory size is in 1k chunksizes, to avoid confusing loadlin.
431# we store the 0xe801 memory size in a completely different place,
432# because it will most likely be longer than 16 bits.
433# (use 1e0 because that's what Larry Augustine uses in his
434# alternative new memory detection scheme, and it's sensible
435# to write everything into the same place.)
436
437meme801:
438 stc # fix to work around buggy
439 xorw %cx,%cx # BIOSes which dont clear/set
440 xorw %dx,%dx # carry on pass/error of
441 # e801h memory size call
442 # or merely pass cx,dx though
443 # without changing them.
444 movw $0xe801, %ax
445 int $0x15
446 jc mem88
447
448 cmpw $0x0, %cx # Kludge to handle BIOSes
449 jne e801usecxdx # which report their extended
450 cmpw $0x0, %dx # memory in AX/BX rather than
451 jne e801usecxdx # CX/DX. The spec I have read
452 movw %ax, %cx # seems to indicate AX/BX
453 movw %bx, %dx # are more reasonable anyway...
454
455e801usecxdx:
456 andl $0xffff, %edx # clear sign extend
457 shll $6, %edx # and go from 64k to 1k chunks
458 movl %edx, (0x1e0) # store extended memory size
459 andl $0xffff, %ecx # clear sign extend
460 addl %ecx, (0x1e0) # and add lower memory into
461 # total size.
462
463# Ye Olde Traditional Methode. Returns the memory size (up to 16mb or
464# 64mb, depending on the bios) in ax.
465mem88:
466
467#endif
468 movb $0x88, %ah
469 int $0x15
470 movw %ax, (2)
471
472# Set the keyboard repeat rate to the max
473 movw $0x0305, %ax
474 xorw %bx, %bx
475 int $0x16
476
477# Check for video adapter and its parameters and allow the
478# user to browse video modes.
479 call video # NOTE: we need %ds pointing
480 # to bootsector
481
482# Get hd0 data...
483 xorw %ax, %ax
484 movw %ax, %ds
485 ldsw (4 * 0x41), %si
486 movw %cs, %ax # aka SETUPSEG
487 subw $DELTA_INITSEG, %ax # aka INITSEG
488 pushw %ax
489 movw %ax, %es
490 movw $0x0080, %di
491 movw $0x10, %cx
492 pushw %cx
493 cld
494 rep
495 movsb
496# Get hd1 data...
497 xorw %ax, %ax
498 movw %ax, %ds
499 ldsw (4 * 0x46), %si
500 popw %cx
501 popw %es
502 movw $0x0090, %di
503 rep
504 movsb
505# Check that there IS a hd1 :-)
506 movw $0x01500, %ax
507 movb $0x81, %dl
508 int $0x13
509 jc no_disk1
510
511 cmpb $3, %ah
512 je is_disk1
513
514no_disk1:
515 movw %cs, %ax # aka SETUPSEG
516 subw $DELTA_INITSEG, %ax # aka INITSEG
517 movw %ax, %es
518 movw $0x0090, %di
519 movw $0x10, %cx
520 xorw %ax, %ax
521 cld
522 rep
523 stosb
524is_disk1:
525
526# Check for PS/2 pointing device
527 movw %cs, %ax # aka SETUPSEG
528 subw $DELTA_INITSEG, %ax # aka INITSEG
529 movw %ax, %ds
530 movw $0, (0x1ff) # default is no pointing device
531 int $0x11 # int 0x11: equipment list
532 testb $0x04, %al # check if mouse installed
533 jz no_psmouse
534
535 movw $0xAA, (0x1ff) # device present
536no_psmouse:
537
538#include "../../i386/boot/edd.S"
539
540# Now we want to move to protected mode ...
541 cmpw $0, %cs:realmode_swtch
542 jz rmodeswtch_normal
543
544 lcall *%cs:realmode_swtch
545
546 jmp rmodeswtch_end
547
548rmodeswtch_normal:
549 pushw %cs
550 call default_switch
551
552rmodeswtch_end:
553# we get the code32 start address and modify the below 'jmpi'
554# (loader may have changed it)
555 movl %cs:code32_start, %eax
556 movl %eax, %cs:code32
557
558# Now we move the system to its rightful place ... but we check if we have a
559# big-kernel. In that case we *must* not move it ...
560 testb $LOADED_HIGH, %cs:loadflags
561 jz do_move0 # .. then we have a normal low
562 # loaded zImage
563 # .. or else we have a high
564 # loaded bzImage
565 jmp end_move # ... and we skip moving
566
567do_move0:
568 movw $0x100, %ax # start of destination segment
569 movw %cs, %bp # aka SETUPSEG
570 subw $DELTA_INITSEG, %bp # aka INITSEG
571 movw %cs:start_sys_seg, %bx # start of source segment
572 cld
573do_move:
574 movw %ax, %es # destination segment
575 incb %ah # instead of add ax,#0x100
576 movw %bx, %ds # source segment
577 addw $0x100, %bx
578 subw %di, %di
579 subw %si, %si
580 movw $0x800, %cx
581 rep
582 movsw
583 cmpw %bp, %bx # assume start_sys_seg > 0x200,
584 # so we will perhaps read one
585 # page more than needed, but
586 # never overwrite INITSEG
587 # because destination is a
588 # minimum one page below source
589 jb do_move
590
591end_move:
592# then we load the segment descriptors
593 movw %cs, %ax # aka SETUPSEG
594 movw %ax, %ds
595
596# Check whether we need to be downward compatible with version <=201
597 cmpl $0, cmd_line_ptr
598 jne end_move_self # loader uses version >=202 features
599 cmpb $0x20, type_of_loader
600 je end_move_self # bootsect loader, we know of it
601
602# Boot loader doesnt support boot protocol version 2.02.
603# If we have our code not at 0x90000, we need to move it there now.
604# We also then need to move the params behind it (commandline)
605# Because we would overwrite the code on the current IP, we move
606# it in two steps, jumping high after the first one.
607 movw %cs, %ax
608 cmpw $SETUPSEG, %ax
609 je end_move_self
610
611 cli # make sure we really have
612 # interrupts disabled !
613 # because after this the stack
614 # should not be used
615 subw $DELTA_INITSEG, %ax # aka INITSEG
616 movw %ss, %dx
617 cmpw %ax, %dx
618 jb move_self_1
619
620 addw $INITSEG, %dx
621 subw %ax, %dx # this will go into %ss after
622 # the move
623move_self_1:
624 movw %ax, %ds
625 movw $INITSEG, %ax # real INITSEG
626 movw %ax, %es
627 movw %cs:setup_move_size, %cx
628 std # we have to move up, so we use
629 # direction down because the
630 # areas may overlap
631 movw %cx, %di
632 decw %di
633 movw %di, %si
634 subw $move_self_here+0x200, %cx
635 rep
636 movsb
637 ljmp $SETUPSEG, $move_self_here
638
639move_self_here:
640 movw $move_self_here+0x200, %cx
641 rep
642 movsb
643 movw $SETUPSEG, %ax
644 movw %ax, %ds
645 movw %dx, %ss
646end_move_self: # now we are at the right place
647 lidt idt_48 # load idt with 0,0
648 xorl %eax, %eax # Compute gdt_base
649 movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
650 shll $4, %eax
651 addl $gdt, %eax
652 movl %eax, (gdt_48+2)
653 lgdt gdt_48 # load gdt with whatever is
654 # appropriate
655
656# that was painless, now we enable a20
657 call empty_8042
658
659 movb $0xD1, %al # command write
660 outb %al, $0x64
661 call empty_8042
662
663 movb $0xDF, %al # A20 on
664 outb %al, $0x60
665 call empty_8042
666
667#
668# You must preserve the other bits here. Otherwise embarrasing things
669# like laptops powering off on boot happen. Corrected version by Kira
670# Brown from Linux 2.2
671#
672 inb $0x92, %al #
673 orb $02, %al # "fast A20" version
674 outb %al, $0x92 # some chips have only this
675
676# wait until a20 really *is* enabled; it can take a fair amount of
677# time on certain systems; Toshiba Tecras are known to have this
678# problem. The memory location used here (0x200) is the int 0x80
679# vector, which should be safe to use.
680
681 xorw %ax, %ax # segment 0x0000
682 movw %ax, %fs
683 decw %ax # segment 0xffff (HMA)
684 movw %ax, %gs
685a20_wait:
686 incw %ax # unused memory location <0xfff0
687 movw %ax, %fs:(0x200) # we use the "int 0x80" vector
688 cmpw %gs:(0x210), %ax # and its corresponding HMA addr
689 je a20_wait # loop until no longer aliased
690
691# make sure any possible coprocessor is properly reset..
692 xorw %ax, %ax
693 outb %al, $0xf0
694 call delay
695
696 outb %al, $0xf1
697 call delay
698
699# well, that went ok, I hope. Now we mask all interrupts - the rest
700# is done in init_IRQ().
701 movb $0xFF, %al # mask all interrupts for now
702 outb %al, $0xA1
703 call delay
704
705 movb $0xFB, %al # mask all irq's but irq2 which
706 outb %al, $0x21 # is cascaded
707
708# Well, that certainly wasn't fun :-(. Hopefully it works, and we don't
709# need no steenking BIOS anyway (except for the initial loading :-).
710# The BIOS-routine wants lots of unnecessary data, and it's less
711# "interesting" anyway. This is how REAL programmers do it.
712#
713# Well, now's the time to actually move into protected mode. To make
714# things as simple as possible, we do no register set-up or anything,
715# we let the gnu-compiled 32-bit programs do that. We just jump to
716# absolute address 0x1000 (or the loader supplied one),
717# in 32-bit protected mode.
718#
719# Note that the short jump isn't strictly needed, although there are
720# reasons why it might be a good idea. It won't hurt in any case.
721 movw $1, %ax # protected mode (PE) bit
722 lmsw %ax # This is it!
723 jmp flush_instr
724
725flush_instr:
726 xorw %bx, %bx # Flag to indicate a boot
727 xorl %esi, %esi # Pointer to real-mode code
728 movw %cs, %si
729 subw $DELTA_INITSEG, %si
730 shll $4, %esi # Convert to 32-bit pointer
731# NOTE: For high loaded big kernels we need a
732# jmpi 0x100000,__KERNEL_CS
733#
734# but we yet haven't reloaded the CS register, so the default size
735# of the target offset still is 16 bit.
736# However, using an operant prefix (0x66), the CPU will properly
737# take our 48 bit far pointer. (INTeL 80386 Programmer's Reference
738# Manual, Mixing 16-bit and 32-bit code, page 16-6)
739
740 .byte 0x66, 0xea # prefix + jmpi-opcode
741code32: .long 0x1000 # will be set to 0x100000
742 # for big kernels
743 .word __KERNEL_CS
744
745# Here's a bunch of information about your current kernel..
746kernel_version: .ascii UTS_RELEASE
747 .ascii " ("
748 .ascii LINUX_COMPILE_BY
749 .ascii "@"
750 .ascii LINUX_COMPILE_HOST
751 .ascii ") "
752 .ascii UTS_VERSION
753 .byte 0
754
755# This is the default real mode switch routine.
756# to be called just before protected mode transition
757default_switch:
758 cli # no interrupts allowed !
759 movb $0x80, %al # disable NMI for bootup
760 # sequence
761 outb %al, $0x70
762 lret
763
764
765# This routine checks that the keyboard command queue is empty
766# (after emptying the output buffers)
767#
768# Some machines have delusions that the keyboard buffer is always full
769# with no keyboard attached...
770#
771# If there is no keyboard controller, we will usually get 0xff
772# to all the reads. With each IO taking a microsecond and
773# a timeout of 100,000 iterations, this can take about half a
774# second ("delay" == outb to port 0x80). That should be ok,
775# and should also be plenty of time for a real keyboard controller
776# to empty.
777#
778
779empty_8042:
780 pushl %ecx
781 movl $100000, %ecx
782
783empty_8042_loop:
784 decl %ecx
785 jz empty_8042_end_loop
786
787 call delay
788
789 inb $0x64, %al # 8042 status port
790 testb $1, %al # output buffer?
791 jz no_output
792
793 call delay
794 inb $0x60, %al # read it
795 jmp empty_8042_loop
796
797no_output:
798 testb $2, %al # is input buffer full?
799 jnz empty_8042_loop # yes - loop
800empty_8042_end_loop:
801 popl %ecx
802 ret
803
804# Read the cmos clock. Return the seconds in al
805gettime:
806 pushw %cx
807 movb $0x02, %ah
808 int $0x1a
809 movb %dh, %al # %dh contains the seconds
810 andb $0x0f, %al
811 movb %dh, %ah
812 movb $0x04, %cl
813 shrb %cl, %ah
814 aad
815 popw %cx
816 ret
817
818# Delay is needed after doing I/O
819delay:
820 outb %al,$0x80
821 ret
822
823# Descriptor tables
824gdt:
825 .word 0, 0, 0, 0 # dummy
826
827 .word 0, 0, 0, 0 # unused
828
829 .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
830 .word 0 # base address = 0
831 .word 0x9A00 # code read/exec
832 .word 0x00CF # granularity = 4096, 386
833 # (+5th nibble of limit)
834
835 .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
836 .word 0 # base address = 0
837 .word 0x9200 # data read/write
838 .word 0x00CF # granularity = 4096, 386
839 # (+5th nibble of limit)
840idt_48:
841 .word 0 # idt limit = 0
842 .word 0, 0 # idt base = 0L
843gdt_48:
844 .word 0x8000 # gdt limit=2048,
845 # 256 GDT entries
846
847 .word 0, 0 # gdt base (filled in later)
848
849# Include video setup & detection code
850
851#include "video.S"
852
853# Setup signature -- must be last
854setup_sig1: .word SIG1
855setup_sig2: .word SIG2
856
857# After this point, there is some free space which is used by the video mode
858# handling code to store the temporary mode table (not used by the kernel).
859
860modelist:
861
862.text
863endtext:
864.data
865enddata:
866.bss
867endbss: