原文地址:http://www.eetop.cn/blog/html/45/11145-1838.html
================================
Author: taoyuetao
Email:[email protected]
Blog:http://www.eetop.cn/blog/?11145
07-04-18
================================
函數__mmap_switched介紹:
/*
* The following fragment of code is executed with the MMU on, and uses
* absolute addresses; this is not position independent.
*
* r0 = processor control register
* r1 = machine ID
* r9 = processor ID
*/
/* 下面按4字節對齊 */
1 .align 5
2 __mmap_switched:
/* r3 = __bss_start */
3 adr r3, __switch_data + 4
4 ldmia r3, {r4, r5, r6, r7, r8, sp}@ r2 = compat
@ sp = stack pointer
5 mov fp, #0 @ Clear BSS (and zero fp)
6 1: cmp r4, r5
7 strcc fp, [r4],#4
8 bcc 1b
9 str r9, [r6] @ Save processor ID
10 str r1, [r7] @ Save machine type
11 orr r0, r0, #2 @ ...........A.
12 bic r2, r0, #2 @ Clear 'A' bit
13 stmia r8, {r0, r2} @ Save control register values
14 b SYMBOL_NAME(start_kernel)
程序的4行執行完成之後的結果是r4=__bss_start,r5=_end,r6=processor_id,r7=__machine_arch_type,
r8=cr_alignment,sp=init_task_union+8192,第5-8行將__bss_start到_end清零,定義在vmlinux.lds文件中,如下:
.bss : {
__bss_start = .; /* BSS */
*(.bss)
*(COMMON)
_end = . ;
}
第9、10行分別將處理器類型和機器類型存儲到變量processor_id和__machine_arch_type中,這些變量以後會
在start_kernel->setup_arch中使用,來得到當前處理器的struct proc_info_list結構和當前系統的machine_desc結構的數據。
第10-13將processor control register保存到cr_alignment中,14行跳轉到init/main.c中的start_kernel進入內核啓動的第二階段。