注:
原文出自taoyuetao大侠的博客上:
http://www.eetop.cn/blog/html/45/11145_itemid_1838.html
小弟参考之研究s3c2410相关代码,然后做了稍微的修改,作为一个学习笔记,方便以后的学习,也希望对后人有所帮助^_^
函数__mmap_switched介绍:
/*
* The following fragment of code is
executed with the MMU on, and uses
* absolute addresses; this is not
position independent.
*
*
r0 = cp#15 control register
*
r1 = machine ID
*
r9 = processor ID
*/
1: .type __mmap_switched,
%function
2: __mmap_switched:
3: adr r3, __switch_data + 4
4: ldmia r3!, {r4, r5, r6,
r7}
5: cmp r4, r5 @
Copy data segment if needed
6: 1: cmpne r5, r6
7: ldrne fp, [r4], #4
8: strne fp, [r5], #4
9: bne 1b
10: mov fp, #0 @ Clear BSS (and zero fp)
11:1: cmp r6, r7
12: strcc fp, [r6],#4
13: bcc 1b
14: ldmia r3, {r4, r5, r6, sp}
15: str r9, [r4] @ Save processor ID
16: str r1, [r5] @ Save machine type
17: bic r4, r0, #CR_A @ Clear 'A' bit
18: stmia r6, {r0, r4} @
Save control register values
19: b start_kernel
20: .type __switch_data, %object
21:__switch_data:
22: .long __mmap_switched
23: .long __data_loc @
r4
24: .long __data_start @ r5
25: .long __bss_start @
r6
26: .long _end @
r7
27: .long processor_id @ r4
28: .long __machine_arch_type @ r5
29: .long cr_alignment @ r6
30: .long init_thread_union + THREAD_START_SP @ sp
程序的4行执行完成之后的结果是r4=__data_loc,r5=__data_start,r6=__bss_start,r7=_end,第10-13行将__bss_start到_end清零,定义在vmlinux.lds文件中,如下:
.bss :
{
__bss_start = .;
/*
BSS
*/
*(.bss)
*(COMMON)
_end = . ;
}
第15-16行分别将处理器类型和机器类型存储到变量processor_id和__machine_arch_type中,这些变量以后会在start_kernel->setup_arch中使用,来得到当前处理器的struct
proc_info_list结构和当前系统的machine_desc结构的数据。
第17-18将processor control
register保存到cr_alignment中,19行跳转到init/main.c中的start_kernel进入内核启动的第二阶段。
posted on 2007-08-04 10:24
lfc 阅读(985)
评论(2) 编辑 收藏 引用