Write Your Own Operating System Tutorial(2)

Lesson 2: Making Our First Bootable Disk

In this lesson, we will learn how to create a boot program on a floppy disk.  We will start by modifying the Microsoft DOS Boot 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 Windows 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 DEBUG program and load the first sector of a formatted floppy disk into memory at address 0.  Then type the command

-u 3E

 

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 loop.  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 typing 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, BIOS 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 http://users.win.be/W0005997/GI/biosref.html.  A longer list of software interrupts can be found at http://burak1.virtualave.net/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 video 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
TensorFlow是一个开源的机器学习框架,用于构建和训练各种机器学习模型。TensorFlow提供了丰富的编程接口和工具,使得开发者能够轻松地创建、训练和部署自己的模型。 TensorFlow Tutorial是TensorFlow官方提供的学习资源,旨在帮助新手快速入门。该教程详细介绍了TensorFlow的基本概念、常用操作和各种模型的构建方法。 在TensorFlow Tutorial中,首先会介绍TensorFlow的基本工作原理和数据流图的概念。通过理解数据流图的结构和运行过程,可以更好地理解TensorFlow的工作方式。 接下来,教程会详细介绍TensorFlow的核心组件,例如张量(Tensor)、变量(Variable)和操作(Operation)。这些组件是构建和处理模型的基本元素,通过使用它们可以创建复杂的神经网络和其他机器学习模型。 在教程的后半部分,会介绍如何使用TensorFlow构建不同类型的模型,例如深度神经网络(DNN)、卷积神经网络(CNN)和递归神经网络(RNN)。每个模型都会有详细的代码示例和实践任务,帮助学习者掌握相关知识和技能。 此外,教程还包含了关于模型的训练、评估和优化的内容,以及如何使用TensorBoard进行可视化和调试。 总结来说,TensorFlow Tutorial提供了全面而详细的学习资源,通过学习该教程,可以快速入门TensorFlow,并且掌握构建和训练机器学习模型的方法。无论是初学者还是有一定经验的开发者,都可以从中受益并扩展自己的机器学习技能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HashCodeWithJava

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值