- Linux Device Driver Development Cookbook
- Rodolfo Giometti
- 349字
- 2021-06-24 13:54:12
A Peek Inside the Kernel
Simple operating systems (such as MS-DOS) always execute in a single CPU mode, but Unix-like operating systems use dual modes to effectively implement timesharing and resource allocation and protection. At any time in Linux, the CPU is either operating in a trusted kernel mode (where we can do everything we wish) or in a restricted user mode (where some operations are not allowed). All user processes execute in user mode, whereas the core kernel itself and most device drivers (except ones implemented in user space) run in kernel mode so that they have unrestricted access to the entire processor instruction set and to the full memory and I/O space.
When a user mode process needs to get access to peripherals, it cannot do it by itself, but it has to channel requests through device drivers or other kernel mode code via system calls, which play a major role in controlling process activities and managing data exchange. In this chapter, we will not see system calls yet (they will be introduced in Chapter 3, Working with Char Drivers), but we will start programming into the kernel by directly adding new code into its sources or by using kernel modules, which is another, more versatile, manner to add code to the kernel.
Once we get started writing kernel code, we must not forget that, while in user mode, every resource allocation (the CPU, RAM, and so on) is automatically managed by the kernel (which can properly release them when a process dies), in kernel mode, we are allowed to monopolize the processor until either we voluntarily relinquish the CPU or an interrupt or exception occurs; moreover, every requested resource (as the RAM, for instance) is lost if not properly released. That's why it's really important to correctly manage the CPU usage and to free whatever resource we request!
Now, it's time to do a first jump into the kernel, so in this chapter, we will cover the following recipes:
- Adding custom code to the sources
- Using kernel messages
- Working with kernel modules
- Using module parameters
- Designing Purpose:Built Drones for Ardupilot Pixhawk 2.1
- 零起點(diǎn)學(xué)Linux系統(tǒng)管理
- Linux Mint Essentials
- Linux從零開始學(xué)(視頻教學(xué)版)
- 新手易學(xué):系統(tǒng)安裝與重裝
- Alfresco 4 Enterprise Content Management Implementation
- 網(wǎng)絡(luò)操作系統(tǒng)管理與應(yīng)用(第三版)
- Linux自動(dòng)化運(yùn)維:Shell與Ansible(微課版)
- 網(wǎng)絡(luò)操作系統(tǒng)教程:Windows Server 2016管理與配置
- 深入淺出Node.js
- OpenStack系統(tǒng)架構(gòu)設(shè)計(jì)實(shí)戰(zhàn)
- NetDevOps入門與實(shí)踐
- Python UNIX和Linux系統(tǒng)管理指南
- Linux軟件管理平臺(tái)設(shè)計(jì)與實(shí)現(xiàn)
- 統(tǒng)信UOS應(yīng)用開發(fā)進(jìn)階教程