新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > ARM Linux內核啟動2

        ARM Linux內核啟動2

        作者: 時間:2016-11-09 來源:網絡 收藏
        上一篇ARM Linux內核啟動(1)的銜接。

        接著上一篇說,看下面源碼:

        本文引用地址:http://www.104case.com/article/201611/317996.htm

        /*
        * Setup the initial page tables. We only setup the barest
        * amount which are required to get the kernel running, which
        * generally means mapping in the kernel code.只創建內核代碼的映射
        *
        * r5 = physical address of start of RAM
        * r6 = physical IO address
        * r7 = byte offset into page tables for IO
        * r8 = page table flags
        */
        __create_page_tables:
        pgtblr4, r5@ page table address頁表地址


        /*
        * Clear the 16K level 1 swapper page table
        */
        movr0, r4
        movr3, #0
        addr2, r0, #0x4000
        1:strr3, [r0], #4
        strr3, [r0], #4
        strr3, [r0], #4
        strr3, [r0], #4
        teqr0, r2
        bne1b

        /*
        * Create identity mapping for first MB of kernel to
        * cater for the MMU enable. This identity mapping
        * will be removed by paging_init(). We use our current program
        * counter to determine corresponding section base address.
        */現在只創建開始1M的映射,其他外設寄存器空間的映射由paging_init()創建
        movr2, pc, lsr #20@ start of kernel section
        addr3, r8, r2, lsl #20@ flags + kernel base
        strr3, [r4, r2, lsl #2]@ identity mapping


        /*
        * Now setup the pagetables for our kernel direct
        * mapped region. We round TEXTADDR down to the
        * nearest megabyte boundary. It is assumed that
        * the kernel fits within 4 contigous 1MB sections.
        */現在為內核直接映射區建立頁表。我們大概將TEXTADDR降到最近的M區域
        addr0, r4, #(TEXTADDR & 0xff000000) >> 18@ start of kernel
        strr3, [r0, #(TEXTADDR & 0x00f00000) >> 18]!
        addr3, r3, #1 << 20
        strr3, [r0, #4]!@ KERNEL + 1MB
        addr3, r3, #1 << 20
        strr3, [r0, #4]!@ KERNEL + 2MB
        addr3, r3, #1 << 20
        strr3, [r0, #4]@ KERNEL + 3MB

        /*
        * Then map first 1MB of ram in case it contains our boot params.
        */
        addr0, r4, #VIRT_OFFSET >> 18
        addr2, r5, r8
        strr2, [r0]

        linux內核中3GB以上的地址空間為內核空間,所以需要把內核所在的物理空間地址映射到3GB以上。這里只映射了4MB。注意第一節進行了兩次映射,一個和物理地址相同映射,另一個映射到3GB以上。

        ......這中間還有一段代碼,就不分析了,都是有關調試的。

        /*
        * Read processor ID register (CP#15, CR0), and look up in the linker-built
        * supported processor list. Note that we cant use the absolute addresses
        * for the __proc_info lists since we arent running with the MMU on
        * (and therefore, we are not in the correct address space). We have to
        * calculate the offset.
        *
        * Returns:
        *r5, r6, r7 corrupted
        *r8 = page table flags
        *r9 = processor ID
        *r10 = pointer to processor structure
        */
        __lookup_processor_type:
        adrr5, 2f
        ldmiar5, {r7, r9, r10}
        subr5, r5, r10@ convert addresses
        addr7, r7, r5@ to our address space
        addr10, r9, r5
        mrcp15, 0, r9, c0, c0@ get processor id
        1:ldmiar10, {r5, r6, r8}@ value, mask, mmuflags
        andr6, r6, r9@ mask wanted bits
        teqr5, r6
        moveqpc, lr
        addr10, r10, #PROC_INFO_SZ@ sizeof(proc_info_list)
        cmpr10, r7
        blt1b
        movr10, #0@ unknown processor
        movpc, lr


        /*
        * Look in include/asm-arm/procinfo.h and arch/arm/kernel/arch.[ch] for
        * more information about the __proc_info and __arch_info structures.
        */

        內核中定義的處理器信息和平臺信息,在連接文件vmlinux.lds.S (archarmkernel)中有如下定義:

        vmlinux.lds.S (archarmkernel)

        __proc_info_begin = .;
        *(.proc.info)
        __proc_info_end = .;
        __arch_info_begin = .;
        *(.arch.info)
        __arch_info_end = .;


        2:.long__proc_info_end
        .long__proc_info_begin
        .long2b
        .long__arch_info_begin
        .long__arch_info_end
        這段代碼的開頭標志,看起來是不是很熟悉,這個就是在第一篇中看到的的,不知道的話,可以回過去查看。這段代碼主要是有關處理器的查找。

        /*
        * Lookup machine architecture in the linker-build list of architectures.
        * Note that we cant use the absolute addresses for the __arch_info
        * lists since we arent running with the MMU on (and therefore, we are
        * not in the correct address space). We have to calculate the offset.
        *不能使用絕對地址
        * r1 = machine architecture number
        * Returns:
        * r2, r3, r4 corrupted
        * r5 = physical start address of RAM
        * r6 = physical address of IO
        * r7 = byte offset into page tables for IO
        */
        __lookup_architecture_type:
        adrr4, 2b
        ldmiar4, {r2, r3, r5, r6, r7}@ throw away r2, r3
        subr5, r4, r5@ convert addresses
        addr4, r6, r5@ to our address space
        addr7, r7, r5
        1:ldrr5, [r4]@ get machine type
        teqr5, r1@ matches loader number?
        beq2f@ found
        addr4, r4, #SIZEOF_MACHINE_DESC@ next machine_desc
        cmpr4, r7
        blt1b
        movr7, #0@ unknown architecture
        movpc, lr
        2:ldmibr4, {r5, r6, r7}@ found, get results
        movpc, lr

        這段代碼也和上面的一樣。這段完成的工作主要是判斷內核對這個平臺的支持。那平臺信息在那里定義呢?

        MACHINE_START (KEV7A400, "Sharp KEV7a400")
        MAINTAINER ("Marc Singer")
        BOOT_MEM (0xc0000000, 0x80000000, io_p2v (0x80000000))
        BOOT_PARAMS (0xc0000100)
        MAPIO (kev7a400_map_io)
        INITIRQ (lh7a400_init_irq)
        .timer= &lh7a40x_timer,
        MACHINE_END

        主要是通過MACHINE_START宏,

        /*
        * Set of macros to define architecture features. This is built into
        * a table by the linker.
        */
        #define MACHINE_START(_type,_name)
        const struct machine_desc __mach_desc_##_type
        __attribute__((__section__(".arch.info"))) = {
        .nr= MACH_TYPE_##_type,
        .name= _name,

        當想要添加新的平臺是,需修改Mach-types (archarmtools)這個文件,因為內核在編譯時Makefile腳本會根據

        Mach-types (archarmtools)文件生成Mach-types.h (includeasm-arm)文件。



        關鍵詞: ARMLinux內核啟

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 潞城市| 高要市| 仪陇县| 镇江市| 二手房| 息烽县| 涟水县| 凌云县| 高台县| 苍南县| 启东市| 长沙市| 特克斯县| 佛冈县| 普宁市| 上高县| 大庆市| 安康市| 伊宁县| 贵德县| 醴陵市| 化州市| 大安市| 丰县| 于田县| 桑日县| 濮阳县| 阳原县| 勐海县| 灵石县| 仁寿县| 岳西县| 新田县| 大连市| 凤凰县| 玉溪市| 拉萨市| 延庆县| 乌拉特后旗| 八宿县| 拉孜县|