TAILIEUCHUNG - Linux Device Drivers-Chapter 2 : Building and Running Modules

Chapter 2 : Building and Running Modules It's high time now to begin programming. This chapter introduces all the essential concepts about modules and kernel programming. In these few pages, we build and run a complete module. Developing such expertise is an essential foundation for any kind of modularized driver. To avoid throwing in too many concepts at once, this chapter talks only about modules, without referring to any specific device class. All the kernel items (functions, variables, header files, and macros) that are introduced here are described in a reference section at the end of the chapter. For the impatient. | Chapter 2 Building and Running Modules It s high time now to begin programming. This chapter introduces all the essential concepts about modules and kernel programming. In these few pages we build and run a complete module. Developing such expertise is an essential foundation for any kind of modularized driver. To avoid throwing in too many concepts at once this chapter talks only about modules without referring to any specific device class. All the kernel items functions variables header files and macros that are introduced here are described in a reference section at the end of the chapter. For the impatient reader the following code is a complete Hello World module which does nothing in particular . This code will compile and run under Linux kernel versions through . 4 4 This example and all the others presented in this book is available on the O Reilly FTP site as explained in Chapter 1 An Introduction to Device Drivers . define MODULE include linux int init_module void printk 1 Hello world n return 0 void cleanup_module void printk 1 Goodbye cruel world n The printk function is defined in the Linux kernel and behaves similarly to the standard C library function printf. The kernel needs its own printing function because it runs by itself without the help of the C library. The module can call printk because after insmod has loaded it the module is linked to the kernel and can access the kernel s public symbols functions and variables as detailed in the next section . The string 1 is the priority of the message. We ve specified a high priority low cardinal number in this module because a message with the default priority might not show on the console depending on the kernel version you are running the version of the klogd daemon and your configuration. You can ignore this issue for now we ll explain it in the section printk in Chapter 4 Debugging Techniques . You can test the module by calling insmodand rmmod as shown in the screen dump in the .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.