亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1019 | 回復(fù): 0
打印 上一主題 下一主題

gd_t和bd_t 以及 *gd asm ("r8") [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-12-23 03:25 |只看該作者 |倒序?yàn)g覽

gd_tbd_t是u-boot中兩個(gè)重要的數(shù)據(jù)結(jié)構(gòu),在初始化操作很多都要靠這兩個(gè)數(shù)據(jù)結(jié)構(gòu)來保存或傳遞.分別定義在./include/asm/global_data.h./include/asm/u_boot.h

1.gd_t: global data數(shù)據(jù)結(jié)構(gòu)定義,位于文件 include/asm-arm/global_data.h。其成員主要是一些全局的系統(tǒng)初始化參數(shù)。需要用到時(shí)用宏定義:DECLARE_GLOBAL_DATA_PTR指定占用寄存器R8。

2.bd_t : board info數(shù)據(jù)結(jié)構(gòu)定義,位于文件 include/asm-arm/u-boot.h。保存板子參數(shù)。


#ifndef __ASM_GBL_DATA_H
#define __ASM_GBL_DATA_H
/*
* The following data structure is placed in some memory wich is
* available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
* some locked parts of the data cache) to allow for a minimum set of
* global variables during system initialization (until we have set
* up the memory controller so that we can use RAM).
*下面的數(shù)據(jù)結(jié)構(gòu)在引導(dǎo)后放在內(nèi)存里,在系統(tǒng)初始化期間給全局變量進(jìn)行最小化設(shè)置。
* Keep it *SMALL* and remember to set CFG_GBL_DATA_SIZE > sizeof(gd_t) 保持簡單且不要忘了使CFG_GBL_DATA_SIZE 大于gd_t的大小
*/


typedef struct global_data

{
bd_t  *bd;                                   //開發(fā)板相關(guān)參數(shù),結(jié)構(gòu)體變量,參考u-boot.h
unsigned long flags;                     //指示標(biāo)志,如設(shè)備已經(jīng)初始化標(biāo)志等
unsigned long baudrate;               //串行口通訊速率
unsigned long have_console;       /* serial_init() was called console_init()中使用控制臺*/
unsigned long reloc_off;             /* Relocation Offset 重定位偏移,就是實(shí)際定向的位置與編譯連接時(shí)

                                                    指定的位置之差,一般為0 */
unsigned longenv_addr;              /* Address of Environment struct 環(huán)境參數(shù)地址*/
unsigned longenv_valid;             /* Checksum of Environment valid? 環(huán)境參數(shù)CRC檢驗(yàn)有效標(biāo)志*/
unsigned longfb_base;                /* base address of frame buffer 幀緩沖區(qū)基地址*/


#ifdef CONFIG_VFD
unsigned charvfd_type;              /* display type 顯示類型*/
#endif


#if  0     
unsigned long cpu_clk;               /*  CPU clock in Hz!   cpu時(shí)鐘  */
unsigned long bus_clk;               // 總線時(shí)鐘
unsigned long ram_size;             /*  RAM  size  of ram大小 */
unsigned long reset_status;      /* reset status register at boot */
#endif


void   **jt;                                /* jump table 跳轉(zhuǎn)表,用來"函數(shù)調(diào)用地址登記" */
}gd_t;

/*
* Global Data Flags   全局?jǐn)?shù)據(jù)標(biāo)志
*/

#define GD_FLG_RELOC 0x00001            /* Code was relocated to RAM   代碼裝載到RAM里*/
#define GD_FLG_DEVINIT 0x00002         /* Devices have been initialized 設(shè)備已經(jīng)初始化*/
#define GD_FLG_SILENT 0x00004           /* Silent mode     */

#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r8")

#endif /* __ASM_GBL_DATA_H */


typedef struct bd_info {
int                                       bi_baudrate;        /* serial console baudrate    串口波特率 */
unsigned long                      bi_ip_addr;          /* IP Address    IP 地址 */
unsigned char                      bi_enetaddr[6];     /* Ethernet adress    MAC地址*/
struct environment_s        *bi_env;                //結(jié)構(gòu)體變量定義見46行
ulong                                   bi_arch_number;   /* unique id for this board    板子的id*/
ulong                                   bi_boot_params;   /* where this board expects params 啟動(dòng)參數(shù)*/
struct     /* RAM configuration    RAM 配置*/
{
ulong start;
ulong size;
}     bi_dram[CONFIG_NR_DRAM_BANKS];
}bd_t;

=====================================================================

=====================================================================


下面是lib_arm\board.c文件分析  

