版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
.file#include<machine/asm.h>#include<assym.h>#define /*segmentwhereweareload
二阶段的启动程序(在OpenBSD上对应二进制文件为biosboot,它会被写在活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将其第一个扇区的内容读出并到内存的0x7c00MBR到这个位置,所以它首先要把自己到其它地方(0x7a00512),把内存中从0x7c00512PBR。把自 到0x7a00PBRAT&T汇编风格直接数前使用内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启动时处于实模式,16位/*程 ,如同C语言中的main()
/*原注释。关于内存的布局Memory0x07E00->0x17BFCourstack(toschemetopartitiondisksintomultipleoperatingbootsectorsoftheofcourseexpecttobe
G,G,
此三行代码的功能为设置栈%ss:%sp****0x07C00->0x07DFFweloadPBRhere(at*OFF, *0x07A00,seg:offset*EG, /*BytesinMBR,relocateitall %cs, %cs, %ax,设置若设置了DEBUG,此行打印S设置
loadedatThefirstsectoroftheharddiskisthemasterbootrecord(MBR).sayswhichoneis
%ax, %ax, %si,
movsb
/*设置%cs0x07c0.BIOSMBRat0000:7C00,theloadthepartitionbootbeforeloadingthePBR.
%di,0x200= ljmp
将%si,%di $0x200,cldflagDF $0x200,
0x07c0:00000000:7c00。这两种表示方式中%cs和%ipljmp来确保%cs:%ip的值为/*ljmp语法ljmp的label( )1分配的内存地址$1f表示从此语句往下找,第一个名称为1 的地址。f表示查找方Makeit
es:di %ds %ds/*and%dsisatthe%cs %es/*nextbootisatthe ceaswewereloadedmov指令不可以将数据从一个内存地址movsb表示每次移动
%es=%ds=%cs=/*Signalthatorbwasseen_CHS,hiftSHIFTSHIFT键是否被按下。以BIOS16此时需要设置%ah为2,返回 在%al中。按SHIFT表示强制以CHSfourseparatepartitionswasused,toallowmultiplesystemstobeinstalledontheonedisk.ThebootsectorsofoperatingsystemsoneachpartitionwouldofcourseexpecttoloadedatThefirstsectoroftheharddiskisthemasterbootrecordsamelocationwheretheMBRneedstoloadthepartitionrecord(PBR,calledbiosbootinTherefore,theMBRneedstorelocateitselfbeforeloadingtheMakeit testb$0x80,%dljnzdrive_ok
个操作数进行testb运算时会跳转到do_chs
BIOS在跳转到0x7c00地址之前会把启动的磁盘信息存入%dl寄存器。0x80表示第一个磁盘,0x81表示第二个 $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.每次循环都把%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,然后系统就停在那里(可以ctrl-Alt-Delete)来重启以十进制保存磁盘号和分区号。用于系统启动时显示“Using$'0'表示字符0,而非数字0,$'0'等于0的ASCII码00110000(48) 指向启动时要显示的信息(Usingdrive……),将它的地址载入%si示在终端上。如果定义了串行端口的话就用int0x14 _CHS,flagsjnz1f _CHS,flagsjnzdo_chs这里以及下面会使用BIOS的中这里以及下面会使用BIOS的中LBA方式来读,如果不能就跳转到do_chs 处,以CHS方式 寄存器可参看int0x13的说明 $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方式无 ,尝试 $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跳转,将控制权交给PBR代码跳转到err_stop,同上跳转到err_stop,同上 $eread, jmpjnc $enoos, jmpljmp$0,$BOOTSEG<<转到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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 达亮电子安全培训课件
- 辰鑫安全培训服务课件
- 生产企业垃圾场封闭建设方案
- 车险公司柜面培训课件
- 2025年安全隐患整治月活动总结例文(2篇)
- 河北事业单位技师考试(行政办事员)试题
- 车间防汛安全教育培训课件
- 车间职工岗位培训课件
- 酒店客房卫生管理标准制度
- 2025年老年护理专科护士医养结合模式实践工作总结(3篇)
- 2026届北京东城55中高一数学第一学期期末质量检测试题含解析
- 2026年广西贵港市华盛集团新桥农工商有限责任公司招聘备考题库及答案详解1套
- 陕西能源职业技术学院2026年教师公开招聘备考题库完整答案详解
- 绿化苗木种植合同范本
- 2026年辽宁省沈阳市单招职业倾向性测试题库及参考答案详解一套
- 冶金原理李洪桂课件
- 2025年南京市导游综合知识问答题库及答案
- 2026《初中英语•优翼学练优》八上早读本
- 公益慈善组织财务管理制度
- 电力抢修-施工方案
- 征兵心理素质测评适应能力测试题及标准答案
评论
0/150
提交评论