为什么程序集需要启动任何OS内核 [英] Why assembly needed to kick-start any OS kernel

查看:52
本文介绍了为什么程序集需要启动任何OS内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读如何编写简单的操作系统,说:

对于您的第一个OS,最好还是坚持使用MikeOS中使用的汇编语言.它更冗长且不可移植,但您不必担心编译器和链接器.此外,您需要一些汇编才能启动任何操作系统.

为什么启动内核需要assembly代码?为什么不只是c代码?

Why is assembly code required to kick-start a kernel? Why not just c code?

在某些实现中,我看到的是assembly文件,除了设置一些魔术数字外,它仅调用了外部c文件中定义的某些功能.

What i have seen in some implementations is assembly file having just a call to some function defined in an external c file apart from setting some magic numbers.

使用汇编与处理实际的物理内存有关,而不与处理虚拟内存的抽象有关吗?

Does use of assembly have something to do with dealing with the real physical memory as opposed to dealing with the abstraction of virtual memory?

编辑

程序集是否用于将内核的text-section加载到实际内存的0x100000地址?

Is(n't) assembly used to load kernel's text-section to address 0x100000 of real memory ?

推荐答案

例如,C代码需要设置堆栈,因此,如果没有其他要求,则在输入第一级代码之前,无需设置堆栈指针.并且从C(不计算内联汇编,在这种情况下将不是C)中,您不能设置堆栈指针.所以你有鸡肉和鸡蛋的问题.接下来是bss和数据段,尽管您当然可以编写不依赖bss或数据设置的干净的C代码,但要满足C标准,则需要对其进行设置.因此,您将找到一些将bss归零的代码,如果需要,可以将.data从nv存储复制到适当的位置.

C code requires for example a stack to be setup, so if nothing else you need to set the stack pointer before you enter the first level of code. And from C (not counting inline asm which in this case would be assembly not C) you cant set the stack pointer. So you have that chicken and egg problem. Next is bss and data segments, although you can certainly write clean C code that does not rely on bss nor data being setup, but to meet the C standards you need them setup. So you will find some code that zeros bss and if need be copies .data into place from nv storage.

一般而言,汇编程序可以执行处理器可以执行的任何操作C不能自然地执行处理器可以执行的任何操作.特别是,您通常无法使用C引导C,您需要asm ...

In general assembly can do anything the processor can do C cannot nativly do anything the processor do. In particular you cant generally bootstrap C with C, you need asm...

这篇关于为什么程序集需要启动任何OS内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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