openbsd mbr匯編語(yǔ)言注釋_第1頁(yè)
openbsd mbr匯編語(yǔ)言注釋_第2頁(yè)
openbsd mbr匯編語(yǔ)言注釋_第3頁(yè)
openbsd mbr匯編語(yǔ)言注釋_第4頁(yè)
openbsd mbr匯編語(yǔ)言注釋_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

.file#include<machine/asm.h>#include<assym.h>#define /*segmentwhereweareload

二階段的啟動(dòng)程序(在OpenBSD上對(duì)應(yīng)二進(jìn)制文件為biosboot,它會(huì)被寫(xiě)在活dcateto*/down*/tes*/dcateto*/down*/tes*/ $c,%al;callLchr $s,%si;callLmessage#defineBOOTRELOCSEG /*segmentwherewe#define /*stackstartshere,#define /*eachpartitiontableentryis16#defineCHAR_LBA_READ'.'#defineCHAR_CHS_READ#define /*UseBEL#defineMBR_FLAGS_ _CHS0x0001#ifdefDEBUG#defineCHAR_S /*started*/#defineCHAR_R /*relocated*/#defineCHAR_L /*lookingforbootablepartition*/#defineCHAR_B /*loadingboot*/#define 'G'/* toboot*/#defineDBGMSG(c) $c,%al;callLchr#else/*!DEBUG*/#defineDBGMSG(c)#endif/*!DEBUG

要加載PBR將其第一個(gè)扇區(qū)的內(nèi)容讀出并到內(nèi)存的0x7c00MBR到這個(gè)位置,所以它首先要把自己到其它地方(0x7a00512),把內(nèi)存中從0x7c00512PBR。把自 到0x7a00PBRAT&T匯編風(fēng)格直接數(shù)前使用內(nèi)mov$1,%eax1存入eax寄存器------------------------------------------------------------------------- ax(不加moveax11eax)PCPCX86LowMemory(thefirst| | | | || |1|256|RAM ||||RAM-e(see||480.5|RAM(guarant|YourOS||| |512||| foruse,ifit||0x0009FFFF|1|RAM|| |384||(originallyonafloppyexecutionstartsatthe

/*PC啟動(dòng)時(shí)處于實(shí)模式,16位/*程 ,如同C語(yǔ)言中的main()

/*原注釋。關(guān)于內(nèi)存的布局Memory0x07E00->0x17BFCourstack(toschemetopartitiondisksintomultipleoperatingbootsectorsoftheofcourseexpecttobe

G,G,

此三行代碼的功能為設(shè)置棧%ss:%sp****0x07C00->0x07DFFweloadPBRhere(at*OFF, *0x07A00,seg:offset*EG, /*BytesinMBR,relocateitall %cs, %cs, %ax,設(shè)置若設(shè)置了DEBUG,此行打印S設(shè)置

loadedatThefirstsectoroftheharddiskisthemasterbootrecord(MBR).sayswhichoneis

%ax, %ax, %si,

movsb

/*設(shè)置%cs0x07c0.BIOSMBRat0000:7C00,theloadthepartitionbootbeforeloadingthePBR.

%di,0x200= ljmp

將%si,%di $0x200,cldflagDF $0x200,

0x07c0:00000000:7c00。這兩種表示方式中%cs和%ipljmp來(lái)確保%cs:%ip的值為/*ljmp語(yǔ)法ljmp的label( )1分配的內(nèi)存地址$1f表示從此語(yǔ)句往下找,第一個(gè)名稱(chēng)為1 的地址。f表示查找方Makeit

es:di %ds %ds/*and%dsisatthe%cs %es/*nextbootisatthe ceaswewereloadedmov指令不可以將數(shù)據(jù)從一個(gè)內(nèi)存地址movsb表示每次移動(dòng)

%es=%ds=%cs=/*Signalthatorbwasseen_CHS,hiftSHIFTSHIFT鍵是否被按下。以BIOS16此時(shí)需要設(shè)置%ah為2,返回 在%al中。按SHIFT表示強(qiáng)制以CHSfourseparatepartitionswasused,toallowmultiplesystemstobeinstalledontheonedisk.ThebootsectorsofoperatingsystemsoneachpartitionwouldofcourseexpecttoloadedatThefirstsectoroftheharddiskisthemasterbootrecordsamelocationwheretheMBRneedstoloadthepartitionrecord(PBR,calledbiosbootinTherefore,theMBRneedstorelocateitselfbeforeloadingtheMakeit testb$0x80,%dljnzdrive_ok

個(gè)操作數(shù)進(jìn)行testb運(yùn)算時(shí)會(huì)跳轉(zhuǎn)到do_chs

BIOS在跳轉(zhuǎn)到0x7c00地址之前會(huì)把啟動(dòng)的磁盤(pán)信息存入%dl寄存器。0x80表示第一個(gè)磁盤(pán),0x81表示第二個(gè) $0x80,$pt, $0x80,$pt, $0x02, $0x02,%ahint$0x16testb$0x3,%al /*Eithershiftkeydown?*/ #ifdef %ax, $0xe3, $SERIAL, int (%si),%al

定義了OpenBSD 的默這里用$ptptpttestb:Performsabit-wiselogicalANDofthetwooperands.Theresultofabit-wiselogicalANDis1ifthevalueofthatbitinbothoperandsis1;otherwise,theresultis0.testdiscardstheresultsandmodifiestheflags.TheOFandCFflagsarecleared;SF,ZFandPFflagsaresetaccordingtotheresult.cmpb:Subtractsoperand1fromoperand2,butdoesnotstoretheresult;onlychangesthe

loopfind_activecall

Loop把%cx $enoboot,至%cx的值為0.每次循環(huán)都把%si $enoboot,Je-jumpifequal(ZF=Jnz-jumpifnotzero(ZF=Jc-jumpifcarryflagisset(CF= %dl, andb$0x0F, addb$'0', %al, $'0'+4, subb%cl, %al, $info,

/*EnsureCtl-Alt-Delwillwork /*(don'trequirepowercycle) jmpNoactivepartition,然后系統(tǒng)就停在那里(可以ctrl-Alt-Delete)來(lái)重啟以十進(jìn)制保存磁盤(pán)號(hào)和分區(qū)號(hào)。用于系統(tǒng)啟動(dòng)時(shí)顯示“Using$'0'表示字符0,而非數(shù)字0,$'0'等于0的ASCII碼00110000(48) 指向啟動(dòng)時(shí)要顯示的信息(Usingdrive……),將它的地址載入%si示在終端上。如果定義了串行端口的話就用int0x14 _CHS,flagsjnz1f _CHS,flagsjnzdo_chs這里以及下面會(huì)使用BIOS的中這里以及下面會(huì)使用BIOS的中LBA方式來(lái)讀,如果不能就跳轉(zhuǎn)到do_chs 處,以CHS方式 寄存器可參看int0x13的說(shuō)明 $0xAA55,/*Checkthatbl,bhexchanged*/jnedo_chs/*Ifnot,don'thaveEDDextensions*/testb$0x01,%cl/*Anddowehave"read"available? /*Didthecommandwork?Jumpifnot %dl,(%si) /*Storedriveheretemporarily*/ $0x55AA,%bx $0x41, int (%si), /*Getbackdrivenumber call $0,itworked,itworked,runthepbrwegot $CHAR_LBA_READ, call利用INT0x13以 8(%si), %ecx, /*We'llneed%silater $0x42, int /*(getback%si)flagsunchangedjnc/*若LBA方式無(wú) ,嘗試 $CHAR_CHS_READ, call利用INT0x13以 磁 1(%si),%dh /*head*/ 2(%si),%cx /*sect,cyl*/ $0x201, /*functionandnumberofblocks %bx, /*putitat%es:0 int $mand, /*Again,useCHSifnot $DOSMBR_SIGNATURE, jne

MBR跳轉(zhuǎn),將控制權(quán)交給PBR代碼跳轉(zhuǎn)到err_stop,同上跳轉(zhuǎn)到err_stop,同上 $eread, jmpjnc $enoos, jmpljmp$0,$BOOTSEG<<轉(zhuǎn)到err_stop,同上lods:lods:loadES:[(E)DI]->LoadsthememorybyteorwordaddressedinthedestinationregisterintotheAL,AX,orEAXregister.Beforeexecutingthelodsinstruction,loadtheindexvaluesintotheSIsource-indexregister.Afterthedataisloaded,thesource-indexregisterisautomaticallyincrementedordecrementedasdeterminedbythevalueofthedirectionflag(DF).TheindexregisterisincrementedifDF=0(DFclearedbyacldinstruction);itisdecrementedifDF=1(DFsetbyastdinstruction).Theincrement/decrementcountis1forabytemove,2foraword,and4foralong.ForablocktransferofCXbytes,wordsorlongs,precedealodsinstructionwitharepprefix;however,lodsisusedmoretypicallywithinaloopconstructwherefurtherprocessingofthedatamovedintoAL,AX,orEAXisusuallyrequired testb%al,%al jmp1b #ifdef

/*%al=*%si++

$0x01,RIAL,RIAL,0e,

INT10h,orINT16isshorthandforBIOSinterruptcall10hex,the17th int int

vectorinanx86-basedcomputersystem.TheBIOStypicallysetsuparealinterrupthandleratthisvectorthatprovides services.Suchservicesincludesettingthe mode,characterandstringoutput,andgraphicsprimitives(readingandwritingpixelsingraphicsmode).Tousethiscall,loadAHwiththenumberofthedesiredsubfunction,loadotherrequiredparametersinotherregisters,andmakethecall.INT10hisfairlyslow,somanyprogramsbypassthisBIOSroutineandaccessthedisyhardwaredirectly.Settingthemode,whichisdoneinfrequently,canbeplishedbyusingtheBIOS,whiledrawinggraphicsonthescreeninagameneedstobedonequickly,sodirectaccesstoRAMismoreappropriatethanmakingaBIOScallforeverypixel. /*sizeofcommandpacket /*sectorstotransfer, /*sectorstotransfer,just1 /*targetbuffer,offset /*targetbuffer,segment 0, /*sectornumber "!Usingdrive" ",partition"

"MBRonfloppyoroldBIOS

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論