Porting Linux to a new processor architecture, part 1: The basics

发布于:2025-05-13 ⋅ 阅读:(14) ⋅ 点赞:(0)

Although a simple port may count as little as 4000 lines of code—exactly 3,775 for the mmu-less Hitachi 8/300 recently reintroduced in Linux 4.2-rc1—getting the Linux kernel running on a new processor architecture is a difficult process. Worse still, there is not much documentation available describing the porting process. The aim of this series of three articles is to provide an overview of the procedure, or at least one possible procedure, that can be followed when porting the Linux kernel to a new processor architecture.

虽然一个简单的移植可能只需要约 4000 行代码——例如在 Linux 4.2-rc1 中重新引入的无 MMU 的 Hitachi 8/300 架构只用了 3775 行代码——但让 Linux 内核运行在一个新的处理器架构上仍然是一个困难的过程。更糟糕的是,几乎没有关于移植流程的文档可供参考。这三篇文章的目标是提供一个大致的流程概览,或者至少是一个可供遵循的 Linux 内核移植到新处理器架构的流程。

After spending countless hours becoming almost fluent in many of the supported architectures, I discovered that a well-defined skeleton shared by the majority of ports exists. Such a skeleton can logically be split into two parts that intersect a great deal. The first part is the boot code, meaning the architecture-specific code that is executed from the moment the kernel takes over from the bootloader until init is finally executed. The second part concerns the architecture-specific code that is regularly executed once the booting phase has been completed and the kernel is running normally. This second part includes starting new threads, dealing with hardware interrupts or software exceptions, copying data from/to user applications, serving system calls, and so on.

在花费了无数小时并几乎熟悉了许多已有架构之后,我发现大多数移植版本之间都存在一个明确的通用框架。这个框架在逻辑上可以划分为两个部分,它们之间有大量交叉。第一部分是启动代码,指的是从内核接管引导加载程序开始,到最终执行 init 之间所运行的架构相关代码。第二部分则是系统启动完成、内核正常运行后周期性执行的架构相关代码。这部分包括启动新线程、处理中断和异常、与用户空间进行数据拷贝、响


网站公告

今日签到

点亮在社区的每一天
去签到