精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>嵌入式开发>>操作系统设计与实现>>翻译计划—《写你自己的操作系统》>>翻译计划:《写你自己的操作系统》(Kernel Questions内核问题)

主题:翻译计划:《写你自己的操作系统》(Kernel Questions内核问题)
发信人: wenbobo()
整理人: wenbobo(2002-12-30 17:24:16), 站内信件
版主注:
我现在打算翻译Write Your Own Operating System [FAQ],希望有兴趣的朋友帮助翻译,我觉得翻译这样的文章是个很好的锻炼,至少比盲目写程序要值得。希望大家支持。有意承担翻译任务者请给我发email。

本文发表于http://www.mega-tokyo.com/os/os-faq.html
作者为 Stuart 'Dark Fiber' George <[email protected]>
本文的译者为 wenbobo <[email protected]>
转载请勿删除以上版权宣示信息
 



Kernel Questions 
内核问题


How do I make a kernel file I can load? 
如何做一个可加载的内核文件?

As with all things, you can do it several ways. You can tell GCC to output a flat binary file with no relocations, headers or any other information. I assume this is what you want. 
和其他事一样,您可以用几种方式来实现。您可以让GCC输出一个没有重定位、文件头以及其他信息的浮动二进制文件。我假定您就是这么做的。

example:
例如:
GCC -c my_kernel.c
LD my_kernel.o -o kernel.bin -oformat binary -Ttext 0x100000

The "-c" GCC switch tells GCC to only compile to an object file and not run the link process.
GCC的“-c”参数告诉GCC只编译成目标文件,不要运行连接程序

Running LD with "-oformat binary" tells the linker you want your output file to be plain, no relocations, no header information, just a straight flat binary image.
用“-oformat binary”参数运行LD是告诉连接器您需要的输出文件是简单的,没有重定位信息,没有文件头信息的,只是个单纯的浮动二进制映像。

"-Ttext 0x100000" tells linker you want your "text" (code segment) address to be at 1mb memory mark.
“-Ttext 0x100000”告诉连接器您打算把“text”(代码段)地址设到1 MB 内存的位置。

You have to of course, load your binary file image into the correct offset for it to run properly since all its relocations have been statically linked already.
当然,要能让它正确的运行,您必须把您的二进制文件装载到正确的偏移量,因为所有的重定位信息都已经被静态地连接好了。


Help! when I load my kernel my machine resets! 
求助!当引导我的内核时电脑重启动了
Yes. DJGPP outputs 32bit protected mode code. When your PC boots up it is in what is known as Real Mode, you have to switch your machine into Protected Mode, THEN jump to your kernel image. 
是的,DJGPP输出32位的保护模式代码。当您的电脑启动后它进入的是实模式,您必须把机器切换入保护模式,然后再跳入您的内核映像。

How you do this is up to you. You can alter your bootsector code to load your file, switch to protected mode and jump to your kernel image (if you have enough room for the code in your bootsector!) or you can write a stub program and stick that on to the front of your kernel image (assuming it gets loaded below 1mb memory mark) OR you can write a stub program, load it in under 1mb memory mark and have that program load in your kernel image.
您怎么做就是您的事情了。您可以改变您的引导区,用来加载您的文件,切换进保护模式,然后再跳入您的内核映像(如果您的引导扇区有足够的空间来放置这些代码的话!),或者您也可以写一段stub程序,附在您的内核映像的前面(假设它装载在1 MB内存以下的地址),或者您也可以写一个stub程序,把它装载到1 MB内存位置,再让这个程序来装载您的内核映像。
 
Is there an easier way to boot my kernel? 
有没有更容易的方法来引导我的内核呢?
Yes, there is an easier way to boot your kernel, and that is is by using an existing boot loader! 
是的,有一个方更加简单的方法来引导您的内核,那就是用一个已有的引导程序!

GRUB is probably the best bootloader around (and its GNU), and will take away the hassle of booting your kernel for you.
GRUB或许是可找到的最好的引导程序了(并且它是GNU软件),可以为您解决加载您的内核的那些麻烦。

You will no longer need to worry about trying to enable the A20 line, finding your kernel file on the disk or what filesystem your kernel is on!
不久您就得操心这些问题了:如何激活A20线,如何从磁盘上找到您的内核文件,以及内核该放在什么文件系统上!


----
掬水月在手
弄花香满身

[关闭][返回]