選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BaseLib.h 283KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912
  1. /** @file
  2. Provides string functions, linked list functions, math functions, synchronization
  3. functions, file path functions, and CPU architecture-specific functions.
  4. Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
  5. Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
  6. This program and the accompanying materials
  7. are licensed and made available under the terms and conditions of the BSD License
  8. which accompanies this distribution. The full text of the license may be found at
  9. http://opensource.org/licenses/bsd-license.php.
  10. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  12. **/
  13. #ifndef __BASE_LIB__
  14. #define __BASE_LIB__
  15. FILE_LICENCE ( BSD3 );
  16. //
  17. // Definitions for architecture-specific types
  18. //
  19. #if defined (MDE_CPU_IA32)
  20. ///
  21. /// The IA-32 architecture context buffer used by SetJump() and LongJump().
  22. ///
  23. typedef struct {
  24. UINT32 Ebx;
  25. UINT32 Esi;
  26. UINT32 Edi;
  27. UINT32 Ebp;
  28. UINT32 Esp;
  29. UINT32 Eip;
  30. } BASE_LIBRARY_JUMP_BUFFER;
  31. #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 4
  32. #endif // defined (MDE_CPU_IA32)
  33. #if defined (MDE_CPU_IPF)
  34. ///
  35. /// The Itanium architecture context buffer used by SetJump() and LongJump().
  36. ///
  37. typedef struct {
  38. UINT64 F2[2];
  39. UINT64 F3[2];
  40. UINT64 F4[2];
  41. UINT64 F5[2];
  42. UINT64 F16[2];
  43. UINT64 F17[2];
  44. UINT64 F18[2];
  45. UINT64 F19[2];
  46. UINT64 F20[2];
  47. UINT64 F21[2];
  48. UINT64 F22[2];
  49. UINT64 F23[2];
  50. UINT64 F24[2];
  51. UINT64 F25[2];
  52. UINT64 F26[2];
  53. UINT64 F27[2];
  54. UINT64 F28[2];
  55. UINT64 F29[2];
  56. UINT64 F30[2];
  57. UINT64 F31[2];
  58. UINT64 R4;
  59. UINT64 R5;
  60. UINT64 R6;
  61. UINT64 R7;
  62. UINT64 SP;
  63. UINT64 BR0;
  64. UINT64 BR1;
  65. UINT64 BR2;
  66. UINT64 BR3;
  67. UINT64 BR4;
  68. UINT64 BR5;
  69. UINT64 InitialUNAT;
  70. UINT64 AfterSpillUNAT;
  71. UINT64 PFS;
  72. UINT64 BSP;
  73. UINT64 Predicates;
  74. UINT64 LoopCount;
  75. UINT64 FPSR;
  76. } BASE_LIBRARY_JUMP_BUFFER;
  77. #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10
  78. #endif // defined (MDE_CPU_IPF)
  79. #if defined (MDE_CPU_X64)
  80. ///
  81. /// The x64 architecture context buffer used by SetJump() and LongJump().
  82. ///
  83. typedef struct {
  84. UINT64 Rbx;
  85. UINT64 Rsp;
  86. UINT64 Rbp;
  87. UINT64 Rdi;
  88. UINT64 Rsi;
  89. UINT64 R12;
  90. UINT64 R13;
  91. UINT64 R14;
  92. UINT64 R15;
  93. UINT64 Rip;
  94. UINT64 MxCsr;
  95. UINT8 XmmBuffer[160]; ///< XMM6-XMM15.
  96. } BASE_LIBRARY_JUMP_BUFFER;
  97. #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
  98. #endif // defined (MDE_CPU_X64)
  99. #if defined (MDE_CPU_EBC)
  100. ///
  101. /// The EBC context buffer used by SetJump() and LongJump().
  102. ///
  103. typedef struct {
  104. UINT64 R0;
  105. UINT64 R1;
  106. UINT64 R2;
  107. UINT64 R3;
  108. UINT64 IP;
  109. } BASE_LIBRARY_JUMP_BUFFER;
  110. #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
  111. #endif // defined (MDE_CPU_EBC)
  112. #if defined (MDE_CPU_ARM)
  113. typedef struct {
  114. UINT32 R3; ///< A copy of R13.
  115. UINT32 R4;
  116. UINT32 R5;
  117. UINT32 R6;
  118. UINT32 R7;
  119. UINT32 R8;
  120. UINT32 R9;
  121. UINT32 R10;
  122. UINT32 R11;
  123. UINT32 R12;
  124. UINT32 R14;
  125. } BASE_LIBRARY_JUMP_BUFFER;
  126. #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 4
  127. #endif // defined (MDE_CPU_ARM)
  128. #if defined (MDE_CPU_AARCH64)
  129. typedef struct {
  130. // GP regs
  131. UINT64 X19;
  132. UINT64 X20;
  133. UINT64 X21;
  134. UINT64 X22;
  135. UINT64 X23;
  136. UINT64 X24;
  137. UINT64 X25;
  138. UINT64 X26;
  139. UINT64 X27;
  140. UINT64 X28;
  141. UINT64 FP;
  142. UINT64 LR;
  143. UINT64 IP0;
  144. // FP regs
  145. UINT64 D8;
  146. UINT64 D9;
  147. UINT64 D10;
  148. UINT64 D11;
  149. UINT64 D12;
  150. UINT64 D13;
  151. UINT64 D14;
  152. UINT64 D15;
  153. } BASE_LIBRARY_JUMP_BUFFER;
  154. #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
  155. #endif // defined (MDE_CPU_AARCH64)
  156. //
  157. // String Services
  158. //
  159. /**
  160. Returns the length of a Null-terminated Unicode string.
  161. This function is similar as strlen_s defined in C11.
  162. If String is not aligned on a 16-bit boundary, then ASSERT().
  163. @param String A pointer to a Null-terminated Unicode string.
  164. @param MaxSize The maximum number of Destination Unicode
  165. char, including terminating null char.
  166. @retval 0 If String is NULL.
  167. @retval MaxSize If there is no null character in the first MaxSize characters of String.
  168. @return The number of characters that percede the terminating null character.
  169. **/
  170. UINTN
  171. EFIAPI
  172. StrnLenS (
  173. IN CONST CHAR16 *String,
  174. IN UINTN MaxSize
  175. );
  176. /**
  177. Returns the size of a Null-terminated Unicode string in bytes, including the
  178. Null terminator.
  179. This function returns the size of the Null-terminated Unicode string
  180. specified by String in bytes, including the Null terminator.
  181. If String is not aligned on a 16-bit boundary, then ASSERT().
  182. @param String A pointer to a Null-terminated Unicode string.
  183. @param MaxSize The maximum number of Destination Unicode
  184. char, including the Null terminator.
  185. @retval 0 If String is NULL.
  186. @retval (sizeof (CHAR16) * (MaxSize + 1))
  187. If there is no Null terminator in the first MaxSize characters of
  188. String.
  189. @return The size of the Null-terminated Unicode string in bytes, including
  190. the Null terminator.
  191. **/
  192. UINTN
  193. EFIAPI
  194. StrnSizeS (
  195. IN CONST CHAR16 *String,
  196. IN UINTN MaxSize
  197. );
  198. /**
  199. Copies the string pointed to by Source (including the terminating null char)
  200. to the array pointed to by Destination.
  201. This function is similar as strcpy_s defined in C11.
  202. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  203. If Source is not aligned on a 16-bit boundary, then ASSERT().
  204. If an error would be returned, then the function will also ASSERT().
  205. If an error is returned, then the Destination is unmodified.
  206. @param Destination A pointer to a Null-terminated Unicode string.
  207. @param DestMax The maximum number of Destination Unicode
  208. char, including terminating null char.
  209. @param Source A pointer to a Null-terminated Unicode string.
  210. @retval RETURN_SUCCESS String is copied.
  211. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).
  212. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  213. If Source is NULL.
  214. If PcdMaximumUnicodeStringLength is not zero,
  215. and DestMax is greater than
  216. PcdMaximumUnicodeStringLength.
  217. If DestMax is 0.
  218. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  219. **/
  220. RETURN_STATUS
  221. EFIAPI
  222. StrCpyS (
  223. OUT CHAR16 *Destination,
  224. IN UINTN DestMax,
  225. IN CONST CHAR16 *Source
  226. );
  227. /**
  228. Copies not more than Length successive char from the string pointed to by
  229. Source to the array pointed to by Destination. If no null char is copied from
  230. Source, then Destination[Length] is always set to null.
  231. This function is similar as strncpy_s defined in C11.
  232. If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
  233. If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
  234. If an error would be returned, then the function will also ASSERT().
  235. If an error is returned, then the Destination is unmodified.
  236. @param Destination A pointer to a Null-terminated Unicode string.
  237. @param DestMax The maximum number of Destination Unicode
  238. char, including terminating null char.
  239. @param Source A pointer to a Null-terminated Unicode string.
  240. @param Length The maximum number of Unicode characters to copy.
  241. @retval RETURN_SUCCESS String is copied.
  242. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than
  243. MIN(StrLen(Source), Length).
  244. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  245. If Source is NULL.
  246. If PcdMaximumUnicodeStringLength is not zero,
  247. and DestMax is greater than
  248. PcdMaximumUnicodeStringLength.
  249. If DestMax is 0.
  250. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  251. **/
  252. RETURN_STATUS
  253. EFIAPI
  254. StrnCpyS (
  255. OUT CHAR16 *Destination,
  256. IN UINTN DestMax,
  257. IN CONST CHAR16 *Source,
  258. IN UINTN Length
  259. );
  260. /**
  261. Appends a copy of the string pointed to by Source (including the terminating
  262. null char) to the end of the string pointed to by Destination.
  263. This function is similar as strcat_s defined in C11.
  264. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  265. If Source is not aligned on a 16-bit boundary, then ASSERT().
  266. If an error would be returned, then the function will also ASSERT().
  267. If an error is returned, then the Destination is unmodified.
  268. @param Destination A pointer to a Null-terminated Unicode string.
  269. @param DestMax The maximum number of Destination Unicode
  270. char, including terminating null char.
  271. @param Source A pointer to a Null-terminated Unicode string.
  272. @retval RETURN_SUCCESS String is appended.
  273. @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than
  274. StrLen(Destination).
  275. @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT
  276. greater than StrLen(Source).
  277. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  278. If Source is NULL.
  279. If PcdMaximumUnicodeStringLength is not zero,
  280. and DestMax is greater than
  281. PcdMaximumUnicodeStringLength.
  282. If DestMax is 0.
  283. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  284. **/
  285. RETURN_STATUS
  286. EFIAPI
  287. StrCatS (
  288. IN OUT CHAR16 *Destination,
  289. IN UINTN DestMax,
  290. IN CONST CHAR16 *Source
  291. );
  292. /**
  293. Appends not more than Length successive char from the string pointed to by
  294. Source to the end of the string pointed to by Destination. If no null char is
  295. copied from Source, then Destination[StrLen(Destination) + Length] is always
  296. set to null.
  297. This function is similar as strncat_s defined in C11.
  298. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  299. If Source is not aligned on a 16-bit boundary, then ASSERT().
  300. If an error would be returned, then the function will also ASSERT().
  301. If an error is returned, then the Destination is unmodified.
  302. @param Destination A pointer to a Null-terminated Unicode string.
  303. @param DestMax The maximum number of Destination Unicode
  304. char, including terminating null char.
  305. @param Source A pointer to a Null-terminated Unicode string.
  306. @param Length The maximum number of Unicode characters to copy.
  307. @retval RETURN_SUCCESS String is appended.
  308. @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than
  309. StrLen(Destination).
  310. @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT
  311. greater than MIN(StrLen(Source), Length).
  312. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  313. If Source is NULL.
  314. If PcdMaximumUnicodeStringLength is not zero,
  315. and DestMax is greater than
  316. PcdMaximumUnicodeStringLength.
  317. If DestMax is 0.
  318. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  319. **/
  320. RETURN_STATUS
  321. EFIAPI
  322. StrnCatS (
  323. IN OUT CHAR16 *Destination,
  324. IN UINTN DestMax,
  325. IN CONST CHAR16 *Source,
  326. IN UINTN Length
  327. );
  328. /**
  329. Convert a Null-terminated Unicode decimal string to a value of type UINTN.
  330. This function outputs a value of type UINTN by interpreting the contents of
  331. the Unicode string specified by String as a decimal number. The format of the
  332. input Unicode string String is:
  333. [spaces] [decimal digits].
  334. The valid decimal digit character is in the range [0-9]. The function will
  335. ignore the pad space, which includes spaces or tab characters, before
  336. [decimal digits]. The running zero in the beginning of [decimal digits] will
  337. be ignored. Then, the function stops at the first character that is a not a
  338. valid decimal character or a Null-terminator, whichever one comes first.
  339. If String is NULL, then ASSERT().
  340. If Data is NULL, then ASSERT().
  341. If String is not aligned in a 16-bit boundary, then ASSERT().
  342. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  343. PcdMaximumUnicodeStringLength Unicode characters, not including the
  344. Null-terminator, then ASSERT().
  345. If String has no valid decimal digits in the above format, then 0 is stored
  346. at the location pointed to by Data.
  347. If the number represented by String exceeds the range defined by UINTN, then
  348. MAX_UINTN is stored at the location pointed to by Data.
  349. If EndPointer is not NULL, a pointer to the character that stopped the scan
  350. is stored at the location pointed to by EndPointer. If String has no valid
  351. decimal digits right after the optional pad spaces, the value of String is
  352. stored at the location pointed to by EndPointer.
  353. @param String Pointer to a Null-terminated Unicode string.
  354. @param EndPointer Pointer to character that stops scan.
  355. @param Data Pointer to the converted value.
  356. @retval RETURN_SUCCESS Value is translated from String.
  357. @retval RETURN_INVALID_PARAMETER If String is NULL.
  358. If Data is NULL.
  359. If PcdMaximumUnicodeStringLength is not
  360. zero, and String contains more than
  361. PcdMaximumUnicodeStringLength Unicode
  362. characters, not including the
  363. Null-terminator.
  364. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  365. the range defined by UINTN.
  366. **/
  367. RETURN_STATUS
  368. EFIAPI
  369. StrDecimalToUintnS (
  370. IN CONST CHAR16 *String,
  371. OUT CHAR16 **EndPointer, OPTIONAL
  372. OUT UINTN *Data
  373. );
  374. /**
  375. Convert a Null-terminated Unicode decimal string to a value of type UINT64.
  376. This function outputs a value of type UINT64 by interpreting the contents of
  377. the Unicode string specified by String as a decimal number. The format of the
  378. input Unicode string String is:
  379. [spaces] [decimal digits].
  380. The valid decimal digit character is in the range [0-9]. The function will
  381. ignore the pad space, which includes spaces or tab characters, before
  382. [decimal digits]. The running zero in the beginning of [decimal digits] will
  383. be ignored. Then, the function stops at the first character that is a not a
  384. valid decimal character or a Null-terminator, whichever one comes first.
  385. If String is NULL, then ASSERT().
  386. If Data is NULL, then ASSERT().
  387. If String is not aligned in a 16-bit boundary, then ASSERT().
  388. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  389. PcdMaximumUnicodeStringLength Unicode characters, not including the
  390. Null-terminator, then ASSERT().
  391. If String has no valid decimal digits in the above format, then 0 is stored
  392. at the location pointed to by Data.
  393. If the number represented by String exceeds the range defined by UINT64, then
  394. MAX_UINT64 is stored at the location pointed to by Data.
  395. If EndPointer is not NULL, a pointer to the character that stopped the scan
  396. is stored at the location pointed to by EndPointer. If String has no valid
  397. decimal digits right after the optional pad spaces, the value of String is
  398. stored at the location pointed to by EndPointer.
  399. @param String Pointer to a Null-terminated Unicode string.
  400. @param EndPointer Pointer to character that stops scan.
  401. @param Data Pointer to the converted value.
  402. @retval RETURN_SUCCESS Value is translated from String.
  403. @retval RETURN_INVALID_PARAMETER If String is NULL.
  404. If Data is NULL.
  405. If PcdMaximumUnicodeStringLength is not
  406. zero, and String contains more than
  407. PcdMaximumUnicodeStringLength Unicode
  408. characters, not including the
  409. Null-terminator.
  410. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  411. the range defined by UINT64.
  412. **/
  413. RETURN_STATUS
  414. EFIAPI
  415. StrDecimalToUint64S (
  416. IN CONST CHAR16 *String,
  417. OUT CHAR16 **EndPointer, OPTIONAL
  418. OUT UINT64 *Data
  419. );
  420. /**
  421. Convert a Null-terminated Unicode hexadecimal string to a value of type
  422. UINTN.
  423. This function outputs a value of type UINTN by interpreting the contents of
  424. the Unicode string specified by String as a hexadecimal number. The format of
  425. the input Unicode string String is:
  426. [spaces][zeros][x][hexadecimal digits].
  427. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  428. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
  429. If "x" appears in the input string, it must be prefixed with at least one 0.
  430. The function will ignore the pad space, which includes spaces or tab
  431. characters, before [zeros], [x] or [hexadecimal digit]. The running zero
  432. before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts
  433. after [x] or the first valid hexadecimal digit. Then, the function stops at
  434. the first character that is a not a valid hexadecimal character or NULL,
  435. whichever one comes first.
  436. If String is NULL, then ASSERT().
  437. If Data is NULL, then ASSERT().
  438. If String is not aligned in a 16-bit boundary, then ASSERT().
  439. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  440. PcdMaximumUnicodeStringLength Unicode characters, not including the
  441. Null-terminator, then ASSERT().
  442. If String has no valid hexadecimal digits in the above format, then 0 is
  443. stored at the location pointed to by Data.
  444. If the number represented by String exceeds the range defined by UINTN, then
  445. MAX_UINTN is stored at the location pointed to by Data.
  446. If EndPointer is not NULL, a pointer to the character that stopped the scan
  447. is stored at the location pointed to by EndPointer. If String has no valid
  448. hexadecimal digits right after the optional pad spaces, the value of String
  449. is stored at the location pointed to by EndPointer.
  450. @param String Pointer to a Null-terminated Unicode string.
  451. @param EndPointer Pointer to character that stops scan.
  452. @param Data Pointer to the converted value.
  453. @retval RETURN_SUCCESS Value is translated from String.
  454. @retval RETURN_INVALID_PARAMETER If String is NULL.
  455. If Data is NULL.
  456. If PcdMaximumUnicodeStringLength is not
  457. zero, and String contains more than
  458. PcdMaximumUnicodeStringLength Unicode
  459. characters, not including the
  460. Null-terminator.
  461. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  462. the range defined by UINTN.
  463. **/
  464. RETURN_STATUS
  465. EFIAPI
  466. StrHexToUintnS (
  467. IN CONST CHAR16 *String,
  468. OUT CHAR16 **EndPointer, OPTIONAL
  469. OUT UINTN *Data
  470. );
  471. /**
  472. Convert a Null-terminated Unicode hexadecimal string to a value of type
  473. UINT64.
  474. This function outputs a value of type UINT64 by interpreting the contents of
  475. the Unicode string specified by String as a hexadecimal number. The format of
  476. the input Unicode string String is:
  477. [spaces][zeros][x][hexadecimal digits].
  478. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  479. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
  480. If "x" appears in the input string, it must be prefixed with at least one 0.
  481. The function will ignore the pad space, which includes spaces or tab
  482. characters, before [zeros], [x] or [hexadecimal digit]. The running zero
  483. before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts
  484. after [x] or the first valid hexadecimal digit. Then, the function stops at
  485. the first character that is a not a valid hexadecimal character or NULL,
  486. whichever one comes first.
  487. If String is NULL, then ASSERT().
  488. If Data is NULL, then ASSERT().
  489. If String is not aligned in a 16-bit boundary, then ASSERT().
  490. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  491. PcdMaximumUnicodeStringLength Unicode characters, not including the
  492. Null-terminator, then ASSERT().
  493. If String has no valid hexadecimal digits in the above format, then 0 is
  494. stored at the location pointed to by Data.
  495. If the number represented by String exceeds the range defined by UINT64, then
  496. MAX_UINT64 is stored at the location pointed to by Data.
  497. If EndPointer is not NULL, a pointer to the character that stopped the scan
  498. is stored at the location pointed to by EndPointer. If String has no valid
  499. hexadecimal digits right after the optional pad spaces, the value of String
  500. is stored at the location pointed to by EndPointer.
  501. @param String Pointer to a Null-terminated Unicode string.
  502. @param EndPointer Pointer to character that stops scan.
  503. @param Data Pointer to the converted value.
  504. @retval RETURN_SUCCESS Value is translated from String.
  505. @retval RETURN_INVALID_PARAMETER If String is NULL.
  506. If Data is NULL.
  507. If PcdMaximumUnicodeStringLength is not
  508. zero, and String contains more than
  509. PcdMaximumUnicodeStringLength Unicode
  510. characters, not including the
  511. Null-terminator.
  512. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  513. the range defined by UINT64.
  514. **/
  515. RETURN_STATUS
  516. EFIAPI
  517. StrHexToUint64S (
  518. IN CONST CHAR16 *String,
  519. OUT CHAR16 **EndPointer, OPTIONAL
  520. OUT UINT64 *Data
  521. );
  522. /**
  523. Returns the length of a Null-terminated Ascii string.
  524. This function is similar as strlen_s defined in C11.
  525. @param String A pointer to a Null-terminated Ascii string.
  526. @param MaxSize The maximum number of Destination Ascii
  527. char, including terminating null char.
  528. @retval 0 If String is NULL.
  529. @retval MaxSize If there is no null character in the first MaxSize characters of String.
  530. @return The number of characters that percede the terminating null character.
  531. **/
  532. UINTN
  533. EFIAPI
  534. AsciiStrnLenS (
  535. IN CONST CHAR8 *String,
  536. IN UINTN MaxSize
  537. );
  538. /**
  539. Returns the size of a Null-terminated Ascii string in bytes, including the
  540. Null terminator.
  541. This function returns the size of the Null-terminated Ascii string specified
  542. by String in bytes, including the Null terminator.
  543. @param String A pointer to a Null-terminated Ascii string.
  544. @param MaxSize The maximum number of Destination Ascii
  545. char, including the Null terminator.
  546. @retval 0 If String is NULL.
  547. @retval (sizeof (CHAR8) * (MaxSize + 1))
  548. If there is no Null terminator in the first MaxSize characters of
  549. String.
  550. @return The size of the Null-terminated Ascii string in bytes, including the
  551. Null terminator.
  552. **/
  553. UINTN
  554. EFIAPI
  555. AsciiStrnSizeS (
  556. IN CONST CHAR8 *String,
  557. IN UINTN MaxSize
  558. );
  559. /**
  560. Copies the string pointed to by Source (including the terminating null char)
  561. to the array pointed to by Destination.
  562. This function is similar as strcpy_s defined in C11.
  563. If an error would be returned, then the function will also ASSERT().
  564. If an error is returned, then the Destination is unmodified.
  565. @param Destination A pointer to a Null-terminated Ascii string.
  566. @param DestMax The maximum number of Destination Ascii
  567. char, including terminating null char.
  568. @param Source A pointer to a Null-terminated Ascii string.
  569. @retval RETURN_SUCCESS String is copied.
  570. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).
  571. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  572. If Source is NULL.
  573. If PcdMaximumAsciiStringLength is not zero,
  574. and DestMax is greater than
  575. PcdMaximumAsciiStringLength.
  576. If DestMax is 0.
  577. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  578. **/
  579. RETURN_STATUS
  580. EFIAPI
  581. AsciiStrCpyS (
  582. OUT CHAR8 *Destination,
  583. IN UINTN DestMax,
  584. IN CONST CHAR8 *Source
  585. );
  586. /**
  587. Copies not more than Length successive char from the string pointed to by
  588. Source to the array pointed to by Destination. If no null char is copied from
  589. Source, then Destination[Length] is always set to null.
  590. This function is similar as strncpy_s defined in C11.
  591. If an error would be returned, then the function will also ASSERT().
  592. If an error is returned, then the Destination is unmodified.
  593. @param Destination A pointer to a Null-terminated Ascii string.
  594. @param DestMax The maximum number of Destination Ascii
  595. char, including terminating null char.
  596. @param Source A pointer to a Null-terminated Ascii string.
  597. @param Length The maximum number of Ascii characters to copy.
  598. @retval RETURN_SUCCESS String is copied.
  599. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than
  600. MIN(StrLen(Source), Length).
  601. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  602. If Source is NULL.
  603. If PcdMaximumAsciiStringLength is not zero,
  604. and DestMax is greater than
  605. PcdMaximumAsciiStringLength.
  606. If DestMax is 0.
  607. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  608. **/
  609. RETURN_STATUS
  610. EFIAPI
  611. AsciiStrnCpyS (
  612. OUT CHAR8 *Destination,
  613. IN UINTN DestMax,
  614. IN CONST CHAR8 *Source,
  615. IN UINTN Length
  616. );
  617. /**
  618. Appends a copy of the string pointed to by Source (including the terminating
  619. null char) to the end of the string pointed to by Destination.
  620. This function is similar as strcat_s defined in C11.
  621. If an error would be returned, then the function will also ASSERT().
  622. If an error is returned, then the Destination is unmodified.
  623. @param Destination A pointer to a Null-terminated Ascii string.
  624. @param DestMax The maximum number of Destination Ascii
  625. char, including terminating null char.
  626. @param Source A pointer to a Null-terminated Ascii string.
  627. @retval RETURN_SUCCESS String is appended.
  628. @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than
  629. StrLen(Destination).
  630. @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT
  631. greater than StrLen(Source).
  632. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  633. If Source is NULL.
  634. If PcdMaximumAsciiStringLength is not zero,
  635. and DestMax is greater than
  636. PcdMaximumAsciiStringLength.
  637. If DestMax is 0.
  638. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  639. **/
  640. RETURN_STATUS
  641. EFIAPI
  642. AsciiStrCatS (
  643. IN OUT CHAR8 *Destination,
  644. IN UINTN DestMax,
  645. IN CONST CHAR8 *Source
  646. );
  647. /**
  648. Appends not more than Length successive char from the string pointed to by
  649. Source to the end of the string pointed to by Destination. If no null char is
  650. copied from Source, then Destination[StrLen(Destination) + Length] is always
  651. set to null.
  652. This function is similar as strncat_s defined in C11.
  653. If an error would be returned, then the function will also ASSERT().
  654. If an error is returned, then the Destination is unmodified.
  655. @param Destination A pointer to a Null-terminated Ascii string.
  656. @param DestMax The maximum number of Destination Ascii
  657. char, including terminating null char.
  658. @param Source A pointer to a Null-terminated Ascii string.
  659. @param Length The maximum number of Ascii characters to copy.
  660. @retval RETURN_SUCCESS String is appended.
  661. @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than
  662. StrLen(Destination).
  663. @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT
  664. greater than MIN(StrLen(Source), Length).
  665. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  666. If Source is NULL.
  667. If PcdMaximumAsciiStringLength is not zero,
  668. and DestMax is greater than
  669. PcdMaximumAsciiStringLength.
  670. If DestMax is 0.
  671. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  672. **/
  673. RETURN_STATUS
  674. EFIAPI
  675. AsciiStrnCatS (
  676. IN OUT CHAR8 *Destination,
  677. IN UINTN DestMax,
  678. IN CONST CHAR8 *Source,
  679. IN UINTN Length
  680. );
  681. /**
  682. Convert a Null-terminated Ascii decimal string to a value of type UINTN.
  683. This function outputs a value of type UINTN by interpreting the contents of
  684. the Ascii string specified by String as a decimal number. The format of the
  685. input Ascii string String is:
  686. [spaces] [decimal digits].
  687. The valid decimal digit character is in the range [0-9]. The function will
  688. ignore the pad space, which includes spaces or tab characters, before
  689. [decimal digits]. The running zero in the beginning of [decimal digits] will
  690. be ignored. Then, the function stops at the first character that is a not a
  691. valid decimal character or a Null-terminator, whichever one comes first.
  692. If String is NULL, then ASSERT().
  693. If Data is NULL, then ASSERT().
  694. If PcdMaximumAsciiStringLength is not zero, and String contains more than
  695. PcdMaximumAsciiStringLength Ascii characters, not including the
  696. Null-terminator, then ASSERT().
  697. If String has no valid decimal digits in the above format, then 0 is stored
  698. at the location pointed to by Data.
  699. If the number represented by String exceeds the range defined by UINTN, then
  700. MAX_UINTN is stored at the location pointed to by Data.
  701. If EndPointer is not NULL, a pointer to the character that stopped the scan
  702. is stored at the location pointed to by EndPointer. If String has no valid
  703. decimal digits right after the optional pad spaces, the value of String is
  704. stored at the location pointed to by EndPointer.
  705. @param String Pointer to a Null-terminated Ascii string.
  706. @param EndPointer Pointer to character that stops scan.
  707. @param Data Pointer to the converted value.
  708. @retval RETURN_SUCCESS Value is translated from String.
  709. @retval RETURN_INVALID_PARAMETER If String is NULL.
  710. If Data is NULL.
  711. If PcdMaximumAsciiStringLength is not zero,
  712. and String contains more than
  713. PcdMaximumAsciiStringLength Ascii
  714. characters, not including the
  715. Null-terminator.
  716. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  717. the range defined by UINTN.
  718. **/
  719. RETURN_STATUS
  720. EFIAPI
  721. AsciiStrDecimalToUintnS (
  722. IN CONST CHAR8 *String,
  723. OUT CHAR8 **EndPointer, OPTIONAL
  724. OUT UINTN *Data
  725. );
  726. /**
  727. Convert a Null-terminated Ascii decimal string to a value of type UINT64.
  728. This function outputs a value of type UINT64 by interpreting the contents of
  729. the Ascii string specified by String as a decimal number. The format of the
  730. input Ascii string String is:
  731. [spaces] [decimal digits].
  732. The valid decimal digit character is in the range [0-9]. The function will
  733. ignore the pad space, which includes spaces or tab characters, before
  734. [decimal digits]. The running zero in the beginning of [decimal digits] will
  735. be ignored. Then, the function stops at the first character that is a not a
  736. valid decimal character or a Null-terminator, whichever one comes first.
  737. If String is NULL, then ASSERT().
  738. If Data is NULL, then ASSERT().
  739. If PcdMaximumAsciiStringLength is not zero, and String contains more than
  740. PcdMaximumAsciiStringLength Ascii characters, not including the
  741. Null-terminator, then ASSERT().
  742. If String has no valid decimal digits in the above format, then 0 is stored
  743. at the location pointed to by Data.
  744. If the number represented by String exceeds the range defined by UINT64, then
  745. MAX_UINT64 is stored at the location pointed to by Data.
  746. If EndPointer is not NULL, a pointer to the character that stopped the scan
  747. is stored at the location pointed to by EndPointer. If String has no valid
  748. decimal digits right after the optional pad spaces, the value of String is
  749. stored at the location pointed to by EndPointer.
  750. @param String Pointer to a Null-terminated Ascii string.
  751. @param EndPointer Pointer to character that stops scan.
  752. @param Data Pointer to the converted value.
  753. @retval RETURN_SUCCESS Value is translated from String.
  754. @retval RETURN_INVALID_PARAMETER If String is NULL.
  755. If Data is NULL.
  756. If PcdMaximumAsciiStringLength is not zero,
  757. and String contains more than
  758. PcdMaximumAsciiStringLength Ascii
  759. characters, not including the
  760. Null-terminator.
  761. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  762. the range defined by UINT64.
  763. **/
  764. RETURN_STATUS
  765. EFIAPI
  766. AsciiStrDecimalToUint64S (
  767. IN CONST CHAR8 *String,
  768. OUT CHAR8 **EndPointer, OPTIONAL
  769. OUT UINT64 *Data
  770. );
  771. /**
  772. Convert a Null-terminated Ascii hexadecimal string to a value of type UINTN.
  773. This function outputs a value of type UINTN by interpreting the contents of
  774. the Ascii string specified by String as a hexadecimal number. The format of
  775. the input Ascii string String is:
  776. [spaces][zeros][x][hexadecimal digits].
  777. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  778. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If
  779. "x" appears in the input string, it must be prefixed with at least one 0. The
  780. function will ignore the pad space, which includes spaces or tab characters,
  781. before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or
  782. [hexadecimal digits] will be ignored. Then, the decoding starts after [x] or
  783. the first valid hexadecimal digit. Then, the function stops at the first
  784. character that is a not a valid hexadecimal character or Null-terminator,
  785. whichever on comes first.
  786. If String is NULL, then ASSERT().
  787. If Data is NULL, then ASSERT().
  788. If PcdMaximumAsciiStringLength is not zero, and String contains more than
  789. PcdMaximumAsciiStringLength Ascii characters, not including the
  790. Null-terminator, then ASSERT().
  791. If String has no valid hexadecimal digits in the above format, then 0 is
  792. stored at the location pointed to by Data.
  793. If the number represented by String exceeds the range defined by UINTN, then
  794. MAX_UINTN is stored at the location pointed to by Data.
  795. If EndPointer is not NULL, a pointer to the character that stopped the scan
  796. is stored at the location pointed to by EndPointer. If String has no valid
  797. hexadecimal digits right after the optional pad spaces, the value of String
  798. is stored at the location pointed to by EndPointer.
  799. @param String Pointer to a Null-terminated Ascii string.
  800. @param EndPointer Pointer to character that stops scan.
  801. @param Data Pointer to the converted value.
  802. @retval RETURN_SUCCESS Value is translated from String.
  803. @retval RETURN_INVALID_PARAMETER If String is NULL.
  804. If Data is NULL.
  805. If PcdMaximumAsciiStringLength is not zero,
  806. and String contains more than
  807. PcdMaximumAsciiStringLength Ascii
  808. characters, not including the
  809. Null-terminator.
  810. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  811. the range defined by UINTN.
  812. **/
  813. RETURN_STATUS
  814. EFIAPI
  815. AsciiStrHexToUintnS (
  816. IN CONST CHAR8 *String,
  817. OUT CHAR8 **EndPointer, OPTIONAL
  818. OUT UINTN *Data
  819. );
  820. /**
  821. Convert a Null-terminated Ascii hexadecimal string to a value of type UINT64.
  822. This function outputs a value of type UINT64 by interpreting the contents of
  823. the Ascii string specified by String as a hexadecimal number. The format of
  824. the input Ascii string String is:
  825. [spaces][zeros][x][hexadecimal digits].
  826. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  827. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If
  828. "x" appears in the input string, it must be prefixed with at least one 0. The
  829. function will ignore the pad space, which includes spaces or tab characters,
  830. before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or
  831. [hexadecimal digits] will be ignored. Then, the decoding starts after [x] or
  832. the first valid hexadecimal digit. Then, the function stops at the first
  833. character that is a not a valid hexadecimal character or Null-terminator,
  834. whichever on comes first.
  835. If String is NULL, then ASSERT().
  836. If Data is NULL, then ASSERT().
  837. If PcdMaximumAsciiStringLength is not zero, and String contains more than
  838. PcdMaximumAsciiStringLength Ascii characters, not including the
  839. Null-terminator, then ASSERT().
  840. If String has no valid hexadecimal digits in the above format, then 0 is
  841. stored at the location pointed to by Data.
  842. If the number represented by String exceeds the range defined by UINT64, then
  843. MAX_UINT64 is stored at the location pointed to by Data.
  844. If EndPointer is not NULL, a pointer to the character that stopped the scan
  845. is stored at the location pointed to by EndPointer. If String has no valid
  846. hexadecimal digits right after the optional pad spaces, the value of String
  847. is stored at the location pointed to by EndPointer.
  848. @param String Pointer to a Null-terminated Ascii string.
  849. @param EndPointer Pointer to character that stops scan.
  850. @param Data Pointer to the converted value.
  851. @retval RETURN_SUCCESS Value is translated from String.
  852. @retval RETURN_INVALID_PARAMETER If String is NULL.
  853. If Data is NULL.
  854. If PcdMaximumAsciiStringLength is not zero,
  855. and String contains more than
  856. PcdMaximumAsciiStringLength Ascii
  857. characters, not including the
  858. Null-terminator.
  859. @retval RETURN_UNSUPPORTED If the number represented by String exceeds
  860. the range defined by UINT64.
  861. **/
  862. RETURN_STATUS
  863. EFIAPI
  864. AsciiStrHexToUint64S (
  865. IN CONST CHAR8 *String,
  866. OUT CHAR8 **EndPointer, OPTIONAL
  867. OUT UINT64 *Data
  868. );
  869. #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
  870. /**
  871. [ATTENTION] This function is deprecated for security reason.
  872. Copies one Null-terminated Unicode string to another Null-terminated Unicode
  873. string and returns the new Unicode string.
  874. This function copies the contents of the Unicode string Source to the Unicode
  875. string Destination, and returns Destination. If Source and Destination
  876. overlap, then the results are undefined.
  877. If Destination is NULL, then ASSERT().
  878. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  879. If Source is NULL, then ASSERT().
  880. If Source is not aligned on a 16-bit boundary, then ASSERT().
  881. If Source and Destination overlap, then ASSERT().
  882. If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
  883. PcdMaximumUnicodeStringLength Unicode characters not including the
  884. Null-terminator, then ASSERT().
  885. @param Destination The pointer to a Null-terminated Unicode string.
  886. @param Source The pointer to a Null-terminated Unicode string.
  887. @return Destination.
  888. **/
  889. CHAR16 *
  890. EFIAPI
  891. StrCpy (
  892. OUT CHAR16 *Destination,
  893. IN CONST CHAR16 *Source
  894. );
  895. /**
  896. [ATTENTION] This function is deprecated for security reason.
  897. Copies up to a specified length from one Null-terminated Unicode string to
  898. another Null-terminated Unicode string and returns the new Unicode string.
  899. This function copies the contents of the Unicode string Source to the Unicode
  900. string Destination, and returns Destination. At most, Length Unicode
  901. characters are copied from Source to Destination. If Length is 0, then
  902. Destination is returned unmodified. If Length is greater that the number of
  903. Unicode characters in Source, then Destination is padded with Null Unicode
  904. characters. If Source and Destination overlap, then the results are
  905. undefined.
  906. If Length > 0 and Destination is NULL, then ASSERT().
  907. If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
  908. If Length > 0 and Source is NULL, then ASSERT().
  909. If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
  910. If Source and Destination overlap, then ASSERT().
  911. If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
  912. PcdMaximumUnicodeStringLength, then ASSERT().
  913. If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
  914. PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
  915. then ASSERT().
  916. @param Destination The pointer to a Null-terminated Unicode string.
  917. @param Source The pointer to a Null-terminated Unicode string.
  918. @param Length The maximum number of Unicode characters to copy.
  919. @return Destination.
  920. **/
  921. CHAR16 *
  922. EFIAPI
  923. StrnCpy (
  924. OUT CHAR16 *Destination,
  925. IN CONST CHAR16 *Source,
  926. IN UINTN Length
  927. );
  928. #endif
  929. /**
  930. Returns the length of a Null-terminated Unicode string.
  931. This function returns the number of Unicode characters in the Null-terminated
  932. Unicode string specified by String.
  933. If String is NULL, then ASSERT().
  934. If String is not aligned on a 16-bit boundary, then ASSERT().
  935. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  936. PcdMaximumUnicodeStringLength Unicode characters not including the
  937. Null-terminator, then ASSERT().
  938. @param String Pointer to a Null-terminated Unicode string.
  939. @return The length of String.
  940. **/
  941. UINTN
  942. EFIAPI
  943. StrLen (
  944. IN CONST CHAR16 *String
  945. );
  946. /**
  947. Returns the size of a Null-terminated Unicode string in bytes, including the
  948. Null terminator.
  949. This function returns the size, in bytes, of the Null-terminated Unicode string
  950. specified by String.
  951. If String is NULL, then ASSERT().
  952. If String is not aligned on a 16-bit boundary, then ASSERT().
  953. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  954. PcdMaximumUnicodeStringLength Unicode characters not including the
  955. Null-terminator, then ASSERT().
  956. @param String The pointer to a Null-terminated Unicode string.
  957. @return The size of String.
  958. **/
  959. UINTN
  960. EFIAPI
  961. StrSize (
  962. IN CONST CHAR16 *String
  963. );
  964. /**
  965. Compares two Null-terminated Unicode strings, and returns the difference
  966. between the first mismatched Unicode characters.
  967. This function compares the Null-terminated Unicode string FirstString to the
  968. Null-terminated Unicode string SecondString. If FirstString is identical to
  969. SecondString, then 0 is returned. Otherwise, the value returned is the first
  970. mismatched Unicode character in SecondString subtracted from the first
  971. mismatched Unicode character in FirstString.
  972. If FirstString is NULL, then ASSERT().
  973. If FirstString is not aligned on a 16-bit boundary, then ASSERT().
  974. If SecondString is NULL, then ASSERT().
  975. If SecondString is not aligned on a 16-bit boundary, then ASSERT().
  976. If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
  977. than PcdMaximumUnicodeStringLength Unicode characters not including the
  978. Null-terminator, then ASSERT().
  979. If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
  980. than PcdMaximumUnicodeStringLength Unicode characters, not including the
  981. Null-terminator, then ASSERT().
  982. @param FirstString The pointer to a Null-terminated Unicode string.
  983. @param SecondString The pointer to a Null-terminated Unicode string.
  984. @retval 0 FirstString is identical to SecondString.
  985. @return others FirstString is not identical to SecondString.
  986. **/
  987. INTN
  988. EFIAPI
  989. StrCmp (
  990. IN CONST CHAR16 *FirstString,
  991. IN CONST CHAR16 *SecondString
  992. );
  993. /**
  994. Compares up to a specified length the contents of two Null-terminated Unicode strings,
  995. and returns the difference between the first mismatched Unicode characters.
  996. This function compares the Null-terminated Unicode string FirstString to the
  997. Null-terminated Unicode string SecondString. At most, Length Unicode
  998. characters will be compared. If Length is 0, then 0 is returned. If
  999. FirstString is identical to SecondString, then 0 is returned. Otherwise, the
  1000. value returned is the first mismatched Unicode character in SecondString
  1001. subtracted from the first mismatched Unicode character in FirstString.
  1002. If Length > 0 and FirstString is NULL, then ASSERT().
  1003. If Length > 0 and FirstString is not aligned on a 16-bit boundary, then ASSERT().
  1004. If Length > 0 and SecondString is NULL, then ASSERT().
  1005. If Length > 0 and SecondString is not aligned on a 16-bit boundary, then ASSERT().
  1006. If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
  1007. PcdMaximumUnicodeStringLength, then ASSERT().
  1008. If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than
  1009. PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
  1010. then ASSERT().
  1011. If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than
  1012. PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
  1013. then ASSERT().
  1014. @param FirstString The pointer to a Null-terminated Unicode string.
  1015. @param SecondString The pointer to a Null-terminated Unicode string.
  1016. @param Length The maximum number of Unicode characters to compare.
  1017. @retval 0 FirstString is identical to SecondString.
  1018. @return others FirstString is not identical to SecondString.
  1019. **/
  1020. INTN
  1021. EFIAPI
  1022. StrnCmp (
  1023. IN CONST CHAR16 *FirstString,
  1024. IN CONST CHAR16 *SecondString,
  1025. IN UINTN Length
  1026. );
  1027. #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
  1028. /**
  1029. [ATTENTION] This function is deprecated for security reason.
  1030. Concatenates one Null-terminated Unicode string to another Null-terminated
  1031. Unicode string, and returns the concatenated Unicode string.
  1032. This function concatenates two Null-terminated Unicode strings. The contents
  1033. of Null-terminated Unicode string Source are concatenated to the end of
  1034. Null-terminated Unicode string Destination. The Null-terminated concatenated
  1035. Unicode String is returned. If Source and Destination overlap, then the
  1036. results are undefined.
  1037. If Destination is NULL, then ASSERT().
  1038. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  1039. If Source is NULL, then ASSERT().
  1040. If Source is not aligned on a 16-bit boundary, then ASSERT().
  1041. If Source and Destination overlap, then ASSERT().
  1042. If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
  1043. than PcdMaximumUnicodeStringLength Unicode characters, not including the
  1044. Null-terminator, then ASSERT().
  1045. If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
  1046. PcdMaximumUnicodeStringLength Unicode characters, not including the
  1047. Null-terminator, then ASSERT().
  1048. If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
  1049. and Source results in a Unicode string with more than
  1050. PcdMaximumUnicodeStringLength Unicode characters, not including the
  1051. Null-terminator, then ASSERT().
  1052. @param Destination The pointer to a Null-terminated Unicode string.
  1053. @param Source The pointer to a Null-terminated Unicode string.
  1054. @return Destination.
  1055. **/
  1056. CHAR16 *
  1057. EFIAPI
  1058. StrCat (
  1059. IN OUT CHAR16 *Destination,
  1060. IN CONST CHAR16 *Source
  1061. );
  1062. /**
  1063. [ATTENTION] This function is deprecated for security reason.
  1064. Concatenates up to a specified length one Null-terminated Unicode to the end
  1065. of another Null-terminated Unicode string, and returns the concatenated
  1066. Unicode string.
  1067. This function concatenates two Null-terminated Unicode strings. The contents
  1068. of Null-terminated Unicode string Source are concatenated to the end of
  1069. Null-terminated Unicode string Destination, and Destination is returned. At
  1070. most, Length Unicode characters are concatenated from Source to the end of
  1071. Destination, and Destination is always Null-terminated. If Length is 0, then
  1072. Destination is returned unmodified. If Source and Destination overlap, then
  1073. the results are undefined.
  1074. If Destination is NULL, then ASSERT().
  1075. If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
  1076. If Length > 0 and Source is NULL, then ASSERT().
  1077. If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
  1078. If Source and Destination overlap, then ASSERT().
  1079. If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
  1080. PcdMaximumUnicodeStringLength, then ASSERT().
  1081. If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
  1082. than PcdMaximumUnicodeStringLength Unicode characters, not including the
  1083. Null-terminator, then ASSERT().
  1084. If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
  1085. PcdMaximumUnicodeStringLength Unicode characters, not including the
  1086. Null-terminator, then ASSERT().
  1087. If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
  1088. and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength
  1089. Unicode characters, not including the Null-terminator, then ASSERT().
  1090. @param Destination The pointer to a Null-terminated Unicode string.
  1091. @param Source The pointer to a Null-terminated Unicode string.
  1092. @param Length The maximum number of Unicode characters to concatenate from
  1093. Source.
  1094. @return Destination.
  1095. **/
  1096. CHAR16 *
  1097. EFIAPI
  1098. StrnCat (
  1099. IN OUT CHAR16 *Destination,
  1100. IN CONST CHAR16 *Source,
  1101. IN UINTN Length
  1102. );
  1103. #endif
  1104. /**
  1105. Returns the first occurrence of a Null-terminated Unicode sub-string
  1106. in a Null-terminated Unicode string.
  1107. This function scans the contents of the Null-terminated Unicode string
  1108. specified by String and returns the first occurrence of SearchString.
  1109. If SearchString is not found in String, then NULL is returned. If
  1110. the length of SearchString is zero, then String is returned.
  1111. If String is NULL, then ASSERT().
  1112. If String is not aligned on a 16-bit boundary, then ASSERT().
  1113. If SearchString is NULL, then ASSERT().
  1114. If SearchString is not aligned on a 16-bit boundary, then ASSERT().
  1115. If PcdMaximumUnicodeStringLength is not zero, and SearchString
  1116. or String contains more than PcdMaximumUnicodeStringLength Unicode
  1117. characters, not including the Null-terminator, then ASSERT().
  1118. @param String The pointer to a Null-terminated Unicode string.
  1119. @param SearchString The pointer to a Null-terminated Unicode string to search for.
  1120. @retval NULL If the SearchString does not appear in String.
  1121. @return others If there is a match.
  1122. **/
  1123. CHAR16 *
  1124. EFIAPI
  1125. StrStr (
  1126. IN CONST CHAR16 *String,
  1127. IN CONST CHAR16 *SearchString
  1128. );
  1129. /**
  1130. Convert a Null-terminated Unicode decimal string to a value of
  1131. type UINTN.
  1132. This function returns a value of type UINTN by interpreting the contents
  1133. of the Unicode string specified by String as a decimal number. The format
  1134. of the input Unicode string String is:
  1135. [spaces] [decimal digits].
  1136. The valid decimal digit character is in the range [0-9]. The
  1137. function will ignore the pad space, which includes spaces or
  1138. tab characters, before [decimal digits]. The running zero in the
  1139. beginning of [decimal digits] will be ignored. Then, the function
  1140. stops at the first character that is a not a valid decimal character
  1141. or a Null-terminator, whichever one comes first.
  1142. If String is NULL, then ASSERT().
  1143. If String is not aligned in a 16-bit boundary, then ASSERT().
  1144. If String has only pad spaces, then 0 is returned.
  1145. If String has no pad spaces or valid decimal digits,
  1146. then 0 is returned.
  1147. If the number represented by String overflows according
  1148. to the range defined by UINTN, then MAX_UINTN is returned.
  1149. If PcdMaximumUnicodeStringLength is not zero, and String contains
  1150. more than PcdMaximumUnicodeStringLength Unicode characters not including
  1151. the Null-terminator, then ASSERT().
  1152. @param String The pointer to a Null-terminated Unicode string.
  1153. @retval Value translated from String.
  1154. **/
  1155. UINTN
  1156. EFIAPI
  1157. StrDecimalToUintn (
  1158. IN CONST CHAR16 *String
  1159. );
  1160. /**
  1161. Convert a Null-terminated Unicode decimal string to a value of
  1162. type UINT64.
  1163. This function returns a value of type UINT64 by interpreting the contents
  1164. of the Unicode string specified by String as a decimal number. The format
  1165. of the input Unicode string String is:
  1166. [spaces] [decimal digits].
  1167. The valid decimal digit character is in the range [0-9]. The
  1168. function will ignore the pad space, which includes spaces or
  1169. tab characters, before [decimal digits]. The running zero in the
  1170. beginning of [decimal digits] will be ignored. Then, the function
  1171. stops at the first character that is a not a valid decimal character
  1172. or a Null-terminator, whichever one comes first.
  1173. If String is NULL, then ASSERT().
  1174. If String is not aligned in a 16-bit boundary, then ASSERT().
  1175. If String has only pad spaces, then 0 is returned.
  1176. If String has no pad spaces or valid decimal digits,
  1177. then 0 is returned.
  1178. If the number represented by String overflows according
  1179. to the range defined by UINT64, then MAX_UINT64 is returned.
  1180. If PcdMaximumUnicodeStringLength is not zero, and String contains
  1181. more than PcdMaximumUnicodeStringLength Unicode characters not including
  1182. the Null-terminator, then ASSERT().
  1183. @param String The pointer to a Null-terminated Unicode string.
  1184. @retval Value translated from String.
  1185. **/
  1186. UINT64
  1187. EFIAPI
  1188. StrDecimalToUint64 (
  1189. IN CONST CHAR16 *String
  1190. );
  1191. /**
  1192. Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
  1193. This function returns a value of type UINTN by interpreting the contents
  1194. of the Unicode string specified by String as a hexadecimal number.
  1195. The format of the input Unicode string String is:
  1196. [spaces][zeros][x][hexadecimal digits].
  1197. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  1198. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
  1199. If "x" appears in the input string, it must be prefixed with at least one 0.
  1200. The function will ignore the pad space, which includes spaces or tab characters,
  1201. before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
  1202. [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
  1203. first valid hexadecimal digit. Then, the function stops at the first character
  1204. that is a not a valid hexadecimal character or NULL, whichever one comes first.
  1205. If String is NULL, then ASSERT().
  1206. If String is not aligned in a 16-bit boundary, then ASSERT().
  1207. If String has only pad spaces, then zero is returned.
  1208. If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
  1209. then zero is returned.
  1210. If the number represented by String overflows according to the range defined by
  1211. UINTN, then MAX_UINTN is returned.
  1212. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  1213. PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
  1214. then ASSERT().
  1215. @param String The pointer to a Null-terminated Unicode string.
  1216. @retval Value translated from String.
  1217. **/
  1218. UINTN
  1219. EFIAPI
  1220. StrHexToUintn (
  1221. IN CONST CHAR16 *String
  1222. );
  1223. /**
  1224. Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
  1225. This function returns a value of type UINT64 by interpreting the contents
  1226. of the Unicode string specified by String as a hexadecimal number.
  1227. The format of the input Unicode string String is
  1228. [spaces][zeros][x][hexadecimal digits].
  1229. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  1230. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
  1231. If "x" appears in the input string, it must be prefixed with at least one 0.
  1232. The function will ignore the pad space, which includes spaces or tab characters,
  1233. before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
  1234. [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
  1235. first valid hexadecimal digit. Then, the function stops at the first character that is
  1236. a not a valid hexadecimal character or NULL, whichever one comes first.
  1237. If String is NULL, then ASSERT().
  1238. If String is not aligned in a 16-bit boundary, then ASSERT().
  1239. If String has only pad spaces, then zero is returned.
  1240. If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
  1241. then zero is returned.
  1242. If the number represented by String overflows according to the range defined by
  1243. UINT64, then MAX_UINT64 is returned.
  1244. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  1245. PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
  1246. then ASSERT().
  1247. @param String The pointer to a Null-terminated Unicode string.
  1248. @retval Value translated from String.
  1249. **/
  1250. UINT64
  1251. EFIAPI
  1252. StrHexToUint64 (
  1253. IN CONST CHAR16 *String
  1254. );
  1255. /**
  1256. Convert a Null-terminated Unicode string to IPv6 address and prefix length.
  1257. This function outputs a value of type IPv6_ADDRESS and may output a value
  1258. of type UINT8 by interpreting the contents of the Unicode string specified
  1259. by String. The format of the input Unicode string String is as follows:
  1260. X:X:X:X:X:X:X:X[/P]
  1261. X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and
  1262. [A-F]. X is converted to a value of type UINT16, whose low byte is stored in low
  1263. memory address and high byte is stored in high memory address. P contains decimal
  1264. digit characters in the range [0-9]. The running zero in the beginning of P will
  1265. be ignored. /P is optional.
  1266. When /P is not in the String, the function stops at the first character that is
  1267. not a valid hexadecimal digit character after eight X's are converted.
  1268. When /P is in the String, the function stops at the first character that is not
  1269. a valid decimal digit character after P is converted.
  1270. "::" can be used to compress one or more groups of X when X contains only 0.
  1271. The "::" can only appear once in the String.
  1272. If String is NULL, then ASSERT().
  1273. If Address is NULL, then ASSERT().
  1274. If String is not aligned in a 16-bit boundary, then ASSERT().
  1275. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  1276. PcdMaximumUnicodeStringLength Unicode characters, not including the
  1277. Null-terminator, then ASSERT().
  1278. If EndPointer is not NULL and Address is translated from String, a pointer
  1279. to the character that stopped the scan is stored at the location pointed to
  1280. by EndPointer.
  1281. @param String Pointer to a Null-terminated Unicode string.
  1282. @param EndPointer Pointer to character that stops scan.
  1283. @param Address Pointer to the converted IPv6 address.
  1284. @param PrefixLength Pointer to the converted IPv6 address prefix
  1285. length. MAX_UINT8 is returned when /P is
  1286. not in the String.
  1287. @retval RETURN_SUCCESS Address is translated from String.
  1288. @retval RETURN_INVALID_PARAMETER If String is NULL.
  1289. If Data is NULL.
  1290. @retval RETURN_UNSUPPORTED If X contains more than four hexadecimal
  1291. digit characters.
  1292. If String contains "::" and number of X
  1293. is not less than 8.
  1294. If P starts with character that is not a
  1295. valid decimal digit character.
  1296. If the decimal number converted from P
  1297. exceeds 128.
  1298. **/
  1299. RETURN_STATUS
  1300. EFIAPI
  1301. StrToIpv6Address (
  1302. IN CONST CHAR16 *String,
  1303. OUT CHAR16 **EndPointer, OPTIONAL
  1304. OUT IPv6_ADDRESS *Address,
  1305. OUT UINT8 *PrefixLength OPTIONAL
  1306. );
  1307. /**
  1308. Convert a Null-terminated Unicode string to IPv4 address and prefix length.
  1309. This function outputs a value of type IPv4_ADDRESS and may output a value
  1310. of type UINT8 by interpreting the contents of the Unicode string specified
  1311. by String. The format of the input Unicode string String is as follows:
  1312. D.D.D.D[/P]
  1313. D and P are decimal digit characters in the range [0-9]. The running zero in
  1314. the beginning of D and P will be ignored. /P is optional.
  1315. When /P is not in the String, the function stops at the first character that is
  1316. not a valid decimal digit character after four D's are converted.
  1317. When /P is in the String, the function stops at the first character that is not
  1318. a valid decimal digit character after P is converted.
  1319. If String is NULL, then ASSERT().
  1320. If Address is NULL, then ASSERT().
  1321. If String is not aligned in a 16-bit boundary, then ASSERT().
  1322. If PcdMaximumUnicodeStringLength is not zero, and String contains more than
  1323. PcdMaximumUnicodeStringLength Unicode characters, not including the
  1324. Null-terminator, then ASSERT().
  1325. If EndPointer is not NULL and Address is translated from String, a pointer
  1326. to the character that stopped the scan is stored at the location pointed to
  1327. by EndPointer.
  1328. @param String Pointer to a Null-terminated Unicode string.
  1329. @param EndPointer Pointer to character that stops scan.
  1330. @param Address Pointer to the converted IPv4 address.
  1331. @param PrefixLength Pointer to the converted IPv4 address prefix
  1332. length. MAX_UINT8 is returned when /P is
  1333. not in the String.
  1334. @retval RETURN_SUCCESS Address is translated from String.
  1335. @retval RETURN_INVALID_PARAMETER If String is NULL.
  1336. If Data is NULL.
  1337. @retval RETURN_UNSUPPORTED If String is not in the correct format.
  1338. If any decimal number converted from D
  1339. exceeds 255.
  1340. If the decimal number converted from P
  1341. exceeds 32.
  1342. **/
  1343. RETURN_STATUS
  1344. EFIAPI
  1345. StrToIpv4Address (
  1346. IN CONST CHAR16 *String,
  1347. OUT CHAR16 **EndPointer, OPTIONAL
  1348. OUT IPv4_ADDRESS *Address,
  1349. OUT UINT8 *PrefixLength OPTIONAL
  1350. );
  1351. #define GUID_STRING_LENGTH 36
  1352. /**
  1353. Convert a Null-terminated Unicode GUID string to a value of type
  1354. EFI_GUID.
  1355. This function outputs a GUID value by interpreting the contents of
  1356. the Unicode string specified by String. The format of the input
  1357. Unicode string String consists of 36 characters, as follows:
  1358. aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
  1359. The pairs aa - pp are two characters in the range [0-9], [a-f] and
  1360. [A-F], with each pair representing a single byte hexadecimal value.
  1361. The mapping between String and the EFI_GUID structure is as follows:
  1362. aa Data1[24:31]
  1363. bb Data1[16:23]
  1364. cc Data1[8:15]
  1365. dd Data1[0:7]
  1366. ee Data2[8:15]
  1367. ff Data2[0:7]
  1368. gg Data3[8:15]
  1369. hh Data3[0:7]
  1370. ii Data4[0:7]
  1371. jj Data4[8:15]
  1372. kk Data4[16:23]
  1373. ll Data4[24:31]
  1374. mm Data4[32:39]
  1375. nn Data4[40:47]
  1376. oo Data4[48:55]
  1377. pp Data4[56:63]
  1378. If String is NULL, then ASSERT().
  1379. If Guid is NULL, then ASSERT().
  1380. If String is not aligned in a 16-bit boundary, then ASSERT().
  1381. @param String Pointer to a Null-terminated Unicode string.
  1382. @param Guid Pointer to the converted GUID.
  1383. @retval RETURN_SUCCESS Guid is translated from String.
  1384. @retval RETURN_INVALID_PARAMETER If String is NULL.
  1385. If Data is NULL.
  1386. @retval RETURN_UNSUPPORTED If String is not as the above format.
  1387. **/
  1388. RETURN_STATUS
  1389. EFIAPI
  1390. StrToGuid (
  1391. IN CONST CHAR16 *String,
  1392. OUT GUID *Guid
  1393. );
  1394. /**
  1395. Convert a Null-terminated Unicode hexadecimal string to a byte array.
  1396. This function outputs a byte array by interpreting the contents of
  1397. the Unicode string specified by String in hexadecimal format. The format of
  1398. the input Unicode string String is:
  1399. [XX]*
  1400. X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].
  1401. The function decodes every two hexadecimal digit characters as one byte. The
  1402. decoding stops after Length of characters and outputs Buffer containing
  1403. (Length / 2) bytes.
  1404. If String is not aligned in a 16-bit boundary, then ASSERT().
  1405. If String is NULL, then ASSERT().
  1406. If Buffer is NULL, then ASSERT().
  1407. If Length is not multiple of 2, then ASSERT().
  1408. If PcdMaximumUnicodeStringLength is not zero and Length is greater than
  1409. PcdMaximumUnicodeStringLength, then ASSERT().
  1410. If MaxBufferSize is less than (Length / 2), then ASSERT().
  1411. @param String Pointer to a Null-terminated Unicode string.
  1412. @param Length The number of Unicode characters to decode.
  1413. @param Buffer Pointer to the converted bytes array.
  1414. @param MaxBufferSize The maximum size of Buffer.
  1415. @retval RETURN_SUCCESS Buffer is translated from String.
  1416. @retval RETURN_INVALID_PARAMETER If String is NULL.
  1417. If Data is NULL.
  1418. If Length is not multiple of 2.
  1419. If PcdMaximumUnicodeStringLength is not zero,
  1420. and Length is greater than
  1421. PcdMaximumUnicodeStringLength.
  1422. @retval RETURN_UNSUPPORTED If Length of characters from String contain
  1423. a character that is not valid hexadecimal
  1424. digit characters, or a Null-terminator.
  1425. @retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length / 2).
  1426. **/
  1427. RETURN_STATUS
  1428. EFIAPI
  1429. StrHexToBytes (
  1430. IN CONST CHAR16 *String,
  1431. IN UINTN Length,
  1432. OUT UINT8 *Buffer,
  1433. IN UINTN MaxBufferSize
  1434. );
  1435. #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
  1436. /**
  1437. [ATTENTION] This function is deprecated for security reason.
  1438. Convert a Null-terminated Unicode string to a Null-terminated
  1439. ASCII string and returns the ASCII string.
  1440. This function converts the content of the Unicode string Source
  1441. to the ASCII string Destination by copying the lower 8 bits of
  1442. each Unicode character. It returns Destination.
  1443. The caller is responsible to make sure Destination points to a buffer with size
  1444. equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.
  1445. If any Unicode characters in Source contain non-zero value in
  1446. the upper 8 bits, then ASSERT().
  1447. If Destination is NULL, then ASSERT().
  1448. If Source is NULL, then ASSERT().
  1449. If Source is not aligned on a 16-bit boundary, then ASSERT().
  1450. If Source and Destination overlap, then ASSERT().
  1451. If PcdMaximumUnicodeStringLength is not zero, and Source contains
  1452. more than PcdMaximumUnicodeStringLength Unicode characters not including
  1453. the Null-terminator, then ASSERT().
  1454. If PcdMaximumAsciiStringLength is not zero, and Source contains more
  1455. than PcdMaximumAsciiStringLength Unicode characters not including the
  1456. Null-terminator, then ASSERT().
  1457. @param Source The pointer to a Null-terminated Unicode string.
  1458. @param Destination The pointer to a Null-terminated ASCII string.
  1459. @return Destination.
  1460. **/
  1461. CHAR8 *
  1462. EFIAPI
  1463. UnicodeStrToAsciiStr (
  1464. IN CONST CHAR16 *Source,
  1465. OUT CHAR8 *Destination
  1466. );
  1467. #endif
  1468. /**
  1469. Convert a Null-terminated Unicode string to a Null-terminated
  1470. ASCII string.
  1471. This function is similar to AsciiStrCpyS.
  1472. This function converts the content of the Unicode string Source
  1473. to the ASCII string Destination by copying the lower 8 bits of
  1474. each Unicode character. The function terminates the ASCII string
  1475. Destination by appending a Null-terminator character at the end.
  1476. The caller is responsible to make sure Destination points to a buffer with size
  1477. equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.
  1478. If any Unicode characters in Source contain non-zero value in
  1479. the upper 8 bits, then ASSERT().
  1480. If Source is not aligned on a 16-bit boundary, then ASSERT().
  1481. If an error would be returned, then the function will also ASSERT().
  1482. If an error is returned, then the Destination is unmodified.
  1483. @param Source The pointer to a Null-terminated Unicode string.
  1484. @param Destination The pointer to a Null-terminated ASCII string.
  1485. @param DestMax The maximum number of Destination Ascii
  1486. char, including terminating null char.
  1487. @retval RETURN_SUCCESS String is converted.
  1488. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).
  1489. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  1490. If Source is NULL.
  1491. If PcdMaximumAsciiStringLength is not zero,
  1492. and DestMax is greater than
  1493. PcdMaximumAsciiStringLength.
  1494. If PcdMaximumUnicodeStringLength is not zero,
  1495. and DestMax is greater than
  1496. PcdMaximumUnicodeStringLength.
  1497. If DestMax is 0.
  1498. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  1499. **/
  1500. RETURN_STATUS
  1501. EFIAPI
  1502. UnicodeStrToAsciiStrS (
  1503. IN CONST CHAR16 *Source,
  1504. OUT CHAR8 *Destination,
  1505. IN UINTN DestMax
  1506. );
  1507. /**
  1508. Convert not more than Length successive characters from a Null-terminated
  1509. Unicode string to a Null-terminated Ascii string. If no null char is copied
  1510. from Source, then Destination[Length] is always set to null.
  1511. This function converts not more than Length successive characters from the
  1512. Unicode string Source to the Ascii string Destination by copying the lower 8
  1513. bits of each Unicode character. The function terminates the Ascii string
  1514. Destination by appending a Null-terminator character at the end.
  1515. The caller is responsible to make sure Destination points to a buffer with size
  1516. equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.
  1517. If any Unicode characters in Source contain non-zero value in the upper 8
  1518. bits, then ASSERT().
  1519. If Source is not aligned on a 16-bit boundary, then ASSERT().
  1520. If an error would be returned, then the function will also ASSERT().
  1521. If an error is returned, then the Destination is unmodified.
  1522. @param Source The pointer to a Null-terminated Unicode string.
  1523. @param Length The maximum number of Unicode characters to
  1524. convert.
  1525. @param Destination The pointer to a Null-terminated Ascii string.
  1526. @param DestMax The maximum number of Destination Ascii
  1527. char, including terminating null char.
  1528. @param DestinationLength The number of Unicode characters converted.
  1529. @retval RETURN_SUCCESS String is converted.
  1530. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  1531. If Source is NULL.
  1532. If DestinationLength is NULL.
  1533. If PcdMaximumAsciiStringLength is not zero,
  1534. and Length or DestMax is greater than
  1535. PcdMaximumAsciiStringLength.
  1536. If PcdMaximumUnicodeStringLength is not
  1537. zero, and Length or DestMax is greater than
  1538. PcdMaximumUnicodeStringLength.
  1539. If DestMax is 0.
  1540. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than
  1541. MIN(StrLen(Source), Length).
  1542. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  1543. **/
  1544. RETURN_STATUS
  1545. EFIAPI
  1546. UnicodeStrnToAsciiStrS (
  1547. IN CONST CHAR16 *Source,
  1548. IN UINTN Length,
  1549. OUT CHAR8 *Destination,
  1550. IN UINTN DestMax,
  1551. OUT UINTN *DestinationLength
  1552. );
  1553. #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
  1554. /**
  1555. [ATTENTION] This function is deprecated for security reason.
  1556. Copies one Null-terminated ASCII string to another Null-terminated ASCII
  1557. string and returns the new ASCII string.
  1558. This function copies the contents of the ASCII string Source to the ASCII
  1559. string Destination, and returns Destination. If Source and Destination
  1560. overlap, then the results are undefined.
  1561. If Destination is NULL, then ASSERT().
  1562. If Source is NULL, then ASSERT().
  1563. If Source and Destination overlap, then ASSERT().
  1564. If PcdMaximumAsciiStringLength is not zero and Source contains more than
  1565. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1566. then ASSERT().
  1567. @param Destination The pointer to a Null-terminated ASCII string.
  1568. @param Source The pointer to a Null-terminated ASCII string.
  1569. @return Destination
  1570. **/
  1571. CHAR8 *
  1572. EFIAPI
  1573. AsciiStrCpy (
  1574. OUT CHAR8 *Destination,
  1575. IN CONST CHAR8 *Source
  1576. );
  1577. /**
  1578. [ATTENTION] This function is deprecated for security reason.
  1579. Copies up to a specified length one Null-terminated ASCII string to another
  1580. Null-terminated ASCII string and returns the new ASCII string.
  1581. This function copies the contents of the ASCII string Source to the ASCII
  1582. string Destination, and returns Destination. At most, Length ASCII characters
  1583. are copied from Source to Destination. If Length is 0, then Destination is
  1584. returned unmodified. If Length is greater that the number of ASCII characters
  1585. in Source, then Destination is padded with Null ASCII characters. If Source
  1586. and Destination overlap, then the results are undefined.
  1587. If Destination is NULL, then ASSERT().
  1588. If Source is NULL, then ASSERT().
  1589. If Source and Destination overlap, then ASSERT().
  1590. If PcdMaximumAsciiStringLength is not zero, and Length is greater than
  1591. PcdMaximumAsciiStringLength, then ASSERT().
  1592. If PcdMaximumAsciiStringLength is not zero, and Source contains more than
  1593. PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
  1594. then ASSERT().
  1595. @param Destination The pointer to a Null-terminated ASCII string.
  1596. @param Source The pointer to a Null-terminated ASCII string.
  1597. @param Length The maximum number of ASCII characters to copy.
  1598. @return Destination
  1599. **/
  1600. CHAR8 *
  1601. EFIAPI
  1602. AsciiStrnCpy (
  1603. OUT CHAR8 *Destination,
  1604. IN CONST CHAR8 *Source,
  1605. IN UINTN Length
  1606. );
  1607. #endif
  1608. /**
  1609. Returns the length of a Null-terminated ASCII string.
  1610. This function returns the number of ASCII characters in the Null-terminated
  1611. ASCII string specified by String.
  1612. If Length > 0 and Destination is NULL, then ASSERT().
  1613. If Length > 0 and Source is NULL, then ASSERT().
  1614. If PcdMaximumAsciiStringLength is not zero and String contains more than
  1615. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1616. then ASSERT().
  1617. @param String The pointer to a Null-terminated ASCII string.
  1618. @return The length of String.
  1619. **/
  1620. UINTN
  1621. EFIAPI
  1622. AsciiStrLen (
  1623. IN CONST CHAR8 *String
  1624. );
  1625. /**
  1626. Returns the size of a Null-terminated ASCII string in bytes, including the
  1627. Null terminator.
  1628. This function returns the size, in bytes, of the Null-terminated ASCII string
  1629. specified by String.
  1630. If String is NULL, then ASSERT().
  1631. If PcdMaximumAsciiStringLength is not zero and String contains more than
  1632. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1633. then ASSERT().
  1634. @param String The pointer to a Null-terminated ASCII string.
  1635. @return The size of String.
  1636. **/
  1637. UINTN
  1638. EFIAPI
  1639. AsciiStrSize (
  1640. IN CONST CHAR8 *String
  1641. );
  1642. /**
  1643. Compares two Null-terminated ASCII strings, and returns the difference
  1644. between the first mismatched ASCII characters.
  1645. This function compares the Null-terminated ASCII string FirstString to the
  1646. Null-terminated ASCII string SecondString. If FirstString is identical to
  1647. SecondString, then 0 is returned. Otherwise, the value returned is the first
  1648. mismatched ASCII character in SecondString subtracted from the first
  1649. mismatched ASCII character in FirstString.
  1650. If FirstString is NULL, then ASSERT().
  1651. If SecondString is NULL, then ASSERT().
  1652. If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
  1653. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1654. then ASSERT().
  1655. If PcdMaximumAsciiStringLength is not zero and SecondString contains more
  1656. than PcdMaximumAsciiStringLength ASCII characters not including the
  1657. Null-terminator, then ASSERT().
  1658. @param FirstString The pointer to a Null-terminated ASCII string.
  1659. @param SecondString The pointer to a Null-terminated ASCII string.
  1660. @retval ==0 FirstString is identical to SecondString.
  1661. @retval !=0 FirstString is not identical to SecondString.
  1662. **/
  1663. INTN
  1664. EFIAPI
  1665. AsciiStrCmp (
  1666. IN CONST CHAR8 *FirstString,
  1667. IN CONST CHAR8 *SecondString
  1668. );
  1669. /**
  1670. Performs a case insensitive comparison of two Null-terminated ASCII strings,
  1671. and returns the difference between the first mismatched ASCII characters.
  1672. This function performs a case insensitive comparison of the Null-terminated
  1673. ASCII string FirstString to the Null-terminated ASCII string SecondString. If
  1674. FirstString is identical to SecondString, then 0 is returned. Otherwise, the
  1675. value returned is the first mismatched lower case ASCII character in
  1676. SecondString subtracted from the first mismatched lower case ASCII character
  1677. in FirstString.
  1678. If FirstString is NULL, then ASSERT().
  1679. If SecondString is NULL, then ASSERT().
  1680. If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
  1681. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1682. then ASSERT().
  1683. If PcdMaximumAsciiStringLength is not zero and SecondString contains more
  1684. than PcdMaximumAsciiStringLength ASCII characters not including the
  1685. Null-terminator, then ASSERT().
  1686. @param FirstString The pointer to a Null-terminated ASCII string.
  1687. @param SecondString The pointer to a Null-terminated ASCII string.
  1688. @retval ==0 FirstString is identical to SecondString using case insensitive
  1689. comparisons.
  1690. @retval !=0 FirstString is not identical to SecondString using case
  1691. insensitive comparisons.
  1692. **/
  1693. INTN
  1694. EFIAPI
  1695. AsciiStriCmp (
  1696. IN CONST CHAR8 *FirstString,
  1697. IN CONST CHAR8 *SecondString
  1698. );
  1699. /**
  1700. Compares two Null-terminated ASCII strings with maximum lengths, and returns
  1701. the difference between the first mismatched ASCII characters.
  1702. This function compares the Null-terminated ASCII string FirstString to the
  1703. Null-terminated ASCII string SecondString. At most, Length ASCII characters
  1704. will be compared. If Length is 0, then 0 is returned. If FirstString is
  1705. identical to SecondString, then 0 is returned. Otherwise, the value returned
  1706. is the first mismatched ASCII character in SecondString subtracted from the
  1707. first mismatched ASCII character in FirstString.
  1708. If Length > 0 and FirstString is NULL, then ASSERT().
  1709. If Length > 0 and SecondString is NULL, then ASSERT().
  1710. If PcdMaximumAsciiStringLength is not zero, and Length is greater than
  1711. PcdMaximumAsciiStringLength, then ASSERT().
  1712. If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than
  1713. PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
  1714. then ASSERT().
  1715. If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than
  1716. PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
  1717. then ASSERT().
  1718. @param FirstString The pointer to a Null-terminated ASCII string.
  1719. @param SecondString The pointer to a Null-terminated ASCII string.
  1720. @param Length The maximum number of ASCII characters for compare.
  1721. @retval ==0 FirstString is identical to SecondString.
  1722. @retval !=0 FirstString is not identical to SecondString.
  1723. **/
  1724. INTN
  1725. EFIAPI
  1726. AsciiStrnCmp (
  1727. IN CONST CHAR8 *FirstString,
  1728. IN CONST CHAR8 *SecondString,
  1729. IN UINTN Length
  1730. );
  1731. #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
  1732. /**
  1733. [ATTENTION] This function is deprecated for security reason.
  1734. Concatenates one Null-terminated ASCII string to another Null-terminated
  1735. ASCII string, and returns the concatenated ASCII string.
  1736. This function concatenates two Null-terminated ASCII strings. The contents of
  1737. Null-terminated ASCII string Source are concatenated to the end of Null-
  1738. terminated ASCII string Destination. The Null-terminated concatenated ASCII
  1739. String is returned.
  1740. If Destination is NULL, then ASSERT().
  1741. If Source is NULL, then ASSERT().
  1742. If PcdMaximumAsciiStringLength is not zero and Destination contains more than
  1743. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1744. then ASSERT().
  1745. If PcdMaximumAsciiStringLength is not zero and Source contains more than
  1746. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1747. then ASSERT().
  1748. If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
  1749. Source results in a ASCII string with more than PcdMaximumAsciiStringLength
  1750. ASCII characters, then ASSERT().
  1751. @param Destination The pointer to a Null-terminated ASCII string.
  1752. @param Source The pointer to a Null-terminated ASCII string.
  1753. @return Destination
  1754. **/
  1755. CHAR8 *
  1756. EFIAPI
  1757. AsciiStrCat (
  1758. IN OUT CHAR8 *Destination,
  1759. IN CONST CHAR8 *Source
  1760. );
  1761. /**
  1762. [ATTENTION] This function is deprecated for security reason.
  1763. Concatenates up to a specified length one Null-terminated ASCII string to
  1764. the end of another Null-terminated ASCII string, and returns the
  1765. concatenated ASCII string.
  1766. This function concatenates two Null-terminated ASCII strings. The contents
  1767. of Null-terminated ASCII string Source are concatenated to the end of Null-
  1768. terminated ASCII string Destination, and Destination is returned. At most,
  1769. Length ASCII characters are concatenated from Source to the end of
  1770. Destination, and Destination is always Null-terminated. If Length is 0, then
  1771. Destination is returned unmodified. If Source and Destination overlap, then
  1772. the results are undefined.
  1773. If Length > 0 and Destination is NULL, then ASSERT().
  1774. If Length > 0 and Source is NULL, then ASSERT().
  1775. If Source and Destination overlap, then ASSERT().
  1776. If PcdMaximumAsciiStringLength is not zero, and Length is greater than
  1777. PcdMaximumAsciiStringLength, then ASSERT().
  1778. If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
  1779. PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
  1780. then ASSERT().
  1781. If PcdMaximumAsciiStringLength is not zero, and Source contains more than
  1782. PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
  1783. then ASSERT().
  1784. If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
  1785. Source results in a ASCII string with more than PcdMaximumAsciiStringLength
  1786. ASCII characters, not including the Null-terminator, then ASSERT().
  1787. @param Destination The pointer to a Null-terminated ASCII string.
  1788. @param Source The pointer to a Null-terminated ASCII string.
  1789. @param Length The maximum number of ASCII characters to concatenate from
  1790. Source.
  1791. @return Destination
  1792. **/
  1793. CHAR8 *
  1794. EFIAPI
  1795. AsciiStrnCat (
  1796. IN OUT CHAR8 *Destination,
  1797. IN CONST CHAR8 *Source,
  1798. IN UINTN Length
  1799. );
  1800. #endif
  1801. /**
  1802. Returns the first occurrence of a Null-terminated ASCII sub-string
  1803. in a Null-terminated ASCII string.
  1804. This function scans the contents of the ASCII string specified by String
  1805. and returns the first occurrence of SearchString. If SearchString is not
  1806. found in String, then NULL is returned. If the length of SearchString is zero,
  1807. then String is returned.
  1808. If String is NULL, then ASSERT().
  1809. If SearchString is NULL, then ASSERT().
  1810. If PcdMaximumAsciiStringLength is not zero, and SearchString or
  1811. String contains more than PcdMaximumAsciiStringLength Unicode characters
  1812. not including the Null-terminator, then ASSERT().
  1813. @param String The pointer to a Null-terminated ASCII string.
  1814. @param SearchString The pointer to a Null-terminated ASCII string to search for.
  1815. @retval NULL If the SearchString does not appear in String.
  1816. @retval others If there is a match return the first occurrence of SearchingString.
  1817. If the length of SearchString is zero,return String.
  1818. **/
  1819. CHAR8 *
  1820. EFIAPI
  1821. AsciiStrStr (
  1822. IN CONST CHAR8 *String,
  1823. IN CONST CHAR8 *SearchString
  1824. );
  1825. /**
  1826. Convert a Null-terminated ASCII decimal string to a value of type
  1827. UINTN.
  1828. This function returns a value of type UINTN by interpreting the contents
  1829. of the ASCII string String as a decimal number. The format of the input
  1830. ASCII string String is:
  1831. [spaces] [decimal digits].
  1832. The valid decimal digit character is in the range [0-9]. The function will
  1833. ignore the pad space, which includes spaces or tab characters, before the digits.
  1834. The running zero in the beginning of [decimal digits] will be ignored. Then, the
  1835. function stops at the first character that is a not a valid decimal character or
  1836. Null-terminator, whichever on comes first.
  1837. If String has only pad spaces, then 0 is returned.
  1838. If String has no pad spaces or valid decimal digits, then 0 is returned.
  1839. If the number represented by String overflows according to the range defined by
  1840. UINTN, then MAX_UINTN is returned.
  1841. If String is NULL, then ASSERT().
  1842. If PcdMaximumAsciiStringLength is not zero, and String contains more than
  1843. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1844. then ASSERT().
  1845. @param String The pointer to a Null-terminated ASCII string.
  1846. @retval The value translated from String.
  1847. **/
  1848. UINTN
  1849. EFIAPI
  1850. AsciiStrDecimalToUintn (
  1851. IN CONST CHAR8 *String
  1852. );
  1853. /**
  1854. Convert a Null-terminated ASCII decimal string to a value of type
  1855. UINT64.
  1856. This function returns a value of type UINT64 by interpreting the contents
  1857. of the ASCII string String as a decimal number. The format of the input
  1858. ASCII string String is:
  1859. [spaces] [decimal digits].
  1860. The valid decimal digit character is in the range [0-9]. The function will
  1861. ignore the pad space, which includes spaces or tab characters, before the digits.
  1862. The running zero in the beginning of [decimal digits] will be ignored. Then, the
  1863. function stops at the first character that is a not a valid decimal character or
  1864. Null-terminator, whichever on comes first.
  1865. If String has only pad spaces, then 0 is returned.
  1866. If String has no pad spaces or valid decimal digits, then 0 is returned.
  1867. If the number represented by String overflows according to the range defined by
  1868. UINT64, then MAX_UINT64 is returned.
  1869. If String is NULL, then ASSERT().
  1870. If PcdMaximumAsciiStringLength is not zero, and String contains more than
  1871. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  1872. then ASSERT().
  1873. @param String The pointer to a Null-terminated ASCII string.
  1874. @retval Value translated from String.
  1875. **/
  1876. UINT64
  1877. EFIAPI
  1878. AsciiStrDecimalToUint64 (
  1879. IN CONST CHAR8 *String
  1880. );
  1881. /**
  1882. Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
  1883. This function returns a value of type UINTN by interpreting the contents of
  1884. the ASCII string String as a hexadecimal number. The format of the input ASCII
  1885. string String is:
  1886. [spaces][zeros][x][hexadecimal digits].
  1887. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  1888. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
  1889. appears in the input string, it must be prefixed with at least one 0. The function
  1890. will ignore the pad space, which includes spaces or tab characters, before [zeros],
  1891. [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
  1892. will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
  1893. digit. Then, the function stops at the first character that is a not a valid
  1894. hexadecimal character or Null-terminator, whichever on comes first.
  1895. If String has only pad spaces, then 0 is returned.
  1896. If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
  1897. 0 is returned.
  1898. If the number represented by String overflows according to the range defined by UINTN,
  1899. then MAX_UINTN is returned.
  1900. If String is NULL, then ASSERT().
  1901. If PcdMaximumAsciiStringLength is not zero,
  1902. and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
  1903. the Null-terminator, then ASSERT().
  1904. @param String The pointer to a Null-terminated ASCII string.
  1905. @retval Value translated from String.
  1906. **/
  1907. UINTN
  1908. EFIAPI
  1909. AsciiStrHexToUintn (
  1910. IN CONST CHAR8 *String
  1911. );
  1912. /**
  1913. Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
  1914. This function returns a value of type UINT64 by interpreting the contents of
  1915. the ASCII string String as a hexadecimal number. The format of the input ASCII
  1916. string String is:
  1917. [spaces][zeros][x][hexadecimal digits].
  1918. The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
  1919. The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
  1920. appears in the input string, it must be prefixed with at least one 0. The function
  1921. will ignore the pad space, which includes spaces or tab characters, before [zeros],
  1922. [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
  1923. will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
  1924. digit. Then, the function stops at the first character that is a not a valid
  1925. hexadecimal character or Null-terminator, whichever on comes first.
  1926. If String has only pad spaces, then 0 is returned.
  1927. If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
  1928. 0 is returned.
  1929. If the number represented by String overflows according to the range defined by UINT64,
  1930. then MAX_UINT64 is returned.
  1931. If String is NULL, then ASSERT().
  1932. If PcdMaximumAsciiStringLength is not zero,
  1933. and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
  1934. the Null-terminator, then ASSERT().
  1935. @param String The pointer to a Null-terminated ASCII string.
  1936. @retval Value translated from String.
  1937. **/
  1938. UINT64
  1939. EFIAPI
  1940. AsciiStrHexToUint64 (
  1941. IN CONST CHAR8 *String
  1942. );
  1943. /**
  1944. Convert a Null-terminated ASCII string to IPv6 address and prefix length.
  1945. This function outputs a value of type IPv6_ADDRESS and may output a value
  1946. of type UINT8 by interpreting the contents of the ASCII string specified
  1947. by String. The format of the input ASCII string String is as follows:
  1948. X:X:X:X:X:X:X:X[/P]
  1949. X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and
  1950. [A-F]. X is converted to a value of type UINT16, whose low byte is stored in low
  1951. memory address and high byte is stored in high memory address. P contains decimal
  1952. digit characters in the range [0-9]. The running zero in the beginning of P will
  1953. be ignored. /P is optional.
  1954. When /P is not in the String, the function stops at the first character that is
  1955. not a valid hexadecimal digit character after eight X's are converted.
  1956. When /P is in the String, the function stops at the first character that is not
  1957. a valid decimal digit character after P is converted.
  1958. "::" can be used to compress one or more groups of X when X contains only 0.
  1959. The "::" can only appear once in the String.
  1960. If String is NULL, then ASSERT().
  1961. If Address is NULL, then ASSERT().
  1962. If EndPointer is not NULL and Address is translated from String, a pointer
  1963. to the character that stopped the scan is stored at the location pointed to
  1964. by EndPointer.
  1965. @param String Pointer to a Null-terminated ASCII string.
  1966. @param EndPointer Pointer to character that stops scan.
  1967. @param Address Pointer to the converted IPv6 address.
  1968. @param PrefixLength Pointer to the converted IPv6 address prefix
  1969. length. MAX_UINT8 is returned when /P is
  1970. not in the String.
  1971. @retval RETURN_SUCCESS Address is translated from String.
  1972. @retval RETURN_INVALID_PARAMETER If String is NULL.
  1973. If Data is NULL.
  1974. @retval RETURN_UNSUPPORTED If X contains more than four hexadecimal
  1975. digit characters.
  1976. If String contains "::" and number of X
  1977. is not less than 8.
  1978. If P starts with character that is not a
  1979. valid decimal digit character.
  1980. If the decimal number converted from P
  1981. exceeds 128.
  1982. **/
  1983. RETURN_STATUS
  1984. EFIAPI
  1985. AsciiStrToIpv6Address (
  1986. IN CONST CHAR8 *String,
  1987. OUT CHAR8 **EndPointer, OPTIONAL
  1988. OUT IPv6_ADDRESS *Address,
  1989. OUT UINT8 *PrefixLength OPTIONAL
  1990. );
  1991. /**
  1992. Convert a Null-terminated ASCII string to IPv4 address and prefix length.
  1993. This function outputs a value of type IPv4_ADDRESS and may output a value
  1994. of type UINT8 by interpreting the contents of the ASCII string specified
  1995. by String. The format of the input ASCII string String is as follows:
  1996. D.D.D.D[/P]
  1997. D and P are decimal digit characters in the range [0-9]. The running zero in
  1998. the beginning of D and P will be ignored. /P is optional.
  1999. When /P is not in the String, the function stops at the first character that is
  2000. not a valid decimal digit character after four D's are converted.
  2001. When /P is in the String, the function stops at the first character that is not
  2002. a valid decimal digit character after P is converted.
  2003. If String is NULL, then ASSERT().
  2004. If Address is NULL, then ASSERT().
  2005. If EndPointer is not NULL and Address is translated from String, a pointer
  2006. to the character that stopped the scan is stored at the location pointed to
  2007. by EndPointer.
  2008. @param String Pointer to a Null-terminated ASCII string.
  2009. @param EndPointer Pointer to character that stops scan.
  2010. @param Address Pointer to the converted IPv4 address.
  2011. @param PrefixLength Pointer to the converted IPv4 address prefix
  2012. length. MAX_UINT8 is returned when /P is
  2013. not in the String.
  2014. @retval RETURN_SUCCESS Address is translated from String.
  2015. @retval RETURN_INVALID_PARAMETER If String is NULL.
  2016. If Data is NULL.
  2017. @retval RETURN_UNSUPPORTED If String is not in the correct format.
  2018. If any decimal number converted from D
  2019. exceeds 255.
  2020. If the decimal number converted from P
  2021. exceeds 32.
  2022. **/
  2023. RETURN_STATUS
  2024. EFIAPI
  2025. AsciiStrToIpv4Address (
  2026. IN CONST CHAR8 *String,
  2027. OUT CHAR8 **EndPointer, OPTIONAL
  2028. OUT IPv4_ADDRESS *Address,
  2029. OUT UINT8 *PrefixLength OPTIONAL
  2030. );
  2031. /**
  2032. Convert a Null-terminated ASCII GUID string to a value of type
  2033. EFI_GUID.
  2034. This function outputs a GUID value by interpreting the contents of
  2035. the ASCII string specified by String. The format of the input
  2036. ASCII string String consists of 36 characters, as follows:
  2037. aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
  2038. The pairs aa - pp are two characters in the range [0-9], [a-f] and
  2039. [A-F], with each pair representing a single byte hexadecimal value.
  2040. The mapping between String and the EFI_GUID structure is as follows:
  2041. aa Data1[24:31]
  2042. bb Data1[16:23]
  2043. cc Data1[8:15]
  2044. dd Data1[0:7]
  2045. ee Data2[8:15]
  2046. ff Data2[0:7]
  2047. gg Data3[8:15]
  2048. hh Data3[0:7]
  2049. ii Data4[0:7]
  2050. jj Data4[8:15]
  2051. kk Data4[16:23]
  2052. ll Data4[24:31]
  2053. mm Data4[32:39]
  2054. nn Data4[40:47]
  2055. oo Data4[48:55]
  2056. pp Data4[56:63]
  2057. If String is NULL, then ASSERT().
  2058. If Guid is NULL, then ASSERT().
  2059. @param String Pointer to a Null-terminated ASCII string.
  2060. @param Guid Pointer to the converted GUID.
  2061. @retval RETURN_SUCCESS Guid is translated from String.
  2062. @retval RETURN_INVALID_PARAMETER If String is NULL.
  2063. If Data is NULL.
  2064. @retval RETURN_UNSUPPORTED If String is not as the above format.
  2065. **/
  2066. RETURN_STATUS
  2067. EFIAPI
  2068. AsciiStrToGuid (
  2069. IN CONST CHAR8 *String,
  2070. OUT GUID *Guid
  2071. );
  2072. /**
  2073. Convert a Null-terminated ASCII hexadecimal string to a byte array.
  2074. This function outputs a byte array by interpreting the contents of
  2075. the ASCII string specified by String in hexadecimal format. The format of
  2076. the input ASCII string String is:
  2077. [XX]*
  2078. X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].
  2079. The function decodes every two hexadecimal digit characters as one byte. The
  2080. decoding stops after Length of characters and outputs Buffer containing
  2081. (Length / 2) bytes.
  2082. If String is NULL, then ASSERT().
  2083. If Buffer is NULL, then ASSERT().
  2084. If Length is not multiple of 2, then ASSERT().
  2085. If PcdMaximumAsciiStringLength is not zero and Length is greater than
  2086. PcdMaximumAsciiStringLength, then ASSERT().
  2087. If MaxBufferSize is less than (Length / 2), then ASSERT().
  2088. @param String Pointer to a Null-terminated ASCII string.
  2089. @param Length The number of ASCII characters to decode.
  2090. @param Buffer Pointer to the converted bytes array.
  2091. @param MaxBufferSize The maximum size of Buffer.
  2092. @retval RETURN_SUCCESS Buffer is translated from String.
  2093. @retval RETURN_INVALID_PARAMETER If String is NULL.
  2094. If Data is NULL.
  2095. If Length is not multiple of 2.
  2096. If PcdMaximumAsciiStringLength is not zero,
  2097. and Length is greater than
  2098. PcdMaximumAsciiStringLength.
  2099. @retval RETURN_UNSUPPORTED If Length of characters from String contain
  2100. a character that is not valid hexadecimal
  2101. digit characters, or a Null-terminator.
  2102. @retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length / 2).
  2103. **/
  2104. RETURN_STATUS
  2105. EFIAPI
  2106. AsciiStrHexToBytes (
  2107. IN CONST CHAR8 *String,
  2108. IN UINTN Length,
  2109. OUT UINT8 *Buffer,
  2110. IN UINTN MaxBufferSize
  2111. );
  2112. #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
  2113. /**
  2114. [ATTENTION] This function is deprecated for security reason.
  2115. Convert one Null-terminated ASCII string to a Null-terminated
  2116. Unicode string and returns the Unicode string.
  2117. This function converts the contents of the ASCII string Source to the Unicode
  2118. string Destination, and returns Destination. The function terminates the
  2119. Unicode string Destination by appending a Null-terminator character at the end.
  2120. The caller is responsible to make sure Destination points to a buffer with size
  2121. equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
  2122. If Destination is NULL, then ASSERT().
  2123. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  2124. If Source is NULL, then ASSERT().
  2125. If Source and Destination overlap, then ASSERT().
  2126. If PcdMaximumAsciiStringLength is not zero, and Source contains more than
  2127. PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
  2128. then ASSERT().
  2129. If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
  2130. PcdMaximumUnicodeStringLength ASCII characters not including the
  2131. Null-terminator, then ASSERT().
  2132. @param Source The pointer to a Null-terminated ASCII string.
  2133. @param Destination The pointer to a Null-terminated Unicode string.
  2134. @return Destination.
  2135. **/
  2136. CHAR16 *
  2137. EFIAPI
  2138. AsciiStrToUnicodeStr (
  2139. IN CONST CHAR8 *Source,
  2140. OUT CHAR16 *Destination
  2141. );
  2142. #endif
  2143. /**
  2144. Convert one Null-terminated ASCII string to a Null-terminated
  2145. Unicode string.
  2146. This function is similar to StrCpyS.
  2147. This function converts the contents of the ASCII string Source to the Unicode
  2148. string Destination. The function terminates the Unicode string Destination by
  2149. appending a Null-terminator character at the end.
  2150. The caller is responsible to make sure Destination points to a buffer with size
  2151. equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
  2152. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  2153. If an error would be returned, then the function will also ASSERT().
  2154. If an error is returned, then the Destination is unmodified.
  2155. @param Source The pointer to a Null-terminated ASCII string.
  2156. @param Destination The pointer to a Null-terminated Unicode string.
  2157. @param DestMax The maximum number of Destination Unicode
  2158. char, including terminating null char.
  2159. @retval RETURN_SUCCESS String is converted.
  2160. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).
  2161. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  2162. If Source is NULL.
  2163. If PcdMaximumUnicodeStringLength is not zero,
  2164. and DestMax is greater than
  2165. PcdMaximumUnicodeStringLength.
  2166. If PcdMaximumAsciiStringLength is not zero,
  2167. and DestMax is greater than
  2168. PcdMaximumAsciiStringLength.
  2169. If DestMax is 0.
  2170. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  2171. **/
  2172. RETURN_STATUS
  2173. EFIAPI
  2174. AsciiStrToUnicodeStrS (
  2175. IN CONST CHAR8 *Source,
  2176. OUT CHAR16 *Destination,
  2177. IN UINTN DestMax
  2178. );
  2179. /**
  2180. Convert not more than Length successive characters from a Null-terminated
  2181. Ascii string to a Null-terminated Unicode string. If no null char is copied
  2182. from Source, then Destination[Length] is always set to null.
  2183. This function converts not more than Length successive characters from the
  2184. Ascii string Source to the Unicode string Destination. The function
  2185. terminates the Unicode string Destination by appending a Null-terminator
  2186. character at the end.
  2187. The caller is responsible to make sure Destination points to a buffer with
  2188. size not smaller than
  2189. ((MIN(AsciiStrLen(Source), Length) + 1) * sizeof (CHAR8)) in bytes.
  2190. If Destination is not aligned on a 16-bit boundary, then ASSERT().
  2191. If an error would be returned, then the function will also ASSERT().
  2192. If an error is returned, then Destination and DestinationLength are
  2193. unmodified.
  2194. @param Source The pointer to a Null-terminated Ascii string.
  2195. @param Length The maximum number of Ascii characters to convert.
  2196. @param Destination The pointer to a Null-terminated Unicode string.
  2197. @param DestMax The maximum number of Destination Unicode char,
  2198. including terminating null char.
  2199. @param DestinationLength The number of Ascii characters converted.
  2200. @retval RETURN_SUCCESS String is converted.
  2201. @retval RETURN_INVALID_PARAMETER If Destination is NULL.
  2202. If Source is NULL.
  2203. If DestinationLength is NULL.
  2204. If PcdMaximumUnicodeStringLength is not
  2205. zero, and Length or DestMax is greater than
  2206. PcdMaximumUnicodeStringLength.
  2207. If PcdMaximumAsciiStringLength is not zero,
  2208. and Length or DestMax is greater than
  2209. PcdMaximumAsciiStringLength.
  2210. If DestMax is 0.
  2211. @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than
  2212. MIN(AsciiStrLen(Source), Length).
  2213. @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
  2214. **/
  2215. RETURN_STATUS
  2216. EFIAPI
  2217. AsciiStrnToUnicodeStrS (
  2218. IN CONST CHAR8 *Source,
  2219. IN UINTN Length,
  2220. OUT CHAR16 *Destination,
  2221. IN UINTN DestMax,
  2222. OUT UINTN *DestinationLength
  2223. );
  2224. /**
  2225. Converts an 8-bit value to an 8-bit BCD value.
  2226. Converts the 8-bit value specified by Value to BCD. The BCD value is
  2227. returned.
  2228. If Value >= 100, then ASSERT().
  2229. @param Value The 8-bit value to convert to BCD. Range 0..99.
  2230. @return The BCD value.
  2231. **/
  2232. UINT8
  2233. EFIAPI
  2234. DecimalToBcd8 (
  2235. IN UINT8 Value
  2236. );
  2237. /**
  2238. Converts an 8-bit BCD value to an 8-bit value.
  2239. Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
  2240. value is returned.
  2241. If Value >= 0xA0, then ASSERT().
  2242. If (Value & 0x0F) >= 0x0A, then ASSERT().
  2243. @param Value The 8-bit BCD value to convert to an 8-bit value.
  2244. @return The 8-bit value is returned.
  2245. **/
  2246. UINT8
  2247. EFIAPI
  2248. BcdToDecimal8 (
  2249. IN UINT8 Value
  2250. );
  2251. //
  2252. // File Path Manipulation Functions
  2253. //
  2254. /**
  2255. Removes the last directory or file entry in a path.
  2256. @param[in, out] Path The pointer to the path to modify.
  2257. @retval FALSE Nothing was found to remove.
  2258. @retval TRUE A directory or file was removed.
  2259. **/
  2260. BOOLEAN
  2261. EFIAPI
  2262. PathRemoveLastItem(
  2263. IN OUT CHAR16 *Path
  2264. );
  2265. /**
  2266. Function to clean up paths.
  2267. - Single periods in the path are removed.
  2268. - Double periods in the path are removed along with a single parent directory.
  2269. - Forward slashes L'/' are converted to backward slashes L'\'.
  2270. This will be done inline and the existing buffer may be larger than required
  2271. upon completion.
  2272. @param[in] Path The pointer to the string containing the path.
  2273. @return Returns Path, otherwise returns NULL to indicate that an error has occurred.
  2274. **/
  2275. CHAR16*
  2276. EFIAPI
  2277. PathCleanUpDirectories(
  2278. IN CHAR16 *Path
  2279. );
  2280. //
  2281. // Linked List Functions and Macros
  2282. //
  2283. /**
  2284. Initializes the head node of a doubly linked list that is declared as a
  2285. global variable in a module.
  2286. Initializes the forward and backward links of a new linked list. After
  2287. initializing a linked list with this macro, the other linked list functions
  2288. may be used to add and remove nodes from the linked list. This macro results
  2289. in smaller executables by initializing the linked list in the data section,
  2290. instead if calling the InitializeListHead() function to perform the
  2291. equivalent operation.
  2292. @param ListHead The head note of a list to initialize.
  2293. **/
  2294. #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&(ListHead), &(ListHead)}
  2295. /**
  2296. Initializes the head node of a doubly linked list, and returns the pointer to
  2297. the head node of the doubly linked list.
  2298. Initializes the forward and backward links of a new linked list. After
  2299. initializing a linked list with this function, the other linked list
  2300. functions may be used to add and remove nodes from the linked list. It is up
  2301. to the caller of this function to allocate the memory for ListHead.
  2302. If ListHead is NULL, then ASSERT().
  2303. @param ListHead A pointer to the head node of a new doubly linked list.
  2304. @return ListHead
  2305. **/
  2306. LIST_ENTRY *
  2307. EFIAPI
  2308. InitializeListHead (
  2309. IN OUT LIST_ENTRY *ListHead
  2310. );
  2311. /**
  2312. Adds a node to the beginning of a doubly linked list, and returns the pointer
  2313. to the head node of the doubly linked list.
  2314. Adds the node Entry at the beginning of the doubly linked list denoted by
  2315. ListHead, and returns ListHead.
  2316. If ListHead is NULL, then ASSERT().
  2317. If Entry is NULL, then ASSERT().
  2318. If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
  2319. InitializeListHead(), then ASSERT().
  2320. If PcdMaximumLinkedListLength is not zero, and prior to insertion the number
  2321. of nodes in ListHead, including the ListHead node, is greater than or
  2322. equal to PcdMaximumLinkedListLength, then ASSERT().
  2323. @param ListHead A pointer to the head node of a doubly linked list.
  2324. @param Entry A pointer to a node that is to be inserted at the beginning
  2325. of a doubly linked list.
  2326. @return ListHead
  2327. **/
  2328. LIST_ENTRY *
  2329. EFIAPI
  2330. InsertHeadList (
  2331. IN OUT LIST_ENTRY *ListHead,
  2332. IN OUT LIST_ENTRY *Entry
  2333. );
  2334. /**
  2335. Adds a node to the end of a doubly linked list, and returns the pointer to
  2336. the head node of the doubly linked list.
  2337. Adds the node Entry to the end of the doubly linked list denoted by ListHead,
  2338. and returns ListHead.
  2339. If ListHead is NULL, then ASSERT().
  2340. If Entry is NULL, then ASSERT().
  2341. If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
  2342. InitializeListHead(), then ASSERT().
  2343. If PcdMaximumLinkedListLength is not zero, and prior to insertion the number
  2344. of nodes in ListHead, including the ListHead node, is greater than or
  2345. equal to PcdMaximumLinkedListLength, then ASSERT().
  2346. @param ListHead A pointer to the head node of a doubly linked list.
  2347. @param Entry A pointer to a node that is to be added at the end of the
  2348. doubly linked list.
  2349. @return ListHead
  2350. **/
  2351. LIST_ENTRY *
  2352. EFIAPI
  2353. InsertTailList (
  2354. IN OUT LIST_ENTRY *ListHead,
  2355. IN OUT LIST_ENTRY *Entry
  2356. );
  2357. /**
  2358. Retrieves the first node of a doubly linked list.
  2359. Returns the first node of a doubly linked list. List must have been
  2360. initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
  2361. If List is empty, then List is returned.
  2362. If List is NULL, then ASSERT().
  2363. If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
  2364. InitializeListHead(), then ASSERT().
  2365. If PcdMaximumLinkedListLength is not zero, and the number of nodes
  2366. in List, including the List node, is greater than or equal to
  2367. PcdMaximumLinkedListLength, then ASSERT().
  2368. @param List A pointer to the head node of a doubly linked list.
  2369. @return The first node of a doubly linked list.
  2370. @retval List The list is empty.
  2371. **/
  2372. LIST_ENTRY *
  2373. EFIAPI
  2374. GetFirstNode (
  2375. IN CONST LIST_ENTRY *List
  2376. );
  2377. /**
  2378. Retrieves the next node of a doubly linked list.
  2379. Returns the node of a doubly linked list that follows Node.
  2380. List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()
  2381. or InitializeListHead(). If List is empty, then List is returned.
  2382. If List is NULL, then ASSERT().
  2383. If Node is NULL, then ASSERT().
  2384. If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
  2385. InitializeListHead(), then ASSERT().
  2386. If PcdMaximumLinkedListLength is not zero, and List contains more than
  2387. PcdMaximumLinkedListLength nodes, then ASSERT().
  2388. If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
  2389. @param List A pointer to the head node of a doubly linked list.
  2390. @param Node A pointer to a node in the doubly linked list.
  2391. @return The pointer to the next node if one exists. Otherwise List is returned.
  2392. **/
  2393. LIST_ENTRY *
  2394. EFIAPI
  2395. GetNextNode (
  2396. IN CONST LIST_ENTRY *List,
  2397. IN CONST LIST_ENTRY *Node
  2398. );
  2399. /**
  2400. Retrieves the previous node of a doubly linked list.
  2401. Returns the node of a doubly linked list that precedes Node.
  2402. List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()
  2403. or InitializeListHead(). If List is empty, then List is returned.
  2404. If List is NULL, then ASSERT().
  2405. If Node is NULL, then ASSERT().
  2406. If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
  2407. InitializeListHead(), then ASSERT().
  2408. If PcdMaximumLinkedListLength is not zero, and List contains more than
  2409. PcdMaximumLinkedListLength nodes, then ASSERT().
  2410. If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
  2411. @param List A pointer to the head node of a doubly linked list.
  2412. @param Node A pointer to a node in the doubly linked list.
  2413. @return The pointer to the previous node if one exists. Otherwise List is returned.
  2414. **/
  2415. LIST_ENTRY *
  2416. EFIAPI
  2417. GetPreviousNode (
  2418. IN CONST LIST_ENTRY *List,
  2419. IN CONST LIST_ENTRY *Node
  2420. );
  2421. /**
  2422. Checks to see if a doubly linked list is empty or not.
  2423. Checks to see if the doubly linked list is empty. If the linked list contains
  2424. zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
  2425. If ListHead is NULL, then ASSERT().
  2426. If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
  2427. InitializeListHead(), then ASSERT().
  2428. If PcdMaximumLinkedListLength is not zero, and the number of nodes
  2429. in List, including the List node, is greater than or equal to
  2430. PcdMaximumLinkedListLength, then ASSERT().
  2431. @param ListHead A pointer to the head node of a doubly linked list.
  2432. @retval TRUE The linked list is empty.
  2433. @retval FALSE The linked list is not empty.
  2434. **/
  2435. BOOLEAN
  2436. EFIAPI
  2437. IsListEmpty (
  2438. IN CONST LIST_ENTRY *ListHead
  2439. );
  2440. /**
  2441. Determines if a node in a doubly linked list is the head node of a the same
  2442. doubly linked list. This function is typically used to terminate a loop that
  2443. traverses all the nodes in a doubly linked list starting with the head node.
  2444. Returns TRUE if Node is equal to List. Returns FALSE if Node is one of the
  2445. nodes in the doubly linked list specified by List. List must have been
  2446. initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
  2447. If List is NULL, then ASSERT().
  2448. If Node is NULL, then ASSERT().
  2449. If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(),
  2450. then ASSERT().
  2451. If PcdMaximumLinkedListLength is not zero, and the number of nodes
  2452. in List, including the List node, is greater than or equal to
  2453. PcdMaximumLinkedListLength, then ASSERT().
  2454. If PcdVerifyNodeInList is TRUE and Node is not a node in List the and Node is not equal
  2455. to List, then ASSERT().
  2456. @param List A pointer to the head node of a doubly linked list.
  2457. @param Node A pointer to a node in the doubly linked list.
  2458. @retval TRUE Node is the head of the doubly-linked list pointed by List.
  2459. @retval FALSE Node is not the head of the doubly-linked list pointed by List.
  2460. **/
  2461. BOOLEAN
  2462. EFIAPI
  2463. IsNull (
  2464. IN CONST LIST_ENTRY *List,
  2465. IN CONST LIST_ENTRY *Node
  2466. );
  2467. /**
  2468. Determines if a node the last node in a doubly linked list.
  2469. Returns TRUE if Node is the last node in the doubly linked list specified by
  2470. List. Otherwise, FALSE is returned. List must have been initialized with
  2471. INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
  2472. If List is NULL, then ASSERT().
  2473. If Node is NULL, then ASSERT().
  2474. If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
  2475. InitializeListHead(), then ASSERT().
  2476. If PcdMaximumLinkedListLength is not zero, and the number of nodes
  2477. in List, including the List node, is greater than or equal to
  2478. PcdMaximumLinkedListLength, then ASSERT().
  2479. If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
  2480. @param List A pointer to the head node of a doubly linked list.
  2481. @param Node A pointer to a node in the doubly linked list.
  2482. @retval TRUE Node is the last node in the linked list.
  2483. @retval FALSE Node is not the last node in the linked list.
  2484. **/
  2485. BOOLEAN
  2486. EFIAPI
  2487. IsNodeAtEnd (
  2488. IN CONST LIST_ENTRY *List,
  2489. IN CONST LIST_ENTRY *Node
  2490. );
  2491. /**
  2492. Swaps the location of two nodes in a doubly linked list, and returns the
  2493. first node after the swap.
  2494. If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
  2495. Otherwise, the location of the FirstEntry node is swapped with the location
  2496. of the SecondEntry node in a doubly linked list. SecondEntry must be in the
  2497. same double linked list as FirstEntry and that double linked list must have
  2498. been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
  2499. SecondEntry is returned after the nodes are swapped.
  2500. If FirstEntry is NULL, then ASSERT().
  2501. If SecondEntry is NULL, then ASSERT().
  2502. If PcdVerifyNodeInList is TRUE and SecondEntry and FirstEntry are not in the
  2503. same linked list, then ASSERT().
  2504. If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
  2505. linked list containing the FirstEntry and SecondEntry nodes, including
  2506. the FirstEntry and SecondEntry nodes, is greater than or equal to
  2507. PcdMaximumLinkedListLength, then ASSERT().
  2508. @param FirstEntry A pointer to a node in a linked list.
  2509. @param SecondEntry A pointer to another node in the same linked list.
  2510. @return SecondEntry.
  2511. **/
  2512. LIST_ENTRY *
  2513. EFIAPI
  2514. SwapListEntries (
  2515. IN OUT LIST_ENTRY *FirstEntry,
  2516. IN OUT LIST_ENTRY *SecondEntry
  2517. );
  2518. /**
  2519. Removes a node from a doubly linked list, and returns the node that follows
  2520. the removed node.
  2521. Removes the node Entry from a doubly linked list. It is up to the caller of
  2522. this function to release the memory used by this node if that is required. On
  2523. exit, the node following Entry in the doubly linked list is returned. If
  2524. Entry is the only node in the linked list, then the head node of the linked
  2525. list is returned.
  2526. If Entry is NULL, then ASSERT().
  2527. If Entry is the head node of an empty list, then ASSERT().
  2528. If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
  2529. linked list containing Entry, including the Entry node, is greater than
  2530. or equal to PcdMaximumLinkedListLength, then ASSERT().
  2531. @param Entry A pointer to a node in a linked list.
  2532. @return Entry.
  2533. **/
  2534. LIST_ENTRY *
  2535. EFIAPI
  2536. RemoveEntryList (
  2537. IN CONST LIST_ENTRY *Entry
  2538. );
  2539. //
  2540. // Math Services
  2541. //
  2542. /**
  2543. Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
  2544. with zeros. The shifted value is returned.
  2545. This function shifts the 64-bit value Operand to the left by Count bits. The
  2546. low Count bits are set to zero. The shifted value is returned.
  2547. If Count is greater than 63, then ASSERT().
  2548. @param Operand The 64-bit operand to shift left.
  2549. @param Count The number of bits to shift left.
  2550. @return Operand << Count.
  2551. **/
  2552. UINT64
  2553. EFIAPI
  2554. LShiftU64 (
  2555. IN UINT64 Operand,
  2556. IN UINTN Count
  2557. );
  2558. /**
  2559. Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
  2560. filled with zeros. The shifted value is returned.
  2561. This function shifts the 64-bit value Operand to the right by Count bits. The
  2562. high Count bits are set to zero. The shifted value is returned.
  2563. If Count is greater than 63, then ASSERT().
  2564. @param Operand The 64-bit operand to shift right.
  2565. @param Count The number of bits to shift right.
  2566. @return Operand >> Count
  2567. **/
  2568. UINT64
  2569. EFIAPI
  2570. RShiftU64 (
  2571. IN UINT64 Operand,
  2572. IN UINTN Count
  2573. );
  2574. /**
  2575. Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
  2576. with original integer's bit 63. The shifted value is returned.
  2577. This function shifts the 64-bit value Operand to the right by Count bits. The
  2578. high Count bits are set to bit 63 of Operand. The shifted value is returned.
  2579. If Count is greater than 63, then ASSERT().
  2580. @param Operand The 64-bit operand to shift right.
  2581. @param Count The number of bits to shift right.
  2582. @return Operand >> Count
  2583. **/
  2584. UINT64
  2585. EFIAPI
  2586. ARShiftU64 (
  2587. IN UINT64 Operand,
  2588. IN UINTN Count
  2589. );
  2590. /**
  2591. Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
  2592. with the high bits that were rotated.
  2593. This function rotates the 32-bit value Operand to the left by Count bits. The
  2594. low Count bits are fill with the high Count bits of Operand. The rotated
  2595. value is returned.
  2596. If Count is greater than 31, then ASSERT().
  2597. @param Operand The 32-bit operand to rotate left.
  2598. @param Count The number of bits to rotate left.
  2599. @return Operand << Count
  2600. **/
  2601. UINT32
  2602. EFIAPI
  2603. LRotU32 (
  2604. IN UINT32 Operand,
  2605. IN UINTN Count
  2606. );
  2607. /**
  2608. Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
  2609. with the low bits that were rotated.
  2610. This function rotates the 32-bit value Operand to the right by Count bits.
  2611. The high Count bits are fill with the low Count bits of Operand. The rotated
  2612. value is returned.
  2613. If Count is greater than 31, then ASSERT().
  2614. @param Operand The 32-bit operand to rotate right.
  2615. @param Count The number of bits to rotate right.
  2616. @return Operand >> Count
  2617. **/
  2618. UINT32
  2619. EFIAPI
  2620. RRotU32 (
  2621. IN UINT32 Operand,
  2622. IN UINTN Count
  2623. );
  2624. /**
  2625. Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
  2626. with the high bits that were rotated.
  2627. This function rotates the 64-bit value Operand to the left by Count bits. The
  2628. low Count bits are fill with the high Count bits of Operand. The rotated
  2629. value is returned.
  2630. If Count is greater than 63, then ASSERT().
  2631. @param Operand The 64-bit operand to rotate left.
  2632. @param Count The number of bits to rotate left.
  2633. @return Operand << Count
  2634. **/
  2635. UINT64
  2636. EFIAPI
  2637. LRotU64 (
  2638. IN UINT64 Operand,
  2639. IN UINTN Count
  2640. );
  2641. /**
  2642. Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
  2643. with the high low bits that were rotated.
  2644. This function rotates the 64-bit value Operand to the right by Count bits.
  2645. The high Count bits are fill with the low Count bits of Operand. The rotated
  2646. value is returned.
  2647. If Count is greater than 63, then ASSERT().
  2648. @param Operand The 64-bit operand to rotate right.
  2649. @param Count The number of bits to rotate right.
  2650. @return Operand >> Count
  2651. **/
  2652. UINT64
  2653. EFIAPI
  2654. RRotU64 (
  2655. IN UINT64 Operand,
  2656. IN UINTN Count
  2657. );
  2658. /**
  2659. Returns the bit position of the lowest bit set in a 32-bit value.
  2660. This function computes the bit position of the lowest bit set in the 32-bit
  2661. value specified by Operand. If Operand is zero, then -1 is returned.
  2662. Otherwise, a value between 0 and 31 is returned.
  2663. @param Operand The 32-bit operand to evaluate.
  2664. @retval 0..31 The lowest bit set in Operand was found.
  2665. @retval -1 Operand is zero.
  2666. **/
  2667. INTN
  2668. EFIAPI
  2669. LowBitSet32 (
  2670. IN UINT32 Operand
  2671. );
  2672. /**
  2673. Returns the bit position of the lowest bit set in a 64-bit value.
  2674. This function computes the bit position of the lowest bit set in the 64-bit
  2675. value specified by Operand. If Operand is zero, then -1 is returned.
  2676. Otherwise, a value between 0 and 63 is returned.
  2677. @param Operand The 64-bit operand to evaluate.
  2678. @retval 0..63 The lowest bit set in Operand was found.
  2679. @retval -1 Operand is zero.
  2680. **/
  2681. INTN
  2682. EFIAPI
  2683. LowBitSet64 (
  2684. IN UINT64 Operand
  2685. );
  2686. /**
  2687. Returns the bit position of the highest bit set in a 32-bit value. Equivalent
  2688. to log2(x).
  2689. This function computes the bit position of the highest bit set in the 32-bit
  2690. value specified by Operand. If Operand is zero, then -1 is returned.
  2691. Otherwise, a value between 0 and 31 is returned.
  2692. @param Operand The 32-bit operand to evaluate.
  2693. @retval 0..31 Position of the highest bit set in Operand if found.
  2694. @retval -1 Operand is zero.
  2695. **/
  2696. INTN
  2697. EFIAPI
  2698. HighBitSet32 (
  2699. IN UINT32 Operand
  2700. );
  2701. /**
  2702. Returns the bit position of the highest bit set in a 64-bit value. Equivalent
  2703. to log2(x).
  2704. This function computes the bit position of the highest bit set in the 64-bit
  2705. value specified by Operand. If Operand is zero, then -1 is returned.
  2706. Otherwise, a value between 0 and 63 is returned.
  2707. @param Operand The 64-bit operand to evaluate.
  2708. @retval 0..63 Position of the highest bit set in Operand if found.
  2709. @retval -1 Operand is zero.
  2710. **/
  2711. INTN
  2712. EFIAPI
  2713. HighBitSet64 (
  2714. IN UINT64 Operand
  2715. );
  2716. /**
  2717. Returns the value of the highest bit set in a 32-bit value. Equivalent to
  2718. 1 << log2(x).
  2719. This function computes the value of the highest bit set in the 32-bit value
  2720. specified by Operand. If Operand is zero, then zero is returned.
  2721. @param Operand The 32-bit operand to evaluate.
  2722. @return 1 << HighBitSet32(Operand)
  2723. @retval 0 Operand is zero.
  2724. **/
  2725. UINT32
  2726. EFIAPI
  2727. GetPowerOfTwo32 (
  2728. IN UINT32 Operand
  2729. );
  2730. /**
  2731. Returns the value of the highest bit set in a 64-bit value. Equivalent to
  2732. 1 << log2(x).
  2733. This function computes the value of the highest bit set in the 64-bit value
  2734. specified by Operand. If Operand is zero, then zero is returned.
  2735. @param Operand The 64-bit operand to evaluate.
  2736. @return 1 << HighBitSet64(Operand)
  2737. @retval 0 Operand is zero.
  2738. **/
  2739. UINT64
  2740. EFIAPI
  2741. GetPowerOfTwo64 (
  2742. IN UINT64 Operand
  2743. );
  2744. /**
  2745. Switches the endianness of a 16-bit integer.
  2746. This function swaps the bytes in a 16-bit unsigned value to switch the value
  2747. from little endian to big endian or vice versa. The byte swapped value is
  2748. returned.
  2749. @param Value A 16-bit unsigned value.
  2750. @return The byte swapped Value.
  2751. **/
  2752. UINT16
  2753. EFIAPI
  2754. SwapBytes16 (
  2755. IN UINT16 Value
  2756. );
  2757. /**
  2758. Switches the endianness of a 32-bit integer.
  2759. This function swaps the bytes in a 32-bit unsigned value to switch the value
  2760. from little endian to big endian or vice versa. The byte swapped value is
  2761. returned.
  2762. @param Value A 32-bit unsigned value.
  2763. @return The byte swapped Value.
  2764. **/
  2765. UINT32
  2766. EFIAPI
  2767. SwapBytes32 (
  2768. IN UINT32 Value
  2769. );
  2770. /**
  2771. Switches the endianness of a 64-bit integer.
  2772. This function swaps the bytes in a 64-bit unsigned value to switch the value
  2773. from little endian to big endian or vice versa. The byte swapped value is
  2774. returned.
  2775. @param Value A 64-bit unsigned value.
  2776. @return The byte swapped Value.
  2777. **/
  2778. UINT64
  2779. EFIAPI
  2780. SwapBytes64 (
  2781. IN UINT64 Value
  2782. );
  2783. /**
  2784. Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
  2785. generates a 64-bit unsigned result.
  2786. This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
  2787. unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
  2788. bit unsigned result is returned.
  2789. @param Multiplicand A 64-bit unsigned value.
  2790. @param Multiplier A 32-bit unsigned value.
  2791. @return Multiplicand * Multiplier
  2792. **/
  2793. UINT64
  2794. EFIAPI
  2795. MultU64x32 (
  2796. IN UINT64 Multiplicand,
  2797. IN UINT32 Multiplier
  2798. );
  2799. /**
  2800. Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
  2801. generates a 64-bit unsigned result.
  2802. This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
  2803. unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
  2804. bit unsigned result is returned.
  2805. @param Multiplicand A 64-bit unsigned value.
  2806. @param Multiplier A 64-bit unsigned value.
  2807. @return Multiplicand * Multiplier.
  2808. **/
  2809. UINT64
  2810. EFIAPI
  2811. MultU64x64 (
  2812. IN UINT64 Multiplicand,
  2813. IN UINT64 Multiplier
  2814. );
  2815. /**
  2816. Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
  2817. 64-bit signed result.
  2818. This function multiples the 64-bit signed value Multiplicand by the 64-bit
  2819. signed value Multiplier and generates a 64-bit signed result. This 64-bit
  2820. signed result is returned.
  2821. @param Multiplicand A 64-bit signed value.
  2822. @param Multiplier A 64-bit signed value.
  2823. @return Multiplicand * Multiplier
  2824. **/
  2825. INT64
  2826. EFIAPI
  2827. MultS64x64 (
  2828. IN INT64 Multiplicand,
  2829. IN INT64 Multiplier
  2830. );
  2831. /**
  2832. Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
  2833. a 64-bit unsigned result.
  2834. This function divides the 64-bit unsigned value Dividend by the 32-bit
  2835. unsigned value Divisor and generates a 64-bit unsigned quotient. This
  2836. function returns the 64-bit unsigned quotient.
  2837. If Divisor is 0, then ASSERT().
  2838. @param Dividend A 64-bit unsigned value.
  2839. @param Divisor A 32-bit unsigned value.
  2840. @return Dividend / Divisor.
  2841. **/
  2842. UINT64
  2843. EFIAPI
  2844. DivU64x32 (
  2845. IN UINT64 Dividend,
  2846. IN UINT32 Divisor
  2847. );
  2848. /**
  2849. Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
  2850. a 32-bit unsigned remainder.
  2851. This function divides the 64-bit unsigned value Dividend by the 32-bit
  2852. unsigned value Divisor and generates a 32-bit remainder. This function
  2853. returns the 32-bit unsigned remainder.
  2854. If Divisor is 0, then ASSERT().
  2855. @param Dividend A 64-bit unsigned value.
  2856. @param Divisor A 32-bit unsigned value.
  2857. @return Dividend % Divisor.
  2858. **/
  2859. UINT32
  2860. EFIAPI
  2861. ModU64x32 (
  2862. IN UINT64 Dividend,
  2863. IN UINT32 Divisor
  2864. );
  2865. /**
  2866. Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
  2867. a 64-bit unsigned result and an optional 32-bit unsigned remainder.
  2868. This function divides the 64-bit unsigned value Dividend by the 32-bit
  2869. unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
  2870. is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
  2871. This function returns the 64-bit unsigned quotient.
  2872. If Divisor is 0, then ASSERT().
  2873. @param Dividend A 64-bit unsigned value.
  2874. @param Divisor A 32-bit unsigned value.
  2875. @param Remainder A pointer to a 32-bit unsigned value. This parameter is
  2876. optional and may be NULL.
  2877. @return Dividend / Divisor.
  2878. **/
  2879. UINT64
  2880. EFIAPI
  2881. DivU64x32Remainder (
  2882. IN UINT64 Dividend,
  2883. IN UINT32 Divisor,
  2884. OUT UINT32 *Remainder OPTIONAL
  2885. );
  2886. /**
  2887. Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
  2888. a 64-bit unsigned result and an optional 64-bit unsigned remainder.
  2889. This function divides the 64-bit unsigned value Dividend by the 64-bit
  2890. unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
  2891. is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
  2892. This function returns the 64-bit unsigned quotient.
  2893. If Divisor is 0, then ASSERT().
  2894. @param Dividend A 64-bit unsigned value.
  2895. @param Divisor A 64-bit unsigned value.
  2896. @param Remainder A pointer to a 64-bit unsigned value. This parameter is
  2897. optional and may be NULL.
  2898. @return Dividend / Divisor.
  2899. **/
  2900. UINT64
  2901. EFIAPI
  2902. DivU64x64Remainder (
  2903. IN UINT64 Dividend,
  2904. IN UINT64 Divisor,
  2905. OUT UINT64 *Remainder OPTIONAL
  2906. );
  2907. /**
  2908. Divides a 64-bit signed integer by a 64-bit signed integer and generates a
  2909. 64-bit signed result and a optional 64-bit signed remainder.
  2910. This function divides the 64-bit signed value Dividend by the 64-bit signed
  2911. value Divisor and generates a 64-bit signed quotient. If Remainder is not
  2912. NULL, then the 64-bit signed remainder is returned in Remainder. This
  2913. function returns the 64-bit signed quotient.
  2914. It is the caller's responsibility to not call this function with a Divisor of 0.
  2915. If Divisor is 0, then the quotient and remainder should be assumed to be
  2916. the largest negative integer.
  2917. If Divisor is 0, then ASSERT().
  2918. @param Dividend A 64-bit signed value.
  2919. @param Divisor A 64-bit signed value.
  2920. @param Remainder A pointer to a 64-bit signed value. This parameter is
  2921. optional and may be NULL.
  2922. @return Dividend / Divisor.
  2923. **/
  2924. INT64
  2925. EFIAPI
  2926. DivS64x64Remainder (
  2927. IN INT64 Dividend,
  2928. IN INT64 Divisor,
  2929. OUT INT64 *Remainder OPTIONAL
  2930. );
  2931. /**
  2932. Reads a 16-bit value from memory that may be unaligned.
  2933. This function returns the 16-bit value pointed to by Buffer. The function
  2934. guarantees that the read operation does not produce an alignment fault.
  2935. If the Buffer is NULL, then ASSERT().
  2936. @param Buffer The pointer to a 16-bit value that may be unaligned.
  2937. @return The 16-bit value read from Buffer.
  2938. **/
  2939. UINT16
  2940. EFIAPI
  2941. ReadUnaligned16 (
  2942. IN CONST UINT16 *Buffer
  2943. );
  2944. /**
  2945. Writes a 16-bit value to memory that may be unaligned.
  2946. This function writes the 16-bit value specified by Value to Buffer. Value is
  2947. returned. The function guarantees that the write operation does not produce
  2948. an alignment fault.
  2949. If the Buffer is NULL, then ASSERT().
  2950. @param Buffer The pointer to a 16-bit value that may be unaligned.
  2951. @param Value 16-bit value to write to Buffer.
  2952. @return The 16-bit value to write to Buffer.
  2953. **/
  2954. UINT16
  2955. EFIAPI
  2956. WriteUnaligned16 (
  2957. OUT UINT16 *Buffer,
  2958. IN UINT16 Value
  2959. );
  2960. /**
  2961. Reads a 24-bit value from memory that may be unaligned.
  2962. This function returns the 24-bit value pointed to by Buffer. The function
  2963. guarantees that the read operation does not produce an alignment fault.
  2964. If the Buffer is NULL, then ASSERT().
  2965. @param Buffer The pointer to a 24-bit value that may be unaligned.
  2966. @return The 24-bit value read from Buffer.
  2967. **/
  2968. UINT32
  2969. EFIAPI
  2970. ReadUnaligned24 (
  2971. IN CONST UINT32 *Buffer
  2972. );
  2973. /**
  2974. Writes a 24-bit value to memory that may be unaligned.
  2975. This function writes the 24-bit value specified by Value to Buffer. Value is
  2976. returned. The function guarantees that the write operation does not produce
  2977. an alignment fault.
  2978. If the Buffer is NULL, then ASSERT().
  2979. @param Buffer The pointer to a 24-bit value that may be unaligned.
  2980. @param Value 24-bit value to write to Buffer.
  2981. @return The 24-bit value to write to Buffer.
  2982. **/
  2983. UINT32
  2984. EFIAPI
  2985. WriteUnaligned24 (
  2986. OUT UINT32 *Buffer,
  2987. IN UINT32 Value
  2988. );
  2989. /**
  2990. Reads a 32-bit value from memory that may be unaligned.
  2991. This function returns the 32-bit value pointed to by Buffer. The function
  2992. guarantees that the read operation does not produce an alignment fault.
  2993. If the Buffer is NULL, then ASSERT().
  2994. @param Buffer The pointer to a 32-bit value that may be unaligned.
  2995. @return The 32-bit value read from Buffer.
  2996. **/
  2997. UINT32
  2998. EFIAPI
  2999. ReadUnaligned32 (
  3000. IN CONST UINT32 *Buffer
  3001. );
  3002. /**
  3003. Writes a 32-bit value to memory that may be unaligned.
  3004. This function writes the 32-bit value specified by Value to Buffer. Value is
  3005. returned. The function guarantees that the write operation does not produce
  3006. an alignment fault.
  3007. If the Buffer is NULL, then ASSERT().
  3008. @param Buffer The pointer to a 32-bit value that may be unaligned.
  3009. @param Value 32-bit value to write to Buffer.
  3010. @return The 32-bit value to write to Buffer.
  3011. **/
  3012. UINT32
  3013. EFIAPI
  3014. WriteUnaligned32 (
  3015. OUT UINT32 *Buffer,
  3016. IN UINT32 Value
  3017. );
  3018. /**
  3019. Reads a 64-bit value from memory that may be unaligned.
  3020. This function returns the 64-bit value pointed to by Buffer. The function
  3021. guarantees that the read operation does not produce an alignment fault.
  3022. If the Buffer is NULL, then ASSERT().
  3023. @param Buffer The pointer to a 64-bit value that may be unaligned.
  3024. @return The 64-bit value read from Buffer.
  3025. **/
  3026. UINT64
  3027. EFIAPI
  3028. ReadUnaligned64 (
  3029. IN CONST UINT64 *Buffer
  3030. );
  3031. /**
  3032. Writes a 64-bit value to memory that may be unaligned.
  3033. This function writes the 64-bit value specified by Value to Buffer. Value is
  3034. returned. The function guarantees that the write operation does not produce
  3035. an alignment fault.
  3036. If the Buffer is NULL, then ASSERT().
  3037. @param Buffer The pointer to a 64-bit value that may be unaligned.
  3038. @param Value 64-bit value to write to Buffer.
  3039. @return The 64-bit value to write to Buffer.
  3040. **/
  3041. UINT64
  3042. EFIAPI
  3043. WriteUnaligned64 (
  3044. OUT UINT64 *Buffer,
  3045. IN UINT64 Value
  3046. );
  3047. //
  3048. // Bit Field Functions
  3049. //
  3050. /**
  3051. Returns a bit field from an 8-bit value.
  3052. Returns the bitfield specified by the StartBit and the EndBit from Operand.
  3053. If 8-bit operations are not supported, then ASSERT().
  3054. If StartBit is greater than 7, then ASSERT().
  3055. If EndBit is greater than 7, then ASSERT().
  3056. If EndBit is less than StartBit, then ASSERT().
  3057. @param Operand Operand on which to perform the bitfield operation.
  3058. @param StartBit The ordinal of the least significant bit in the bit field.
  3059. Range 0..7.
  3060. @param EndBit The ordinal of the most significant bit in the bit field.
  3061. Range 0..7.
  3062. @return The bit field read.
  3063. **/
  3064. UINT8
  3065. EFIAPI
  3066. BitFieldRead8 (
  3067. IN UINT8 Operand,
  3068. IN UINTN StartBit,
  3069. IN UINTN EndBit
  3070. );
  3071. /**
  3072. Writes a bit field to an 8-bit value, and returns the result.
  3073. Writes Value to the bit field specified by the StartBit and the EndBit in
  3074. Operand. All other bits in Operand are preserved. The new 8-bit value is
  3075. returned.
  3076. If 8-bit operations are not supported, then ASSERT().
  3077. If StartBit is greater than 7, then ASSERT().
  3078. If EndBit is greater than 7, then ASSERT().
  3079. If EndBit is less than StartBit, then ASSERT().
  3080. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3081. @param Operand Operand on which to perform the bitfield operation.
  3082. @param StartBit The ordinal of the least significant bit in the bit field.
  3083. Range 0..7.
  3084. @param EndBit The ordinal of the most significant bit in the bit field.
  3085. Range 0..7.
  3086. @param Value New value of the bit field.
  3087. @return The new 8-bit value.
  3088. **/
  3089. UINT8
  3090. EFIAPI
  3091. BitFieldWrite8 (
  3092. IN UINT8 Operand,
  3093. IN UINTN StartBit,
  3094. IN UINTN EndBit,
  3095. IN UINT8 Value
  3096. );
  3097. /**
  3098. Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
  3099. result.
  3100. Performs a bitwise OR between the bit field specified by StartBit
  3101. and EndBit in Operand and the value specified by OrData. All other bits in
  3102. Operand are preserved. The new 8-bit value is returned.
  3103. If 8-bit operations are not supported, then ASSERT().
  3104. If StartBit is greater than 7, then ASSERT().
  3105. If EndBit is greater than 7, then ASSERT().
  3106. If EndBit is less than StartBit, then ASSERT().
  3107. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3108. @param Operand Operand on which to perform the bitfield operation.
  3109. @param StartBit The ordinal of the least significant bit in the bit field.
  3110. Range 0..7.
  3111. @param EndBit The ordinal of the most significant bit in the bit field.
  3112. Range 0..7.
  3113. @param OrData The value to OR with the read value from the value
  3114. @return The new 8-bit value.
  3115. **/
  3116. UINT8
  3117. EFIAPI
  3118. BitFieldOr8 (
  3119. IN UINT8 Operand,
  3120. IN UINTN StartBit,
  3121. IN UINTN EndBit,
  3122. IN UINT8 OrData
  3123. );
  3124. /**
  3125. Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
  3126. the result.
  3127. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3128. in Operand and the value specified by AndData. All other bits in Operand are
  3129. preserved. The new 8-bit value is returned.
  3130. If 8-bit operations are not supported, then ASSERT().
  3131. If StartBit is greater than 7, then ASSERT().
  3132. If EndBit is greater than 7, then ASSERT().
  3133. If EndBit is less than StartBit, then ASSERT().
  3134. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3135. @param Operand Operand on which to perform the bitfield operation.
  3136. @param StartBit The ordinal of the least significant bit in the bit field.
  3137. Range 0..7.
  3138. @param EndBit The ordinal of the most significant bit in the bit field.
  3139. Range 0..7.
  3140. @param AndData The value to AND with the read value from the value.
  3141. @return The new 8-bit value.
  3142. **/
  3143. UINT8
  3144. EFIAPI
  3145. BitFieldAnd8 (
  3146. IN UINT8 Operand,
  3147. IN UINTN StartBit,
  3148. IN UINTN EndBit,
  3149. IN UINT8 AndData
  3150. );
  3151. /**
  3152. Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
  3153. bitwise OR, and returns the result.
  3154. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3155. in Operand and the value specified by AndData, followed by a bitwise
  3156. OR with value specified by OrData. All other bits in Operand are
  3157. preserved. The new 8-bit value is returned.
  3158. If 8-bit operations are not supported, then ASSERT().
  3159. If StartBit is greater than 7, then ASSERT().
  3160. If EndBit is greater than 7, then ASSERT().
  3161. If EndBit is less than StartBit, then ASSERT().
  3162. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3163. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3164. @param Operand Operand on which to perform the bitfield operation.
  3165. @param StartBit The ordinal of the least significant bit in the bit field.
  3166. Range 0..7.
  3167. @param EndBit The ordinal of the most significant bit in the bit field.
  3168. Range 0..7.
  3169. @param AndData The value to AND with the read value from the value.
  3170. @param OrData The value to OR with the result of the AND operation.
  3171. @return The new 8-bit value.
  3172. **/
  3173. UINT8
  3174. EFIAPI
  3175. BitFieldAndThenOr8 (
  3176. IN UINT8 Operand,
  3177. IN UINTN StartBit,
  3178. IN UINTN EndBit,
  3179. IN UINT8 AndData,
  3180. IN UINT8 OrData
  3181. );
  3182. /**
  3183. Returns a bit field from a 16-bit value.
  3184. Returns the bitfield specified by the StartBit and the EndBit from Operand.
  3185. If 16-bit operations are not supported, then ASSERT().
  3186. If StartBit is greater than 15, then ASSERT().
  3187. If EndBit is greater than 15, then ASSERT().
  3188. If EndBit is less than StartBit, then ASSERT().
  3189. @param Operand Operand on which to perform the bitfield operation.
  3190. @param StartBit The ordinal of the least significant bit in the bit field.
  3191. Range 0..15.
  3192. @param EndBit The ordinal of the most significant bit in the bit field.
  3193. Range 0..15.
  3194. @return The bit field read.
  3195. **/
  3196. UINT16
  3197. EFIAPI
  3198. BitFieldRead16 (
  3199. IN UINT16 Operand,
  3200. IN UINTN StartBit,
  3201. IN UINTN EndBit
  3202. );
  3203. /**
  3204. Writes a bit field to a 16-bit value, and returns the result.
  3205. Writes Value to the bit field specified by the StartBit and the EndBit in
  3206. Operand. All other bits in Operand are preserved. The new 16-bit value is
  3207. returned.
  3208. If 16-bit operations are not supported, then ASSERT().
  3209. If StartBit is greater than 15, then ASSERT().
  3210. If EndBit is greater than 15, then ASSERT().
  3211. If EndBit is less than StartBit, then ASSERT().
  3212. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3213. @param Operand Operand on which to perform the bitfield operation.
  3214. @param StartBit The ordinal of the least significant bit in the bit field.
  3215. Range 0..15.
  3216. @param EndBit The ordinal of the most significant bit in the bit field.
  3217. Range 0..15.
  3218. @param Value New value of the bit field.
  3219. @return The new 16-bit value.
  3220. **/
  3221. UINT16
  3222. EFIAPI
  3223. BitFieldWrite16 (
  3224. IN UINT16 Operand,
  3225. IN UINTN StartBit,
  3226. IN UINTN EndBit,
  3227. IN UINT16 Value
  3228. );
  3229. /**
  3230. Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
  3231. result.
  3232. Performs a bitwise OR between the bit field specified by StartBit
  3233. and EndBit in Operand and the value specified by OrData. All other bits in
  3234. Operand are preserved. The new 16-bit value is returned.
  3235. If 16-bit operations are not supported, then ASSERT().
  3236. If StartBit is greater than 15, then ASSERT().
  3237. If EndBit is greater than 15, then ASSERT().
  3238. If EndBit is less than StartBit, then ASSERT().
  3239. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3240. @param Operand Operand on which to perform the bitfield operation.
  3241. @param StartBit The ordinal of the least significant bit in the bit field.
  3242. Range 0..15.
  3243. @param EndBit The ordinal of the most significant bit in the bit field.
  3244. Range 0..15.
  3245. @param OrData The value to OR with the read value from the value
  3246. @return The new 16-bit value.
  3247. **/
  3248. UINT16
  3249. EFIAPI
  3250. BitFieldOr16 (
  3251. IN UINT16 Operand,
  3252. IN UINTN StartBit,
  3253. IN UINTN EndBit,
  3254. IN UINT16 OrData
  3255. );
  3256. /**
  3257. Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
  3258. the result.
  3259. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3260. in Operand and the value specified by AndData. All other bits in Operand are
  3261. preserved. The new 16-bit value is returned.
  3262. If 16-bit operations are not supported, then ASSERT().
  3263. If StartBit is greater than 15, then ASSERT().
  3264. If EndBit is greater than 15, then ASSERT().
  3265. If EndBit is less than StartBit, then ASSERT().
  3266. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3267. @param Operand Operand on which to perform the bitfield operation.
  3268. @param StartBit The ordinal of the least significant bit in the bit field.
  3269. Range 0..15.
  3270. @param EndBit The ordinal of the most significant bit in the bit field.
  3271. Range 0..15.
  3272. @param AndData The value to AND with the read value from the value
  3273. @return The new 16-bit value.
  3274. **/
  3275. UINT16
  3276. EFIAPI
  3277. BitFieldAnd16 (
  3278. IN UINT16 Operand,
  3279. IN UINTN StartBit,
  3280. IN UINTN EndBit,
  3281. IN UINT16 AndData
  3282. );
  3283. /**
  3284. Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
  3285. bitwise OR, and returns the result.
  3286. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3287. in Operand and the value specified by AndData, followed by a bitwise
  3288. OR with value specified by OrData. All other bits in Operand are
  3289. preserved. The new 16-bit value is returned.
  3290. If 16-bit operations are not supported, then ASSERT().
  3291. If StartBit is greater than 15, then ASSERT().
  3292. If EndBit is greater than 15, then ASSERT().
  3293. If EndBit is less than StartBit, then ASSERT().
  3294. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3295. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3296. @param Operand Operand on which to perform the bitfield operation.
  3297. @param StartBit The ordinal of the least significant bit in the bit field.
  3298. Range 0..15.
  3299. @param EndBit The ordinal of the most significant bit in the bit field.
  3300. Range 0..15.
  3301. @param AndData The value to AND with the read value from the value.
  3302. @param OrData The value to OR with the result of the AND operation.
  3303. @return The new 16-bit value.
  3304. **/
  3305. UINT16
  3306. EFIAPI
  3307. BitFieldAndThenOr16 (
  3308. IN UINT16 Operand,
  3309. IN UINTN StartBit,
  3310. IN UINTN EndBit,
  3311. IN UINT16 AndData,
  3312. IN UINT16 OrData
  3313. );
  3314. /**
  3315. Returns a bit field from a 32-bit value.
  3316. Returns the bitfield specified by the StartBit and the EndBit from Operand.
  3317. If 32-bit operations are not supported, then ASSERT().
  3318. If StartBit is greater than 31, then ASSERT().
  3319. If EndBit is greater than 31, then ASSERT().
  3320. If EndBit is less than StartBit, then ASSERT().
  3321. @param Operand Operand on which to perform the bitfield operation.
  3322. @param StartBit The ordinal of the least significant bit in the bit field.
  3323. Range 0..31.
  3324. @param EndBit The ordinal of the most significant bit in the bit field.
  3325. Range 0..31.
  3326. @return The bit field read.
  3327. **/
  3328. UINT32
  3329. EFIAPI
  3330. BitFieldRead32 (
  3331. IN UINT32 Operand,
  3332. IN UINTN StartBit,
  3333. IN UINTN EndBit
  3334. );
  3335. /**
  3336. Writes a bit field to a 32-bit value, and returns the result.
  3337. Writes Value to the bit field specified by the StartBit and the EndBit in
  3338. Operand. All other bits in Operand are preserved. The new 32-bit value is
  3339. returned.
  3340. If 32-bit operations are not supported, then ASSERT().
  3341. If StartBit is greater than 31, then ASSERT().
  3342. If EndBit is greater than 31, then ASSERT().
  3343. If EndBit is less than StartBit, then ASSERT().
  3344. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3345. @param Operand Operand on which to perform the bitfield operation.
  3346. @param StartBit The ordinal of the least significant bit in the bit field.
  3347. Range 0..31.
  3348. @param EndBit The ordinal of the most significant bit in the bit field.
  3349. Range 0..31.
  3350. @param Value New value of the bit field.
  3351. @return The new 32-bit value.
  3352. **/
  3353. UINT32
  3354. EFIAPI
  3355. BitFieldWrite32 (
  3356. IN UINT32 Operand,
  3357. IN UINTN StartBit,
  3358. IN UINTN EndBit,
  3359. IN UINT32 Value
  3360. );
  3361. /**
  3362. Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
  3363. result.
  3364. Performs a bitwise OR between the bit field specified by StartBit
  3365. and EndBit in Operand and the value specified by OrData. All other bits in
  3366. Operand are preserved. The new 32-bit value is returned.
  3367. If 32-bit operations are not supported, then ASSERT().
  3368. If StartBit is greater than 31, then ASSERT().
  3369. If EndBit is greater than 31, then ASSERT().
  3370. If EndBit is less than StartBit, then ASSERT().
  3371. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3372. @param Operand Operand on which to perform the bitfield operation.
  3373. @param StartBit The ordinal of the least significant bit in the bit field.
  3374. Range 0..31.
  3375. @param EndBit The ordinal of the most significant bit in the bit field.
  3376. Range 0..31.
  3377. @param OrData The value to OR with the read value from the value.
  3378. @return The new 32-bit value.
  3379. **/
  3380. UINT32
  3381. EFIAPI
  3382. BitFieldOr32 (
  3383. IN UINT32 Operand,
  3384. IN UINTN StartBit,
  3385. IN UINTN EndBit,
  3386. IN UINT32 OrData
  3387. );
  3388. /**
  3389. Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
  3390. the result.
  3391. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3392. in Operand and the value specified by AndData. All other bits in Operand are
  3393. preserved. The new 32-bit value is returned.
  3394. If 32-bit operations are not supported, then ASSERT().
  3395. If StartBit is greater than 31, then ASSERT().
  3396. If EndBit is greater than 31, then ASSERT().
  3397. If EndBit is less than StartBit, then ASSERT().
  3398. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3399. @param Operand Operand on which to perform the bitfield operation.
  3400. @param StartBit The ordinal of the least significant bit in the bit field.
  3401. Range 0..31.
  3402. @param EndBit The ordinal of the most significant bit in the bit field.
  3403. Range 0..31.
  3404. @param AndData The value to AND with the read value from the value
  3405. @return The new 32-bit value.
  3406. **/
  3407. UINT32
  3408. EFIAPI
  3409. BitFieldAnd32 (
  3410. IN UINT32 Operand,
  3411. IN UINTN StartBit,
  3412. IN UINTN EndBit,
  3413. IN UINT32 AndData
  3414. );
  3415. /**
  3416. Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
  3417. bitwise OR, and returns the result.
  3418. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3419. in Operand and the value specified by AndData, followed by a bitwise
  3420. OR with value specified by OrData. All other bits in Operand are
  3421. preserved. The new 32-bit value is returned.
  3422. If 32-bit operations are not supported, then ASSERT().
  3423. If StartBit is greater than 31, then ASSERT().
  3424. If EndBit is greater than 31, then ASSERT().
  3425. If EndBit is less than StartBit, then ASSERT().
  3426. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3427. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3428. @param Operand Operand on which to perform the bitfield operation.
  3429. @param StartBit The ordinal of the least significant bit in the bit field.
  3430. Range 0..31.
  3431. @param EndBit The ordinal of the most significant bit in the bit field.
  3432. Range 0..31.
  3433. @param AndData The value to AND with the read value from the value.
  3434. @param OrData The value to OR with the result of the AND operation.
  3435. @return The new 32-bit value.
  3436. **/
  3437. UINT32
  3438. EFIAPI
  3439. BitFieldAndThenOr32 (
  3440. IN UINT32 Operand,
  3441. IN UINTN StartBit,
  3442. IN UINTN EndBit,
  3443. IN UINT32 AndData,
  3444. IN UINT32 OrData
  3445. );
  3446. /**
  3447. Returns a bit field from a 64-bit value.
  3448. Returns the bitfield specified by the StartBit and the EndBit from Operand.
  3449. If 64-bit operations are not supported, then ASSERT().
  3450. If StartBit is greater than 63, then ASSERT().
  3451. If EndBit is greater than 63, then ASSERT().
  3452. If EndBit is less than StartBit, then ASSERT().
  3453. @param Operand Operand on which to perform the bitfield operation.
  3454. @param StartBit The ordinal of the least significant bit in the bit field.
  3455. Range 0..63.
  3456. @param EndBit The ordinal of the most significant bit in the bit field.
  3457. Range 0..63.
  3458. @return The bit field read.
  3459. **/
  3460. UINT64
  3461. EFIAPI
  3462. BitFieldRead64 (
  3463. IN UINT64 Operand,
  3464. IN UINTN StartBit,
  3465. IN UINTN EndBit
  3466. );
  3467. /**
  3468. Writes a bit field to a 64-bit value, and returns the result.
  3469. Writes Value to the bit field specified by the StartBit and the EndBit in
  3470. Operand. All other bits in Operand are preserved. The new 64-bit value is
  3471. returned.
  3472. If 64-bit operations are not supported, then ASSERT().
  3473. If StartBit is greater than 63, then ASSERT().
  3474. If EndBit is greater than 63, then ASSERT().
  3475. If EndBit is less than StartBit, then ASSERT().
  3476. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3477. @param Operand Operand on which to perform the bitfield operation.
  3478. @param StartBit The ordinal of the least significant bit in the bit field.
  3479. Range 0..63.
  3480. @param EndBit The ordinal of the most significant bit in the bit field.
  3481. Range 0..63.
  3482. @param Value New value of the bit field.
  3483. @return The new 64-bit value.
  3484. **/
  3485. UINT64
  3486. EFIAPI
  3487. BitFieldWrite64 (
  3488. IN UINT64 Operand,
  3489. IN UINTN StartBit,
  3490. IN UINTN EndBit,
  3491. IN UINT64 Value
  3492. );
  3493. /**
  3494. Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
  3495. result.
  3496. Performs a bitwise OR between the bit field specified by StartBit
  3497. and EndBit in Operand and the value specified by OrData. All other bits in
  3498. Operand are preserved. The new 64-bit value is returned.
  3499. If 64-bit operations are not supported, then ASSERT().
  3500. If StartBit is greater than 63, then ASSERT().
  3501. If EndBit is greater than 63, then ASSERT().
  3502. If EndBit is less than StartBit, then ASSERT().
  3503. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3504. @param Operand Operand on which to perform the bitfield operation.
  3505. @param StartBit The ordinal of the least significant bit in the bit field.
  3506. Range 0..63.
  3507. @param EndBit The ordinal of the most significant bit in the bit field.
  3508. Range 0..63.
  3509. @param OrData The value to OR with the read value from the value
  3510. @return The new 64-bit value.
  3511. **/
  3512. UINT64
  3513. EFIAPI
  3514. BitFieldOr64 (
  3515. IN UINT64 Operand,
  3516. IN UINTN StartBit,
  3517. IN UINTN EndBit,
  3518. IN UINT64 OrData
  3519. );
  3520. /**
  3521. Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
  3522. the result.
  3523. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3524. in Operand and the value specified by AndData. All other bits in Operand are
  3525. preserved. The new 64-bit value is returned.
  3526. If 64-bit operations are not supported, then ASSERT().
  3527. If StartBit is greater than 63, then ASSERT().
  3528. If EndBit is greater than 63, then ASSERT().
  3529. If EndBit is less than StartBit, then ASSERT().
  3530. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3531. @param Operand Operand on which to perform the bitfield operation.
  3532. @param StartBit The ordinal of the least significant bit in the bit field.
  3533. Range 0..63.
  3534. @param EndBit The ordinal of the most significant bit in the bit field.
  3535. Range 0..63.
  3536. @param AndData The value to AND with the read value from the value
  3537. @return The new 64-bit value.
  3538. **/
  3539. UINT64
  3540. EFIAPI
  3541. BitFieldAnd64 (
  3542. IN UINT64 Operand,
  3543. IN UINTN StartBit,
  3544. IN UINTN EndBit,
  3545. IN UINT64 AndData
  3546. );
  3547. /**
  3548. Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
  3549. bitwise OR, and returns the result.
  3550. Performs a bitwise AND between the bit field specified by StartBit and EndBit
  3551. in Operand and the value specified by AndData, followed by a bitwise
  3552. OR with value specified by OrData. All other bits in Operand are
  3553. preserved. The new 64-bit value is returned.
  3554. If 64-bit operations are not supported, then ASSERT().
  3555. If StartBit is greater than 63, then ASSERT().
  3556. If EndBit is greater than 63, then ASSERT().
  3557. If EndBit is less than StartBit, then ASSERT().
  3558. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3559. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  3560. @param Operand Operand on which to perform the bitfield operation.
  3561. @param StartBit The ordinal of the least significant bit in the bit field.
  3562. Range 0..63.
  3563. @param EndBit The ordinal of the most significant bit in the bit field.
  3564. Range 0..63.
  3565. @param AndData The value to AND with the read value from the value.
  3566. @param OrData The value to OR with the result of the AND operation.
  3567. @return The new 64-bit value.
  3568. **/
  3569. UINT64
  3570. EFIAPI
  3571. BitFieldAndThenOr64 (
  3572. IN UINT64 Operand,
  3573. IN UINTN StartBit,
  3574. IN UINTN EndBit,
  3575. IN UINT64 AndData,
  3576. IN UINT64 OrData
  3577. );
  3578. //
  3579. // Base Library Checksum Functions
  3580. //
  3581. /**
  3582. Returns the sum of all elements in a buffer in unit of UINT8.
  3583. During calculation, the carry bits are dropped.
  3584. This function calculates the sum of all elements in a buffer
  3585. in unit of UINT8. The carry bits in result of addition are dropped.
  3586. The result is returned as UINT8. If Length is Zero, then Zero is
  3587. returned.
  3588. If Buffer is NULL, then ASSERT().
  3589. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3590. @param Buffer The pointer to the buffer to carry out the sum operation.
  3591. @param Length The size, in bytes, of Buffer.
  3592. @return Sum The sum of Buffer with carry bits dropped during additions.
  3593. **/
  3594. UINT8
  3595. EFIAPI
  3596. CalculateSum8 (
  3597. IN CONST UINT8 *Buffer,
  3598. IN UINTN Length
  3599. );
  3600. /**
  3601. Returns the two's complement checksum of all elements in a buffer
  3602. of 8-bit values.
  3603. This function first calculates the sum of the 8-bit values in the
  3604. buffer specified by Buffer and Length. The carry bits in the result
  3605. of addition are dropped. Then, the two's complement of the sum is
  3606. returned. If Length is 0, then 0 is returned.
  3607. If Buffer is NULL, then ASSERT().
  3608. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3609. @param Buffer The pointer to the buffer to carry out the checksum operation.
  3610. @param Length The size, in bytes, of Buffer.
  3611. @return Checksum The two's complement checksum of Buffer.
  3612. **/
  3613. UINT8
  3614. EFIAPI
  3615. CalculateCheckSum8 (
  3616. IN CONST UINT8 *Buffer,
  3617. IN UINTN Length
  3618. );
  3619. /**
  3620. Returns the sum of all elements in a buffer of 16-bit values. During
  3621. calculation, the carry bits are dropped.
  3622. This function calculates the sum of the 16-bit values in the buffer
  3623. specified by Buffer and Length. The carry bits in result of addition are dropped.
  3624. The 16-bit result is returned. If Length is 0, then 0 is returned.
  3625. If Buffer is NULL, then ASSERT().
  3626. If Buffer is not aligned on a 16-bit boundary, then ASSERT().
  3627. If Length is not aligned on a 16-bit boundary, then ASSERT().
  3628. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3629. @param Buffer The pointer to the buffer to carry out the sum operation.
  3630. @param Length The size, in bytes, of Buffer.
  3631. @return Sum The sum of Buffer with carry bits dropped during additions.
  3632. **/
  3633. UINT16
  3634. EFIAPI
  3635. CalculateSum16 (
  3636. IN CONST UINT16 *Buffer,
  3637. IN UINTN Length
  3638. );
  3639. /**
  3640. Returns the two's complement checksum of all elements in a buffer of
  3641. 16-bit values.
  3642. This function first calculates the sum of the 16-bit values in the buffer
  3643. specified by Buffer and Length. The carry bits in the result of addition
  3644. are dropped. Then, the two's complement of the sum is returned. If Length
  3645. is 0, then 0 is returned.
  3646. If Buffer is NULL, then ASSERT().
  3647. If Buffer is not aligned on a 16-bit boundary, then ASSERT().
  3648. If Length is not aligned on a 16-bit boundary, then ASSERT().
  3649. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3650. @param Buffer The pointer to the buffer to carry out the checksum operation.
  3651. @param Length The size, in bytes, of Buffer.
  3652. @return Checksum The two's complement checksum of Buffer.
  3653. **/
  3654. UINT16
  3655. EFIAPI
  3656. CalculateCheckSum16 (
  3657. IN CONST UINT16 *Buffer,
  3658. IN UINTN Length
  3659. );
  3660. /**
  3661. Returns the sum of all elements in a buffer of 32-bit values. During
  3662. calculation, the carry bits are dropped.
  3663. This function calculates the sum of the 32-bit values in the buffer
  3664. specified by Buffer and Length. The carry bits in result of addition are dropped.
  3665. The 32-bit result is returned. If Length is 0, then 0 is returned.
  3666. If Buffer is NULL, then ASSERT().
  3667. If Buffer is not aligned on a 32-bit boundary, then ASSERT().
  3668. If Length is not aligned on a 32-bit boundary, then ASSERT().
  3669. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3670. @param Buffer The pointer to the buffer to carry out the sum operation.
  3671. @param Length The size, in bytes, of Buffer.
  3672. @return Sum The sum of Buffer with carry bits dropped during additions.
  3673. **/
  3674. UINT32
  3675. EFIAPI
  3676. CalculateSum32 (
  3677. IN CONST UINT32 *Buffer,
  3678. IN UINTN Length
  3679. );
  3680. /**
  3681. Returns the two's complement checksum of all elements in a buffer of
  3682. 32-bit values.
  3683. This function first calculates the sum of the 32-bit values in the buffer
  3684. specified by Buffer and Length. The carry bits in the result of addition
  3685. are dropped. Then, the two's complement of the sum is returned. If Length
  3686. is 0, then 0 is returned.
  3687. If Buffer is NULL, then ASSERT().
  3688. If Buffer is not aligned on a 32-bit boundary, then ASSERT().
  3689. If Length is not aligned on a 32-bit boundary, then ASSERT().
  3690. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3691. @param Buffer The pointer to the buffer to carry out the checksum operation.
  3692. @param Length The size, in bytes, of Buffer.
  3693. @return Checksum The two's complement checksum of Buffer.
  3694. **/
  3695. UINT32
  3696. EFIAPI
  3697. CalculateCheckSum32 (
  3698. IN CONST UINT32 *Buffer,
  3699. IN UINTN Length
  3700. );
  3701. /**
  3702. Returns the sum of all elements in a buffer of 64-bit values. During
  3703. calculation, the carry bits are dropped.
  3704. This function calculates the sum of the 64-bit values in the buffer
  3705. specified by Buffer and Length. The carry bits in result of addition are dropped.
  3706. The 64-bit result is returned. If Length is 0, then 0 is returned.
  3707. If Buffer is NULL, then ASSERT().
  3708. If Buffer is not aligned on a 64-bit boundary, then ASSERT().
  3709. If Length is not aligned on a 64-bit boundary, then ASSERT().
  3710. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3711. @param Buffer The pointer to the buffer to carry out the sum operation.
  3712. @param Length The size, in bytes, of Buffer.
  3713. @return Sum The sum of Buffer with carry bits dropped during additions.
  3714. **/
  3715. UINT64
  3716. EFIAPI
  3717. CalculateSum64 (
  3718. IN CONST UINT64 *Buffer,
  3719. IN UINTN Length
  3720. );
  3721. /**
  3722. Returns the two's complement checksum of all elements in a buffer of
  3723. 64-bit values.
  3724. This function first calculates the sum of the 64-bit values in the buffer
  3725. specified by Buffer and Length. The carry bits in the result of addition
  3726. are dropped. Then, the two's complement of the sum is returned. If Length
  3727. is 0, then 0 is returned.
  3728. If Buffer is NULL, then ASSERT().
  3729. If Buffer is not aligned on a 64-bit boundary, then ASSERT().
  3730. If Length is not aligned on a 64-bit boundary, then ASSERT().
  3731. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  3732. @param Buffer The pointer to the buffer to carry out the checksum operation.
  3733. @param Length The size, in bytes, of Buffer.
  3734. @return Checksum The two's complement checksum of Buffer.
  3735. **/
  3736. UINT64
  3737. EFIAPI
  3738. CalculateCheckSum64 (
  3739. IN CONST UINT64 *Buffer,
  3740. IN UINTN Length
  3741. );
  3742. //
  3743. // Base Library CPU Functions
  3744. //
  3745. /**
  3746. Function entry point used when a stack switch is requested with SwitchStack()
  3747. @param Context1 Context1 parameter passed into SwitchStack().
  3748. @param Context2 Context2 parameter passed into SwitchStack().
  3749. **/
  3750. typedef
  3751. VOID
  3752. (EFIAPI *SWITCH_STACK_ENTRY_POINT)(
  3753. IN VOID *Context1, OPTIONAL
  3754. IN VOID *Context2 OPTIONAL
  3755. );
  3756. /**
  3757. Used to serialize load and store operations.
  3758. All loads and stores that proceed calls to this function are guaranteed to be
  3759. globally visible when this function returns.
  3760. **/
  3761. VOID
  3762. EFIAPI
  3763. MemoryFence (
  3764. VOID
  3765. );
  3766. /**
  3767. Saves the current CPU context that can be restored with a call to LongJump()
  3768. and returns 0.
  3769. Saves the current CPU context in the buffer specified by JumpBuffer and
  3770. returns 0. The initial call to SetJump() must always return 0. Subsequent
  3771. calls to LongJump() cause a non-zero value to be returned by SetJump().
  3772. If JumpBuffer is NULL, then ASSERT().
  3773. For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
  3774. NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.
  3775. The same structure must never be used for more than one CPU architecture context.
  3776. For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module.
  3777. SetJump()/LongJump() is not currently supported for the EBC processor type.
  3778. @param JumpBuffer A pointer to CPU context buffer.
  3779. @retval 0 Indicates a return from SetJump().
  3780. **/
  3781. UINTN
  3782. EFIAPI
  3783. SetJump (
  3784. OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
  3785. );
  3786. /**
  3787. Restores the CPU context that was saved with SetJump().
  3788. Restores the CPU context from the buffer specified by JumpBuffer. This
  3789. function never returns to the caller. Instead is resumes execution based on
  3790. the state of JumpBuffer.
  3791. If JumpBuffer is NULL, then ASSERT().
  3792. For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
  3793. If Value is 0, then ASSERT().
  3794. @param JumpBuffer A pointer to CPU context buffer.
  3795. @param Value The value to return when the SetJump() context is
  3796. restored and must be non-zero.
  3797. **/
  3798. VOID
  3799. EFIAPI
  3800. LongJump (
  3801. IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
  3802. IN UINTN Value
  3803. );
  3804. /**
  3805. Enables CPU interrupts.
  3806. **/
  3807. VOID
  3808. EFIAPI
  3809. EnableInterrupts (
  3810. VOID
  3811. );
  3812. /**
  3813. Disables CPU interrupts.
  3814. **/
  3815. VOID
  3816. EFIAPI
  3817. DisableInterrupts (
  3818. VOID
  3819. );
  3820. /**
  3821. Disables CPU interrupts and returns the interrupt state prior to the disable
  3822. operation.
  3823. @retval TRUE CPU interrupts were enabled on entry to this call.
  3824. @retval FALSE CPU interrupts were disabled on entry to this call.
  3825. **/
  3826. BOOLEAN
  3827. EFIAPI
  3828. SaveAndDisableInterrupts (
  3829. VOID
  3830. );
  3831. /**
  3832. Enables CPU interrupts for the smallest window required to capture any
  3833. pending interrupts.
  3834. **/
  3835. VOID
  3836. EFIAPI
  3837. EnableDisableInterrupts (
  3838. VOID
  3839. );
  3840. /**
  3841. Retrieves the current CPU interrupt state.
  3842. Returns TRUE if interrupts are currently enabled. Otherwise
  3843. returns FALSE.
  3844. @retval TRUE CPU interrupts are enabled.
  3845. @retval FALSE CPU interrupts are disabled.
  3846. **/
  3847. BOOLEAN
  3848. EFIAPI
  3849. GetInterruptState (
  3850. VOID
  3851. );
  3852. /**
  3853. Set the current CPU interrupt state.
  3854. Sets the current CPU interrupt state to the state specified by
  3855. InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
  3856. InterruptState is FALSE, then interrupts are disabled. InterruptState is
  3857. returned.
  3858. @param InterruptState TRUE if interrupts should enabled. FALSE if
  3859. interrupts should be disabled.
  3860. @return InterruptState
  3861. **/
  3862. BOOLEAN
  3863. EFIAPI
  3864. SetInterruptState (
  3865. IN BOOLEAN InterruptState
  3866. );
  3867. /**
  3868. Requests CPU to pause for a short period of time.
  3869. Requests CPU to pause for a short period of time. Typically used in MP
  3870. systems to prevent memory starvation while waiting for a spin lock.
  3871. **/
  3872. VOID
  3873. EFIAPI
  3874. CpuPause (
  3875. VOID
  3876. );
  3877. /**
  3878. Transfers control to a function starting with a new stack.
  3879. Transfers control to the function specified by EntryPoint using the
  3880. new stack specified by NewStack and passing in the parameters specified
  3881. by Context1 and Context2. Context1 and Context2 are optional and may
  3882. be NULL. The function EntryPoint must never return. This function
  3883. supports a variable number of arguments following the NewStack parameter.
  3884. These additional arguments are ignored on IA-32, x64, and EBC architectures.
  3885. Itanium processors expect one additional parameter of type VOID * that specifies
  3886. the new backing store pointer.
  3887. If EntryPoint is NULL, then ASSERT().
  3888. If NewStack is NULL, then ASSERT().
  3889. @param EntryPoint A pointer to function to call with the new stack.
  3890. @param Context1 A pointer to the context to pass into the EntryPoint
  3891. function.
  3892. @param Context2 A pointer to the context to pass into the EntryPoint
  3893. function.
  3894. @param NewStack A pointer to the new stack to use for the EntryPoint
  3895. function.
  3896. @param ... This variable argument list is ignored for IA-32, x64, and
  3897. EBC architectures. For Itanium processors, this variable
  3898. argument list is expected to contain a single parameter of
  3899. type VOID * that specifies the new backing store pointer.
  3900. **/
  3901. VOID
  3902. EFIAPI
  3903. SwitchStack (
  3904. IN SWITCH_STACK_ENTRY_POINT EntryPoint,
  3905. IN VOID *Context1, OPTIONAL
  3906. IN VOID *Context2, OPTIONAL
  3907. IN VOID *NewStack,
  3908. ...
  3909. );
  3910. /**
  3911. Generates a breakpoint on the CPU.
  3912. Generates a breakpoint on the CPU. The breakpoint must be implemented such
  3913. that code can resume normal execution after the breakpoint.
  3914. **/
  3915. VOID
  3916. EFIAPI
  3917. CpuBreakpoint (
  3918. VOID
  3919. );
  3920. /**
  3921. Executes an infinite loop.
  3922. Forces the CPU to execute an infinite loop. A debugger may be used to skip
  3923. past the loop and the code that follows the loop must execute properly. This
  3924. implies that the infinite loop must not cause the code that follow it to be
  3925. optimized away.
  3926. **/
  3927. VOID
  3928. EFIAPI
  3929. CpuDeadLoop (
  3930. VOID
  3931. );
  3932. #if defined (MDE_CPU_IPF)
  3933. /**
  3934. Flush a range of cache lines in the cache coherency domain of the calling
  3935. CPU.
  3936. Flushes the cache lines specified by Address and Length. If Address is not aligned
  3937. on a cache line boundary, then entire cache line containing Address is flushed.
  3938. If Address + Length is not aligned on a cache line boundary, then the entire cache
  3939. line containing Address + Length - 1 is flushed. This function may choose to flush
  3940. the entire cache if that is more efficient than flushing the specified range. If
  3941. Length is 0, the no cache lines are flushed. Address is returned.
  3942. This function is only available on Itanium processors.
  3943. If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
  3944. @param Address The base address of the instruction lines to invalidate. If
  3945. the CPU is in a physical addressing mode, then Address is a
  3946. physical address. If the CPU is in a virtual addressing mode,
  3947. then Address is a virtual address.
  3948. @param Length The number of bytes to invalidate from the instruction cache.
  3949. @return Address.
  3950. **/
  3951. VOID *
  3952. EFIAPI
  3953. AsmFlushCacheRange (
  3954. IN VOID *Address,
  3955. IN UINTN Length
  3956. );
  3957. /**
  3958. Executes an FC instruction.
  3959. Executes an FC instruction on the cache line specified by Address.
  3960. The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
  3961. An implementation may flush a larger region. This function is only available on Itanium processors.
  3962. @param Address The Address of cache line to be flushed.
  3963. @return The address of FC instruction executed.
  3964. **/
  3965. UINT64
  3966. EFIAPI
  3967. AsmFc (
  3968. IN UINT64 Address
  3969. );
  3970. /**
  3971. Executes an FC.I instruction.
  3972. Executes an FC.I instruction on the cache line specified by Address.
  3973. The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
  3974. An implementation may flush a larger region. This function is only available on Itanium processors.
  3975. @param Address The Address of cache line to be flushed.
  3976. @return The address of the FC.I instruction executed.
  3977. **/
  3978. UINT64
  3979. EFIAPI
  3980. AsmFci (
  3981. IN UINT64 Address
  3982. );
  3983. /**
  3984. Reads the current value of a Processor Identifier Register (CPUID).
  3985. Reads and returns the current value of Processor Identifier Register specified by Index.
  3986. The Index of largest implemented CPUID (One less than the number of implemented CPUID
  3987. registers) is determined by CPUID [3] bits {7:0}.
  3988. No parameter checking is performed on Index. If the Index value is beyond the
  3989. implemented CPUID register range, a Reserved Register/Field fault may occur. The caller
  3990. must either guarantee that Index is valid, or the caller must set up fault handlers to
  3991. catch the faults. This function is only available on Itanium processors.
  3992. @param Index The 8-bit Processor Identifier Register index to read.
  3993. @return The current value of Processor Identifier Register specified by Index.
  3994. **/
  3995. UINT64
  3996. EFIAPI
  3997. AsmReadCpuid (
  3998. IN UINT8 Index
  3999. );
  4000. /**
  4001. Reads the current value of 64-bit Processor Status Register (PSR).
  4002. This function is only available on Itanium processors.
  4003. @return The current value of PSR.
  4004. **/
  4005. UINT64
  4006. EFIAPI
  4007. AsmReadPsr (
  4008. VOID
  4009. );
  4010. /**
  4011. Writes the current value of 64-bit Processor Status Register (PSR).
  4012. No parameter checking is performed on Value. All bits of Value corresponding to
  4013. reserved fields of PSR must be 0 or a Reserved Register/Field fault may occur.
  4014. The caller must either guarantee that Value is valid, or the caller must set up
  4015. fault handlers to catch the faults. This function is only available on Itanium processors.
  4016. @param Value The 64-bit value to write to PSR.
  4017. @return The 64-bit value written to the PSR.
  4018. **/
  4019. UINT64
  4020. EFIAPI
  4021. AsmWritePsr (
  4022. IN UINT64 Value
  4023. );
  4024. /**
  4025. Reads the current value of 64-bit Kernel Register #0 (KR0).
  4026. Reads and returns the current value of KR0.
  4027. This function is only available on Itanium processors.
  4028. @return The current value of KR0.
  4029. **/
  4030. UINT64
  4031. EFIAPI
  4032. AsmReadKr0 (
  4033. VOID
  4034. );
  4035. /**
  4036. Reads the current value of 64-bit Kernel Register #1 (KR1).
  4037. Reads and returns the current value of KR1.
  4038. This function is only available on Itanium processors.
  4039. @return The current value of KR1.
  4040. **/
  4041. UINT64
  4042. EFIAPI
  4043. AsmReadKr1 (
  4044. VOID
  4045. );
  4046. /**
  4047. Reads the current value of 64-bit Kernel Register #2 (KR2).
  4048. Reads and returns the current value of KR2.
  4049. This function is only available on Itanium processors.
  4050. @return The current value of KR2.
  4051. **/
  4052. UINT64
  4053. EFIAPI
  4054. AsmReadKr2 (
  4055. VOID
  4056. );
  4057. /**
  4058. Reads the current value of 64-bit Kernel Register #3 (KR3).
  4059. Reads and returns the current value of KR3.
  4060. This function is only available on Itanium processors.
  4061. @return The current value of KR3.
  4062. **/
  4063. UINT64
  4064. EFIAPI
  4065. AsmReadKr3 (
  4066. VOID
  4067. );
  4068. /**
  4069. Reads the current value of 64-bit Kernel Register #4 (KR4).
  4070. Reads and returns the current value of KR4.
  4071. This function is only available on Itanium processors.
  4072. @return The current value of KR4.
  4073. **/
  4074. UINT64
  4075. EFIAPI
  4076. AsmReadKr4 (
  4077. VOID
  4078. );
  4079. /**
  4080. Reads the current value of 64-bit Kernel Register #5 (KR5).
  4081. Reads and returns the current value of KR5.
  4082. This function is only available on Itanium processors.
  4083. @return The current value of KR5.
  4084. **/
  4085. UINT64
  4086. EFIAPI
  4087. AsmReadKr5 (
  4088. VOID
  4089. );
  4090. /**
  4091. Reads the current value of 64-bit Kernel Register #6 (KR6).
  4092. Reads and returns the current value of KR6.
  4093. This function is only available on Itanium processors.
  4094. @return The current value of KR6.
  4095. **/
  4096. UINT64
  4097. EFIAPI
  4098. AsmReadKr6 (
  4099. VOID
  4100. );
  4101. /**
  4102. Reads the current value of 64-bit Kernel Register #7 (KR7).
  4103. Reads and returns the current value of KR7.
  4104. This function is only available on Itanium processors.
  4105. @return The current value of KR7.
  4106. **/
  4107. UINT64
  4108. EFIAPI
  4109. AsmReadKr7 (
  4110. VOID
  4111. );
  4112. /**
  4113. Write the current value of 64-bit Kernel Register #0 (KR0).
  4114. Writes the current value of KR0. The 64-bit value written to
  4115. the KR0 is returned. This function is only available on Itanium processors.
  4116. @param Value The 64-bit value to write to KR0.
  4117. @return The 64-bit value written to the KR0.
  4118. **/
  4119. UINT64
  4120. EFIAPI
  4121. AsmWriteKr0 (
  4122. IN UINT64 Value
  4123. );
  4124. /**
  4125. Write the current value of 64-bit Kernel Register #1 (KR1).
  4126. Writes the current value of KR1. The 64-bit value written to
  4127. the KR1 is returned. This function is only available on Itanium processors.
  4128. @param Value The 64-bit value to write to KR1.
  4129. @return The 64-bit value written to the KR1.
  4130. **/
  4131. UINT64
  4132. EFIAPI
  4133. AsmWriteKr1 (
  4134. IN UINT64 Value
  4135. );
  4136. /**
  4137. Write the current value of 64-bit Kernel Register #2 (KR2).
  4138. Writes the current value of KR2. The 64-bit value written to
  4139. the KR2 is returned. This function is only available on Itanium processors.
  4140. @param Value The 64-bit value to write to KR2.
  4141. @return The 64-bit value written to the KR2.
  4142. **/
  4143. UINT64
  4144. EFIAPI
  4145. AsmWriteKr2 (
  4146. IN UINT64 Value
  4147. );
  4148. /**
  4149. Write the current value of 64-bit Kernel Register #3 (KR3).
  4150. Writes the current value of KR3. The 64-bit value written to
  4151. the KR3 is returned. This function is only available on Itanium processors.
  4152. @param Value The 64-bit value to write to KR3.
  4153. @return The 64-bit value written to the KR3.
  4154. **/
  4155. UINT64
  4156. EFIAPI
  4157. AsmWriteKr3 (
  4158. IN UINT64 Value
  4159. );
  4160. /**
  4161. Write the current value of 64-bit Kernel Register #4 (KR4).
  4162. Writes the current value of KR4. The 64-bit value written to
  4163. the KR4 is returned. This function is only available on Itanium processors.
  4164. @param Value The 64-bit value to write to KR4.
  4165. @return The 64-bit value written to the KR4.
  4166. **/
  4167. UINT64
  4168. EFIAPI
  4169. AsmWriteKr4 (
  4170. IN UINT64 Value
  4171. );
  4172. /**
  4173. Write the current value of 64-bit Kernel Register #5 (KR5).
  4174. Writes the current value of KR5. The 64-bit value written to
  4175. the KR5 is returned. This function is only available on Itanium processors.
  4176. @param Value The 64-bit value to write to KR5.
  4177. @return The 64-bit value written to the KR5.
  4178. **/
  4179. UINT64
  4180. EFIAPI
  4181. AsmWriteKr5 (
  4182. IN UINT64 Value
  4183. );
  4184. /**
  4185. Write the current value of 64-bit Kernel Register #6 (KR6).
  4186. Writes the current value of KR6. The 64-bit value written to
  4187. the KR6 is returned. This function is only available on Itanium processors.
  4188. @param Value The 64-bit value to write to KR6.
  4189. @return The 64-bit value written to the KR6.
  4190. **/
  4191. UINT64
  4192. EFIAPI
  4193. AsmWriteKr6 (
  4194. IN UINT64 Value
  4195. );
  4196. /**
  4197. Write the current value of 64-bit Kernel Register #7 (KR7).
  4198. Writes the current value of KR7. The 64-bit value written to
  4199. the KR7 is returned. This function is only available on Itanium processors.
  4200. @param Value The 64-bit value to write to KR7.
  4201. @return The 64-bit value written to the KR7.
  4202. **/
  4203. UINT64
  4204. EFIAPI
  4205. AsmWriteKr7 (
  4206. IN UINT64 Value
  4207. );
  4208. /**
  4209. Reads the current value of Interval Timer Counter Register (ITC).
  4210. Reads and returns the current value of ITC.
  4211. This function is only available on Itanium processors.
  4212. @return The current value of ITC.
  4213. **/
  4214. UINT64
  4215. EFIAPI
  4216. AsmReadItc (
  4217. VOID
  4218. );
  4219. /**
  4220. Reads the current value of Interval Timer Vector Register (ITV).
  4221. Reads and returns the current value of ITV.
  4222. This function is only available on Itanium processors.
  4223. @return The current value of ITV.
  4224. **/
  4225. UINT64
  4226. EFIAPI
  4227. AsmReadItv (
  4228. VOID
  4229. );
  4230. /**
  4231. Reads the current value of Interval Timer Match Register (ITM).
  4232. Reads and returns the current value of ITM.
  4233. This function is only available on Itanium processors.
  4234. @return The current value of ITM.
  4235. **/
  4236. UINT64
  4237. EFIAPI
  4238. AsmReadItm (
  4239. VOID
  4240. );
  4241. /**
  4242. Writes the current value of 64-bit Interval Timer Counter Register (ITC).
  4243. Writes the current value of ITC. The 64-bit value written to the ITC is returned.
  4244. This function is only available on Itanium processors.
  4245. @param Value The 64-bit value to write to ITC.
  4246. @return The 64-bit value written to the ITC.
  4247. **/
  4248. UINT64
  4249. EFIAPI
  4250. AsmWriteItc (
  4251. IN UINT64 Value
  4252. );
  4253. /**
  4254. Writes the current value of 64-bit Interval Timer Match Register (ITM).
  4255. Writes the current value of ITM. The 64-bit value written to the ITM is returned.
  4256. This function is only available on Itanium processors.
  4257. @param Value The 64-bit value to write to ITM.
  4258. @return The 64-bit value written to the ITM.
  4259. **/
  4260. UINT64
  4261. EFIAPI
  4262. AsmWriteItm (
  4263. IN UINT64 Value
  4264. );
  4265. /**
  4266. Writes the current value of 64-bit Interval Timer Vector Register (ITV).
  4267. Writes the current value of ITV. The 64-bit value written to the ITV is returned.
  4268. No parameter checking is performed on Value. All bits of Value corresponding to
  4269. reserved fields of ITV must be 0 or a Reserved Register/Field fault may occur.
  4270. The caller must either guarantee that Value is valid, or the caller must set up
  4271. fault handlers to catch the faults.
  4272. This function is only available on Itanium processors.
  4273. @param Value The 64-bit value to write to ITV.
  4274. @return The 64-bit value written to the ITV.
  4275. **/
  4276. UINT64
  4277. EFIAPI
  4278. AsmWriteItv (
  4279. IN UINT64 Value
  4280. );
  4281. /**
  4282. Reads the current value of Default Control Register (DCR).
  4283. Reads and returns the current value of DCR. This function is only available on Itanium processors.
  4284. @return The current value of DCR.
  4285. **/
  4286. UINT64
  4287. EFIAPI
  4288. AsmReadDcr (
  4289. VOID
  4290. );
  4291. /**
  4292. Reads the current value of Interruption Vector Address Register (IVA).
  4293. Reads and returns the current value of IVA. This function is only available on Itanium processors.
  4294. @return The current value of IVA.
  4295. **/
  4296. UINT64
  4297. EFIAPI
  4298. AsmReadIva (
  4299. VOID
  4300. );
  4301. /**
  4302. Reads the current value of Page Table Address Register (PTA).
  4303. Reads and returns the current value of PTA. This function is only available on Itanium processors.
  4304. @return The current value of PTA.
  4305. **/
  4306. UINT64
  4307. EFIAPI
  4308. AsmReadPta (
  4309. VOID
  4310. );
  4311. /**
  4312. Writes the current value of 64-bit Default Control Register (DCR).
  4313. Writes the current value of DCR. The 64-bit value written to the DCR is returned.
  4314. No parameter checking is performed on Value. All bits of Value corresponding to
  4315. reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
  4316. The caller must either guarantee that Value is valid, or the caller must set up
  4317. fault handlers to catch the faults.
  4318. This function is only available on Itanium processors.
  4319. @param Value The 64-bit value to write to DCR.
  4320. @return The 64-bit value written to the DCR.
  4321. **/
  4322. UINT64
  4323. EFIAPI
  4324. AsmWriteDcr (
  4325. IN UINT64 Value
  4326. );
  4327. /**
  4328. Writes the current value of 64-bit Interruption Vector Address Register (IVA).
  4329. Writes the current value of IVA. The 64-bit value written to the IVA is returned.
  4330. The size of vector table is 32 K bytes and is 32 K bytes aligned
  4331. the low 15 bits of Value is ignored when written.
  4332. This function is only available on Itanium processors.
  4333. @param Value The 64-bit value to write to IVA.
  4334. @return The 64-bit value written to the IVA.
  4335. **/
  4336. UINT64
  4337. EFIAPI
  4338. AsmWriteIva (
  4339. IN UINT64 Value
  4340. );
  4341. /**
  4342. Writes the current value of 64-bit Page Table Address Register (PTA).
  4343. Writes the current value of PTA. The 64-bit value written to the PTA is returned.
  4344. No parameter checking is performed on Value. All bits of Value corresponding to
  4345. reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
  4346. The caller must either guarantee that Value is valid, or the caller must set up
  4347. fault handlers to catch the faults.
  4348. This function is only available on Itanium processors.
  4349. @param Value The 64-bit value to write to PTA.
  4350. @return The 64-bit value written to the PTA.
  4351. **/
  4352. UINT64
  4353. EFIAPI
  4354. AsmWritePta (
  4355. IN UINT64 Value
  4356. );
  4357. /**
  4358. Reads the current value of Local Interrupt ID Register (LID).
  4359. Reads and returns the current value of LID. This function is only available on Itanium processors.
  4360. @return The current value of LID.
  4361. **/
  4362. UINT64
  4363. EFIAPI
  4364. AsmReadLid (
  4365. VOID
  4366. );
  4367. /**
  4368. Reads the current value of External Interrupt Vector Register (IVR).
  4369. Reads and returns the current value of IVR. This function is only available on Itanium processors.
  4370. @return The current value of IVR.
  4371. **/
  4372. UINT64
  4373. EFIAPI
  4374. AsmReadIvr (
  4375. VOID
  4376. );
  4377. /**
  4378. Reads the current value of Task Priority Register (TPR).
  4379. Reads and returns the current value of TPR. This function is only available on Itanium processors.
  4380. @return The current value of TPR.
  4381. **/
  4382. UINT64
  4383. EFIAPI
  4384. AsmReadTpr (
  4385. VOID
  4386. );
  4387. /**
  4388. Reads the current value of External Interrupt Request Register #0 (IRR0).
  4389. Reads and returns the current value of IRR0. This function is only available on Itanium processors.
  4390. @return The current value of IRR0.
  4391. **/
  4392. UINT64
  4393. EFIAPI
  4394. AsmReadIrr0 (
  4395. VOID
  4396. );
  4397. /**
  4398. Reads the current value of External Interrupt Request Register #1 (IRR1).
  4399. Reads and returns the current value of IRR1. This function is only available on Itanium processors.
  4400. @return The current value of IRR1.
  4401. **/
  4402. UINT64
  4403. EFIAPI
  4404. AsmReadIrr1 (
  4405. VOID
  4406. );
  4407. /**
  4408. Reads the current value of External Interrupt Request Register #2 (IRR2).
  4409. Reads and returns the current value of IRR2. This function is only available on Itanium processors.
  4410. @return The current value of IRR2.
  4411. **/
  4412. UINT64
  4413. EFIAPI
  4414. AsmReadIrr2 (
  4415. VOID
  4416. );
  4417. /**
  4418. Reads the current value of External Interrupt Request Register #3 (IRR3).
  4419. Reads and returns the current value of IRR3. This function is only available on Itanium processors.
  4420. @return The current value of IRR3.
  4421. **/
  4422. UINT64
  4423. EFIAPI
  4424. AsmReadIrr3 (
  4425. VOID
  4426. );
  4427. /**
  4428. Reads the current value of Performance Monitor Vector Register (PMV).
  4429. Reads and returns the current value of PMV. This function is only available on Itanium processors.
  4430. @return The current value of PMV.
  4431. **/
  4432. UINT64
  4433. EFIAPI
  4434. AsmReadPmv (
  4435. VOID
  4436. );
  4437. /**
  4438. Reads the current value of Corrected Machine Check Vector Register (CMCV).
  4439. Reads and returns the current value of CMCV. This function is only available on Itanium processors.
  4440. @return The current value of CMCV.
  4441. **/
  4442. UINT64
  4443. EFIAPI
  4444. AsmReadCmcv (
  4445. VOID
  4446. );
  4447. /**
  4448. Reads the current value of Local Redirection Register #0 (LRR0).
  4449. Reads and returns the current value of LRR0. This function is only available on Itanium processors.
  4450. @return The current value of LRR0.
  4451. **/
  4452. UINT64
  4453. EFIAPI
  4454. AsmReadLrr0 (
  4455. VOID
  4456. );
  4457. /**
  4458. Reads the current value of Local Redirection Register #1 (LRR1).
  4459. Reads and returns the current value of LRR1. This function is only available on Itanium processors.
  4460. @return The current value of LRR1.
  4461. **/
  4462. UINT64
  4463. EFIAPI
  4464. AsmReadLrr1 (
  4465. VOID
  4466. );
  4467. /**
  4468. Writes the current value of 64-bit Page Local Interrupt ID Register (LID).
  4469. Writes the current value of LID. The 64-bit value written to the LID is returned.
  4470. No parameter checking is performed on Value. All bits of Value corresponding to
  4471. reserved fields of LID must be 0 or a Reserved Register/Field fault may occur.
  4472. The caller must either guarantee that Value is valid, or the caller must set up
  4473. fault handlers to catch the faults.
  4474. This function is only available on Itanium processors.
  4475. @param Value The 64-bit value to write to LID.
  4476. @return The 64-bit value written to the LID.
  4477. **/
  4478. UINT64
  4479. EFIAPI
  4480. AsmWriteLid (
  4481. IN UINT64 Value
  4482. );
  4483. /**
  4484. Writes the current value of 64-bit Task Priority Register (TPR).
  4485. Writes the current value of TPR. The 64-bit value written to the TPR is returned.
  4486. No parameter checking is performed on Value. All bits of Value corresponding to
  4487. reserved fields of TPR must be 0 or a Reserved Register/Field fault may occur.
  4488. The caller must either guarantee that Value is valid, or the caller must set up
  4489. fault handlers to catch the faults.
  4490. This function is only available on Itanium processors.
  4491. @param Value The 64-bit value to write to TPR.
  4492. @return The 64-bit value written to the TPR.
  4493. **/
  4494. UINT64
  4495. EFIAPI
  4496. AsmWriteTpr (
  4497. IN UINT64 Value
  4498. );
  4499. /**
  4500. Performs a write operation on End OF External Interrupt Register (EOI).
  4501. Writes a value of 0 to the EOI Register. This function is only available on Itanium processors.
  4502. **/
  4503. VOID
  4504. EFIAPI
  4505. AsmWriteEoi (
  4506. VOID
  4507. );
  4508. /**
  4509. Writes the current value of 64-bit Performance Monitor Vector Register (PMV).
  4510. Writes the current value of PMV. The 64-bit value written to the PMV is returned.
  4511. No parameter checking is performed on Value. All bits of Value corresponding
  4512. to reserved fields of PMV must be 0 or a Reserved Register/Field fault may occur.
  4513. The caller must either guarantee that Value is valid, or the caller must set up
  4514. fault handlers to catch the faults.
  4515. This function is only available on Itanium processors.
  4516. @param Value The 64-bit value to write to PMV.
  4517. @return The 64-bit value written to the PMV.
  4518. **/
  4519. UINT64
  4520. EFIAPI
  4521. AsmWritePmv (
  4522. IN UINT64 Value
  4523. );
  4524. /**
  4525. Writes the current value of 64-bit Corrected Machine Check Vector Register (CMCV).
  4526. Writes the current value of CMCV. The 64-bit value written to the CMCV is returned.
  4527. No parameter checking is performed on Value. All bits of Value corresponding
  4528. to reserved fields of CMCV must be 0 or a Reserved Register/Field fault may occur.
  4529. The caller must either guarantee that Value is valid, or the caller must set up
  4530. fault handlers to catch the faults.
  4531. This function is only available on Itanium processors.
  4532. @param Value The 64-bit value to write to CMCV.
  4533. @return The 64-bit value written to the CMCV.
  4534. **/
  4535. UINT64
  4536. EFIAPI
  4537. AsmWriteCmcv (
  4538. IN UINT64 Value
  4539. );
  4540. /**
  4541. Writes the current value of 64-bit Local Redirection Register #0 (LRR0).
  4542. Writes the current value of LRR0. The 64-bit value written to the LRR0 is returned.
  4543. No parameter checking is performed on Value. All bits of Value corresponding
  4544. to reserved fields of LRR0 must be 0 or a Reserved Register/Field fault may occur.
  4545. The caller must either guarantee that Value is valid, or the caller must set up
  4546. fault handlers to catch the faults.
  4547. This function is only available on Itanium processors.
  4548. @param Value The 64-bit value to write to LRR0.
  4549. @return The 64-bit value written to the LRR0.
  4550. **/
  4551. UINT64
  4552. EFIAPI
  4553. AsmWriteLrr0 (
  4554. IN UINT64 Value
  4555. );
  4556. /**
  4557. Writes the current value of 64-bit Local Redirection Register #1 (LRR1).
  4558. Writes the current value of LRR1. The 64-bit value written to the LRR1 is returned.
  4559. No parameter checking is performed on Value. All bits of Value corresponding
  4560. to reserved fields of LRR1 must be 0 or a Reserved Register/Field fault may occur.
  4561. The caller must either guarantee that Value is valid, or the caller must
  4562. set up fault handlers to catch the faults.
  4563. This function is only available on Itanium processors.
  4564. @param Value The 64-bit value to write to LRR1.
  4565. @return The 64-bit value written to the LRR1.
  4566. **/
  4567. UINT64
  4568. EFIAPI
  4569. AsmWriteLrr1 (
  4570. IN UINT64 Value
  4571. );
  4572. /**
  4573. Reads the current value of Instruction Breakpoint Register (IBR).
  4574. The Instruction Breakpoint Registers are used in pairs. The even numbered
  4575. registers contain breakpoint addresses, and the odd numbered registers contain
  4576. breakpoint mask conditions. At least four instruction registers pairs are implemented
  4577. on all processor models. Implemented registers are contiguous starting with
  4578. register 0. No parameter checking is performed on Index, and if the Index value
  4579. is beyond the implemented IBR register range, a Reserved Register/Field fault may
  4580. occur. The caller must either guarantee that Index is valid, or the caller must
  4581. set up fault handlers to catch the faults.
  4582. This function is only available on Itanium processors.
  4583. @param Index The 8-bit Instruction Breakpoint Register index to read.
  4584. @return The current value of Instruction Breakpoint Register specified by Index.
  4585. **/
  4586. UINT64
  4587. EFIAPI
  4588. AsmReadIbr (
  4589. IN UINT8 Index
  4590. );
  4591. /**
  4592. Reads the current value of Data Breakpoint Register (DBR).
  4593. The Data Breakpoint Registers are used in pairs. The even numbered registers
  4594. contain breakpoint addresses, and odd numbered registers contain breakpoint
  4595. mask conditions. At least four data registers pairs are implemented on all processor
  4596. models. Implemented registers are contiguous starting with register 0.
  4597. No parameter checking is performed on Index. If the Index value is beyond
  4598. the implemented DBR register range, a Reserved Register/Field fault may occur.
  4599. The caller must either guarantee that Index is valid, or the caller must set up
  4600. fault handlers to catch the faults.
  4601. This function is only available on Itanium processors.
  4602. @param Index The 8-bit Data Breakpoint Register index to read.
  4603. @return The current value of Data Breakpoint Register specified by Index.
  4604. **/
  4605. UINT64
  4606. EFIAPI
  4607. AsmReadDbr (
  4608. IN UINT8 Index
  4609. );
  4610. /**
  4611. Reads the current value of Performance Monitor Configuration Register (PMC).
  4612. All processor implementations provide at least four performance counters
  4613. (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow
  4614. status registers (PMC [0]... PMC [3]). Processor implementations may provide
  4615. additional implementation-dependent PMC and PMD to increase the number of
  4616. 'generic' performance counters (PMC/PMD pairs). The remainder of PMC and PMD
  4617. register set is implementation dependent. No parameter checking is performed
  4618. on Index. If the Index value is beyond the implemented PMC register range,
  4619. zero value will be returned.
  4620. This function is only available on Itanium processors.
  4621. @param Index The 8-bit Performance Monitor Configuration Register index to read.
  4622. @return The current value of Performance Monitor Configuration Register
  4623. specified by Index.
  4624. **/
  4625. UINT64
  4626. EFIAPI
  4627. AsmReadPmc (
  4628. IN UINT8 Index
  4629. );
  4630. /**
  4631. Reads the current value of Performance Monitor Data Register (PMD).
  4632. All processor implementations provide at least 4 performance counters
  4633. (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter
  4634. overflow status registers (PMC [0]... PMC [3]). Processor implementations may
  4635. provide additional implementation-dependent PMC and PMD to increase the number
  4636. of 'generic' performance counters (PMC/PMD pairs). The remainder of PMC and PMD
  4637. register set is implementation dependent. No parameter checking is performed
  4638. on Index. If the Index value is beyond the implemented PMD register range,
  4639. zero value will be returned.
  4640. This function is only available on Itanium processors.
  4641. @param Index The 8-bit Performance Monitor Data Register index to read.
  4642. @return The current value of Performance Monitor Data Register specified by Index.
  4643. **/
  4644. UINT64
  4645. EFIAPI
  4646. AsmReadPmd (
  4647. IN UINT8 Index
  4648. );
  4649. /**
  4650. Writes the current value of 64-bit Instruction Breakpoint Register (IBR).
  4651. Writes current value of Instruction Breakpoint Register specified by Index.
  4652. The Instruction Breakpoint Registers are used in pairs. The even numbered
  4653. registers contain breakpoint addresses, and odd numbered registers contain
  4654. breakpoint mask conditions. At least four instruction registers pairs are implemented
  4655. on all processor models. Implemented registers are contiguous starting with
  4656. register 0. No parameter checking is performed on Index. If the Index value
  4657. is beyond the implemented IBR register range, a Reserved Register/Field fault may
  4658. occur. The caller must either guarantee that Index is valid, or the caller must
  4659. set up fault handlers to catch the faults.
  4660. This function is only available on Itanium processors.
  4661. @param Index The 8-bit Instruction Breakpoint Register index to write.
  4662. @param Value The 64-bit value to write to IBR.
  4663. @return The 64-bit value written to the IBR.
  4664. **/
  4665. UINT64
  4666. EFIAPI
  4667. AsmWriteIbr (
  4668. IN UINT8 Index,
  4669. IN UINT64 Value
  4670. );
  4671. /**
  4672. Writes the current value of 64-bit Data Breakpoint Register (DBR).
  4673. Writes current value of Data Breakpoint Register specified by Index.
  4674. The Data Breakpoint Registers are used in pairs. The even numbered registers
  4675. contain breakpoint addresses, and odd numbered registers contain breakpoint
  4676. mask conditions. At least four data registers pairs are implemented on all processor
  4677. models. Implemented registers are contiguous starting with register 0. No parameter
  4678. checking is performed on Index. If the Index value is beyond the implemented
  4679. DBR register range, a Reserved Register/Field fault may occur. The caller must
  4680. either guarantee that Index is valid, or the caller must set up fault handlers to
  4681. catch the faults.
  4682. This function is only available on Itanium processors.
  4683. @param Index The 8-bit Data Breakpoint Register index to write.
  4684. @param Value The 64-bit value to write to DBR.
  4685. @return The 64-bit value written to the DBR.
  4686. **/
  4687. UINT64
  4688. EFIAPI
  4689. AsmWriteDbr (
  4690. IN UINT8 Index,
  4691. IN UINT64 Value
  4692. );
  4693. /**
  4694. Writes the current value of 64-bit Performance Monitor Configuration Register (PMC).
  4695. Writes current value of Performance Monitor Configuration Register specified by Index.
  4696. All processor implementations provide at least four performance counters
  4697. (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow status
  4698. registers (PMC [0]... PMC [3]). Processor implementations may provide additional
  4699. implementation-dependent PMC and PMD to increase the number of 'generic' performance
  4700. counters (PMC/PMD pairs). The remainder of PMC and PMD register set is implementation
  4701. dependent. No parameter checking is performed on Index. If the Index value is
  4702. beyond the implemented PMC register range, the write is ignored.
  4703. This function is only available on Itanium processors.
  4704. @param Index The 8-bit Performance Monitor Configuration Register index to write.
  4705. @param Value The 64-bit value to write to PMC.
  4706. @return The 64-bit value written to the PMC.
  4707. **/
  4708. UINT64
  4709. EFIAPI
  4710. AsmWritePmc (
  4711. IN UINT8 Index,
  4712. IN UINT64 Value
  4713. );
  4714. /**
  4715. Writes the current value of 64-bit Performance Monitor Data Register (PMD).
  4716. Writes current value of Performance Monitor Data Register specified by Index.
  4717. All processor implementations provide at least four performance counters
  4718. (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow
  4719. status registers (PMC [0]... PMC [3]). Processor implementations may provide
  4720. additional implementation-dependent PMC and PMD to increase the number of 'generic'
  4721. performance counters (PMC/PMD pairs). The remainder of PMC and PMD register set
  4722. is implementation dependent. No parameter checking is performed on Index. If the
  4723. Index value is beyond the implemented PMD register range, the write is ignored.
  4724. This function is only available on Itanium processors.
  4725. @param Index The 8-bit Performance Monitor Data Register index to write.
  4726. @param Value The 64-bit value to write to PMD.
  4727. @return The 64-bit value written to the PMD.
  4728. **/
  4729. UINT64
  4730. EFIAPI
  4731. AsmWritePmd (
  4732. IN UINT8 Index,
  4733. IN UINT64 Value
  4734. );
  4735. /**
  4736. Reads the current value of 64-bit Global Pointer (GP).
  4737. Reads and returns the current value of GP.
  4738. This function is only available on Itanium processors.
  4739. @return The current value of GP.
  4740. **/
  4741. UINT64
  4742. EFIAPI
  4743. AsmReadGp (
  4744. VOID
  4745. );
  4746. /**
  4747. Write the current value of 64-bit Global Pointer (GP).
  4748. Writes the current value of GP. The 64-bit value written to the GP is returned.
  4749. No parameter checking is performed on Value.
  4750. This function is only available on Itanium processors.
  4751. @param Value The 64-bit value to write to GP.
  4752. @return The 64-bit value written to the GP.
  4753. **/
  4754. UINT64
  4755. EFIAPI
  4756. AsmWriteGp (
  4757. IN UINT64 Value
  4758. );
  4759. /**
  4760. Reads the current value of 64-bit Stack Pointer (SP).
  4761. Reads and returns the current value of SP.
  4762. This function is only available on Itanium processors.
  4763. @return The current value of SP.
  4764. **/
  4765. UINT64
  4766. EFIAPI
  4767. AsmReadSp (
  4768. VOID
  4769. );
  4770. ///
  4771. /// Valid Index value for AsmReadControlRegister().
  4772. ///
  4773. #define IPF_CONTROL_REGISTER_DCR 0
  4774. #define IPF_CONTROL_REGISTER_ITM 1
  4775. #define IPF_CONTROL_REGISTER_IVA 2
  4776. #define IPF_CONTROL_REGISTER_PTA 8
  4777. #define IPF_CONTROL_REGISTER_IPSR 16
  4778. #define IPF_CONTROL_REGISTER_ISR 17
  4779. #define IPF_CONTROL_REGISTER_IIP 19
  4780. #define IPF_CONTROL_REGISTER_IFA 20
  4781. #define IPF_CONTROL_REGISTER_ITIR 21
  4782. #define IPF_CONTROL_REGISTER_IIPA 22
  4783. #define IPF_CONTROL_REGISTER_IFS 23
  4784. #define IPF_CONTROL_REGISTER_IIM 24
  4785. #define IPF_CONTROL_REGISTER_IHA 25
  4786. #define IPF_CONTROL_REGISTER_LID 64
  4787. #define IPF_CONTROL_REGISTER_IVR 65
  4788. #define IPF_CONTROL_REGISTER_TPR 66
  4789. #define IPF_CONTROL_REGISTER_EOI 67
  4790. #define IPF_CONTROL_REGISTER_IRR0 68
  4791. #define IPF_CONTROL_REGISTER_IRR1 69
  4792. #define IPF_CONTROL_REGISTER_IRR2 70
  4793. #define IPF_CONTROL_REGISTER_IRR3 71
  4794. #define IPF_CONTROL_REGISTER_ITV 72
  4795. #define IPF_CONTROL_REGISTER_PMV 73
  4796. #define IPF_CONTROL_REGISTER_CMCV 74
  4797. #define IPF_CONTROL_REGISTER_LRR0 80
  4798. #define IPF_CONTROL_REGISTER_LRR1 81
  4799. /**
  4800. Reads a 64-bit control register.
  4801. Reads and returns the control register specified by Index. The valid Index valued
  4802. are defined above in "Related Definitions".
  4803. If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned. This function is only
  4804. available on Itanium processors.
  4805. @param Index The index of the control register to read.
  4806. @return The control register specified by Index.
  4807. **/
  4808. UINT64
  4809. EFIAPI
  4810. AsmReadControlRegister (
  4811. IN UINT64 Index
  4812. );
  4813. ///
  4814. /// Valid Index value for AsmReadApplicationRegister().
  4815. ///
  4816. #define IPF_APPLICATION_REGISTER_K0 0
  4817. #define IPF_APPLICATION_REGISTER_K1 1
  4818. #define IPF_APPLICATION_REGISTER_K2 2
  4819. #define IPF_APPLICATION_REGISTER_K3 3
  4820. #define IPF_APPLICATION_REGISTER_K4 4
  4821. #define IPF_APPLICATION_REGISTER_K5 5
  4822. #define IPF_APPLICATION_REGISTER_K6 6
  4823. #define IPF_APPLICATION_REGISTER_K7 7
  4824. #define IPF_APPLICATION_REGISTER_RSC 16
  4825. #define IPF_APPLICATION_REGISTER_BSP 17
  4826. #define IPF_APPLICATION_REGISTER_BSPSTORE 18
  4827. #define IPF_APPLICATION_REGISTER_RNAT 19
  4828. #define IPF_APPLICATION_REGISTER_FCR 21
  4829. #define IPF_APPLICATION_REGISTER_EFLAG 24
  4830. #define IPF_APPLICATION_REGISTER_CSD 25
  4831. #define IPF_APPLICATION_REGISTER_SSD 26
  4832. #define IPF_APPLICATION_REGISTER_CFLG 27
  4833. #define IPF_APPLICATION_REGISTER_FSR 28
  4834. #define IPF_APPLICATION_REGISTER_FIR 29
  4835. #define IPF_APPLICATION_REGISTER_FDR 30
  4836. #define IPF_APPLICATION_REGISTER_CCV 32
  4837. #define IPF_APPLICATION_REGISTER_UNAT 36
  4838. #define IPF_APPLICATION_REGISTER_FPSR 40
  4839. #define IPF_APPLICATION_REGISTER_ITC 44
  4840. #define IPF_APPLICATION_REGISTER_PFS 64
  4841. #define IPF_APPLICATION_REGISTER_LC 65
  4842. #define IPF_APPLICATION_REGISTER_EC 66
  4843. /**
  4844. Reads a 64-bit application register.
  4845. Reads and returns the application register specified by Index. The valid Index
  4846. valued are defined above in "Related Definitions".
  4847. If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned. This function is only
  4848. available on Itanium processors.
  4849. @param Index The index of the application register to read.
  4850. @return The application register specified by Index.
  4851. **/
  4852. UINT64
  4853. EFIAPI
  4854. AsmReadApplicationRegister (
  4855. IN UINT64 Index
  4856. );
  4857. /**
  4858. Reads the current value of a Machine Specific Register (MSR).
  4859. Reads and returns the current value of the Machine Specific Register specified by Index. No
  4860. parameter checking is performed on Index, and if the Index value is beyond the implemented MSR
  4861. register range, a Reserved Register/Field fault may occur. The caller must either guarantee that
  4862. Index is valid, or the caller must set up fault handlers to catch the faults. This function is
  4863. only available on Itanium processors.
  4864. @param Index The 8-bit Machine Specific Register index to read.
  4865. @return The current value of the Machine Specific Register specified by Index.
  4866. **/
  4867. UINT64
  4868. EFIAPI
  4869. AsmReadMsr (
  4870. IN UINT8 Index
  4871. );
  4872. /**
  4873. Writes the current value of a Machine Specific Register (MSR).
  4874. Writes Value to the Machine Specific Register specified by Index. Value is returned. No
  4875. parameter checking is performed on Index, and if the Index value is beyond the implemented MSR
  4876. register range, a Reserved Register/Field fault may occur. The caller must either guarantee that
  4877. Index is valid, or the caller must set up fault handlers to catch the faults. This function is
  4878. only available on Itanium processors.
  4879. @param Index The 8-bit Machine Specific Register index to write.
  4880. @param Value The 64-bit value to write to the Machine Specific Register.
  4881. @return The 64-bit value to write to the Machine Specific Register.
  4882. **/
  4883. UINT64
  4884. EFIAPI
  4885. AsmWriteMsr (
  4886. IN UINT8 Index,
  4887. IN UINT64 Value
  4888. );
  4889. /**
  4890. Determines if the CPU is currently executing in virtual, physical, or mixed mode.
  4891. Determines the current execution mode of the CPU.
  4892. If the CPU is in virtual mode(PSR.RT=1, PSR.DT=1, PSR.IT=1), then 1 is returned.
  4893. If the CPU is in physical mode(PSR.RT=0, PSR.DT=0, PSR.IT=0), then 0 is returned.
  4894. If the CPU is not in physical mode or virtual mode, then it is in mixed mode,
  4895. and -1 is returned.
  4896. This function is only available on Itanium processors.
  4897. @retval 1 The CPU is in virtual mode.
  4898. @retval 0 The CPU is in physical mode.
  4899. @retval -1 The CPU is in mixed mode.
  4900. **/
  4901. INT64
  4902. EFIAPI
  4903. AsmCpuVirtual (
  4904. VOID
  4905. );
  4906. /**
  4907. Makes a PAL procedure call.
  4908. This is a wrapper function to make a PAL procedure call. Based on the Index
  4909. value this API will make static or stacked PAL call. The following table
  4910. describes the usage of PAL Procedure Index Assignment. Architected procedures
  4911. may be designated as required or optional. If a PAL procedure is specified
  4912. as optional, a unique return code of 0xFFFFFFFFFFFFFFFF is returned in the
  4913. Status field of the PAL_CALL_RETURN structure.
  4914. This indicates that the procedure is not present in this PAL implementation.
  4915. It is the caller's responsibility to check for this return code after calling
  4916. any optional PAL procedure.
  4917. No parameter checking is performed on the 5 input parameters, but there are
  4918. some common rules that the caller should follow when making a PAL call. Any
  4919. address passed to PAL as buffers for return parameters must be 8-byte aligned.
  4920. Unaligned addresses may cause undefined results. For those parameters defined
  4921. as reserved or some fields defined as reserved must be zero filled or the invalid
  4922. argument return value may be returned or undefined result may occur during the
  4923. execution of the procedure. If the PalEntryPoint does not point to a valid
  4924. PAL entry point then the system behavior is undefined. This function is only
  4925. available on Itanium processors.
  4926. @param PalEntryPoint The PAL procedure calls entry point.
  4927. @param Index The PAL procedure Index number.
  4928. @param Arg2 The 2nd parameter for PAL procedure calls.
  4929. @param Arg3 The 3rd parameter for PAL procedure calls.
  4930. @param Arg4 The 4th parameter for PAL procedure calls.
  4931. @return structure returned from the PAL Call procedure, including the status and return value.
  4932. **/
  4933. PAL_CALL_RETURN
  4934. EFIAPI
  4935. AsmPalCall (
  4936. IN UINT64 PalEntryPoint,
  4937. IN UINT64 Index,
  4938. IN UINT64 Arg2,
  4939. IN UINT64 Arg3,
  4940. IN UINT64 Arg4
  4941. );
  4942. #endif
  4943. #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
  4944. ///
  4945. /// IA32 and x64 Specific Functions.
  4946. /// Byte packed structure for 16-bit Real Mode EFLAGS.
  4947. ///
  4948. typedef union {
  4949. struct {
  4950. UINT32 CF:1; ///< Carry Flag.
  4951. UINT32 Reserved_0:1; ///< Reserved.
  4952. UINT32 PF:1; ///< Parity Flag.
  4953. UINT32 Reserved_1:1; ///< Reserved.
  4954. UINT32 AF:1; ///< Auxiliary Carry Flag.
  4955. UINT32 Reserved_2:1; ///< Reserved.
  4956. UINT32 ZF:1; ///< Zero Flag.
  4957. UINT32 SF:1; ///< Sign Flag.
  4958. UINT32 TF:1; ///< Trap Flag.
  4959. UINT32 IF:1; ///< Interrupt Enable Flag.
  4960. UINT32 DF:1; ///< Direction Flag.
  4961. UINT32 OF:1; ///< Overflow Flag.
  4962. UINT32 IOPL:2; ///< I/O Privilege Level.
  4963. UINT32 NT:1; ///< Nested Task.
  4964. UINT32 Reserved_3:1; ///< Reserved.
  4965. } Bits;
  4966. UINT16 Uint16;
  4967. } IA32_FLAGS16;
  4968. ///
  4969. /// Byte packed structure for EFLAGS/RFLAGS.
  4970. /// 32-bits on IA-32.
  4971. /// 64-bits on x64. The upper 32-bits on x64 are reserved.
  4972. ///
  4973. typedef union {
  4974. struct {
  4975. UINT32 CF:1; ///< Carry Flag.
  4976. UINT32 Reserved_0:1; ///< Reserved.
  4977. UINT32 PF:1; ///< Parity Flag.
  4978. UINT32 Reserved_1:1; ///< Reserved.
  4979. UINT32 AF:1; ///< Auxiliary Carry Flag.
  4980. UINT32 Reserved_2:1; ///< Reserved.
  4981. UINT32 ZF:1; ///< Zero Flag.
  4982. UINT32 SF:1; ///< Sign Flag.
  4983. UINT32 TF:1; ///< Trap Flag.
  4984. UINT32 IF:1; ///< Interrupt Enable Flag.
  4985. UINT32 DF:1; ///< Direction Flag.
  4986. UINT32 OF:1; ///< Overflow Flag.
  4987. UINT32 IOPL:2; ///< I/O Privilege Level.
  4988. UINT32 NT:1; ///< Nested Task.
  4989. UINT32 Reserved_3:1; ///< Reserved.
  4990. UINT32 RF:1; ///< Resume Flag.
  4991. UINT32 VM:1; ///< Virtual 8086 Mode.
  4992. UINT32 AC:1; ///< Alignment Check.
  4993. UINT32 VIF:1; ///< Virtual Interrupt Flag.
  4994. UINT32 VIP:1; ///< Virtual Interrupt Pending.
  4995. UINT32 ID:1; ///< ID Flag.
  4996. UINT32 Reserved_4:10; ///< Reserved.
  4997. } Bits;
  4998. UINTN UintN;
  4999. } IA32_EFLAGS32;
  5000. ///
  5001. /// Byte packed structure for Control Register 0 (CR0).
  5002. /// 32-bits on IA-32.
  5003. /// 64-bits on x64. The upper 32-bits on x64 are reserved.
  5004. ///
  5005. typedef union {
  5006. struct {
  5007. UINT32 PE:1; ///< Protection Enable.
  5008. UINT32 MP:1; ///< Monitor Coprocessor.
  5009. UINT32 EM:1; ///< Emulation.
  5010. UINT32 TS:1; ///< Task Switched.
  5011. UINT32 ET:1; ///< Extension Type.
  5012. UINT32 NE:1; ///< Numeric Error.
  5013. UINT32 Reserved_0:10; ///< Reserved.
  5014. UINT32 WP:1; ///< Write Protect.
  5015. UINT32 Reserved_1:1; ///< Reserved.
  5016. UINT32 AM:1; ///< Alignment Mask.
  5017. UINT32 Reserved_2:10; ///< Reserved.
  5018. UINT32 NW:1; ///< Mot Write-through.
  5019. UINT32 CD:1; ///< Cache Disable.
  5020. UINT32 PG:1; ///< Paging.
  5021. } Bits;
  5022. UINTN UintN;
  5023. } IA32_CR0;
  5024. ///
  5025. /// Byte packed structure for Control Register 4 (CR4).
  5026. /// 32-bits on IA-32.
  5027. /// 64-bits on x64. The upper 32-bits on x64 are reserved.
  5028. ///
  5029. typedef union {
  5030. struct {
  5031. UINT32 VME:1; ///< Virtual-8086 Mode Extensions.
  5032. UINT32 PVI:1; ///< Protected-Mode Virtual Interrupts.
  5033. UINT32 TSD:1; ///< Time Stamp Disable.
  5034. UINT32 DE:1; ///< Debugging Extensions.
  5035. UINT32 PSE:1; ///< Page Size Extensions.
  5036. UINT32 PAE:1; ///< Physical Address Extension.
  5037. UINT32 MCE:1; ///< Machine Check Enable.
  5038. UINT32 PGE:1; ///< Page Global Enable.
  5039. UINT32 PCE:1; ///< Performance Monitoring Counter
  5040. ///< Enable.
  5041. UINT32 OSFXSR:1; ///< Operating System Support for
  5042. ///< FXSAVE and FXRSTOR instructions
  5043. UINT32 OSXMMEXCPT:1; ///< Operating System Support for
  5044. ///< Unmasked SIMD Floating Point
  5045. ///< Exceptions.
  5046. UINT32 Reserved_0:2; ///< Reserved.
  5047. UINT32 VMXE:1; ///< VMX Enable
  5048. UINT32 Reserved_1:18; ///< Reserved.
  5049. } Bits;
  5050. UINTN UintN;
  5051. } IA32_CR4;
  5052. ///
  5053. /// Byte packed structure for a segment descriptor in a GDT/LDT.
  5054. ///
  5055. typedef union {
  5056. struct {
  5057. UINT32 LimitLow:16;
  5058. UINT32 BaseLow:16;
  5059. UINT32 BaseMid:8;
  5060. UINT32 Type:4;
  5061. UINT32 S:1;
  5062. UINT32 DPL:2;
  5063. UINT32 P:1;
  5064. UINT32 LimitHigh:4;
  5065. UINT32 AVL:1;
  5066. UINT32 L:1;
  5067. UINT32 DB:1;
  5068. UINT32 G:1;
  5069. UINT32 BaseHigh:8;
  5070. } Bits;
  5071. UINT64 Uint64;
  5072. } IA32_SEGMENT_DESCRIPTOR;
  5073. ///
  5074. /// Byte packed structure for an IDTR, GDTR, LDTR descriptor.
  5075. ///
  5076. #pragma pack (1)
  5077. typedef struct {
  5078. UINT16 Limit;
  5079. UINTN Base;
  5080. } IA32_DESCRIPTOR;
  5081. #pragma pack ()
  5082. #define IA32_IDT_GATE_TYPE_TASK 0x85
  5083. #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
  5084. #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
  5085. #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
  5086. #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
  5087. #if defined (MDE_CPU_IA32)
  5088. ///
  5089. /// Byte packed structure for an IA-32 Interrupt Gate Descriptor.
  5090. ///
  5091. typedef union {
  5092. struct {
  5093. UINT32 OffsetLow:16; ///< Offset bits 15..0.
  5094. UINT32 Selector:16; ///< Selector.
  5095. UINT32 Reserved_0:8; ///< Reserved.
  5096. UINT32 GateType:8; ///< Gate Type. See #defines above.
  5097. UINT32 OffsetHigh:16; ///< Offset bits 31..16.
  5098. } Bits;
  5099. UINT64 Uint64;
  5100. } IA32_IDT_GATE_DESCRIPTOR;
  5101. #endif
  5102. #if defined (MDE_CPU_X64)
  5103. ///
  5104. /// Byte packed structure for an x64 Interrupt Gate Descriptor.
  5105. ///
  5106. typedef union {
  5107. struct {
  5108. UINT32 OffsetLow:16; ///< Offset bits 15..0.
  5109. UINT32 Selector:16; ///< Selector.
  5110. UINT32 Reserved_0:8; ///< Reserved.
  5111. UINT32 GateType:8; ///< Gate Type. See #defines above.
  5112. UINT32 OffsetHigh:16; ///< Offset bits 31..16.
  5113. UINT32 OffsetUpper:32; ///< Offset bits 63..32.
  5114. UINT32 Reserved_1:32; ///< Reserved.
  5115. } Bits;
  5116. struct {
  5117. UINT64 Uint64;
  5118. UINT64 Uint64_1;
  5119. } Uint128;
  5120. } IA32_IDT_GATE_DESCRIPTOR;
  5121. #endif
  5122. ///
  5123. /// Byte packed structure for an FP/SSE/SSE2 context.
  5124. ///
  5125. typedef struct {
  5126. UINT8 Buffer[512];
  5127. } IA32_FX_BUFFER;
  5128. ///
  5129. /// Structures for the 16-bit real mode thunks.
  5130. ///
  5131. typedef struct {
  5132. UINT32 Reserved1;
  5133. UINT32 Reserved2;
  5134. UINT32 Reserved3;
  5135. UINT32 Reserved4;
  5136. UINT8 BL;
  5137. UINT8 BH;
  5138. UINT16 Reserved5;
  5139. UINT8 DL;
  5140. UINT8 DH;
  5141. UINT16 Reserved6;
  5142. UINT8 CL;
  5143. UINT8 CH;
  5144. UINT16 Reserved7;
  5145. UINT8 AL;
  5146. UINT8 AH;
  5147. UINT16 Reserved8;
  5148. } IA32_BYTE_REGS;
  5149. typedef struct {
  5150. UINT16 DI;
  5151. UINT16 Reserved1;
  5152. UINT16 SI;
  5153. UINT16 Reserved2;
  5154. UINT16 BP;
  5155. UINT16 Reserved3;
  5156. UINT16 SP;
  5157. UINT16 Reserved4;
  5158. UINT16 BX;
  5159. UINT16 Reserved5;
  5160. UINT16 DX;
  5161. UINT16 Reserved6;
  5162. UINT16 CX;
  5163. UINT16 Reserved7;
  5164. UINT16 AX;
  5165. UINT16 Reserved8;
  5166. } IA32_WORD_REGS;
  5167. typedef struct {
  5168. UINT32 EDI;
  5169. UINT32 ESI;
  5170. UINT32 EBP;
  5171. UINT32 ESP;
  5172. UINT32 EBX;
  5173. UINT32 EDX;
  5174. UINT32 ECX;
  5175. UINT32 EAX;
  5176. UINT16 DS;
  5177. UINT16 ES;
  5178. UINT16 FS;
  5179. UINT16 GS;
  5180. IA32_EFLAGS32 EFLAGS;
  5181. UINT32 Eip;
  5182. UINT16 CS;
  5183. UINT16 SS;
  5184. } IA32_DWORD_REGS;
  5185. typedef union {
  5186. IA32_DWORD_REGS E;
  5187. IA32_WORD_REGS X;
  5188. IA32_BYTE_REGS H;
  5189. } IA32_REGISTER_SET;
  5190. ///
  5191. /// Byte packed structure for an 16-bit real mode thunks.
  5192. ///
  5193. typedef struct {
  5194. IA32_REGISTER_SET *RealModeState;
  5195. VOID *RealModeBuffer;
  5196. UINT32 RealModeBufferSize;
  5197. UINT32 ThunkAttributes;
  5198. } THUNK_CONTEXT;
  5199. #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
  5200. #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
  5201. #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
  5202. /**
  5203. Retrieves CPUID information.
  5204. Executes the CPUID instruction with EAX set to the value specified by Index.
  5205. This function always returns Index.
  5206. If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
  5207. If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
  5208. If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
  5209. If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
  5210. This function is only available on IA-32 and x64.
  5211. @param Index The 32-bit value to load into EAX prior to invoking the CPUID
  5212. instruction.
  5213. @param Eax The pointer to the 32-bit EAX value returned by the CPUID
  5214. instruction. This is an optional parameter that may be NULL.
  5215. @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
  5216. instruction. This is an optional parameter that may be NULL.
  5217. @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
  5218. instruction. This is an optional parameter that may be NULL.
  5219. @param Edx The pointer to the 32-bit EDX value returned by the CPUID
  5220. instruction. This is an optional parameter that may be NULL.
  5221. @return Index.
  5222. **/
  5223. UINT32
  5224. EFIAPI
  5225. AsmCpuid (
  5226. IN UINT32 Index,
  5227. OUT UINT32 *Eax, OPTIONAL
  5228. OUT UINT32 *Ebx, OPTIONAL
  5229. OUT UINT32 *Ecx, OPTIONAL
  5230. OUT UINT32 *Edx OPTIONAL
  5231. );
  5232. /**
  5233. Retrieves CPUID information using an extended leaf identifier.
  5234. Executes the CPUID instruction with EAX set to the value specified by Index
  5235. and ECX set to the value specified by SubIndex. This function always returns
  5236. Index. This function is only available on IA-32 and x64.
  5237. If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
  5238. If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
  5239. If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
  5240. If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
  5241. @param Index The 32-bit value to load into EAX prior to invoking the
  5242. CPUID instruction.
  5243. @param SubIndex The 32-bit value to load into ECX prior to invoking the
  5244. CPUID instruction.
  5245. @param Eax The pointer to the 32-bit EAX value returned by the CPUID
  5246. instruction. This is an optional parameter that may be
  5247. NULL.
  5248. @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
  5249. instruction. This is an optional parameter that may be
  5250. NULL.
  5251. @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
  5252. instruction. This is an optional parameter that may be
  5253. NULL.
  5254. @param Edx The pointer to the 32-bit EDX value returned by the CPUID
  5255. instruction. This is an optional parameter that may be
  5256. NULL.
  5257. @return Index.
  5258. **/
  5259. UINT32
  5260. EFIAPI
  5261. AsmCpuidEx (
  5262. IN UINT32 Index,
  5263. IN UINT32 SubIndex,
  5264. OUT UINT32 *Eax, OPTIONAL
  5265. OUT UINT32 *Ebx, OPTIONAL
  5266. OUT UINT32 *Ecx, OPTIONAL
  5267. OUT UINT32 *Edx OPTIONAL
  5268. );
  5269. /**
  5270. Set CD bit and clear NW bit of CR0 followed by a WBINVD.
  5271. Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,
  5272. and executing a WBINVD instruction. This function is only available on IA-32 and x64.
  5273. **/
  5274. VOID
  5275. EFIAPI
  5276. AsmDisableCache (
  5277. VOID
  5278. );
  5279. /**
  5280. Perform a WBINVD and clear both the CD and NW bits of CR0.
  5281. Enables the caches by executing a WBINVD instruction and then clear both the CD and NW
  5282. bits of CR0 to 0. This function is only available on IA-32 and x64.
  5283. **/
  5284. VOID
  5285. EFIAPI
  5286. AsmEnableCache (
  5287. VOID
  5288. );
  5289. /**
  5290. Returns the lower 32-bits of a Machine Specific Register(MSR).
  5291. Reads and returns the lower 32-bits of the MSR specified by Index.
  5292. No parameter checking is performed on Index, and some Index values may cause
  5293. CPU exceptions. The caller must either guarantee that Index is valid, or the
  5294. caller must set up exception handlers to catch the exceptions. This function
  5295. is only available on IA-32 and x64.
  5296. @param Index The 32-bit MSR index to read.
  5297. @return The lower 32 bits of the MSR identified by Index.
  5298. **/
  5299. UINT32
  5300. EFIAPI
  5301. AsmReadMsr32 (
  5302. IN UINT32 Index
  5303. );
  5304. /**
  5305. Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.
  5306. The upper 32-bits of the MSR are set to zero.
  5307. Writes the 32-bit value specified by Value to the MSR specified by Index. The
  5308. upper 32-bits of the MSR write are set to zero. The 32-bit value written to
  5309. the MSR is returned. No parameter checking is performed on Index or Value,
  5310. and some of these may cause CPU exceptions. The caller must either guarantee
  5311. that Index and Value are valid, or the caller must establish proper exception
  5312. handlers. This function is only available on IA-32 and x64.
  5313. @param Index The 32-bit MSR index to write.
  5314. @param Value The 32-bit value to write to the MSR.
  5315. @return Value
  5316. **/
  5317. UINT32
  5318. EFIAPI
  5319. AsmWriteMsr32 (
  5320. IN UINT32 Index,
  5321. IN UINT32 Value
  5322. );
  5323. /**
  5324. Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and
  5325. writes the result back to the 64-bit MSR.
  5326. Reads the 64-bit MSR specified by Index, performs a bitwise OR
  5327. between the lower 32-bits of the read result and the value specified by
  5328. OrData, and writes the result to the 64-bit MSR specified by Index. The lower
  5329. 32-bits of the value written to the MSR is returned. No parameter checking is
  5330. performed on Index or OrData, and some of these may cause CPU exceptions. The
  5331. caller must either guarantee that Index and OrData are valid, or the caller
  5332. must establish proper exception handlers. This function is only available on
  5333. IA-32 and x64.
  5334. @param Index The 32-bit MSR index to write.
  5335. @param OrData The value to OR with the read value from the MSR.
  5336. @return The lower 32-bit value written to the MSR.
  5337. **/
  5338. UINT32
  5339. EFIAPI
  5340. AsmMsrOr32 (
  5341. IN UINT32 Index,
  5342. IN UINT32 OrData
  5343. );
  5344. /**
  5345. Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
  5346. the result back to the 64-bit MSR.
  5347. Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
  5348. lower 32-bits of the read result and the value specified by AndData, and
  5349. writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
  5350. the value written to the MSR is returned. No parameter checking is performed
  5351. on Index or AndData, and some of these may cause CPU exceptions. The caller
  5352. must either guarantee that Index and AndData are valid, or the caller must
  5353. establish proper exception handlers. This function is only available on IA-32
  5354. and x64.
  5355. @param Index The 32-bit MSR index to write.
  5356. @param AndData The value to AND with the read value from the MSR.
  5357. @return The lower 32-bit value written to the MSR.
  5358. **/
  5359. UINT32
  5360. EFIAPI
  5361. AsmMsrAnd32 (
  5362. IN UINT32 Index,
  5363. IN UINT32 AndData
  5364. );
  5365. /**
  5366. Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR
  5367. on the lower 32-bits, and writes the result back to the 64-bit MSR.
  5368. Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
  5369. lower 32-bits of the read result and the value specified by AndData
  5370. preserving the upper 32-bits, performs a bitwise OR between the
  5371. result of the AND operation and the value specified by OrData, and writes the
  5372. result to the 64-bit MSR specified by Address. The lower 32-bits of the value
  5373. written to the MSR is returned. No parameter checking is performed on Index,
  5374. AndData, or OrData, and some of these may cause CPU exceptions. The caller
  5375. must either guarantee that Index, AndData, and OrData are valid, or the
  5376. caller must establish proper exception handlers. This function is only
  5377. available on IA-32 and x64.
  5378. @param Index The 32-bit MSR index to write.
  5379. @param AndData The value to AND with the read value from the MSR.
  5380. @param OrData The value to OR with the result of the AND operation.
  5381. @return The lower 32-bit value written to the MSR.
  5382. **/
  5383. UINT32
  5384. EFIAPI
  5385. AsmMsrAndThenOr32 (
  5386. IN UINT32 Index,
  5387. IN UINT32 AndData,
  5388. IN UINT32 OrData
  5389. );
  5390. /**
  5391. Reads a bit field of an MSR.
  5392. Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
  5393. specified by the StartBit and the EndBit. The value of the bit field is
  5394. returned. The caller must either guarantee that Index is valid, or the caller
  5395. must set up exception handlers to catch the exceptions. This function is only
  5396. available on IA-32 and x64.
  5397. If StartBit is greater than 31, then ASSERT().
  5398. If EndBit is greater than 31, then ASSERT().
  5399. If EndBit is less than StartBit, then ASSERT().
  5400. @param Index The 32-bit MSR index to read.
  5401. @param StartBit The ordinal of the least significant bit in the bit field.
  5402. Range 0..31.
  5403. @param EndBit The ordinal of the most significant bit in the bit field.
  5404. Range 0..31.
  5405. @return The bit field read from the MSR.
  5406. **/
  5407. UINT32
  5408. EFIAPI
  5409. AsmMsrBitFieldRead32 (
  5410. IN UINT32 Index,
  5411. IN UINTN StartBit,
  5412. IN UINTN EndBit
  5413. );
  5414. /**
  5415. Writes a bit field to an MSR.
  5416. Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
  5417. field is specified by the StartBit and the EndBit. All other bits in the
  5418. destination MSR are preserved. The lower 32-bits of the MSR written is
  5419. returned. The caller must either guarantee that Index and the data written
  5420. is valid, or the caller must set up exception handlers to catch the exceptions.
  5421. This function is only available on IA-32 and x64.
  5422. If StartBit is greater than 31, then ASSERT().
  5423. If EndBit is greater than 31, then ASSERT().
  5424. If EndBit is less than StartBit, then ASSERT().
  5425. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5426. @param Index The 32-bit MSR index to write.
  5427. @param StartBit The ordinal of the least significant bit in the bit field.
  5428. Range 0..31.
  5429. @param EndBit The ordinal of the most significant bit in the bit field.
  5430. Range 0..31.
  5431. @param Value New value of the bit field.
  5432. @return The lower 32-bit of the value written to the MSR.
  5433. **/
  5434. UINT32
  5435. EFIAPI
  5436. AsmMsrBitFieldWrite32 (
  5437. IN UINT32 Index,
  5438. IN UINTN StartBit,
  5439. IN UINTN EndBit,
  5440. IN UINT32 Value
  5441. );
  5442. /**
  5443. Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
  5444. result back to the bit field in the 64-bit MSR.
  5445. Reads the 64-bit MSR specified by Index, performs a bitwise OR
  5446. between the read result and the value specified by OrData, and writes the
  5447. result to the 64-bit MSR specified by Index. The lower 32-bits of the value
  5448. written to the MSR are returned. Extra left bits in OrData are stripped. The
  5449. caller must either guarantee that Index and the data written is valid, or
  5450. the caller must set up exception handlers to catch the exceptions. This
  5451. function is only available on IA-32 and x64.
  5452. If StartBit is greater than 31, then ASSERT().
  5453. If EndBit is greater than 31, then ASSERT().
  5454. If EndBit is less than StartBit, then ASSERT().
  5455. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5456. @param Index The 32-bit MSR index to write.
  5457. @param StartBit The ordinal of the least significant bit in the bit field.
  5458. Range 0..31.
  5459. @param EndBit The ordinal of the most significant bit in the bit field.
  5460. Range 0..31.
  5461. @param OrData The value to OR with the read value from the MSR.
  5462. @return The lower 32-bit of the value written to the MSR.
  5463. **/
  5464. UINT32
  5465. EFIAPI
  5466. AsmMsrBitFieldOr32 (
  5467. IN UINT32 Index,
  5468. IN UINTN StartBit,
  5469. IN UINTN EndBit,
  5470. IN UINT32 OrData
  5471. );
  5472. /**
  5473. Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
  5474. result back to the bit field in the 64-bit MSR.
  5475. Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
  5476. read result and the value specified by AndData, and writes the result to the
  5477. 64-bit MSR specified by Index. The lower 32-bits of the value written to the
  5478. MSR are returned. Extra left bits in AndData are stripped. The caller must
  5479. either guarantee that Index and the data written is valid, or the caller must
  5480. set up exception handlers to catch the exceptions. This function is only
  5481. available on IA-32 and x64.
  5482. If StartBit is greater than 31, then ASSERT().
  5483. If EndBit is greater than 31, then ASSERT().
  5484. If EndBit is less than StartBit, then ASSERT().
  5485. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5486. @param Index The 32-bit MSR index to write.
  5487. @param StartBit The ordinal of the least significant bit in the bit field.
  5488. Range 0..31.
  5489. @param EndBit The ordinal of the most significant bit in the bit field.
  5490. Range 0..31.
  5491. @param AndData The value to AND with the read value from the MSR.
  5492. @return The lower 32-bit of the value written to the MSR.
  5493. **/
  5494. UINT32
  5495. EFIAPI
  5496. AsmMsrBitFieldAnd32 (
  5497. IN UINT32 Index,
  5498. IN UINTN StartBit,
  5499. IN UINTN EndBit,
  5500. IN UINT32 AndData
  5501. );
  5502. /**
  5503. Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
  5504. bitwise OR, and writes the result back to the bit field in the
  5505. 64-bit MSR.
  5506. Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
  5507. bitwise OR between the read result and the value specified by
  5508. AndData, and writes the result to the 64-bit MSR specified by Index. The
  5509. lower 32-bits of the value written to the MSR are returned. Extra left bits
  5510. in both AndData and OrData are stripped. The caller must either guarantee
  5511. that Index and the data written is valid, or the caller must set up exception
  5512. handlers to catch the exceptions. This function is only available on IA-32
  5513. and x64.
  5514. If StartBit is greater than 31, then ASSERT().
  5515. If EndBit is greater than 31, then ASSERT().
  5516. If EndBit is less than StartBit, then ASSERT().
  5517. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5518. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5519. @param Index The 32-bit MSR index to write.
  5520. @param StartBit The ordinal of the least significant bit in the bit field.
  5521. Range 0..31.
  5522. @param EndBit The ordinal of the most significant bit in the bit field.
  5523. Range 0..31.
  5524. @param AndData The value to AND with the read value from the MSR.
  5525. @param OrData The value to OR with the result of the AND operation.
  5526. @return The lower 32-bit of the value written to the MSR.
  5527. **/
  5528. UINT32
  5529. EFIAPI
  5530. AsmMsrBitFieldAndThenOr32 (
  5531. IN UINT32 Index,
  5532. IN UINTN StartBit,
  5533. IN UINTN EndBit,
  5534. IN UINT32 AndData,
  5535. IN UINT32 OrData
  5536. );
  5537. /**
  5538. Returns a 64-bit Machine Specific Register(MSR).
  5539. Reads and returns the 64-bit MSR specified by Index. No parameter checking is
  5540. performed on Index, and some Index values may cause CPU exceptions. The
  5541. caller must either guarantee that Index is valid, or the caller must set up
  5542. exception handlers to catch the exceptions. This function is only available
  5543. on IA-32 and x64.
  5544. @param Index The 32-bit MSR index to read.
  5545. @return The value of the MSR identified by Index.
  5546. **/
  5547. UINT64
  5548. EFIAPI
  5549. AsmReadMsr64 (
  5550. IN UINT32 Index
  5551. );
  5552. /**
  5553. Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
  5554. value.
  5555. Writes the 64-bit value specified by Value to the MSR specified by Index. The
  5556. 64-bit value written to the MSR is returned. No parameter checking is
  5557. performed on Index or Value, and some of these may cause CPU exceptions. The
  5558. caller must either guarantee that Index and Value are valid, or the caller
  5559. must establish proper exception handlers. This function is only available on
  5560. IA-32 and x64.
  5561. @param Index The 32-bit MSR index to write.
  5562. @param Value The 64-bit value to write to the MSR.
  5563. @return Value
  5564. **/
  5565. UINT64
  5566. EFIAPI
  5567. AsmWriteMsr64 (
  5568. IN UINT32 Index,
  5569. IN UINT64 Value
  5570. );
  5571. /**
  5572. Reads a 64-bit MSR, performs a bitwise OR, and writes the result
  5573. back to the 64-bit MSR.
  5574. Reads the 64-bit MSR specified by Index, performs a bitwise OR
  5575. between the read result and the value specified by OrData, and writes the
  5576. result to the 64-bit MSR specified by Index. The value written to the MSR is
  5577. returned. No parameter checking is performed on Index or OrData, and some of
  5578. these may cause CPU exceptions. The caller must either guarantee that Index
  5579. and OrData are valid, or the caller must establish proper exception handlers.
  5580. This function is only available on IA-32 and x64.
  5581. @param Index The 32-bit MSR index to write.
  5582. @param OrData The value to OR with the read value from the MSR.
  5583. @return The value written back to the MSR.
  5584. **/
  5585. UINT64
  5586. EFIAPI
  5587. AsmMsrOr64 (
  5588. IN UINT32 Index,
  5589. IN UINT64 OrData
  5590. );
  5591. /**
  5592. Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
  5593. 64-bit MSR.
  5594. Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
  5595. read result and the value specified by OrData, and writes the result to the
  5596. 64-bit MSR specified by Index. The value written to the MSR is returned. No
  5597. parameter checking is performed on Index or OrData, and some of these may
  5598. cause CPU exceptions. The caller must either guarantee that Index and OrData
  5599. are valid, or the caller must establish proper exception handlers. This
  5600. function is only available on IA-32 and x64.
  5601. @param Index The 32-bit MSR index to write.
  5602. @param AndData The value to AND with the read value from the MSR.
  5603. @return The value written back to the MSR.
  5604. **/
  5605. UINT64
  5606. EFIAPI
  5607. AsmMsrAnd64 (
  5608. IN UINT32 Index,
  5609. IN UINT64 AndData
  5610. );
  5611. /**
  5612. Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise
  5613. OR, and writes the result back to the 64-bit MSR.
  5614. Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
  5615. result and the value specified by AndData, performs a bitwise OR
  5616. between the result of the AND operation and the value specified by OrData,
  5617. and writes the result to the 64-bit MSR specified by Index. The value written
  5618. to the MSR is returned. No parameter checking is performed on Index, AndData,
  5619. or OrData, and some of these may cause CPU exceptions. The caller must either
  5620. guarantee that Index, AndData, and OrData are valid, or the caller must
  5621. establish proper exception handlers. This function is only available on IA-32
  5622. and x64.
  5623. @param Index The 32-bit MSR index to write.
  5624. @param AndData The value to AND with the read value from the MSR.
  5625. @param OrData The value to OR with the result of the AND operation.
  5626. @return The value written back to the MSR.
  5627. **/
  5628. UINT64
  5629. EFIAPI
  5630. AsmMsrAndThenOr64 (
  5631. IN UINT32 Index,
  5632. IN UINT64 AndData,
  5633. IN UINT64 OrData
  5634. );
  5635. /**
  5636. Reads a bit field of an MSR.
  5637. Reads the bit field in the 64-bit MSR. The bit field is specified by the
  5638. StartBit and the EndBit. The value of the bit field is returned. The caller
  5639. must either guarantee that Index is valid, or the caller must set up
  5640. exception handlers to catch the exceptions. This function is only available
  5641. on IA-32 and x64.
  5642. If StartBit is greater than 63, then ASSERT().
  5643. If EndBit is greater than 63, then ASSERT().
  5644. If EndBit is less than StartBit, then ASSERT().
  5645. @param Index The 32-bit MSR index to read.
  5646. @param StartBit The ordinal of the least significant bit in the bit field.
  5647. Range 0..63.
  5648. @param EndBit The ordinal of the most significant bit in the bit field.
  5649. Range 0..63.
  5650. @return The value read from the MSR.
  5651. **/
  5652. UINT64
  5653. EFIAPI
  5654. AsmMsrBitFieldRead64 (
  5655. IN UINT32 Index,
  5656. IN UINTN StartBit,
  5657. IN UINTN EndBit
  5658. );
  5659. /**
  5660. Writes a bit field to an MSR.
  5661. Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
  5662. the StartBit and the EndBit. All other bits in the destination MSR are
  5663. preserved. The MSR written is returned. The caller must either guarantee
  5664. that Index and the data written is valid, or the caller must set up exception
  5665. handlers to catch the exceptions. This function is only available on IA-32 and x64.
  5666. If StartBit is greater than 63, then ASSERT().
  5667. If EndBit is greater than 63, then ASSERT().
  5668. If EndBit is less than StartBit, then ASSERT().
  5669. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5670. @param Index The 32-bit MSR index to write.
  5671. @param StartBit The ordinal of the least significant bit in the bit field.
  5672. Range 0..63.
  5673. @param EndBit The ordinal of the most significant bit in the bit field.
  5674. Range 0..63.
  5675. @param Value New value of the bit field.
  5676. @return The value written back to the MSR.
  5677. **/
  5678. UINT64
  5679. EFIAPI
  5680. AsmMsrBitFieldWrite64 (
  5681. IN UINT32 Index,
  5682. IN UINTN StartBit,
  5683. IN UINTN EndBit,
  5684. IN UINT64 Value
  5685. );
  5686. /**
  5687. Reads a bit field in a 64-bit MSR, performs a bitwise OR, and
  5688. writes the result back to the bit field in the 64-bit MSR.
  5689. Reads the 64-bit MSR specified by Index, performs a bitwise OR
  5690. between the read result and the value specified by OrData, and writes the
  5691. result to the 64-bit MSR specified by Index. The value written to the MSR is
  5692. returned. Extra left bits in OrData are stripped. The caller must either
  5693. guarantee that Index and the data written is valid, or the caller must set up
  5694. exception handlers to catch the exceptions. This function is only available
  5695. on IA-32 and x64.
  5696. If StartBit is greater than 63, then ASSERT().
  5697. If EndBit is greater than 63, then ASSERT().
  5698. If EndBit is less than StartBit, then ASSERT().
  5699. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5700. @param Index The 32-bit MSR index to write.
  5701. @param StartBit The ordinal of the least significant bit in the bit field.
  5702. Range 0..63.
  5703. @param EndBit The ordinal of the most significant bit in the bit field.
  5704. Range 0..63.
  5705. @param OrData The value to OR with the read value from the bit field.
  5706. @return The value written back to the MSR.
  5707. **/
  5708. UINT64
  5709. EFIAPI
  5710. AsmMsrBitFieldOr64 (
  5711. IN UINT32 Index,
  5712. IN UINTN StartBit,
  5713. IN UINTN EndBit,
  5714. IN UINT64 OrData
  5715. );
  5716. /**
  5717. Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
  5718. result back to the bit field in the 64-bit MSR.
  5719. Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
  5720. read result and the value specified by AndData, and writes the result to the
  5721. 64-bit MSR specified by Index. The value written to the MSR is returned.
  5722. Extra left bits in AndData are stripped. The caller must either guarantee
  5723. that Index and the data written is valid, or the caller must set up exception
  5724. handlers to catch the exceptions. This function is only available on IA-32
  5725. and x64.
  5726. If StartBit is greater than 63, then ASSERT().
  5727. If EndBit is greater than 63, then ASSERT().
  5728. If EndBit is less than StartBit, then ASSERT().
  5729. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5730. @param Index The 32-bit MSR index to write.
  5731. @param StartBit The ordinal of the least significant bit in the bit field.
  5732. Range 0..63.
  5733. @param EndBit The ordinal of the most significant bit in the bit field.
  5734. Range 0..63.
  5735. @param AndData The value to AND with the read value from the bit field.
  5736. @return The value written back to the MSR.
  5737. **/
  5738. UINT64
  5739. EFIAPI
  5740. AsmMsrBitFieldAnd64 (
  5741. IN UINT32 Index,
  5742. IN UINTN StartBit,
  5743. IN UINTN EndBit,
  5744. IN UINT64 AndData
  5745. );
  5746. /**
  5747. Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
  5748. bitwise OR, and writes the result back to the bit field in the
  5749. 64-bit MSR.
  5750. Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
  5751. a bitwise OR between the read result and the value specified by
  5752. AndData, and writes the result to the 64-bit MSR specified by Index. The
  5753. value written to the MSR is returned. Extra left bits in both AndData and
  5754. OrData are stripped. The caller must either guarantee that Index and the data
  5755. written is valid, or the caller must set up exception handlers to catch the
  5756. exceptions. This function is only available on IA-32 and x64.
  5757. If StartBit is greater than 63, then ASSERT().
  5758. If EndBit is greater than 63, then ASSERT().
  5759. If EndBit is less than StartBit, then ASSERT().
  5760. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5761. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  5762. @param Index The 32-bit MSR index to write.
  5763. @param StartBit The ordinal of the least significant bit in the bit field.
  5764. Range 0..63.
  5765. @param EndBit The ordinal of the most significant bit in the bit field.
  5766. Range 0..63.
  5767. @param AndData The value to AND with the read value from the bit field.
  5768. @param OrData The value to OR with the result of the AND operation.
  5769. @return The value written back to the MSR.
  5770. **/
  5771. UINT64
  5772. EFIAPI
  5773. AsmMsrBitFieldAndThenOr64 (
  5774. IN UINT32 Index,
  5775. IN UINTN StartBit,
  5776. IN UINTN EndBit,
  5777. IN UINT64 AndData,
  5778. IN UINT64 OrData
  5779. );
  5780. /**
  5781. Reads the current value of the EFLAGS register.
  5782. Reads and returns the current value of the EFLAGS register. This function is
  5783. only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a
  5784. 64-bit value on x64.
  5785. @return EFLAGS on IA-32 or RFLAGS on x64.
  5786. **/
  5787. UINTN
  5788. EFIAPI
  5789. AsmReadEflags (
  5790. VOID
  5791. );
  5792. /**
  5793. Reads the current value of the Control Register 0 (CR0).
  5794. Reads and returns the current value of CR0. This function is only available
  5795. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5796. x64.
  5797. @return The value of the Control Register 0 (CR0).
  5798. **/
  5799. UINTN
  5800. EFIAPI
  5801. AsmReadCr0 (
  5802. VOID
  5803. );
  5804. /**
  5805. Reads the current value of the Control Register 2 (CR2).
  5806. Reads and returns the current value of CR2. This function is only available
  5807. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5808. x64.
  5809. @return The value of the Control Register 2 (CR2).
  5810. **/
  5811. UINTN
  5812. EFIAPI
  5813. AsmReadCr2 (
  5814. VOID
  5815. );
  5816. /**
  5817. Reads the current value of the Control Register 3 (CR3).
  5818. Reads and returns the current value of CR3. This function is only available
  5819. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5820. x64.
  5821. @return The value of the Control Register 3 (CR3).
  5822. **/
  5823. UINTN
  5824. EFIAPI
  5825. AsmReadCr3 (
  5826. VOID
  5827. );
  5828. /**
  5829. Reads the current value of the Control Register 4 (CR4).
  5830. Reads and returns the current value of CR4. This function is only available
  5831. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5832. x64.
  5833. @return The value of the Control Register 4 (CR4).
  5834. **/
  5835. UINTN
  5836. EFIAPI
  5837. AsmReadCr4 (
  5838. VOID
  5839. );
  5840. /**
  5841. Writes a value to Control Register 0 (CR0).
  5842. Writes and returns a new value to CR0. This function is only available on
  5843. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  5844. @param Cr0 The value to write to CR0.
  5845. @return The value written to CR0.
  5846. **/
  5847. UINTN
  5848. EFIAPI
  5849. AsmWriteCr0 (
  5850. UINTN Cr0
  5851. );
  5852. /**
  5853. Writes a value to Control Register 2 (CR2).
  5854. Writes and returns a new value to CR2. This function is only available on
  5855. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  5856. @param Cr2 The value to write to CR2.
  5857. @return The value written to CR2.
  5858. **/
  5859. UINTN
  5860. EFIAPI
  5861. AsmWriteCr2 (
  5862. UINTN Cr2
  5863. );
  5864. /**
  5865. Writes a value to Control Register 3 (CR3).
  5866. Writes and returns a new value to CR3. This function is only available on
  5867. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  5868. @param Cr3 The value to write to CR3.
  5869. @return The value written to CR3.
  5870. **/
  5871. UINTN
  5872. EFIAPI
  5873. AsmWriteCr3 (
  5874. UINTN Cr3
  5875. );
  5876. /**
  5877. Writes a value to Control Register 4 (CR4).
  5878. Writes and returns a new value to CR4. This function is only available on
  5879. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  5880. @param Cr4 The value to write to CR4.
  5881. @return The value written to CR4.
  5882. **/
  5883. UINTN
  5884. EFIAPI
  5885. AsmWriteCr4 (
  5886. UINTN Cr4
  5887. );
  5888. /**
  5889. Reads the current value of Debug Register 0 (DR0).
  5890. Reads and returns the current value of DR0. This function is only available
  5891. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5892. x64.
  5893. @return The value of Debug Register 0 (DR0).
  5894. **/
  5895. UINTN
  5896. EFIAPI
  5897. AsmReadDr0 (
  5898. VOID
  5899. );
  5900. /**
  5901. Reads the current value of Debug Register 1 (DR1).
  5902. Reads and returns the current value of DR1. This function is only available
  5903. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5904. x64.
  5905. @return The value of Debug Register 1 (DR1).
  5906. **/
  5907. UINTN
  5908. EFIAPI
  5909. AsmReadDr1 (
  5910. VOID
  5911. );
  5912. /**
  5913. Reads the current value of Debug Register 2 (DR2).
  5914. Reads and returns the current value of DR2. This function is only available
  5915. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5916. x64.
  5917. @return The value of Debug Register 2 (DR2).
  5918. **/
  5919. UINTN
  5920. EFIAPI
  5921. AsmReadDr2 (
  5922. VOID
  5923. );
  5924. /**
  5925. Reads the current value of Debug Register 3 (DR3).
  5926. Reads and returns the current value of DR3. This function is only available
  5927. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5928. x64.
  5929. @return The value of Debug Register 3 (DR3).
  5930. **/
  5931. UINTN
  5932. EFIAPI
  5933. AsmReadDr3 (
  5934. VOID
  5935. );
  5936. /**
  5937. Reads the current value of Debug Register 4 (DR4).
  5938. Reads and returns the current value of DR4. This function is only available
  5939. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5940. x64.
  5941. @return The value of Debug Register 4 (DR4).
  5942. **/
  5943. UINTN
  5944. EFIAPI
  5945. AsmReadDr4 (
  5946. VOID
  5947. );
  5948. /**
  5949. Reads the current value of Debug Register 5 (DR5).
  5950. Reads and returns the current value of DR5. This function is only available
  5951. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5952. x64.
  5953. @return The value of Debug Register 5 (DR5).
  5954. **/
  5955. UINTN
  5956. EFIAPI
  5957. AsmReadDr5 (
  5958. VOID
  5959. );
  5960. /**
  5961. Reads the current value of Debug Register 6 (DR6).
  5962. Reads and returns the current value of DR6. This function is only available
  5963. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5964. x64.
  5965. @return The value of Debug Register 6 (DR6).
  5966. **/
  5967. UINTN
  5968. EFIAPI
  5969. AsmReadDr6 (
  5970. VOID
  5971. );
  5972. /**
  5973. Reads the current value of Debug Register 7 (DR7).
  5974. Reads and returns the current value of DR7. This function is only available
  5975. on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
  5976. x64.
  5977. @return The value of Debug Register 7 (DR7).
  5978. **/
  5979. UINTN
  5980. EFIAPI
  5981. AsmReadDr7 (
  5982. VOID
  5983. );
  5984. /**
  5985. Writes a value to Debug Register 0 (DR0).
  5986. Writes and returns a new value to DR0. This function is only available on
  5987. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  5988. @param Dr0 The value to write to Dr0.
  5989. @return The value written to Debug Register 0 (DR0).
  5990. **/
  5991. UINTN
  5992. EFIAPI
  5993. AsmWriteDr0 (
  5994. UINTN Dr0
  5995. );
  5996. /**
  5997. Writes a value to Debug Register 1 (DR1).
  5998. Writes and returns a new value to DR1. This function is only available on
  5999. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  6000. @param Dr1 The value to write to Dr1.
  6001. @return The value written to Debug Register 1 (DR1).
  6002. **/
  6003. UINTN
  6004. EFIAPI
  6005. AsmWriteDr1 (
  6006. UINTN Dr1
  6007. );
  6008. /**
  6009. Writes a value to Debug Register 2 (DR2).
  6010. Writes and returns a new value to DR2. This function is only available on
  6011. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  6012. @param Dr2 The value to write to Dr2.
  6013. @return The value written to Debug Register 2 (DR2).
  6014. **/
  6015. UINTN
  6016. EFIAPI
  6017. AsmWriteDr2 (
  6018. UINTN Dr2
  6019. );
  6020. /**
  6021. Writes a value to Debug Register 3 (DR3).
  6022. Writes and returns a new value to DR3. This function is only available on
  6023. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  6024. @param Dr3 The value to write to Dr3.
  6025. @return The value written to Debug Register 3 (DR3).
  6026. **/
  6027. UINTN
  6028. EFIAPI
  6029. AsmWriteDr3 (
  6030. UINTN Dr3
  6031. );
  6032. /**
  6033. Writes a value to Debug Register 4 (DR4).
  6034. Writes and returns a new value to DR4. This function is only available on
  6035. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  6036. @param Dr4 The value to write to Dr4.
  6037. @return The value written to Debug Register 4 (DR4).
  6038. **/
  6039. UINTN
  6040. EFIAPI
  6041. AsmWriteDr4 (
  6042. UINTN Dr4
  6043. );
  6044. /**
  6045. Writes a value to Debug Register 5 (DR5).
  6046. Writes and returns a new value to DR5. This function is only available on
  6047. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  6048. @param Dr5 The value to write to Dr5.
  6049. @return The value written to Debug Register 5 (DR5).
  6050. **/
  6051. UINTN
  6052. EFIAPI
  6053. AsmWriteDr5 (
  6054. UINTN Dr5
  6055. );
  6056. /**
  6057. Writes a value to Debug Register 6 (DR6).
  6058. Writes and returns a new value to DR6. This function is only available on
  6059. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  6060. @param Dr6 The value to write to Dr6.
  6061. @return The value written to Debug Register 6 (DR6).
  6062. **/
  6063. UINTN
  6064. EFIAPI
  6065. AsmWriteDr6 (
  6066. UINTN Dr6
  6067. );
  6068. /**
  6069. Writes a value to Debug Register 7 (DR7).
  6070. Writes and returns a new value to DR7. This function is only available on
  6071. IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
  6072. @param Dr7 The value to write to Dr7.
  6073. @return The value written to Debug Register 7 (DR7).
  6074. **/
  6075. UINTN
  6076. EFIAPI
  6077. AsmWriteDr7 (
  6078. UINTN Dr7
  6079. );
  6080. /**
  6081. Reads the current value of Code Segment Register (CS).
  6082. Reads and returns the current value of CS. This function is only available on
  6083. IA-32 and x64.
  6084. @return The current value of CS.
  6085. **/
  6086. UINT16
  6087. EFIAPI
  6088. AsmReadCs (
  6089. VOID
  6090. );
  6091. /**
  6092. Reads the current value of Data Segment Register (DS).
  6093. Reads and returns the current value of DS. This function is only available on
  6094. IA-32 and x64.
  6095. @return The current value of DS.
  6096. **/
  6097. UINT16
  6098. EFIAPI
  6099. AsmReadDs (
  6100. VOID
  6101. );
  6102. /**
  6103. Reads the current value of Extra Segment Register (ES).
  6104. Reads and returns the current value of ES. This function is only available on
  6105. IA-32 and x64.
  6106. @return The current value of ES.
  6107. **/
  6108. UINT16
  6109. EFIAPI
  6110. AsmReadEs (
  6111. VOID
  6112. );
  6113. /**
  6114. Reads the current value of FS Data Segment Register (FS).
  6115. Reads and returns the current value of FS. This function is only available on
  6116. IA-32 and x64.
  6117. @return The current value of FS.
  6118. **/
  6119. UINT16
  6120. EFIAPI
  6121. AsmReadFs (
  6122. VOID
  6123. );
  6124. /**
  6125. Reads the current value of GS Data Segment Register (GS).
  6126. Reads and returns the current value of GS. This function is only available on
  6127. IA-32 and x64.
  6128. @return The current value of GS.
  6129. **/
  6130. UINT16
  6131. EFIAPI
  6132. AsmReadGs (
  6133. VOID
  6134. );
  6135. /**
  6136. Reads the current value of Stack Segment Register (SS).
  6137. Reads and returns the current value of SS. This function is only available on
  6138. IA-32 and x64.
  6139. @return The current value of SS.
  6140. **/
  6141. UINT16
  6142. EFIAPI
  6143. AsmReadSs (
  6144. VOID
  6145. );
  6146. /**
  6147. Reads the current value of Task Register (TR).
  6148. Reads and returns the current value of TR. This function is only available on
  6149. IA-32 and x64.
  6150. @return The current value of TR.
  6151. **/
  6152. UINT16
  6153. EFIAPI
  6154. AsmReadTr (
  6155. VOID
  6156. );
  6157. /**
  6158. Reads the current Global Descriptor Table Register(GDTR) descriptor.
  6159. Reads and returns the current GDTR descriptor and returns it in Gdtr. This
  6160. function is only available on IA-32 and x64.
  6161. If Gdtr is NULL, then ASSERT().
  6162. @param Gdtr The pointer to a GDTR descriptor.
  6163. **/
  6164. VOID
  6165. EFIAPI
  6166. AsmReadGdtr (
  6167. OUT IA32_DESCRIPTOR *Gdtr
  6168. );
  6169. /**
  6170. Writes the current Global Descriptor Table Register (GDTR) descriptor.
  6171. Writes and the current GDTR descriptor specified by Gdtr. This function is
  6172. only available on IA-32 and x64.
  6173. If Gdtr is NULL, then ASSERT().
  6174. @param Gdtr The pointer to a GDTR descriptor.
  6175. **/
  6176. VOID
  6177. EFIAPI
  6178. AsmWriteGdtr (
  6179. IN CONST IA32_DESCRIPTOR *Gdtr
  6180. );
  6181. /**
  6182. Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.
  6183. Reads and returns the current IDTR descriptor and returns it in Idtr. This
  6184. function is only available on IA-32 and x64.
  6185. If Idtr is NULL, then ASSERT().
  6186. @param Idtr The pointer to a IDTR descriptor.
  6187. **/
  6188. VOID
  6189. EFIAPI
  6190. AsmReadIdtr (
  6191. OUT IA32_DESCRIPTOR *Idtr
  6192. );
  6193. /**
  6194. Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.
  6195. Writes the current IDTR descriptor and returns it in Idtr. This function is
  6196. only available on IA-32 and x64.
  6197. If Idtr is NULL, then ASSERT().
  6198. @param Idtr The pointer to a IDTR descriptor.
  6199. **/
  6200. VOID
  6201. EFIAPI
  6202. AsmWriteIdtr (
  6203. IN CONST IA32_DESCRIPTOR *Idtr
  6204. );
  6205. /**
  6206. Reads the current Local Descriptor Table Register(LDTR) selector.
  6207. Reads and returns the current 16-bit LDTR descriptor value. This function is
  6208. only available on IA-32 and x64.
  6209. @return The current selector of LDT.
  6210. **/
  6211. UINT16
  6212. EFIAPI
  6213. AsmReadLdtr (
  6214. VOID
  6215. );
  6216. /**
  6217. Writes the current Local Descriptor Table Register (LDTR) selector.
  6218. Writes and the current LDTR descriptor specified by Ldtr. This function is
  6219. only available on IA-32 and x64.
  6220. @param Ldtr 16-bit LDTR selector value.
  6221. **/
  6222. VOID
  6223. EFIAPI
  6224. AsmWriteLdtr (
  6225. IN UINT16 Ldtr
  6226. );
  6227. /**
  6228. Save the current floating point/SSE/SSE2 context to a buffer.
  6229. Saves the current floating point/SSE/SSE2 state to the buffer specified by
  6230. Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
  6231. available on IA-32 and x64.
  6232. If Buffer is NULL, then ASSERT().
  6233. If Buffer is not aligned on a 16-byte boundary, then ASSERT().
  6234. @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
  6235. **/
  6236. VOID
  6237. EFIAPI
  6238. AsmFxSave (
  6239. OUT IA32_FX_BUFFER *Buffer
  6240. );
  6241. /**
  6242. Restores the current floating point/SSE/SSE2 context from a buffer.
  6243. Restores the current floating point/SSE/SSE2 state from the buffer specified
  6244. by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
  6245. only available on IA-32 and x64.
  6246. If Buffer is NULL, then ASSERT().
  6247. If Buffer is not aligned on a 16-byte boundary, then ASSERT().
  6248. If Buffer was not saved with AsmFxSave(), then ASSERT().
  6249. @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
  6250. **/
  6251. VOID
  6252. EFIAPI
  6253. AsmFxRestore (
  6254. IN CONST IA32_FX_BUFFER *Buffer
  6255. );
  6256. /**
  6257. Reads the current value of 64-bit MMX Register #0 (MM0).
  6258. Reads and returns the current value of MM0. This function is only available
  6259. on IA-32 and x64.
  6260. @return The current value of MM0.
  6261. **/
  6262. UINT64
  6263. EFIAPI
  6264. AsmReadMm0 (
  6265. VOID
  6266. );
  6267. /**
  6268. Reads the current value of 64-bit MMX Register #1 (MM1).
  6269. Reads and returns the current value of MM1. This function is only available
  6270. on IA-32 and x64.
  6271. @return The current value of MM1.
  6272. **/
  6273. UINT64
  6274. EFIAPI
  6275. AsmReadMm1 (
  6276. VOID
  6277. );
  6278. /**
  6279. Reads the current value of 64-bit MMX Register #2 (MM2).
  6280. Reads and returns the current value of MM2. This function is only available
  6281. on IA-32 and x64.
  6282. @return The current value of MM2.
  6283. **/
  6284. UINT64
  6285. EFIAPI
  6286. AsmReadMm2 (
  6287. VOID
  6288. );
  6289. /**
  6290. Reads the current value of 64-bit MMX Register #3 (MM3).
  6291. Reads and returns the current value of MM3. This function is only available
  6292. on IA-32 and x64.
  6293. @return The current value of MM3.
  6294. **/
  6295. UINT64
  6296. EFIAPI
  6297. AsmReadMm3 (
  6298. VOID
  6299. );
  6300. /**
  6301. Reads the current value of 64-bit MMX Register #4 (MM4).
  6302. Reads and returns the current value of MM4. This function is only available
  6303. on IA-32 and x64.
  6304. @return The current value of MM4.
  6305. **/
  6306. UINT64
  6307. EFIAPI
  6308. AsmReadMm4 (
  6309. VOID
  6310. );
  6311. /**
  6312. Reads the current value of 64-bit MMX Register #5 (MM5).
  6313. Reads and returns the current value of MM5. This function is only available
  6314. on IA-32 and x64.
  6315. @return The current value of MM5.
  6316. **/
  6317. UINT64
  6318. EFIAPI
  6319. AsmReadMm5 (
  6320. VOID
  6321. );
  6322. /**
  6323. Reads the current value of 64-bit MMX Register #6 (MM6).
  6324. Reads and returns the current value of MM6. This function is only available
  6325. on IA-32 and x64.
  6326. @return The current value of MM6.
  6327. **/
  6328. UINT64
  6329. EFIAPI
  6330. AsmReadMm6 (
  6331. VOID
  6332. );
  6333. /**
  6334. Reads the current value of 64-bit MMX Register #7 (MM7).
  6335. Reads and returns the current value of MM7. This function is only available
  6336. on IA-32 and x64.
  6337. @return The current value of MM7.
  6338. **/
  6339. UINT64
  6340. EFIAPI
  6341. AsmReadMm7 (
  6342. VOID
  6343. );
  6344. /**
  6345. Writes the current value of 64-bit MMX Register #0 (MM0).
  6346. Writes the current value of MM0. This function is only available on IA32 and
  6347. x64.
  6348. @param Value The 64-bit value to write to MM0.
  6349. **/
  6350. VOID
  6351. EFIAPI
  6352. AsmWriteMm0 (
  6353. IN UINT64 Value
  6354. );
  6355. /**
  6356. Writes the current value of 64-bit MMX Register #1 (MM1).
  6357. Writes the current value of MM1. This function is only available on IA32 and
  6358. x64.
  6359. @param Value The 64-bit value to write to MM1.
  6360. **/
  6361. VOID
  6362. EFIAPI
  6363. AsmWriteMm1 (
  6364. IN UINT64 Value
  6365. );
  6366. /**
  6367. Writes the current value of 64-bit MMX Register #2 (MM2).
  6368. Writes the current value of MM2. This function is only available on IA32 and
  6369. x64.
  6370. @param Value The 64-bit value to write to MM2.
  6371. **/
  6372. VOID
  6373. EFIAPI
  6374. AsmWriteMm2 (
  6375. IN UINT64 Value
  6376. );
  6377. /**
  6378. Writes the current value of 64-bit MMX Register #3 (MM3).
  6379. Writes the current value of MM3. This function is only available on IA32 and
  6380. x64.
  6381. @param Value The 64-bit value to write to MM3.
  6382. **/
  6383. VOID
  6384. EFIAPI
  6385. AsmWriteMm3 (
  6386. IN UINT64 Value
  6387. );
  6388. /**
  6389. Writes the current value of 64-bit MMX Register #4 (MM4).
  6390. Writes the current value of MM4. This function is only available on IA32 and
  6391. x64.
  6392. @param Value The 64-bit value to write to MM4.
  6393. **/
  6394. VOID
  6395. EFIAPI
  6396. AsmWriteMm4 (
  6397. IN UINT64 Value
  6398. );
  6399. /**
  6400. Writes the current value of 64-bit MMX Register #5 (MM5).
  6401. Writes the current value of MM5. This function is only available on IA32 and
  6402. x64.
  6403. @param Value The 64-bit value to write to MM5.
  6404. **/
  6405. VOID
  6406. EFIAPI
  6407. AsmWriteMm5 (
  6408. IN UINT64 Value
  6409. );
  6410. /**
  6411. Writes the current value of 64-bit MMX Register #6 (MM6).
  6412. Writes the current value of MM6. This function is only available on IA32 and
  6413. x64.
  6414. @param Value The 64-bit value to write to MM6.
  6415. **/
  6416. VOID
  6417. EFIAPI
  6418. AsmWriteMm6 (
  6419. IN UINT64 Value
  6420. );
  6421. /**
  6422. Writes the current value of 64-bit MMX Register #7 (MM7).
  6423. Writes the current value of MM7. This function is only available on IA32 and
  6424. x64.
  6425. @param Value The 64-bit value to write to MM7.
  6426. **/
  6427. VOID
  6428. EFIAPI
  6429. AsmWriteMm7 (
  6430. IN UINT64 Value
  6431. );
  6432. /**
  6433. Reads the current value of Time Stamp Counter (TSC).
  6434. Reads and returns the current value of TSC. This function is only available
  6435. on IA-32 and x64.
  6436. @return The current value of TSC
  6437. **/
  6438. UINT64
  6439. EFIAPI
  6440. AsmReadTsc (
  6441. VOID
  6442. );
  6443. /**
  6444. Reads the current value of a Performance Counter (PMC).
  6445. Reads and returns the current value of performance counter specified by
  6446. Index. This function is only available on IA-32 and x64.
  6447. @param Index The 32-bit Performance Counter index to read.
  6448. @return The value of the PMC specified by Index.
  6449. **/
  6450. UINT64
  6451. EFIAPI
  6452. AsmReadPmc (
  6453. IN UINT32 Index
  6454. );
  6455. /**
  6456. Sets up a monitor buffer that is used by AsmMwait().
  6457. Executes a MONITOR instruction with the register state specified by Eax, Ecx
  6458. and Edx. Returns Eax. This function is only available on IA-32 and x64.
  6459. @param Eax The value to load into EAX or RAX before executing the MONITOR
  6460. instruction.
  6461. @param Ecx The value to load into ECX or RCX before executing the MONITOR
  6462. instruction.
  6463. @param Edx The value to load into EDX or RDX before executing the MONITOR
  6464. instruction.
  6465. @return Eax
  6466. **/
  6467. UINTN
  6468. EFIAPI
  6469. AsmMonitor (
  6470. IN UINTN Eax,
  6471. IN UINTN Ecx,
  6472. IN UINTN Edx
  6473. );
  6474. /**
  6475. Executes an MWAIT instruction.
  6476. Executes an MWAIT instruction with the register state specified by Eax and
  6477. Ecx. Returns Eax. This function is only available on IA-32 and x64.
  6478. @param Eax The value to load into EAX or RAX before executing the MONITOR
  6479. instruction.
  6480. @param Ecx The value to load into ECX or RCX before executing the MONITOR
  6481. instruction.
  6482. @return Eax
  6483. **/
  6484. UINTN
  6485. EFIAPI
  6486. AsmMwait (
  6487. IN UINTN Eax,
  6488. IN UINTN Ecx
  6489. );
  6490. /**
  6491. Executes a WBINVD instruction.
  6492. Executes a WBINVD instruction. This function is only available on IA-32 and
  6493. x64.
  6494. **/
  6495. VOID
  6496. EFIAPI
  6497. AsmWbinvd (
  6498. VOID
  6499. );
  6500. /**
  6501. Executes a INVD instruction.
  6502. Executes a INVD instruction. This function is only available on IA-32 and
  6503. x64.
  6504. **/
  6505. VOID
  6506. EFIAPI
  6507. AsmInvd (
  6508. VOID
  6509. );
  6510. /**
  6511. Flushes a cache line from all the instruction and data caches within the
  6512. coherency domain of the CPU.
  6513. Flushed the cache line specified by LinearAddress, and returns LinearAddress.
  6514. This function is only available on IA-32 and x64.
  6515. @param LinearAddress The address of the cache line to flush. If the CPU is
  6516. in a physical addressing mode, then LinearAddress is a
  6517. physical address. If the CPU is in a virtual
  6518. addressing mode, then LinearAddress is a virtual
  6519. address.
  6520. @return LinearAddress.
  6521. **/
  6522. VOID *
  6523. EFIAPI
  6524. AsmFlushCacheLine (
  6525. IN VOID *LinearAddress
  6526. );
  6527. /**
  6528. Enables the 32-bit paging mode on the CPU.
  6529. Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
  6530. must be properly initialized prior to calling this service. This function
  6531. assumes the current execution mode is 32-bit protected mode. This function is
  6532. only available on IA-32. After the 32-bit paging mode is enabled, control is
  6533. transferred to the function specified by EntryPoint using the new stack
  6534. specified by NewStack and passing in the parameters specified by Context1 and
  6535. Context2. Context1 and Context2 are optional and may be NULL. The function
  6536. EntryPoint must never return.
  6537. If the current execution mode is not 32-bit protected mode, then ASSERT().
  6538. If EntryPoint is NULL, then ASSERT().
  6539. If NewStack is NULL, then ASSERT().
  6540. There are a number of constraints that must be followed before calling this
  6541. function:
  6542. 1) Interrupts must be disabled.
  6543. 2) The caller must be in 32-bit protected mode with flat descriptors. This
  6544. means all descriptors must have a base of 0 and a limit of 4GB.
  6545. 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
  6546. descriptors.
  6547. 4) CR3 must point to valid page tables that will be used once the transition
  6548. is complete, and those page tables must guarantee that the pages for this
  6549. function and the stack are identity mapped.
  6550. @param EntryPoint A pointer to function to call with the new stack after
  6551. paging is enabled.
  6552. @param Context1 A pointer to the context to pass into the EntryPoint
  6553. function as the first parameter after paging is enabled.
  6554. @param Context2 A pointer to the context to pass into the EntryPoint
  6555. function as the second parameter after paging is enabled.
  6556. @param NewStack A pointer to the new stack to use for the EntryPoint
  6557. function after paging is enabled.
  6558. **/
  6559. VOID
  6560. EFIAPI
  6561. AsmEnablePaging32 (
  6562. IN SWITCH_STACK_ENTRY_POINT EntryPoint,
  6563. IN VOID *Context1, OPTIONAL
  6564. IN VOID *Context2, OPTIONAL
  6565. IN VOID *NewStack
  6566. );
  6567. /**
  6568. Disables the 32-bit paging mode on the CPU.
  6569. Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
  6570. mode. This function assumes the current execution mode is 32-paged protected
  6571. mode. This function is only available on IA-32. After the 32-bit paging mode
  6572. is disabled, control is transferred to the function specified by EntryPoint
  6573. using the new stack specified by NewStack and passing in the parameters
  6574. specified by Context1 and Context2. Context1 and Context2 are optional and
  6575. may be NULL. The function EntryPoint must never return.
  6576. If the current execution mode is not 32-bit paged mode, then ASSERT().
  6577. If EntryPoint is NULL, then ASSERT().
  6578. If NewStack is NULL, then ASSERT().
  6579. There are a number of constraints that must be followed before calling this
  6580. function:
  6581. 1) Interrupts must be disabled.
  6582. 2) The caller must be in 32-bit paged mode.
  6583. 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
  6584. 4) CR3 must point to valid page tables that guarantee that the pages for
  6585. this function and the stack are identity mapped.
  6586. @param EntryPoint A pointer to function to call with the new stack after
  6587. paging is disabled.
  6588. @param Context1 A pointer to the context to pass into the EntryPoint
  6589. function as the first parameter after paging is disabled.
  6590. @param Context2 A pointer to the context to pass into the EntryPoint
  6591. function as the second parameter after paging is
  6592. disabled.
  6593. @param NewStack A pointer to the new stack to use for the EntryPoint
  6594. function after paging is disabled.
  6595. **/
  6596. VOID
  6597. EFIAPI
  6598. AsmDisablePaging32 (
  6599. IN SWITCH_STACK_ENTRY_POINT EntryPoint,
  6600. IN VOID *Context1, OPTIONAL
  6601. IN VOID *Context2, OPTIONAL
  6602. IN VOID *NewStack
  6603. );
  6604. /**
  6605. Enables the 64-bit paging mode on the CPU.
  6606. Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
  6607. must be properly initialized prior to calling this service. This function
  6608. assumes the current execution mode is 32-bit protected mode with flat
  6609. descriptors. This function is only available on IA-32. After the 64-bit
  6610. paging mode is enabled, control is transferred to the function specified by
  6611. EntryPoint using the new stack specified by NewStack and passing in the
  6612. parameters specified by Context1 and Context2. Context1 and Context2 are
  6613. optional and may be 0. The function EntryPoint must never return.
  6614. If the current execution mode is not 32-bit protected mode with flat
  6615. descriptors, then ASSERT().
  6616. If EntryPoint is 0, then ASSERT().
  6617. If NewStack is 0, then ASSERT().
  6618. @param Cs The 16-bit selector to load in the CS before EntryPoint
  6619. is called. The descriptor in the GDT that this selector
  6620. references must be setup for long mode.
  6621. @param EntryPoint The 64-bit virtual address of the function to call with
  6622. the new stack after paging is enabled.
  6623. @param Context1 The 64-bit virtual address of the context to pass into
  6624. the EntryPoint function as the first parameter after
  6625. paging is enabled.
  6626. @param Context2 The 64-bit virtual address of the context to pass into
  6627. the EntryPoint function as the second parameter after
  6628. paging is enabled.
  6629. @param NewStack The 64-bit virtual address of the new stack to use for
  6630. the EntryPoint function after paging is enabled.
  6631. **/
  6632. VOID
  6633. EFIAPI
  6634. AsmEnablePaging64 (
  6635. IN UINT16 Cs,
  6636. IN UINT64 EntryPoint,
  6637. IN UINT64 Context1, OPTIONAL
  6638. IN UINT64 Context2, OPTIONAL
  6639. IN UINT64 NewStack
  6640. );
  6641. /**
  6642. Disables the 64-bit paging mode on the CPU.
  6643. Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
  6644. mode. This function assumes the current execution mode is 64-paging mode.
  6645. This function is only available on x64. After the 64-bit paging mode is
  6646. disabled, control is transferred to the function specified by EntryPoint
  6647. using the new stack specified by NewStack and passing in the parameters
  6648. specified by Context1 and Context2. Context1 and Context2 are optional and
  6649. may be 0. The function EntryPoint must never return.
  6650. If the current execution mode is not 64-bit paged mode, then ASSERT().
  6651. If EntryPoint is 0, then ASSERT().
  6652. If NewStack is 0, then ASSERT().
  6653. @param Cs The 16-bit selector to load in the CS before EntryPoint
  6654. is called. The descriptor in the GDT that this selector
  6655. references must be setup for 32-bit protected mode.
  6656. @param EntryPoint The 64-bit virtual address of the function to call with
  6657. the new stack after paging is disabled.
  6658. @param Context1 The 64-bit virtual address of the context to pass into
  6659. the EntryPoint function as the first parameter after
  6660. paging is disabled.
  6661. @param Context2 The 64-bit virtual address of the context to pass into
  6662. the EntryPoint function as the second parameter after
  6663. paging is disabled.
  6664. @param NewStack The 64-bit virtual address of the new stack to use for
  6665. the EntryPoint function after paging is disabled.
  6666. **/
  6667. VOID
  6668. EFIAPI
  6669. AsmDisablePaging64 (
  6670. IN UINT16 Cs,
  6671. IN UINT32 EntryPoint,
  6672. IN UINT32 Context1, OPTIONAL
  6673. IN UINT32 Context2, OPTIONAL
  6674. IN UINT32 NewStack
  6675. );
  6676. //
  6677. // 16-bit thunking services
  6678. //
  6679. /**
  6680. Retrieves the properties for 16-bit thunk functions.
  6681. Computes the size of the buffer and stack below 1MB required to use the
  6682. AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
  6683. buffer size is returned in RealModeBufferSize, and the stack size is returned
  6684. in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
  6685. then the actual minimum stack size is ExtraStackSize plus the maximum number
  6686. of bytes that need to be passed to the 16-bit real mode code.
  6687. If RealModeBufferSize is NULL, then ASSERT().
  6688. If ExtraStackSize is NULL, then ASSERT().
  6689. @param RealModeBufferSize A pointer to the size of the buffer below 1MB
  6690. required to use the 16-bit thunk functions.
  6691. @param ExtraStackSize A pointer to the extra size of stack below 1MB
  6692. that the 16-bit thunk functions require for
  6693. temporary storage in the transition to and from
  6694. 16-bit real mode.
  6695. **/
  6696. VOID
  6697. EFIAPI
  6698. AsmGetThunk16Properties (
  6699. OUT UINT32 *RealModeBufferSize,
  6700. OUT UINT32 *ExtraStackSize
  6701. );
  6702. /**
  6703. Prepares all structures a code required to use AsmThunk16().
  6704. Prepares all structures and code required to use AsmThunk16().
  6705. This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
  6706. virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
  6707. If ThunkContext is NULL, then ASSERT().
  6708. @param ThunkContext A pointer to the context structure that describes the
  6709. 16-bit real mode code to call.
  6710. **/
  6711. VOID
  6712. EFIAPI
  6713. AsmPrepareThunk16 (
  6714. IN OUT THUNK_CONTEXT *ThunkContext
  6715. );
  6716. /**
  6717. Transfers control to a 16-bit real mode entry point and returns the results.
  6718. Transfers control to a 16-bit real mode entry point and returns the results.
  6719. AsmPrepareThunk16() must be called with ThunkContext before this function is used.
  6720. This function must be called with interrupts disabled.
  6721. The register state from the RealModeState field of ThunkContext is restored just prior
  6722. to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,
  6723. which is used to set the interrupt state when a 16-bit real mode entry point is called.
  6724. Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.
  6725. The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to
  6726. the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.
  6727. The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,
  6728. so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment
  6729. and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry
  6730. point must exit with a RETF instruction. The register state is captured into RealModeState immediately
  6731. after the RETF instruction is executed.
  6732. If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
  6733. or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure
  6734. the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.
  6735. If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
  6736. then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.
  6737. This includes the base vectors, the interrupt masks, and the edge/level trigger mode.
  6738. If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code
  6739. is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.
  6740. If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
  6741. ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to
  6742. disable the A20 mask.
  6743. If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in
  6744. ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,
  6745. then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
  6746. If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in
  6747. ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
  6748. If ThunkContext is NULL, then ASSERT().
  6749. If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
  6750. If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
  6751. ThunkAttributes, then ASSERT().
  6752. This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
  6753. virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.
  6754. @param ThunkContext A pointer to the context structure that describes the
  6755. 16-bit real mode code to call.
  6756. **/
  6757. VOID
  6758. EFIAPI
  6759. AsmThunk16 (
  6760. IN OUT THUNK_CONTEXT *ThunkContext
  6761. );
  6762. /**
  6763. Prepares all structures and code for a 16-bit real mode thunk, transfers
  6764. control to a 16-bit real mode entry point, and returns the results.
  6765. Prepares all structures and code for a 16-bit real mode thunk, transfers
  6766. control to a 16-bit real mode entry point, and returns the results. If the
  6767. caller only need to perform a single 16-bit real mode thunk, then this
  6768. service should be used. If the caller intends to make more than one 16-bit
  6769. real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
  6770. once and AsmThunk16() can be called for each 16-bit real mode thunk.
  6771. This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
  6772. virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
  6773. See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.
  6774. @param ThunkContext A pointer to the context structure that describes the
  6775. 16-bit real mode code to call.
  6776. **/
  6777. VOID
  6778. EFIAPI
  6779. AsmPrepareAndThunk16 (
  6780. IN OUT THUNK_CONTEXT *ThunkContext
  6781. );
  6782. /**
  6783. Generates a 16-bit random number through RDRAND instruction.
  6784. if Rand is NULL, then ASSERT().
  6785. @param[out] Rand Buffer pointer to store the random result.
  6786. @retval TRUE RDRAND call was successful.
  6787. @retval FALSE Failed attempts to call RDRAND.
  6788. **/
  6789. BOOLEAN
  6790. EFIAPI
  6791. AsmRdRand16 (
  6792. OUT UINT16 *Rand
  6793. );
  6794. /**
  6795. Generates a 32-bit random number through RDRAND instruction.
  6796. if Rand is NULL, then ASSERT().
  6797. @param[out] Rand Buffer pointer to store the random result.
  6798. @retval TRUE RDRAND call was successful.
  6799. @retval FALSE Failed attempts to call RDRAND.
  6800. **/
  6801. BOOLEAN
  6802. EFIAPI
  6803. AsmRdRand32 (
  6804. OUT UINT32 *Rand
  6805. );
  6806. /**
  6807. Generates a 64-bit random number through RDRAND instruction.
  6808. if Rand is NULL, then ASSERT().
  6809. @param[out] Rand Buffer pointer to store the random result.
  6810. @retval TRUE RDRAND call was successful.
  6811. @retval FALSE Failed attempts to call RDRAND.
  6812. **/
  6813. BOOLEAN
  6814. EFIAPI
  6815. AsmRdRand64 (
  6816. OUT UINT64 *Rand
  6817. );
  6818. #endif
  6819. #endif