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

发布于 2024-12-18 23:56:21 字数 88 浏览 2 评论 0原文

ASM 因处理器而异,因此您为某种处理器架构编写的代码不适用于另一种处理器架构。但是为什么操作系统可以做到这一点,并且它们包含一些 KLOC 的 asm 行代码?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放手` 2024-12-25 23:56:21

现代(或者至少不是太旧)操作系统,例如 Linux,大多是用 C 语言编写的,并且只包含几行特定于平台的汇编代码。为了移植到另一个体系结构,必须重写此类汇编代码——这就是所做的事情。但C代码只需重新编译即可,无需重写。尽管平台的汇编语言有所不同,但它们都是基于相同的概念构建的(例如,通过MMU)。有些操作必须在汇编中完成,因为可移植的 C 不提供任何方法来完成这些操作(例如任务切换或中断处理的初始步骤),但操作系统所做的大部分工作是纯算法,可以在 C 中完成(例如,所有网络代码都是用 C 编写的;只有通过以太网接口发送数据包的非常低级的部分最多需要十几行汇编代码)。

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 (e.g. 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 (e.g. 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).

从来不烧饼 2024-12-25 23:56:21

因为操作系统会为每个支持的架构重新实现 ASM 部分,所以在构建时选择正确的部分?

Because operating systems re-implement the ASM parts for each supported architecture, choosing the correct one at build time?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文