Each computer platform has its peculiarities, and kernel designers are free to exploit all the peculiarities to achieve better performance in the target object file. 每个计算机平台都有其特性,内核设计者可以自由地利用所有特性来在目标目标文件中实现更好的性能。
Unlike application developers, who must link their code with precompiled libraries and stick to conventions on parameter passing, kernel developers can dedicate some processor registers to specific roles, and they have done so. Moreover, kernel code can be optimized for a specific processor in a CPU family to get the best from the target platform: unlike applications that are often distributed in binary format, a custom compilation of the kernel can be optimized for a specific computer set. 与必须将代码与预编译库链接并遵守参数传递约定的应用程序开发人员不同,内核开发人员可以将一些处理器寄存器专用于特定角色,他们已经这样做了。 此外,内核代码可以针对 CPU 系列中的特定处理器进行优化,以充分利用目标平台:与通常以二进制格式分发的应用程序不同,内核的自定义编译可以针对特定计算机集进行优化。
For example, the IA32 (x86) architecture has been subdivided into several different processor types. The old 80386 processor is still supported (for now), even though its instruction set is, by modern standards, quite limited. The more modern processors in this architecture have introduced a number of new capabilities, including faster instructions for entering the kernel, interprocessor locking, copying data, etc. Newer processors can also, when operated in the correct mode, employ 36-bit (or larger) physical addresses, allowing them to address more than 4 GB of physical memory. Other processor families have seen similar improvements. The kernel, depending on various configuration options, can be built to make use of these additional features. 例如,IA32 (x86) 架构已细分为几种不同的处理器类型。 (目前)仍然支持旧的 80386 处理器,尽管它的指令集按照现代标准非常有限。 这种架构中更现代的处理器引入了许多新功能,包括更快的进入内核的指令、处理器间锁定、复制数据等。更新的处理器在正确模式下运行时也可以采用 36 位(或更大 ) 物理地址,允许它们寻址超过 4 GB 的物理内存。 其他处理器系列也看到了类似的改进。 根据各种配置选项,可以构建内核以利用这些附加功能。
Clearly, if a module is to work with a given kernel, it must be built with the same understanding of the target processor as that kernel was. Once again, the vermagic.o object comes in to play. When a module is loaded, the kernel checks the processor-specific configuration options for the module and makes sure they match the running kernel. If the module was compiled with different options, it is not loaded. 显然,如果一个模块要与一个给定的内核一起工作,它必须在构建它时对目标处理器的理解与该内核相同。 再次,vermagic.o 对象开始发挥作用。 加载模块时,内核会检查模块的特定于处理器的配置选项,并确保它们与正在运行的内核匹配。 如果模块是用不同的选项编译的,它不会被加载。
If you are planning to write a driver for general distribution, you may well be wondering just how you can possibly support all these different variations. The best answer, of course, is to release your driver under a GPL-compatible license and contribute it to the mainline kernel. Failing that, distributing your driver in source form and a set of scripts to compile it on the user's system may be the best answer. Some vendors have released tools to make this task easier. If you must distribute your driver in binary form, you need to look at the different kernels provided by your target distributions, and provide a version of the module for each. Be sure to take into account any errata kernels that may have been released since the distribution was produced. Then, there are licensing issues to be considered, as we discussed in Section 1.6. As a general rule, distributing things in source form is an easier way to make your way in the world. 如果您打算为通用分发编写驱动程序,您可能想知道如何才能支持所有这些不同的变体。 当然,最好的答案是在与 GPL 兼容的许可下发布您的驱动程序并将其贡献给主线内核。 如果做不到这一点,以源代码形式分发驱动程序和一组脚本以在用户系统上编译它可能是最好的答案。 一些供应商已经发布了工具来简化这项任务。 如果必须以二进制形式分发驱动程序,则需要查看目标分发提供的不同内核,并为每个版本提供模块版本。 请务必考虑自发行版发布以来可能已发布的任何勘误表内核。 然后,正如我们在第 1.6 节中讨论的那样,需要考虑许可问题。 作为一般规则,以源代码形式分发内容是一种更容易在世界上取得成功的方式。