




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、基于基于i386體系結(jié)構(gòu)的體系結(jié)構(gòu)的Linux啟動(dòng)代碼分析啟動(dòng)代碼分析xlanchen2006.6.1xlanchen2006.6.1Embedded Operating Systems2啟動(dòng)代碼文件啟動(dòng)代碼文件llinux/arch/i386/boot/bootsect.Sllinux/arch/i386/boot/setup.Sllinux/arch/i386/boot/compressed/head.Sllinux/arch/i386/kernel/head.Sllinux/arch/i386/kernel/init_task.cllinux/arch/init/main.cxlanch
2、en2006.6.1Embedded Operating Systems3實(shí)模式實(shí)模式l實(shí)模式是為了兼容早期的CPU而設(shè)置的l系統(tǒng)總是始于實(shí)模式l實(shí)模式下l地址總線:20位l內(nèi)存范圍:01MBl邏輯地址 = 段地址 + 段內(nèi)偏移l段地址 = 段寄存器中的值*16 (或左移4位)l段寄存器長度:16bitxlanchen2006.6.1Embedded Operating Systems4I386實(shí)模式下的內(nèi)存布局圖實(shí)模式下的內(nèi)存布局圖RAM1-MBROM-BIOSVIDEO-BIOSVRAM0 xA00000 xC00000 xF00000 x00000 xlanchen2006.6.1Emb
3、edded Operating Systems5軟盤和硬盤啟動(dòng)軟盤和硬盤啟動(dòng)l軟盤啟動(dòng),bootsect.Sl0 x7c000 x90000l0 x7c00, BIOSl0 x90000, lilol堆棧,0 x3ff4(0 x4000-12), 向下增長l磁盤參數(shù)表,12Bytes,0 x3ff40 x4000l顯示“Loading”lSetup0 x90200l系統(tǒng)l小內(nèi)核,0 x10000(64KB處),低裝載l大內(nèi)核,0 x100000(1MB處),高裝載lsetupl硬盤啟動(dòng),兩階段引導(dǎo)l裝載LILO(LInuxLOader)l第一個(gè)扇區(qū)ll裝載LINUXlBootsect.S0 x
4、90000lSetup.S0 x90200l系統(tǒng)0 x100000 x100000l跳轉(zhuǎn)到setupxlanchen2006.6.1Embedded Operating Systems6Setupl初始化硬件設(shè)備并為內(nèi)核程序的執(zhí)行建立環(huán)境l內(nèi)存檢測(cè)l鍵盤l視頻l磁盤控制器lIBM微通道總線MCAlPS/2設(shè)備(總線鼠標(biāo))lAPM BIOSl若低裝載,將系統(tǒng)移動(dòng)到0 x1000處(4KB處)否則,不必l臨時(shí)IDT和臨時(shí)GDTlFPUlPIC, 16個(gè)硬件中斷中斷向量3247l實(shí)模式保護(hù)模式lStartup_32xlanchen2006.6.1Embedded Operating Systems7
5、Compressed/head.SlStartup_32l初始化段寄存器和一個(gè)臨時(shí)堆棧l初始化BSS段l解壓縮l高裝載或低裝載解壓縮0 x100000(1MB)l跳轉(zhuǎn)到0 x100000處xlanchen2006.6.1Embedded Operating Systems8Head.SlStartup_32l初始化段寄存器l建立進(jìn)程0的內(nèi)核堆棧lSetup_idtl拷貝系統(tǒng)參數(shù)l識(shí)別處理器lGDT、IDTlStart_kernelxlanchen2006.6.1Embedded Operating Systems9The system-segment registerslIn protecte
6、d-mode the CPU needs quick access to some important data-structures, such as:lMemory-Segment DescriptorslInterrupt-Gate DescriptorslCall-Gate DescriptorslTask-State DescriptorslPage-Directory and Page-Table DescriptorslSpecial CPU registers locate these itemsxlanchen2006.6.1Embedded Operating System
7、s10GDT and IDTlTwo most vital system registers for protected-mode execution are:lGDTR (Global Descriptor Table Register)lIDTR (Interrupt Descriptor Table Register)l48-bits widebase-address + segment-limit (an array of descriptors, the GDT & the IDT)lSpecial instructionslSGDT/LGDT, SIDT/LIDTSegme
8、nt Base-AddressSegmentLimit4716 15016 bits32 bitsxlanchen2006.6.1Embedded Operating Systems11System Relationshipsdescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescriptordescrip
9、tordescriptorInterrupt Descriptor TableGlobal Descriptor TableGDTRIDTRxlanchen2006.6.1Embedded Operating Systems12LDT and TSSlFor protected-mode multitasking, the CPU needs to access two other data-structures:lThe current Local Descriptor Table (LDT)lThe current Task-State Segment (TSS)lAgain, speci
10、al registers tell the CPU where to find these data-structures in memory (assuming protected-mode is enabled)lInstructions:lSLDT/LLDT, STR/LTRxlanchen2006.6.1Embedded Operating Systems13Control RegisterslCR0lCR1lCR2lCR3xlanchen2006.6.1Embedded Operating Systems14CR0lCR0, MSW register (Machine Status
11、Word, 32-bit version) lContains system control flags that control operating mode and states of the processorlPE-bit (Protection Enabled)0 CPU is in real-mode, 1 CPU is in protected-modelInstruction: lmswlLINUX setup.S:l movw $1, %ax l lmsw %axl jmp flush_instr / why?lflush_instr: lTo turn on the PE-
12、bit (enables protected-mode),xlanchen2006.6.1Embedded Operating Systems15CR1、CR2、CR3lCR1lReservedlCR2lContains the page-fault linear address (the linear address that caused a page fault)lCR3lContains the physical address of the base of the page directory and two flags (PCD & PWT) xlanchen2006.6.
13、1Embedded Operating Systems16Segment Descriptor FormatBase31.24G DRSVAVLLimit19.16PDPLS XC/DR/WABase23.16Base15.0Limit15.03116150 xlanchen2006.6.1Embedded Operating Systems17“Hidden” part of Segment RegistersselectorSegment baseSegment limitAccessrightsThe programmer-visible part of a segment-regist
14、erThe “invisible” parts of a segment-registerindexTI RPL2 1 015Segment selectorxlanchen2006.6.1Embedded Operating Systems18Three VRAM zonesGRAPHICSMONOCHROME TEXTCOLOR TEXT64-KB32-KB32-KB0 xA00000 xB00000 xB8000 xlanchen2006.6.1Embedded Operating Systems19Array of picture-elementslText-mode VRAM is
15、organized as an arraylEach array-element occupies one word lWords LSB holds ascii character-codelWords MSB holds a color-number pair bgcolorfgcolorASCII character-code1512 118 70bytenybblenybblexlanchen2006.6.1Embedded Operating Systems20Color-Attribute ByteBlinkRGBIntenseGBRforeground color attribu
16、tebackground color attributexlanchen2006.6.1Embedded Operating Systems21Screen-element locations80 columns 25rowscharacters 0.79characters 80.159Video screencharacters 1920.1999xlanchen2006.6.1Embedded Operating Systems22l邏輯地址l段:偏移量l線性地址l32位無符號(hào)整數(shù),04G-1, 即0 x000000000 xFFFFFFFFl物理地址l芯片級(jí)內(nèi)存單元尋址l地址轉(zhuǎn)換過程
17、內(nèi)存尋址內(nèi)存尋址物理地址線性地址分段單元分頁單元邏輯地址xlanchen2006.6.1Embedded Operating Systems23實(shí)模式?保護(hù)模式?分頁?實(shí)模式?保護(hù)模式?分頁?lReal modelExists mostly to maintain processor compatibility with older models, &lTo allow the OS to bootstrapxlanchen2006.6.1Embedded Operating Systems24段選擇子段選擇子indexTIRPL 2 1 015Segment selectorxlan
18、chen2006.6.1Embedded Operating Systems25_KERNEL_CSl_KERNEL_CS0 x10 = 0000 0000 0001 0000blIndex(0 x2), TI(0), RPL(0, highest)llimit(0 xFFFFF), base(0),lG(1, =4096), D(1,=32位),lP(1, in main memory), DPL(0, hignest), S(1),ltype(0 xA) lE(1), executable, codelC(0), not currentlR(1), readablelA(0), unacc
19、essedgdt: .word 0, 0, 0, 0 # dummy .word 0, 0, 0, 0 # unused .word 0 xFFFF # 4Gb .word 0 # base address = 0 .word 0 x9A00 # code read/exec.word 0 x00CF # granularity(4096).word 0 xFFFF # 4Gb .word 0 # base address = 0 .word 0 x9200 # data read/write .word 0 x00CF # granularity(4096)xlanchen2006.6.1Embedded Operating Systems26段描述符段描述符xlanchen2006.6.1Embedded Operating Systems27xlanchen2006.6.1Embedded Operating Systems2
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 花卉購銷協(xié)議書
- 調(diào)整宅基協(xié)議書
- 配送保密協(xié)議書
- 贓款退還協(xié)議書
- 建材業(yè)務(wù)員合同協(xié)議書
- 旅行社地接合同協(xié)議書
- 竹筍合作協(xié)議書
- 租房轉(zhuǎn)手協(xié)議書
- 職工外住協(xié)議書
- 現(xiàn)貨會(huì)員協(xié)議書
- 肌肉注射課件(共45張課件)
- 改革開放史智慧樹知到期末考試答案2024年
- 院內(nèi)按病種分值付費(fèi)(DIP)專題培訓(xùn)
- 單病種管理匯總
- 第六單元作文訓(xùn)練:“批判與觀察”高一語文教材同步作文 素材拓展+范文展示(統(tǒng)編版必修下冊(cè))
- 心肺聽診課件
- 中小學(xué)生環(huán)境教育專題教育大綱
- 商務(wù)禮儀之辦公室禮儀課件
- 公司鑰匙移交單
- 綠色施工策劃書(模板)
- 肺癌生活質(zhì)量量表
評(píng)論
0/150
提交評(píng)論