/*
* Breathe some life into the board...           //給開發(fā)板注入些活力
*
* Initialize a serial port as console, and carry out some hardware
* tests.
*         初始化串口作為控制臺并實(shí)現(xiàn)硬件測試
* The first part of initialization is running from Flash memory;
* its main purpose is to initialize the RAM so that we
* can relocate the monitor code to RAM.
 初始化的第一個(gè)階段是在flash中運(yùn)行,主要目的是初始化ram以便于可以重載監(jiān)控代碼到ram里
*/
/* All attempts to come up with a "common" initialization sequence
* that works for all boards and architectures failed: some of the
* requirements are just _too_ different. To get rid of the resulting
* mess of board dependent #ifdef'ed code we now make the whole
* initialization sequence configurable to the user.
*試圖提出一個(gè)公共的初始化序列應(yīng)用于所有開發(fā)板和體系結(jié)構(gòu)幾乎是不可能的。為避免開發(fā)板混亂需要依賴條件編譯代碼。
* The requirements for any new initalization function is simple: it
* receives a pointer to the "global data" structure as it's only
* argument, and returns an integer return code, where 0 means
* "continue" and != 0 means "fatal error, hang the system".
任何新的初始化函數(shù)的要求都是簡單的:函數(shù)接受一個(gè)指針參數(shù)作為全局?jǐn)?shù)據(jù)結(jié)構(gòu),返回整型數(shù)據(jù)類型,為0表示繼續(xù),非0表示致命錯(cuò)誤,系統(tǒng)掛起*/
typedef int (init_fnc_t) (void); //自定義數(shù)據(jù)類型

/*初始化函數(shù)序列init_sequence[]
init_sequence[]數(shù)組保存著基本的初始化函數(shù)指針。這些函數(shù)名稱和實(shí)現(xiàn)的程序文件在下列注釋中。*/


init_fnc_t   *init_sequence[]= {
cpu_init,               /* basic cpu dependent setup 基本的處理器相關(guān)配置-- cpu/s3c44b0/cpu.c */
board_init,           /* basic board dependent setup 基本的板級相關(guān)配置-- board/hfrk/hfrks3c44b0/hfrks3c44b0.c*/
interrupt_init,    /* set up exceptions 初始化例外處理-- cpu/s3c44b0/interrupt.c*/
env_init,               /* initialize environment 初始化環(huán)境變量-- common/env_flash.c*/
init_baudrate,      /* initialze baudrate settings 初始化波特率設(shè)置-- lib_arm/board.c*/
serial_init,          /* serial communications setup串口通訊設(shè)置 -- cpu/s3c44b0/serial.c*/
console_init_f,    /* stage 1 init of console控制臺初始化階段1 -- common/console.c*/
display_banner,    /* say that we are here 打印u-boot信息 -- lib_arm/board.c*/
dram_init,            /* configure available RAM banks 配置可用的DRAM-- board/hfrk/hfrks3c44b0/hfrks3c44b0.c*/
display_dram_config,                   //顯示RAM的配置大小 -- lib_arm/board.c 


#if defined(CONFIG_VCMA9)
checkboard,
#endif


NULL,
};


//整個(gè)u-boot的執(zhí)行就進(jìn)入等待用戶輸入命令,解析并執(zhí)行命令的死循環(huán)中。
//start_armboot是U-Boot執(zhí)行的第一個(gè)C語言函數(shù),完成系統(tǒng)初始化工作,進(jìn)入主循環(huán),處理用戶輸入的命令
。


void start_armboot (void)
{
DECLARE_GLOBAL_DATA_PTR;   
/*DECLARE_GLOBAL_DATA_PTR 只是一個(gè)定義的宏,這個(gè)宏定義了一個(gè)gd_t全局?jǐn)?shù)據(jù)結(jié)構(gòu)的指針,

         這個(gè)指針存放在指定的寄存器中(386體系結(jié)構(gòu)沒有放到指定寄存器中)。
這個(gè)宏定義在\include\asm-arm\globe_data.h文件中
#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm("r8")
聲明一個(gè)寄存器變量 gd 占用r8。這個(gè)宏在所有需要引用全局?jǐn)?shù)據(jù)指針gd_t *gd的源碼中都有申明。
這個(gè)申明也避免編譯器把r8分配給其它的變量. 所以gd就是r8,用r8來保存內(nèi)存地址,達(dá)到全局使用目的,這個(gè)指針變量不占用內(nèi)存。
         總結(jié):gd指向一個(gè)數(shù)據(jù)結(jié)構(gòu),用于保存參數(shù)。。*/

        ulong size;
init_fnc_t**init_fnc_ptr;            //這個(gè)是函數(shù)的指針,指向==>硬件初始化的函數(shù)
char *s;


#if defined(CONFIG_VFD)
unsigned long addr;
#endif


#if CFG_LED_FLASH
LED();
#endif
/* gd指針可寫,因?yàn)橐呀?jīng)分配一個(gè)寄存器給它作為變量。
這里就相當(dāng)于把后面算出來的地址保存到r8寄存器.
*/

/* Pointer is writable since we allocated a register for it */
gd = (gd_t*)(_armboot_start -CFG_MALLOC_LEN-sizeof(gd_t));                 //計(jì)算出gd在RAM中的地址
memset ((void*)gd, 0, sizeof (gd_t));                   //給全局?jǐn)?shù)據(jù)變量gd安排空間,用0填充全局?jǐn)?shù)據(jù)表*gd

gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));                    //給板子數(shù)據(jù)變量gd->bd安排空間
memset (gd->bd, 0, sizeof (bd_t));                                   //gd區(qū)包含了bd區(qū),gd_t,bd_t都是結(jié)構(gòu)體變量,

