在JOS中加载全局/中断描述符表寄存器后,BIOS会做什么?

时间:2016-07-06 10:27:12

标签: operating-system bios

我已经分析了BIOS开始执行时的第一个代码,直到加载全局/中断描述符表寄存器。我正在谈论的BIOS是麻省理工学院课程"操作系统工程"的BIOS。我很难理解BIOS之后的工作方式。

[f000:fff0]    0xffff0: ljmp   $0xf000,$0xe05b
#when BIOS starts executing, jump to the address fe05bH to continue to execute
[f000:e05b]    0xfe05b: cmpl   $0x0,%cs:0x6574
[f000:e062]    0xfe062: jne    0xfd2b6
[f000:e066]    0xfe066: xor    %ax,%ax
[f000:e068]    0xfe068: mov    %ax,%ss
#set %ss to 0
[f000:e06a]    0xfe06a: mov    $0x7000,%esp
[f000:e070]    0xfe070: mov    $0xf3c24,%edx
[f000:e076]    0xfe076: jmp    0xfd124
[f000:d124]    0xfd124: mov    %eax,%ecx
[f000:d127]    0xfd127: cli
#turn off interrupt
[f000:d128]    0xfd128: cld 
# set DF flag to 0, when  DF=0, SI = SI + 1 , DI = DI + 1
[f000:d129]    0xfd129: mov    $0x8f,%eax
[f000:d12f]    0xfd12f: out    %al,$0x70
[f000:d131]    0xfd131: in     $0x71,%al
#close NMI through 70H I/O port, selecting CMOS 0xF register, and assigining 0xF register's value to %al register
[f000:d133]    0xfd133: in     $0x92,%al
[f000:d135]    0xfd135: or     $0x2,%al
[f000:d137]    0xfd137: out    %al,$0x92
#enable A20 address line
[f000:d139]    0xfd139: lidtw  %cs:0x6690
[f000:d13f]    0xfd13f: lgdtw  %cs:0x6650
#loading Global/Interrupt Descriptor Table Register
[f000:d145]    0xfd145: mov    %cr0,%eax
[f000:d148]    0xfd148: or     $0x1,%eax
[f000:d14c]    0xfd14c: mov    %eax,%cr0
#set CR0 PE=1. when PE=1 CPU is in protected mode
[f000:d14f]    0xfd14f: ljmpl  $0x8,$0xfd157
 The target architecture is assumed to be i386
 => 0xfd157:    mov    $0x10,%eax
 => 0xfd15c:    mov    %eax,%ds
 => 0xfd15e:    mov    %eax,%es
 => 0xfd160:    mov    %eax,%ss
 => 0xfd162:    mov    %eax,%fs
 => 0xfd164:    mov    %eax,%gs
 #After loading GDTR, it's necessary to reload all the segment register
 .....

在这些代码之后,我不知道BIOS如何执行以搜索可引导设备,例如软盘,硬盘驱动器或CD-ROM。最终,当它找到可引导磁盘时,BIOS从磁盘读取引导加载程序并将控制转移到它

1 个答案:

答案 0 :(得分:0)

超级迟到的回复,但我有同样的问题,并在SeaBIOS source code

中找到答案

我链接的页面是映射到重置向量的向量的源代码。 如果你真的想要解析GDB中40千字节的BIOS代码,可以随意获取一些草稿纸并开始绘制堆栈布局和BIOS代码布局。在决定阅读源代码之前,我花了几个小时做这件事;阅读源代码可能更健康。

编辑:还可以在维基百科页面上查看选项ROM上BIOS的this section,提供有关选项ROM的更多信息,而不是选项ROM的维基百科页面。永远想弄清楚。