分类: LINUX
2008-03-19 15:40:40
================================
Author: taoyuetao
Email:
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进入内核启动的第二阶段。