//用0填充(初始化) *gd->bd board info數(shù)據(jù)結(jié)構(gòu)定義,位于文件 include/asm-arm/u-boot.h
monitor_flash_len = _bss_start - _armboot_start;      // 取u-boot的長度

/* 順序執(zhí)行init_sequence數(shù)組中的初始化函數(shù) */

for (init_fnc_ptr = init_sequence;    *init_fnc_ptr;     ++init_fnc_ptr)

{
if ((*init_fnc_ptr)() != 0) {
hang ();      //打印錯(cuò)誤信息并死鎖
}
}

/* configure available FLASH banks   配置可用的Flash */
size = flash_init ();                      //drivers/cfi_flash.c或自定義
display_flash_config (size);

#ifdef CONFIG_VFD                        //如果定義了VFD(真空熒光顯示),就定義頁面大小為4096B
# ifndef PAGE_SIZE
#   define PAGE_SIZE 4096
# endif


/*
* reserve memory for VFD display (always full pages)給VFD保留內(nèi)存空間,以頁為單位
*/
/* armboot_end is defined in the board-specific linker script */


addr = (_bss_start + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
size = vfd_setmem (addr);
gd->fb_base = addr;     //全局?jǐn)?shù)據(jù)gd中定義的幀緩沖區(qū)的基地址
#endif /* CONFIG_VFD */


/* armboot_start is defined in the board-specific linker script初始化堆空間*/
mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);            //malloc使用的內(nèi)存空間地址0x0c700000-129k(0x00080400)

#if (CONFIG_COMMANDS & CFG_CMD_NAND)              //如果有nandflash的話就在下面的代碼中進(jìn)行初始化
puts ("NAND:");
nand_init();           /* go init the NAND */
#endif

#ifdef CONFIG_HAS_DATAFLASH
AT91F_DataflashInit();
dataflash_print_info();
#endif

/* initialize environment 重新初始化環(huán)境,重新定位環(huán)境變量參數(shù)區(qū),它在/common/env_common.c文件中定義*/
env_relocate ();

#ifdef CONFIG_VFD
/* must do this after the framebuffer is allocated */
drv_vfd_init();           //vfd初始化,在分配幀緩沖區(qū)之后必須的
#endif /* CONFIG_VFD */

/* IP Address 從環(huán)境變量中獲取IP地址*/
gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

/* MAC Address 以太網(wǎng)接口MAC 地址*/
{
int       i;
ulong    reg;
char      *s,    *e;
uchar    tmp[64];

         i = getenv_r ("ethaddr", tmp, sizeof (tmp));
s =  (i  >  0)  ?  tmp  :  NULL;

         for (reg = 0;   reg < 6;   ++reg){
gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0;
if (s)
s = (*e) ? e + 1 : e;          
}
}

devices_init ();              /* get the devices list going.設(shè)備初始化*/

jumptable_init ();          //跳轉(zhuǎn)表初始化

console_init_r ();          /* fully init console as a device 完整地初始化控制臺設(shè)備*/

#if defined(CONFIG_MISC_INIT_R)
/* miscellaneous platform dependent initialisations */
misc_init_r ();
#endif

/* enable exceptions 使能中斷處理*/
enable_interrupts ();

。。。。。。

/* main_loop() can return to retry autoboot, if so just run it again. 循環(huán)不斷執(zhí)行*/
for  ( ;  ; ){
main_loop ();      //主循環(huán)函數(shù)處理執(zhí)行用戶命令 -- common/main.c
}

/* NOTREACHED - no way out of command loop except booting */
}

void hang (void)
{
puts ("### ERROR ### Please RESET the board ###\n");     //輸出錯(cuò)誤信息需要reset,進(jìn)入死循環(huán)
for (  ;  ;  );
}

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP