这两个汇编文件完成的功能和sagalinux中的基本一致,只不过实现的更好一点,增强了一些扩展性。
就把代码贴在这里。
看看就行,好像我一直是在贴代码。。。。这只算是我自己学习的一个记录吧。。。可能对大家帮助不大。
欢迎同学们留言讨论哦。
./src/geekos/boot.asm
; fd_boot.asm编译出的二进制代码存放在软盘的0号扇区内,BIOS会将此代码复制到0x07c00运行时它先将自身复制到0x90000处,然后跳到0x90000执行。
; 执行时把setup代码和kernel代码载入到内存0x90200处和0x10000,boot代码执行完后 跳到内存中的0x90200处执行setup代码
; Boot sector for GeekOS
; Copyright (c) 2001,2004 David H. Hovemeyer <daveho@cs.umd.edu>
; Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
; $Revision: 1.5 $
; This is free software. You are permitted to use,
; redistribute, and modify it as specified in the file "COPYING".
; Loads setup code and a program image from sectors 1..n of a floppy
; and executes the setup code (which will in turn execute
; the program image).
; Some of this code is adapted from Kernel Toolkit 0.2
; and Linux version 2.2.x, so the following copyrights apply:
; Copyright (C) 1991, 1992 Linus Torvalds
; modified by Drew Eckhardt
; modified by Bruce Evans (bde)
; adapted for Kernel Toolkit by Luigi Sgro
%include "defs.asm"
; Pad to desired offset from start symbol.
; Usage: Pad_From_Symbol offset, symbol
;带两个参数的宏,在剩下的空间填充0,使达到一个扇区的大小
%macro Pad_From_Symbol 2
times (%1 - ($ - %2)) db 0
%endmacro
; ----------------------------------------------------------------------
; The actual code
; ----------------------------------------------------------------------
[BITS 16]
[ORG 0x0]
BeginText: ; needed to calculate padding bytes to fill the sector
; Copy the boot sector into INITSEG.
mov ax, BOOTSEG ; mov ax, 0x7c0
mov ds, ax ; source segment for string copy
xor si, si ; source index for string copy
mov ax, INITSEG ; mov ax, 0x900
mov es, ax ; destination segment for string copy
xor di, di ; destination index for string copy
cld ; clear direction flag
mov cx, 256 ; number of words to copy
rep movsw ; copy 512 bytes
jmp INITSEG:after_move ; after_move is a offset.the offset in a segment won't change even the place of segment changes.
after_move:
; Now we're executing in INITSEG
; We want the data segment to refer to INITSEG
; (since we've defined variables in the same place as the code)
mov ds, ax ; ax still contains INITSEG
; Put the stack in the place where we were originally loaded.
; By definition, there is nothing important there now.
mov ax, 0
mov ss, ax
mov sp, (BOOTSEG << 4) + 512 - 2
load_setup:
; Load the setup code.
mov ax, word [setupStart] ;mov ax, 1,setup从扇区号1开始
mov word [sec_count], ax ;mov word [sec_count], 1
add ax, [setupSize] ;注意这里的setupSize依赖于setup.s编译出的二进制文件大小,在根目录下的Makefile中由已编译出的setup.bin文件获得
mov word [max_sector], ax ;fd_boot.bin和setup.bin在软盘上扇区号0~[max_sector],(setup.bin占1个扇区的话就是0~2)
.again:
mov ax, [sec_count] ;
push ax ; 1st param to ReadSector (log sec num),setup从扇区1开始存放
push word SETUPSEG ; 2nd param to ReadSec