我怎么能直接写在屏幕上? [英] How can I write directly to the screen?

查看:119
本文介绍了我怎么能直接写在屏幕上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个十几岁谁已经成为汇编语言非常感兴趣。我试着写在英特尔x86汇编一个小的操作系统,我想知道如何直接写入到屏幕上,在不依赖于BIOS或任何其他工作CPCI系统。我一直在寻找通过coreboot,Linux和一颗Kolibri的来源,除其他外,发现和了解一些片code,做这一点的希望。我还没有成功地在这方面,但我相信我会再看看Linux的源$ C ​​$ C,它是最理解我的来源我已经搜查过。

I'm a teenager who has become very interested in assembly language. I'm trying to write a small operating system in Intel x86 assembler, and I was wondering how to write directly to the screen, as in without relying on the BIOS or any other operating sytems. I was looking through the sources of coreboot, Linux, and Kolibri, among others, in the hopes of finding and understanding some piece of code that does this. I have not yet succeeded in this regard, though I believe I'll take another look at the Linux source code, it being the most understandable to me of the sources I've searched through.

如果有人知道这一点,或者知道哪里在一些片源$ C ​​$ C的,我可以看看,我会AP preciate它,如果他们告诉我的。

If anybody knows this, or knows where in some piece of source code that I could look at, I would appreciate it if they told me.

或者更好的是,如果有人知道如何确定哪些英特尔的x86 CPU上的I / O端口连接到什么样的硬件,这将是AP preciated了。我要问这个的原因是,在没有输入/输出在Intel 64和IA-32架构软件开发人员手册第1卷的一章:基本结构,也没有在第3卷各部分的IN或OUT指令,我能找到任何信息。因为它已经太艰苦来搜索,我有来源的相关说明。

Or better yet, if someone knows how to identify what I/O port on an Intel x86 CPU connects to what piece of hardware, that would be appreciated too. The reason I need to ask this, is that in neither the chapter for input/output in the Intel 64 and IA-32 Architectures Software Developer's Manual Volume 1: Basic Architecture, nor in the sections for the IN or OUT instruction in Volume 3, could I find any of this information. And because it has been too arduous to search for the relevant instructions in the sources that I have.

推荐答案

第1部分

有关旧的VGA模式,有写入(传统)显示存储器区域的固定的地址。对于文本模式,这个区域开始于0x000B8000。对于图形模式,它开始于0x000A0000。

For old VGA modes, there's a fixed address to write to the (legacy) display memory area. For text modes this area starts at 0x000B8000. For graphics modes it starts at 0x000A0000.

(例如那些由VESA / VBE接口设置)这不起作用,因为传统的显示内存区域的大小限制为64个昆明植物,最高分辨率的视频模式需要更多的空间,对于高分辨率视频模式(如:1024 * 768 * 32 = BPP 2.25 MIB)。要解决这个问题,有一项VBE支持2种不同的方法。

For high-resolution video modes (e.g. those set by the VESA/VBE interface) this doesn't work because the size of legacy display memory area is limited to 64 KiB and most high-resolution video modes need a lot more space (e.g. 1024 * 768 * 32-bpp = 2.25 MiB). To get around that there's 2 different methods supported by VBE.

第一种方法被称为银行开关,只有显卡的显示内存的一部分,在任何时候被映射到传统领域(你可以更改部分映射)。这可以是相当混乱 - 例如,画一个像素您可能需要计算出银行像素为,然后切换到银行,然后计算在银行抵消。为了使这种糟糕的是,对于某些视频模式(例如24-bpp的视频模式那里的每个像素3字节)仅一个像素的数据的第一部分可能是在一个银行,并且在同一象素的数据的第二部分是在不同的银行。这样做的主要好处是,它与真正的寻址模式,为传统显示内存区域低于0x00100000。

The first method is called "bank switching", where only part of the video card's display memory is mapped into the legacy area at any time (and you can change which part is mapped). This can be quite messy - for example, to draw one pixel you might need to calculate which bank the pixel is in, then switch to that bank, then calculate which offset in the bank. To make this worse, for some video modes (e.g. 24-bpp video modes where there's 3 bytes per pixel) only the first part of a pixel's data might be in one bank and the second part of the same pixel's data is in a different bank. The main benefit of this is that it works with real mode addressing, as the legacy display memory area is below 0x00100000.

第二种方法称为线性帧缓冲(或只是LFB),其中,视频卡的整个显示存储器区域可在没有任何杂乱银行交换访问。你要问的VESA / VBE界面,在这个区域(和它的典型的PCI洞的地方为0xC0000000和0xFFF00000之间)。这意味着你不能访问它在实模式,并需要使用保护模式或长模式或不真实的模式。

The second method is called "Linear Framebuffer" (or just "LFB"), where the video card's entire display memory area can be accessed without any messy bank switching. You have to ask the VESA/VBE interface where this area is (and it's typically in the "PCI hole" somewhere between 0xC0000000 and 0xFFF00000). This means you can't access it in real mode, and need to use protected mode or long mode or "unreal mode".

要当您使用LFB模式找到一个像素的地址,你会做这样的事pixel_address = display_memory_address + Y * bytes_per_line + X * bytes_per_pixel。在bytes_per_line来自VESA / VBE接口(也可能不一样horizo​​ntal_resolution * bytes_per_line,因为可以有水平线之间填充)。

