操作系统开发 – 婴儿教程 1
来源:互联网 发布:移动搜索引擎seo 编辑:程序博客网 时间:2024/04/29 12:10
The following code is the smallest possible example of booting code from a floppy.
; boot.asmhang: jmp hang times 512-($-$$) db 0
The CPU starts in real mode and the BIOS loads this code at address 0000:7c00. The "times 512..." stuff is NASM's way of saying fill up 512 bytes with zeros. And partcopy is going to expect that (200 in Hex = 512 in Decimal). Change it and you'll see Partcopy choke.
Often, you will see a so-called boot signature (0xAA55) at the end. Older versions of BIOSes looked for this in order to identify a boot sector on a disk. It is evidently unnecessary nowadays. If it's needed, the last line would be replaced with (or some version of it)
; boot.asmhang: jmp hang times 510-($-$$) db 0 ; 2 bytes less now db 0x55 db 0xAA
But the thing I'd really like to point out is how once you've booted, and the cursor is happily blinking on a blank screen, you might notice two things. One is that the floppy motor will turn off and the other is that you can press Ctrl-Alt-Del to reboot. The point is that interrupts (such as INT 0x09) as still being generated.
For kicks try clearing the interrupts flag:
;boot.asm cli hang: jmp hang times 510-($-$$) db 0 db 0x55 db 0xAA
You may notice that the floppy motor doesn't turn off and you can't reboot with Ctrl-Alt-Del.
If you try to reduce this even more by removing the loop and merely pad out the sector with zeros, the BIOS will have something to say about it. On my machine, it was "Operating System Not Found". I have yet to try filling the sector with zeros except for adding a boot signature.
Not exactly something you would show your girlfriend, but I wanted to show just what the bare minimum is before I elaborate. Unless I'm irritating anyone, in which case I'll desist.
Creating disk image
The code is assembled in NASM and copied to floppy using partcopy,dd,or debug. Then you simply boot from the floppy.
Windows
nasmw boot.asm -f bin -o boot.binpartcopy boot.bin 0 200 -f0 ORdebug boot.bin-W 100 0 0 1-Q
Unix
nasm boot.asm -f bin -o boot.bindd if=boot.bin of=/dev/fd0
- 操作系统开发 – 婴儿教程 1
- 操作系统开发 – 婴儿教程 2
- 操作系统开发 – 婴儿教程 3
- 操作系统开发 – 婴儿教程 4
- 操作系统开发 – 婴儿教程 5
- 操作系统开发 – 婴儿教程 6
- 操作系统开发 – 婴儿教程 7
- 操作系统开发 – 婴儿教程 8
- Google 手机操作系统 Android 开发教程 转载
- 《操作系统教程》读书笔记(1)
- Aix6.1操作系统安装教程
- 计算机操作系统教程 1 综述
- BEAR操作系统开发(1)
- 简明教程:如何在Solaris操作系统上开发C 应用程序
- 操作系统教程——概论(1)
- ROS机器人操作系统中级教程 1
- 1个人开发操作系统-初篇
- 1个人开发操作系统-初篇
- Android应用程序与SurfaceFlinger服务的关系概述和学习计划
- makefile 自动处理头文件的依赖关系
- 我理解的逻辑地址、线性地址、物理地址和虚拟地址
- C#控件设置技巧积累
- Android帧缓冲区(Frame Buffer)硬件抽象层(HAL)模块Gralloc的实现原理分析
- 操作系统开发 – 婴儿教程 1
- 业界云监控应用和市场现状
- 操作系统开发 – 婴儿教程 2
- 做淘宝客要懂得如何去分析竞争对手
- Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器
- Web应用界面设计规范—给项目组培训
- Android系统的开机画面显示过程分析
- 操作系统开发 – 婴儿教程 3
- 【研发管理】从技术到管理,思维转变是关键