一. Linux ARMv7啟動階段對中斷向量表的搬移
1、中斷向量表和中斷處理部分代碼的搬移
經(jīng)歷過kernel的匯編階段,進入C語言start_kernel后對中斷向量表的位置進行搬移,搬移函數(shù)是early_trap_init。
early_trap_init函數(shù)的調(diào)用流程為:
start_kernel(init/main.c)--->setup_arch(arch/arm/kernel/setup.c)--->paging_init(arch/arm/mm/mmu.c)--->devicemaps_init(arch/arm/mm/mmu.c)--->early_trap_init(arch/arm/kernel/traps.c)
/*
* Set up the device mappings. Since we clear out the page tables for all
* mappings above VMALLOC_START, except early fixmap, we might remove debug
* device mappings. This means earlycon can be used to debug this function
* Any other function or debugging method which may touch any device _will_
* crash the kernel.
*/
static void __init devicemaps_init(const struct machine_desc *mdesc)
{
struct map_desc map;
unsigned long addr;
void *vectors;
/*
* Allocate the vector page early.
*分配兩個頁的內(nèi)存空間,arm中每個頁的大小為4K,這兩個頁的內(nèi)存空間,一個是為保存中斷向量
*表,一個是為了保存中斷的處理部分代碼,這兩部分代碼的排布可以在
*(arch/arm/kernel/vmlinux.lds和arch/arm/kernel/entry-armv.S)中可以具體分析出來
*/
vectors = early_alloc(PAGE_SIZE * 2);
early_trap_init(vectors);
/*
* Clear page table except top pmd used by early fixmaps
*/
for (addr = VMALLOC_START; addr < (FIXADDR_TOP & PMD_MASK); addr += PMD_SIZE)
pmd_clear(pmd_off_k(addr));
/*
* Map the kernel if it is XIP.
* It is always first in the modulearea.
*/
#ifdef CONFIG_XIP_KERNEL //此宏未定義
map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
map.virtual = MODULES_VADDR;
map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
map.type = MT_ROM;
create_mapping(&map);
#endif
/*
* Map the cache flushing regions.
*/
#ifdef FLUSH_BASE //此宏未定義
map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
map.virtual = FLUSH_BASE;
map.length = SZ_1M;
map.type = MT_CACHECLEAN;
create_mapping(&map);
#endif
#ifdef FLUSH_BASE_MINICACHE //此宏未定義
map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
map.virtual = FLUSH_BASE_MINICACHE;
map.length = SZ_1M;
map.type = MT_MINICLEAN;
create_mapping(&map);
#endif
/*
* Create a mapping for the machine vectors at the high-vectors
* location (0xffff0000). If we aren't using high-vectors, also
* create a mapping at the low-vectors virtual address.
*/
/*
*創(chuàng)建一個頁的內(nèi)存地址映射,虛擬地址為0xffff0000,此地址為中斷向量表的高端地址
*設(shè)置中斷向量表的高端地址在匯編的v7_setup中,使用的v7_crval設(shè)置了cp15的c1寄存器
*v7_crval定義在arch/arm/mm/proc-v7-2level.S。
*/
map.pfn = __phys_to_pfn(virt_to_phys(vectors));
map.virtual = 0xffff0000;
map.length = PAGE_SIZE;
#ifdef CONFIG_KUSER_HELPERS //此宏有定義
map.type = MT_HIGH_VECTORS;
#else
map.type = MT_LOW_VECTORS;
#endif
create_mapping(&map);
/*
*判斷中斷向量表的位置是否設(shè)置在高端地址,如果中斷向量表沒有設(shè)置在高端地址,
*在映射低端中斷向量表地址。
*/
if (!vectors_high()) {
map.virtual = 0;
map.length = PAGE_SIZE * 2;
map.type = MT_LOW_VECTORS;
create_mapping(&map);
}
/* Now create a kernel read-only mapping */
map.pfn += 1;
map.virtual = 0xffff0000 + PAGE_SIZE;
map.length = PAGE_SIZE;
map.type = MT_LOW_VECTORS;
create_mapping(&map);
/*
* Ask the machine support to map in the statically mapped devices.
*/
if (mdesc->map_io)
mdesc->map_io();
else
debug_ll_io_init();
fill_pmd_gaps();
/* Reserve fixed i/o space in VMALLOC region */
pci_reserve_io();
/*
* Finally flush the caches and tlb to ensure that we're in a
* consistent state wrt the writebuffer. This also ensures that
* any write-allocated cache lines in the vector page are written
* back. After this point, we can start to touch devices again.
*/
local_flush_tlb_all();
flush_cache_all();
/* Enable asynchronous aborts */
early_abt_enable();
}
/* AT
* TFR EV X F I D LR S
* .EEE ..EE PUI. .T.T 4RVI ZWRS BLDP WCAM
* rxxx rrxx xxx0 0101 xxxx xxxx x111 xxxx < forced
* 01 0 110 0011 1100 .111 1101 < we want
*/
.align 2
.type v7_crval, #object
v7_crval:
crval clear=0x2120c302, mmuset=0x10c03c7d, ucset=0x00c01c7c
early_trap_init函數(shù)的分析
void __init early_trap_init(void *vectors_base)
{
#ifndef CONFIG_CPU_V7M
unsigned long vectors = (unsigned long)vectors_base;
extern char __stubs_start[], __stubs_end[];
extern char __vectors_start[], __vectors_end[];
unsigned i;
vectors_page = vectors_base;
/*
* Poison the vectors page with an undefined instruction. This
* rly_trap_init instruction is chosen to be undefined for both ARM and Thumb
* ISAs. The Thumb version is an undefined instruction with a
* branch back to the undefined instruction.
* 將申請的4K先設(shè)置為未定義指令,防止在發(fā)生其他中斷時,沒有處理導(dǎo)致cpu錯誤
*/
for (i = 0; i < PAGE_SIZE / sizeof(u32); i++)
((u32 *)vectors_base)[i] = 0xe7fddef1;/*
* Copy the vectors, stubs and kuser helpers (in entry-armv.S)
* into the vector page, mapped at 0xffff0000, and ensure these
* are visible to the instruction stream.
*/
/*
*將中斷向量表和中斷處理的代碼搬移到申請的兩頁地址空間內(nèi)
*/
memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
memcpy((void *)vectors + 0x1000, __stubs_start, __stubs_end - __stubs_start);
kuser_init(vectors_base);
flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
#else /* ifndef CONFIG_CPU_V7M */
/*
* on V7-M there is no need to copy the vector table to a dedicated
* memory area. The address is configurable and so a table in the kernel
* image can be used.
*/
#endif
}
上一篇:I2C協(xié)議->裸機程序->adapter驅(qū)動程序分析
下一篇:linux arm mmu基礎(chǔ)
推薦閱讀
史海拾趣
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦
- Microchip 升級數(shù)字信號控制器(DSC)產(chǎn)品線 推出PWM 分辨率和 ADC 速度業(yè)界領(lǐng)先的新器件
- 意法半導(dǎo)體STM32MP23x:突破成本限制的工業(yè)AI應(yīng)用核心
- 意法半導(dǎo)體推出用于匹配遠距離無線微控制器STM32WL33的集成的匹配濾波芯片
- ESP32開發(fā)板連接TFT顯示屏ST7789跳坑記
- 如何讓ESP32支持analogWrite函數(shù)
- LGVL配合FreeType為可變字體設(shè)置字重-ESP32篇
- 使用樹莓派進行 ESP32 Jtag 調(diào)試
- ESP32怎么在SPIFFS里面存儲html,css,js文件,以及網(wǎng)頁和arduino的通訊
- ESP32 freeRTOS使用測試
- 上汽大眾:汽車網(wǎng)絡(luò)安全漏洞防護
- 恩智浦推出全新電池控制IC系列 助力新能源解決方案發(fā)展
- 全球首條GWh級新型固態(tài)電池生產(chǎn)線樣件下線
- 總投資455億元!三大動力電池項目齊刷進度條
- 現(xiàn)代汽車韓國建氫燃料電池廠,2028年投產(chǎn)
- 6月融資一覽:智能汽車芯片、第三代半導(dǎo)體、機器人成資本焦點
- 艙駕一體“點燃”新戰(zhàn)事
- 汽車智能化2.0引爆「萬億蛋糕」,誰在改寫游戲規(guī)則?
- 2025研華智能系統(tǒng)產(chǎn)業(yè)伙伴峰會成功舉辦
- 意法半導(dǎo)體公布2025年第二季度財報和電話會議時間安排
- 《美光2022臺北國際電腦展主題演講精選:數(shù)據(jù)中心專輯》,關(guān)注、評論贏固態(tài)硬盤等好禮!
- EEWORLD E金礦榮耀登場!為夢想加分!
- 揭Altera MAX10神秘面紗,下載白皮書,搶樓贏好禮!
- 【技術(shù)直播】 MPS、Nexperia、泰克專家齊聚,暢談新能源汽車動力設(shè)計注意要點
- ams圣誕禮物大作戰(zhàn):掃碼、關(guān)注、玩游戲、贏禮!
- 助人為樂,打榜領(lǐng)獎: EEWORLD月度問答榜換新推出~
- 幸運十一月,器件購買e問e答!
- EEWORLD 示波器問卷有獎大調(diào)查
- 恩智浦跨界處理器能玩出多少應(yīng)用
- 美光科技聲明:聯(lián)電和晉華提起專利侵權(quán)訴訟實為報復(fù)
- 未來兩年將有3000臺工業(yè)機器人“加盟”許昌
- 低調(diào)的小i機器人 這次一口氣推出“AI+”8大領(lǐng)域解決方案
- Tesla引挪威消費者不滿 投訴增多
- 物靈科技宣布獲1.5億元Pre-A輪融資
- 業(yè)內(nèi)首款認證藍牙?Mesh產(chǎn)品采用賽普拉斯方案
- 2017-2027年3D打印材料市場將達到240億美元
- 瑞薩推出領(lǐng)先的完全集成雙輸出30A和單輸出33A數(shù)字電源模塊
- AMD:2017年Q4營收大漲34%
- Dialog推出首款具有系統(tǒng)在線編程功能的可配置混合信號IC