内核是否有主要功能? [英] Does kernel have main function?

查看:130
本文介绍了内核是否有主要功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习设备驱动程序内核 programming.According乔纳森·科比特本书中,我们没有设备驱动程序的main()功能。

 的#include< Linux的/ init.h中>
#包括LT&; Linux的/ - module.h中GT;静态INT my_init(无效)
{
     返回0;
}静态无效my_exit(无效)
{
     返回;
}宏module_init(my_init);
宏module_exit(my_exit);

在这里,我有两个问题:


  1. 为什么我们不需要的main()设备驱动程序的功能?

  2. 内核是否有的main()功能?


解决方案

从根本上说,没有什么特别的例行被命名为的main()。正如上面提到的,的main()作为切入点的可执行文件加载模块。但是,您可以为加载模块定义不同的入口点。事实上,你可以定义多个切入点,例如参考您最喜爱的DLL。

但从操作系统的(OS)点,所有它真正需要的是code,这将作为设备驱动程序函数的入口点的地址。当需要的设备驱动程序来执行的I / O设备的操作系统将控制传递给该入口点。

一个系统程序员定义(每个OS都有其自己的方法)的装置,一个加载模块之间的连接,其功能作为设备的驱动程序,以及加载模块中的入口点的名称

每个操作系统都有自己的内核(显然)和一些强权/可能与启动的main(),但我会很惊讶地发现,使用的内核的main()比一个简单的,如UNIX等!到时候你正在编写内核code你早已过去移动的要求来命名每次你写的模块的main()

希望这有助于?

找到从内核版本的Unix 6.本code段正如你看到的的main()只是另一种方案,试图开始!

 的main()
{
     EXTERN SCHAR;
     寄存器i,* P;
     / *
     *为零,无任何核心
     * /     UPDLOCK = 0;
     I = * KA6 + USIZE;
     UISD-> R [0] = 077406;
     为(;;){
        如果(fuibyte(0)℃的)中断;
        clearsig(ⅰ);
        MAXMEM ++;
        mfree(coremap,1,I);
         我++;
     }
     如果(CPUTYPE == 70)
     对于(I = 0; I&下; 62; ​​I = + 2){
       UBMAP-> R [i] = I<< 12;
       UBMAP-> R [I + 1] = 0;
      }    //等等,等等等等。

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 :

  1. Why we do not need main() function in Device Drivers?
  2. Does Kernel have main() function?

解决方案

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.

这篇关于内核是否有主要功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