Write Your Own Operating System Tutorial(2) (轉)
In this lesson, we will learn how to create a boot program on a floppy disk. We will start by modifying the DBoot Record.
For our purposes, we want to replace the boot loader code without changing the other data in the boot sector. If we change the data to something invalid, then DOS and will not recognize the disk as being valid. Windows will give an error saying the disk is not formatted. This will cause you to be unable to access any of the files on the disk. However, we can change the boot program code all we want and, as long as we don’t mess with the other data, DOS and Windows will be able to read and write the files on the disk just fine.
We will leave the first instruction (jmp 0x3E) alone, because we need to jump over the Boot Record data. Thus we can begin modifying the code at 0x3E. Run the DOS DE program and load the first sector of a formatted floppy disk into memory at address 0. Then type the command
-u 3E
:namespace prefix = o ns = "urn:schemas-microsoft-com::office" />
to view the instructions there. Now, we will begin modifying the code. Type the command
-a 3E
to begin assembling instructions. The prompt changes from a hyphen to the address at the location that we gave. Type the following instruction and press enter.
jmp 3E
The instruction is assembled to machine code and placed into memory, and the following prompt is the next available memory after the instruction you just entered. Press Enter once more to exit the assembly mode. The whole procedure on my computer looked like this.
-a 3E
0AFC:003E jmp 3E
0AFC:0040
-
The segment address (0x0AFC, in my case) can (an probably will be) different on your computer, or even between different sessions of DEBUG. Now view the instruction you just entered by giving the unassembled command.
-u 3E
As you can see, the first instruction is now our jump instruction. This will create an infinite l. If we quit DEBUG now, no changes will be saved, but we can now write our modified boot sector back to the disk (overwriting the previous one) by ty this command.
-w 0 0 0 1
This "write" command uses the same syntax as the "load" command. This writes the data found at memory address 0 to disk 0, starting with sector 0 and writing 1 sector. Be very careful when using the write command. This command can be used to overwrite sectors on any drive, and cause loss of data.
You can now boot with this floppy. When you boot, will load the first sector off the disk into memory and begin execution at the beginning of the sector. This will be the jump to 0x3E instruction. The instruction there is one to jump to 0x3E, so this will continue forever. Try it. Boot up a computer with this disk. Nothing appears to happen. The computer will just sit there and do nothing. But your new “operating system” is running.
Okay, I know what you’re saying, you want to see some sign that the code you wrote is actually does running and you haven’t done something to mess up your computer. In order to do this, we are going to make function calls to BIOS (at least at first). As of the time of this writing, you can find a short list of BIOS function calls at . A longer list of software interrupts can be found at /Interrup.txt">, but keep in mind that some of those interrupts are BIOS calls, while others are MS-DOS calls which cannot be used since, of course, MS-DOS is not running. You would have to implement those functions yourself before using them.
We are going to use interrupt 0x10, function 0x0E to write a character to the screen. The registers must be set as follows.
AH = 0x0E
AL = ASCII code of the character to be printed
BL = color/style of character
Now, repeat the instructions in this lesson, only instead of entering the jump instruction as we did before, this time enter the following instructions.
-a 3E
0AF6:003E mov ah, 0e
0AF6:0040 mov al, 48
0AF6:0042 mov bl, 07
0AF6:0044 int 10
0AF6:0046 jmp 46
0AF6:0048
-
First we set AH to zero, AL to 0x48 (ASCII for the letter ‘H’), BL to 7 (color code for white-on-black), and then we call interrupt 0x10, which handles the vo controller. The last instruction creates an infinite loop like before, so things stop there. Save the modified boot sector to a disk (-w 0 0 0 1) and try booting with the disk. This time you should see the character ‘H’ printed on the screen before the system hangs.
Play around with this for a while. You can repeat the code for printing a character multiple times to print a phrase, or you can try out other software interrupts. When you are done, continue on to the next lesson where we will learn to use a full-blown assembler to write our programs rather than DEBUG.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993836/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- operating-system structuresStruct
- Is programming an Operating System so hard?
- What’s your own way of spending two-day weekend?
- mysql 啟動錯誤(InnoDB: Operating system error number 13 )MySqlError
- 【build your own xxx】實現你自己的bind函式UI函式
- 【build your own xxx】實現你自己的call和applyUIAPP
- 作業系統-Operating-System第一章:概述作業系統
- Operating Systems: Principles and Practice 2nd ed. Edition
- Pytorch | Tutorial-03 資料轉換PyTorch
- Project Management - 2) Estimate Your WorkProject
- 轉載:System:System.arraycopy方法詳解
- JQuery Plugin 2 - Passing Options into Your PluginjQueryPlugin
- Zeiss tutorial
- COMP3230 Principles of Operating Systems
- Pwn2Own黑客大賽:Safari瀏覽器被入侵黑客瀏覽器
- Batch Scripting TutorialBAT
- simvison tutorial pdf
- 【轉載】System_Verilog列印格式
- 【冷啟動#2】實用的springboot tutorial入門demoSpring Boot
- Pwn2Own黑客大賽首日:Safari、IE8被攻破黑客
- RabbitMQ tutorial - "Hello world!"MQ
- System.Linq.Dynamic字串轉委託字串
- Linux核心同步機制之(五):Read Write spin lock【轉】Linux
- 作業系統概念(Operating System Concepts Ninth Edition恐龍書)第三章課後非程式設計題答案作業系統程式設計
- Your title
- Detectron2-寫模型(Write Models)官方文件中文翻譯模型
- Pwn2Own Austin 2021 Cisco RV34x RCE 漏洞鏈復現
- 1155000美元獎金,Pwn2Own 2022溫哥華黑客大賽落幕黑客
- Pwn2Own 2020 春季賽落下帷幕,Fluoroacetate 團隊成最大贏家
- linux symbolic link attack tutorialLinuxSymbol
- [譯]A Simple CSS Animation TutorialCSS
- yii2 Unable to verify your data submission錯誤解決
- MongoDB Write ConcernMongoDB
- [Javascript] Write .call()JavaScript
- hio_write
- MySQL double writeMySql
- django rest framework個人學習筆記(四)————Tutorial2.Request and ResponseDjangoRESTFramework筆記
- Scan Your Truck Using Nexiq Adapter: Simplifying Your Diagnostic ProcessAPT
- Prettier your projectProject