In C, how is the main() method initially called?

后端 未结 7 2070
甜味超标
甜味超标 2020-12-07 09:04

How does a C program get started?

7条回答
  •  猫巷女王i
    2020-12-07 09:43

    The operating system calls main. There will be an address in the relocatable executable that points at the location of main (See the Unix ABI for more information).

    But, who calls the operating system?

    The central processing unit, on the "RESET" signal, (which is also asserted at power on), will begin looking in some ROM at a given address (say, 0xffff) for its instructions.

    Typically there will be some sort of jump instruction out to the BIOS, which gets the memory chips configured, the basic hard drive drivers loaded, etc, etc. Then the Boot Sector of the hard drive is read, and the next bootloader is started, which loads the file containing the basic information of how to read, say, an NTFS partition and how to read the kernel file itself. The kernel environment will be set up, the kernel loaded, and then - and then! - the kernel will be jumped to for execution.

    After all that hard work has been done, the kernel can then proceed to load our software.

提交回复
热议问题