/*
* 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