我是靠谱客的博主 优美乌龟,这篇文章主要介绍操作系统:使用AT&T实现引导扇区,现在分享给大家,希望可以做个参考。

参考学习于渊的书箱时,里面都是用nasm来写的,而自己更熟悉和使用AT&T的语法,心想用AT&T来实现一下,这个过程是十分漫长与痛苦的,但也收获颇丰。


1. 引导扇区代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
.code16 .section .text .globl _start _start: movw %cs, %ax movw %ax, %ds movw %ax, %es call DispStr loop1: jmp loop1 DispStr: movw $BootMessage, %ax movw %ax, %bp movw $0x10, %cx movw $0x1301, %ax movw $0xc, %bx movb $0, %dl int $0x10 ret BootMessage: .ascii "Hello, MN world!" .org 510 .word 0xAA55

如果理解有些难,请先参考我的另一篇文章《操作系统:实现引导扇区》 http://blog.csdn.net/furzoom/article/details/52485090

首先.code16含义为16位运行模式,参考http://web.mit.edu/gnu/doc/html/as_18.html#SEC209

While GAS normally writes only "pure" 32-bit i386 code, it has limited support for writing code to run in real mode or in 16-bit protected mode code segments. To do this, insert a `.code16' directive before the assembly language instructions to be run in 16-bit mode. You can switch GAS back to writing normal 32-bit code with the `.code32' directive.

2. 编译

复制代码
1
2
3
4
5
6
as -o boot.o boot.s ld -Ttext=0x7c00 --oformat binary -o boot.bin boot.o dd if=/dev/zero of=emptydisk.img bs=512 count=2880 dd if=boot.bin of=Finix.img bs=512 count=1 dd if=emptydisk.img of=Finix.img skip=1 seek=1 bs=512 count=2879


3. 运行

VirtualBox运行结果:

Bochs运行结果:


4. 参考

于渊《自己动手写操作系统》

关于.code16指令:http://web.mit.edu/gnu/doc/html/as_18.html#SEC209


转载于:https://www.cnblogs.com/furzoom/p/7710230.html

最后

以上就是优美乌龟最近收集整理的关于操作系统:使用AT&T实现引导扇区的全部内容,更多相关操作系统内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部