简体   繁体   中英

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. But why Operating Systems can do it, and they contain a few KLOC of asm line-codes?

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. 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. Although platforms differ in their assembly dialects, they are built over the same concepts (eg page-based memory management through a 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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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