zoukankan      html  css  js  c++  java
  • 跟踪内核启动过程CONFIG_DEBUG_LL【转自】

    最近在调试Linux内核,跟踪启动过程。发现在没有turn on mmu之前,可以使用物理地址,通过向串口Fifo丢数据的方式输出调试信息。但是代码一旦运行到开启mmu,在汇编阶段,mmu只做了物理内存的映射,并没有映射io,所以就无法访问串口了。
     
    此时应该通过串口输出的数据都保存在串口缓冲池里,直到在c语言阶段,建立io映射并初始化控制台后才进行输出。
     
    但是,如果我想实时跟踪内核启动过程,应该如何才好?
    这是就要提到Linux的Lowlevel Debug功能了。
     
    这个选项位于:
    Kernel hacking  ---> 
     [*] Kernel debugging 
     [*] Kernel low-level debugging functions 
     
    打开这个选项会在.config中增加CONFIG_DEBUG_LL宏定义
    初步估计,影响的地方有以下几点:
    (1)arch/arm/kernel/head.s的__create_page_tables部分
    (2)arch/arc/mach-处理器/处理器.c中的宏定义部分
    (3)kernel/prink.c
    为了提供DEBUG_LL功能,还必须完善arch/arc/mach-处理器/include/mach/debug-macro.S
     
    首先说说好处,为什幺打开Kernel low-level debugging functions 功能。
    打开这个宏定义后,会在head.s函数的__create_page_tables建立一部分io映射,具体代码如下:
     
    #ifdef CONFIG_DEBUG_LL
    ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
    /*
     * Map in IO space for serial debugging.
     * This allows debug messages to be output
     * via a serial console before paging_init.
     */
    ldr r3, [r8, #MACHINFO_PGOFFIO]
    add r0, r4, r3
    rsb r3, r3, #0x4000 @ PTRS_PER_PGD*sizeof(long)
    cmp r3, #0x0800 @ limit to 512MB
    movhi r3, #0x0800
    add r6, r0, r3
    ldr r3, [r8, #MACHINFO_PHYSIO]
    orr r3, r3, r7
    1: str r3, [r0], #4
    add r3, r3, #1 << 20
    teq r0, r6
    bne 1b
     
    代码中也提到,映射io的作用是为了串口调试使用。
    这段代码中使用的物理地址和虚拟地址从何而来?arch/arc/mach-处理器/处理器.c中的宏定义部分
    比如以下处理器:
    MACHINE_START(EASIC0718, "SEP0718 board")
     
    .phys_io = 0x10005000,
    .io_pg_offst = ((0xe005000) >> 18) & 0xfffc,
    .boot_params = 0x30000100,
    .fixup = fixup_gfd0718,
    .map_io = sep0718_map_io,
    .init_irq =  sep0718_init_irq,
    .init_machine = sep0718_init,
    .timer = &sep0718_timer,
     
    MACHINE_END
     
    中间
    .phys_io = 0x10005000,
    .io_pg_offst = ((0xe005000) >> 18) & 0xfffc,
    就是供__create_page_tables的 CONFIG_DEBUG_LL中做io映射使用
     
    最后就是对printk.c的改动了,主要是多定义了void printascii(char *)可以直接输出。
    完善了debug-macro.S后可以用printascii了。建立了内存映射后,哪里都可以用,无论汇编还是C,无论开mmu前还是开mmu后。代码会判断有没有开mmu的。
    同时prink会在缓冲池保留一份数据,也同时调用printkasii直接输出,因此内核启动后会看到信息输出了两次。
     
    最后贴上debug-macro.S,writed by leeming,注意其中的io地址和处理器架构相关,不能直接使用。
    /* linux/include/asm-arm/arch-sep0718/debug-macro.S
     *
     * Debugging macro include header
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License version 2 as
     * published by the Free Software Foundation.
     *
    */
    #include <asm/hardware.h>
     
    .macro addruart,rx
    mrc p15, 0, x, c1, c0
    tst x, #1 @ MMU enabled?
    moveq x, #0x10000000
    movne x, #0xe0000000
    add  x, x, #0x5000
    .endm
     
    .macro senduart,rd,rx
    str d, [ x] @ UARTDR
    .endm
                
    .macro waituart,rd,rx
    1001: ldr d, [ x, #0x14] @ SYSFLGx
    tst d, #1 << 6 @ UBUSYx
    beq 1001b
    .endm
     
    .macro busyuart,rd,rx
    1001: ldr d, [ x, #0x14] @ SYSFLGx
    tst d, #1 << 6 @ UBUSYx
    beq 1001b
    .endm
  • 相关阅读:
    SPARK 中 DriverMemory和ExecutorMemory
    Logistic Regression vs Decision Trees vs SVM: Part II
    Logistic Regression Vs Decision Trees Vs SVM: Part I
    Scala _ [underscore] magic
    spark-shell --conf
    spark-submit [options]
    maven 将依赖的jar包打入jar包中
    log4j
    eclipse java工程和maven工程的互相转换
    插件上传2
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/5344801.html
Copyright © 2011-2022 走看看