Does Linux kernel have main function?
c, linux, linux-device-driver, linux-kernel
Solution
Fundamentally, there is nothing special about a routine being named `main()`. As alluded to above, `main()` serves as the entry point for an executable load module. However, you can define different entry points for a load module. In fact, you can define more than one entry point, for example, refer to your favorite dll.
From the operating system's (OS) point of view, all it really needs is the address of the entry point of the code that will function as a device driver. The OS will pass control to that entry point when the device driver is required to perform I/O to the device.
A system programmer defines (each OS has its own method) the connection between a device, a load module that functions as the device's driver, and the name of the entry point in the load module.
Each OS has its own kernel (obviously) and some might/maybe start with `main()` but I would be surprised to find a kernel that used `main()` other than in a simple one, such as UNIX! By the time you are writing kernel code you have long moved past the requirement to name every module you write as `main()`.
Hope this helps?
Found this code snippet from the kernel for Unix Version 6. As you can see `main()` is just another program, trying to get started!
main()
{
extern schar;
register i, *p;
/*
* zero and free all of core
*/
updlock = 0;
i = *ka6 + USIZE;
UISD->r[0] = 077406;
for(;;) {
if(fuibyte(0) < 0) break;
clearsig(i);
maxmem++;
mfree(coremap, 1, i);
i++;
}
if(cputype == 70)
for(i=0; i<62; i=+2) {
UBMAP->r[i] = i<<12;
UBMAP->r[i+1] = 0;
}
// etc. etc. etc.
Problem
I am learning `Device Driver` and `Kernel` programming.According to Jonathan Corbet book we do not have `main()` function in device drivers. ``` #include <linux/init.h> #include <linux/module.h> static int my_init(void) { return 0; } static void my_exit(void) { return; } module_init(my_init); module_exit(my_exit); ``` Here I have two questions : - Why we do not need `main()` function in Device Drivers? - Does Kernel have `main()` function?