GeekOS源代码学习(1) fd_boot.asm 和 setup.asm

本文主要介绍了GeekOS操作系统中fd_boot.asm和setup.asm两个汇编文件的源代码学习,相较于Sagalinux,它们提供了更好的扩展性和初始化功能。内容以代码展示为主,作为作者个人学习的记录,可能对读者帮助有限。欢迎大家留言交流。
摘要由CSDN通过智能技术生成

这两个汇编文件完成的功能和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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值