📄 dosstart.s
字号:
shll $6, %edx # and go from 64k to 1k chunks movl %edx, (0x1e0) # store extended memory size andl $0xffff, %ecx # clear sign extend addl %ecx, (0x1e0) # and add lower memory into # total size.# Ye Olde Traditional Methode. Returns the memory size (up to 16mb or# 64mb, depending on the bios) in ax.mem88:#endif movb $0x88, %ah int $0x15 movw %ax, (2)get_mem_size_end: # Set the keyboard repeat rate to the max movw $0x0305, %ax xorw %bx, %bx int $0x16#; grub4dos needn't get video, hd, mouse, APM, edd#; jmp get_misc_info_end#;#;# Check for video adapter and its parameters and allow the#;# user to browse video modes.#; call video # NOTE: we need %ds pointing#; # to bootsector#;#;# Get hd0 data...#; xorw %ax, %ax#; movw %ax, %ds#; ldsw (4 * 0x41), %si#; movw %cs, %ax # aka SETUPSEG#; subw $DELTA_INITSEG, %ax # aka INITSEG#; pushw %ax#; movw %ax, %es#; movw $0x0080, %di#; movw $0x10, %cx#; pushw %cx#; cld#; rep#; movsb#;# Get hd1 data...#; xorw %ax, %ax#; movw %ax, %ds#; ldsw (4 * 0x46), %si#; popw %cx#; popw %es#; movw $0x0090, %di#; rep#; movsb#;# Check that there IS a hd1 :-)#; movw $0x01500, %ax#; movb $0x81, %dl#; int $0x13#; jc no_disk1#; #; cmpb $3, %ah#; je is_disk1#;#;no_disk1:#; movw %cs, %ax # aka SETUPSEG#; subw $DELTA_INITSEG, %ax # aka INITSEG#; movw %ax, %es#; movw $0x0090, %di#; movw $0x10, %cx#; xorw %ax, %ax#; cld#; rep#; stosb#;is_disk1:#;# check for Micro Channel (MCA) bus#; movw %cs, %ax # aka SETUPSEG#; subw $DELTA_INITSEG, %ax # aka INITSEG#; movw %ax, %ds#; xorw %ax, %ax#; movw %ax, (0xa0) # set table length to 0#; movb $0xc0, %ah#; stc#; int $0x15 # moves feature table to es:bx#; jc no_mca#;#; pushw %ds#; movw %es, %ax#; movw %ax, %ds#; movw %cs, %ax # aka SETUPSEG#; subw $DELTA_INITSEG, %ax # aka INITSEG#; movw %ax, %es#; movw %bx, %si#; movw $0xa0, %di#; movw (%si), %cx#; addw $2, %cx # table length is a short#; cmpw $0x10, %cx#; jc sysdesc_ok#;#; movw $0x10, %cx # we keep only first 16 bytes#;sysdesc_ok:#; rep#; movsb#; popw %ds#;no_mca:#;#ifdef CONFIG_X86_VOYAGER#; movb $0xff, 0x40 # flag on config found#; movb $0xc0, %al#; mov $0xff, %ah#; int $0x15 # put voyager config info at es:di#; jc no_voyager#; movw $0x40, %si # place voyager info in apm table#; cld#; movw $7, %cx#;voyager_rep:#; movb %es:(%di), %al#; movb %al,(%si)#; incw %di#; incw %si#; decw %cx#; jnz voyager_rep#;no_voyager: #;#endif#;# Check for PS/2 pointing device#; movw %cs, %ax # aka SETUPSEG#; subw $DELTA_INITSEG, %ax # aka INITSEG#; movw %ax, %ds#; movw $0, (0x1ff) # default is no pointing device#; int $0x11 # int 0x11: equipment list#; testb $0x04, %al # check if mouse installed#; jz no_psmouse#;#; movw $0xAA, (0x1ff) # device present#;no_psmouse:#;#;#if defined(CONFIG_X86_SPEEDSTEP_SMI) || defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)#; movl $0x0000E980, %eax # IST Support #; movl $0x47534943, %edx # Request value#; int $0x15#;#; movl %eax, (96)#; movl %ebx, (100)#; movl %ecx, (104)#; movl %edx, (108)#;#endif#;#;#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)#;# Then check for an APM BIOS...#; # %ds points to the bootsector#; movw $0, 0x40 # version = 0 means no APM BIOS#; movw $0x05300, %ax # APM BIOS installation check#; xorw %bx, %bx#; int $0x15#; jc done_apm_bios # Nope, no APM BIOS#; #; cmpw $0x0504d, %bx # Check for "PM" signature#; jne done_apm_bios # No signature, no APM BIOS#;#; andw $0x02, %cx # Is 32 bit supported?#; je done_apm_bios # No 32-bit, no (good) APM BIOS#;#; movw $0x05304, %ax # Disconnect first just in case#; xorw %bx, %bx#; int $0x15 # ignore return code#; movw $0x05303, %ax # 32 bit connect#; xorl %ebx, %ebx#; xorw %cx, %cx # paranoia :-)#; xorw %dx, %dx # ...#; xorl %esi, %esi # ...#; xorw %di, %di # ...#; int $0x15#; jc no_32_apm_bios # Ack, error. #;#; movw %ax, (66) # BIOS code segment#; movl %ebx, (68) # BIOS entry point offset#; movw %cx, (72) # BIOS 16 bit code segment#; movw %dx, (74) # BIOS data segment#; movl %esi, (78) # BIOS code segment lengths#; movw %di, (82) # BIOS data segment length#;# Redo the installation check as the 32 bit connect#;# modifies the flags returned on some BIOSs#; movw $0x05300, %ax # APM BIOS installation check#; xorw %bx, %bx#; xorw %cx, %cx # paranoia#; int $0x15#; jc apm_disconnect # error -> shouldn't happen#;#; cmpw $0x0504d, %bx # check for "PM" signature#; jne apm_disconnect # no sig -> shouldn't happen#;#; movw %ax, (64) # record the APM BIOS version#; movw %cx, (76) # and flags#; jmp done_apm_bios#;#;apm_disconnect: # Tidy up#; movw $0x05304, %ax # Disconnect#; xorw %bx, %bx#; int $0x15 # ignore return code#;#; jmp done_apm_bios#;#;no_32_apm_bios:#; andw $0xfffd, (76) # remove 32 bit support bit#;done_apm_bios:#;#endif#;#;#include "edd.S"#;#;get_misc_info_end:# Now we want to move to protected mode ... cmpw $0, %cs:realmode_swtch - start jz rmodeswtch_normal lcall *%cs:realmode_swtch - start jmp rmodeswtch_endrmodeswtch_normal: pushw %cs call default_switchrmodeswtch_end:# we get the code32 start address and modify the below 'jmpi'# (loader may have changed it) movl %cs:code32_start - start, %eax movl %eax, %cs:code32 - start# Now we move the system to its rightful place ... but we check if we have a# big-kernel. In that case we *must* not move it ... testb $LOADED_HIGH, %cs:loadflags - start jz do_move0 # .. then we have a normal low # loaded zImage # .. or else we have a high # loaded bzImage jmp end_move # ... and we skip movingdo_move0: movw $0x100, %ax # start of destination segment movw %cs, %bp # aka SETUPSEG subw $DELTA_INITSEG, %bp # aka INITSEG movw %cs:start_sys_seg - start, %bx # start of source segment clddo_move: movw %ax, %es # destination segment incb %ah # instead of add ax,#0x100 movw %bx, %ds # source segment addw $0x100, %bx subw %di, %di subw %si, %si movw $0x800, %cx rep movsw cmpw %bp, %bx # assume start_sys_seg > 0x200, # so we will perhaps read one # page more than needed, but # never overwrite INITSEG # because destination is a # minimum one page below source jb do_moveend_move:# then we load the segment descriptors movw %cs, %ax # aka SETUPSEG movw %ax, %ds # Check whether we need to be downward compatible with version <=201 cmpl $0, cmd_line_ptr - start jne end_move_self # loader uses version >=202 features cmpb $0x20, type_of_loader - start je end_move_self # bootsect loader, we know of it# Boot loader doesnt support boot protocol version 2.02.# If we have our code not at 0x90000, we need to move it there now.# We also then need to move the params behind it (commandline)# Because we would overwrite the code on the current IP, we move# it in two steps, jumping high after the first one. movw %cs, %ax cmpw $SETUPSEG, %ax je end_move_self cli # make sure we really have # interrupts disabled ! # because after this the stack # should not be used subw $DELTA_INITSEG, %ax # aka INITSEG movw %ss, %dx cmpw %ax, %dx jb move_self_1 addw $INITSEG, %dx subw %ax, %dx # this will go into %ss after # the movemove_self_1: movw %ax, %ds movw $INITSEG, %ax # real INITSEG movw %ax, %es movw %cs:setup_move_size - start, %cx std # we have to move up, so we use # direction down because the # areas may overlap movw %cx, %di decw %di movw %di, %si subw $(move_self_here - start+0x200), %cx rep movsb ljmp $SETUPSEG, $(move_self_here - start)move_self_here: movw $(move_self_here - start+0x200), %cx rep movsb movw $SETUPSEG, %ax movw %ax, %ds movw %dx, %ssend_move_self: # now we are at the right place## Enable A20. This is at the very best an annoying procedure.# A20 code ported from SYSLINUX 1.52-1.63 by H. Peter Anvin.# AMD Elan bug fix by Robert Schwebel.# movw $(a20_control_begin_string - start), %si call prtstr movw $0x00ff, %cx # try so many times on failure movw $0x0101, %dx # non-zero means `enable' call enable_disable_a20 jz 3f movw $(a20_control_fail_string - start), %si call prtstr1: hlt jmp 1b3: movw $(a20_control_ok_string - start), %si call prtstr# set up gdt and idt lidt idt_48 - start # load idt with 0,0 xorl %eax, %eax # Compute gdt_base movw %ds, %ax # (Convert %ds:gdt to a linear ptr) shll $4, %eax addl $gdt - start, %eax movl %eax, (gdt_48 - start+2) lgdt gdt_48 - start # load gdt with whatever is # appropriate# make sure any possible coprocessor is properly reset.. xorw %ax, %ax outb %al, $0xf0 call delay outb %al, $0xf1 call delay# well, that went ok, I hope. Now we mask all interrupts - the rest# is done in init_IRQ(). movb $0xFF, %al # mask all interrupts for now outb %al, $0xA1 call delay movb $0xFB, %al # mask all irq's but irq2 which outb %al, $0x21 # is cascaded# Well, that certainly wasn't fun :-(. Hopefully it works, and we don't# need no steenking BIOS anyway (except for the initial loading :-).# The BIOS-routine wants lots of unnecessary data, and it's less# "interesting" anyway. This is how REAL programmers do it.## Well, now's the time to actually move into protected mode. To make# things as simple as possible, we do no register set-up or anything,# we let the gnu-compiled 32-bit programs do that. We just jump to# absolute address 0x1000 (or the loader supplied one),# in 32-bit protected mode.## Note that the short jump isn't strictly needed, although there are# reasons why it might be a good idea. It won't hurt in any case. movw $1, %ax # protected mode (PE) bit lmsw %ax # This is it! jmp flush_instrflush_instr: xorw %bx, %bx # Flag to indicate a boot xorl %esi, %esi # Pointer to real-mode code movw %cs, %si subw $DELTA_INITSEG, %si shll $4, %esi # Convert to 32-bit pointer# jump to startup_32 in arch/i386/boot/compressed/head.S# # NOTE: For high loaded big kernels we need a# jmpi 0x100000,__BOOT_CS## but we yet haven't reloaded the CS register, so the default size # of the target offset still is 16 bit.# However, using an operand prefix (0x66), the CPU will properly# take our 48 bit far pointer. (INTeL 80386 Programmer's Reference# Manual, Mixing 16-bit and 32-bit code, page 16-6) .byte 0x66, 0xea # prefix + jmpi-opcodecode32: .long 0x1000 # will be set to 0x100000 # for big kernels .word __BOOT_CS# Here's a bunch of information about your current kernel..kernel_version: .ascii UTS_RELEASE .ascii " (" .ascii LINUX_COMPILE_BY .ascii "@" .ascii LINUX_COMPILE_HOST .ascii ") " .ascii UTS_VERSION .byte 0# This is the default real mode switch routine.# to be called just before protected mode transitiondefault_switch: cli # no interrupts allowed ! movb $0x80, %al # disable NMI for bootup # sequence outb %al, $0x70 lret#-----------------------------------------------------------------------------# DOS device driver and EXE will use this code to enable/disable A20#----------------------------------------------------------------------------- // to asure the command-line menu will not overwrite our code here . = start + 0x1000 + 0x82 + (. - (start + 0x1000 + 0x82)) * (1 & (. > (start + 0x1000 + 0x82))) . = . - ((0x1000 + 0x81) / (. - start)) /* print ASCIZ string DS:SI (modifies AX BX SI) */1: xorw %bx, %bx /* video page 0 */ movb $0x0e, %ah /* print char in AL */ int $0x10 /* via TTY mode */prtstr: lodsb /* get token */ cmpb $0, %al /* end of string? */ jne 1b ret//# Routine to print asciiz string at ds:si//prtstr:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -