简体   繁体   English

操作系统可以在多个处理器上运行吗?

[英]Operating Systems can run on multiple processors?

ASM differ from one processor to another, so the code that you write for a processor architecture won`t work for another. ASM因一个处理器而异,因此,您为处理器体系结构编写的代码不适用于另一种。 But why Operating Systems can do it, and they contain a few KLOC of asm line-codes? 但是,为什么操作系统可以做到这一点,并且它们包含一些KLOC的asm行代码?

Modern (or at least not too old) operating systems such as Linux are mostly written in C, and contain only a few lines of platform-specific assembly code. 诸如Linux之类的现代(或至少不是太老)的操作系统大多是用C编写的,并且仅包含几行特定于平台的汇编代码。 To be ported to another architecture, such assembly code must be rewritten -- and that's what is done. 要移植到另一种体系结构,必须重新编写这样的汇编代码,这就是完成的工作。 But the C code can just be recompiled, no need to rewrite it. 但是C代码可以重新编译,而无需重写。 Although platforms differ in their assembly dialects, they are built over the same concepts (eg page-based memory management through a MMU ). 尽管平台的组装方言不同,但是它们是基于相同的概念构建的(例如,通过MMU进行基于页面的内存管理)。 Some operations must be done in assembly because portable C does not offer any way to do them (eg task switching or the initial steps of interrupt handling), but the bulk of what an OS does is pure algorithmics, it can be done in C (for instance, all the network code is in C; only the very low level part of sending a packet over an ethernet interface requires at most a dozen lines of assembly). 某些操作必须在汇编中完成,因为可移植的C不提供任何方式来进行操作(例如,任务切换或中断处理的初始步骤),但是OS的大部分工作都是纯算法,可以在C中完成(例如,所有网络代码都在C语言中;仅通过以太网接口发送数据包的最底层部分最多需要十几行汇编。

因为操作系统为每种受支持的体系结构重新实现了ASM部分,所以在构建时选择正确的体系结构?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM