> I have been looking at the linux serial driver initialization routine
> rs_init() in drivers/char/serial.c. This routine gets invoked as a
> part of a do-while loop in do_initcalls() in init/main.c.The code
> looks something like this:
>
> static void __init do_initcalls(void)
> {
> initcall_t *call;
>
> call = &__initcall_start;
> do {
> (*call)();
> call++;
> } while (call < &__initcall_end);
>
> /* Make sure there is no pending stuff from the initcall sequence */
> flush_scheduled_tasks();
> }
>
> I would like to know where exactly is rs_init() being inserted into
> the chain of routines that gets invoked in the do-while loop.
Welcome to linker magic!
The __initcall directive expands to something like __attribute__
((unused,__section__ (".initcall.init"))), which will instruct the
compiler to but the function pointer in the .initcall.init ELF section
(see gcc info file for more information). The boundaries of this
section are __initcall_start and __initcall_end, also filled in by the
linker at link time.
So the rs_init() function pointer will be put *somewhere* into the
.initcall.init section. At boot, the function do_initcalls() will call
all function pointers in the section, so at a certain point rs_init()
will also be called through its function pointer in the .initcall.init
section.
'QnA' 카테고리의 다른 글
| signal함수의 프로토타입은 왜 함수포인터로 되어 있을까요? (0) | 2009.07.28 |
|---|---|
| cat /dev/null > a.txt 2>&1 (0) | 2009.07.27 |
| /dev/ttyS, "Input/output error" (0) | 2009.07.18 |
| BTUART사용시 질문 (0) | 2009.07.16 |
| external memory interface (0) | 2009.07.16 |
WRITTEN BY
- RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.
,




