本文介绍了如何产生一个最小的BIOS的Hello World的引导与GCC部门从在真实硬件USB记忆棒的作品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已成功地生产出最小的引导扇区,与QEMU工作2.0.0的Ubuntu 14.04:

I have managed to produce a minimal boot sector that works with QEMU 2.0.0 Ubuntu 14.04:

.code16
.global _start
_start:
    cli
    mov $msg, %si
    mov $0x0e, %ah
loop:
    lodsb
    or %al, %al
    jz halt
    int $0x10
    jmp loop
halt:
    hlt
msg:
    .asciz "hello world"
.org 510
.word 0xaa55

与编译:

as -o main.o main.S
ld --oformat binary -o main.img -Ttext 0x7C00 main.o

这个例子可在此回购:https://github.com/cirosantilli/x86-bare-metal-examples/tree/2b79ac21df801fbf4619d009411be6b9cd10e6e0/no-ld-script

qemu -hda main.img

它显示了的Hello World 如预期在仿真器屏幕。

但是,如果我尝试刻录到USB:

But if I try to burn to a USB:

sudo dd if=main.img of=/dev/sdb

然后只需将USB插入一台ThinkPad T400 T430或者,打F12,并选择USB我观察的是:

then plug the USB into a ThinkPad T400 or T430, hit F12, and select the USB what I observe is:


  • 一些启动的消息显示快速

  • 然后屏幕一片空白,只在顶部
  • 一个下划线光标
  • some boot messages show up quickly
  • then the screen goes blank, with only a underscore cursor at the top

我还测试了Ubuntu的14.04图像相同的USB接口,它启动罚款,所以USB工作。

I have also tested the same USB with a Ubuntu 14.04 image, and it booted fine, so the USB is working.

如何改变这个例子,这样它会引导硬件和显示的Hello World消息?

How should I change this example so that it will boot on the hardware and show the hello world message?

什么是Ubuntu的形象,我创建了一个区别?

What is the difference between the Ubuntu image and the one I've created?

在哪里这个记录?

我已经上传须藤dmide code 的输出的T400到:的

I have uploaded the output of sudo dmidecode on the T400 to: https://gist.github.com/cirosantilli/d47d35bacc9be588009f#file-lenovo-t400

推荐答案

正如@Jester提到的,我不得不零 DS

As mentioned by @Jester, I had to zero DS with:

@@ -4,2 +4,4 @@ _start:
     cli
+    xor %ax, %ax
+    mov %ax, %ds
     mov $msg, %si

请注意,这是不可能的 MOV 的立即到 DS :我们必须通过 AX :8086-我们为什么不能移动的即时数据到段寄存器?

Note that it is not possible to mov immediates to ds: we must pass through ax: 8086- why can't we move an immediate data into segment register?

所以,问题的根源是QEMU的初始状态和实际硬件之间的区别。

So the root of the problem was difference between QEMU's initial state and that of the real hardware.

我现在加入以下16位初始化code到我所有的引导程序,以保证清洁的初始状态。并非所有这些都是强制性的,因为在评论中提到迈克尔·佩奇。

I am now adding the following 16-bit initialization code to all my bootloaders to guarantee a cleaner initial state. Not all of those are mandatory as mentioned by Michael Petch on the comments.

 .code16
cli
/* This sets %cs to 0. TODO Is that really needed? */
ljmp $0, $1f
1:
xor %ax, %ax
/* We must zero %ds for any data access. */
mov %ax, %ds
/* The other segments are not mandatory. TODO source */
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
/*
TODO What to move into BP and SP? http://stackoverflow.com/questions/10598802/which-value-should-be-used-for-sp-for-booting-process
Setting BP does not seem mandatory for BIOS.
*/
mov %ax, %bp
/* Automatically disables interrupts until the end of the next instruction. */
mov %ax, %ss
/* We should set SP because BIOS calls may depend on that. TODO confirm. */
mov %bp, %sp

我还发现这个密切相关的问题:C内核 - 工作正常VM上而不是实际的计算机

的英特尔手册卷3系统编程指南 - 325384-056US 2015年9月 9.10.2STARTUP.ASM上市
包含了大量的初始化例子。

The Intel Manual Volume 3 System Programming Guide - 325384-056US September 2015 9.10.2 "STARTUP.ASM Listing" contains a large initialization example.

这篇关于如何产生一个最小的BIOS的Hello World的引导与GCC部门从在真实硬件USB记忆棒的作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 03:12