/*
* 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.
*
*/
我们处于实模式下,使用64k个段,因此段地址必须是16的倍数,为避免冲突,线性地址用16进制头书写,段地址作为偏移书写
#include <asm/segment.h>
#include <linux/utsrelease.h>
#include <asm/boot.h>
#include <asm/e820.h>
#include <asm/page_types.h>
#include <asm/setup.h>
#include "boot.h"
#include "offsets.h"
BOOTSEG = 0x07C0 /* original address of boot-sector */
SYSSEG = 0x1000 /* historical load address >> 4 */
#ifndef SVGA_MODE
#define SVGA_MODE ASK_VGA
#endif
#ifndef RAMDISK
#define RAMDISK 0
#endif
#ifndef ROOT_RDONLY
#define ROOT_RDONLY 1
#endif
.code16
.section ".bstext", "ax"
.global bootsect_start
bootsect_start:
# Normalize the start address
ljmp $BOOTSEG, $start2 跳到0x07c000start2的地方
start2:
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
xorw %sp, %sp
sti允许中断
cld
movw $bugger_off_msg, %si
msg_loop:
lodsb将DS:[si]中的内容取到AL中,由于前边的cld,si开始递减
andb %al, %al
jz bs_die 如果bug信息打完,则跳转
AL-显示ASCII字符
BH-页号(在我们要进行的工作中,它一直是0x00)
BL-文本属性(在我们将进行的工作中,它一直是0x07) 通过更改它的值可以选择不同 的颜色等。
movb $0xe, %ah显示字符
movw $7, %bx
int $0x10 INT 0x10是BIOS视频中断
jmp msg_loop
bs_die:
# Allow the user to press a key, then reboot
xorw %ax, %ax清零
int $0x16按任意键重启
16 |
1 |
读键盘缓冲区字符 |
|
ZF=0 AL=字符码 |
int $0x19
重新启动系统
# int 0x19 should never return. In case it does anyway,
# invoke the BIOS reset code...
ljmp $0xf000,$0xfff0跳转到f000,fff0
bios的重置码
.section ".bsdata", "a"
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