基於ARM 的Linux 的啟動分析報告——ARM+Linux的啟動分析(3)

來源:互聯網
上載者:User

(9) 調用檔案misc.c的函數decompress_kernel(),解壓核心於緩衝結束的地
方(r2地址之後)。此時各寄存器值有如下變化:
r0為解壓後kernel的大小
r4為kernel執行時的地址
r5為解壓後kernel的起始地址
r6為CPU類型值(processor ID)
r7為系統類別型值(architecture ID)
(10) 將reloc_start代碼拷貝之kernel之後(r5+r0之後),首先清除緩衝,而
後執行reloc_start。
(11) reloc_start將r5開始的kernel重載於r4地址處。
(12) 清除cache內容,關閉cache,將r7中architecture ID賦於r1,執行
r4開始的kernel代碼。
5) 我們在核心啟動的開始都會看到這樣的輸出
Uncompressing Linux...done, booting the kernel.
這也是由decompress_kernel函數內部輸出的,它調用了putc()輸出字串,
putc是在#/include/asm-arm/arch-pxa/uncompress.h中實現的。執行完解壓過
程,再返回到#/arch/arm/boot/compressed/head.S中,啟動核心:
call_kernel: bl cache_clean_flush
bl cache_off
mov r0, #0
mov r1, r7 @ restore architecture number
mov pc, r4 @ call kernel
6) 執行zImage 鏡像,到start_kernel( )
整個arm linux核心的啟動可分為三個階段:第一階段主要是進行cpu和
體繫結構的檢查、cpu本身的初始化以及頁表的建立等;第一階段的初始化是從
核心入口(ENTRY(stext))開始到start_kernel前結束。這一階段的代碼
在/arch/arm/kernel/head.S中。/arch/arm/kernel/head.S用彙編程式碼完成,
是核心最先執行的一個檔案。這一段彙編代碼的主要作用,是檢查cpu
id,architecture number,初始化頁表、cpu、bbs等操作,並跳到
start_kernel函數。它在執行前,處理器的狀態應滿足:
r 0 - should be 0
r1 - unique architecture number
MMU - off
I-cache - on or off
D-cache – off
a) 流程圖


b) 代碼詳細注釋
#/arch/arm/kernel/head.S
/*
* swapper_pg_dir is the virtual address of the initial page table.
* We place the page tables 16K below KERNEL_RAM_VADDR. Therefore, we
* must make sure that KERNEL_RAM_VADDR is correctly set. Currently,
we *expect the least significant 16 bits to be 0x8000, but we could
probably relax this *restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET +
0x4000.
*/
#if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
#error KERNEL_RAM_VADDR must start at 0xXXXX8000
#endif
.globl swapper_pg_dir
.equ swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000
.macro pgtbl, rd
ldr /rd, =(KERNEL_RAM_PADDR - 0x4000)
.endm
/*
* Since the page table is closely related to the kernel start
address, we
* can convert the page table base address to the base address of the
section
* containing both.
*/
.macro krnladr, rd, pgtable, rambase
bic /rd, /pgtable, #0x000ff000
.endm
/*
/*
* Kernel startup entry point.
* ---------------------------
*
* This is normally called from the decompressor code. The
requirements
* are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
* r1 = machine nr, r2 = atags pointer.
*
* See linux/arch/arm/tools/mach-types for the complete list of
machine
* numbers for r1.
*/
.section ".text.head", "ax"
.type stext, %function
ENTRY(stext) //核心進入點
msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
//程式狀態,禁止FIQ、IRQ,設定Supervisor模式。0b11010011
mrc p15, 0, r9, c0, c0 @ get processor id
bl __lookup_processor_type @ r5=procinfo r9=cupid //跳轉到
判斷
//cpu類型,尋找啟動並執行cpu的id值和此linux編譯支援的id值是否有相

movs r10, r5 @ invalid processor (r5=0)?
beq __error_p @ yes, error 'p'
bl __lookup_machine_type @ r5=machinfo
//跳轉到判斷體系類型,看r1寄存器的architecture number值是否支援。
movs r8, r5 @ invalid machine (r5=0)?
beq __error_a @ yes, error 'a'
bl __vet_atags
bl __create_page_tables //建立核心頁表
/*
* The following calls CPU specific code in a position independent
* manner. See arch/arm/mm/proc-*.S for details. r10 = base of
* xxx_proc_info structure selected by __lookup_machine_type
* above. On return, the CPU will be ready for the MMU to be
* turned on, and r0 will hold the CPU control register value.
*/
ldr r13, __switch_data @ address to jump to after
@ mmu has been enabled
adr lr, __enable_mmu @ return (PIC) address //lr=0xc0028054
add pc, r10, #PROCINFO_INITFUNC
@ initialise processor //r10:pointer to processor
structure
#/arch/arm/kernel/head-common.S
*/
#define ATAG_CORE 0x54410001
#define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2)
.type __switch_data, %object
__switch_data:
.long __mmap_switched
.long __data_loc @ r4
.long __data_start @ r5
.long __bss_start @ r6

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.