To find the address of a pixel when you're using an LFB mode, you'd do something like "pixel_address = display_memory_address + y * bytes_per_line + x * bytes_per_pixel". The "bytes_per_line" comes from the VESA/VBE interface (and may not be the same as "horizontal_resolution * bytes_per_line" because there can be padding between horizontal lines).

有关银行交换VBE / VESA模式,它变得更像是:

For "bank switched" VBE/VESA modes, it becomes something more like:

pixel_offset = y * bytes_per_line + x * bytes_per_pixel;
bank_number = pixel_offset / bank_size;
pixel_starting_address_within_bank = pixel_offset % bank_size;

对于一些老的VGA模式(如256色模式0x13),这是非常相似的LFB,除了有行之间没有填充,你可以做pixel_address = display_memory_address +(Y * horizo​​ntal_resolution + X)* bytes_per_pixel 。对于文本模式,它基本上是同样的事情,除了2个字节确定每个字符和它的属性 - 例如char_address = display_memory_address +(Y * horizo​​ntal_resolution + X)* 2。对于其他老的VGA模式(黑白/ 2色,4色和16色模式)的视频卡的内存被安排完​​全不同。它分为其中每个平面包含的像素的一位,(例如为)双雄中,你需要写4个独立的平面16色模式来更新一个像素。出于性能方面的VGA硬件支持不同的写入模式和不同的读取模式,它可能很复杂(太复杂,以充分形容这里)。

For some old VGA modes (e.g. the 256-colour "mode 0x13") it's very similar to LFB, except there is no padding between lines and you can do "pixel_address = display_memory_address + (y * horizontal_resolution + x) * bytes_per_pixel". For text modes it's basically the same thing, except 2 bytes determine each character and its attribute - e.g. "char_address = display_memory_address + (y * horizontal_resolution + x) * 2". For other old VGA modes (monochrome/2-colour, 4-colour and 16-colour modes) the video card's memory is arranged completely differently. It's split into "planes" where each plane contains one bit of the pixel, and (for e.g.) to update one pixel in a 16-colour mode you need to write to 4 separate planes. For performance reasons the VGA hardware supports different write modes and different read modes, and it can get complicated (too complicated to describe adequately here).

第2部分

有关I / O端口(80x86的,PC兼容机),有3大类。首先是事实标准,它使用固定的I / O端口旧设备。这包括像PIC芯片,ISA DMA控制器,PS / 2控制器,PIT芯片,串行/并行端口等几乎任何介绍了如何编程这些设备会告诉你装置使用的I / O端口。

For I/O ports (on 80x86, "PC compatibles"), there's 3 general categories. The first is "de facto standard" legacy devices which use fixed I/O ports. This includes things like the PIC chips, ISA DMA controller, PS/2 controller, PIT chip, serial/parallel ports, etc. Almost anything that describes how to program each of these devices will tell you which I/O ports the device uses.

下一类是传统/ ISA设备,其中I / O端口上的设备使用由跳线卡本身决定的,而且也没有正常的方式,以确定它们从软件使用的I / O端口。为了解决这个问题的最终用户必须知道哪些I / O端口,每个设备使用的操作系统。值得庆幸的是这个东西硬皮所有已过时(尽管这并不一定意味着没有人使用它)。

The next category is legacy/ISA devices, where the I/O ports the devices use is determined by jumpers on the card itself, and there's no sane way to determine which I/O ports they use from software. To get around this the end-user has to tell the OS which I/O ports each device uses. Thankfully this crusty stuff has all become obsolete (although that doesn't necessarily mean that nobody is using it).

第三类是即插即用放大器;玩,那里有问其I / O端口,它使用(在大多数情况下,更改设备使用I / O端口)的设备的一些方法。这样的一个例子是PCI,那里有一个PCI配置空间,告诉你许多关于每个PCI设备的信息。对于这个类,有办法的人不能够确定将使用哪些设备而I / O端口,而不会在运行时做这件事,并更改某些BIOS设置可能会导致任何/所有这些设备来改变I / O端口。

The third category is "plug & play", where there's some method of asking the device which I/O ports it uses (and in most cases, changing the I/O ports the device uses). An example of this is PCI, where there's a "PCI configuration space" that tells you lots of information about each PCI device. For this categories, there is no way anyone can determine which devices will be using which I/O ports without doing it at run-time, and changing some BIOS settings can cause any/all of these devices to change I/O ports.

另外请注意,Intel的CPU只有一个的CPU。没有$ P $从东西是一个PC兼容的计算机完全不同的使用pvents这些CPU。 Intel的CPU手册将永远不会告诉你存在的CPU本身(包括芯片组或设备)以外的任何硬件

Also note that an Intel CPU is only a CPU. Nothing prevents those CPUs from being used in something that is radically different to a "PC compatible" computer. Intel's CPU manuals will never tell you anything about hardware that exists outside of the CPU itself (including the chipset or devices).

3部分

大概去的更多信息(这是针对OS开发者/爱好者)是 http://osdev.org/ (最好的地方他们的wiki网站的论坛)。

Probably the best place to go for more information (that's intended for OS developers/hobbyists) is http://osdev.org/ (their wiki and their forums).

这篇关于我怎么能直接写在屏幕上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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