linux2.6.11启动代码之bootsect.s

本文解析了一段典型的启动扇区代码,介绍了其通过BIOS中断显示消息的过程,并详细说明了Int10、Int16及Int19三个关键BIOS中断调用的功能。

/*

* bootsect.S Copyright (C) 1991, 1992 Linus Torvalds

*

* modified by Drew Eckhardt

* modified by Bruce Evans (bde)

* modified by Chris Noe (May 1999) (as86 -> gas)

* gutted by H. Peter Anvin (Jan 2003)

*

* BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment

* addresses must be multiplied by 16 to obtain their respective linear

* addresses. To avoid confusion, linear addresses are written using leading

* hex while segment addresses are written as segment:offset.

*

*/

这段代码首先是有bios系统调用装入的,应该是LILO的一部分。

这部分主要实现了一个显示bugger_off_msg的过程,主要有3个比较重要的bios调用,int 10

Int 16 int 19,下面详细的讲一下这三个系统调用的意思:

(1) Int 0x10

所用到的寄存器的解释:

AH = 0Eh

AL = 要显示的字符

BH = 页号(开启页机制的情况下)

BL = 前景色 (仅在图形模式下用)

Return: nothing

功能:display a character on the screen, advancing the cursor and scrolling

the screen as necessary

(2) Int 0x16

Inp.:

AH = 00h

Return: AH = BIOS scan code

AL = ASCII character

(3) Int 0x19

This interrupt reboots the system without clearing memory or restoring

interrupt vectors. Because interrupt vectors are preserved, this

interrupt usually causes a system hang if any TSRs have hooked

vectors from 00h through 1Ch, particularly INT 08.

/***********************************************************************

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

#include <asm/boot.h>

SETUPSECTS = 4 /* default nr of setup-sectors */

BOOTSEG = 0x07C0 /* original address of boot-sector */

INITSEG = DEF_INITSEG /* we move boot here - out of the way 0x9000*/

SETUPSEG = DEF_SETUPSEG /*setup starts here 0x9020*/

SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */

SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */

/* to be loaded */

ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */

SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */

#ifndef SVGA_MODE

#define SVGA_MODE ASK_VGA //0xfffd

#endif

#ifndef RAMDISK

#define RAMDISK 0

#endif

#ifndef ROOT_RDONLY

#define ROOT_RDONLY 1

#endif

.code16

.text

.global _start

_start:

# Normalize the start address

jmpl $BOOTSEG, $start2

start2:

movw %cs, %ax

movw %ax, %ds

movw %ax, %es

movw %ax, %ss

movw $0x7c00, %sp

sti //设置中断

cld //清除方向标志,cld即告诉程序sidi

//向前移动,std指令为设置方向,告诉程

//sidi向后移动

movw $bugger_off_msg, %si //si指向要显示的字符

/*********************************************

逐字符的显示bugger_off_msg中的内容

**************************************************************/

msg_loop:

lodsb // LODSB的功能是将DS:[si]中的内容取到AL中,然后SI<=SI+/-1

andb %al, %al

jz die // jejump if zero的意思,jzjump if equal的意思,两者都是结果为

//0(相等),zF=1,转移,

movb $0xe, %ah

movw $7, %bx

int $0x10 //显示

jmp msg_loop

die:

# Allow the user to press a key, then reboot

xorw %ax, %ax

int $0x16 //键盘中断 在ah中接收基本键盘输入功能信号

int $0x19

//int 19一般是不会执行的,因为在int 16之后系统将会跳到用户选择的系统运行,也就//是说如果用户不选择的话,系统将会重启,然后执行下面的跳转代码

# int 0x19 should never return. In case it does anyway,

# invoke the BIOS reset code...

ljmp $0xf000,$0xfff0 //

bugger_off_msg:

.ascii "Direct booting from floppy is no longer supported./r/n"

.ascii "Please use a boot loader program instead./r/n"

.ascii "/n"

.ascii "Remove disk and press any key to reboot . . ./r/n"

.byte 0

# Kernel attributes; used by setup

.org 497

setup_sects: .byte SETUPSECTS

root_flags: .word ROOT_RDONLY

syssize: .word SYSSIZE

swap_dev: .word SWAP_DEV

ram_size: .word RAMDISK

vid_mode: .word SVGA_MODE

root_dev: .word ROOT_DEV

boot_flag: .word 0xAA55

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值