Something went wrong. Try again.
Reactos
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119/* * Fast486 386/486 CPU Emulation Library * opcodes.c * * Copyright (C) 2015 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* INCLUDES *******************************************************************/
#include <windef.h>
// #define NDEBUG#include <debug.h>
#include <fast486.h>#include "opcodes.h"#include "opgroups.h"#include "extraops.h"#include "common.h"#include "fpu.h"
/* PUBLIC VARIABLES ***********************************************************/
FAST486_OPCODE_HANDLER_PROCFast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] ={ Fast486OpcodeAddByteModrm, /* 0x00 - 0x03 */ Fast486OpcodeAddModrm, Fast486OpcodeAddByteModrm, Fast486OpcodeAddModrm, Fast486OpcodeAddAl, /* 0x04 */ Fast486OpcodeAddEax, /* 0x05 */ Fast486OpcodePushEs, /* 0x06 */ Fast486OpcodePopEs, /* 0x07 */ Fast486OpcodeOrByteModrm, /* 0x08 - 0x0B */ Fast486OpcodeOrModrm, Fast486OpcodeOrByteModrm, Fast486OpcodeOrModrm, Fast486OpcodeOrAl, /* 0x0C */ Fast486OpcodeOrEax, /* 0x0D */ Fast486OpcodePushCs, /* 0x0E */ Fast486OpcodeExtended, /* 0x0F */ Fast486OpcodeAdcByteModrm, /* 0x10 - 0x13 */ Fast486OpcodeAdcModrm, Fast486OpcodeAdcByteModrm, Fast486OpcodeAdcModrm, Fast486OpcodeAdcAl, /* 0x14 */ Fast486OpcodeAdcEax, /* 0x15 */ Fast486OpcodePushSs, /* 0x16 */ Fast486OpcodePopSs, /* 0x17 */ Fast486OpcodeSbbByteModrm, /* 0x18 - 0x1B */ Fast486OpcodeSbbModrm, Fast486OpcodeSbbByteModrm, Fast486OpcodeSbbModrm, Fast486OpcodeSbbAl, /* 0x1C */ Fast486OpcodeSbbEax, /* 0x1D */ Fast486OpcodePushDs, /* 0x1E */ Fast486OpcodePopDs, /* 0x1F */ Fast486OpcodeAndByteModrm, /* 0x20 - 0x23 */ Fast486OpcodeAndModrm, Fast486OpcodeAndByteModrm, Fast486OpcodeAndModrm, Fast486OpcodeAndAl, /* 0x24 */ Fast486OpcodeAndEax, /* 0x25 */ Fast486OpcodePrefix, /* 0x26 */ Fast486OpcodeDaa, /* 0x27 */ Fast486OpcodeCmpSubByteModrm, /* 0x28 - 0x2B */ Fast486OpcodeCmpSubModrm, Fast486OpcodeCmpSubByteModrm, Fast486OpcodeCmpSubModrm, Fast486OpcodeCmpSubAl, /* 0x2C */ Fast486OpcodeCmpSubEax, /* 0x2D */ Fast486OpcodePrefix, /* 0x2E */ Fast486OpcodeDas, /* 0x2F */ Fast486OpcodeXorByteModrm, /* 0x30 - 0x33 */ Fast486OpcodeXorModrm, Fast486OpcodeXorByteModrm, Fast486OpcodeXorModrm, Fast486OpcodeXorAl, /* 0x34 */ Fast486OpcodeXorEax, /* 0x35 */ Fast486OpcodePrefix, /* 0x36 */ Fast486OpcodeAaa, /* 0x37 */ Fast486OpcodeCmpSubByteModrm, /* 0x38 - 0x3B */ Fast486OpcodeCmpSubModrm, Fast486OpcodeCmpSubByteModrm, Fast486OpcodeCmpSubModrm, Fast486OpcodeCmpSubAl, /* 0x3C */ Fast486OpcodeCmpSubEax, /* 0x3D */ Fast486OpcodePrefix, /* 0x3E */ Fast486OpcodeAas, /* 0x3F */ Fast486OpcodeIncrement, /* 0x40 - 0x47 */ Fast486OpcodeIncrement, Fast486OpcodeIncrement, Fast486OpcodeIncrement, Fast486OpcodeIncrement, Fast486OpcodeIncrement, Fast486OpcodeIncrement, Fast486OpcodeIncrement, Fast486OpcodeDecrement, /* 0x48 - 0x4F */ Fast486OpcodeDecrement, Fast486OpcodeDecrement, Fast486OpcodeDecrement, Fast486OpcodeDecrement, Fast486OpcodeDecrement, Fast486OpcodeDecrement, Fast486OpcodeDecrement, Fast486OpcodePushReg, /* 0x50 - 0x57 */ Fast486OpcodePushReg, Fast486OpcodePushReg, Fast486OpcodePushReg, Fast486OpcodePushReg, Fast486OpcodePushReg, Fast486OpcodePushReg, Fast486OpcodePushReg, Fast486OpcodePopReg, /* 0x58 - 0x5F */ Fast486OpcodePopReg, Fast486OpcodePopReg, Fast486OpcodePopReg, Fast486OpcodePopReg, Fast486OpcodePopReg, Fast486OpcodePopReg, Fast486OpcodePopReg, Fast486OpcodePushAll, /* 0x60 */ Fast486OpcodePopAll, /* 0x61 */ Fast486OpcodeBound, /* 0x62 */ Fast486OpcodeArpl, /* 0x63 */ Fast486OpcodePrefix, /* 0x64 - 0x67 */ Fast486OpcodePrefix, Fast486OpcodePrefix, Fast486OpcodePrefix, Fast486OpcodePushImm, /* 0x68 */ Fast486OpcodeImulModrmImm, /* 0x69 */ Fast486OpcodePushByteImm, /* 0x6A */ Fast486OpcodeImulModrmImm, /* 0x6B */ Fast486OpcodeIns, /* 0x6C */ Fast486OpcodeIns, /* 0x6D */ Fast486OpcodeOuts, /* 0x6E */ Fast486OpcodeOuts, /* 0x6F */ Fast486OpcodeShortConditionalJmp, /* 0x70 - 0x7F */ Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeShortConditionalJmp, Fast486OpcodeGroup8082, /* 0x80 */ Fast486OpcodeGroup81, /* 0x81 */ Fast486OpcodeGroup8082, /* 0x82 */ Fast486OpcodeGroup83, /* 0x83 */ Fast486OpcodeTestByteModrm, /* 0x84 */ Fast486OpcodeTestModrm, /* 0x85 */ Fast486OpcodeXchgByteModrm, /* 0x86 */ Fast486OpcodeXchgModrm, /* 0x87 */ Fast486OpcodeMovByteModrm, /* 0x88 */ Fast486OpcodeMovModrm, /* 0x89 */ Fast486OpcodeMovByteModrm, /* 0x8A */ Fast486OpcodeMovModrm, /* 0x8B */ Fast486OpcodeMovStoreSeg, /* 0x8C */ Fast486OpcodeLea, /* 0x8D */ Fast486OpcodeMovLoadSeg, /* 0x8E */ Fast486OpcodeGroup8F, /* 0x8F */ Fast486OpcodeNop, /* 0x90 */ Fast486OpcodeExchangeEax, /* 0x91 - 0x97 */ Fast486OpcodeExchangeEax, Fast486OpcodeExchangeEax, Fast486OpcodeExchangeEax, Fast486OpcodeExchangeEax, Fast486OpcodeExchangeEax, Fast486OpcodeExchangeEax, Fast486OpcodeCwde, /* 0x98 */ Fast486OpcodeCdq, /* 0x99 */ Fast486OpcodeCallAbs, /* 0x9A */ Fast486OpcodeWait, /* 0x9B */ Fast486OpcodePushFlags, /* 0x9C */ Fast486OpcodePopFlags, /* 0x9D */ Fast486OpcodeSahf, /* 0x9E */ Fast486OpcodeLahf, /* 0x9F */ Fast486OpcodeMovAlOffset, /* 0xA0 */ Fast486OpcodeMovEaxOffset, /* 0xA1 */ Fast486OpcodeMovOffsetAl, /* 0xA2 */ Fast486OpcodeMovOffsetEax, /* 0xA3 */ Fast486OpcodeMovs, /* 0xA4 */ Fast486OpcodeMovs, /* 0xA5 */ Fast486OpcodeCmps, /* 0xA6 */ Fast486OpcodeCmps, /* 0xA7 */ Fast486OpcodeTestAl, /* 0xA8 */ Fast486OpcodeTestEax, /* 0xA9 */ Fast486OpcodeStos, /* 0xAA */ Fast486OpcodeStos, /* 0xAB */ Fast486OpcodeLods, /* 0xAC */ Fast486OpcodeLods, /* 0xAD */ Fast486OpcodeScas, /* 0xAE */ Fast486OpcodeScas, /* 0xAF */ Fast486OpcodeMovByteRegImm, /* 0xB0 - 0xB7 */ Fast486OpcodeMovByteRegImm, Fast486OpcodeMovByteRegImm, Fast486OpcodeMovByteRegImm, Fast486OpcodeMovByteRegImm, Fast486OpcodeMovByteRegImm, Fast486OpcodeMovByteRegImm, Fast486OpcodeMovByteRegImm, Fast486OpcodeMovRegImm, /* 0xB8 - 0xBF */ Fast486OpcodeMovRegImm, Fast486OpcodeMovRegImm, Fast486OpcodeMovRegImm, Fast486OpcodeMovRegImm, Fast486OpcodeMovRegImm, Fast486OpcodeMovRegImm, Fast486OpcodeMovRegImm, Fast486OpcodeGroupC0, /* 0xC0 */ Fast486OpcodeGroupC1, /* 0xC1 */ Fast486OpcodeRet, /* 0xC2 */ Fast486OpcodeRet, /* 0xC3 */ Fast486OpcodeLdsLes, /* 0xC4 */ Fast486OpcodeLdsLes, /* 0xC5 */ Fast486OpcodeGroupC6, /* 0xC6 */ Fast486OpcodeGroupC7, /* 0xC7 */ Fast486OpcodeEnter, /* 0xC8 */ Fast486OpcodeLeave, /* 0xC9 */ Fast486OpcodeRetFar, /* 0xCA */ Fast486OpcodeRetFar, /* 0xCB */ Fast486OpcodeInt, /* 0xCC */ Fast486OpcodeInt, /* 0xCD */ Fast486OpcodeInt, /* 0xCE */ Fast486OpcodeIret, /* 0xCF */ Fast486OpcodeGroupD0, /* 0xD0 - 0xD3 */ Fast486OpcodeGroupD1, Fast486OpcodeGroupD2, Fast486OpcodeGroupD3, Fast486OpcodeAam, /* 0xD4 */ Fast486OpcodeAad, /* 0xD5 */ Fast486OpcodeSalc, /* 0xD6 */ Fast486OpcodeXlat, /* 0xD7 */ Fast486FpuOpcodeD8, /* 0xD8 - 0xDF */ Fast486FpuOpcodeD9, Fast486FpuOpcodeDA, Fast486FpuOpcodeDB, Fast486FpuOpcodeDC, Fast486FpuOpcodeDD, Fast486FpuOpcodeDE, Fast486FpuOpcodeDF, Fast486OpcodeLoop, /* 0xE0 - 0xE2 */ Fast486OpcodeLoop, Fast486OpcodeLoop, Fast486OpcodeJecxz, /* 0xE3 */ Fast486OpcodeInByte, /* 0xE4 */ Fast486OpcodeIn, /* 0xE5 */ Fast486OpcodeOutByte, /* 0xE6 */ Fast486OpcodeOut, /* 0xE7 */ Fast486OpcodeCall, /* 0xE8 */ Fast486OpcodeJmp, /* 0xE9 */ Fast486OpcodeJmpAbs, /* 0xEA */ Fast486OpcodeShortJump, /* 0xEB */ Fast486OpcodeInByte, /* 0xEC */ Fast486OpcodeIn, /* 0xED */ Fast486OpcodeOutByte, /* 0xEE */ Fast486OpcodeOut, /* 0xEF */ Fast486OpcodePrefix, /* 0xF0 */ Fast486OpcodeInvalid, /* 0xF1 */ // Invalid opcode -- ICEBP/INT01 opcode Fast486OpcodePrefix, /* 0xF2 */ Fast486OpcodePrefix, /* 0xF3 */ Fast486OpcodeHalt, /* 0xF4 */ Fast486OpcodeComplCarry, /* 0xF5 */ Fast486OpcodeGroupF6, /* 0xF6 */ Fast486OpcodeGroupF7, /* 0xF7 */ Fast486OpcodeClearCarry, /* 0xF8 */ Fast486OpcodeSetCarry, /* 0xF9 */ Fast486OpcodeClearInt, /* 0xFA */ Fast486OpcodeSetInt, /* 0xFB */ Fast486OpcodeClearDir, /* 0xFC */ Fast486OpcodeSetDir, /* 0xFD */ Fast486OpcodeGroupFE, /* 0xFE */ Fast486OpcodeGroupFF, /* 0xFF */};
/* PUBLIC FUNCTIONS ***********************************************************/
FAST486_OPCODE_HANDLER(Fast486OpcodeInvalid){ /* * This is not a valid opcode. * Well, not totally: see http://www.rcollins.org/secrets/opcodes/ICEBP.html * for more details. */ DPRINT1("FAST486 -- Calling ICEBP opcode\n"); Fast486Exception(State, FAST486_EXCEPTION_UD);}
FAST486_OPCODE_HANDLER(Fast486OpcodePrefix){ switch (Opcode) { /* ES: */ case 0x26: { State->PrefixFlags |= FAST486_PREFIX_SEG; State->SegmentOverride = FAST486_REG_ES; break; }
/* CS: */ case 0x2E: { State->PrefixFlags |= FAST486_PREFIX_SEG; State->SegmentOverride = FAST486_REG_CS; break; }
/* SS: */ case 0x36: { State->PrefixFlags |= FAST486_PREFIX_SEG; State->SegmentOverride = FAST486_REG_SS; break; }
/* DS: */ case 0x3E: { State->PrefixFlags |= FAST486_PREFIX_SEG; State->SegmentOverride = FAST486_REG_DS; break; }
/* FS: */ case 0x64: { State->PrefixFlags |= FAST486_PREFIX_SEG; State->SegmentOverride = FAST486_REG_FS; break; }
/* GS: */ case 0x65: { State->PrefixFlags |= FAST486_PREFIX_SEG; State->SegmentOverride = FAST486_REG_GS; break; }
/* OPSIZE */ case 0x66: { State->PrefixFlags |= FAST486_PREFIX_OPSIZE; break; }
/* ADSIZE */ case 0x67: { State->PrefixFlags |= FAST486_PREFIX_ADSIZE; break; }
/* LOCK */ case 0xF0: { State->PrefixFlags |= FAST486_PREFIX_LOCK; break; }
/* REPNZ */ case 0xF2: { /* Mutually exclusive with REP */ State->PrefixFlags |= FAST486_PREFIX_REPNZ; State->PrefixFlags &= ~FAST486_PREFIX_REP; break; }
/* REP / REPZ */ case 0xF3: { /* Mutually exclusive with REPNZ */ State->PrefixFlags |= FAST486_PREFIX_REP; State->PrefixFlags &= ~FAST486_PREFIX_REPNZ; break; }
default: { /* Shouldn't happen */ ASSERT(FALSE); } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeIncrement){ ULONG Value; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF8) == 0x40);
if (Size) { Value = ++State->GeneralRegs[Opcode & 0x07].Long;
State->Flags.Of = (Value == SIGN_FLAG_LONG); State->Flags.Sf = ((Value & SIGN_FLAG_LONG) != 0); } else { Value = ++State->GeneralRegs[Opcode & 0x07].LowWord;
State->Flags.Of = (Value == SIGN_FLAG_WORD); State->Flags.Sf = ((Value & SIGN_FLAG_WORD) != 0); }
State->Flags.Zf = (Value == 0); State->Flags.Af = ((Value & 0x0F) == 0); State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));}
FAST486_OPCODE_HANDLER(Fast486OpcodeDecrement){ ULONG Value; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF8) == 0x48);
if (Size) { Value = --State->GeneralRegs[Opcode & 0x07].Long;
State->Flags.Of = (Value == (SIGN_FLAG_LONG - 1)); State->Flags.Sf = ((Value & SIGN_FLAG_LONG) != 0); } else { Value = --State->GeneralRegs[Opcode & 0x07].LowWord;
State->Flags.Of = (Value == (SIGN_FLAG_WORD - 1)); State->Flags.Sf = ((Value & SIGN_FLAG_WORD) != 0); }
State->Flags.Zf = (Value == 0); State->Flags.Af = ((Value & 0x0F) == 0x0F); State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));}
FAST486_OPCODE_HANDLER(Fast486OpcodePushReg){ NO_LOCK_PREFIX();
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF8) == 0x50);
/* Call the internal function */ Fast486StackPush(State, State->GeneralRegs[Opcode & 0x07].Long);}
FAST486_OPCODE_HANDLER(Fast486OpcodePopReg){ ULONG Value; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF8) == 0x58);
/* Call the internal function */ if (!Fast486StackPop(State, &Value)) return;
/* Store the value */ if (Size) State->GeneralRegs[Opcode & 0x07].Long = Value; else State->GeneralRegs[Opcode & 0x07].LowWord = Value;}
FAST486_OPCODE_HANDLER(Fast486OpcodeNop){}
FAST486_OPCODE_HANDLER(Fast486OpcodeExchangeEax){ INT Reg = Opcode & 0x07; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF8) == 0x90);
/* Exchange the values */ if (Size) { ULONG Value;
Value = State->GeneralRegs[Reg].Long; State->GeneralRegs[Reg].Long = State->GeneralRegs[FAST486_REG_EAX].Long; State->GeneralRegs[FAST486_REG_EAX].Long = Value; } else { USHORT Value;
Value = State->GeneralRegs[Reg].LowWord; State->GeneralRegs[Reg].LowWord = State->GeneralRegs[FAST486_REG_EAX].LowWord; State->GeneralRegs[FAST486_REG_EAX].LowWord = Value; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeShortConditionalJmp){ BOOLEAN Jump = FALSE; CHAR Offset = 0; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF0) == 0x70);
TOGGLE_OPSIZE(Size);
/* Fetch the offset */ if (!Fast486FetchByte(State, (PUCHAR)&Offset)) { /* An exception occurred */ return; }
switch ((Opcode & 0x0F) >> 1) { /* JO / JNO */ case 0: { Jump = State->Flags.Of; break; }
/* JC / JNC */ case 1: { Jump = State->Flags.Cf; break; }
/* JZ / JNZ */ case 2: { Jump = State->Flags.Zf; break; }
/* JBE / JNBE */ case 3: { Jump = State->Flags.Cf || State->Flags.Zf; break; }
/* JS / JNS */ case 4: { Jump = State->Flags.Sf; break; }
/* JP / JNP */ case 5: { Jump = State->Flags.Pf; break; }
/* JL / JNL */ case 6: { Jump = State->Flags.Sf != State->Flags.Of; break; }
/* JLE / JNLE */ case 7: { Jump = (State->Flags.Sf != State->Flags.Of) || State->Flags.Zf; break; } }
if (Opcode & 1) { /* Invert the result */ Jump = !Jump; }
if (Jump) { /* Move the instruction pointer */ State->InstPtr.Long += Offset;
if (!Size) { /* Clear the top half of EIP */ State->InstPtr.Long &= 0xFFFF; } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeClearCarry){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xF8);
NO_LOCK_PREFIX();
/* Clear CF and return success */ State->Flags.Cf = FALSE;}
FAST486_OPCODE_HANDLER(Fast486OpcodeSetCarry){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xF9);
NO_LOCK_PREFIX();
/* Set CF and return success*/ State->Flags.Cf = TRUE;}
FAST486_OPCODE_HANDLER(Fast486OpcodeComplCarry){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xF5);
NO_LOCK_PREFIX();
/* Toggle CF and return success */ State->Flags.Cf = !State->Flags.Cf; return;}
FAST486_OPCODE_HANDLER(Fast486OpcodeClearInt){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFA);
NO_LOCK_PREFIX();
/* Check for protected mode */ if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) { /* Check IOPL */ if (State->Flags.Iopl >= Fast486GetCurrentPrivLevel(State)) { /* Clear the interrupt flag */ State->Flags.If = FALSE; } else { /* General Protection Fault */ Fast486Exception(State, FAST486_EXCEPTION_GP); return; } } else { /* Just clear the interrupt flag */ State->Flags.If = FALSE; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeSetInt){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFB);
NO_LOCK_PREFIX();
/* Check for protected mode */ if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) { /* Check IOPL */ if (State->Flags.Iopl >= Fast486GetCurrentPrivLevel(State)) { /* Set the interrupt flag */ State->Flags.If = TRUE; } else { /* General Protection Fault */ Fast486Exception(State, FAST486_EXCEPTION_GP); return; } } else { /* Just set the interrupt flag */ State->Flags.If = TRUE; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeClearDir){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFC);
NO_LOCK_PREFIX();
/* Clear DF */ State->Flags.Df = FALSE;}
FAST486_OPCODE_HANDLER(Fast486OpcodeSetDir){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFD);
NO_LOCK_PREFIX();
/* Set DF */ State->Flags.Df = TRUE;}
FAST486_OPCODE_HANDLER(Fast486OpcodeHalt){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xF4);
NO_LOCK_PREFIX();
/* Privileged instructions can only be executed under CPL = 0 */ if (Fast486GetCurrentPrivLevel(State) != 0) { Fast486Exception(State, FAST486_EXCEPTION_GP); return; }
/* Halt */ State->Halted = TRUE;}
FAST486_OPCODE_HANDLER(Fast486OpcodeInByte){ UCHAR Data; ULONG Port;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF7) == 0xE4);
if (Opcode == 0xE4) { /* Fetch the parameter */ if (!Fast486FetchByte(State, &Data)) { /* Exception occurred */ return; }
/* Set the port number to the parameter */ Port = Data; } else { /* The port number is in DX */ Port = State->GeneralRegs[FAST486_REG_EDX].LowWord; }
if (!Fast486IoPrivilegeCheck(State, Port)) return;
/* Read a byte from the I/O port */ State->IoReadCallback(State, Port, &Data, 1, sizeof(UCHAR));
/* Store the result in AL */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Data;}
FAST486_OPCODE_HANDLER(Fast486OpcodeIn){ ULONG Port; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF7) == 0xE5);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Opcode == 0xE5) { UCHAR Data;
/* Fetch the parameter */ if (!Fast486FetchByte(State, &Data)) { /* Exception occurred */ return; }
/* Set the port number to the parameter */ Port = Data; } else { /* The port number is in DX */ Port = State->GeneralRegs[FAST486_REG_EDX].LowWord; }
if (!Fast486IoPrivilegeCheck(State, Port)) return;
if (Size) { ULONG Data;
/* Read a dword from the I/O port */ State->IoReadCallback(State, Port, &Data, 1, sizeof(ULONG));
/* Store the value in EAX */ State->GeneralRegs[FAST486_REG_EAX].Long = Data; } else { USHORT Data;
/* Read a word from the I/O port */ State->IoReadCallback(State, Port, &Data, 1, sizeof(USHORT));
/* Store the value in AX */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Data; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeOutByte){ UCHAR Data; ULONG Port;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF7) == 0xE6);
if (Opcode == 0xE6) { /* Fetch the parameter */ if (!Fast486FetchByte(State, &Data)) { /* Exception occurred */ return; }
/* Set the port number to the parameter */ Port = Data; } else { /* The port number is in DX */ Port = State->GeneralRegs[FAST486_REG_EDX].LowWord; }
if (!Fast486IoPrivilegeCheck(State, Port)) return;
/* Read the value from AL */ Data = State->GeneralRegs[FAST486_REG_EAX].LowByte;
/* Write the byte to the I/O port */ State->IoWriteCallback(State, Port, &Data, 1, sizeof(UCHAR));}
FAST486_OPCODE_HANDLER(Fast486OpcodeOut){ ULONG Port; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF7) == 0xE7);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Opcode == 0xE7) { UCHAR Data;
/* Fetch the parameter */ if (!Fast486FetchByte(State, &Data)) { /* Exception occurred */ return; }
/* Set the port number to the parameter */ Port = Data; } else { /* The port number is in DX */ Port = State->GeneralRegs[FAST486_REG_EDX].LowWord; }
if (!Fast486IoPrivilegeCheck(State, Port)) return;
if (Size) { /* Get the value from EAX */ ULONG Data = State->GeneralRegs[FAST486_REG_EAX].Long;
/* Write a dword to the I/O port */ State->IoWriteCallback(State, Port, &Data, 1, sizeof(ULONG)); } else { /* Get the value from AX */ USHORT Data = State->GeneralRegs[FAST486_REG_EAX].LowWord;
/* Write a word to the I/O port */ State->IoWriteCallback(State, Port, &Data, 1, sizeof(USHORT)); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeShortJump){ CHAR Offset = 0; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_OPSIZE(Size);
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xEB);
/* Fetch the offset */ if (!Fast486FetchByte(State, (PUCHAR)&Offset)) { /* An exception occurred */ return; }
/* Move the instruction pointer */ State->InstPtr.Long += Offset;
if (!Size) { /* Clear the top half of EIP */ State->InstPtr.Long &= 0xFFFF; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovRegImm){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF8) == 0xB8);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Size) { ULONG Value;
/* Fetch the dword */ if (!Fast486FetchDword(State, &Value)) { /* Exception occurred */ return; }
/* Store the value in the register */ State->GeneralRegs[Opcode & 0x07].Long = Value; } else { USHORT Value;
/* Fetch the word */ if (!Fast486FetchWord(State, &Value)) { /* Exception occurred */ return; }
/* Store the value in the register */ State->GeneralRegs[Opcode & 0x07].LowWord = Value; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteRegImm){ UCHAR Value;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xF8) == 0xB0);
NO_LOCK_PREFIX();
/* Fetch the byte */ if (!Fast486FetchByte(State, &Value)) { /* Exception occurred */ return; }
if (Opcode & 0x04) { /* AH, CH, DH or BH */ State->GeneralRegs[Opcode & 0x03].HighByte = Value; } else { /* AL, CL, DL or BL */ State->GeneralRegs[Opcode & 0x03].LowByte = Value; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeAddByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x00);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue;
/* Update the flags */ State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x01);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue;
/* Update the flags */ State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue;
/* Update the flags */ State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeAddAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x04);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue;
/* Update the flags */ State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;}
FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x05);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue;
/* Update the flags */ State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].Long = Result; } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue;
/* Update the flags */ State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Result; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeOrByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x08);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue | SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x09);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue | SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue | SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeOrAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x0C);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue | SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;}
FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x0D);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue | SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].Long = Result; } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue | SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Result; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeAndByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x20);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x21);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeAndAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x24);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;}
FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x25);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].Long = Result; } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Result; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeXorByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x30);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue ^ SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x31);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue ^ SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue ^ SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeXorAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x34);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue ^ SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;}
FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x35);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue ^ SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].Long = Result; } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue ^ SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Result; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeTestByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x84);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; } /* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x85);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result); } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeTestAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xA8);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xA9);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result); } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue & SecondValue;
/* Update the flags */ State->Flags.Cf = FALSE; State->Flags.Of = FALSE; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeXchgByteModrm){ UCHAR FirstValue, SecondValue; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x86);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Write the value from the register to the R/M */ if (!Fast486WriteModrmByteOperands(State, &ModRegRm, FALSE, FirstValue)) { /* Exception occurred */ return; }
/* Write the value from the R/M to the register */ Fast486WriteModrmByteOperands(State, &ModRegRm, TRUE, SecondValue);}
FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x87);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Write the value from the register to the R/M */ if (!Fast486WriteModrmDwordOperands(State, &ModRegRm, FALSE, FirstValue)) { /* Exception occurred */ return; }
/* Write the value from the R/M to the register */ Fast486WriteModrmDwordOperands(State, &ModRegRm, TRUE, SecondValue); } else { USHORT FirstValue, SecondValue;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Write the value from the register to the R/M */ if (!Fast486WriteModrmWordOperands(State, &ModRegRm, FALSE, FirstValue)) { /* Exception occurred */ return; }
/* Write the value from the R/M to the register */ Fast486WriteModrmWordOperands(State, &ModRegRm, TRUE, SecondValue); }}
FAST486_OPCODE_HANDLER(Fast486OpcodePushEs){ /* Call the internal API */ Fast486StackPush(State, State->SegmentRegs[FAST486_REG_ES].Selector);}
FAST486_OPCODE_HANDLER(Fast486OpcodePopEs){ ULONG NewSelector;
if (!Fast486StackPop(State, &NewSelector)) { /* Exception occurred */ return; }
/* Call the internal API */ Fast486LoadSegment(State, FAST486_REG_ES, LOWORD(NewSelector));}
FAST486_OPCODE_HANDLER(Fast486OpcodePushCs){ /* Call the internal API */ Fast486StackPush(State, State->SegmentRegs[FAST486_REG_CS].Selector);}
FAST486_OPCODE_HANDLER(Fast486OpcodeAdcByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x10);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue + State->Flags.Cf;
/* Special exception for CF */ State->Flags.Cf = State->Flags.Cf && ((FirstValue == 0xFF) || (SecondValue == 0xFF));
/* Update the flags */ State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue)); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x11);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue + State->Flags.Cf;
/* Special exception for CF */ State->Flags.Cf = State->Flags.Cf && ((FirstValue == 0xFFFFFFFF) || (SecondValue == 0xFFFFFFFF));
/* Update the flags */ State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue)); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue + State->Flags.Cf;
/* Special exception for CF */ State->Flags.Cf = State->Flags.Cf && ((FirstValue == 0xFFFF) || (SecondValue == 0xFFFF));
/* Update the flags */ State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue)); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }
}
FAST486_OPCODE_HANDLER(Fast486OpcodeAdcAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x14);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue + State->Flags.Cf;
/* Special exception for CF */ State->Flags.Cf = State->Flags.Cf && ((FirstValue == 0xFF) || (SecondValue == 0xFF));
/* Update the flags */ State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue)); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;}
FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x15);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue + State->Flags.Cf;
/* Special exception for CF */ State->Flags.Cf = State->Flags.Cf && ((FirstValue == 0xFFFFFFFF) || (SecondValue == 0xFFFFFFFF));
/* Update the flags */ State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue)); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].Long = Result; } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue + SecondValue + State->Flags.Cf;
/* Special exception for CF */ State->Flags.Cf = State->Flags.Cf && ((FirstValue == 0xFFFF) || (SecondValue == 0xFFFF));
/* Update the flags */ State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue)); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Result; }}
FAST486_OPCODE_HANDLER(Fast486OpcodePushSs){ /* Call the internal API */ Fast486StackPush(State, State->SegmentRegs[FAST486_REG_SS].Selector);}
FAST486_OPCODE_HANDLER(Fast486OpcodePopSs){ ULONG NewSelector;
if (!Fast486StackPop(State, &NewSelector)) { /* Exception occurred */ return; }
/* Call the internal API */ if (Fast486LoadSegment(State, FAST486_REG_SS, LOWORD(NewSelector))) { /* Inhibit all interrupts until the next instruction */ State->DoNotInterrupt = TRUE; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size; INT Carry = State->Flags.Cf ? 1 : 0;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x18);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Check if this is the instruction that writes to R/M */ if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ SWAP(FirstValue, SecondValue); }
/* Calculate the result */ Result = FirstValue - SecondValue - Carry;
/* Update the flags */ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize; INT Carry = State->Flags.Cf ? 1 : 0;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x19);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Check if this is the instruction that writes to R/M */ if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ SWAP(FirstValue, SecondValue); }
/* Calculate the result */ Result = FirstValue - SecondValue - Carry;
/* Update the flags */ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Check if this is the instruction that writes to R/M */ if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ SWAP(FirstValue, SecondValue); }
/* Calculate the result */ Result = FirstValue - SecondValue - Carry;
/* Update the flags */ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeSbbAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result; INT Carry = State->Flags.Cf ? 1 : 0;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x1C);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue - SecondValue - Carry;
/* Update the flags */ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;}
FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; INT Carry = State->Flags.Cf ? 1 : 0;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x1D);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue - SecondValue - Carry;
/* Update the flags */ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].Long = Result; } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue - SecondValue - Carry;
/* Update the flags */ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0; State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Result; }}
FAST486_OPCODE_HANDLER(Fast486OpcodePushDs){ /* Call the internal API */ Fast486StackPush(State, State->SegmentRegs[FAST486_REG_DS].Selector);}
FAST486_OPCODE_HANDLER(Fast486OpcodePopDs){ ULONG NewSelector;
if (!Fast486StackPop(State, &NewSelector)) { /* Exception occurred */ return; }
/* Call the internal API */ Fast486LoadSegment(State, FAST486_REG_DS, LOWORD(NewSelector));}
FAST486_OPCODE_HANDLER(Fast486OpcodeDaa){ UCHAR Value = State->GeneralRegs[FAST486_REG_EAX].LowByte; BOOLEAN Carry = State->Flags.Cf;
/* Clear the carry flag */ State->Flags.Cf = FALSE;
/* Check if the first BCD digit is invalid or there was a carry from it */ if (((Value & 0x0F) > 9) || State->Flags.Af) { /* Correct it */ State->GeneralRegs[FAST486_REG_EAX].LowByte += 0x06; if (State->GeneralRegs[FAST486_REG_EAX].LowByte < 0x06) { /* A carry occurred */ State->Flags.Cf = TRUE; }
/* Set the adjust flag */ State->Flags.Af = TRUE; }
/* Check if the second BCD digit is invalid or there was a carry from it */ if ((Value > 0x99) || Carry) { /* Correct it */ State->GeneralRegs[FAST486_REG_EAX].LowByte += 0x60;
/* There was a carry */ State->Flags.Cf = TRUE; }
Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
/* Update the flags */ State->Flags.Sf = (Value & SIGN_FLAG_BYTE) != 0; State->Flags.Zf = (Value == 0); State->Flags.Pf = Fast486CalculateParity(Value);}
FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm){ UCHAR FirstValue, SecondValue, Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xED) == 0x28);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Check if this is the instruction that writes to R/M */ if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ SWAP(FirstValue, SecondValue); }
/* Calculate the result */ Result = FirstValue - SecondValue;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */ if (!(Opcode & 0x10)) { /* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xED) == 0x29);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG FirstValue, SecondValue, Result;
if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Check if this is the instruction that writes to R/M */ if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ SWAP(FirstValue, SecondValue); }
/* Calculate the result */ Result = FirstValue - SecondValue;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */ if (!(Opcode & 0x10)) { /* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } } else { USHORT FirstValue, SecondValue, Result;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Check if this is the instruction that writes to R/M */ if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ SWAP(FirstValue, SecondValue); }
/* Calculate the result */ Result = FirstValue - SecondValue;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */ if (!(Opcode & 0x10)) { /* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubAl){ UCHAR FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowByte; UCHAR SecondValue, Result;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xEF) == 0x2C);
NO_LOCK_PREFIX();
if (!Fast486FetchByte(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue - SecondValue;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE)) && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */ if (!(Opcode & 0x10)) { /* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Result; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xEF) == 0x2D);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue, Result;
if (!Fast486FetchDword(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue - SecondValue;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG)) && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */ if (!(Opcode & 0x10)) { /* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].Long = Result; } } else { USHORT FirstValue = State->GeneralRegs[FAST486_REG_EAX].LowWord; USHORT SecondValue, Result;
if (!Fast486FetchWord(State, &SecondValue)) { /* Exception occurred */ return; }
/* Calculate the result */ Result = FirstValue - SecondValue;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD)) && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */ if (!(Opcode & 0x10)) { /* Write back the result */ State->GeneralRegs[FAST486_REG_EAX].LowWord = Result; } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeDas){ UCHAR Value = State->GeneralRegs[FAST486_REG_EAX].LowByte; BOOLEAN Carry = State->Flags.Cf;
/* Clear the carry flag */ State->Flags.Cf = FALSE;
/* Check if the first BCD digit is invalid or there was a borrow */ if (((Value & 0x0F) > 9) || State->Flags.Af) { /* Correct it */ State->GeneralRegs[FAST486_REG_EAX].LowByte -= 0x06; if (State->GeneralRegs[FAST486_REG_EAX].LowByte > 0xFB) { /* A borrow occurred */ State->Flags.Cf = TRUE; }
/* Set the adjust flag */ State->Flags.Af = TRUE; }
/* Check if the second BCD digit is invalid or there was a borrow */ if ((Value > 0x99) || Carry) { /* Correct it */ State->GeneralRegs[FAST486_REG_EAX].LowByte -= 0x60;
/* There was a borrow */ State->Flags.Cf = TRUE; }
Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
/* Update the flags */ State->Flags.Sf = (Value & SIGN_FLAG_BYTE) != 0; State->Flags.Zf = (Value == 0); State->Flags.Pf = Fast486CalculateParity(Value);}
FAST486_OPCODE_HANDLER(Fast486OpcodeAaa){ UCHAR Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
/* * Check if the value in AL is not a valid BCD digit, * or there was a carry from the lowest 4 bits of AL */ if (((Value & 0x0F) > 9) || State->Flags.Af) { /* Correct it */ State->GeneralRegs[FAST486_REG_EAX].LowWord += 0x06; State->GeneralRegs[FAST486_REG_EAX].HighByte++;
/* Set CF and AF */ State->Flags.Cf = State->Flags.Af = TRUE; } else { /* Clear CF and AF */ State->Flags.Cf = State->Flags.Af = FALSE; }
/* Keep only the lowest 4 bits of AL */ State->GeneralRegs[FAST486_REG_EAX].LowByte &= 0x0F;}
FAST486_OPCODE_HANDLER(Fast486OpcodeAas){ UCHAR Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
/* * Check if the value in AL is not a valid BCD digit, * or there was a borrow from the lowest 4 bits of AL */ if (((Value & 0x0F) > 9) || State->Flags.Af) { /* Correct it */ State->GeneralRegs[FAST486_REG_EAX].LowWord -= 0x06; State->GeneralRegs[FAST486_REG_EAX].HighByte--;
/* Set CF and AF */ State->Flags.Cf = State->Flags.Af = TRUE; } else { /* Clear CF and AF */ State->Flags.Cf = State->Flags.Af = FALSE; }
/* Keep only the lowest 4 bits of AL */ State->GeneralRegs[FAST486_REG_EAX].LowByte &= 0x0F;}
FAST486_OPCODE_HANDLER(Fast486OpcodePushAll){ INT i; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; FAST486_REG SavedEsp = State->GeneralRegs[FAST486_REG_ESP];
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x60);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Push all the registers in order */ for (i = 0; i < FAST486_NUM_GEN_REGS; i++) { if (i == FAST486_REG_ESP) { /* Use the saved ESP instead */ if (!Fast486StackPush(State, Size ? SavedEsp.Long : SavedEsp.LowWord)) { /* Exception occurred */ return; } } else { /* Push the register */ if (!Fast486StackPush(State, Size ? State->GeneralRegs[i].Long : State->GeneralRegs[i].LowWord)) { /* Exception occurred */ return; } } }}
FAST486_OPCODE_HANDLER(Fast486OpcodePopAll){ INT i; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; ULONG Value;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x61);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Pop all the registers in reverse order */ for (i = FAST486_NUM_GEN_REGS - 1; i >= 0; i--) { /* Pop the value */ if (!Fast486StackPop(State, &Value)) { /* Exception occurred */ return; }
/* Don't modify ESP */ if (i != FAST486_REG_ESP) { if (Size) State->GeneralRegs[i].Long = Value; else State->GeneralRegs[i].LowWord = LOWORD(Value); } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeBound){ BOOLEAN OperandSize, AddressSize; FAST486_MOD_REG_RM ModRegRm; FAST486_SEG_REGS Segment = FAST486_REG_DS;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!ModRegRm.Memory) { /* Invalid */ Fast486Exception(State, FAST486_EXCEPTION_UD); return; }
/* Check for the segment override */ if (State->PrefixFlags & FAST486_PREFIX_SEG) { /* Use the override segment instead */ Segment = State->SegmentOverride; }
if (OperandSize) { LONG Index, LowerBound, UpperBound;
/* Read the operands */ if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, (PULONG)&Index, (PULONG)&LowerBound)) { /* Exception occurred */ return; }
if (!Fast486ReadMemory(State, Segment, ModRegRm.MemoryAddress + sizeof(ULONG), FALSE, &UpperBound, sizeof(ULONG))) { /* Exception occurred */ return; }
if ((Index < LowerBound) || (Index > UpperBound)) { /* Out of bounds */ Fast486Exception(State, FAST486_EXCEPTION_BR); } } else { SHORT Index, LowerBound, UpperBound;
/* Read the operands */ if (!Fast486ReadModrmWordOperands(State, &ModRegRm, (PUSHORT)&Index, (PUSHORT)&LowerBound)) { /* Exception occurred */ return; }
if (!Fast486ReadMemory(State, Segment, ModRegRm.MemoryAddress + sizeof(USHORT), FALSE, &UpperBound, sizeof(USHORT))) { /* Exception occurred */ return; }
if ((Index < LowerBound) || (Index > UpperBound)) { /* Out of bounds */ Fast486Exception(State, FAST486_EXCEPTION_BR); } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeArpl){ USHORT FirstValue, SecondValue; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
if (!(State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) || State->Flags.Vm || (State->PrefixFlags & FAST486_PREFIX_LOCK)) { /* Cannot be used in real mode or with a LOCK prefix */ Fast486Exception(State, FAST486_EXCEPTION_UD); return; }
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Read the operands */ if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &FirstValue, &SecondValue)) { /* Exception occurred */ return; }
/* Check if the RPL needs adjusting */ if ((SecondValue & 3) < (FirstValue & 3)) { /* Adjust the RPL */ SecondValue &= ~3; SecondValue |= FirstValue & 3;
/* Set ZF */ State->Flags.Zf = TRUE;
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, FALSE, SecondValue); } else { /* Clear ZF */ State->Flags.Zf = FALSE; }}
FAST486_OPCODE_HANDLER(Fast486OpcodePushImm){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x68);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Size) { ULONG Data;
if (!Fast486FetchDword(State, &Data)) { /* Exception occurred */ return; }
/* Call the internal API */ Fast486StackPush(State, Data); } else { SHORT Data;
if (!Fast486FetchWord(State, (PUSHORT)&Data)) { /* Exception occurred */ return; }
/* Call the internal API */ Fast486StackPush(State, Data); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm){ BOOLEAN OperandSize, AddressSize; FAST486_MOD_REG_RM ModRegRm; LONG Multiplier;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x69);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Fetch the parameters */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (Opcode == 0x6B) { CHAR Byte;
/* Fetch the immediate operand */ if (!Fast486FetchByte(State, (PUCHAR)&Byte)) { /* Exception occurred */ return; }
Multiplier = (LONG)Byte; } else { if (OperandSize) { LONG Dword;
/* Fetch the immediate operand */ if (!Fast486FetchDword(State, (PULONG)&Dword)) { /* Exception occurred */ return; }
Multiplier = Dword; } else { SHORT Word;
/* Fetch the immediate operand */ if (!Fast486FetchWord(State, (PUSHORT)&Word)) { /* Exception occurred */ return; }
Multiplier = (LONG)Word; } }
if (OperandSize) { LONG RegValue, Multiplicand; LONGLONG Product;
/* Read the operands */ if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, (PULONG)&RegValue, (PULONG)&Multiplicand)) { /* Exception occurred */ return; }
/* Multiply */ Product = (LONGLONG)Multiplicand * (LONGLONG)Multiplier;
/* Check for carry/overflow */ State->Flags.Cf = State->Flags.Of = ((Product < FAST486_LONG_MIN) || (Product > FAST486_LONG_MAX));
/* Write-back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, TRUE, (ULONG)((LONG)Product)); } else { SHORT RegValue, Multiplicand; LONG Product;
/* Read the operands */ if (!Fast486ReadModrmWordOperands(State, &ModRegRm, (PUSHORT)&RegValue, (PUSHORT)&Multiplicand)) { /* Exception occurred */ return; }
/* Multiply */ Product = (LONG)Multiplicand * (LONG)Multiplier;
/* Check for carry/overflow */ State->Flags.Cf = State->Flags.Of = ((Product < FAST486_SHORT_MIN) || (Product > FAST486_SHORT_MAX));
/* Write-back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, TRUE, (USHORT)((SHORT)Product)); }}
FAST486_OPCODE_HANDLER(Fast486OpcodePushByteImm){ CHAR Data;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x6A);
if (!Fast486FetchByte(State, (PUCHAR)&Data)) { /* Exception occurred */ return; }
/* Call the internal API */ Fast486StackPush(State, Data);}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteModrm){ UCHAR Result; FAST486_MOD_REG_RM ModRegRm; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x88);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (Opcode & FAST486_OPCODE_WRITE_REG) { if (!Fast486ReadModrmByteOperands(State, &ModRegRm, NULL, &Result)) { /* Exception occurred */ return; } } else { if (!Fast486ReadModrmByteOperands(State, &ModRegRm, &Result, NULL)) { /* Exception occurred */ return; } }
/* Write back the result */ Fast486WriteModrmByteOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result);}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFD) == 0x89);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* Check the operand size */ if (OperandSize) { ULONG Result;
if (Opcode & FAST486_OPCODE_WRITE_REG) { if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, NULL, &Result)) { /* Exception occurred */ return; } } else { if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &Result, NULL)) { /* Exception occurred */ return; } }
/* Write back the result */ Fast486WriteModrmDwordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); } else { USHORT Result;
if (Opcode & FAST486_OPCODE_WRITE_REG) { if (!Fast486ReadModrmWordOperands(State, &ModRegRm, NULL, &Result)) { /* Exception occurred */ return; } } else { if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &Result, NULL)) { /* Exception occurred */ return; } }
/* Write back the result */ Fast486WriteModrmWordOperands(State, &ModRegRm, Opcode & FAST486_OPCODE_WRITE_REG, Result); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovStoreSeg){ BOOLEAN OperandSize, AddressSize; FAST486_MOD_REG_RM ModRegRm;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x8C);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (ModRegRm.Register >= FAST486_NUM_SEG_REGS) { /* Invalid */ Fast486Exception(State, FAST486_EXCEPTION_UD); return; }
/* When the other operand is a memory location, always use 16-bit */ if (OperandSize && !ModRegRm.Memory) { Fast486WriteModrmDwordOperands(State, &ModRegRm, FALSE, State->SegmentRegs[ModRegRm.Register].Selector); } else { Fast486WriteModrmWordOperands(State, &ModRegRm, FALSE, State->SegmentRegs[ModRegRm.Register].Selector); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeLea){ FAST486_MOD_REG_RM ModRegRm; BOOLEAN OperandSize, AddressSize;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x8D);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize); TOGGLE_OPSIZE(OperandSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
/* The second operand must be memory */ if (!ModRegRm.Memory) { /* Invalid */ Fast486Exception(State, FAST486_EXCEPTION_UD); return; }
/* Write the address to the register */ if (OperandSize) { Fast486WriteModrmDwordOperands(State, &ModRegRm, TRUE, ModRegRm.MemoryAddress); } else { Fast486WriteModrmWordOperands(State, &ModRegRm, TRUE, ModRegRm.MemoryAddress);
}}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovLoadSeg){ BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size; FAST486_MOD_REG_RM ModRegRm; USHORT Selector;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x8E);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if ((ModRegRm.Register >= FAST486_NUM_SEG_REGS) || ((FAST486_SEG_REGS)ModRegRm.Register == FAST486_REG_CS)) { /* Invalid */ Fast486Exception(State, FAST486_EXCEPTION_UD); return; }
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, NULL, &Selector)) { /* Exception occurred */ return; }
if (!Fast486LoadSegment(State, ModRegRm.Register, Selector)) { /* Exception occurred */ return; }
if ((INT)ModRegRm.Register == FAST486_REG_SS) { /* Inhibit all interrupts until the next instruction */ State->DoNotInterrupt = TRUE; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCwde){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x98);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Size) { /* Sign extend AX to EAX */ State->GeneralRegs[FAST486_REG_EAX].Long = MAKELONG ( State->GeneralRegs[FAST486_REG_EAX].LowWord, (State->GeneralRegs[FAST486_REG_EAX].LowWord & SIGN_FLAG_WORD) ? 0xFFFF : 0x0000 ); } else { /* Sign extend AL to AX */ State->GeneralRegs[FAST486_REG_EAX].HighByte = (State->GeneralRegs[FAST486_REG_EAX].LowByte & SIGN_FLAG_BYTE) ? 0xFF : 0x00; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCdq){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x99);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Size) { /* Sign extend EAX to EDX:EAX */ State->GeneralRegs[FAST486_REG_EDX].Long = (State->GeneralRegs[FAST486_REG_EAX].Long & SIGN_FLAG_LONG) ? 0xFFFFFFFF : 0x00000000; } else { /* Sign extend AX to DX:AX */ State->GeneralRegs[FAST486_REG_EDX].LowWord = (State->GeneralRegs[FAST486_REG_EAX].LowWord & SIGN_FLAG_WORD) ? 0xFFFF : 0x0000; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCallAbs){ USHORT Segment = 0; ULONG Offset = 0; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0x9A);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Fetch the offset */ if (Size) { if (!Fast486FetchDword(State, &Offset)) { /* Exception occurred */ return; } } else { if (!Fast486FetchWord(State, (PUSHORT)&Offset)) { /* Exception occurred */ return; } }
/* Fetch the segment */ if (!Fast486FetchWord(State, &Segment)) { /* Exception occurred */ return; }
if ((State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) && !State->Flags.Vm) { if (!Fast486ProcessGate(State, Segment, Offset, TRUE)) { /* Gate processed or exception occurred */ return; } }
/* Push the current code segment selector */ if (!Fast486StackPush(State, State->SegmentRegs[FAST486_REG_CS].Selector)) { /* Exception occurred */ return; }
/* Push the current value of the instruction pointer */ if (!Fast486StackPush(State, State->InstPtr.Long)) { /* Exception occurred */ return; }
/* Load the new CS */ if (!Fast486LoadSegment(State, FAST486_REG_CS, Segment)) { /* Exception occurred */ return; }
/* Load new (E)IP */ if (Size) State->InstPtr.Long = Offset; else State->InstPtr.LowWord = LOWORD(Offset);}
FAST486_OPCODE_HANDLER(Fast486OpcodeWait){#ifndef FAST486_NO_FPU Fast486FpuExceptionCheck(State);#endif}
FAST486_OPCODE_HANDLER(Fast486OpcodePushFlags){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
/* Check for VM86 mode when IOPL is not 3 */ if (State->Flags.Vm && (State->Flags.Iopl != 3)) { /* Call the VM86 monitor */ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0); return; }
/* Push the flags */ if (Size) Fast486StackPush(State, State->Flags.Long); else Fast486StackPush(State, LOWORD(State->Flags.Long));}
FAST486_OPCODE_HANDLER(Fast486OpcodePopFlags){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; UINT Cpl = Fast486GetCurrentPrivLevel(State); FAST486_FLAGS_REG NewFlags;
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
/* Pop the new flags */ if (!Fast486StackPop(State, &NewFlags.Long)) { /* Exception occurred */ return; }
/* Check for VM86 mode when IOPL is not 3 */ if (State->Flags.Vm && (State->Flags.Iopl != 3)) { /* Call the VM86 monitor */ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0); return; }
State->Flags.Cf = NewFlags.Cf; State->Flags.Pf = NewFlags.Pf; State->Flags.Af = NewFlags.Af; State->Flags.Zf = NewFlags.Zf; State->Flags.Sf = NewFlags.Sf; State->Flags.Tf = NewFlags.Tf; State->Flags.Df = NewFlags.Df; State->Flags.Of = NewFlags.Of; State->Flags.Nt = NewFlags.Nt; State->Flags.Ac = NewFlags.Ac;
if (Cpl == 0) State->Flags.Iopl = NewFlags.Iopl; if (Cpl <= State->Flags.Iopl) State->Flags.If = NewFlags.If;}
FAST486_OPCODE_HANDLER(Fast486OpcodeSahf){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0x9E);
/* Set the low-order byte of FLAGS to AH */ State->Flags.Long &= 0xFFFFFF00; State->Flags.Long |= State->GeneralRegs[FAST486_REG_EAX].HighByte;
/* Restore the reserved bits of FLAGS */ State->Flags.AlwaysSet = TRUE; State->Flags.Reserved0 = State->Flags.Reserved1 = FALSE;}
FAST486_OPCODE_HANDLER(Fast486OpcodeLahf){ /* Make sure this is the right instruction */ ASSERT(Opcode == 0x9F);
/* Set AH to the low-order byte of FLAGS */ State->GeneralRegs[FAST486_REG_EAX].HighByte = LOBYTE(State->Flags.Long);}
FAST486_OPCODE_HANDLER(Fast486OpcodeRet){ ULONG ReturnAddress; USHORT BytesToPop = 0; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xC2);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (Opcode == 0xC2) { /* Fetch the number of bytes to pop after the return */ if (!Fast486FetchWord(State, &BytesToPop)) return; }
/* Pop the return address */ if (!Fast486StackPop(State, &ReturnAddress)) return;
/* Return to the calling procedure, and if necessary, pop the parameters */ if (Size) { State->InstPtr.Long = ReturnAddress; State->GeneralRegs[FAST486_REG_ESP].Long += BytesToPop; } else { State->InstPtr.LowWord = LOWORD(ReturnAddress); State->GeneralRegs[FAST486_REG_ESP].LowWord += BytesToPop; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes){ UCHAR FarPointer[6]; BOOLEAN OperandSize, AddressSize; FAST486_MOD_REG_RM ModRegRm;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xC4);
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
/* Get the operands */ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm)) { /* Exception occurred */ return; }
if (!ModRegRm.Memory) { /* Check if this is a BOP and the host supports BOPs */ if ((Opcode == 0xC4) && (ModRegRm.Register == FAST486_REG_EAX) && (ModRegRm.SecondRegister == FAST486_REG_ESP) && (State->BopCallback != NULL)) { UCHAR BopCode;
/* Fetch the BOP code */ if (!Fast486FetchByte(State, &BopCode)) { /* Exception occurred */ return; }
#ifndef FAST486_NO_PREFETCH /* Invalidate the prefetch since BOP handlers can alter the memory */ State->PrefetchValid = FALSE;#endif
/* Call the BOP handler */ State->BopCallback(State, BopCode);
/* * If an interrupt should occur at this time, delay it. * We must do this because if an interrupt begins and the BOP callback * changes the CS:IP, the interrupt handler won't execute and the * stack pointer will never be restored. */ State->DoNotInterrupt = TRUE;
return; }
/* Invalid */ Fast486Exception(State, FAST486_EXCEPTION_UD); return; }
if (!Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, ModRegRm.MemoryAddress, FALSE, FarPointer, OperandSize ? 6 : 4)) { /* Exception occurred */ return; }
if (OperandSize) { ULONG Offset = *((PULONG)FarPointer); USHORT Segment = *((PUSHORT)&FarPointer[sizeof(ULONG)]);
/* Set the register to the offset */ State->GeneralRegs[ModRegRm.Register].Long = Offset;
/* Load the segment */ Fast486LoadSegment(State, (Opcode == 0xC4) ? FAST486_REG_ES : FAST486_REG_DS, Segment); } else { USHORT Offset = *((PUSHORT)FarPointer); USHORT Segment = *((PUSHORT)&FarPointer[sizeof(USHORT)]);
/* Set the register to the offset */ State->GeneralRegs[ModRegRm.Register].LowWord = Offset;
/* Load the segment */ Fast486LoadSegment(State, (Opcode == 0xC4) ? FAST486_REG_ES : FAST486_REG_DS, Segment); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeEnter){ INT i; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; USHORT FrameSize; UCHAR NestingLevel; FAST486_REG FramePointer;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xC8);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (!Fast486FetchWord(State, &FrameSize)) { /* Exception occurred */ return; }
if (!Fast486FetchByte(State, &NestingLevel)) { /* Exception occurred */ return; }
/* Push EBP */ if (!Fast486StackPush(State, State->GeneralRegs[FAST486_REG_EBP].Long)) { /* Exception occurred */ return; }
/* Save ESP */ FramePointer = State->GeneralRegs[FAST486_REG_ESP];
/* Set up the nested procedure stacks */ for (i = 1; i < NestingLevel; i++) { if (Size) { State->GeneralRegs[FAST486_REG_EBP].Long -= 4; Fast486StackPush(State, State->GeneralRegs[FAST486_REG_EBP].Long); } else { State->GeneralRegs[FAST486_REG_EBP].LowWord -= 2; Fast486StackPush(State, State->GeneralRegs[FAST486_REG_EBP].LowWord); } }
if (NestingLevel > 0) Fast486StackPush(State, FramePointer.Long);
/* Set EBP to the frame pointer */ if (Size) State->GeneralRegs[FAST486_REG_EBP].Long = FramePointer.Long; else State->GeneralRegs[FAST486_REG_EBP].LowWord = FramePointer.LowWord;
/* Reserve space for the frame */ if (State->SegmentRegs[FAST486_REG_SS].Size) { State->GeneralRegs[FAST486_REG_ESP].Long -= (ULONG)FrameSize; } else { State->GeneralRegs[FAST486_REG_ESP].LowWord -= FrameSize; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeLeave){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; ULONG Value;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xC9);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
if (State->SegmentRegs[FAST486_REG_SS].Size) { /* Set the stack pointer (ESP) to the base pointer (EBP) */ State->GeneralRegs[FAST486_REG_ESP].Long = State->GeneralRegs[FAST486_REG_EBP].Long; } else { /* Set the stack pointer (SP) to the base pointer (BP) */ State->GeneralRegs[FAST486_REG_ESP].LowWord = State->GeneralRegs[FAST486_REG_EBP].LowWord; }
/* Pop the saved base pointer from the stack */ if (Fast486StackPop(State, &Value)) { if (Size) State->GeneralRegs[FAST486_REG_EBP].Long = Value; else State->GeneralRegs[FAST486_REG_EBP].LowWord = LOWORD(Value); }}
FAST486_OPCODE_HANDLER(Fast486OpcodeRetFar){ ULONG Segment = 0; ULONG Offset = 0; USHORT BytesToPop = 0; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; ULONG StackPtr; ULONG StackSel; UCHAR OldCpl = Fast486GetCurrentPrivLevel(State);
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xCA);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Opcode == 0xCA) { /* Fetch the number of bytes to pop after the return */ if (!Fast486FetchWord(State, &BytesToPop)) return; }
/* Pop the offset */ if (!Fast486StackPop(State, &Offset)) { /* Exception occurred */ return; }
/* Pop the segment */ if (!Fast486StackPop(State, &Segment)) { /* Exception occurred */ return; }
/* Pop the parameters */ if (State->SegmentRegs[FAST486_REG_SS].Size) { State->GeneralRegs[FAST486_REG_ESP].Long += BytesToPop; } else { State->GeneralRegs[FAST486_REG_ESP].LowWord += BytesToPop; }
if ((State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) && !State->Flags.Vm) { if (GET_SEGMENT_RPL(Segment) > OldCpl) { /* Pop ESP */ if (!Fast486StackPop(State, &StackPtr)) { /* Exception */ return; }
/* Pop SS */ if (!Fast486StackPop(State, &StackSel)) { /* Exception */ return; } } }
/* Load the new CS */ if (!Fast486LoadSegment(State, FAST486_REG_CS, Segment)) { /* Exception occurred */ return; }
/* Load new (E)IP */ if (Size) State->InstPtr.Long = Offset; else State->InstPtr.LowWord = LOWORD(Offset);
if ((State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) && !State->Flags.Vm) { UINT i;
/* Update the CPL */ State->Cpl = GET_SEGMENT_RPL(Segment);
if (State->Cpl > OldCpl) { /* Load new SS */ if (!Fast486LoadSegment(State, FAST486_REG_SS, StackSel)) { /* Exception */ return; }
/* Set ESP */ if (Size) State->GeneralRegs[FAST486_REG_ESP].Long = StackPtr; else State->GeneralRegs[FAST486_REG_ESP].LowWord = LOWORD(StackPtr);
/* Check segment security */ for (i = 0; i < FAST486_NUM_SEG_REGS; i++) { /* Don't check CS or SS */ if ((i == FAST486_REG_CS) || (i == FAST486_REG_SS)) continue;
if ((State->Cpl > State->SegmentRegs[i].Dpl) && (!State->SegmentRegs[i].Executable || !State->SegmentRegs[i].DirConf)) { /* Load the NULL descriptor in the segment */ if (!Fast486LoadSegment(State, i, 0)) return; } } } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeInt){ UCHAR IntNum;
/* Check for V86 mode */ if (State->Flags.Vm && (State->Flags.Iopl != 3)) { /* Call the V86 monitor */ Fast486Exception(State, FAST486_EXCEPTION_GP); return; }
switch (Opcode) { case 0xCC: // INT 3 { /* This is the INT3 instruction */ IntNum = 3; break; }
case 0xCD: // INT xx { /* Fetch the interrupt number */ if (!Fast486FetchByte(State, &IntNum)) { /* Exception occurred */ return; }
break; }
case 0xCE: // INTO { /* Don't do anything if OF is cleared */ if (!State->Flags.Of) return;
/* Exception #OF */ IntNum = FAST486_EXCEPTION_OF;
break; }
default: { /* Should not happen */ ASSERT(FALSE); } }
/* Perform the interrupt */ Fast486PerformInterrupt(State, IntNum);}
FAST486_OPCODE_HANDLER(Fast486OpcodeIret){ FAST486_SEG_REGS i; ULONG InstPtr, CodeSel, StackPtr, StackSel; FAST486_FLAGS_REG NewFlags; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xCF);
NO_LOCK_PREFIX(); TOGGLE_OPSIZE(Size);
/* Check if this is a nested task return */ if (State->Flags.Nt && (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE)) { /* Clear the NT flag of the current task */ State->Flags.Nt = FALSE;
/* Switch to the old task */ Fast486TaskSwitch(State, FAST486_TASK_RETURN, 0); return; }
/* Pop EIP */ if (!Fast486StackPop(State, &InstPtr)) { /* Exception occurred */ return; }
/* Pop CS */ if (!Fast486StackPop(State, &CodeSel)) { /* Exception occurred */ return; }
/* Pop EFLAGS */ if (!Fast486StackPop(State, &NewFlags.Long)) { /* Exception occurred */ return; }
/* Check for protected mode */ if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) { UINT OldCpl = Fast486GetCurrentPrivLevel(State);
if (State->Flags.Vm) { /* Return from VM86 mode */
/* Check the IOPL */ if (State->Flags.Iopl == 3) { /* Set new EIP */ State->InstPtr.Long = LOWORD(InstPtr);
/* Load new CS */ if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel)) { /* Exception occurred */ return; }
/* Set the new flags */ if (Size) State->Flags.Long = NewFlags.Long & REAL_MODE_FLAGS_MASK; else State->Flags.LowWord = NewFlags.LowWord & REAL_MODE_FLAGS_MASK; State->Flags.AlwaysSet = State->Flags.Vm = TRUE; State->Flags.Iopl = 3; } else { /* Call the VM86 monitor */ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0); return; }
return; }
if (NewFlags.Vm) { /* Return to VM86 mode */ ULONG Es, Ds, Fs, Gs;
/* Pop ESP, SS, ES, DS, FS, GS */ if (!Fast486StackPop(State, &StackPtr)) return; if (!Fast486StackPop(State, &StackSel)) return; if (!Fast486StackPop(State, &Es)) return; if (!Fast486StackPop(State, &Ds)) return; if (!Fast486StackPop(State, &Fs)) return; if (!Fast486StackPop(State, &Gs)) return;
/* Set the new IP */ State->InstPtr.Long = LOWORD(InstPtr);
/* Set the new SP */ State->GeneralRegs[FAST486_REG_ESP].Long = StackPtr;
/* Set the new flags */ if (Size) State->Flags.Long = NewFlags.Long & REAL_MODE_FLAGS_MASK; else State->Flags.LowWord = NewFlags.LowWord & REAL_MODE_FLAGS_MASK; State->Flags.AlwaysSet = State->Flags.Vm = TRUE;
/* Switch to CPL 3 */ State->Cpl = 3;
/* Load the new segments */ if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel)) return; if (!Fast486LoadSegment(State, FAST486_REG_SS, StackSel)) return; if (!Fast486LoadSegment(State, FAST486_REG_ES, Es)) return; if (!Fast486LoadSegment(State, FAST486_REG_DS, Ds)) return; if (!Fast486LoadSegment(State, FAST486_REG_FS, Fs)) return; if (!Fast486LoadSegment(State, FAST486_REG_GS, Gs)) return;
return; }
if (GET_SEGMENT_RPL(CodeSel) > OldCpl) { /* Pop ESP */ if (!Fast486StackPop(State, &StackPtr)) { /* Exception */ return; }
/* Pop SS */ if (!Fast486StackPop(State, &StackSel)) { /* Exception */ return; } }
/* Load the new CS */ if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel)) { /* Exception occurred */ return; }
/* Set EIP */ if (Size) State->InstPtr.Long = InstPtr; else State->InstPtr.LowWord = LOWORD(InstPtr);
/* Update the CPL */ State->Cpl = GET_SEGMENT_RPL(CodeSel);
/* Set the new flags */ if (Size) { State->Flags.Long = (State->Flags.Long & ~PROT_MODE_FLAGS_MASK) | (NewFlags.Long & PROT_MODE_FLAGS_MASK); } else { State->Flags.LowWord = (State->Flags.LowWord & ~PROT_MODE_FLAGS_MASK) | (NewFlags.LowWord & PROT_MODE_FLAGS_MASK); } State->Flags.AlwaysSet = TRUE;
/* Set additional flags */ if (OldCpl <= State->Flags.Iopl) State->Flags.If = NewFlags.If; if (OldCpl == 0) State->Flags.Iopl = NewFlags.Iopl;
if (State->Cpl > OldCpl) { /* Load new SS */ if (!Fast486LoadSegment(State, FAST486_REG_SS, StackSel)) { /* Exception */ return; }
/* Set ESP */ if (Size) State->GeneralRegs[FAST486_REG_ESP].Long = StackPtr; else State->GeneralRegs[FAST486_REG_ESP].LowWord = LOWORD(StackPtr);
/* Check segment security */ for (i = 0; i < FAST486_NUM_SEG_REGS; i++) { /* Don't check CS or SS */ if ((i == FAST486_REG_CS) || (i == FAST486_REG_SS)) continue;
if ((State->Cpl > State->SegmentRegs[i].Dpl) && (!State->SegmentRegs[i].Executable || !State->SegmentRegs[i].DirConf)) { /* Load the NULL descriptor in the segment */ if (!Fast486LoadSegment(State, i, 0)) return; } } } } else { if (Size && (InstPtr & 0xFFFF0000)) { /* Invalid */ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0); return; }
/* Set new EIP */ State->InstPtr.Long = InstPtr;
/* Load new CS */ if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel)) { /* Exception occurred */ return; }
/* Set the new flags */ if (Size) State->Flags.Long = NewFlags.Long & REAL_MODE_FLAGS_MASK; else State->Flags.LowWord = NewFlags.LowWord & REAL_MODE_FLAGS_MASK; State->Flags.AlwaysSet = TRUE; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeAam){ UCHAR Base; UCHAR Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
NO_LOCK_PREFIX();
/* Fetch the base */ if (!Fast486FetchByte(State, &Base)) { /* Exception occurred */ return; }
/* Check if the base is zero */ if (Base == 0) { /* Divide error */ Fast486Exception(State, FAST486_EXCEPTION_DE); return; }
/* Adjust */ State->GeneralRegs[FAST486_REG_EAX].HighByte = Value / Base; State->GeneralRegs[FAST486_REG_EAX].LowByte = Value %= Base;
/* Update flags */ State->Flags.Af = FALSE; State->Flags.Zf = (Value == 0); State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Value);}
FAST486_OPCODE_HANDLER(Fast486OpcodeAad){ UCHAR Base; UCHAR Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
NO_LOCK_PREFIX();
/* Fetch the base */ if (!Fast486FetchByte(State, &Base)) { /* Exception occurred */ return; }
/* Adjust */ Value += State->GeneralRegs[FAST486_REG_EAX].HighByte * Base; State->GeneralRegs[FAST486_REG_EAX].LowWord = Value;
/* Update flags */ State->Flags.Af = FALSE; State->Flags.Zf = (Value == 0); State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0); State->Flags.Pf = Fast486CalculateParity(Value);}
FAST486_OPCODE_HANDLER(Fast486OpcodeXlat){ UCHAR Value; BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_ADSIZE(AddressSize);
/* Read a byte from DS:[(E)BX + AL] */ if (!Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, (AddressSize ? State->GeneralRegs[FAST486_REG_EBX].Long : State->GeneralRegs[FAST486_REG_EBX].LowWord) + State->GeneralRegs[FAST486_REG_EAX].LowByte, FALSE, &Value, sizeof(UCHAR))) { /* Exception occurred */ return; }
/* Set AL to the result */ State->GeneralRegs[FAST486_REG_EAX].LowByte = Value;}
FAST486_OPCODE_HANDLER(Fast486OpcodeLoop){ BOOLEAN Condition; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; CHAR Offset = 0;
/* Make sure this is the right instruction */ ASSERT((Opcode >= 0xE0) && (Opcode <= 0xE2));
NO_LOCK_PREFIX(); TOGGLE_ADSIZE(Size);
if (Size) Condition = ((--State->GeneralRegs[FAST486_REG_ECX].Long) != 0); else Condition = ((--State->GeneralRegs[FAST486_REG_ECX].LowWord) != 0);
if (Opcode == 0xE0) { /* Additional rule for LOOPNZ */ if (State->Flags.Zf) Condition = FALSE; } else if (Opcode == 0xE1) { /* Additional rule for LOOPZ */ if (!State->Flags.Zf) Condition = FALSE; }
/* Fetch the offset */ if (!Fast486FetchByte(State, (PUCHAR)&Offset)) { /* An exception occurred */ return; }
if (Condition) { /* Move the instruction pointer */ if (Size) State->InstPtr.Long += Offset; else State->InstPtr.LowWord += Offset; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeJecxz){ BOOLEAN Condition; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size; CHAR Offset = 0;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xE3);
NO_LOCK_PREFIX(); TOGGLE_ADSIZE(Size);
if (Size) Condition = (State->GeneralRegs[FAST486_REG_ECX].Long == 0); else Condition = (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0);
/* Fetch the offset */ if (!Fast486FetchByte(State, (PUCHAR)&Offset)) { /* An exception occurred */ return; }
if (Condition) { /* Move the instruction pointer */ if (Size) State->InstPtr.Long += Offset; else State->InstPtr.LowWord += Offset; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCall){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xE8);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Size) { LONG Offset = 0;
/* Fetch the offset */ if (!Fast486FetchDword(State, (PULONG)&Offset)) { /* An exception occurred */ return; }
/* Push the current value of the instruction pointer */ if (!Fast486StackPush(State, State->InstPtr.Long)) { /* Exception occurred */ return; }
/* Move the instruction pointer */ State->InstPtr.Long += Offset; } else { SHORT Offset = 0;
/* Fetch the offset */ if (!Fast486FetchWord(State, (PUSHORT)&Offset)) { /* An exception occurred */ return; }
/* Push the current value of the instruction pointer */ if (!Fast486StackPush(State, State->InstPtr.Long)) { /* Exception occurred */ return; }
/* Move the instruction pointer */ State->InstPtr.LowWord += Offset; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeJmp){ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xE9);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
if (Size) { LONG Offset = 0;
/* Fetch the offset */ if (!Fast486FetchDword(State, (PULONG)&Offset)) { /* An exception occurred */ return; }
/* Move the instruction pointer */ State->InstPtr.Long += Offset; } else { SHORT Offset = 0;
/* Fetch the offset */ if (!Fast486FetchWord(State, (PUSHORT)&Offset)) { /* An exception occurred */ return; }
/* Move the instruction pointer */ State->InstPtr.Long += Offset;
/* Clear the top half of EIP */ State->InstPtr.Long &= 0xFFFF; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeJmpAbs){ USHORT Segment = 0; ULONG Offset = 0; BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xEA);
TOGGLE_OPSIZE(Size); NO_LOCK_PREFIX();
/* Fetch the offset */ if (Size) { if (!Fast486FetchDword(State, &Offset)) { /* Exception occurred */ return; } } else { if (!Fast486FetchWord(State, (PUSHORT)&Offset)) { /* Exception occurred */ return; } }
/* Fetch the segment */ if (!Fast486FetchWord(State, &Segment)) { /* Exception occurred */ return; }
if ((State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) && !State->Flags.Vm) { if (!Fast486ProcessGate(State, Segment, Offset, FALSE)) { /* Gate processed or exception occurred */ return; } }
/* Load the new CS */ if (!Fast486LoadSegment(State, FAST486_REG_CS, Segment)) { /* Exception occurred */ return; }
/* Load new EIP */ State->InstPtr.Long = Offset;}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovAlOffset){ BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size; ULONG Offset;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xA0);
TOGGLE_ADSIZE(AddressSize);
if (AddressSize) { if (!Fast486FetchDword(State, &Offset)) { /* Exception occurred */ return; } } else { USHORT WordOffset;
if (!Fast486FetchWord(State, &WordOffset)) { /* Exception occurred */ return; }
Offset = (ULONG)WordOffset; }
/* Read from memory */ Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, FALSE, &State->GeneralRegs[FAST486_REG_EAX].LowByte, sizeof(UCHAR));}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovEaxOffset){ BOOLEAN OperandSize, AddressSize;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xA1);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (AddressSize) { ULONG Offset;
if (!Fast486FetchDword(State, &Offset)) { /* Exception occurred */ return; }
/* Read from memory */ if (OperandSize) { Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, FALSE, &State->GeneralRegs[FAST486_REG_EAX].Long, sizeof(ULONG)); } else { Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, FALSE, &State->GeneralRegs[FAST486_REG_EAX].LowWord, sizeof(USHORT)); } } else { USHORT Offset;
if (!Fast486FetchWord(State, &Offset)) { /* Exception occurred */ return; }
/* Read from memory */ if (OperandSize) { Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, FALSE, &State->GeneralRegs[FAST486_REG_EAX].Long, sizeof(ULONG)); } else { Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, FALSE, &State->GeneralRegs[FAST486_REG_EAX].LowWord, sizeof(USHORT)); } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetAl){ BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size; ULONG Offset;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xA2);
TOGGLE_ADSIZE(AddressSize);
if (AddressSize) { if (!Fast486FetchDword(State, &Offset)) { /* Exception occurred */ return; } } else { USHORT WordOffset;
if (!Fast486FetchWord(State, &WordOffset)) { /* Exception occurred */ return; }
Offset = (ULONG)WordOffset; }
/* Write to memory */ Fast486WriteMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, &State->GeneralRegs[FAST486_REG_EAX].LowByte, sizeof(UCHAR));}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax){ BOOLEAN OperandSize, AddressSize;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xA3);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (AddressSize) { ULONG Offset;
if (!Fast486FetchDword(State, &Offset)) { /* Exception occurred */ return; }
/* Write to memory */ if (OperandSize) { Fast486WriteMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, &State->GeneralRegs[FAST486_REG_EAX].Long, sizeof(ULONG)); } else { Fast486WriteMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, &State->GeneralRegs[FAST486_REG_EAX].LowWord, sizeof(USHORT)); } } else { USHORT Offset;
if (!Fast486FetchWord(State, &Offset)) { /* Exception occurred */ return; }
/* Write to memory */ if (OperandSize) { Fast486WriteMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, &State->GeneralRegs[FAST486_REG_EAX].Long, sizeof(ULONG)); } else { Fast486WriteMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, Offset, &State->GeneralRegs[FAST486_REG_EAX].LowWord, sizeof(USHORT)); } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeSalc){ /* * See: http://www.rcollins.org/secrets/opcodes/SALC.html * for more information. */
/* Make sure this is the right instruction */ ASSERT(Opcode == 0xD6);
NO_LOCK_PREFIX();
/* Set all the bits of AL to CF */ State->GeneralRegs[FAST486_REG_EAX].LowByte = State->Flags.Cf ? 0xFF : 0x00;}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovs){ ULONG Data, DataSize; BOOLEAN OperandSize, AddressSize; FAST486_SEG_REGS Segment = FAST486_REG_DS;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xA4);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (State->PrefixFlags & FAST486_PREFIX_SEG) { /* Use the override segment instead of DS */ Segment = State->SegmentOverride; }
if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ)) { if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0)) || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0))) { /* Do nothing */ return; } }
/* Calculate the size */ if (Opcode == 0xA4) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
/* Read from the source operand */ if (!Fast486ReadMemory(State, Segment, AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long : State->GeneralRegs[FAST486_REG_ESI].LowWord, FALSE, &Data, DataSize)) { /* Exception occurred */ return; }
/* Write to the destination operand */ if (!Fast486WriteMemory(State, FAST486_REG_ES, AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long : State->GeneralRegs[FAST486_REG_EDI].LowWord, &Data, DataSize)) { /* Exception occurred */ return; }
/* Increment/decrement ESI and EDI */ if (AddressSize) { if (!State->Flags.Df) { State->GeneralRegs[FAST486_REG_ESI].Long += DataSize; State->GeneralRegs[FAST486_REG_EDI].Long += DataSize; } else { State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize; State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize; } } else { if (!State->Flags.Df) { State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize; State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize; } else { State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize; State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize; } }
// FIXME: This method is slow! if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ)) { if (AddressSize) { if (--State->GeneralRegs[FAST486_REG_ECX].Long) { /* Repeat the instruction */ State->InstPtr = State->SavedInstPtr; } } else { if (--State->GeneralRegs[FAST486_REG_ECX].LowWord) { /* Repeat the instruction */ State->InstPtr = State->SavedInstPtr; } } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeCmps){ ULONG FirstValue = 0, SecondValue = 0, Result; ULONG DataSize, DataMask, SignFlag; BOOLEAN OperandSize, AddressSize; FAST486_SEG_REGS Segment = FAST486_REG_DS;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xA6);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (State->PrefixFlags & FAST486_PREFIX_SEG) { /* Use the override segment instead of DS */ Segment = State->SegmentOverride; }
if ((State->PrefixFlags & FAST486_PREFIX_REP) || (State->PrefixFlags & FAST486_PREFIX_REPNZ)) { if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0)) || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0))) { /* Do nothing */ return; } }
/* Calculate the size */ if (Opcode == 0xA6) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
/* Calculate the mask and sign flag */ SignFlag = 1 << ((DataSize * 8) - 1); DataMask = SignFlag | (SignFlag - 1);
/* Read from the first source operand */ if (!Fast486ReadMemory(State, Segment, AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long : State->GeneralRegs[FAST486_REG_ESI].LowWord, FALSE, &FirstValue, DataSize)) { /* Exception occurred */ return; }
/* Read from the second source operand */ if (!Fast486ReadMemory(State, FAST486_REG_ES, AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long : State->GeneralRegs[FAST486_REG_EDI].LowWord, FALSE, &SecondValue, DataSize)) { /* Exception occurred */ return; }
/* Calculate the result */ FirstValue &= DataMask; SecondValue &= DataMask; Result = (FirstValue - SecondValue) & DataMask;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag)) && ((FirstValue & SignFlag) != (Result & SignFlag)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SignFlag) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Increment/decrement ESI and EDI */ if (AddressSize) { if (!State->Flags.Df) { State->GeneralRegs[FAST486_REG_ESI].Long += DataSize; State->GeneralRegs[FAST486_REG_EDI].Long += DataSize; } else { State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize; State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize; } } else { if (!State->Flags.Df) { State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize; State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize; } else { State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize; State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize; } }
// FIXME: This method is slow! if ((State->PrefixFlags & FAST486_PREFIX_REP) || (State->PrefixFlags & FAST486_PREFIX_REPNZ)) { BOOLEAN Repeat = TRUE;
if (AddressSize) { if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0) { /* ECX is 0 */ Repeat = FALSE; } } else { if ((--State->GeneralRegs[FAST486_REG_ECX].LowWord) == 0) { /* CX is 0 */ Repeat = FALSE; } }
if (((State->PrefixFlags & FAST486_PREFIX_REP) && !State->Flags.Zf) || ((State->PrefixFlags & FAST486_PREFIX_REPNZ) && State->Flags.Zf)) { /* REPZ with ZF = 0 or REPNZ with ZF = 1 */ Repeat = FALSE; }
if (Repeat) { /* Repeat the instruction */ State->InstPtr = State->SavedInstPtr; } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeStos){ ULONG DataSize; BOOLEAN OperandSize, AddressSize;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xAA);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
/* Calculate the size */ if (Opcode == 0xAA) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ)) { UCHAR Block[STRING_BLOCK_SIZE]; ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long : State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* Fill the memory block with the data */ if (DataSize == sizeof(UCHAR)) { RtlFillMemory(Block, sizeof(Block), State->GeneralRegs[FAST486_REG_EAX].LowByte); } else { ULONG i;
for (i = 0; i < STRING_BLOCK_SIZE / DataSize; i++) { if (DataSize == sizeof(USHORT)) { ((PUSHORT)Block)[i] = State->GeneralRegs[FAST486_REG_EAX].LowWord; } else { ((PULONG)Block)[i] = State->GeneralRegs[FAST486_REG_EAX].Long; } } }
/* Transfer until finished */ while (Count) { ULONG Processed = min(Count, STRING_BLOCK_SIZE / DataSize);
/* Simulate the 16-bit wrap-around of DI in 16-bit address mode */ if (!AddressSize) { ULONG MaxBytes = State->Flags.Df ? (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord);
Processed = min(Processed, MaxBytes / DataSize); if (Processed == 0) Processed = 1; }
if (State->Flags.Df) { /* Set EDI to the starting location */ if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= (Processed - 1) * DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord -= (Processed - 1) * DataSize; }
/* Write to memory */ if (!Fast486WriteMemory(State, FAST486_REG_ES, AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long : State->GeneralRegs[FAST486_REG_EDI].LowWord, Block, Processed * DataSize)) { /* Set ECX */ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count; else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
/* Exception occurred */ return; }
if (!State->Flags.Df) { /* Increase EDI by the number of bytes transfered */ if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long += Processed * DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord += Processed * DataSize; } else { /* Reduce EDI */ if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize; }
/* Reduce the total count by the number processed in this run */ Count -= Processed; }
/* Clear ECX */ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0; else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0; } else { /* Write to the destination operand */ if (!Fast486WriteMemory(State, FAST486_REG_ES, AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long : State->GeneralRegs[FAST486_REG_EDI].LowWord, &State->GeneralRegs[FAST486_REG_EAX].Long, DataSize)) { /* Exception occurred */ return; }
/* Increment/decrement EDI */ if (AddressSize) { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize; else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize; } else { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize; } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeLods){ ULONG DataSize; BOOLEAN OperandSize, AddressSize; FAST486_SEG_REGS Segment = FAST486_REG_DS;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xAC);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (State->PrefixFlags & FAST486_PREFIX_SEG) { /* Use the override segment instead of DS */ Segment = State->SegmentOverride; }
/* Calculate the size */ if (Opcode == 0xAC) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ)) { ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long : State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* If the count is 0, do nothing */ if (Count == 0) return;
/* Only the last entry will be loaded */ if (!State->Flags.Df) { if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long += (Count - 1) * DataSize; else State->GeneralRegs[FAST486_REG_ESI].LowWord += (Count - 1) * DataSize; } else { if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long -= (Count - 1) * DataSize; else State->GeneralRegs[FAST486_REG_ESI].LowWord -= (Count - 1) * DataSize; }
/* Clear ECX */ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0; else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0; }
/* Read from the source operand */ if (!Fast486ReadMemory(State, Segment, AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long : State->GeneralRegs[FAST486_REG_ESI].LowWord, FALSE, &State->GeneralRegs[FAST486_REG_EAX].Long, DataSize)) { /* Exception occurred */ return; }
/* Increment/decrement ESI */ if (AddressSize) { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].Long += DataSize; else State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize; } else { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize; else State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize; }}
FAST486_OPCODE_HANDLER(Fast486OpcodeScas){ ULONG FirstValue = State->GeneralRegs[FAST486_REG_EAX].Long; ULONG SecondValue = 0; ULONG Result; ULONG DataSize, DataMask, SignFlag; BOOLEAN OperandSize, AddressSize;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0xAE);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if ((State->PrefixFlags & FAST486_PREFIX_REP) || (State->PrefixFlags & FAST486_PREFIX_REPNZ)) { if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0)) || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0))) { /* Do nothing */ return; } }
/* Calculate the size */ if (Opcode == 0xAE) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
/* Calculate the mask and sign flag */ SignFlag = 1 << ((DataSize * 8) - 1); DataMask = SignFlag | (SignFlag - 1);
/* Read from the source operand */ if (!Fast486ReadMemory(State, FAST486_REG_ES, AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long : State->GeneralRegs[FAST486_REG_EDI].LowWord, FALSE, &SecondValue, DataSize)) { /* Exception occurred */ return; }
/* Calculate the result */ FirstValue &= DataMask; SecondValue &= DataMask; Result = (FirstValue - SecondValue) & DataMask;
/* Update the flags */ State->Flags.Cf = (FirstValue < SecondValue); State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag)) && ((FirstValue & SignFlag) != (Result & SignFlag)); State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F); State->Flags.Zf = (Result == 0); State->Flags.Sf = ((Result & SignFlag) != 0); State->Flags.Pf = Fast486CalculateParity(Result);
/* Increment/decrement EDI */ if (AddressSize) { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize; else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize; } else { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize; }
// FIXME: This method is slow! if ((State->PrefixFlags & FAST486_PREFIX_REP) || (State->PrefixFlags & FAST486_PREFIX_REPNZ)) { BOOLEAN Repeat = TRUE;
if (AddressSize) { if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0) { /* ECX is 0 */ Repeat = FALSE; } } else { if ((--State->GeneralRegs[FAST486_REG_ECX].LowWord) == 0) { /* CX is 0 */ Repeat = FALSE; } }
if (((State->PrefixFlags & FAST486_PREFIX_REP) && !State->Flags.Zf) || ((State->PrefixFlags & FAST486_PREFIX_REPNZ) && State->Flags.Zf)) { /* REPZ with ZF = 0 or REPNZ with ZF = 1 */ Repeat = FALSE; }
if (Repeat) { /* Repeat the instruction */ State->InstPtr = State->SavedInstPtr; } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeIns){ ULONG DataSize; BOOLEAN OperandSize, AddressSize;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0x6C);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (!Fast486IoPrivilegeCheck(State, State->GeneralRegs[FAST486_REG_EDX].LowWord)) return;
/* Calculate the size */ if (Opcode == 0x6C) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ)) { UCHAR Block[STRING_BLOCK_SIZE]; ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long : State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* Clear the memory block */ RtlZeroMemory(Block, sizeof(Block));
/* Transfer until finished */ while (Count) { ULONG Processed = min(Count, STRING_BLOCK_SIZE / DataSize);
/* Simulate the 16-bit wrap-around of DI in 16-bit address mode */ if (!AddressSize) { ULONG MaxBytes = State->Flags.Df ? (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord);
Processed = min(Processed, MaxBytes / DataSize); if (Processed == 0) Processed = 1; }
/* Read from the I/O port */ State->IoReadCallback(State, State->GeneralRegs[FAST486_REG_EDX].LowWord, Block, Processed, DataSize);
if (State->Flags.Df) { ULONG i, j;
/* Reduce EDI by the number of bytes to transfer */ if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= Processed * DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord -= Processed * DataSize;
/* Reverse the block data */ for (i = 0; i < Processed / 2; i++) { /* Swap the values */ for (j = 0; j < DataSize; j++) { UCHAR Temp = Block[i * DataSize + j]; Block[i * DataSize + j] = Block[(Processed - i - 1) * DataSize + j]; Block[(Processed - i - 1) * DataSize + j] = Temp; } } }
/* Write to memory */ if (!Fast486WriteMemory(State, FAST486_REG_ES, AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long : State->GeneralRegs[FAST486_REG_EDI].LowWord, Block, Processed * DataSize)) { /* Set ECX */ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count; else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
/* Exception occurred */ return; }
if (!State->Flags.Df) { /* Increase EDI by the number of bytes transfered */ if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long += Processed * DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord += Processed * DataSize; }
/* Reduce the total count by the number processed in this run */ Count -= Processed; }
/* Clear ECX */ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0; else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0; } else { ULONG Data = 0;
/* Read from the I/O port */ State->IoReadCallback(State, State->GeneralRegs[FAST486_REG_EDX].LowWord, &Data, 1, DataSize);
/* Write to the destination operand */ if (!Fast486WriteMemory(State, FAST486_REG_ES, AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long : State->GeneralRegs[FAST486_REG_EDI].LowWord, &Data, DataSize)) { /* Exception occurred */ return; }
/* Increment/decrement EDI */ if (AddressSize) { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize; else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize; } else { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize; else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize; } }}
FAST486_OPCODE_HANDLER(Fast486OpcodeOuts){ ULONG DataSize; BOOLEAN OperandSize, AddressSize;
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */ ASSERT((Opcode & 0xFE) == 0x6E);
TOGGLE_OPSIZE(OperandSize); TOGGLE_ADSIZE(AddressSize);
if (!Fast486IoPrivilegeCheck(State, State->GeneralRegs[FAST486_REG_EDX].LowWord)) return;
/* Calculate the size */ if (Opcode == 0x6E) DataSize = sizeof(UCHAR); else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ)) { UCHAR Block[STRING_BLOCK_SIZE]; ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long : State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* Clear the memory block */ RtlZeroMemory(Block, sizeof(Block));
/* Transfer until finished */ while (Count) { ULONG Processed = min(Count, STRING_BLOCK_SIZE / DataSize);
/* Simulate the 16-bit wrap-around of DI in 16-bit address mode */ if (!AddressSize) { ULONG MaxBytes = State->Flags.Df ? (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord);
Processed = min(Processed, MaxBytes / DataSize); if (Processed == 0) Processed = 1; }
/* Read from memory */ if (!Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long : State->GeneralRegs[FAST486_REG_ESI].LowWord, FALSE, Block, Processed * DataSize)) { /* Set ECX */ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count; else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
/* Exception occurred */ return; }
if (State->Flags.Df) { ULONG i, j;
/* Reduce ESI by the number of bytes to transfer */ if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long -= Processed * DataSize; else State->GeneralRegs[FAST486_REG_ESI].LowWord -= Processed * DataSize;
/* Reverse the block data */ for (i = 0; i < Processed / 2; i++) { /* Swap the values */ for (j = 0; j < DataSize; j++) { UCHAR Temp = Block[i * DataSize + j]; Block[i * DataSize + j] = Block[(Processed - i - 1) * DataSize + j]; Block[(Processed - i - 1) * DataSize + j] = Temp; } } }
/* Write to the I/O port */ State->IoWriteCallback(State, State->GeneralRegs[FAST486_REG_EDX].LowWord, Block, Processed, DataSize);
if (!State->Flags.Df) { /* Increase ESI by the number of bytes transfered */ if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long += Processed * DataSize; else State->GeneralRegs[FAST486_REG_ESI].LowWord += Processed * DataSize; }
/* Reduce the total count by the number processed in this run */ Count -= Processed; }
/* Clear ECX */ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0; else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0; } else { ULONG Data = 0;
/* Read from the source operand */ if (!Fast486ReadMemory(State, (State->PrefixFlags & FAST486_PREFIX_SEG) ? State->SegmentOverride : FAST486_REG_DS, AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long : State->GeneralRegs[FAST486_REG_ESI].LowWord, FALSE, &Data, DataSize)) { /* Exception occurred */ return; }
/* Write to the I/O port */ State->IoWriteCallback(State, State->GeneralRegs[FAST486_REG_EDX].LowWord, &Data, 1, DataSize);
/* Increment/decrement ESI */ if (AddressSize) { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].Long += DataSize; else State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize; } else { if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize; else State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize; } }}
/* EOF */