实模式BIOS例程和保护模式 [英] Real mode BIOS routine and Protected Mode

查看:125
本文介绍了实模式BIOS例程和保护模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些OS实验.到目前为止,我所有的代码都利用实模式BIOS中断来操作硬盘和软盘.但是一旦我的代码启用了CPU的保护模式,所有的实模式BIOS中断服务例程将不可用.我如何读写硬盘和软盘? 我现在需要做一些硬件驱动程序吗?如何开始?这是OS如此难以开发的原因之一吗?

I am doing some OS experiment. Until now, all my code utilized the real mode BIOS interrupt to manipulate hard disk and floppy. But once my code enabled the Protect Mode of the CPU, all the real mode BIOS interrupt service routine won't be available. How could I R/W the hard disk and floppy? Do I need to do some hardware drivers now? How could I start? Is this one of the reasons that an OS is so difficult to develop?

我知道,硬件都是通过读写某些控制或数据寄存器来控制的.例如,我知道硬盘的命令块寄存器的范围是0x1F0到0x1F7. 但是我想知道PC平台上这么多不同硬件的寄存器地址是否相同?还是我必须在使用它们之前检测到它?如何检测到它们?

I know that hardwares are all controlled by reading from and writing to certain control or data registers. For example, I know that the Command Block Registers of hard disk range from 0x1F0 to 0x1F7. But I am wondering whether the register addresses of so many different hardwares are the same on the PC platform? Or do I have to detect that before using them? How to detect them??

由于我不确定如何在保护模式下读写软盘或硬盘,因此我现在必须使用BIOS中断将所有必要的内核文件从软盘加载到内存中.但是如果我的内核文件超过了实模式1M空间限制,我该怎么办?

Since I am not sure about how to R/W floppy or hard disk in Protect Mode, I have to use the BIOS interrupt to load all my necessary kernel file from floppy into memory for now. But what could I do if my kernel file exceeds the real mode 1M space limit?

对于任何回应,我深表感谢.

For any responses I present my deep appreciation.

我隐约记得,有一种方法可以先切换保护模式,然后再切换回实模式.然后,我们可以在保护模式下使用BIOS例程.也许我记得错了.有人记得对吗?

I vaguely recall that there's a way to switch Protected Mode first and then switched back to real mode. And then we could use the BIOS routine in Protected Mode. Maybe I remember wrong. Did someone remember it right?

推荐答案

虽然可以在保护模式和实模式之间进行切换是 ,但是几乎可以肯定,不是 d想做.这就是在286上所做的事情(很笨拙,因为它不故意支持从保护模式切换回实模式).但是从386开始,他们添加了V86模式,该模式可以作为任务在保护模式下运行.

While it's possible to switch between protected mode and real mode, it's almost certainly not what you'd want to do. This is how things were done on the 286 (quite clumsily, since it didn't intentionally support switching from protect mode back to real mode t all). Starting with the 386, however, they added a V86 mode which can run as a task in protected mode.

如果要从保护模式使用BIOS,几乎可以肯定这是处理问题的方法.您基本上可以创建一个V86任务,切换到它以使用BIOS,然后再切换回另一个任务以执行保护模式代码.

If you want to use the BIOS from protected mode, this is almost certainly the way to do things. You can basically create a V86 task, switch to it to use the BIOS, then switch back to another task to execute protected mode code.

如果您想玩这个游戏,不妨看看 DJGPP ,它是DOS扩展程序(基本上是我刚刚描述的程序,用于处理磁盘I/O等需要处理的V86任务的切入/切出),以及一个相当旧的版本的端口gcc的代码,因此您可以编写在其上运行的代码.

If you want to play with this, you might want to take a look at DJGPP, which is a DOS extender (basically, a program like I just described to handle the switching into/out of a V86 task as needed to handle disk I/O and such) along with a port of a rather old version of gcc so you can write code that runs on it.

DOS扩展器的商业市场现在已经基本消亡,因此至少有一个以前的DOS扩展器( HX )现在可以作为开放源代码使用.如果要使用该功能,则可能要与 OpenWatcom 编译器.

The commercial market for DOS extenders is now essentially dead, so at least one formerly commercial DOS extender (HX) is now available as open source. If you're going to play with that, you'd probably want to use it with the OpenWatcom compiler.

就读取大于1 MB的文件而言(例如),这很简单但笨拙:逐块读取数据,读完后您可以重新映射内存,或复制内容,以将阅读的内容带到您真正想要的地方,然后再读取另一个块.

As far as how you read a file of more than 1 MB (for example), it's simple but clumsy: read the data in chunks, and when you've finished a read you either re-map the memory, or copy the contents, to get what you read to where you really want it, then read another chunk.

就与硬件的交流而言:很大程度上取决于您是否只想在某种程度上发挥作用,还是要充分利用现有的硬件.只需使用基本的IDE端口,您就可以与几乎没有真正使用过的所有硬盘进行对话-但是,充分利用硬件的工作量还很多. IDE/ATAPI驱动器使用了大约六种不同的DMA模式,每种模式的设置必须略有不同.其中一些已经足够老了,您可能根本不在乎它们,因此您可能只想直接支持几个最新版本,而其他任何事情都可以回退到基本(非DMA)传输.

As far as talking to the hardware goes: a lot depends on whether you just want something that works to some degree, or if you want to take full advantage of the hardware that's present. Just using the basic IDE ports will let you talk to almost any hard drive that isn't really ancient -- but getting the most out of the hardware is quite a bit more work. IDE/ATAPI drives have used about a half dozen different DMA modes, each of which has to be set up slightly differently. Quite a few of those are old enough you probably don't care about them, so you might want to directly support only a couple of the newest, and for anything else fall back to basic (non-DMA) transfers.

这篇关于实模式BIOS例程和保护模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