tc-m68k.c 201 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144
  1. /* tc-m68k.c -- Assemble for the m68k family
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #include "as.h"
  17. #include "safe-ctype.h"
  18. #include "obstack.h"
  19. #include "subsegs.h"
  20. #include "dwarf2dbg.h"
  21. #include "dw2gencfi.h"
  22. #include "opcode/m68k.h"
  23. #include "m68k-parse.h"
  24. #if defined (OBJ_ELF)
  25. #include "elf/m68k.h"
  26. #endif
  27. #ifdef M68KCOFF
  28. #include "obj-coff.h"
  29. #endif
  30. #ifdef OBJ_ELF
  31. static void m68k_elf_cons (int);
  32. #endif
  33. /* This string holds the chars that always start a comment. If the
  34. pre-processor is disabled, these aren't very useful. The macro
  35. tc_comment_chars points to this. We use this, rather than the
  36. usual comment_chars, so that the --bitwise-or option will work. */
  37. #if defined (TE_SVR4) || defined (TE_DELTA)
  38. const char *m68k_comment_chars = "|#";
  39. #else
  40. const char *m68k_comment_chars = "|";
  41. #endif
  42. /* This array holds the chars that only start a comment at the beginning of
  43. a line. If the line seems to have the form '# 123 filename'
  44. .line and .file directives will appear in the pre-processed output */
  45. /* Note that input_file.c hand checks for '#' at the beginning of the
  46. first line of the input file. This is because the compiler outputs
  47. #NO_APP at the beginning of its output. */
  48. /* Also note that comments like this one will always work. */
  49. const char line_comment_chars[] = "#*";
  50. const char line_separator_chars[] = ";";
  51. /* Chars that can be used to separate mant from exp in floating point nums. */
  52. const char EXP_CHARS[] = "eE";
  53. /* Chars that mean this number is a floating point constant, as
  54. in "0f12.456" or "0d1.2345e12". */
  55. const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  56. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  57. changed in read.c . Ideally it shouldn't have to know about it at all,
  58. but nothing is ideal around here. */
  59. /* Are we trying to generate PIC code? If so, absolute references
  60. ought to be made into linkage table references or pc-relative
  61. references. Not implemented. For ELF there are other means
  62. to denote pic relocations. */
  63. int flag_want_pic;
  64. static int flag_short_refs; /* -l option. */
  65. static int flag_long_jumps; /* -S option. */
  66. static int flag_keep_pcrel; /* --pcrel option. */
  67. #ifdef REGISTER_PREFIX_OPTIONAL
  68. int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
  69. #else
  70. int flag_reg_prefix_optional;
  71. #endif
  72. /* Whether --register-prefix-optional was used on the command line. */
  73. static int reg_prefix_optional_seen;
  74. /* The floating point coprocessor to use by default. */
  75. static enum m68k_register m68k_float_copnum = COP1;
  76. /* If this is non-zero, then references to number(%pc) will be taken
  77. to refer to number, rather than to %pc + number. */
  78. static int m68k_abspcadd;
  79. /* If this is non-zero, then the quick forms of the move, add, and sub
  80. instructions are used when possible. */
  81. static int m68k_quick = 1;
  82. /* If this is non-zero, then if the size is not specified for a base
  83. or outer displacement, the assembler assumes that the size should
  84. be 32 bits. */
  85. static int m68k_rel32 = 1;
  86. /* This is non-zero if m68k_rel32 was set from the command line. */
  87. static int m68k_rel32_from_cmdline;
  88. /* The default width to use for an index register when using a base
  89. displacement. */
  90. static enum m68k_size m68k_index_width_default = SIZE_LONG;
  91. /* We want to warn if any text labels are misaligned. In order to get
  92. the right line number, we need to record the line number for each
  93. label. */
  94. struct label_line
  95. {
  96. struct label_line *next;
  97. symbolS *label;
  98. char *file;
  99. unsigned int line;
  100. int text;
  101. };
  102. /* The list of labels. */
  103. static struct label_line *labels;
  104. /* The current label. */
  105. static struct label_line *current_label;
  106. /* Pointer to list holding the opcodes sorted by name. */
  107. static struct m68k_opcode const ** m68k_sorted_opcodes;
  108. /* Its an arbitrary name: This means I don't approve of it.
  109. See flames below. */
  110. static struct obstack robyn;
  111. struct m68k_incant
  112. {
  113. const char *m_operands;
  114. unsigned long m_opcode;
  115. short m_opnum;
  116. short m_codenum;
  117. int m_arch;
  118. struct m68k_incant *m_next;
  119. };
  120. #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
  121. #define gettwo(x) (((x)->m_opcode)&0xffff)
  122. static const enum m68k_register m68000_ctrl[] = { 0 };
  123. static const enum m68k_register m68010_ctrl[] = {
  124. SFC, DFC, USP, VBR,
  125. 0
  126. };
  127. static const enum m68k_register m68020_ctrl[] = {
  128. SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
  129. 0
  130. };
  131. static const enum m68k_register m68040_ctrl[] = {
  132. SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
  133. USP, VBR, MSP, ISP, MMUSR, URP, SRP,
  134. 0
  135. };
  136. static const enum m68k_register m68060_ctrl[] = {
  137. SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
  138. USP, VBR, URP, SRP, PCR,
  139. 0
  140. };
  141. static const enum m68k_register mcf_ctrl[] = {
  142. CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
  143. RAMBAR0, RAMBAR1, RAMBAR, MBAR,
  144. 0
  145. };
  146. static const enum m68k_register mcf51_ctrl[] = {
  147. VBR, CPUCR,
  148. 0
  149. };
  150. static const enum m68k_register mcf5206_ctrl[] = {
  151. CACR, ACR0, ACR1, VBR, RAMBAR0, RAMBAR_ALT, MBAR,
  152. 0
  153. };
  154. static const enum m68k_register mcf5208_ctrl[] = {
  155. CACR, ACR0, ACR1, VBR, RAMBAR, RAMBAR1,
  156. 0
  157. };
  158. static const enum m68k_register mcf5210a_ctrl[] = {
  159. VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR, RAMBAR1, MBAR,
  160. 0
  161. };
  162. static const enum m68k_register mcf5213_ctrl[] = {
  163. VBR, RAMBAR, RAMBAR1, FLASHBAR,
  164. 0
  165. };
  166. static const enum m68k_register mcf5216_ctrl[] = {
  167. VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, RAMBAR1,
  168. 0
  169. };
  170. static const enum m68k_register mcf5221x_ctrl[] = {
  171. VBR, FLASHBAR, RAMBAR, RAMBAR1,
  172. 0
  173. };
  174. static const enum m68k_register mcf52223_ctrl[] = {
  175. VBR, FLASHBAR, RAMBAR, RAMBAR1,
  176. 0
  177. };
  178. static const enum m68k_register mcf52235_ctrl[] = {
  179. VBR, FLASHBAR, RAMBAR, RAMBAR1,
  180. 0
  181. };
  182. static const enum m68k_register mcf5225_ctrl[] = {
  183. VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, MBAR, RAMBAR1,
  184. 0
  185. };
  186. static const enum m68k_register mcf52259_ctrl[] = {
  187. VBR, FLASHBAR, RAMBAR, RAMBAR1,
  188. 0
  189. };
  190. static const enum m68k_register mcf52277_ctrl[] = {
  191. VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
  192. 0
  193. };
  194. static const enum m68k_register mcf5235_ctrl[] = {
  195. VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
  196. 0
  197. };
  198. static const enum m68k_register mcf5249_ctrl[] = {
  199. VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, RAMBAR, MBAR, MBAR2,
  200. 0
  201. };
  202. static const enum m68k_register mcf5250_ctrl[] = {
  203. VBR,
  204. 0
  205. };
  206. static const enum m68k_register mcf5253_ctrl[] = {
  207. VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR1, RAMBAR, MBAR, MBAR2,
  208. 0
  209. };
  210. static const enum m68k_register mcf5271_ctrl[] = {
  211. VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
  212. 0
  213. };
  214. static const enum m68k_register mcf5272_ctrl[] = {
  215. VBR, CACR, ACR0, ACR1, ROMBAR, RAMBAR_ALT, RAMBAR0, MBAR,
  216. 0
  217. };
  218. static const enum m68k_register mcf5275_ctrl[] = {
  219. VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
  220. 0
  221. };
  222. static const enum m68k_register mcf5282_ctrl[] = {
  223. VBR, CACR, ACR0, ACR1, FLASHBAR, RAMBAR, RAMBAR1,
  224. 0
  225. };
  226. static const enum m68k_register mcf53017_ctrl[] = {
  227. VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
  228. 0
  229. };
  230. static const enum m68k_register mcf5307_ctrl[] = {
  231. VBR, CACR, ACR0, ACR1, RAMBAR0, RAMBAR_ALT, MBAR,
  232. 0
  233. };
  234. static const enum m68k_register mcf5329_ctrl[] = {
  235. VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
  236. 0
  237. };
  238. static const enum m68k_register mcf5373_ctrl[] = {
  239. VBR, CACR, ACR0, ACR1, RAMBAR, RAMBAR1,
  240. 0
  241. };
  242. static const enum m68k_register mcfv4e_ctrl[] = {
  243. CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
  244. VBR, PC, ROMBAR0, ROMBAR1, RAMBAR0, RAMBAR1,
  245. MBAR, SECMBAR,
  246. MPCR /* Multiprocessor Control register */,
  247. EDRAMBAR /* Embedded DRAM Base Address Register */,
  248. /* Permutation control registers. */
  249. PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
  250. PCR3U0, PCR3L0, PCR3U1, PCR3L1,
  251. /* Legacy names */
  252. TC /* ASID */, BUSCR /* MMUBAR */,
  253. ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
  254. MBAR1 /* MBAR */, MBAR2 /* SECMBAR */, MBAR0 /* SECMBAR */,
  255. ROMBAR /* ROMBAR0 */, RAMBAR /* RAMBAR1 */,
  256. 0
  257. };
  258. static const enum m68k_register mcf5407_ctrl[] = {
  259. CACR, ASID, ACR0, ACR1, ACR2, ACR3,
  260. VBR, PC, RAMBAR0, RAMBAR1, MBAR,
  261. /* Legacy names */
  262. TC /* ASID */,
  263. ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
  264. MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
  265. 0
  266. };
  267. static const enum m68k_register mcf54418_ctrl[] = {
  268. CACR, ASID, ACR0, ACR1, ACR2, ACR3, ACR4, ACR5, ACR6, ACR7, MMUBAR, RGPIOBAR,
  269. VBR, PC, RAMBAR1,
  270. /* Legacy names */
  271. TC /* ASID */, BUSCR /* MMUBAR */,
  272. ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
  273. RAMBAR /* RAMBAR1 */,
  274. 0
  275. };
  276. static const enum m68k_register mcf54455_ctrl[] = {
  277. CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
  278. VBR, PC, RAMBAR1,
  279. /* Legacy names */
  280. TC /* ASID */, BUSCR /* MMUBAR */,
  281. ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
  282. RAMBAR /* RAMBAR1 */,
  283. 0
  284. };
  285. static const enum m68k_register mcf5475_ctrl[] = {
  286. CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
  287. VBR, PC, RAMBAR0, RAMBAR1, MBAR,
  288. /* Legacy names */
  289. TC /* ASID */, BUSCR /* MMUBAR */,
  290. ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
  291. MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
  292. 0
  293. };
  294. static const enum m68k_register mcf5485_ctrl[] = {
  295. CACR, ASID, ACR0, ACR1, ACR2, ACR3, MMUBAR,
  296. VBR, PC, RAMBAR0, RAMBAR1, MBAR,
  297. /* Legacy names */
  298. TC /* ASID */, BUSCR /* MMUBAR */,
  299. ITT0 /* ACR0 */, ITT1 /* ACR1 */, DTT0 /* ACR2 */, DTT1 /* ACR3 */,
  300. MBAR1 /* MBAR */, RAMBAR /* RAMBAR1 */,
  301. 0
  302. };
  303. static const enum m68k_register fido_ctrl[] = {
  304. SFC, DFC, USP, VBR, CAC, MBO,
  305. 0
  306. };
  307. #define cpu32_ctrl m68010_ctrl
  308. static const enum m68k_register *control_regs;
  309. /* Internal form of a 68020 instruction. */
  310. struct m68k_it
  311. {
  312. const char *error;
  313. const char *args; /* List of opcode info. */
  314. int numargs;
  315. int numo; /* Number of shorts in opcode. */
  316. short opcode[11];
  317. struct m68k_op operands[6];
  318. int nexp; /* Number of exprs in use. */
  319. struct m68k_exp exprs[4];
  320. int nfrag; /* Number of frags we have to produce. */
  321. struct
  322. {
  323. int fragoff; /* Where in the current opcode the frag ends. */
  324. symbolS *fadd;
  325. offsetT foff;
  326. int fragty;
  327. }
  328. fragb[4];
  329. int nrel; /* Num of reloc strucs in use. */
  330. struct
  331. {
  332. int n;
  333. expressionS exp;
  334. char wid;
  335. char pcrel;
  336. /* In a pc relative address the difference between the address
  337. of the offset and the address that the offset is relative
  338. to. This depends on the addressing mode. Basically this
  339. is the value to put in the offset field to address the
  340. first byte of the offset, without regarding the special
  341. significance of some values (in the branch instruction, for
  342. example). */
  343. int pcrel_fix;
  344. #ifdef OBJ_ELF
  345. /* Whether this expression needs special pic relocation, and if
  346. so, which. */
  347. enum pic_relocation pic_reloc;
  348. #endif
  349. }
  350. reloc[5]; /* Five is enough??? */
  351. };
  352. #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a | fido_a))
  353. #define float_of_arch(x) ((x) & mfloat)
  354. #define mmu_of_arch(x) ((x) & mmmu)
  355. #define arch_coldfire_p(x) ((x) & mcfisa_a)
  356. #define arch_coldfire_fpu(x) ((x) & cfloat)
  357. /* Macros for determining if cpu supports a specific addressing mode. */
  358. #define HAVE_LONG_DISP(x) \
  359. ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
  360. #define HAVE_LONG_CALL(x) \
  361. ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
  362. #define HAVE_LONG_COND(x) \
  363. ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b|mcfisa_c))
  364. #define HAVE_LONG_BRANCH(x) \
  365. ((x) & (m68020|m68030|m68040|m68060|cpu32|fido_a|mcfisa_b))
  366. #define LONG_BRANCH_VIA_COND(x) (HAVE_LONG_COND(x) && !HAVE_LONG_BRANCH(x))
  367. static struct m68k_it the_ins; /* The instruction being assembled. */
  368. #define op(ex) ((ex)->exp.X_op)
  369. #define adds(ex) ((ex)->exp.X_add_symbol)
  370. #define subs(ex) ((ex)->exp.X_op_symbol)
  371. #define offs(ex) ((ex)->exp.X_add_number)
  372. /* Macros for adding things to the m68k_it struct. */
  373. #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
  374. /* Like addword, but goes BEFORE general operands. */
  375. static void
  376. insop (int w, const struct m68k_incant *opcode)
  377. {
  378. int z;
  379. for (z = the_ins.numo; z > opcode->m_codenum; --z)
  380. the_ins.opcode[z] = the_ins.opcode[z - 1];
  381. for (z = 0; z < the_ins.nrel; z++)
  382. the_ins.reloc[z].n += 2;
  383. for (z = 0; z < the_ins.nfrag; z++)
  384. the_ins.fragb[z].fragoff++;
  385. the_ins.opcode[opcode->m_codenum] = w;
  386. the_ins.numo++;
  387. }
  388. /* The numo+1 kludge is so we can hit the low order byte of the prev word.
  389. Blecch. */
  390. static void
  391. add_fix (int width, struct m68k_exp *exp, int pc_rel, int pc_fix)
  392. {
  393. the_ins.reloc[the_ins.nrel].n = (width == 'B' || width == '3'
  394. ? the_ins.numo * 2 - 1
  395. : (width == 'b'
  396. ? the_ins.numo * 2 + 1
  397. : the_ins.numo * 2));
  398. the_ins.reloc[the_ins.nrel].exp = exp->exp;
  399. the_ins.reloc[the_ins.nrel].wid = width;
  400. the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
  401. #ifdef OBJ_ELF
  402. the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
  403. #endif
  404. the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
  405. }
  406. /* Cause an extra frag to be generated here, inserting up to 10 bytes
  407. (that value is chosen in the frag_var call in md_assemble). TYPE
  408. is the subtype of the frag to be generated; its primary type is
  409. rs_machine_dependent.
  410. The TYPE parameter is also used by md_convert_frag_1 and
  411. md_estimate_size_before_relax. The appropriate type of fixup will
  412. be emitted by md_convert_frag_1.
  413. ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
  414. static void
  415. add_frag (symbolS *add, offsetT off, int type)
  416. {
  417. the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
  418. the_ins.fragb[the_ins.nfrag].fadd = add;
  419. the_ins.fragb[the_ins.nfrag].foff = off;
  420. the_ins.fragb[the_ins.nfrag++].fragty = type;
  421. }
  422. #define isvar(ex) \
  423. (op (ex) != O_constant && op (ex) != O_big)
  424. static char *crack_operand (char *str, struct m68k_op *opP);
  425. static int get_num (struct m68k_exp *exp, int ok);
  426. static int reverse_16_bits (int in);
  427. static int reverse_8_bits (int in);
  428. static void install_gen_operand (int mode, int val);
  429. static void install_operand (int mode, int val);
  430. static void s_bss (int);
  431. static void s_data1 (int);
  432. static void s_data2 (int);
  433. static void s_even (int);
  434. static void s_proc (int);
  435. static void s_chip (int);
  436. static void s_fopt (int);
  437. static void s_opt (int);
  438. static void s_reg (int);
  439. static void s_restore (int);
  440. static void s_save (int);
  441. static void s_mri_if (int);
  442. static void s_mri_else (int);
  443. static void s_mri_endi (int);
  444. static void s_mri_break (int);
  445. static void s_mri_next (int);
  446. static void s_mri_for (int);
  447. static void s_mri_endf (int);
  448. static void s_mri_repeat (int);
  449. static void s_mri_until (int);
  450. static void s_mri_while (int);
  451. static void s_mri_endw (int);
  452. static void s_m68k_cpu (int);
  453. static void s_m68k_arch (int);
  454. struct m68k_cpu
  455. {
  456. unsigned long arch; /* Architecture features. */
  457. const enum m68k_register *control_regs; /* Control regs on chip */
  458. const char *name; /* Name */
  459. int alias; /* Alias for a cannonical name. If 1, then
  460. succeeds canonical name, if -1 then
  461. succeeds canonical name, if <-1 ||>1 this is a
  462. deprecated name, and the next/previous name
  463. should be used. */
  464. };
  465. /* We hold flags for features explicitly enabled and explicitly
  466. disabled. */
  467. static int current_architecture;
  468. static int not_current_architecture;
  469. static const struct m68k_cpu *selected_arch;
  470. static const struct m68k_cpu *selected_cpu;
  471. static int initialized;
  472. /* Architecture models. */
  473. static const struct m68k_cpu m68k_archs[] =
  474. {
  475. {m68000, m68000_ctrl, "68000", 0},
  476. {m68010, m68010_ctrl, "68010", 0},
  477. {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
  478. {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
  479. {m68040, m68040_ctrl, "68040", 0},
  480. {m68060, m68060_ctrl, "68060", 0},
  481. {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
  482. {fido_a, fido_ctrl, "fidoa", 0},
  483. {mcfisa_a|mcfhwdiv, NULL, "isaa", 0},
  484. {mcfisa_a|mcfhwdiv|mcfisa_aa|mcfusp, NULL, "isaaplus", 0},
  485. {mcfisa_a|mcfhwdiv|mcfisa_b|mcfusp, NULL, "isab", 0},
  486. {mcfisa_a|mcfhwdiv|mcfisa_c|mcfusp, NULL, "isac", 0},
  487. {mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac|mcfusp, mcf_ctrl, "cfv4", 0},
  488. {mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcfv4e_ctrl, "cfv4e", 0},
  489. {0,0,NULL, 0}
  490. };
  491. /* For -mno-mac we want to turn off all types of mac. */
  492. static const unsigned no_mac = mcfmac | mcfemac;
  493. /* Architecture extensions, here 'alias' -1 for m68k, +1 for cf and 0
  494. for either. */
  495. static const struct m68k_cpu m68k_extensions[] =
  496. {
  497. {m68851, NULL, "68851", -1},
  498. {m68881, NULL, "68881", -1},
  499. {m68881, NULL, "68882", -1},
  500. {cfloat|m68881, NULL, "float", 0},
  501. {mcfhwdiv, NULL, "div", 1},
  502. {mcfusp, NULL, "usp", 1},
  503. {mcfmac, (void *)&no_mac, "mac", 1},
  504. {mcfemac, NULL, "emac", 1},
  505. {0,NULL,NULL, 0}
  506. };
  507. /* Processor list */
  508. static const struct m68k_cpu m68k_cpus[] =
  509. {
  510. {m68000, m68000_ctrl, "68000", 0},
  511. {m68000, m68000_ctrl, "68ec000", 1},
  512. {m68000, m68000_ctrl, "68hc000", 1},
  513. {m68000, m68000_ctrl, "68hc001", 1},
  514. {m68000, m68000_ctrl, "68008", 1},
  515. {m68000, m68000_ctrl, "68302", 1},
  516. {m68000, m68000_ctrl, "68306", 1},
  517. {m68000, m68000_ctrl, "68307", 1},
  518. {m68000, m68000_ctrl, "68322", 1},
  519. {m68000, m68000_ctrl, "68356", 1},
  520. {m68010, m68010_ctrl, "68010", 0},
  521. {m68020|m68881|m68851, m68020_ctrl, "68020", 0},
  522. {m68020|m68881|m68851, m68020_ctrl, "68k", 1},
  523. {m68020|m68881|m68851, m68020_ctrl, "68ec020", 1},
  524. {m68030|m68881|m68851, m68020_ctrl, "68030", 0},
  525. {m68030|m68881|m68851, m68020_ctrl, "68ec030", 1},
  526. {m68040, m68040_ctrl, "68040", 0},
  527. {m68040, m68040_ctrl, "68ec040", 1},
  528. {m68060, m68060_ctrl, "68060", 0},
  529. {m68060, m68060_ctrl, "68ec060", 1},
  530. {cpu32|m68881, cpu32_ctrl, "cpu32", 0},
  531. {cpu32|m68881, cpu32_ctrl, "68330", 1},
  532. {cpu32|m68881, cpu32_ctrl, "68331", 1},
  533. {cpu32|m68881, cpu32_ctrl, "68332", 1},
  534. {cpu32|m68881, cpu32_ctrl, "68333", 1},
  535. {cpu32|m68881, cpu32_ctrl, "68334", 1},
  536. {cpu32|m68881, cpu32_ctrl, "68336", 1},
  537. {cpu32|m68881, cpu32_ctrl, "68340", 1},
  538. {cpu32|m68881, cpu32_ctrl, "68341", 1},
  539. {cpu32|m68881, cpu32_ctrl, "68349", 1},
  540. {cpu32|m68881, cpu32_ctrl, "68360", 1},
  541. {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51", 0},
  542. {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51ac", 1},
  543. {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51ag", 1},
  544. {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51cn", 1},
  545. {mcfisa_a|mcfisa_c|mcfusp|mcfmac, mcf51_ctrl, "51em", 1},
  546. {mcfisa_a|mcfisa_c|mcfusp|mcfmac, mcf51_ctrl, "51je", 1},
  547. {mcfisa_a|mcfisa_c|mcfusp|mcfemac, mcf51_ctrl, "51jf", 1},
  548. {mcfisa_a|mcfisa_c|mcfusp|mcfemac, mcf51_ctrl, "51jg", 1},
  549. {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51jm", 1},
  550. {mcfisa_a|mcfisa_c|mcfusp|mcfmac, mcf51_ctrl, "51mm", 1},
  551. {mcfisa_a|mcfisa_c|mcfusp, mcf51_ctrl, "51qe", 1},
  552. {mcfisa_a|mcfisa_c|mcfusp|mcfemac, mcf51_ctrl, "51qm", 1},
  553. {mcfisa_a, mcf_ctrl, "5200", 0},
  554. {mcfisa_a, mcf_ctrl, "5202", 1},
  555. {mcfisa_a, mcf_ctrl, "5204", 1},
  556. {mcfisa_a, mcf5206_ctrl, "5206", 1},
  557. {mcfisa_a|mcfhwdiv|mcfmac, mcf5206_ctrl, "5206e", 0},
  558. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5207", -1},
  559. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5208_ctrl, "5208", 0},
  560. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5210a_ctrl, "5210a", 0},
  561. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5210a_ctrl, "5211a", 1},
  562. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5211", -1},
  563. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5212", -1},
  564. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5213_ctrl, "5213", 0},
  565. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5214", -1},
  566. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "5216", 0},
  567. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5216_ctrl, "521x", 2},
  568. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5221x_ctrl, "5221x", 0},
  569. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf52223_ctrl, "52221", -1},
  570. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf52223_ctrl, "52223", 0},
  571. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52230", -1},
  572. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52233", -1},
  573. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52234", -1},
  574. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52235_ctrl, "52235", 0},
  575. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5225_ctrl, "5224", -1},
  576. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfmac|mcfusp, mcf5225_ctrl, "5225", 0},
  577. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52277_ctrl, "52274", -1},
  578. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52277_ctrl, "52277", 0},
  579. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5232", -1},
  580. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5233", -1},
  581. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5234", -1},
  582. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "5235", -1},
  583. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5235_ctrl, "523x", 0},
  584. {mcfisa_a|mcfhwdiv|mcfemac, mcf5249_ctrl, "5249", 0},
  585. {mcfisa_a|mcfhwdiv|mcfemac, mcf5250_ctrl, "5250", 0},
  586. {mcfisa_a|mcfhwdiv|mcfemac, mcf5253_ctrl, "5253", 0},
  587. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52252", -1},
  588. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52254", -1},
  589. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52255", -1},
  590. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52256", -1},
  591. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52258", -1},
  592. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf52259_ctrl, "52259", 0},
  593. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5270", -1},
  594. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5271_ctrl, "5271", 0},
  595. {mcfisa_a|mcfhwdiv|mcfmac, mcf5272_ctrl, "5272", 0},
  596. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5274", -1},
  597. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5275_ctrl, "5275", 0},
  598. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5280", -1},
  599. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5281", -1},
  600. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "5282", -1},
  601. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5282_ctrl, "528x", 0},
  602. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53011", -1},
  603. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53012", -1},
  604. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53013", -1},
  605. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53014", -1},
  606. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53015", -1},
  607. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53016", -1},
  608. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf53017_ctrl, "53017", 0},
  609. {mcfisa_a|mcfhwdiv|mcfmac, mcf5307_ctrl, "5307", 0},
  610. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5327", -1},
  611. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5328", -1},
  612. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "5329", -1},
  613. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5329_ctrl, "532x", 0},
  614. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5372", -1},
  615. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "5373", -1},
  616. {mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf5373_ctrl, "537x", 0},
  617. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfmac, mcf5407_ctrl, "5407",0},
  618. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54410", -1},
  619. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54415", -1},
  620. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54416", -1},
  621. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54417", -1},
  622. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54418_ctrl, "54418", 0},
  623. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54450", -1},
  624. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54451", -1},
  625. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54452", -1},
  626. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54453", -1},
  627. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54454", -1},
  628. {mcfisa_a|mcfisa_c|mcfhwdiv|mcfemac|mcfusp, mcf54455_ctrl, "54455", 0},
  629. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5470", -1},
  630. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5471", -1},
  631. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5472", -1},
  632. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5473", -1},
  633. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5474", -1},
  634. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "5475", -1},
  635. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5475_ctrl, "547x", 0},
  636. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5480", -1},
  637. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5481", -1},
  638. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5482", -1},
  639. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5483", -1},
  640. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5484", -1},
  641. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "5485", -1},
  642. {mcfisa_a|mcfisa_b|mcfhwdiv|mcfemac|mcfusp|cfloat, mcf5485_ctrl, "548x", 0},
  643. {fido_a, fido_ctrl, "fidoa", 0},
  644. {fido_a, fido_ctrl, "fido", 1},
  645. {0,NULL,NULL, 0}
  646. };
  647. static const struct m68k_cpu *m68k_lookup_cpu
  648. (const char *, const struct m68k_cpu *, int, int *);
  649. static int m68k_set_arch (const char *, int, int);
  650. static int m68k_set_cpu (const char *, int, int);
  651. static int m68k_set_extension (const char *, int, int);
  652. static void m68k_init_arch (void);
  653. /* This is the assembler relaxation table for m68k. m68k is a rich CISC
  654. architecture and we have a lot of relaxation modes. */
  655. /* Macros used in the relaxation code. */
  656. #define TAB(x,y) (((x) << 2) + (y))
  657. #define TABTYPE(x) ((x) >> 2)
  658. /* Relaxation states. */
  659. #define BYTE 0
  660. #define SHORT 1
  661. #define LONG 2
  662. #define SZ_UNDEF 3
  663. /* Here are all the relaxation modes we support. First we can relax ordinary
  664. branches. On 68020 and higher and on CPU32 all branch instructions take
  665. three forms, so on these CPUs all branches always remain as such. When we
  666. have to expand to the LONG form on a 68000, though, we substitute an
  667. absolute jump instead. This is a direct replacement for unconditional
  668. branches and a branch over a jump for conditional branches. However, if the
  669. user requires PIC and disables this with --pcrel, we can only relax between
  670. BYTE and SHORT forms, punting if that isn't enough. This gives us four
  671. different relaxation modes for branches: */
  672. #define BRANCHBWL 0 /* Branch byte, word, or long. */
  673. #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
  674. #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
  675. #define BRANCHBW 3 /* Branch byte or word. */
  676. /* We also relax coprocessor branches and DBcc's. All CPUs that support
  677. coprocessor branches support them in word and long forms, so we have only
  678. one relaxation mode for them. DBcc's are word only on all CPUs. We can
  679. relax them to the LONG form with a branch-around sequence. This sequence
  680. can use a long branch (if available) or an absolute jump (if acceptable).
  681. This gives us two relaxation modes. If long branches are not available and
  682. absolute jumps are not acceptable, we don't relax DBcc's. */
  683. #define FBRANCH 4 /* Coprocessor branch. */
  684. #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
  685. #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
  686. /* That's all for instruction relaxation. However, we also relax PC-relative
  687. operands. Specifically, we have three operand relaxation modes. On the
  688. 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
  689. on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
  690. two. Also PC+displacement+index operands in their simple form (with a non-
  691. suppressed index without memory indirection) are supported on all CPUs, but
  692. on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
  693. and on CPU32 we relax it to SHORT and LONG forms as well using the extended
  694. form of the PC+displacement+index operand. Finally, some absolute operands
  695. can be relaxed down to 16-bit PC-relative. */
  696. #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
  697. #define PCINDEX 8 /* PC + displacement + index. */
  698. #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
  699. /* This relaxation is required for branches where there is no long
  700. branch and we are in pcrel mode. We generate a bne/beq pair. */
  701. #define BRANCHBWPL 10 /* Branch byte, word or pair of longs
  702. */
  703. /* Note that calls to frag_var need to specify the maximum expansion
  704. needed; this is currently 12 bytes for bne/beq pair. */
  705. #define FRAG_VAR_SIZE 12
  706. /* The fields are:
  707. How far Forward this mode will reach:
  708. How far Backward this mode will reach:
  709. How many bytes this mode will add to the size of the frag
  710. Which mode to go to if the offset won't fit in this one
  711. Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
  712. relax_typeS md_relax_table[] =
  713. {
  714. { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
  715. { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
  716. { 0, 0, 4, 0 },
  717. { 1, 1, 0, 0 },
  718. { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
  719. { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
  720. { 0, 0, 4, 0 },
  721. { 1, 1, 0, 0 },
  722. { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
  723. { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
  724. { 0, 0, 6, 0 },
  725. { 1, 1, 0, 0 },
  726. { 127, -128, 0, TAB (BRANCHBW, SHORT) },
  727. { 0, 0, 2, 0 },
  728. { 1, 1, 0, 0 },
  729. { 1, 1, 0, 0 },
  730. { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
  731. { 32767, -32768, 2, TAB (FBRANCH, LONG) },
  732. { 0, 0, 4, 0 },
  733. { 1, 1, 0, 0 },
  734. { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
  735. { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
  736. { 0, 0, 10, 0 },
  737. { 1, 1, 0, 0 },
  738. { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
  739. { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
  740. { 0, 0, 10, 0 },
  741. { 1, 1, 0, 0 },
  742. { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
  743. { 32767, -32768, 2, TAB (PCREL1632, LONG) },
  744. { 0, 0, 6, 0 },
  745. { 1, 1, 0, 0 },
  746. { 125, -130, 0, TAB (PCINDEX, SHORT) },
  747. { 32765, -32770, 2, TAB (PCINDEX, LONG) },
  748. { 0, 0, 4, 0 },
  749. { 1, 1, 0, 0 },
  750. { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
  751. { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
  752. { 0, 0, 4, 0 },
  753. { 1, 1, 0, 0 },
  754. { 127, -128, 0, TAB (BRANCHBWPL, SHORT) },
  755. { 32767, -32768, 2, TAB (BRANCHBWPL, LONG) },
  756. { 0, 0, 10, 0 },
  757. { 1, 1, 0, 0 },
  758. };
  759. /* These are the machine dependent pseudo-ops. These are included so
  760. the assembler can work on the output from the SUN C compiler, which
  761. generates these. */
  762. /* This table describes all the machine specific pseudo-ops the assembler
  763. has to support. The fields are:
  764. pseudo-op name without dot
  765. function to call to execute this pseudo-op
  766. Integer arg to pass to the function. */
  767. const pseudo_typeS md_pseudo_table[] =
  768. {
  769. {"data1", s_data1, 0},
  770. {"data2", s_data2, 0},
  771. {"bss", s_bss, 0},
  772. {"even", s_even, 0},
  773. {"skip", s_space, 0},
  774. {"proc", s_proc, 0},
  775. #if defined (TE_SUN3) || defined (OBJ_ELF)
  776. {"align", s_align_bytes, 0},
  777. #endif
  778. #ifdef OBJ_ELF
  779. {"swbeg", s_ignore, 0},
  780. {"long", m68k_elf_cons, 4},
  781. #endif
  782. {"extend", float_cons, 'x'},
  783. {"ldouble", float_cons, 'x'},
  784. {"arch", s_m68k_arch, 0},
  785. {"cpu", s_m68k_cpu, 0},
  786. /* The following pseudo-ops are supported for MRI compatibility. */
  787. {"chip", s_chip, 0},
  788. {"comline", s_space, 1},
  789. {"fopt", s_fopt, 0},
  790. {"mask2", s_ignore, 0},
  791. {"opt", s_opt, 0},
  792. {"reg", s_reg, 0},
  793. {"restore", s_restore, 0},
  794. {"save", s_save, 0},
  795. {"if", s_mri_if, 0},
  796. {"if.b", s_mri_if, 'b'},
  797. {"if.w", s_mri_if, 'w'},
  798. {"if.l", s_mri_if, 'l'},
  799. {"else", s_mri_else, 0},
  800. {"else.s", s_mri_else, 's'},
  801. {"else.l", s_mri_else, 'l'},
  802. {"endi", s_mri_endi, 0},
  803. {"break", s_mri_break, 0},
  804. {"break.s", s_mri_break, 's'},
  805. {"break.l", s_mri_break, 'l'},
  806. {"next", s_mri_next, 0},
  807. {"next.s", s_mri_next, 's'},
  808. {"next.l", s_mri_next, 'l'},
  809. {"for", s_mri_for, 0},
  810. {"for.b", s_mri_for, 'b'},
  811. {"for.w", s_mri_for, 'w'},
  812. {"for.l", s_mri_for, 'l'},
  813. {"endf", s_mri_endf, 0},
  814. {"repeat", s_mri_repeat, 0},
  815. {"until", s_mri_until, 0},
  816. {"until.b", s_mri_until, 'b'},
  817. {"until.w", s_mri_until, 'w'},
  818. {"until.l", s_mri_until, 'l'},
  819. {"while", s_mri_while, 0},
  820. {"while.b", s_mri_while, 'b'},
  821. {"while.w", s_mri_while, 'w'},
  822. {"while.l", s_mri_while, 'l'},
  823. {"endw", s_mri_endw, 0},
  824. {0, 0, 0}
  825. };
  826. /* The mote pseudo ops are put into the opcode table, since they
  827. don't start with a . they look like opcodes to gas. */
  828. const pseudo_typeS mote_pseudo_table[] =
  829. {
  830. {"dcl", cons, 4},
  831. {"dc", cons, 2},
  832. {"dcw", cons, 2},
  833. {"dcb", cons, 1},
  834. {"dsl", s_space, 4},
  835. {"ds", s_space, 2},
  836. {"dsw", s_space, 2},
  837. {"dsb", s_space, 1},
  838. {"xdef", s_globl, 0},
  839. #ifdef OBJ_ELF
  840. {"align", s_align_bytes, 0},
  841. #else
  842. {"align", s_align_ptwo, 0},
  843. #endif
  844. #ifdef M68KCOFF
  845. {"sect", obj_coff_section, 0},
  846. {"section", obj_coff_section, 0},
  847. #endif
  848. {0, 0, 0}
  849. };
  850. /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
  851. gives identical results to a 32-bit host. */
  852. #define TRUNC(X) ((valueT) (X) & 0xffffffff)
  853. #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
  854. #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
  855. #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
  856. #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
  857. #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
  858. #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
  859. #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
  860. #define islong(x) (1)
  861. static char notend_table[256];
  862. static char alt_notend_table[256];
  863. #define notend(s) \
  864. (! (notend_table[(unsigned char) *s] \
  865. || (*s == ':' \
  866. && alt_notend_table[(unsigned char) s[1]])))
  867. #ifdef OBJ_ELF
  868. /* Return zero if the reference to SYMBOL from within the same segment may
  869. be relaxed. */
  870. /* On an ELF system, we can't relax an externally visible symbol,
  871. because it may be overridden by a shared library. However, if
  872. TARGET_OS is "elf", then we presume that we are assembling for an
  873. embedded system, in which case we don't have to worry about shared
  874. libraries, and we can relax any external sym. */
  875. #define relaxable_symbol(symbol) \
  876. (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
  877. || S_IS_WEAK (symbol)))
  878. /* Compute the relocation code for a fixup of SIZE bytes, using pc
  879. relative relocation if PCREL is non-zero. PIC says whether a special
  880. pic relocation was requested. */
  881. static bfd_reloc_code_real_type
  882. get_reloc_code (int size, int pcrel, enum pic_relocation pic)
  883. {
  884. switch (pic)
  885. {
  886. case pic_got_pcrel:
  887. switch (size)
  888. {
  889. case 1:
  890. return BFD_RELOC_8_GOT_PCREL;
  891. case 2:
  892. return BFD_RELOC_16_GOT_PCREL;
  893. case 4:
  894. return BFD_RELOC_32_GOT_PCREL;
  895. }
  896. break;
  897. case pic_got_off:
  898. switch (size)
  899. {
  900. case 1:
  901. return BFD_RELOC_8_GOTOFF;
  902. case 2:
  903. return BFD_RELOC_16_GOTOFF;
  904. case 4:
  905. return BFD_RELOC_32_GOTOFF;
  906. }
  907. break;
  908. case pic_plt_pcrel:
  909. switch (size)
  910. {
  911. case 1:
  912. return BFD_RELOC_8_PLT_PCREL;
  913. case 2:
  914. return BFD_RELOC_16_PLT_PCREL;
  915. case 4:
  916. return BFD_RELOC_32_PLT_PCREL;
  917. }
  918. break;
  919. case pic_plt_off:
  920. switch (size)
  921. {
  922. case 1:
  923. return BFD_RELOC_8_PLTOFF;
  924. case 2:
  925. return BFD_RELOC_16_PLTOFF;
  926. case 4:
  927. return BFD_RELOC_32_PLTOFF;
  928. }
  929. break;
  930. case pic_tls_gd:
  931. switch (size)
  932. {
  933. case 1:
  934. return BFD_RELOC_68K_TLS_GD8;
  935. case 2:
  936. return BFD_RELOC_68K_TLS_GD16;
  937. case 4:
  938. return BFD_RELOC_68K_TLS_GD32;
  939. }
  940. break;
  941. case pic_tls_ldm:
  942. switch (size)
  943. {
  944. case 1:
  945. return BFD_RELOC_68K_TLS_LDM8;
  946. case 2:
  947. return BFD_RELOC_68K_TLS_LDM16;
  948. case 4:
  949. return BFD_RELOC_68K_TLS_LDM32;
  950. }
  951. break;
  952. case pic_tls_ldo:
  953. switch (size)
  954. {
  955. case 1:
  956. return BFD_RELOC_68K_TLS_LDO8;
  957. case 2:
  958. return BFD_RELOC_68K_TLS_LDO16;
  959. case 4:
  960. return BFD_RELOC_68K_TLS_LDO32;
  961. }
  962. break;
  963. case pic_tls_ie:
  964. switch (size)
  965. {
  966. case 1:
  967. return BFD_RELOC_68K_TLS_IE8;
  968. case 2:
  969. return BFD_RELOC_68K_TLS_IE16;
  970. case 4:
  971. return BFD_RELOC_68K_TLS_IE32;
  972. }
  973. break;
  974. case pic_tls_le:
  975. switch (size)
  976. {
  977. case 1:
  978. return BFD_RELOC_68K_TLS_LE8;
  979. case 2:
  980. return BFD_RELOC_68K_TLS_LE16;
  981. case 4:
  982. return BFD_RELOC_68K_TLS_LE32;
  983. }
  984. break;
  985. case pic_none:
  986. if (pcrel)
  987. {
  988. switch (size)
  989. {
  990. case 1:
  991. return BFD_RELOC_8_PCREL;
  992. case 2:
  993. return BFD_RELOC_16_PCREL;
  994. case 4:
  995. return BFD_RELOC_32_PCREL;
  996. }
  997. }
  998. else
  999. {
  1000. switch (size)
  1001. {
  1002. case 1:
  1003. return BFD_RELOC_8;
  1004. case 2:
  1005. return BFD_RELOC_16;
  1006. case 4:
  1007. return BFD_RELOC_32;
  1008. }
  1009. }
  1010. }
  1011. if (pcrel)
  1012. {
  1013. if (pic == pic_none)
  1014. as_bad (_("Can not do %d byte pc-relative relocation"), size);
  1015. else
  1016. as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
  1017. }
  1018. else
  1019. {
  1020. if (pic == pic_none)
  1021. as_bad (_("Can not do %d byte relocation"), size);
  1022. else
  1023. as_bad (_("Can not do %d byte pic relocation"), size);
  1024. }
  1025. return BFD_RELOC_NONE;
  1026. }
  1027. /* Here we decide which fixups can be adjusted to make them relative
  1028. to the beginning of the section instead of the symbol. Basically
  1029. we need to make sure that the dynamic relocations are done
  1030. correctly, so in some cases we force the original symbol to be
  1031. used. */
  1032. int
  1033. tc_m68k_fix_adjustable (fixS *fixP)
  1034. {
  1035. /* Adjust_reloc_syms doesn't know about the GOT. */
  1036. switch (fixP->fx_r_type)
  1037. {
  1038. case BFD_RELOC_8_GOT_PCREL:
  1039. case BFD_RELOC_16_GOT_PCREL:
  1040. case BFD_RELOC_32_GOT_PCREL:
  1041. case BFD_RELOC_8_GOTOFF:
  1042. case BFD_RELOC_16_GOTOFF:
  1043. case BFD_RELOC_32_GOTOFF:
  1044. case BFD_RELOC_8_PLT_PCREL:
  1045. case BFD_RELOC_16_PLT_PCREL:
  1046. case BFD_RELOC_32_PLT_PCREL:
  1047. case BFD_RELOC_8_PLTOFF:
  1048. case BFD_RELOC_16_PLTOFF:
  1049. case BFD_RELOC_32_PLTOFF:
  1050. case BFD_RELOC_68K_TLS_GD32:
  1051. case BFD_RELOC_68K_TLS_GD16:
  1052. case BFD_RELOC_68K_TLS_GD8:
  1053. case BFD_RELOC_68K_TLS_LDM32:
  1054. case BFD_RELOC_68K_TLS_LDM16:
  1055. case BFD_RELOC_68K_TLS_LDM8:
  1056. case BFD_RELOC_68K_TLS_LDO32:
  1057. case BFD_RELOC_68K_TLS_LDO16:
  1058. case BFD_RELOC_68K_TLS_LDO8:
  1059. case BFD_RELOC_68K_TLS_IE32:
  1060. case BFD_RELOC_68K_TLS_IE16:
  1061. case BFD_RELOC_68K_TLS_IE8:
  1062. case BFD_RELOC_68K_TLS_LE32:
  1063. case BFD_RELOC_68K_TLS_LE16:
  1064. case BFD_RELOC_68K_TLS_LE8:
  1065. return 0;
  1066. case BFD_RELOC_VTABLE_INHERIT:
  1067. case BFD_RELOC_VTABLE_ENTRY:
  1068. return 0;
  1069. default:
  1070. return 1;
  1071. }
  1072. }
  1073. #else /* !OBJ_ELF */
  1074. #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
  1075. /* PR gas/3041 Weak symbols are not relaxable
  1076. because they must be treated as extern. */
  1077. #define relaxable_symbol(symbol) (!(S_IS_WEAK (symbol)))
  1078. #endif /* OBJ_ELF */
  1079. arelent *
  1080. tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
  1081. {
  1082. arelent *reloc;
  1083. bfd_reloc_code_real_type code;
  1084. /* If the tcbit is set, then this was a fixup of a negative value
  1085. that was never resolved. We do not have a reloc to handle this,
  1086. so just return. We assume that other code will have detected this
  1087. situation and produced a helpful error message, so we just tell the
  1088. user that the reloc cannot be produced. */
  1089. if (fixp->fx_tcbit)
  1090. {
  1091. if (fixp->fx_addsy)
  1092. as_bad_where (fixp->fx_file, fixp->fx_line,
  1093. _("Unable to produce reloc against symbol '%s'"),
  1094. S_GET_NAME (fixp->fx_addsy));
  1095. return NULL;
  1096. }
  1097. if (fixp->fx_r_type != BFD_RELOC_NONE)
  1098. {
  1099. code = fixp->fx_r_type;
  1100. /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
  1101. that fixup_segment converted a non-PC relative reloc into a
  1102. PC relative reloc. In such a case, we need to convert the
  1103. reloc code. */
  1104. if (fixp->fx_pcrel)
  1105. {
  1106. switch (code)
  1107. {
  1108. case BFD_RELOC_8:
  1109. code = BFD_RELOC_8_PCREL;
  1110. break;
  1111. case BFD_RELOC_16:
  1112. code = BFD_RELOC_16_PCREL;
  1113. break;
  1114. case BFD_RELOC_32:
  1115. code = BFD_RELOC_32_PCREL;
  1116. break;
  1117. case BFD_RELOC_8_PCREL:
  1118. case BFD_RELOC_16_PCREL:
  1119. case BFD_RELOC_32_PCREL:
  1120. case BFD_RELOC_8_GOT_PCREL:
  1121. case BFD_RELOC_16_GOT_PCREL:
  1122. case BFD_RELOC_32_GOT_PCREL:
  1123. case BFD_RELOC_8_GOTOFF:
  1124. case BFD_RELOC_16_GOTOFF:
  1125. case BFD_RELOC_32_GOTOFF:
  1126. case BFD_RELOC_8_PLT_PCREL:
  1127. case BFD_RELOC_16_PLT_PCREL:
  1128. case BFD_RELOC_32_PLT_PCREL:
  1129. case BFD_RELOC_8_PLTOFF:
  1130. case BFD_RELOC_16_PLTOFF:
  1131. case BFD_RELOC_32_PLTOFF:
  1132. case BFD_RELOC_68K_TLS_GD32:
  1133. case BFD_RELOC_68K_TLS_GD16:
  1134. case BFD_RELOC_68K_TLS_GD8:
  1135. case BFD_RELOC_68K_TLS_LDM32:
  1136. case BFD_RELOC_68K_TLS_LDM16:
  1137. case BFD_RELOC_68K_TLS_LDM8:
  1138. case BFD_RELOC_68K_TLS_LDO32:
  1139. case BFD_RELOC_68K_TLS_LDO16:
  1140. case BFD_RELOC_68K_TLS_LDO8:
  1141. case BFD_RELOC_68K_TLS_IE32:
  1142. case BFD_RELOC_68K_TLS_IE16:
  1143. case BFD_RELOC_68K_TLS_IE8:
  1144. case BFD_RELOC_68K_TLS_LE32:
  1145. case BFD_RELOC_68K_TLS_LE16:
  1146. case BFD_RELOC_68K_TLS_LE8:
  1147. break;
  1148. default:
  1149. as_bad_where (fixp->fx_file, fixp->fx_line,
  1150. _("Cannot make %s relocation PC relative"),
  1151. bfd_get_reloc_code_name (code));
  1152. }
  1153. }
  1154. }
  1155. else
  1156. {
  1157. #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
  1158. switch (F (fixp->fx_size, fixp->fx_pcrel))
  1159. {
  1160. #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
  1161. MAP (1, 0, BFD_RELOC_8);
  1162. MAP (2, 0, BFD_RELOC_16);
  1163. MAP (4, 0, BFD_RELOC_32);
  1164. MAP (1, 1, BFD_RELOC_8_PCREL);
  1165. MAP (2, 1, BFD_RELOC_16_PCREL);
  1166. MAP (4, 1, BFD_RELOC_32_PCREL);
  1167. default:
  1168. abort ();
  1169. }
  1170. }
  1171. #undef F
  1172. #undef MAP
  1173. reloc = (arelent *) xmalloc (sizeof (arelent));
  1174. reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
  1175. *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
  1176. reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1177. #ifndef OBJ_ELF
  1178. if (OUTPUT_FLAVOR == bfd_target_aout_flavour
  1179. && fixp->fx_addsy
  1180. && S_IS_WEAK (fixp->fx_addsy)
  1181. && ! bfd_is_und_section (S_GET_SEGMENT (fixp->fx_addsy)))
  1182. {
  1183. /* PR gas/3041 References to weak symbols must be treated as extern
  1184. in order to be overridable by the linker, even if they are defined
  1185. in the same object file. So the original addend must be written
  1186. "as is" into the output section without further processing.
  1187. The addend value must be hacked here in order to force
  1188. bfd_install_relocation() to write the original value into the
  1189. output section.
  1190. 1) MD_APPLY_SYM_VALUE() is set to 1 for m68k/a.out, so the symbol
  1191. value has already been added to the addend in fixup_segment(). We
  1192. have to remove it.
  1193. 2) bfd_install_relocation() will incorrectly treat this symbol as
  1194. resolved, so it will write the symbol value plus its addend and
  1195. section VMA. As a workaround we can tweak the addend value here in
  1196. order to get the original value in the section after the call to
  1197. bfd_install_relocation(). */
  1198. reloc->addend = fixp->fx_addnumber
  1199. /* Fix because of MD_APPLY_SYM_VALUE() */
  1200. - S_GET_VALUE (fixp->fx_addsy)
  1201. /* Fix for bfd_install_relocation() */
  1202. - (S_GET_VALUE (fixp->fx_addsy)
  1203. + S_GET_SEGMENT (fixp->fx_addsy)->vma);
  1204. }
  1205. else if (fixp->fx_pcrel)
  1206. reloc->addend = fixp->fx_addnumber;
  1207. else
  1208. reloc->addend = 0;
  1209. #else
  1210. if (!fixp->fx_pcrel)
  1211. reloc->addend = fixp->fx_addnumber;
  1212. else
  1213. reloc->addend = (section->vma
  1214. + fixp->fx_pcrel_adjust
  1215. + fixp->fx_addnumber
  1216. + md_pcrel_from (fixp));
  1217. #endif
  1218. reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  1219. gas_assert (reloc->howto != 0);
  1220. return reloc;
  1221. }
  1222. /* Handle of the OPCODE hash table. NULL means any use before
  1223. m68k_ip_begin() will crash. */
  1224. static struct hash_control *op_hash;
  1225. /* Assemble an m68k instruction. */
  1226. static void
  1227. m68k_ip (char *instring)
  1228. {
  1229. char *p;
  1230. struct m68k_op *opP;
  1231. const struct m68k_incant *opcode;
  1232. const char *s;
  1233. int tmpreg = 0, baseo = 0, outro = 0, nextword;
  1234. char *pdot, *pdotmove;
  1235. enum m68k_size siz1, siz2;
  1236. char c;
  1237. int losing;
  1238. int opsfound;
  1239. struct m68k_op operands_backup[6];
  1240. LITTLENUM_TYPE words[6];
  1241. LITTLENUM_TYPE *wordp;
  1242. unsigned long ok_arch = 0;
  1243. if (*instring == ' ')
  1244. instring++; /* Skip leading whitespace. */
  1245. /* Scan up to end of operation-code, which MUST end in end-of-string
  1246. or exactly 1 space. */
  1247. pdot = 0;
  1248. for (p = instring; *p != '\0'; p++)
  1249. {
  1250. if (*p == ' ')
  1251. break;
  1252. if (*p == '.')
  1253. pdot = p;
  1254. }
  1255. if (p == instring)
  1256. {
  1257. the_ins.error = _("No operator");
  1258. return;
  1259. }
  1260. /* p now points to the end of the opcode name, probably whitespace.
  1261. Make sure the name is null terminated by clobbering the
  1262. whitespace, look it up in the hash table, then fix it back.
  1263. Remove a dot, first, since the opcode tables have none. */
  1264. if (pdot != NULL)
  1265. {
  1266. for (pdotmove = pdot; pdotmove < p; pdotmove++)
  1267. *pdotmove = pdotmove[1];
  1268. p--;
  1269. }
  1270. c = *p;
  1271. *p = '\0';
  1272. opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
  1273. *p = c;
  1274. if (pdot != NULL)
  1275. {
  1276. for (pdotmove = p; pdotmove > pdot; pdotmove--)
  1277. *pdotmove = pdotmove[-1];
  1278. *pdot = '.';
  1279. ++p;
  1280. }
  1281. if (opcode == NULL)
  1282. {
  1283. the_ins.error = _("Unknown operator");
  1284. return;
  1285. }
  1286. /* Found a legitimate opcode, start matching operands. */
  1287. while (*p == ' ')
  1288. ++p;
  1289. if (opcode->m_operands == 0)
  1290. {
  1291. char *old = input_line_pointer;
  1292. *old = '\n';
  1293. input_line_pointer = p;
  1294. /* Ahh - it's a motorola style psuedo op. */
  1295. mote_pseudo_table[opcode->m_opnum].poc_handler
  1296. (mote_pseudo_table[opcode->m_opnum].poc_val);
  1297. input_line_pointer = old;
  1298. *old = 0;
  1299. return;
  1300. }
  1301. if (flag_mri && opcode->m_opnum == 0)
  1302. {
  1303. /* In MRI mode, random garbage is allowed after an instruction
  1304. which accepts no operands. */
  1305. the_ins.args = opcode->m_operands;
  1306. the_ins.numargs = opcode->m_opnum;
  1307. the_ins.numo = opcode->m_codenum;
  1308. the_ins.opcode[0] = getone (opcode);
  1309. the_ins.opcode[1] = gettwo (opcode);
  1310. return;
  1311. }
  1312. for (opP = &the_ins.operands[0]; *p; opP++)
  1313. {
  1314. p = crack_operand (p, opP);
  1315. if (opP->error)
  1316. {
  1317. the_ins.error = opP->error;
  1318. return;
  1319. }
  1320. }
  1321. opsfound = opP - &the_ins.operands[0];
  1322. /* This ugly hack is to support the floating pt opcodes in their
  1323. standard form. Essentially, we fake a first enty of type COP#1 */
  1324. if (opcode->m_operands[0] == 'I')
  1325. {
  1326. int n;
  1327. for (n = opsfound; n > 0; --n)
  1328. the_ins.operands[n] = the_ins.operands[n - 1];
  1329. memset (&the_ins.operands[0], '\0', sizeof (the_ins.operands[0]));
  1330. the_ins.operands[0].mode = CONTROL;
  1331. the_ins.operands[0].reg = m68k_float_copnum;
  1332. opsfound++;
  1333. }
  1334. /* We've got the operands. Find an opcode that'll accept them. */
  1335. for (losing = 0;;)
  1336. {
  1337. /* If we didn't get the right number of ops, or we have no
  1338. common model with this pattern then reject this pattern. */
  1339. ok_arch |= opcode->m_arch;
  1340. if (opsfound != opcode->m_opnum
  1341. || ((opcode->m_arch & current_architecture) == 0))
  1342. ++losing;
  1343. else
  1344. {
  1345. int i;
  1346. /* Make a copy of the operands of this insn so that
  1347. we can modify them safely, should we want to. */
  1348. gas_assert (opsfound <= (int) ARRAY_SIZE (operands_backup));
  1349. for (i = 0; i < opsfound; i++)
  1350. operands_backup[i] = the_ins.operands[i];
  1351. for (s = opcode->m_operands, opP = &operands_backup[0];
  1352. *s && !losing;
  1353. s += 2, opP++)
  1354. {
  1355. /* Warning: this switch is huge! */
  1356. /* I've tried to organize the cases into this order:
  1357. non-alpha first, then alpha by letter. Lower-case
  1358. goes directly before uppercase counterpart. */
  1359. /* Code with multiple case ...: gets sorted by the lowest
  1360. case ... it belongs to. I hope this makes sense. */
  1361. switch (*s)
  1362. {
  1363. case '!':
  1364. switch (opP->mode)
  1365. {
  1366. case IMMED:
  1367. case DREG:
  1368. case AREG:
  1369. case FPREG:
  1370. case CONTROL:
  1371. case AINC:
  1372. case ADEC:
  1373. case REGLST:
  1374. losing++;
  1375. break;
  1376. default:
  1377. break;
  1378. }
  1379. break;
  1380. case '<':
  1381. switch (opP->mode)
  1382. {
  1383. case DREG:
  1384. case AREG:
  1385. case FPREG:
  1386. case CONTROL:
  1387. case IMMED:
  1388. case ADEC:
  1389. case REGLST:
  1390. losing++;
  1391. break;
  1392. default:
  1393. break;
  1394. }
  1395. break;
  1396. case '>':
  1397. switch (opP->mode)
  1398. {
  1399. case DREG:
  1400. case AREG:
  1401. case FPREG:
  1402. case CONTROL:
  1403. case IMMED:
  1404. case AINC:
  1405. case REGLST:
  1406. losing++;
  1407. break;
  1408. case ABSL:
  1409. break;
  1410. default:
  1411. if (opP->reg == PC
  1412. || opP->reg == ZPC)
  1413. losing++;
  1414. break;
  1415. }
  1416. break;
  1417. case 'm':
  1418. switch (opP->mode)
  1419. {
  1420. case DREG:
  1421. case AREG:
  1422. case AINDR:
  1423. case AINC:
  1424. case ADEC:
  1425. break;
  1426. default:
  1427. losing++;
  1428. }
  1429. break;
  1430. case 'n':
  1431. switch (opP->mode)
  1432. {
  1433. case DISP:
  1434. break;
  1435. default:
  1436. losing++;
  1437. }
  1438. break;
  1439. case 'o':
  1440. switch (opP->mode)
  1441. {
  1442. case BASE:
  1443. case ABSL:
  1444. case IMMED:
  1445. break;
  1446. default:
  1447. losing++;
  1448. }
  1449. break;
  1450. case 'p':
  1451. switch (opP->mode)
  1452. {
  1453. case DREG:
  1454. case AREG:
  1455. case AINDR:
  1456. case AINC:
  1457. case ADEC:
  1458. break;
  1459. case DISP:
  1460. if (opP->reg == PC || opP->reg == ZPC)
  1461. losing++;
  1462. break;
  1463. default:
  1464. losing++;
  1465. }
  1466. break;
  1467. case 'q':
  1468. switch (opP->mode)
  1469. {
  1470. case DREG:
  1471. case AINDR:
  1472. case AINC:
  1473. case ADEC:
  1474. break;
  1475. case DISP:
  1476. if (opP->reg == PC || opP->reg == ZPC)
  1477. losing++;
  1478. break;
  1479. default:
  1480. losing++;
  1481. break;
  1482. }
  1483. break;
  1484. case 'v':
  1485. switch (opP->mode)
  1486. {
  1487. case DREG:
  1488. case AINDR:
  1489. case AINC:
  1490. case ADEC:
  1491. case ABSL:
  1492. break;
  1493. case DISP:
  1494. if (opP->reg == PC || opP->reg == ZPC)
  1495. losing++;
  1496. break;
  1497. default:
  1498. losing++;
  1499. break;
  1500. }
  1501. break;
  1502. case '#':
  1503. if (opP->mode != IMMED)
  1504. losing++;
  1505. else if (s[1] == 'b'
  1506. && ! isvar (&opP->disp)
  1507. && (opP->disp.exp.X_op != O_constant
  1508. || ! isbyte (opP->disp.exp.X_add_number)))
  1509. losing++;
  1510. else if (s[1] == 'B'
  1511. && ! isvar (&opP->disp)
  1512. && (opP->disp.exp.X_op != O_constant
  1513. || ! issbyte (opP->disp.exp.X_add_number)))
  1514. losing++;
  1515. else if (s[1] == 'w'
  1516. && ! isvar (&opP->disp)
  1517. && (opP->disp.exp.X_op != O_constant
  1518. || ! isword (opP->disp.exp.X_add_number)))
  1519. losing++;
  1520. else if (s[1] == 'W'
  1521. && ! isvar (&opP->disp)
  1522. && (opP->disp.exp.X_op != O_constant
  1523. || ! issword (opP->disp.exp.X_add_number)))
  1524. losing++;
  1525. break;
  1526. case '^':
  1527. case 'T':
  1528. if (opP->mode != IMMED)
  1529. losing++;
  1530. break;
  1531. case '$':
  1532. if (opP->mode == AREG
  1533. || opP->mode == CONTROL
  1534. || opP->mode == FPREG
  1535. || opP->mode == IMMED
  1536. || opP->mode == REGLST
  1537. || (opP->mode != ABSL
  1538. && (opP->reg == PC
  1539. || opP->reg == ZPC)))
  1540. losing++;
  1541. break;
  1542. case '%':
  1543. if (opP->mode == CONTROL
  1544. || opP->mode == FPREG
  1545. || opP->mode == REGLST
  1546. || opP->mode == IMMED
  1547. || (opP->mode != ABSL
  1548. && (opP->reg == PC
  1549. || opP->reg == ZPC)))
  1550. losing++;
  1551. break;
  1552. case '&':
  1553. switch (opP->mode)
  1554. {
  1555. case DREG:
  1556. case AREG:
  1557. case FPREG:
  1558. case CONTROL:
  1559. case IMMED:
  1560. case AINC:
  1561. case ADEC:
  1562. case REGLST:
  1563. losing++;
  1564. break;
  1565. case ABSL:
  1566. break;
  1567. default:
  1568. if (opP->reg == PC
  1569. || opP->reg == ZPC)
  1570. losing++;
  1571. break;
  1572. }
  1573. break;
  1574. case '*':
  1575. if (opP->mode == CONTROL
  1576. || opP->mode == FPREG
  1577. || opP->mode == REGLST)
  1578. losing++;
  1579. break;
  1580. case '+':
  1581. if (opP->mode != AINC)
  1582. losing++;
  1583. break;
  1584. case '-':
  1585. if (opP->mode != ADEC)
  1586. losing++;
  1587. break;
  1588. case '/':
  1589. switch (opP->mode)
  1590. {
  1591. case AREG:
  1592. case CONTROL:
  1593. case FPREG:
  1594. case AINC:
  1595. case ADEC:
  1596. case IMMED:
  1597. case REGLST:
  1598. losing++;
  1599. break;
  1600. default:
  1601. break;
  1602. }
  1603. break;
  1604. case ';':
  1605. switch (opP->mode)
  1606. {
  1607. case AREG:
  1608. case CONTROL:
  1609. case FPREG:
  1610. case REGLST:
  1611. losing++;
  1612. break;
  1613. default:
  1614. break;
  1615. }
  1616. break;
  1617. case '?':
  1618. switch (opP->mode)
  1619. {
  1620. case AREG:
  1621. case CONTROL:
  1622. case FPREG:
  1623. case AINC:
  1624. case ADEC:
  1625. case IMMED:
  1626. case REGLST:
  1627. losing++;
  1628. break;
  1629. case ABSL:
  1630. break;
  1631. default:
  1632. if (opP->reg == PC || opP->reg == ZPC)
  1633. losing++;
  1634. break;
  1635. }
  1636. break;
  1637. case '@':
  1638. switch (opP->mode)
  1639. {
  1640. case AREG:
  1641. case CONTROL:
  1642. case FPREG:
  1643. case IMMED:
  1644. case REGLST:
  1645. losing++;
  1646. break;
  1647. default:
  1648. break;
  1649. }
  1650. break;
  1651. case '~': /* For now! (JF FOO is this right?) */
  1652. switch (opP->mode)
  1653. {
  1654. case DREG:
  1655. case AREG:
  1656. case CONTROL:
  1657. case FPREG:
  1658. case IMMED:
  1659. case REGLST:
  1660. losing++;
  1661. break;
  1662. case ABSL:
  1663. break;
  1664. default:
  1665. if (opP->reg == PC
  1666. || opP->reg == ZPC)
  1667. losing++;
  1668. break;
  1669. }
  1670. break;
  1671. case '3':
  1672. if (opP->mode != CONTROL
  1673. || (opP->reg != TT0 && opP->reg != TT1))
  1674. losing++;
  1675. break;
  1676. case 'A':
  1677. if (opP->mode != AREG)
  1678. losing++;
  1679. break;
  1680. case 'a':
  1681. if (opP->mode != AINDR)
  1682. ++losing;
  1683. break;
  1684. case '4':
  1685. if (opP->mode != AINDR && opP->mode != AINC && opP->mode != ADEC
  1686. && (opP->mode != DISP
  1687. || opP->reg < ADDR0
  1688. || opP->reg > ADDR7))
  1689. ++losing;
  1690. break;
  1691. case 'B': /* FOO */
  1692. if (opP->mode != ABSL
  1693. || (flag_long_jumps
  1694. && strncmp (instring, "jbsr", 4) == 0))
  1695. losing++;
  1696. break;
  1697. case 'b':
  1698. switch (opP->mode)
  1699. {
  1700. case IMMED:
  1701. case ABSL:
  1702. case AREG:
  1703. case FPREG:
  1704. case CONTROL:
  1705. case POST:
  1706. case PRE:
  1707. case REGLST:
  1708. losing++;
  1709. break;
  1710. default:
  1711. break;
  1712. }
  1713. break;
  1714. case 'C':
  1715. if (opP->mode != CONTROL || opP->reg != CCR)
  1716. losing++;
  1717. break;
  1718. case 'd':
  1719. if (opP->mode != DISP
  1720. || opP->reg < ADDR0
  1721. || opP->reg > ADDR7)
  1722. losing++;
  1723. break;
  1724. case 'D':
  1725. if (opP->mode != DREG)
  1726. losing++;
  1727. break;
  1728. case 'E':
  1729. if (opP->reg != ACC)
  1730. losing++;
  1731. break;
  1732. case 'e':
  1733. if (opP->reg != ACC && opP->reg != ACC1
  1734. && opP->reg != ACC2 && opP->reg != ACC3)
  1735. losing++;
  1736. break;
  1737. case 'F':
  1738. if (opP->mode != FPREG)
  1739. losing++;
  1740. break;
  1741. case 'G':
  1742. if (opP->reg != MACSR)
  1743. losing++;
  1744. break;
  1745. case 'g':
  1746. if (opP->reg != ACCEXT01 && opP->reg != ACCEXT23)
  1747. losing++;
  1748. break;
  1749. case 'H':
  1750. if (opP->reg != MASK)
  1751. losing++;
  1752. break;
  1753. case 'I':
  1754. if (opP->mode != CONTROL
  1755. || opP->reg < COP0
  1756. || opP->reg > COP7)
  1757. losing++;
  1758. break;
  1759. case 'i':
  1760. if (opP->mode != LSH && opP->mode != RSH)
  1761. losing++;
  1762. break;
  1763. case 'J':
  1764. if (opP->mode != CONTROL
  1765. || opP->reg < USP
  1766. || opP->reg > last_movec_reg
  1767. || !control_regs)
  1768. losing++;
  1769. else
  1770. {
  1771. const enum m68k_register *rp;
  1772. for (rp = control_regs; *rp; rp++)
  1773. {
  1774. if (*rp == opP->reg)
  1775. break;
  1776. /* In most CPUs RAMBAR refers to control reg
  1777. c05 (RAMBAR1), but a few CPUs have it
  1778. refer to c04 (RAMBAR0). */
  1779. else if (*rp == RAMBAR_ALT && opP->reg == RAMBAR)
  1780. {
  1781. opP->reg = RAMBAR_ALT;
  1782. break;
  1783. }
  1784. }
  1785. if (*rp == 0)
  1786. losing++;
  1787. }
  1788. break;
  1789. case 'k':
  1790. if (opP->mode != IMMED)
  1791. losing++;
  1792. break;
  1793. case 'l':
  1794. case 'L':
  1795. if (opP->mode == DREG
  1796. || opP->mode == AREG
  1797. || opP->mode == FPREG)
  1798. {
  1799. if (s[1] == '8')
  1800. losing++;
  1801. else
  1802. {
  1803. switch (opP->mode)
  1804. {
  1805. case DREG:
  1806. opP->mask = 1 << (opP->reg - DATA0);
  1807. break;
  1808. case AREG:
  1809. opP->mask = 1 << (opP->reg - ADDR0 + 8);
  1810. break;
  1811. case FPREG:
  1812. opP->mask = 1 << (opP->reg - FP0 + 16);
  1813. break;
  1814. default:
  1815. abort ();
  1816. }
  1817. opP->mode = REGLST;
  1818. }
  1819. }
  1820. else if (opP->mode == CONTROL)
  1821. {
  1822. if (s[1] != '8')
  1823. losing++;
  1824. else
  1825. {
  1826. switch (opP->reg)
  1827. {
  1828. case FPI:
  1829. opP->mask = 1 << 24;
  1830. break;
  1831. case FPS:
  1832. opP->mask = 1 << 25;
  1833. break;
  1834. case FPC:
  1835. opP->mask = 1 << 26;
  1836. break;
  1837. default:
  1838. losing++;
  1839. break;
  1840. }
  1841. opP->mode = REGLST;
  1842. }
  1843. }
  1844. else if (opP->mode != REGLST)
  1845. losing++;
  1846. else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
  1847. losing++;
  1848. else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
  1849. losing++;
  1850. break;
  1851. case 'M':
  1852. if (opP->mode != IMMED)
  1853. losing++;
  1854. else if (opP->disp.exp.X_op != O_constant
  1855. || ! issbyte (opP->disp.exp.X_add_number))
  1856. losing++;
  1857. else if (! m68k_quick
  1858. && instring[3] != 'q'
  1859. && instring[4] != 'q')
  1860. losing++;
  1861. break;
  1862. case 'O':
  1863. if (opP->mode != DREG
  1864. && opP->mode != IMMED
  1865. && opP->mode != ABSL)
  1866. losing++;
  1867. break;
  1868. case 'Q':
  1869. if (opP->mode != IMMED)
  1870. losing++;
  1871. else if (opP->disp.exp.X_op != O_constant
  1872. || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
  1873. losing++;
  1874. else if (! m68k_quick
  1875. && (strncmp (instring, "add", 3) == 0
  1876. || strncmp (instring, "sub", 3) == 0)
  1877. && instring[3] != 'q')
  1878. losing++;
  1879. break;
  1880. case 'R':
  1881. if (opP->mode != DREG && opP->mode != AREG)
  1882. losing++;
  1883. break;
  1884. case 'r':
  1885. if (opP->mode != AINDR
  1886. && (opP->mode != BASE
  1887. || (opP->reg != 0
  1888. && opP->reg != ZADDR0)
  1889. || opP->disp.exp.X_op != O_absent
  1890. || ((opP->index.reg < DATA0
  1891. || opP->index.reg > DATA7)
  1892. && (opP->index.reg < ADDR0
  1893. || opP->index.reg > ADDR7))
  1894. || opP->index.size != SIZE_UNSPEC
  1895. || opP->index.scale != 1))
  1896. losing++;
  1897. break;
  1898. case 's':
  1899. if (opP->mode != CONTROL
  1900. || ! (opP->reg == FPI
  1901. || opP->reg == FPS
  1902. || opP->reg == FPC))
  1903. losing++;
  1904. break;
  1905. case 'S':
  1906. if (opP->mode != CONTROL || opP->reg != SR)
  1907. losing++;
  1908. break;
  1909. case 't':
  1910. if (opP->mode != IMMED)
  1911. losing++;
  1912. else if (opP->disp.exp.X_op != O_constant
  1913. || TRUNC (opP->disp.exp.X_add_number) > 7)
  1914. losing++;
  1915. break;
  1916. case 'U':
  1917. if (opP->mode != CONTROL || opP->reg != USP)
  1918. losing++;
  1919. break;
  1920. case 'x':
  1921. if (opP->mode != IMMED)
  1922. losing++;
  1923. else if (opP->disp.exp.X_op != O_constant
  1924. || (TRUNC (opP->disp.exp.X_add_number) != 0xffffffff
  1925. && TRUNC (opP->disp.exp.X_add_number) - 1 > 6))
  1926. losing++;
  1927. break;
  1928. case 'j':
  1929. if (opP->mode != IMMED)
  1930. losing++;
  1931. else if (opP->disp.exp.X_op != O_constant
  1932. || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
  1933. losing++;
  1934. break;
  1935. case 'K':
  1936. if (opP->mode != IMMED)
  1937. losing++;
  1938. else if (opP->disp.exp.X_op != O_constant
  1939. || TRUNC (opP->disp.exp.X_add_number) > 511)
  1940. losing++;
  1941. break;
  1942. /* JF these are out of order. We could put them
  1943. in order if we were willing to put up with
  1944. bunches of #ifdef m68851s in the code.
  1945. Don't forget that you need these operands
  1946. to use 68030 MMU instructions. */
  1947. #ifndef NO_68851
  1948. /* Memory addressing mode used by pflushr. */
  1949. case '|':
  1950. if (opP->mode == CONTROL
  1951. || opP->mode == FPREG
  1952. || opP->mode == DREG
  1953. || opP->mode == AREG
  1954. || opP->mode == REGLST)
  1955. losing++;
  1956. /* We should accept immediate operands, but they
  1957. supposedly have to be quad word, and we don't
  1958. handle that. I would like to see what a Motorola
  1959. assembler does before doing something here. */
  1960. if (opP->mode == IMMED)
  1961. losing++;
  1962. break;
  1963. case 'f':
  1964. if (opP->mode != CONTROL
  1965. || (opP->reg != SFC && opP->reg != DFC))
  1966. losing++;
  1967. break;
  1968. case '0':
  1969. if (opP->mode != CONTROL || opP->reg != TC)
  1970. losing++;
  1971. break;
  1972. case '1':
  1973. if (opP->mode != CONTROL || opP->reg != AC)
  1974. losing++;
  1975. break;
  1976. case '2':
  1977. if (opP->mode != CONTROL
  1978. || (opP->reg != CAL
  1979. && opP->reg != VAL
  1980. && opP->reg != SCC))
  1981. losing++;
  1982. break;
  1983. case 'V':
  1984. if (opP->mode != CONTROL
  1985. || opP->reg != VAL)
  1986. losing++;
  1987. break;
  1988. case 'W':
  1989. if (opP->mode != CONTROL
  1990. || (opP->reg != DRP
  1991. && opP->reg != SRP
  1992. && opP->reg != CRP))
  1993. losing++;
  1994. break;
  1995. case 'w':
  1996. switch (opP->mode)
  1997. {
  1998. case IMMED:
  1999. case ABSL:
  2000. case AREG:
  2001. case DREG:
  2002. case FPREG:
  2003. case CONTROL:
  2004. case POST:
  2005. case PRE:
  2006. case REGLST:
  2007. losing++;
  2008. break;
  2009. default:
  2010. break;
  2011. }
  2012. break;
  2013. case 'X':
  2014. if (opP->mode != CONTROL
  2015. || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
  2016. && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
  2017. losing++;
  2018. break;
  2019. case 'Y':
  2020. if (opP->mode != CONTROL || opP->reg != PSR)
  2021. losing++;
  2022. break;
  2023. case 'Z':
  2024. if (opP->mode != CONTROL || opP->reg != PCSR)
  2025. losing++;
  2026. break;
  2027. #endif
  2028. case 'c':
  2029. if (opP->mode != CONTROL
  2030. || (opP->reg != NC
  2031. && opP->reg != IC
  2032. && opP->reg != DC
  2033. && opP->reg != BC))
  2034. losing++;
  2035. break;
  2036. case '_':
  2037. if (opP->mode != ABSL)
  2038. ++losing;
  2039. break;
  2040. case 'u':
  2041. if (opP->reg < DATA0L || opP->reg > ADDR7U)
  2042. losing++;
  2043. /* FIXME: kludge instead of fixing parser:
  2044. upper/lower registers are *not* CONTROL
  2045. registers, but ordinary ones. */
  2046. if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
  2047. || (opP->reg >= DATA0U && opP->reg <= DATA7U))
  2048. opP->mode = DREG;
  2049. else
  2050. opP->mode = AREG;
  2051. break;
  2052. case 'y':
  2053. if (!(opP->mode == AINDR
  2054. || (opP->mode == DISP
  2055. && !(opP->reg == PC || opP->reg == ZPC))))
  2056. losing++;
  2057. break;
  2058. case 'z':
  2059. if (!(opP->mode == AINDR || opP->mode == DISP))
  2060. losing++;
  2061. break;
  2062. default:
  2063. abort ();
  2064. }
  2065. if (losing)
  2066. break;
  2067. }
  2068. /* Since we have found the correct instruction, copy
  2069. in the modifications that we may have made. */
  2070. if (!losing)
  2071. for (i = 0; i < opsfound; i++)
  2072. the_ins.operands[i] = operands_backup[i];
  2073. }
  2074. if (!losing)
  2075. break;
  2076. opcode = opcode->m_next;
  2077. if (!opcode)
  2078. {
  2079. if (ok_arch
  2080. && !(ok_arch & current_architecture))
  2081. {
  2082. const struct m68k_cpu *cpu;
  2083. int any = 0;
  2084. size_t space = 400;
  2085. char *buf = xmalloc (space + 1);
  2086. size_t len;
  2087. int paren = 1;
  2088. the_ins.error = buf;
  2089. /* Make sure there's a NUL at the end of the buffer -- strncpy
  2090. won't write one when it runs out of buffer. */
  2091. buf[space] = 0;
  2092. #define APPEND(STRING) \
  2093. (strncpy (buf, STRING, space), len = strlen (buf), buf += len, space -= len)
  2094. APPEND (_("invalid instruction for this architecture; needs "));
  2095. switch (ok_arch)
  2096. {
  2097. case mcfisa_a:
  2098. APPEND ("ColdFire ISA_A");
  2099. break;
  2100. case mcfhwdiv:
  2101. APPEND ("ColdFire ");
  2102. APPEND (_("hardware divide"));
  2103. break;
  2104. case mcfisa_aa:
  2105. APPEND ("ColdFire ISA_A+");
  2106. break;
  2107. case mcfisa_b:
  2108. APPEND ("ColdFire ISA_B");
  2109. break;
  2110. case mcfisa_c:
  2111. APPEND ("ColdFire ISA_C");
  2112. break;
  2113. case cfloat:
  2114. APPEND ("ColdFire fpu");
  2115. break;
  2116. case mfloat:
  2117. APPEND ("M68K fpu");
  2118. break;
  2119. case mmmu:
  2120. APPEND ("M68K mmu");
  2121. break;
  2122. case m68020up:
  2123. APPEND ("68020 ");
  2124. APPEND (_("or higher"));
  2125. break;
  2126. case m68000up:
  2127. APPEND ("68000 ");
  2128. APPEND (_("or higher"));
  2129. break;
  2130. case m68010up:
  2131. APPEND ("68010 ");
  2132. APPEND (_("or higher"));
  2133. break;
  2134. default:
  2135. paren = 0;
  2136. }
  2137. if (paren)
  2138. APPEND (" (");
  2139. for (cpu = m68k_cpus; cpu->name; cpu++)
  2140. if (!cpu->alias && (cpu->arch & ok_arch))
  2141. {
  2142. const struct m68k_cpu *alias;
  2143. int seen_master = 0;
  2144. if (any)
  2145. APPEND (", ");
  2146. any = 0;
  2147. APPEND (cpu->name);
  2148. for (alias = cpu; alias != m68k_cpus; alias--)
  2149. if (alias[-1].alias >= 0)
  2150. break;
  2151. for (; !seen_master || alias->alias > 0; alias++)
  2152. {
  2153. if (!alias->alias)
  2154. seen_master = 1;
  2155. else
  2156. {
  2157. if (any)
  2158. APPEND (", ");
  2159. else
  2160. APPEND (" [");
  2161. APPEND (alias->name);
  2162. any = 1;
  2163. }
  2164. }
  2165. if (any)
  2166. APPEND ("]");
  2167. any = 1;
  2168. }
  2169. if (paren)
  2170. APPEND (")");
  2171. #undef APPEND
  2172. if (!space)
  2173. {
  2174. /* We ran out of space, so replace the end of the list
  2175. with ellipsis. */
  2176. buf -= 4;
  2177. while (*buf != ' ')
  2178. buf--;
  2179. strcpy (buf, " ...");
  2180. }
  2181. }
  2182. else
  2183. the_ins.error = _("operands mismatch");
  2184. return;
  2185. }
  2186. losing = 0;
  2187. }
  2188. /* Now assemble it. */
  2189. the_ins.args = opcode->m_operands;
  2190. the_ins.numargs = opcode->m_opnum;
  2191. the_ins.numo = opcode->m_codenum;
  2192. the_ins.opcode[0] = getone (opcode);
  2193. the_ins.opcode[1] = gettwo (opcode);
  2194. for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
  2195. {
  2196. int have_disp = 0;
  2197. int use_pl = 0;
  2198. /* This switch is a doozy.
  2199. Watch the first step; its a big one! */
  2200. switch (s[0])
  2201. {
  2202. case '*':
  2203. case '~':
  2204. case '%':
  2205. case ';':
  2206. case '@':
  2207. case '!':
  2208. case '&':
  2209. case '$':
  2210. case '?':
  2211. case '/':
  2212. case '<':
  2213. case '>':
  2214. case 'b':
  2215. case 'm':
  2216. case 'n':
  2217. case 'o':
  2218. case 'p':
  2219. case 'q':
  2220. case 'v':
  2221. case 'w':
  2222. case 'y':
  2223. case 'z':
  2224. case '4':
  2225. #ifndef NO_68851
  2226. case '|':
  2227. #endif
  2228. switch (opP->mode)
  2229. {
  2230. case IMMED:
  2231. tmpreg = 0x3c; /* 7.4 */
  2232. if (strchr ("bwl", s[1]))
  2233. nextword = get_num (&opP->disp, 90);
  2234. else
  2235. nextword = get_num (&opP->disp, 0);
  2236. if (isvar (&opP->disp))
  2237. add_fix (s[1], &opP->disp, 0, 0);
  2238. switch (s[1])
  2239. {
  2240. case 'b':
  2241. if (!isbyte (nextword))
  2242. opP->error = _("operand out of range");
  2243. addword (nextword);
  2244. baseo = 0;
  2245. break;
  2246. case 'w':
  2247. if (!isword (nextword))
  2248. opP->error = _("operand out of range");
  2249. addword (nextword);
  2250. baseo = 0;
  2251. break;
  2252. case 'W':
  2253. if (!issword (nextword))
  2254. opP->error = _("operand out of range");
  2255. addword (nextword);
  2256. baseo = 0;
  2257. break;
  2258. case 'l':
  2259. addword (nextword >> 16);
  2260. addword (nextword);
  2261. baseo = 0;
  2262. break;
  2263. case 'f':
  2264. baseo = 2;
  2265. outro = 8;
  2266. break;
  2267. case 'F':
  2268. baseo = 4;
  2269. outro = 11;
  2270. break;
  2271. case 'x':
  2272. baseo = 6;
  2273. outro = 15;
  2274. break;
  2275. case 'p':
  2276. baseo = 6;
  2277. outro = -1;
  2278. break;
  2279. default:
  2280. abort ();
  2281. }
  2282. if (!baseo)
  2283. break;
  2284. /* We gotta put out some float. */
  2285. if (op (&opP->disp) != O_big)
  2286. {
  2287. valueT val;
  2288. int gencnt;
  2289. /* Can other cases happen here? */
  2290. if (op (&opP->disp) != O_constant)
  2291. abort ();
  2292. val = (valueT) offs (&opP->disp);
  2293. gencnt = 0;
  2294. do
  2295. {
  2296. generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
  2297. val >>= LITTLENUM_NUMBER_OF_BITS;
  2298. ++gencnt;
  2299. }
  2300. while (val != 0);
  2301. offs (&opP->disp) = gencnt;
  2302. }
  2303. if (offs (&opP->disp) > 0)
  2304. {
  2305. if (offs (&opP->disp) > baseo)
  2306. {
  2307. as_warn (_("Bignum too big for %c format; truncated"),
  2308. s[1]);
  2309. offs (&opP->disp) = baseo;
  2310. }
  2311. baseo -= offs (&opP->disp);
  2312. while (baseo--)
  2313. addword (0);
  2314. for (wordp = generic_bignum + offs (&opP->disp) - 1;
  2315. offs (&opP->disp)--;
  2316. --wordp)
  2317. addword (*wordp);
  2318. break;
  2319. }
  2320. gen_to_words (words, baseo, (long) outro);
  2321. for (wordp = words; baseo--; wordp++)
  2322. addword (*wordp);
  2323. break;
  2324. case DREG:
  2325. tmpreg = opP->reg - DATA; /* 0.dreg */
  2326. break;
  2327. case AREG:
  2328. tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
  2329. break;
  2330. case AINDR:
  2331. tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
  2332. break;
  2333. case ADEC:
  2334. tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
  2335. break;
  2336. case AINC:
  2337. tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
  2338. break;
  2339. case DISP:
  2340. nextword = get_num (&opP->disp, 90);
  2341. /* Convert mode 5 addressing with a zero offset into
  2342. mode 2 addressing to reduce the instruction size by a
  2343. word. */
  2344. if (! isvar (&opP->disp)
  2345. && (nextword == 0)
  2346. && (opP->disp.size == SIZE_UNSPEC)
  2347. && (opP->reg >= ADDR0)
  2348. && (opP->reg <= ADDR7))
  2349. {
  2350. tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
  2351. break;
  2352. }
  2353. if (opP->reg == PC
  2354. && ! isvar (&opP->disp)
  2355. && m68k_abspcadd)
  2356. {
  2357. opP->disp.exp.X_op = O_symbol;
  2358. opP->disp.exp.X_add_symbol =
  2359. section_symbol (absolute_section);
  2360. }
  2361. /* Force into index mode. Hope this works. */
  2362. /* We do the first bit for 32-bit displacements, and the
  2363. second bit for 16 bit ones. It is possible that we
  2364. should make the default be WORD instead of LONG, but
  2365. I think that'd break GCC, so we put up with a little
  2366. inefficiency for the sake of working output. */
  2367. if (!issword (nextword)
  2368. || (isvar (&opP->disp)
  2369. && ((opP->disp.size == SIZE_UNSPEC
  2370. && flag_short_refs == 0
  2371. && cpu_of_arch (current_architecture) >= m68020
  2372. && ! arch_coldfire_p (current_architecture))
  2373. || opP->disp.size == SIZE_LONG)))
  2374. {
  2375. if (cpu_of_arch (current_architecture) < m68020
  2376. || arch_coldfire_p (current_architecture))
  2377. opP->error =
  2378. _("displacement too large for this architecture; needs 68020 or higher");
  2379. if (opP->reg == PC)
  2380. tmpreg = 0x3B; /* 7.3 */
  2381. else
  2382. tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
  2383. if (isvar (&opP->disp))
  2384. {
  2385. if (opP->reg == PC)
  2386. {
  2387. if (opP->disp.size == SIZE_LONG
  2388. #ifdef OBJ_ELF
  2389. /* If the displacement needs pic
  2390. relocation it cannot be relaxed. */
  2391. || opP->disp.pic_reloc != pic_none
  2392. #endif
  2393. )
  2394. {
  2395. addword (0x0170);
  2396. add_fix ('l', &opP->disp, 1, 2);
  2397. }
  2398. else
  2399. {
  2400. add_frag (adds (&opP->disp),
  2401. SEXT (offs (&opP->disp)),
  2402. TAB (PCREL1632, SZ_UNDEF));
  2403. break;
  2404. }
  2405. }
  2406. else
  2407. {
  2408. addword (0x0170);
  2409. add_fix ('l', &opP->disp, 0, 0);
  2410. }
  2411. }
  2412. else
  2413. addword (0x0170);
  2414. addword (nextword >> 16);
  2415. }
  2416. else
  2417. {
  2418. if (opP->reg == PC)
  2419. tmpreg = 0x3A; /* 7.2 */
  2420. else
  2421. tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
  2422. if (isvar (&opP->disp))
  2423. {
  2424. if (opP->reg == PC)
  2425. {
  2426. add_fix ('w', &opP->disp, 1, 0);
  2427. }
  2428. else
  2429. add_fix ('w', &opP->disp, 0, 0);
  2430. }
  2431. }
  2432. addword (nextword);
  2433. break;
  2434. case POST:
  2435. case PRE:
  2436. case BASE:
  2437. nextword = 0;
  2438. baseo = get_num (&opP->disp, 90);
  2439. if (opP->mode == POST || opP->mode == PRE)
  2440. outro = get_num (&opP->odisp, 90);
  2441. /* Figure out the `addressing mode'.
  2442. Also turn on the BASE_DISABLE bit, if needed. */
  2443. if (opP->reg == PC || opP->reg == ZPC)
  2444. {
  2445. tmpreg = 0x3b; /* 7.3 */
  2446. if (opP->reg == ZPC)
  2447. nextword |= 0x80;
  2448. }
  2449. else if (opP->reg == 0)
  2450. {
  2451. nextword |= 0x80;
  2452. tmpreg = 0x30; /* 6.garbage */
  2453. }
  2454. else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
  2455. {
  2456. nextword |= 0x80;
  2457. tmpreg = 0x30 + opP->reg - ZADDR0;
  2458. }
  2459. else
  2460. tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
  2461. siz1 = opP->disp.size;
  2462. if (opP->mode == POST || opP->mode == PRE)
  2463. siz2 = opP->odisp.size;
  2464. else
  2465. siz2 = SIZE_UNSPEC;
  2466. /* Index register stuff. */
  2467. if (opP->index.reg != 0
  2468. && opP->index.reg >= DATA
  2469. && opP->index.reg <= ADDR7)
  2470. {
  2471. nextword |= (opP->index.reg - DATA) << 12;
  2472. if (opP->index.size == SIZE_LONG
  2473. || (opP->index.size == SIZE_UNSPEC
  2474. && m68k_index_width_default == SIZE_LONG))
  2475. nextword |= 0x800;
  2476. if ((opP->index.scale != 1
  2477. && cpu_of_arch (current_architecture) < m68020)
  2478. || (opP->index.scale == 8
  2479. && (arch_coldfire_p (current_architecture)
  2480. && !arch_coldfire_fpu (current_architecture))))
  2481. {
  2482. opP->error =
  2483. _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
  2484. }
  2485. if (arch_coldfire_p (current_architecture)
  2486. && opP->index.size == SIZE_WORD)
  2487. opP->error = _("invalid index size for coldfire");
  2488. switch (opP->index.scale)
  2489. {
  2490. case 1:
  2491. break;
  2492. case 2:
  2493. nextword |= 0x200;
  2494. break;
  2495. case 4:
  2496. nextword |= 0x400;
  2497. break;
  2498. case 8:
  2499. nextword |= 0x600;
  2500. break;
  2501. default:
  2502. abort ();
  2503. }
  2504. /* IF its simple,
  2505. GET US OUT OF HERE! */
  2506. /* Must be INDEX, with an index register. Address
  2507. register cannot be ZERO-PC, and either :b was
  2508. forced, or we know it will fit. For a 68000 or
  2509. 68010, force this mode anyways, because the
  2510. larger modes aren't supported. */
  2511. if (opP->mode == BASE
  2512. && ((opP->reg >= ADDR0
  2513. && opP->reg <= ADDR7)
  2514. || opP->reg == PC))
  2515. {
  2516. if (siz1 == SIZE_BYTE
  2517. || cpu_of_arch (current_architecture) < m68020
  2518. || arch_coldfire_p (current_architecture)
  2519. || (siz1 == SIZE_UNSPEC
  2520. && ! isvar (&opP->disp)
  2521. && issbyte (baseo)))
  2522. {
  2523. nextword += baseo & 0xff;
  2524. addword (nextword);
  2525. if (isvar (&opP->disp))
  2526. {
  2527. /* Do a byte relocation. If it doesn't
  2528. fit (possible on m68000) let the
  2529. fixup processing complain later. */
  2530. if (opP->reg == PC)
  2531. add_fix ('B', &opP->disp, 1, 1);
  2532. else
  2533. add_fix ('B', &opP->disp, 0, 0);
  2534. }
  2535. else if (siz1 != SIZE_BYTE)
  2536. {
  2537. if (siz1 != SIZE_UNSPEC)
  2538. as_warn (_("Forcing byte displacement"));
  2539. if (! issbyte (baseo))
  2540. opP->error = _("byte displacement out of range");
  2541. }
  2542. break;
  2543. }
  2544. else if (siz1 == SIZE_UNSPEC
  2545. && opP->reg == PC
  2546. && isvar (&opP->disp)
  2547. && subs (&opP->disp) == NULL
  2548. #ifdef OBJ_ELF
  2549. /* If the displacement needs pic
  2550. relocation it cannot be relaxed. */
  2551. && opP->disp.pic_reloc == pic_none
  2552. #endif
  2553. )
  2554. {
  2555. /* The code in md_convert_frag_1 needs to be
  2556. able to adjust nextword. Call frag_grow
  2557. to ensure that we have enough space in
  2558. the frag obstack to make all the bytes
  2559. contiguous. */
  2560. frag_grow (14);
  2561. nextword += baseo & 0xff;
  2562. addword (nextword);
  2563. add_frag (adds (&opP->disp),
  2564. SEXT (offs (&opP->disp)),
  2565. TAB (PCINDEX, SZ_UNDEF));
  2566. break;
  2567. }
  2568. }
  2569. }
  2570. else
  2571. {
  2572. nextword |= 0x40; /* No index reg. */
  2573. if (opP->index.reg >= ZDATA0
  2574. && opP->index.reg <= ZDATA7)
  2575. nextword |= (opP->index.reg - ZDATA0) << 12;
  2576. else if (opP->index.reg >= ZADDR0
  2577. || opP->index.reg <= ZADDR7)
  2578. nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
  2579. }
  2580. /* It isn't simple. */
  2581. if (cpu_of_arch (current_architecture) < m68020
  2582. || arch_coldfire_p (current_architecture))
  2583. opP->error =
  2584. _("invalid operand mode for this architecture; needs 68020 or higher");
  2585. nextword |= 0x100;
  2586. /* If the guy specified a width, we assume that it is
  2587. wide enough. Maybe it isn't. If so, we lose. */
  2588. switch (siz1)
  2589. {
  2590. case SIZE_UNSPEC:
  2591. if (isvar (&opP->disp)
  2592. ? m68k_rel32
  2593. : ! issword (baseo))
  2594. {
  2595. siz1 = SIZE_LONG;
  2596. nextword |= 0x30;
  2597. }
  2598. else if (! isvar (&opP->disp) && baseo == 0)
  2599. nextword |= 0x10;
  2600. else
  2601. {
  2602. nextword |= 0x20;
  2603. siz1 = SIZE_WORD;
  2604. }
  2605. break;
  2606. case SIZE_BYTE:
  2607. as_warn (_(":b not permitted; defaulting to :w"));
  2608. /* Fall through. */
  2609. case SIZE_WORD:
  2610. nextword |= 0x20;
  2611. break;
  2612. case SIZE_LONG:
  2613. nextword |= 0x30;
  2614. break;
  2615. }
  2616. /* Figure out inner displacement stuff. */
  2617. if (opP->mode == POST || opP->mode == PRE)
  2618. {
  2619. if (cpu_of_arch (current_architecture) & cpu32)
  2620. opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
  2621. switch (siz2)
  2622. {
  2623. case SIZE_UNSPEC:
  2624. if (isvar (&opP->odisp)
  2625. ? m68k_rel32
  2626. : ! issword (outro))
  2627. {
  2628. siz2 = SIZE_LONG;
  2629. nextword |= 0x3;
  2630. }
  2631. else if (! isvar (&opP->odisp) && outro == 0)
  2632. nextword |= 0x1;
  2633. else
  2634. {
  2635. nextword |= 0x2;
  2636. siz2 = SIZE_WORD;
  2637. }
  2638. break;
  2639. case 1:
  2640. as_warn (_(":b not permitted; defaulting to :w"));
  2641. /* Fall through. */
  2642. case 2:
  2643. nextword |= 0x2;
  2644. break;
  2645. case 3:
  2646. nextword |= 0x3;
  2647. break;
  2648. }
  2649. if (opP->mode == POST
  2650. && (nextword & 0x40) == 0)
  2651. nextword |= 0x04;
  2652. }
  2653. addword (nextword);
  2654. if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
  2655. {
  2656. if (opP->reg == PC || opP->reg == ZPC)
  2657. add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
  2658. else
  2659. add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
  2660. }
  2661. if (siz1 == SIZE_LONG)
  2662. addword (baseo >> 16);
  2663. if (siz1 != SIZE_UNSPEC)
  2664. addword (baseo);
  2665. if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
  2666. add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
  2667. if (siz2 == SIZE_LONG)
  2668. addword (outro >> 16);
  2669. if (siz2 != SIZE_UNSPEC)
  2670. addword (outro);
  2671. break;
  2672. case ABSL:
  2673. nextword = get_num (&opP->disp, 90);
  2674. switch (opP->disp.size)
  2675. {
  2676. default:
  2677. abort ();
  2678. case SIZE_UNSPEC:
  2679. if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
  2680. {
  2681. tmpreg = 0x38; /* 7.0 */
  2682. addword (nextword);
  2683. break;
  2684. }
  2685. if (isvar (&opP->disp)
  2686. && !subs (&opP->disp)
  2687. && adds (&opP->disp)
  2688. #ifdef OBJ_ELF
  2689. /* If the displacement needs pic relocation it
  2690. cannot be relaxed. */
  2691. && opP->disp.pic_reloc == pic_none
  2692. #endif
  2693. && !flag_long_jumps
  2694. && !strchr ("~%&$?", s[0]))
  2695. {
  2696. tmpreg = 0x3A; /* 7.2 */
  2697. add_frag (adds (&opP->disp),
  2698. SEXT (offs (&opP->disp)),
  2699. TAB (ABSTOPCREL, SZ_UNDEF));
  2700. break;
  2701. }
  2702. /* Fall through into long. */
  2703. case SIZE_LONG:
  2704. if (isvar (&opP->disp))
  2705. add_fix ('l', &opP->disp, 0, 0);
  2706. tmpreg = 0x39;/* 7.1 mode */
  2707. addword (nextword >> 16);
  2708. addword (nextword);
  2709. break;
  2710. case SIZE_BYTE:
  2711. as_bad (_("unsupported byte value; use a different suffix"));
  2712. /* Fall through. */
  2713. case SIZE_WORD:
  2714. if (isvar (&opP->disp))
  2715. add_fix ('w', &opP->disp, 0, 0);
  2716. tmpreg = 0x38;/* 7.0 mode */
  2717. addword (nextword);
  2718. break;
  2719. }
  2720. break;
  2721. case CONTROL:
  2722. case FPREG:
  2723. default:
  2724. as_bad (_("unknown/incorrect operand"));
  2725. /* abort (); */
  2726. }
  2727. /* If s[0] is '4', then this is for the mac instructions
  2728. that can have a trailing_ampersand set. If so, set 0x100
  2729. bit on tmpreg so install_gen_operand can check for it and
  2730. set the appropriate bit (word2, bit 5). */
  2731. if (s[0] == '4')
  2732. {
  2733. if (opP->trailing_ampersand)
  2734. tmpreg |= 0x100;
  2735. }
  2736. install_gen_operand (s[1], tmpreg);
  2737. break;
  2738. case '#':
  2739. case '^':
  2740. switch (s[1])
  2741. { /* JF: I hate floating point! */
  2742. case 'j':
  2743. tmpreg = 70;
  2744. break;
  2745. case '8':
  2746. tmpreg = 20;
  2747. break;
  2748. case 'C':
  2749. tmpreg = 50;
  2750. break;
  2751. case '3':
  2752. default:
  2753. tmpreg = 90;
  2754. break;
  2755. }
  2756. tmpreg = get_num (&opP->disp, tmpreg);
  2757. if (isvar (&opP->disp))
  2758. add_fix (s[1], &opP->disp, 0, 0);
  2759. switch (s[1])
  2760. {
  2761. case 'b': /* Danger: These do no check for
  2762. certain types of overflow.
  2763. user beware! */
  2764. if (!isbyte (tmpreg))
  2765. opP->error = _("out of range");
  2766. insop (tmpreg, opcode);
  2767. if (isvar (&opP->disp))
  2768. the_ins.reloc[the_ins.nrel - 1].n =
  2769. (opcode->m_codenum) * 2 + 1;
  2770. break;
  2771. case 'B':
  2772. if (!issbyte (tmpreg))
  2773. opP->error = _("out of range");
  2774. the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
  2775. if (isvar (&opP->disp))
  2776. the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
  2777. break;
  2778. case 'w':
  2779. if (!isword (tmpreg))
  2780. opP->error = _("out of range");
  2781. insop (tmpreg, opcode);
  2782. if (isvar (&opP->disp))
  2783. the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2784. break;
  2785. case 'W':
  2786. if (!issword (tmpreg))
  2787. opP->error = _("out of range");
  2788. insop (tmpreg, opcode);
  2789. if (isvar (&opP->disp))
  2790. the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2791. break;
  2792. case 'l':
  2793. /* Because of the way insop works, we put these two out
  2794. backwards. */
  2795. insop (tmpreg, opcode);
  2796. insop (tmpreg >> 16, opcode);
  2797. if (isvar (&opP->disp))
  2798. the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2799. break;
  2800. case '3':
  2801. tmpreg &= 0xFF;
  2802. case '8':
  2803. case 'C':
  2804. case 'j':
  2805. install_operand (s[1], tmpreg);
  2806. break;
  2807. default:
  2808. abort ();
  2809. }
  2810. break;
  2811. case '+':
  2812. case '-':
  2813. case 'A':
  2814. case 'a':
  2815. install_operand (s[1], opP->reg - ADDR);
  2816. break;
  2817. case 'B':
  2818. tmpreg = get_num (&opP->disp, 90);
  2819. switch (s[1])
  2820. {
  2821. case 'B':
  2822. add_fix ('B', &opP->disp, 1, -1);
  2823. break;
  2824. case 'W':
  2825. add_fix ('w', &opP->disp, 1, 0);
  2826. addword (0);
  2827. break;
  2828. case 'L':
  2829. long_branch:
  2830. the_ins.opcode[0] |= 0xff;
  2831. add_fix ('l', &opP->disp, 1, 0);
  2832. addword (0);
  2833. addword (0);
  2834. break;
  2835. case 'g': /* Conditional branch */
  2836. have_disp = HAVE_LONG_CALL (current_architecture);
  2837. goto var_branch;
  2838. case 'b': /* Unconditional branch */
  2839. have_disp = HAVE_LONG_BRANCH (current_architecture);
  2840. use_pl = LONG_BRANCH_VIA_COND (current_architecture);
  2841. goto var_branch;
  2842. case 's': /* Unconditional subroutine */
  2843. have_disp = HAVE_LONG_CALL (current_architecture);
  2844. var_branch:
  2845. if (subs (&opP->disp) /* We can't relax it. */
  2846. #ifdef OBJ_ELF
  2847. /* If the displacement needs pic relocation it cannot be
  2848. relaxed. */
  2849. || opP->disp.pic_reloc != pic_none
  2850. #endif
  2851. || 0)
  2852. {
  2853. if (!have_disp)
  2854. as_warn (_("Can't use long branches on this architecture"));
  2855. goto long_branch;
  2856. }
  2857. /* This could either be a symbol, or an absolute
  2858. address. If it's an absolute address, turn it into
  2859. an absolute jump right here and keep it out of the
  2860. relaxer. */
  2861. if (adds (&opP->disp) == 0)
  2862. {
  2863. if (the_ins.opcode[0] == 0x6000) /* jbra */
  2864. the_ins.opcode[0] = 0x4EF9;
  2865. else if (the_ins.opcode[0] == 0x6100) /* jbsr */
  2866. the_ins.opcode[0] = 0x4EB9;
  2867. else /* jCC */
  2868. {
  2869. the_ins.opcode[0] ^= 0x0100;
  2870. the_ins.opcode[0] |= 0x0006;
  2871. addword (0x4EF9);
  2872. }
  2873. add_fix ('l', &opP->disp, 0, 0);
  2874. addword (0);
  2875. addword (0);
  2876. break;
  2877. }
  2878. /* Now we know it's going into the relaxer. Now figure
  2879. out which mode. We try in this order of preference:
  2880. long branch, absolute jump, byte/word branches only. */
  2881. if (have_disp)
  2882. add_frag (adds (&opP->disp),
  2883. SEXT (offs (&opP->disp)),
  2884. TAB (BRANCHBWL, SZ_UNDEF));
  2885. else if (! flag_keep_pcrel)
  2886. {
  2887. if ((the_ins.opcode[0] == 0x6000)
  2888. || (the_ins.opcode[0] == 0x6100))
  2889. add_frag (adds (&opP->disp),
  2890. SEXT (offs (&opP->disp)),
  2891. TAB (BRABSJUNC, SZ_UNDEF));
  2892. else
  2893. add_frag (adds (&opP->disp),
  2894. SEXT (offs (&opP->disp)),
  2895. TAB (BRABSJCOND, SZ_UNDEF));
  2896. }
  2897. else
  2898. add_frag (adds (&opP->disp),
  2899. SEXT (offs (&opP->disp)),
  2900. (use_pl ? TAB (BRANCHBWPL, SZ_UNDEF)
  2901. : TAB (BRANCHBW, SZ_UNDEF)));
  2902. break;
  2903. case 'w':
  2904. if (isvar (&opP->disp))
  2905. {
  2906. /* Check for DBcc instructions. We can relax them,
  2907. but only if we have long branches and/or absolute
  2908. jumps. */
  2909. if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
  2910. && (HAVE_LONG_BRANCH (current_architecture)
  2911. || ! flag_keep_pcrel))
  2912. {
  2913. if (HAVE_LONG_BRANCH (current_architecture))
  2914. add_frag (adds (&opP->disp),
  2915. SEXT (offs (&opP->disp)),
  2916. TAB (DBCCLBR, SZ_UNDEF));
  2917. else
  2918. add_frag (adds (&opP->disp),
  2919. SEXT (offs (&opP->disp)),
  2920. TAB (DBCCABSJ, SZ_UNDEF));
  2921. break;
  2922. }
  2923. add_fix ('w', &opP->disp, 1, 0);
  2924. }
  2925. addword (0);
  2926. break;
  2927. case 'C': /* Fixed size LONG coproc branches. */
  2928. add_fix ('l', &opP->disp, 1, 0);
  2929. addword (0);
  2930. addword (0);
  2931. break;
  2932. case 'c': /* Var size Coprocesssor branches. */
  2933. if (subs (&opP->disp) || (adds (&opP->disp) == 0))
  2934. {
  2935. the_ins.opcode[the_ins.numo - 1] |= 0x40;
  2936. add_fix ('l', &opP->disp, 1, 0);
  2937. addword (0);
  2938. addword (0);
  2939. }
  2940. else
  2941. add_frag (adds (&opP->disp),
  2942. SEXT (offs (&opP->disp)),
  2943. TAB (FBRANCH, SZ_UNDEF));
  2944. break;
  2945. default:
  2946. abort ();
  2947. }
  2948. break;
  2949. case 'C': /* Ignore it. */
  2950. break;
  2951. case 'd': /* JF this is a kludge. */
  2952. install_operand ('s', opP->reg - ADDR);
  2953. tmpreg = get_num (&opP->disp, 90);
  2954. if (!issword (tmpreg))
  2955. {
  2956. as_warn (_("Expression out of range, using 0"));
  2957. tmpreg = 0;
  2958. }
  2959. addword (tmpreg);
  2960. break;
  2961. case 'D':
  2962. install_operand (s[1], opP->reg - DATA);
  2963. break;
  2964. case 'e': /* EMAC ACCx, reg/reg. */
  2965. install_operand (s[1], opP->reg - ACC);
  2966. break;
  2967. case 'E': /* Ignore it. */
  2968. break;
  2969. case 'F':
  2970. install_operand (s[1], opP->reg - FP0);
  2971. break;
  2972. case 'g': /* EMAC ACCEXTx. */
  2973. install_operand (s[1], opP->reg - ACCEXT01);
  2974. break;
  2975. case 'G': /* Ignore it. */
  2976. case 'H':
  2977. break;
  2978. case 'I':
  2979. tmpreg = opP->reg - COP0;
  2980. install_operand (s[1], tmpreg);
  2981. break;
  2982. case 'i': /* MAC/EMAC scale factor. */
  2983. install_operand (s[1], opP->mode == LSH ? 0x1 : 0x3);
  2984. break;
  2985. case 'J': /* JF foo. */
  2986. switch (opP->reg)
  2987. {
  2988. case SFC:
  2989. tmpreg = 0x000;
  2990. break;
  2991. case DFC:
  2992. tmpreg = 0x001;
  2993. break;
  2994. case CACR:
  2995. tmpreg = 0x002;
  2996. break;
  2997. case TC:
  2998. case ASID:
  2999. tmpreg = 0x003;
  3000. break;
  3001. case ACR0:
  3002. case ITT0:
  3003. tmpreg = 0x004;
  3004. break;
  3005. case ACR1:
  3006. case ITT1:
  3007. tmpreg = 0x005;
  3008. break;
  3009. case ACR2:
  3010. case DTT0:
  3011. tmpreg = 0x006;
  3012. break;
  3013. case ACR3:
  3014. case DTT1:
  3015. tmpreg = 0x007;
  3016. break;
  3017. case BUSCR:
  3018. case MMUBAR:
  3019. tmpreg = 0x008;
  3020. break;
  3021. case RGPIOBAR:
  3022. tmpreg = 0x009;
  3023. break;
  3024. case ACR4:
  3025. case ACR5:
  3026. case ACR6:
  3027. case ACR7:
  3028. tmpreg = 0x00c + (opP->reg - ACR4);
  3029. break;
  3030. case USP:
  3031. tmpreg = 0x800;
  3032. break;
  3033. case VBR:
  3034. tmpreg = 0x801;
  3035. break;
  3036. case CAAR:
  3037. case CPUCR:
  3038. tmpreg = 0x802;
  3039. break;
  3040. case MSP:
  3041. tmpreg = 0x803;
  3042. break;
  3043. case ISP:
  3044. tmpreg = 0x804;
  3045. break;
  3046. case MMUSR:
  3047. tmpreg = 0x805;
  3048. break;
  3049. case URP:
  3050. tmpreg = 0x806;
  3051. break;
  3052. case SRP:
  3053. tmpreg = 0x807;
  3054. break;
  3055. case PCR:
  3056. tmpreg = 0x808;
  3057. break;
  3058. case ROMBAR:
  3059. case ROMBAR0:
  3060. tmpreg = 0xC00;
  3061. break;
  3062. case ROMBAR1:
  3063. tmpreg = 0xC01;
  3064. break;
  3065. case FLASHBAR:
  3066. case RAMBAR0:
  3067. case RAMBAR_ALT:
  3068. tmpreg = 0xC04;
  3069. break;
  3070. case RAMBAR:
  3071. case RAMBAR1:
  3072. tmpreg = 0xC05;
  3073. break;
  3074. case MPCR:
  3075. tmpreg = 0xC0C;
  3076. break;
  3077. case EDRAMBAR:
  3078. tmpreg = 0xC0D;
  3079. break;
  3080. case MBAR0:
  3081. case MBAR2:
  3082. case SECMBAR:
  3083. tmpreg = 0xC0E;
  3084. break;
  3085. case MBAR1:
  3086. case MBAR:
  3087. tmpreg = 0xC0F;
  3088. break;
  3089. case PCR1U0:
  3090. tmpreg = 0xD02;
  3091. break;
  3092. case PCR1L0:
  3093. tmpreg = 0xD03;
  3094. break;
  3095. case PCR2U0:
  3096. tmpreg = 0xD04;
  3097. break;
  3098. case PCR2L0:
  3099. tmpreg = 0xD05;
  3100. break;
  3101. case PCR3U0:
  3102. tmpreg = 0xD06;
  3103. break;
  3104. case PCR3L0:
  3105. tmpreg = 0xD07;
  3106. break;
  3107. case PCR1L1:
  3108. tmpreg = 0xD0A;
  3109. break;
  3110. case PCR1U1:
  3111. tmpreg = 0xD0B;
  3112. break;
  3113. case PCR2L1:
  3114. tmpreg = 0xD0C;
  3115. break;
  3116. case PCR2U1:
  3117. tmpreg = 0xD0D;
  3118. break;
  3119. case PCR3L1:
  3120. tmpreg = 0xD0E;
  3121. break;
  3122. case PCR3U1:
  3123. tmpreg = 0xD0F;
  3124. break;
  3125. case CAC:
  3126. tmpreg = 0xFFE;
  3127. break;
  3128. case MBO:
  3129. tmpreg = 0xFFF;
  3130. break;
  3131. default:
  3132. abort ();
  3133. }
  3134. install_operand (s[1], tmpreg);
  3135. break;
  3136. case 'k':
  3137. tmpreg = get_num (&opP->disp, 55);
  3138. install_operand (s[1], tmpreg & 0x7f);
  3139. break;
  3140. case 'l':
  3141. tmpreg = opP->mask;
  3142. if (s[1] == 'w')
  3143. {
  3144. if (tmpreg & 0x7FF0000)
  3145. as_bad (_("Floating point register in register list"));
  3146. insop (reverse_16_bits (tmpreg), opcode);
  3147. }
  3148. else
  3149. {
  3150. if (tmpreg & 0x700FFFF)
  3151. as_bad (_("Wrong register in floating-point reglist"));
  3152. install_operand (s[1], reverse_8_bits (tmpreg >> 16));
  3153. }
  3154. break;
  3155. case 'L':
  3156. tmpreg = opP->mask;
  3157. if (s[1] == 'w')
  3158. {
  3159. if (tmpreg & 0x7FF0000)
  3160. as_bad (_("Floating point register in register list"));
  3161. insop (tmpreg, opcode);
  3162. }
  3163. else if (s[1] == '8')
  3164. {
  3165. if (tmpreg & 0x0FFFFFF)
  3166. as_bad (_("incorrect register in reglist"));
  3167. install_operand (s[1], tmpreg >> 24);
  3168. }
  3169. else
  3170. {
  3171. if (tmpreg & 0x700FFFF)
  3172. as_bad (_("wrong register in floating-point reglist"));
  3173. else
  3174. install_operand (s[1], tmpreg >> 16);
  3175. }
  3176. break;
  3177. case 'M':
  3178. install_operand (s[1], get_num (&opP->disp, 60));
  3179. break;
  3180. case 'O':
  3181. tmpreg = ((opP->mode == DREG)
  3182. ? 0x20 + (int) (opP->reg - DATA)
  3183. : (get_num (&opP->disp, 40) & 0x1F));
  3184. install_operand (s[1], tmpreg);
  3185. break;
  3186. case 'Q':
  3187. tmpreg = get_num (&opP->disp, 10);
  3188. if (tmpreg == 8)
  3189. tmpreg = 0;
  3190. install_operand (s[1], tmpreg);
  3191. break;
  3192. case 'R':
  3193. /* This depends on the fact that ADDR registers are eight
  3194. more than their corresponding DATA regs, so the result
  3195. will have the ADDR_REG bit set. */
  3196. install_operand (s[1], opP->reg - DATA);
  3197. break;
  3198. case 'r':
  3199. if (opP->mode == AINDR)
  3200. install_operand (s[1], opP->reg - DATA);
  3201. else
  3202. install_operand (s[1], opP->index.reg - DATA);
  3203. break;
  3204. case 's':
  3205. if (opP->reg == FPI)
  3206. tmpreg = 0x1;
  3207. else if (opP->reg == FPS)
  3208. tmpreg = 0x2;
  3209. else if (opP->reg == FPC)
  3210. tmpreg = 0x4;
  3211. else
  3212. abort ();
  3213. install_operand (s[1], tmpreg);
  3214. break;
  3215. case 'S': /* Ignore it. */
  3216. break;
  3217. case 'T':
  3218. install_operand (s[1], get_num (&opP->disp, 30));
  3219. break;
  3220. case 'U': /* Ignore it. */
  3221. break;
  3222. case 'c':
  3223. switch (opP->reg)
  3224. {
  3225. case NC:
  3226. tmpreg = 0;
  3227. break;
  3228. case DC:
  3229. tmpreg = 1;
  3230. break;
  3231. case IC:
  3232. tmpreg = 2;
  3233. break;
  3234. case BC:
  3235. tmpreg = 3;
  3236. break;
  3237. default:
  3238. as_fatal (_("failed sanity check"));
  3239. } /* switch on cache token. */
  3240. install_operand (s[1], tmpreg);
  3241. break;
  3242. #ifndef NO_68851
  3243. /* JF: These are out of order, I fear. */
  3244. case 'f':
  3245. switch (opP->reg)
  3246. {
  3247. case SFC:
  3248. tmpreg = 0;
  3249. break;
  3250. case DFC:
  3251. tmpreg = 1;
  3252. break;
  3253. default:
  3254. abort ();
  3255. }
  3256. install_operand (s[1], tmpreg);
  3257. break;
  3258. case '0':
  3259. case '1':
  3260. case '2':
  3261. switch (opP->reg)
  3262. {
  3263. case TC:
  3264. tmpreg = 0;
  3265. break;
  3266. case CAL:
  3267. tmpreg = 4;
  3268. break;
  3269. case VAL:
  3270. tmpreg = 5;
  3271. break;
  3272. case SCC:
  3273. tmpreg = 6;
  3274. break;
  3275. case AC:
  3276. tmpreg = 7;
  3277. break;
  3278. default:
  3279. abort ();
  3280. }
  3281. install_operand (s[1], tmpreg);
  3282. break;
  3283. case 'V':
  3284. if (opP->reg == VAL)
  3285. break;
  3286. abort ();
  3287. case 'W':
  3288. switch (opP->reg)
  3289. {
  3290. case DRP:
  3291. tmpreg = 1;
  3292. break;
  3293. case SRP:
  3294. tmpreg = 2;
  3295. break;
  3296. case CRP:
  3297. tmpreg = 3;
  3298. break;
  3299. default:
  3300. abort ();
  3301. }
  3302. install_operand (s[1], tmpreg);
  3303. break;
  3304. case 'X':
  3305. switch (opP->reg)
  3306. {
  3307. case BAD:
  3308. case BAD + 1:
  3309. case BAD + 2:
  3310. case BAD + 3:
  3311. case BAD + 4:
  3312. case BAD + 5:
  3313. case BAD + 6:
  3314. case BAD + 7:
  3315. tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  3316. break;
  3317. case BAC:
  3318. case BAC + 1:
  3319. case BAC + 2:
  3320. case BAC + 3:
  3321. case BAC + 4:
  3322. case BAC + 5:
  3323. case BAC + 6:
  3324. case BAC + 7:
  3325. tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  3326. break;
  3327. default:
  3328. abort ();
  3329. }
  3330. install_operand (s[1], tmpreg);
  3331. break;
  3332. case 'Y':
  3333. know (opP->reg == PSR);
  3334. break;
  3335. case 'Z':
  3336. know (opP->reg == PCSR);
  3337. break;
  3338. #endif /* m68851 */
  3339. case '3':
  3340. switch (opP->reg)
  3341. {
  3342. case TT0:
  3343. tmpreg = 2;
  3344. break;
  3345. case TT1:
  3346. tmpreg = 3;
  3347. break;
  3348. default:
  3349. abort ();
  3350. }
  3351. install_operand (s[1], tmpreg);
  3352. break;
  3353. case 't':
  3354. tmpreg = get_num (&opP->disp, 20);
  3355. install_operand (s[1], tmpreg);
  3356. break;
  3357. case '_': /* used only for move16 absolute 32-bit address. */
  3358. if (isvar (&opP->disp))
  3359. add_fix ('l', &opP->disp, 0, 0);
  3360. tmpreg = get_num (&opP->disp, 90);
  3361. addword (tmpreg >> 16);
  3362. addword (tmpreg & 0xFFFF);
  3363. break;
  3364. case 'u':
  3365. install_operand (s[1], opP->reg - DATA0L);
  3366. opP->reg -= (DATA0L);
  3367. opP->reg &= 0x0F; /* remove upper/lower bit. */
  3368. break;
  3369. case 'x':
  3370. tmpreg = get_num (&opP->disp, 80);
  3371. if (tmpreg == -1)
  3372. tmpreg = 0;
  3373. install_operand (s[1], tmpreg);
  3374. break;
  3375. case 'j':
  3376. tmpreg = get_num (&opP->disp, 10);
  3377. install_operand (s[1], tmpreg - 1);
  3378. break;
  3379. case 'K':
  3380. tmpreg = get_num (&opP->disp, 65);
  3381. install_operand (s[1], tmpreg);
  3382. break;
  3383. default:
  3384. abort ();
  3385. }
  3386. }
  3387. /* By the time whe get here (FINALLY) the_ins contains the complete
  3388. instruction, ready to be emitted. . . */
  3389. }
  3390. static int
  3391. reverse_16_bits (int in)
  3392. {
  3393. int out = 0;
  3394. int n;
  3395. static int mask[16] =
  3396. {
  3397. 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  3398. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
  3399. };
  3400. for (n = 0; n < 16; n++)
  3401. {
  3402. if (in & mask[n])
  3403. out |= mask[15 - n];
  3404. }
  3405. return out;
  3406. } /* reverse_16_bits() */
  3407. static int
  3408. reverse_8_bits (int in)
  3409. {
  3410. int out = 0;
  3411. int n;
  3412. static int mask[8] =
  3413. {
  3414. 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  3415. };
  3416. for (n = 0; n < 8; n++)
  3417. {
  3418. if (in & mask[n])
  3419. out |= mask[7 - n];
  3420. }
  3421. return out;
  3422. } /* reverse_8_bits() */
  3423. /* Cause an extra frag to be generated here, inserting up to
  3424. FRAG_VAR_SIZE bytes. TYPE is the subtype of the frag to be
  3425. generated; its primary type is rs_machine_dependent.
  3426. The TYPE parameter is also used by md_convert_frag_1 and
  3427. md_estimate_size_before_relax. The appropriate type of fixup will
  3428. be emitted by md_convert_frag_1.
  3429. ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
  3430. static void
  3431. install_operand (int mode, int val)
  3432. {
  3433. switch (mode)
  3434. {
  3435. case 's':
  3436. the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge. */
  3437. break;
  3438. case 'd':
  3439. the_ins.opcode[0] |= val << 9;
  3440. break;
  3441. case 'E':
  3442. the_ins.opcode[1] |= val << 9;
  3443. break;
  3444. case '1':
  3445. the_ins.opcode[1] |= val << 12;
  3446. break;
  3447. case '2':
  3448. the_ins.opcode[1] |= val << 6;
  3449. break;
  3450. case '3':
  3451. the_ins.opcode[1] |= val;
  3452. break;
  3453. case '4':
  3454. the_ins.opcode[2] |= val << 12;
  3455. break;
  3456. case '5':
  3457. the_ins.opcode[2] |= val << 6;
  3458. break;
  3459. case '6':
  3460. /* DANGER! This is a hack to force cas2l and cas2w cmds to be
  3461. three words long! */
  3462. the_ins.numo++;
  3463. the_ins.opcode[2] |= val;
  3464. break;
  3465. case '7':
  3466. the_ins.opcode[1] |= val << 7;
  3467. break;
  3468. case '8':
  3469. the_ins.opcode[1] |= val << 10;
  3470. break;
  3471. #ifndef NO_68851
  3472. case '9':
  3473. the_ins.opcode[1] |= val << 5;
  3474. break;
  3475. #endif
  3476. case 't':
  3477. the_ins.opcode[1] |= (val << 10) | (val << 7);
  3478. break;
  3479. case 'D':
  3480. the_ins.opcode[1] |= (val << 12) | val;
  3481. break;
  3482. case 'g':
  3483. the_ins.opcode[0] |= val = 0xff;
  3484. break;
  3485. case 'i':
  3486. the_ins.opcode[0] |= val << 9;
  3487. break;
  3488. case 'C':
  3489. the_ins.opcode[1] |= val;
  3490. break;
  3491. case 'j':
  3492. the_ins.opcode[1] |= val;
  3493. the_ins.numo++; /* What a hack. */
  3494. break;
  3495. case 'k':
  3496. the_ins.opcode[1] |= val << 4;
  3497. break;
  3498. case 'b':
  3499. case 'w':
  3500. case 'W':
  3501. case 'l':
  3502. break;
  3503. case 'e':
  3504. the_ins.opcode[0] |= (val << 6);
  3505. break;
  3506. case 'L':
  3507. the_ins.opcode[1] = (val >> 16);
  3508. the_ins.opcode[2] = val & 0xffff;
  3509. break;
  3510. case 'm':
  3511. the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
  3512. the_ins.opcode[0] |= ((val & 0x7) << 9);
  3513. the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
  3514. break;
  3515. case 'n': /* MAC/EMAC Rx on !load. */
  3516. the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
  3517. the_ins.opcode[0] |= ((val & 0x7) << 9);
  3518. the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
  3519. break;
  3520. case 'o': /* MAC/EMAC Rx on load. */
  3521. the_ins.opcode[1] |= val << 12;
  3522. the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
  3523. break;
  3524. case 'M': /* MAC/EMAC Ry on !load. */
  3525. the_ins.opcode[0] |= (val & 0xF);
  3526. the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
  3527. break;
  3528. case 'N': /* MAC/EMAC Ry on load. */
  3529. the_ins.opcode[1] |= (val & 0xF);
  3530. the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
  3531. break;
  3532. case 'h':
  3533. the_ins.opcode[1] |= ((val != 1) << 10);
  3534. break;
  3535. case 'F':
  3536. the_ins.opcode[0] |= ((val & 0x3) << 9);
  3537. break;
  3538. case 'f':
  3539. the_ins.opcode[0] |= ((val & 0x3) << 0);
  3540. break;
  3541. case 'G': /* EMAC accumulator in a EMAC load instruction. */
  3542. the_ins.opcode[0] |= ((~val & 0x1) << 7);
  3543. the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
  3544. break;
  3545. case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
  3546. the_ins.opcode[0] |= ((val & 0x1) << 7);
  3547. the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
  3548. break;
  3549. case 'I':
  3550. the_ins.opcode[1] |= ((val & 0x3) << 9);
  3551. break;
  3552. case ']':
  3553. the_ins.opcode[0] |= (val & 0x1) <<10;
  3554. break;
  3555. case 'c':
  3556. default:
  3557. as_fatal (_("failed sanity check."));
  3558. }
  3559. }
  3560. static void
  3561. install_gen_operand (int mode, int val)
  3562. {
  3563. switch (mode)
  3564. {
  3565. case '/': /* Special for mask loads for mac/msac insns with
  3566. possible mask; trailing_ampersend set in bit 8. */
  3567. the_ins.opcode[0] |= (val & 0x3f);
  3568. the_ins.opcode[1] |= (((val & 0x100) >> 8) << 5);
  3569. break;
  3570. case 's':
  3571. the_ins.opcode[0] |= val;
  3572. break;
  3573. case 'd':
  3574. /* This is a kludge!!! */
  3575. the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
  3576. break;
  3577. case 'b':
  3578. case 'w':
  3579. case 'l':
  3580. case 'f':
  3581. case 'F':
  3582. case 'x':
  3583. case 'p':
  3584. the_ins.opcode[0] |= val;
  3585. break;
  3586. /* more stuff goes here. */
  3587. default:
  3588. as_fatal (_("failed sanity check."));
  3589. }
  3590. }
  3591. /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
  3592. then deal with the bitfield hack. */
  3593. static char *
  3594. crack_operand (char *str, struct m68k_op *opP)
  3595. {
  3596. int parens;
  3597. int c;
  3598. char *beg_str;
  3599. int inquote = 0;
  3600. if (!str)
  3601. {
  3602. return str;
  3603. }
  3604. beg_str = str;
  3605. for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
  3606. {
  3607. if (! inquote)
  3608. {
  3609. if (*str == '(')
  3610. parens++;
  3611. else if (*str == ')')
  3612. {
  3613. if (!parens)
  3614. { /* ERROR. */
  3615. opP->error = _("Extra )");
  3616. return str;
  3617. }
  3618. --parens;
  3619. }
  3620. }
  3621. if (flag_mri && *str == '\'')
  3622. inquote = ! inquote;
  3623. }
  3624. if (!*str && parens)
  3625. { /* ERROR. */
  3626. opP->error = _("Missing )");
  3627. return str;
  3628. }
  3629. c = *str;
  3630. *str = '\0';
  3631. if (m68k_ip_op (beg_str, opP) != 0)
  3632. {
  3633. *str = c;
  3634. return str;
  3635. }
  3636. *str = c;
  3637. if (c == '}')
  3638. c = *++str; /* JF bitfield hack. */
  3639. if (c)
  3640. {
  3641. c = *++str;
  3642. if (!c)
  3643. as_bad (_("Missing operand"));
  3644. }
  3645. /* Detect MRI REG symbols and convert them to REGLSTs. */
  3646. if (opP->mode == CONTROL && (int)opP->reg < 0)
  3647. {
  3648. opP->mode = REGLST;
  3649. opP->mask = ~(int)opP->reg;
  3650. opP->reg = 0;
  3651. }
  3652. return str;
  3653. }
  3654. /* This is the guts of the machine-dependent assembler. STR points to a
  3655. machine dependent instruction. This function is supposed to emit
  3656. the frags/bytes it assembles to.
  3657. */
  3658. static void
  3659. insert_reg (const char *regname, int regnum)
  3660. {
  3661. char buf[100];
  3662. int i;
  3663. #ifdef REGISTER_PREFIX
  3664. if (!flag_reg_prefix_optional)
  3665. {
  3666. buf[0] = REGISTER_PREFIX;
  3667. strcpy (buf + 1, regname);
  3668. regname = buf;
  3669. }
  3670. #endif
  3671. symbol_table_insert (symbol_new (regname, reg_section, regnum,
  3672. &zero_address_frag));
  3673. for (i = 0; regname[i]; i++)
  3674. buf[i] = TOUPPER (regname[i]);
  3675. buf[i] = '\0';
  3676. symbol_table_insert (symbol_new (buf, reg_section, regnum,
  3677. &zero_address_frag));
  3678. }
  3679. struct init_entry
  3680. {
  3681. const char *name;
  3682. int number;
  3683. };
  3684. static const struct init_entry init_table[] =
  3685. {
  3686. { "d0", DATA0 },
  3687. { "d1", DATA1 },
  3688. { "d2", DATA2 },
  3689. { "d3", DATA3 },
  3690. { "d4", DATA4 },
  3691. { "d5", DATA5 },
  3692. { "d6", DATA6 },
  3693. { "d7", DATA7 },
  3694. { "a0", ADDR0 },
  3695. { "a1", ADDR1 },
  3696. { "a2", ADDR2 },
  3697. { "a3", ADDR3 },
  3698. { "a4", ADDR4 },
  3699. { "a5", ADDR5 },
  3700. { "a6", ADDR6 },
  3701. { "fp", ADDR6 },
  3702. { "a7", ADDR7 },
  3703. { "sp", ADDR7 },
  3704. { "ssp", ADDR7 },
  3705. { "fp0", FP0 },
  3706. { "fp1", FP1 },
  3707. { "fp2", FP2 },
  3708. { "fp3", FP3 },
  3709. { "fp4", FP4 },
  3710. { "fp5", FP5 },
  3711. { "fp6", FP6 },
  3712. { "fp7", FP7 },
  3713. { "fpi", FPI },
  3714. { "fpiar", FPI },
  3715. { "fpc", FPI },
  3716. { "fps", FPS },
  3717. { "fpsr", FPS },
  3718. { "fpc", FPC },
  3719. { "fpcr", FPC },
  3720. { "control", FPC },
  3721. { "status", FPS },
  3722. { "iaddr", FPI },
  3723. { "cop0", COP0 },
  3724. { "cop1", COP1 },
  3725. { "cop2", COP2 },
  3726. { "cop3", COP3 },
  3727. { "cop4", COP4 },
  3728. { "cop5", COP5 },
  3729. { "cop6", COP6 },
  3730. { "cop7", COP7 },
  3731. { "pc", PC },
  3732. { "zpc", ZPC },
  3733. { "sr", SR },
  3734. { "ccr", CCR },
  3735. { "cc", CCR },
  3736. { "acc", ACC },
  3737. { "acc0", ACC },
  3738. { "acc1", ACC1 },
  3739. { "acc2", ACC2 },
  3740. { "acc3", ACC3 },
  3741. { "accext01", ACCEXT01 },
  3742. { "accext23", ACCEXT23 },
  3743. { "macsr", MACSR },
  3744. { "mask", MASK },
  3745. /* Control registers. */
  3746. { "sfc", SFC }, /* Source Function Code. */
  3747. { "sfcr", SFC },
  3748. { "dfc", DFC }, /* Destination Function Code. */
  3749. { "dfcr", DFC },
  3750. { "cacr", CACR }, /* Cache Control Register. */
  3751. { "caar", CAAR }, /* Cache Address Register. */
  3752. { "cpucr", CPUCR }, /* CPU Control Register. */
  3753. { "usp", USP }, /* User Stack Pointer. */
  3754. { "vbr", VBR }, /* Vector Base Register. */
  3755. { "msp", MSP }, /* Master Stack Pointer. */
  3756. { "isp", ISP }, /* Interrupt Stack Pointer. */
  3757. { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0. */
  3758. { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1. */
  3759. { "dtt0", DTT0 }, /* Data Transparent Translation Register 0. */
  3760. { "dtt1", DTT1 }, /* Data Transparent Translation Register 1. */
  3761. /* 68ec040 versions of same */
  3762. { "iacr0", ITT0 }, /* Instruction Access Control Register 0. */
  3763. { "iacr1", ITT1 }, /* Instruction Access Control Register 0. */
  3764. { "dacr0", DTT0 }, /* Data Access Control Register 0. */
  3765. { "dacr1", DTT1 }, /* Data Access Control Register 0. */
  3766. /* Coldfire versions of same. The ColdFire programmer's reference
  3767. manual indicated that the order is 2,3,0,1, but Ken Rose
  3768. <rose@netcom.com> says that 0,1,2,3 is the correct order. */
  3769. { "acr0", ACR0 }, /* Access Control Unit 0. */
  3770. { "acr1", ACR1 }, /* Access Control Unit 1. */
  3771. { "acr2", ACR2 }, /* Access Control Unit 2. */
  3772. { "acr3", ACR3 }, /* Access Control Unit 3. */
  3773. { "acr4", ACR4 }, /* Access Control Unit 4. */
  3774. { "acr5", ACR5 }, /* Access Control Unit 5. */
  3775. { "acr6", ACR6 }, /* Access Control Unit 6. */
  3776. { "acr7", ACR7 }, /* Access Control Unit 7. */
  3777. { "tc", TC }, /* MMU Translation Control Register. */
  3778. { "tcr", TC },
  3779. { "asid", ASID },
  3780. { "mmusr", MMUSR }, /* MMU Status Register. */
  3781. { "srp", SRP }, /* User Root Pointer. */
  3782. { "urp", URP }, /* Supervisor Root Pointer. */
  3783. { "buscr", BUSCR },
  3784. { "mmubar", MMUBAR },
  3785. { "pcr", PCR },
  3786. { "rombar", ROMBAR }, /* ROM Base Address Register. */
  3787. { "rambar0", RAMBAR0 }, /* ROM Base Address Register. */
  3788. { "rambar1", RAMBAR1 }, /* ROM Base Address Register. */
  3789. { "mbar", MBAR }, /* Module Base Address Register. */
  3790. { "mbar0", MBAR0 }, /* mcfv4e registers. */
  3791. { "mbar1", MBAR1 }, /* mcfv4e registers. */
  3792. { "rombar0", ROMBAR0 }, /* mcfv4e registers. */
  3793. { "rombar1", ROMBAR1 }, /* mcfv4e registers. */
  3794. { "mpcr", MPCR }, /* mcfv4e registers. */
  3795. { "edrambar", EDRAMBAR }, /* mcfv4e registers. */
  3796. { "secmbar", SECMBAR }, /* mcfv4e registers. */
  3797. { "asid", TC }, /* mcfv4e registers. */
  3798. { "mmubar", BUSCR }, /* mcfv4e registers. */
  3799. { "pcr1u0", PCR1U0 }, /* mcfv4e registers. */
  3800. { "pcr1l0", PCR1L0 }, /* mcfv4e registers. */
  3801. { "pcr2u0", PCR2U0 }, /* mcfv4e registers. */
  3802. { "pcr2l0", PCR2L0 }, /* mcfv4e registers. */
  3803. { "pcr3u0", PCR3U0 }, /* mcfv4e registers. */
  3804. { "pcr3l0", PCR3L0 }, /* mcfv4e registers. */
  3805. { "pcr1u1", PCR1U1 }, /* mcfv4e registers. */
  3806. { "pcr1l1", PCR1L1 }, /* mcfv4e registers. */
  3807. { "pcr2u1", PCR2U1 }, /* mcfv4e registers. */
  3808. { "pcr2l1", PCR2L1 }, /* mcfv4e registers. */
  3809. { "pcr3u1", PCR3U1 }, /* mcfv4e registers. */
  3810. { "pcr3l1", PCR3L1 }, /* mcfv4e registers. */
  3811. { "flashbar", FLASHBAR }, /* mcf528x registers. */
  3812. { "rambar", RAMBAR }, /* mcf528x registers. */
  3813. { "mbar2", MBAR2 }, /* mcf5249 registers. */
  3814. { "rgpiobar", RGPIOBAR }, /* mcf54418 registers. */
  3815. { "cac", CAC }, /* fido registers. */
  3816. { "mbb", MBO }, /* fido registers (obsolete). */
  3817. { "mbo", MBO }, /* fido registers. */
  3818. /* End of control registers. */
  3819. { "ac", AC },
  3820. { "bc", BC },
  3821. { "cal", CAL },
  3822. { "crp", CRP },
  3823. { "drp", DRP },
  3824. { "pcsr", PCSR },
  3825. { "psr", PSR },
  3826. { "scc", SCC },
  3827. { "val", VAL },
  3828. { "bad0", BAD0 },
  3829. { "bad1", BAD1 },
  3830. { "bad2", BAD2 },
  3831. { "bad3", BAD3 },
  3832. { "bad4", BAD4 },
  3833. { "bad5", BAD5 },
  3834. { "bad6", BAD6 },
  3835. { "bad7", BAD7 },
  3836. { "bac0", BAC0 },
  3837. { "bac1", BAC1 },
  3838. { "bac2", BAC2 },
  3839. { "bac3", BAC3 },
  3840. { "bac4", BAC4 },
  3841. { "bac5", BAC5 },
  3842. { "bac6", BAC6 },
  3843. { "bac7", BAC7 },
  3844. { "ic", IC },
  3845. { "dc", DC },
  3846. { "nc", NC },
  3847. { "tt0", TT0 },
  3848. { "tt1", TT1 },
  3849. /* 68ec030 versions of same. */
  3850. { "ac0", TT0 },
  3851. { "ac1", TT1 },
  3852. /* 68ec030 access control unit, identical to 030 MMU status reg. */
  3853. { "acusr", PSR },
  3854. /* Suppressed data and address registers. */
  3855. { "zd0", ZDATA0 },
  3856. { "zd1", ZDATA1 },
  3857. { "zd2", ZDATA2 },
  3858. { "zd3", ZDATA3 },
  3859. { "zd4", ZDATA4 },
  3860. { "zd5", ZDATA5 },
  3861. { "zd6", ZDATA6 },
  3862. { "zd7", ZDATA7 },
  3863. { "za0", ZADDR0 },
  3864. { "za1", ZADDR1 },
  3865. { "za2", ZADDR2 },
  3866. { "za3", ZADDR3 },
  3867. { "za4", ZADDR4 },
  3868. { "za5", ZADDR5 },
  3869. { "za6", ZADDR6 },
  3870. { "za7", ZADDR7 },
  3871. /* Upper and lower data and address registers, used by macw and msacw. */
  3872. { "d0l", DATA0L },
  3873. { "d1l", DATA1L },
  3874. { "d2l", DATA2L },
  3875. { "d3l", DATA3L },
  3876. { "d4l", DATA4L },
  3877. { "d5l", DATA5L },
  3878. { "d6l", DATA6L },
  3879. { "d7l", DATA7L },
  3880. { "a0l", ADDR0L },
  3881. { "a1l", ADDR1L },
  3882. { "a2l", ADDR2L },
  3883. { "a3l", ADDR3L },
  3884. { "a4l", ADDR4L },
  3885. { "a5l", ADDR5L },
  3886. { "a6l", ADDR6L },
  3887. { "a7l", ADDR7L },
  3888. { "d0u", DATA0U },
  3889. { "d1u", DATA1U },
  3890. { "d2u", DATA2U },
  3891. { "d3u", DATA3U },
  3892. { "d4u", DATA4U },
  3893. { "d5u", DATA5U },
  3894. { "d6u", DATA6U },
  3895. { "d7u", DATA7U },
  3896. { "a0u", ADDR0U },
  3897. { "a1u", ADDR1U },
  3898. { "a2u", ADDR2U },
  3899. { "a3u", ADDR3U },
  3900. { "a4u", ADDR4U },
  3901. { "a5u", ADDR5U },
  3902. { "a6u", ADDR6U },
  3903. { "a7u", ADDR7U },
  3904. { 0, 0 }
  3905. };
  3906. static void
  3907. init_regtable (void)
  3908. {
  3909. int i;
  3910. for (i = 0; init_table[i].name; i++)
  3911. insert_reg (init_table[i].name, init_table[i].number);
  3912. }
  3913. void
  3914. md_assemble (char *str)
  3915. {
  3916. const char *er;
  3917. short *fromP;
  3918. char *toP = NULL;
  3919. int m, n = 0;
  3920. char *to_beg_P;
  3921. int shorts_this_frag;
  3922. fixS *fixP;
  3923. if (!selected_cpu && !selected_arch)
  3924. {
  3925. /* We've not selected an architecture yet. Set the default
  3926. now. We do this lazily so that an initial .cpu or .arch directive
  3927. can specify. */
  3928. if (!m68k_set_cpu (TARGET_CPU, 1, 1))
  3929. as_bad (_("unrecognized default cpu `%s'"), TARGET_CPU);
  3930. }
  3931. if (!initialized)
  3932. m68k_init_arch ();
  3933. /* In MRI mode, the instruction and operands are separated by a
  3934. space. Anything following the operands is a comment. The label
  3935. has already been removed. */
  3936. if (flag_mri)
  3937. {
  3938. char *s;
  3939. int fields = 0;
  3940. int infield = 0;
  3941. int inquote = 0;
  3942. for (s = str; *s != '\0'; s++)
  3943. {
  3944. if ((*s == ' ' || *s == '\t') && ! inquote)
  3945. {
  3946. if (infield)
  3947. {
  3948. ++fields;
  3949. if (fields >= 2)
  3950. {
  3951. *s = '\0';
  3952. break;
  3953. }
  3954. infield = 0;
  3955. }
  3956. }
  3957. else
  3958. {
  3959. if (! infield)
  3960. infield = 1;
  3961. if (*s == '\'')
  3962. inquote = ! inquote;
  3963. }
  3964. }
  3965. }
  3966. memset (&the_ins, '\0', sizeof (the_ins));
  3967. m68k_ip (str);
  3968. er = the_ins.error;
  3969. if (!er)
  3970. {
  3971. for (n = 0; n < the_ins.numargs; n++)
  3972. if (the_ins.operands[n].error)
  3973. {
  3974. er = the_ins.operands[n].error;
  3975. break;
  3976. }
  3977. }
  3978. if (er)
  3979. {
  3980. as_bad (_("%s -- statement `%s' ignored"), er, str);
  3981. return;
  3982. }
  3983. /* If there is a current label, record that it marks an instruction. */
  3984. if (current_label != NULL)
  3985. {
  3986. current_label->text = 1;
  3987. current_label = NULL;
  3988. }
  3989. #ifdef OBJ_ELF
  3990. /* Tie dwarf2 debug info to the address at the start of the insn. */
  3991. dwarf2_emit_insn (0);
  3992. #endif
  3993. if (the_ins.nfrag == 0)
  3994. {
  3995. /* No frag hacking involved; just put it out. */
  3996. toP = frag_more (2 * the_ins.numo);
  3997. fromP = &the_ins.opcode[0];
  3998. for (m = the_ins.numo; m; --m)
  3999. {
  4000. md_number_to_chars (toP, (long) (*fromP), 2);
  4001. toP += 2;
  4002. fromP++;
  4003. }
  4004. /* Put out symbol-dependent info. */
  4005. for (m = 0; m < the_ins.nrel; m++)
  4006. {
  4007. switch (the_ins.reloc[m].wid)
  4008. {
  4009. case 'B':
  4010. n = 1;
  4011. break;
  4012. case 'b':
  4013. n = 1;
  4014. break;
  4015. case '3':
  4016. n = 1;
  4017. break;
  4018. case 'w':
  4019. case 'W':
  4020. n = 2;
  4021. break;
  4022. case 'l':
  4023. n = 4;
  4024. break;
  4025. default:
  4026. as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
  4027. the_ins.reloc[m].wid);
  4028. }
  4029. fixP = fix_new_exp (frag_now,
  4030. ((toP - frag_now->fr_literal)
  4031. - the_ins.numo * 2 + the_ins.reloc[m].n),
  4032. n,
  4033. &the_ins.reloc[m].exp,
  4034. the_ins.reloc[m].pcrel,
  4035. get_reloc_code (n, the_ins.reloc[m].pcrel,
  4036. the_ins.reloc[m].pic_reloc));
  4037. fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
  4038. if (the_ins.reloc[m].wid == 'B')
  4039. fixP->fx_signed = 1;
  4040. }
  4041. return;
  4042. }
  4043. /* There's some frag hacking. */
  4044. {
  4045. /* Calculate the max frag size. */
  4046. int wid;
  4047. wid = 2 * the_ins.fragb[0].fragoff;
  4048. for (n = 1; n < the_ins.nfrag; n++)
  4049. wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  4050. /* frag_var part. */
  4051. wid += FRAG_VAR_SIZE;
  4052. /* Make sure the whole insn fits in one chunk, in particular that
  4053. the var part is attached, as we access one byte before the
  4054. variable frag for byte branches. */
  4055. frag_grow (wid);
  4056. }
  4057. for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
  4058. {
  4059. int wid;
  4060. if (n == 0)
  4061. wid = 2 * the_ins.fragb[n].fragoff;
  4062. else
  4063. wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  4064. toP = frag_more (wid);
  4065. to_beg_P = toP;
  4066. shorts_this_frag = 0;
  4067. for (m = wid / 2; m; --m)
  4068. {
  4069. md_number_to_chars (toP, (long) (*fromP), 2);
  4070. toP += 2;
  4071. fromP++;
  4072. shorts_this_frag++;
  4073. }
  4074. for (m = 0; m < the_ins.nrel; m++)
  4075. {
  4076. if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
  4077. {
  4078. the_ins.reloc[m].n -= 2 * shorts_this_frag;
  4079. break;
  4080. }
  4081. wid = the_ins.reloc[m].wid;
  4082. if (wid == 0)
  4083. continue;
  4084. the_ins.reloc[m].wid = 0;
  4085. wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  4086. fixP = fix_new_exp (frag_now,
  4087. ((toP - frag_now->fr_literal)
  4088. - the_ins.numo * 2 + the_ins.reloc[m].n),
  4089. wid,
  4090. &the_ins.reloc[m].exp,
  4091. the_ins.reloc[m].pcrel,
  4092. get_reloc_code (wid, the_ins.reloc[m].pcrel,
  4093. the_ins.reloc[m].pic_reloc));
  4094. fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
  4095. }
  4096. (void) frag_var (rs_machine_dependent, FRAG_VAR_SIZE, 0,
  4097. (relax_substateT) (the_ins.fragb[n].fragty),
  4098. the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
  4099. }
  4100. gas_assert (the_ins.nfrag >= 1);
  4101. n = the_ins.numo - the_ins.fragb[the_ins.nfrag - 1].fragoff;
  4102. shorts_this_frag = 0;
  4103. if (n)
  4104. {
  4105. toP = frag_more (n * 2);
  4106. while (n--)
  4107. {
  4108. md_number_to_chars (toP, (long) (*fromP), 2);
  4109. toP += 2;
  4110. fromP++;
  4111. shorts_this_frag++;
  4112. }
  4113. }
  4114. for (m = 0; m < the_ins.nrel; m++)
  4115. {
  4116. int wid;
  4117. wid = the_ins.reloc[m].wid;
  4118. if (wid == 0)
  4119. continue;
  4120. the_ins.reloc[m].wid = 0;
  4121. wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  4122. fixP = fix_new_exp (frag_now,
  4123. ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
  4124. - shorts_this_frag * 2),
  4125. wid,
  4126. &the_ins.reloc[m].exp,
  4127. the_ins.reloc[m].pcrel,
  4128. get_reloc_code (wid, the_ins.reloc[m].pcrel,
  4129. the_ins.reloc[m].pic_reloc));
  4130. fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
  4131. }
  4132. }
  4133. /* Comparison function used by qsort to rank the opcode entries by name. */
  4134. static int
  4135. m68k_compare_opcode (const void * v1, const void * v2)
  4136. {
  4137. struct m68k_opcode * op1, * op2;
  4138. int ret;
  4139. if (v1 == v2)
  4140. return 0;
  4141. op1 = *(struct m68k_opcode **) v1;
  4142. op2 = *(struct m68k_opcode **) v2;
  4143. /* Compare the two names. If different, return the comparison.
  4144. If the same, return the order they are in the opcode table. */
  4145. ret = strcmp (op1->name, op2->name);
  4146. if (ret)
  4147. return ret;
  4148. if (op1 < op2)
  4149. return -1;
  4150. return 1;
  4151. }
  4152. void
  4153. md_begin (void)
  4154. {
  4155. const struct m68k_opcode *ins;
  4156. struct m68k_incant *hack, *slak;
  4157. const char *retval = 0; /* Empty string, or error msg text. */
  4158. int i;
  4159. /* Set up hash tables with 68000 instructions.
  4160. similar to what the vax assembler does. */
  4161. /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  4162. a copy of it at runtime, adding in the information we want but isn't
  4163. there. I think it'd be better to have an awk script hack the table
  4164. at compile time. Or even just xstr the table and use it as-is. But
  4165. my lord ghod hath spoken, so we do it this way. Excuse the ugly var
  4166. names. */
  4167. if (flag_mri)
  4168. {
  4169. flag_reg_prefix_optional = 1;
  4170. m68k_abspcadd = 1;
  4171. if (! m68k_rel32_from_cmdline)
  4172. m68k_rel32 = 0;
  4173. }
  4174. /* First sort the opcode table into alphabetical order to seperate
  4175. the order that the assembler wants to see the opcodes from the
  4176. order that the disassembler wants to see them. */
  4177. m68k_sorted_opcodes = xmalloc (m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
  4178. if (!m68k_sorted_opcodes)
  4179. as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
  4180. m68k_numopcodes * ((int) sizeof (* m68k_sorted_opcodes)));
  4181. for (i = m68k_numopcodes; i--;)
  4182. m68k_sorted_opcodes[i] = m68k_opcodes + i;
  4183. qsort (m68k_sorted_opcodes, m68k_numopcodes,
  4184. sizeof (m68k_sorted_opcodes[0]), m68k_compare_opcode);
  4185. op_hash = hash_new ();
  4186. obstack_begin (&robyn, 4000);
  4187. for (i = 0; i < m68k_numopcodes; i++)
  4188. {
  4189. hack = slak = obstack_alloc (&robyn, sizeof (struct m68k_incant));
  4190. do
  4191. {
  4192. ins = m68k_sorted_opcodes[i];
  4193. /* We must enter all insns into the table, because .arch and
  4194. .cpu directives can change things. */
  4195. slak->m_operands = ins->args;
  4196. slak->m_arch = ins->arch;
  4197. slak->m_opcode = ins->opcode;
  4198. /* In most cases we can determine the number of opcode words
  4199. by checking the second word of the mask. Unfortunately
  4200. some instructions have 2 opcode words, but no fixed bits
  4201. in the second word. A leading dot in the operands
  4202. string also indicates 2 opcodes. */
  4203. if (*slak->m_operands == '.')
  4204. {
  4205. slak->m_operands++;
  4206. slak->m_codenum = 2;
  4207. }
  4208. else if (ins->match & 0xffffL)
  4209. slak->m_codenum = 2;
  4210. else
  4211. slak->m_codenum = 1;
  4212. slak->m_opnum = strlen (slak->m_operands) / 2;
  4213. if (i + 1 != m68k_numopcodes
  4214. && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
  4215. {
  4216. slak->m_next = obstack_alloc (&robyn, sizeof (struct m68k_incant));
  4217. i++;
  4218. }
  4219. else
  4220. slak->m_next = 0;
  4221. slak = slak->m_next;
  4222. }
  4223. while (slak);
  4224. retval = hash_insert (op_hash, ins->name, (char *) hack);
  4225. if (retval)
  4226. as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
  4227. }
  4228. for (i = 0; i < m68k_numaliases; i++)
  4229. {
  4230. const char *name = m68k_opcode_aliases[i].primary;
  4231. const char *alias = m68k_opcode_aliases[i].alias;
  4232. void *val = hash_find (op_hash, name);
  4233. if (!val)
  4234. as_fatal (_("Internal Error: Can't find %s in hash table"), name);
  4235. retval = hash_insert (op_hash, alias, val);
  4236. if (retval)
  4237. as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
  4238. }
  4239. /* In MRI mode, all unsized branches are variable sized. Normally,
  4240. they are word sized. */
  4241. if (flag_mri)
  4242. {
  4243. static struct m68k_opcode_alias mri_aliases[] =
  4244. {
  4245. { "bhi", "jhi", },
  4246. { "bls", "jls", },
  4247. { "bcc", "jcc", },
  4248. { "bcs", "jcs", },
  4249. { "bne", "jne", },
  4250. { "beq", "jeq", },
  4251. { "bvc", "jvc", },
  4252. { "bvs", "jvs", },
  4253. { "bpl", "jpl", },
  4254. { "bmi", "jmi", },
  4255. { "bge", "jge", },
  4256. { "blt", "jlt", },
  4257. { "bgt", "jgt", },
  4258. { "ble", "jle", },
  4259. { "bra", "jra", },
  4260. { "bsr", "jbsr", },
  4261. };
  4262. for (i = 0;
  4263. i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
  4264. i++)
  4265. {
  4266. const char *name = mri_aliases[i].primary;
  4267. const char *alias = mri_aliases[i].alias;
  4268. void *val = hash_find (op_hash, name);
  4269. if (!val)
  4270. as_fatal (_("Internal Error: Can't find %s in hash table"), name);
  4271. retval = hash_jam (op_hash, alias, val);
  4272. if (retval)
  4273. as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
  4274. }
  4275. }
  4276. for (i = 0; i < (int) sizeof (notend_table); i++)
  4277. {
  4278. notend_table[i] = 0;
  4279. alt_notend_table[i] = 0;
  4280. }
  4281. notend_table[','] = 1;
  4282. notend_table['{'] = 1;
  4283. notend_table['}'] = 1;
  4284. alt_notend_table['a'] = 1;
  4285. alt_notend_table['A'] = 1;
  4286. alt_notend_table['d'] = 1;
  4287. alt_notend_table['D'] = 1;
  4288. alt_notend_table['#'] = 1;
  4289. alt_notend_table['&'] = 1;
  4290. alt_notend_table['f'] = 1;
  4291. alt_notend_table['F'] = 1;
  4292. #ifdef REGISTER_PREFIX
  4293. alt_notend_table[REGISTER_PREFIX] = 1;
  4294. #endif
  4295. /* We need to put '(' in alt_notend_table to handle
  4296. cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
  4297. alt_notend_table['('] = 1;
  4298. /* We need to put '@' in alt_notend_table to handle
  4299. cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
  4300. alt_notend_table['@'] = 1;
  4301. /* We need to put digits in alt_notend_table to handle
  4302. bfextu %d0{24:1},%d0 */
  4303. alt_notend_table['0'] = 1;
  4304. alt_notend_table['1'] = 1;
  4305. alt_notend_table['2'] = 1;
  4306. alt_notend_table['3'] = 1;
  4307. alt_notend_table['4'] = 1;
  4308. alt_notend_table['5'] = 1;
  4309. alt_notend_table['6'] = 1;
  4310. alt_notend_table['7'] = 1;
  4311. alt_notend_table['8'] = 1;
  4312. alt_notend_table['9'] = 1;
  4313. #ifndef MIT_SYNTAX_ONLY
  4314. /* Insert pseudo ops, these have to go into the opcode table since
  4315. gas expects pseudo ops to start with a dot. */
  4316. {
  4317. int n = 0;
  4318. while (mote_pseudo_table[n].poc_name)
  4319. {
  4320. hack = obstack_alloc (&robyn, sizeof (struct m68k_incant));
  4321. hash_insert (op_hash,
  4322. mote_pseudo_table[n].poc_name, (char *) hack);
  4323. hack->m_operands = 0;
  4324. hack->m_opnum = n;
  4325. n++;
  4326. }
  4327. }
  4328. #endif
  4329. init_regtable ();
  4330. #ifdef OBJ_ELF
  4331. record_alignment (text_section, 2);
  4332. record_alignment (data_section, 2);
  4333. record_alignment (bss_section, 2);
  4334. #endif
  4335. }
  4336. /* This is called when a label is defined. */
  4337. void
  4338. m68k_frob_label (symbolS *sym)
  4339. {
  4340. struct label_line *n;
  4341. n = (struct label_line *) xmalloc (sizeof *n);
  4342. n->next = labels;
  4343. n->label = sym;
  4344. as_where (&n->file, &n->line);
  4345. n->text = 0;
  4346. labels = n;
  4347. current_label = n;
  4348. #ifdef OBJ_ELF
  4349. dwarf2_emit_label (sym);
  4350. #endif
  4351. }
  4352. /* This is called when a value that is not an instruction is emitted. */
  4353. void
  4354. m68k_flush_pending_output (void)
  4355. {
  4356. current_label = NULL;
  4357. }
  4358. /* This is called at the end of the assembly, when the final value of
  4359. the label is known. We warn if this is a text symbol aligned at an
  4360. odd location. */
  4361. void
  4362. m68k_frob_symbol (symbolS *sym)
  4363. {
  4364. if (S_GET_SEGMENT (sym) == reg_section
  4365. && (int) S_GET_VALUE (sym) < 0)
  4366. {
  4367. S_SET_SEGMENT (sym, absolute_section);
  4368. S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
  4369. }
  4370. else if ((S_GET_VALUE (sym) & 1) != 0)
  4371. {
  4372. struct label_line *l;
  4373. for (l = labels; l != NULL; l = l->next)
  4374. {
  4375. if (l->label == sym)
  4376. {
  4377. if (l->text)
  4378. as_warn_where (l->file, l->line,
  4379. _("text label `%s' aligned to odd boundary"),
  4380. S_GET_NAME (sym));
  4381. break;
  4382. }
  4383. }
  4384. }
  4385. }
  4386. /* This is called if we go in or out of MRI mode because of the .mri
  4387. pseudo-op. */
  4388. void
  4389. m68k_mri_mode_change (int on)
  4390. {
  4391. if (on)
  4392. {
  4393. if (! flag_reg_prefix_optional)
  4394. {
  4395. flag_reg_prefix_optional = 1;
  4396. #ifdef REGISTER_PREFIX
  4397. init_regtable ();
  4398. #endif
  4399. }
  4400. m68k_abspcadd = 1;
  4401. if (! m68k_rel32_from_cmdline)
  4402. m68k_rel32 = 0;
  4403. }
  4404. else
  4405. {
  4406. if (! reg_prefix_optional_seen)
  4407. {
  4408. #ifdef REGISTER_PREFIX_OPTIONAL
  4409. flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
  4410. #else
  4411. flag_reg_prefix_optional = 0;
  4412. #endif
  4413. #ifdef REGISTER_PREFIX
  4414. init_regtable ();
  4415. #endif
  4416. }
  4417. m68k_abspcadd = 0;
  4418. if (! m68k_rel32_from_cmdline)
  4419. m68k_rel32 = 1;
  4420. }
  4421. }
  4422. char *
  4423. md_atof (int type, char *litP, int *sizeP)
  4424. {
  4425. return ieee_md_atof (type, litP, sizeP, TRUE);
  4426. }
  4427. void
  4428. md_number_to_chars (char *buf, valueT val, int n)
  4429. {
  4430. number_to_chars_bigendian (buf, val, n);
  4431. }
  4432. void
  4433. md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
  4434. {
  4435. offsetT val = *valP;
  4436. addressT upper_limit;
  4437. offsetT lower_limit;
  4438. /* This is unnecessary but it convinces the native rs6000 compiler
  4439. to generate the code we want. */
  4440. char *buf = fixP->fx_frag->fr_literal;
  4441. buf += fixP->fx_where;
  4442. /* End ibm compiler workaround. */
  4443. val = SEXT (val);
  4444. if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
  4445. fixP->fx_done = 1;
  4446. #ifdef OBJ_ELF
  4447. if (fixP->fx_addsy)
  4448. {
  4449. memset (buf, 0, fixP->fx_size);
  4450. fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
  4451. if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
  4452. && !S_IS_DEFINED (fixP->fx_addsy)
  4453. && !S_IS_WEAK (fixP->fx_addsy))
  4454. S_SET_WEAK (fixP->fx_addsy);
  4455. switch (fixP->fx_r_type)
  4456. {
  4457. case BFD_RELOC_68K_TLS_GD32:
  4458. case BFD_RELOC_68K_TLS_GD16:
  4459. case BFD_RELOC_68K_TLS_GD8:
  4460. case BFD_RELOC_68K_TLS_LDM32:
  4461. case BFD_RELOC_68K_TLS_LDM16:
  4462. case BFD_RELOC_68K_TLS_LDM8:
  4463. case BFD_RELOC_68K_TLS_LDO32:
  4464. case BFD_RELOC_68K_TLS_LDO16:
  4465. case BFD_RELOC_68K_TLS_LDO8:
  4466. case BFD_RELOC_68K_TLS_IE32:
  4467. case BFD_RELOC_68K_TLS_IE16:
  4468. case BFD_RELOC_68K_TLS_IE8:
  4469. case BFD_RELOC_68K_TLS_LE32:
  4470. case BFD_RELOC_68K_TLS_LE16:
  4471. case BFD_RELOC_68K_TLS_LE8:
  4472. S_SET_THREAD_LOCAL (fixP->fx_addsy);
  4473. break;
  4474. default:
  4475. break;
  4476. }
  4477. return;
  4478. }
  4479. #elif defined(OBJ_AOUT)
  4480. /* PR gas/3041 Do not fix frags referencing a weak symbol. */
  4481. if (fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy))
  4482. {
  4483. memset (buf, 0, fixP->fx_size);
  4484. fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
  4485. return;
  4486. }
  4487. #endif
  4488. if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
  4489. || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
  4490. return;
  4491. switch (fixP->fx_size)
  4492. {
  4493. /* The cast to offsetT below are necessary to make code
  4494. correct for machines where ints are smaller than offsetT. */
  4495. case 1:
  4496. *buf++ = val;
  4497. upper_limit = 0x7f;
  4498. lower_limit = - (offsetT) 0x80;
  4499. break;
  4500. case 2:
  4501. *buf++ = (val >> 8);
  4502. *buf++ = val;
  4503. upper_limit = 0x7fff;
  4504. lower_limit = - (offsetT) 0x8000;
  4505. break;
  4506. case 4:
  4507. *buf++ = (val >> 24);
  4508. *buf++ = (val >> 16);
  4509. *buf++ = (val >> 8);
  4510. *buf++ = val;
  4511. upper_limit = 0x7fffffff;
  4512. lower_limit = - (offsetT) 0x7fffffff - 1; /* Avoid constant overflow. */
  4513. break;
  4514. default:
  4515. BAD_CASE (fixP->fx_size);
  4516. }
  4517. /* Fix up a negative reloc. */
  4518. if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
  4519. {
  4520. fixP->fx_addsy = fixP->fx_subsy;
  4521. fixP->fx_subsy = NULL;
  4522. fixP->fx_tcbit = 1;
  4523. }
  4524. /* For non-pc-relative values, it's conceivable we might get something
  4525. like "0xff" for a byte field. So extend the upper part of the range
  4526. to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
  4527. so that we can do any range checking at all. */
  4528. if (! fixP->fx_pcrel && ! fixP->fx_signed)
  4529. upper_limit = upper_limit * 2 + 1;
  4530. if ((addressT) val > upper_limit
  4531. && (val > 0 || val < lower_limit))
  4532. as_bad_where (fixP->fx_file, fixP->fx_line,
  4533. _("value %ld out of range"), (long)val);
  4534. /* A one byte PC-relative reloc means a short branch. We can't use
  4535. a short branch with a value of 0 or -1, because those indicate
  4536. different opcodes (branches with longer offsets). fixup_segment
  4537. in write.c may have clobbered fx_pcrel, so we need to examine the
  4538. reloc type. */
  4539. if ((fixP->fx_pcrel
  4540. || fixP->fx_r_type == BFD_RELOC_8_PCREL)
  4541. && fixP->fx_size == 1
  4542. && (fixP->fx_addsy == NULL
  4543. || S_IS_DEFINED (fixP->fx_addsy))
  4544. && (val == 0 || val == -1))
  4545. as_bad_where (fixP->fx_file, fixP->fx_line,
  4546. _("invalid byte branch offset"));
  4547. }
  4548. /* *fragP has been relaxed to its final size, and now needs to have
  4549. the bytes inside it modified to conform to the new size There is UGLY
  4550. MAGIC here. ..
  4551. */
  4552. static void
  4553. md_convert_frag_1 (fragS *fragP)
  4554. {
  4555. long disp;
  4556. fixS *fixP = NULL;
  4557. /* Address in object code of the displacement. */
  4558. int object_address = fragP->fr_fix + fragP->fr_address;
  4559. /* Address in gas core of the place to store the displacement. */
  4560. /* This convinces the native rs6000 compiler to generate the code we
  4561. want. */
  4562. char *buffer_address = fragP->fr_literal;
  4563. buffer_address += fragP->fr_fix;
  4564. /* End ibm compiler workaround. */
  4565. /* The displacement of the address, from current location. */
  4566. disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
  4567. disp = (disp + fragP->fr_offset) - object_address;
  4568. switch (fragP->fr_subtype)
  4569. {
  4570. case TAB (BRANCHBWL, BYTE):
  4571. case TAB (BRABSJUNC, BYTE):
  4572. case TAB (BRABSJCOND, BYTE):
  4573. case TAB (BRANCHBW, BYTE):
  4574. case TAB (BRANCHBWPL, BYTE):
  4575. know (issbyte (disp));
  4576. if (disp == 0)
  4577. as_bad_where (fragP->fr_file, fragP->fr_line,
  4578. _("short branch with zero offset: use :w"));
  4579. fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
  4580. fragP->fr_offset, 1, RELAX_RELOC_PC8);
  4581. fixP->fx_pcrel_adjust = -1;
  4582. break;
  4583. case TAB (BRANCHBWL, SHORT):
  4584. case TAB (BRABSJUNC, SHORT):
  4585. case TAB (BRABSJCOND, SHORT):
  4586. case TAB (BRANCHBW, SHORT):
  4587. case TAB (BRANCHBWPL, SHORT):
  4588. fragP->fr_opcode[1] = 0x00;
  4589. fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4590. fragP->fr_offset, 1, RELAX_RELOC_PC16);
  4591. fragP->fr_fix += 2;
  4592. break;
  4593. case TAB (BRANCHBWL, LONG):
  4594. fragP->fr_opcode[1] = (char) 0xFF;
  4595. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4596. fragP->fr_offset, 1, RELAX_RELOC_PC32);
  4597. fragP->fr_fix += 4;
  4598. break;
  4599. case TAB (BRANCHBWPL, LONG):
  4600. /* Here we are converting an unconditional branch into a pair of
  4601. conditional branches, in order to get the range. */
  4602. fragP->fr_opcode[0] = 0x66; /* bne */
  4603. fragP->fr_opcode[1] = 0xFF;
  4604. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4605. fragP->fr_offset, 1, RELAX_RELOC_PC32);
  4606. fixP->fx_file = fragP->fr_file;
  4607. fixP->fx_line = fragP->fr_line;
  4608. fragP->fr_fix += 4; /* Skip first offset */
  4609. buffer_address += 4;
  4610. *buffer_address++ = 0x67; /* beq */
  4611. *buffer_address++ = 0xff;
  4612. fragP->fr_fix += 2; /* Skip second branch opcode */
  4613. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4614. fragP->fr_offset, 1, RELAX_RELOC_PC32);
  4615. fragP->fr_fix += 4;
  4616. break;
  4617. case TAB (BRABSJUNC, LONG):
  4618. if (fragP->fr_opcode[0] == 0x61) /* jbsr */
  4619. {
  4620. if (flag_keep_pcrel)
  4621. as_bad_where (fragP->fr_file, fragP->fr_line,
  4622. _("Conversion of PC relative BSR to absolute JSR"));
  4623. fragP->fr_opcode[0] = 0x4E;
  4624. fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
  4625. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4626. fragP->fr_offset, 0, RELAX_RELOC_ABS32);
  4627. fragP->fr_fix += 4;
  4628. }
  4629. else if (fragP->fr_opcode[0] == 0x60) /* jbra */
  4630. {
  4631. if (flag_keep_pcrel)
  4632. as_bad_where (fragP->fr_file, fragP->fr_line,
  4633. _("Conversion of PC relative branch to absolute jump"));
  4634. fragP->fr_opcode[0] = 0x4E;
  4635. fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
  4636. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4637. fragP->fr_offset, 0, RELAX_RELOC_ABS32);
  4638. fragP->fr_fix += 4;
  4639. }
  4640. else
  4641. {
  4642. /* This cannot happen, because jbsr and jbra are the only two
  4643. unconditional branches. */
  4644. abort ();
  4645. }
  4646. break;
  4647. case TAB (BRABSJCOND, LONG):
  4648. if (flag_keep_pcrel)
  4649. as_bad_where (fragP->fr_file, fragP->fr_line,
  4650. _("Conversion of PC relative conditional branch to absolute jump"));
  4651. /* Only Bcc 68000 instructions can come here
  4652. Change bcc into b!cc/jmp absl long. */
  4653. fragP->fr_opcode[0] ^= 0x01; /* Invert bcc. */
  4654. fragP->fr_opcode[1] = 0x06; /* Branch offset = 6. */
  4655. /* JF: these used to be fr_opcode[2,3], but they may be in a
  4656. different frag, in which case referring to them is a no-no.
  4657. Only fr_opcode[0,1] are guaranteed to work. */
  4658. *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
  4659. *buffer_address++ = (char) 0xf9;
  4660. fragP->fr_fix += 2; /* Account for jmp instruction. */
  4661. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4662. fragP->fr_offset, 0, RELAX_RELOC_ABS32);
  4663. fragP->fr_fix += 4;
  4664. break;
  4665. case TAB (FBRANCH, SHORT):
  4666. know ((fragP->fr_opcode[1] & 0x40) == 0);
  4667. fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4668. fragP->fr_offset, 1, RELAX_RELOC_PC16);
  4669. fragP->fr_fix += 2;
  4670. break;
  4671. case TAB (FBRANCH, LONG):
  4672. fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
  4673. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4674. fragP->fr_offset, 1, RELAX_RELOC_PC32);
  4675. fragP->fr_fix += 4;
  4676. break;
  4677. case TAB (DBCCLBR, SHORT):
  4678. case TAB (DBCCABSJ, SHORT):
  4679. fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4680. fragP->fr_offset, 1, RELAX_RELOC_PC16);
  4681. fragP->fr_fix += 2;
  4682. break;
  4683. case TAB (DBCCLBR, LONG):
  4684. /* Only DBcc instructions can come here.
  4685. Change dbcc into dbcc/bral.
  4686. JF: these used to be fr_opcode[2-7], but that's wrong. */
  4687. *buffer_address++ = 0x00; /* Branch offset = 4. */
  4688. *buffer_address++ = 0x04;
  4689. *buffer_address++ = 0x60; /* Put in bra pc+6. */
  4690. *buffer_address++ = 0x06;
  4691. *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
  4692. *buffer_address++ = (char) 0xff;
  4693. fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
  4694. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4695. fragP->fr_offset, 1, RELAX_RELOC_PC32);
  4696. fragP->fr_fix += 4;
  4697. break;
  4698. case TAB (DBCCABSJ, LONG):
  4699. /* Only DBcc instructions can come here.
  4700. Change dbcc into dbcc/jmp.
  4701. JF: these used to be fr_opcode[2-7], but that's wrong. */
  4702. if (flag_keep_pcrel)
  4703. as_bad_where (fragP->fr_file, fragP->fr_line,
  4704. _("Conversion of PC relative conditional branch to absolute jump"));
  4705. *buffer_address++ = 0x00; /* Branch offset = 4. */
  4706. *buffer_address++ = 0x04;
  4707. *buffer_address++ = 0x60; /* Put in bra pc + 6. */
  4708. *buffer_address++ = 0x06;
  4709. *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
  4710. *buffer_address++ = (char) 0xf9;
  4711. fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
  4712. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4713. fragP->fr_offset, 0, RELAX_RELOC_ABS32);
  4714. fragP->fr_fix += 4;
  4715. break;
  4716. case TAB (PCREL1632, SHORT):
  4717. fragP->fr_opcode[1] &= ~0x3F;
  4718. fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
  4719. fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
  4720. fragP->fr_offset, 1, RELAX_RELOC_PC16);
  4721. fragP->fr_fix += 2;
  4722. break;
  4723. case TAB (PCREL1632, LONG):
  4724. /* Already set to mode 7.3; this indicates: PC indirect with
  4725. suppressed index, 32-bit displacement. */
  4726. *buffer_address++ = 0x01;
  4727. *buffer_address++ = 0x70;
  4728. fragP->fr_fix += 2;
  4729. fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
  4730. fragP->fr_offset, 1, RELAX_RELOC_PC32);
  4731. fixP->fx_pcrel_adjust = 2;
  4732. fragP->fr_fix += 4;
  4733. break;
  4734. case TAB (PCINDEX, BYTE):
  4735. gas_assert (fragP->fr_fix >= 2);
  4736. buffer_address[-2] &= ~1;
  4737. fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
  4738. fragP->fr_offset, 1, RELAX_RELOC_PC8);
  4739. fixP->fx_pcrel_adjust = 1;
  4740. break;
  4741. case TAB (PCINDEX, SHORT):
  4742. gas_assert (fragP->fr_fix >= 2);
  4743. buffer_address[-2] |= 0x1;
  4744. buffer_address[-1] = 0x20;
  4745. fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
  4746. fragP->fr_offset, 1, RELAX_RELOC_PC16);
  4747. fixP->fx_pcrel_adjust = 2;
  4748. fragP->fr_fix += 2;
  4749. break;
  4750. case TAB (PCINDEX, LONG):
  4751. gas_assert (fragP->fr_fix >= 2);
  4752. buffer_address[-2] |= 0x1;
  4753. buffer_address[-1] = 0x30;
  4754. fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
  4755. fragP->fr_offset, 1, RELAX_RELOC_PC32);
  4756. fixP->fx_pcrel_adjust = 2;
  4757. fragP->fr_fix += 4;
  4758. break;
  4759. case TAB (ABSTOPCREL, SHORT):
  4760. fixP = fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
  4761. fragP->fr_offset, 1, RELAX_RELOC_PC16);
  4762. fragP->fr_fix += 2;
  4763. break;
  4764. case TAB (ABSTOPCREL, LONG):
  4765. if (flag_keep_pcrel)
  4766. as_bad_where (fragP->fr_file, fragP->fr_line,
  4767. _("Conversion of PC relative displacement to absolute"));
  4768. /* The thing to do here is force it to ABSOLUTE LONG, since
  4769. ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
  4770. if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  4771. abort ();
  4772. fragP->fr_opcode[1] &= ~0x3F;
  4773. fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
  4774. fixP = fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
  4775. fragP->fr_offset, 0, RELAX_RELOC_ABS32);
  4776. fragP->fr_fix += 4;
  4777. break;
  4778. }
  4779. if (fixP)
  4780. {
  4781. fixP->fx_file = fragP->fr_file;
  4782. fixP->fx_line = fragP->fr_line;
  4783. }
  4784. }
  4785. void
  4786. md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
  4787. segT sec ATTRIBUTE_UNUSED,
  4788. fragS *fragP)
  4789. {
  4790. md_convert_frag_1 (fragP);
  4791. }
  4792. /* Force truly undefined symbols to their maximum size, and generally set up
  4793. the frag list to be relaxed
  4794. */
  4795. int
  4796. md_estimate_size_before_relax (fragS *fragP, segT segment)
  4797. {
  4798. /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
  4799. switch (fragP->fr_subtype)
  4800. {
  4801. case TAB (BRANCHBWL, SZ_UNDEF):
  4802. case TAB (BRANCHBWPL, SZ_UNDEF):
  4803. case TAB (BRABSJUNC, SZ_UNDEF):
  4804. case TAB (BRABSJCOND, SZ_UNDEF):
  4805. {
  4806. if (S_GET_SEGMENT (fragP->fr_symbol) == segment
  4807. && relaxable_symbol (fragP->fr_symbol))
  4808. {
  4809. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
  4810. }
  4811. else if (flag_short_refs)
  4812. {
  4813. /* Symbol is undefined and we want short ref. */
  4814. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
  4815. }
  4816. else
  4817. {
  4818. /* Symbol is still undefined. Make it LONG. */
  4819. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
  4820. }
  4821. break;
  4822. }
  4823. case TAB (BRANCHBW, SZ_UNDEF):
  4824. {
  4825. if (S_GET_SEGMENT (fragP->fr_symbol) == segment
  4826. && relaxable_symbol (fragP->fr_symbol))
  4827. {
  4828. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
  4829. }
  4830. else
  4831. {
  4832. /* Symbol is undefined and we don't have long branches. */
  4833. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
  4834. }
  4835. break;
  4836. }
  4837. case TAB (FBRANCH, SZ_UNDEF):
  4838. case TAB (DBCCLBR, SZ_UNDEF):
  4839. case TAB (DBCCABSJ, SZ_UNDEF):
  4840. case TAB (PCREL1632, SZ_UNDEF):
  4841. {
  4842. if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
  4843. && relaxable_symbol (fragP->fr_symbol))
  4844. || flag_short_refs)
  4845. {
  4846. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
  4847. }
  4848. else
  4849. {
  4850. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
  4851. }
  4852. break;
  4853. }
  4854. case TAB (PCINDEX, SZ_UNDEF):
  4855. if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
  4856. && relaxable_symbol (fragP->fr_symbol)))
  4857. {
  4858. fragP->fr_subtype = TAB (PCINDEX, BYTE);
  4859. }
  4860. else
  4861. {
  4862. fragP->fr_subtype = TAB (PCINDEX, LONG);
  4863. }
  4864. break;
  4865. case TAB (ABSTOPCREL, SZ_UNDEF):
  4866. {
  4867. if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
  4868. && relaxable_symbol (fragP->fr_symbol)))
  4869. {
  4870. fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
  4871. }
  4872. else
  4873. {
  4874. fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
  4875. }
  4876. break;
  4877. }
  4878. default:
  4879. break;
  4880. }
  4881. /* Now that SZ_UNDEF are taken care of, check others. */
  4882. switch (fragP->fr_subtype)
  4883. {
  4884. case TAB (BRANCHBWL, BYTE):
  4885. case TAB (BRABSJUNC, BYTE):
  4886. case TAB (BRABSJCOND, BYTE):
  4887. case TAB (BRANCHBW, BYTE):
  4888. /* We can't do a short jump to the next instruction, so in that
  4889. case we force word mode. If the symbol is at the start of a
  4890. frag, and it is the next frag with any data in it (usually
  4891. this is just the next frag, but assembler listings may
  4892. introduce empty frags), we must use word mode. */
  4893. if (fragP->fr_symbol)
  4894. {
  4895. fragS *sym_frag;
  4896. sym_frag = symbol_get_frag (fragP->fr_symbol);
  4897. if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
  4898. {
  4899. fragS *l;
  4900. for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
  4901. if (l->fr_fix != 0)
  4902. break;
  4903. if (l == sym_frag)
  4904. fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
  4905. }
  4906. }
  4907. break;
  4908. default:
  4909. break;
  4910. }
  4911. return md_relax_table[fragP->fr_subtype].rlx_length;
  4912. }
  4913. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  4914. /* the bit-field entries in the relocation_info struct plays hell
  4915. with the byte-order problems of cross-assembly. So as a hack,
  4916. I added this mach. dependent ri twiddler. Ugly, but it gets
  4917. you there. -KWK */
  4918. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  4919. are symbolnum, most sig. byte first. Last byte is broken up with
  4920. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  4921. nibble as nuthin. (on Sun 3 at least) */
  4922. /* Translate the internal relocation information into target-specific
  4923. format. */
  4924. #ifdef comment
  4925. void
  4926. md_ri_to_chars (char *the_bytes, struct reloc_info_generic *ri)
  4927. {
  4928. /* This is easy. */
  4929. md_number_to_chars (the_bytes, ri->r_address, 4);
  4930. /* Now the fun stuff. */
  4931. the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
  4932. the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
  4933. the_bytes[6] = ri->r_symbolnum & 0x0ff;
  4934. the_bytes[7] = (((ri->r_pcrel << 7) & 0x80)
  4935. | ((ri->r_length << 5) & 0x60)
  4936. | ((ri->r_extern << 4) & 0x10));
  4937. }
  4938. #endif
  4939. #endif /* OBJ_AOUT or OBJ_BOUT */
  4940. #ifndef WORKING_DOT_WORD
  4941. int md_short_jump_size = 4;
  4942. int md_long_jump_size = 6;
  4943. void
  4944. md_create_short_jump (char *ptr, addressT from_addr, addressT to_addr,
  4945. fragS *frag ATTRIBUTE_UNUSED,
  4946. symbolS *to_symbol ATTRIBUTE_UNUSED)
  4947. {
  4948. valueT offset;
  4949. offset = to_addr - (from_addr + 2);
  4950. md_number_to_chars (ptr, (valueT) 0x6000, 2);
  4951. md_number_to_chars (ptr + 2, (valueT) offset, 2);
  4952. }
  4953. void
  4954. md_create_long_jump (char *ptr, addressT from_addr, addressT to_addr,
  4955. fragS *frag, symbolS *to_symbol)
  4956. {
  4957. valueT offset;
  4958. if (!HAVE_LONG_BRANCH (current_architecture))
  4959. {
  4960. if (flag_keep_pcrel)
  4961. as_fatal (_("Tried to convert PC relative branch to absolute jump"));
  4962. offset = to_addr - S_GET_VALUE (to_symbol);
  4963. md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
  4964. md_number_to_chars (ptr + 2, (valueT) offset, 4);
  4965. fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
  4966. 0, NO_RELOC);
  4967. }
  4968. else
  4969. {
  4970. offset = to_addr - (from_addr + 2);
  4971. md_number_to_chars (ptr, (valueT) 0x60ff, 2);
  4972. md_number_to_chars (ptr + 2, (valueT) offset, 4);
  4973. }
  4974. }
  4975. #endif
  4976. /* Different values of OK tell what its OK to return. Things that
  4977. aren't OK are an error (what a shock, no?)
  4978. 0: Everything is OK
  4979. 10: Absolute 1:8 only
  4980. 20: Absolute 0:7 only
  4981. 30: absolute 0:15 only
  4982. 40: Absolute 0:31 only
  4983. 50: absolute 0:127 only
  4984. 55: absolute -64:63 only
  4985. 60: absolute -128:127 only
  4986. 65: absolute 0:511 only
  4987. 70: absolute 0:4095 only
  4988. 80: absolute -1, 1:7 only
  4989. 90: No bignums. */
  4990. static int
  4991. get_num (struct m68k_exp *exp, int ok)
  4992. {
  4993. if (exp->exp.X_op == O_absent)
  4994. {
  4995. /* Do the same thing the VAX asm does. */
  4996. op (exp) = O_constant;
  4997. adds (exp) = 0;
  4998. subs (exp) = 0;
  4999. offs (exp) = 0;
  5000. if (ok == 10)
  5001. {
  5002. as_warn (_("expression out of range: defaulting to 1"));
  5003. offs (exp) = 1;
  5004. }
  5005. }
  5006. else if (exp->exp.X_op == O_constant)
  5007. {
  5008. switch (ok)
  5009. {
  5010. case 10:
  5011. if ((valueT) TRUNC (offs (exp)) - 1 > 7)
  5012. {
  5013. as_warn (_("expression out of range: defaulting to 1"));
  5014. offs (exp) = 1;
  5015. }
  5016. break;
  5017. case 20:
  5018. if ((valueT) TRUNC (offs (exp)) > 7)
  5019. goto outrange;
  5020. break;
  5021. case 30:
  5022. if ((valueT) TRUNC (offs (exp)) > 15)
  5023. goto outrange;
  5024. break;
  5025. case 40:
  5026. if ((valueT) TRUNC (offs (exp)) > 32)
  5027. goto outrange;
  5028. break;
  5029. case 50:
  5030. if ((valueT) TRUNC (offs (exp)) > 127)
  5031. goto outrange;
  5032. break;
  5033. case 55:
  5034. if ((valueT) SEXT (offs (exp)) + 64 > 127)
  5035. goto outrange;
  5036. break;
  5037. case 60:
  5038. if ((valueT) SEXT (offs (exp)) + 128 > 255)
  5039. goto outrange;
  5040. break;
  5041. case 65:
  5042. if ((valueT) TRUNC (offs (exp)) > 511)
  5043. goto outrange;
  5044. break;
  5045. case 70:
  5046. if ((valueT) TRUNC (offs (exp)) > 4095)
  5047. {
  5048. outrange:
  5049. as_warn (_("expression out of range: defaulting to 0"));
  5050. offs (exp) = 0;
  5051. }
  5052. break;
  5053. case 80:
  5054. if ((valueT) TRUNC (offs (exp)) != 0xffffffff
  5055. && (valueT) TRUNC (offs (exp)) - 1 > 6)
  5056. {
  5057. as_warn (_("expression out of range: defaulting to 1"));
  5058. offs (exp) = 1;
  5059. }
  5060. break;
  5061. default:
  5062. break;
  5063. }
  5064. }
  5065. else if (exp->exp.X_op == O_big)
  5066. {
  5067. if (offs (exp) <= 0 /* flonum. */
  5068. && (ok == 90 /* no bignums */
  5069. || (ok > 10 /* Small-int ranges including 0 ok. */
  5070. /* If we have a flonum zero, a zero integer should
  5071. do as well (e.g., in moveq). */
  5072. && generic_floating_point_number.exponent == 0
  5073. && generic_floating_point_number.low[0] == 0)))
  5074. {
  5075. /* HACK! Turn it into a long. */
  5076. LITTLENUM_TYPE words[6];
  5077. gen_to_words (words, 2, 8L); /* These numbers are magic! */
  5078. op (exp) = O_constant;
  5079. adds (exp) = 0;
  5080. subs (exp) = 0;
  5081. offs (exp) = words[1] | (words[0] << 16);
  5082. }
  5083. else if (ok != 0)
  5084. {
  5085. op (exp) = O_constant;
  5086. adds (exp) = 0;
  5087. subs (exp) = 0;
  5088. offs (exp) = (ok == 10) ? 1 : 0;
  5089. as_warn (_("Can't deal with expression; defaulting to %ld"),
  5090. (long) offs (exp));
  5091. }
  5092. }
  5093. else
  5094. {
  5095. if (ok >= 10 && ok <= 80)
  5096. {
  5097. op (exp) = O_constant;
  5098. adds (exp) = 0;
  5099. subs (exp) = 0;
  5100. offs (exp) = (ok == 10) ? 1 : 0;
  5101. as_warn (_("Can't deal with expression; defaulting to %ld"),
  5102. (long) offs (exp));
  5103. }
  5104. }
  5105. if (exp->size != SIZE_UNSPEC)
  5106. {
  5107. switch (exp->size)
  5108. {
  5109. case SIZE_UNSPEC:
  5110. case SIZE_LONG:
  5111. break;
  5112. case SIZE_BYTE:
  5113. if (!isbyte (offs (exp)))
  5114. as_warn (_("expression doesn't fit in BYTE"));
  5115. break;
  5116. case SIZE_WORD:
  5117. if (!isword (offs (exp)))
  5118. as_warn (_("expression doesn't fit in WORD"));
  5119. break;
  5120. }
  5121. }
  5122. return offs (exp);
  5123. }
  5124. /* These are the back-ends for the various machine dependent pseudo-ops. */
  5125. static void
  5126. s_data1 (int ignore ATTRIBUTE_UNUSED)
  5127. {
  5128. subseg_set (data_section, 1);
  5129. demand_empty_rest_of_line ();
  5130. }
  5131. static void
  5132. s_data2 (int ignore ATTRIBUTE_UNUSED)
  5133. {
  5134. subseg_set (data_section, 2);
  5135. demand_empty_rest_of_line ();
  5136. }
  5137. static void
  5138. s_bss (int ignore ATTRIBUTE_UNUSED)
  5139. {
  5140. /* We don't support putting frags in the BSS segment, we fake it
  5141. by marking in_bss, then looking at s_skip for clues. */
  5142. subseg_set (bss_section, 0);
  5143. demand_empty_rest_of_line ();
  5144. }
  5145. static void
  5146. s_even (int ignore ATTRIBUTE_UNUSED)
  5147. {
  5148. int temp;
  5149. long temp_fill;
  5150. temp = 1; /* JF should be 2? */
  5151. temp_fill = get_absolute_expression ();
  5152. if (!need_pass_2) /* Never make frag if expect extra pass. */
  5153. frag_align (temp, (int) temp_fill, 0);
  5154. demand_empty_rest_of_line ();
  5155. record_alignment (now_seg, temp);
  5156. }
  5157. static void
  5158. s_proc (int ignore ATTRIBUTE_UNUSED)
  5159. {
  5160. demand_empty_rest_of_line ();
  5161. }
  5162. /* Pseudo-ops handled for MRI compatibility. */
  5163. /* This function returns non-zero if the argument is a conditional
  5164. pseudo-op. This is called when checking whether a pending
  5165. alignment is needed. */
  5166. int
  5167. m68k_conditional_pseudoop (pseudo_typeS *pop)
  5168. {
  5169. return (pop->poc_handler == s_mri_if
  5170. || pop->poc_handler == s_mri_else);
  5171. }
  5172. /* Handle an MRI style chip specification. */
  5173. static void
  5174. mri_chip (void)
  5175. {
  5176. char *s;
  5177. char c;
  5178. int i;
  5179. s = input_line_pointer;
  5180. /* We can't use get_symbol_name since the processor names are not proper
  5181. symbols. */
  5182. while (is_part_of_name (c = *input_line_pointer++))
  5183. ;
  5184. *--input_line_pointer = 0;
  5185. for (i = 0; m68k_cpus[i].name; i++)
  5186. if (strcasecmp (s, m68k_cpus[i].name) == 0)
  5187. break;
  5188. if (!m68k_cpus[i].name)
  5189. {
  5190. as_bad (_("%s: unrecognized processor name"), s);
  5191. *input_line_pointer = c;
  5192. ignore_rest_of_line ();
  5193. return;
  5194. }
  5195. *input_line_pointer = c;
  5196. if (*input_line_pointer == '/')
  5197. current_architecture = 0;
  5198. else
  5199. current_architecture &= m68881 | m68851;
  5200. current_architecture |= m68k_cpus[i].arch & ~(m68881 | m68851);
  5201. control_regs = m68k_cpus[i].control_regs;
  5202. while (*input_line_pointer == '/')
  5203. {
  5204. ++input_line_pointer;
  5205. s = input_line_pointer;
  5206. /* We can't use get_symbol_name since the processor names are not
  5207. proper symbols. */
  5208. while (is_part_of_name (c = *input_line_pointer++))
  5209. ;
  5210. *--input_line_pointer = 0;
  5211. if (strcmp (s, "68881") == 0)
  5212. current_architecture |= m68881;
  5213. else if (strcmp (s, "68851") == 0)
  5214. current_architecture |= m68851;
  5215. *input_line_pointer = c;
  5216. }
  5217. }
  5218. /* The MRI CHIP pseudo-op. */
  5219. static void
  5220. s_chip (int ignore ATTRIBUTE_UNUSED)
  5221. {
  5222. char *stop = NULL;
  5223. char stopc;
  5224. if (flag_mri)
  5225. stop = mri_comment_field (&stopc);
  5226. mri_chip ();
  5227. if (flag_mri)
  5228. mri_comment_end (stop, stopc);
  5229. demand_empty_rest_of_line ();
  5230. }
  5231. /* The MRI FOPT pseudo-op. */
  5232. static void
  5233. s_fopt (int ignore ATTRIBUTE_UNUSED)
  5234. {
  5235. SKIP_WHITESPACE ();
  5236. if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
  5237. {
  5238. int temp;
  5239. input_line_pointer += 3;
  5240. temp = get_absolute_expression ();
  5241. if (temp < 0 || temp > 7)
  5242. as_bad (_("bad coprocessor id"));
  5243. else
  5244. m68k_float_copnum = COP0 + temp;
  5245. }
  5246. else
  5247. {
  5248. as_bad (_("unrecognized fopt option"));
  5249. ignore_rest_of_line ();
  5250. return;
  5251. }
  5252. demand_empty_rest_of_line ();
  5253. }
  5254. /* The structure used to handle the MRI OPT pseudo-op. */
  5255. struct opt_action
  5256. {
  5257. /* The name of the option. */
  5258. const char *name;
  5259. /* If this is not NULL, just call this function. The first argument
  5260. is the ARG field of this structure, the second argument is
  5261. whether the option was negated. */
  5262. void (*pfn) (int arg, int on);
  5263. /* If this is not NULL, and the PFN field is NULL, set the variable
  5264. this points to. Set it to the ARG field if the option was not
  5265. negated, and the NOTARG field otherwise. */
  5266. int *pvar;
  5267. /* The value to pass to PFN or to assign to *PVAR. */
  5268. int arg;
  5269. /* The value to assign to *PVAR if the option is negated. If PFN is
  5270. NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
  5271. the option may not be negated. */
  5272. int notarg;
  5273. };
  5274. /* The table used to handle the MRI OPT pseudo-op. */
  5275. static void skip_to_comma (int, int);
  5276. static void opt_nest (int, int);
  5277. static void opt_chip (int, int);
  5278. static void opt_list (int, int);
  5279. static void opt_list_symbols (int, int);
  5280. static const struct opt_action opt_table[] =
  5281. {
  5282. { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
  5283. /* We do relaxing, so there is little use for these options. */
  5284. { "b", 0, 0, 0, 0 },
  5285. { "brs", 0, 0, 0, 0 },
  5286. { "brb", 0, 0, 0, 0 },
  5287. { "brl", 0, 0, 0, 0 },
  5288. { "brw", 0, 0, 0, 0 },
  5289. { "c", 0, 0, 0, 0 },
  5290. { "cex", 0, 0, 0, 0 },
  5291. { "case", 0, &symbols_case_sensitive, 1, 0 },
  5292. { "cl", 0, 0, 0, 0 },
  5293. { "cre", 0, 0, 0, 0 },
  5294. { "d", 0, &flag_keep_locals, 1, 0 },
  5295. { "e", 0, 0, 0, 0 },
  5296. { "f", 0, &flag_short_refs, 1, 0 },
  5297. { "frs", 0, &flag_short_refs, 1, 0 },
  5298. { "frl", 0, &flag_short_refs, 0, 1 },
  5299. { "g", 0, 0, 0, 0 },
  5300. { "i", 0, 0, 0, 0 },
  5301. { "m", 0, 0, 0, 0 },
  5302. { "mex", 0, 0, 0, 0 },
  5303. { "mc", 0, 0, 0, 0 },
  5304. { "md", 0, 0, 0, 0 },
  5305. { "nest", opt_nest, 0, 0, 0 },
  5306. { "next", skip_to_comma, 0, 0, 0 },
  5307. { "o", 0, 0, 0, 0 },
  5308. { "old", 0, 0, 0, 0 },
  5309. { "op", skip_to_comma, 0, 0, 0 },
  5310. { "pco", 0, 0, 0, 0 },
  5311. { "p", opt_chip, 0, 0, 0 },
  5312. { "pcr", 0, 0, 0, 0 },
  5313. { "pcs", 0, 0, 0, 0 },
  5314. { "r", 0, 0, 0, 0 },
  5315. { "quick", 0, &m68k_quick, 1, 0 },
  5316. { "rel32", 0, &m68k_rel32, 1, 0 },
  5317. { "s", opt_list, 0, 0, 0 },
  5318. { "t", opt_list_symbols, 0, 0, 0 },
  5319. { "w", 0, &flag_no_warnings, 0, 1 },
  5320. { "x", 0, 0, 0, 0 }
  5321. };
  5322. #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
  5323. /* The MRI OPT pseudo-op. */
  5324. static void
  5325. s_opt (int ignore ATTRIBUTE_UNUSED)
  5326. {
  5327. do
  5328. {
  5329. int t;
  5330. char *s;
  5331. char c;
  5332. int i;
  5333. const struct opt_action *o;
  5334. SKIP_WHITESPACE ();
  5335. t = 1;
  5336. if (*input_line_pointer == '-')
  5337. {
  5338. ++input_line_pointer;
  5339. t = 0;
  5340. }
  5341. else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
  5342. {
  5343. input_line_pointer += 2;
  5344. t = 0;
  5345. }
  5346. c = get_symbol_name (&s);
  5347. for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
  5348. {
  5349. if (strcasecmp (s, o->name) == 0)
  5350. {
  5351. if (o->pfn)
  5352. {
  5353. /* Restore input_line_pointer now in case the option
  5354. takes arguments. */
  5355. (void) restore_line_pointer (c);
  5356. (*o->pfn) (o->arg, t);
  5357. }
  5358. else if (o->pvar != NULL)
  5359. {
  5360. if (! t && o->arg == o->notarg)
  5361. as_bad (_("option `%s' may not be negated"), s);
  5362. restore_line_pointer (c);
  5363. *o->pvar = t ? o->arg : o->notarg;
  5364. }
  5365. else
  5366. *input_line_pointer = c;
  5367. break;
  5368. }
  5369. }
  5370. if (i >= OPTCOUNT)
  5371. {
  5372. as_bad (_("option `%s' not recognized"), s);
  5373. restore_line_pointer (c);
  5374. }
  5375. }
  5376. while (*input_line_pointer++ == ',');
  5377. /* Move back to terminating character. */
  5378. --input_line_pointer;
  5379. demand_empty_rest_of_line ();
  5380. }
  5381. /* Skip ahead to a comma. This is used for OPT options which we do
  5382. not support and which take arguments. */
  5383. static void
  5384. skip_to_comma (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
  5385. {
  5386. while (*input_line_pointer != ','
  5387. && ! is_end_of_line[(unsigned char) *input_line_pointer])
  5388. ++input_line_pointer;
  5389. }
  5390. /* Handle the OPT NEST=depth option. */
  5391. static void
  5392. opt_nest (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
  5393. {
  5394. if (*input_line_pointer != '=')
  5395. {
  5396. as_bad (_("bad format of OPT NEST=depth"));
  5397. return;
  5398. }
  5399. ++input_line_pointer;
  5400. max_macro_nest = get_absolute_expression ();
  5401. }
  5402. /* Handle the OPT P=chip option. */
  5403. static void
  5404. opt_chip (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
  5405. {
  5406. if (*input_line_pointer != '=')
  5407. {
  5408. /* This is just OPT P, which we do not support. */
  5409. return;
  5410. }
  5411. ++input_line_pointer;
  5412. mri_chip ();
  5413. }
  5414. /* Handle the OPT S option. */
  5415. static void
  5416. opt_list (int arg ATTRIBUTE_UNUSED, int on)
  5417. {
  5418. listing_list (on);
  5419. }
  5420. /* Handle the OPT T option. */
  5421. static void
  5422. opt_list_symbols (int arg ATTRIBUTE_UNUSED, int on)
  5423. {
  5424. if (on)
  5425. listing |= LISTING_SYMBOLS;
  5426. else
  5427. listing &= ~LISTING_SYMBOLS;
  5428. }
  5429. /* Handle the MRI REG pseudo-op. */
  5430. static void
  5431. s_reg (int ignore ATTRIBUTE_UNUSED)
  5432. {
  5433. char *s;
  5434. int c;
  5435. struct m68k_op rop;
  5436. int mask;
  5437. char *stop = NULL;
  5438. char stopc;
  5439. if (line_label == NULL)
  5440. {
  5441. as_bad (_("missing label"));
  5442. ignore_rest_of_line ();
  5443. return;
  5444. }
  5445. if (flag_mri)
  5446. stop = mri_comment_field (&stopc);
  5447. SKIP_WHITESPACE ();
  5448. s = input_line_pointer;
  5449. while (ISALNUM (*input_line_pointer)
  5450. #ifdef REGISTER_PREFIX
  5451. || *input_line_pointer == REGISTER_PREFIX
  5452. #endif
  5453. || *input_line_pointer == '/'
  5454. || *input_line_pointer == '-')
  5455. ++input_line_pointer;
  5456. c = *input_line_pointer;
  5457. *input_line_pointer = '\0';
  5458. if (m68k_ip_op (s, &rop) != 0)
  5459. {
  5460. if (rop.error == NULL)
  5461. as_bad (_("bad register list"));
  5462. else
  5463. as_bad (_("bad register list: %s"), rop.error);
  5464. *input_line_pointer = c;
  5465. ignore_rest_of_line ();
  5466. return;
  5467. }
  5468. *input_line_pointer = c;
  5469. if (rop.mode == REGLST)
  5470. mask = rop.mask;
  5471. else if (rop.mode == DREG)
  5472. mask = 1 << (rop.reg - DATA0);
  5473. else if (rop.mode == AREG)
  5474. mask = 1 << (rop.reg - ADDR0 + 8);
  5475. else if (rop.mode == FPREG)
  5476. mask = 1 << (rop.reg - FP0 + 16);
  5477. else if (rop.mode == CONTROL
  5478. && rop.reg == FPI)
  5479. mask = 1 << 24;
  5480. else if (rop.mode == CONTROL
  5481. && rop.reg == FPS)
  5482. mask = 1 << 25;
  5483. else if (rop.mode == CONTROL
  5484. && rop.reg == FPC)
  5485. mask = 1 << 26;
  5486. else
  5487. {
  5488. as_bad (_("bad register list"));
  5489. ignore_rest_of_line ();
  5490. return;
  5491. }
  5492. S_SET_SEGMENT (line_label, reg_section);
  5493. S_SET_VALUE (line_label, ~mask);
  5494. symbol_set_frag (line_label, &zero_address_frag);
  5495. if (flag_mri)
  5496. mri_comment_end (stop, stopc);
  5497. demand_empty_rest_of_line ();
  5498. }
  5499. /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
  5500. struct save_opts
  5501. {
  5502. struct save_opts *next;
  5503. int abspcadd;
  5504. int symbols_case_sensitive;
  5505. int keep_locals;
  5506. int short_refs;
  5507. int architecture;
  5508. const enum m68k_register *control_regs;
  5509. int quick;
  5510. int rel32;
  5511. int listing;
  5512. int no_warnings;
  5513. /* FIXME: We don't save OPT S. */
  5514. };
  5515. /* This variable holds the stack of saved options. */
  5516. static struct save_opts *save_stack;
  5517. /* The MRI SAVE pseudo-op. */
  5518. static void
  5519. s_save (int ignore ATTRIBUTE_UNUSED)
  5520. {
  5521. struct save_opts *s;
  5522. s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
  5523. s->abspcadd = m68k_abspcadd;
  5524. s->symbols_case_sensitive = symbols_case_sensitive;
  5525. s->keep_locals = flag_keep_locals;
  5526. s->short_refs = flag_short_refs;
  5527. s->architecture = current_architecture;
  5528. s->control_regs = control_regs;
  5529. s->quick = m68k_quick;
  5530. s->rel32 = m68k_rel32;
  5531. s->listing = listing;
  5532. s->no_warnings = flag_no_warnings;
  5533. s->next = save_stack;
  5534. save_stack = s;
  5535. demand_empty_rest_of_line ();
  5536. }
  5537. /* The MRI RESTORE pseudo-op. */
  5538. static void
  5539. s_restore (int ignore ATTRIBUTE_UNUSED)
  5540. {
  5541. struct save_opts *s;
  5542. if (save_stack == NULL)
  5543. {
  5544. as_bad (_("restore without save"));
  5545. ignore_rest_of_line ();
  5546. return;
  5547. }
  5548. s = save_stack;
  5549. save_stack = s->next;
  5550. m68k_abspcadd = s->abspcadd;
  5551. symbols_case_sensitive = s->symbols_case_sensitive;
  5552. flag_keep_locals = s->keep_locals;
  5553. flag_short_refs = s->short_refs;
  5554. current_architecture = s->architecture;
  5555. control_regs = s->control_regs;
  5556. m68k_quick = s->quick;
  5557. m68k_rel32 = s->rel32;
  5558. listing = s->listing;
  5559. flag_no_warnings = s->no_warnings;
  5560. free (s);
  5561. demand_empty_rest_of_line ();
  5562. }
  5563. /* Types of MRI structured control directives. */
  5564. enum mri_control_type
  5565. {
  5566. mri_for,
  5567. mri_if,
  5568. mri_repeat,
  5569. mri_while
  5570. };
  5571. /* This structure is used to stack the MRI structured control
  5572. directives. */
  5573. struct mri_control_info
  5574. {
  5575. /* The directive within which this one is enclosed. */
  5576. struct mri_control_info *outer;
  5577. /* The type of directive. */
  5578. enum mri_control_type type;
  5579. /* Whether an ELSE has been in an IF. */
  5580. int else_seen;
  5581. /* The add or sub statement at the end of a FOR. */
  5582. char *incr;
  5583. /* The label of the top of a FOR or REPEAT loop. */
  5584. char *top;
  5585. /* The label to jump to for the next iteration, or the else
  5586. expression of a conditional. */
  5587. char *next;
  5588. /* The label to jump to to break out of the loop, or the label past
  5589. the end of a conditional. */
  5590. char *bottom;
  5591. };
  5592. /* The stack of MRI structured control directives. */
  5593. static struct mri_control_info *mri_control_stack;
  5594. /* The current MRI structured control directive index number, used to
  5595. generate label names. */
  5596. static int mri_control_index;
  5597. /* Assemble an instruction for an MRI structured control directive. */
  5598. static void
  5599. mri_assemble (char *str)
  5600. {
  5601. char *s;
  5602. /* md_assemble expects the opcode to be in lower case. */
  5603. for (s = str; *s != ' ' && *s != '\0'; s++)
  5604. *s = TOLOWER (*s);
  5605. md_assemble (str);
  5606. }
  5607. /* Generate a new MRI label structured control directive label name. */
  5608. static char *
  5609. mri_control_label (void)
  5610. {
  5611. char *n;
  5612. n = (char *) xmalloc (20);
  5613. sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
  5614. ++mri_control_index;
  5615. return n;
  5616. }
  5617. /* Create a new MRI structured control directive. */
  5618. static struct mri_control_info *
  5619. push_mri_control (enum mri_control_type type)
  5620. {
  5621. struct mri_control_info *n;
  5622. n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
  5623. n->type = type;
  5624. n->else_seen = 0;
  5625. if (type == mri_if || type == mri_while)
  5626. n->top = NULL;
  5627. else
  5628. n->top = mri_control_label ();
  5629. n->next = mri_control_label ();
  5630. n->bottom = mri_control_label ();
  5631. n->outer = mri_control_stack;
  5632. mri_control_stack = n;
  5633. return n;
  5634. }
  5635. /* Pop off the stack of MRI structured control directives. */
  5636. static void
  5637. pop_mri_control (void)
  5638. {
  5639. struct mri_control_info *n;
  5640. n = mri_control_stack;
  5641. mri_control_stack = n->outer;
  5642. if (n->top != NULL)
  5643. free (n->top);
  5644. free (n->next);
  5645. free (n->bottom);
  5646. free (n);
  5647. }
  5648. /* Recognize a condition code in an MRI structured control expression. */
  5649. static int
  5650. parse_mri_condition (int *pcc)
  5651. {
  5652. char c1, c2;
  5653. know (*input_line_pointer == '<');
  5654. ++input_line_pointer;
  5655. c1 = *input_line_pointer++;
  5656. c2 = *input_line_pointer++;
  5657. if (*input_line_pointer != '>')
  5658. {
  5659. as_bad (_("syntax error in structured control directive"));
  5660. return 0;
  5661. }
  5662. ++input_line_pointer;
  5663. SKIP_WHITESPACE ();
  5664. c1 = TOLOWER (c1);
  5665. c2 = TOLOWER (c2);
  5666. *pcc = (c1 << 8) | c2;
  5667. return 1;
  5668. }
  5669. /* Parse a single operand in an MRI structured control expression. */
  5670. static int
  5671. parse_mri_control_operand (int *pcc, char **leftstart, char **leftstop,
  5672. char **rightstart, char **rightstop)
  5673. {
  5674. char *s;
  5675. SKIP_WHITESPACE ();
  5676. *pcc = -1;
  5677. *leftstart = NULL;
  5678. *leftstop = NULL;
  5679. *rightstart = NULL;
  5680. *rightstop = NULL;
  5681. if (*input_line_pointer == '<')
  5682. {
  5683. /* It's just a condition code. */
  5684. return parse_mri_condition (pcc);
  5685. }
  5686. /* Look ahead for the condition code. */
  5687. for (s = input_line_pointer; *s != '\0'; ++s)
  5688. {
  5689. if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
  5690. break;
  5691. }
  5692. if (*s == '\0')
  5693. {
  5694. as_bad (_("missing condition code in structured control directive"));
  5695. return 0;
  5696. }
  5697. *leftstart = input_line_pointer;
  5698. *leftstop = s;
  5699. if (*leftstop > *leftstart
  5700. && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
  5701. --*leftstop;
  5702. input_line_pointer = s;
  5703. if (! parse_mri_condition (pcc))
  5704. return 0;
  5705. /* Look ahead for AND or OR or end of line. */
  5706. for (s = input_line_pointer; *s != '\0'; ++s)
  5707. {
  5708. /* We must make sure we don't misinterpret AND/OR at the end of labels!
  5709. if d0 <eq> #FOOAND and d1 <ne> #BAROR then
  5710. ^^^ ^^ */
  5711. if ((s == input_line_pointer
  5712. || *(s-1) == ' '
  5713. || *(s-1) == '\t')
  5714. && ((strncasecmp (s, "AND", 3) == 0
  5715. && (s[3] == '.' || ! is_part_of_name (s[3])))
  5716. || (strncasecmp (s, "OR", 2) == 0
  5717. && (s[2] == '.' || ! is_part_of_name (s[2])))))
  5718. break;
  5719. }
  5720. *rightstart = input_line_pointer;
  5721. *rightstop = s;
  5722. if (*rightstop > *rightstart
  5723. && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
  5724. --*rightstop;
  5725. input_line_pointer = s;
  5726. return 1;
  5727. }
  5728. #define MCC(b1, b2) (((b1) << 8) | (b2))
  5729. /* Swap the sense of a condition. This changes the condition so that
  5730. it generates the same result when the operands are swapped. */
  5731. static int
  5732. swap_mri_condition (int cc)
  5733. {
  5734. switch (cc)
  5735. {
  5736. case MCC ('h', 'i'): return MCC ('c', 's');
  5737. case MCC ('l', 's'): return MCC ('c', 'c');
  5738. /* <HS> is an alias for <CC>. */
  5739. case MCC ('h', 's'):
  5740. case MCC ('c', 'c'): return MCC ('l', 's');
  5741. /* <LO> is an alias for <CS>. */
  5742. case MCC ('l', 'o'):
  5743. case MCC ('c', 's'): return MCC ('h', 'i');
  5744. case MCC ('p', 'l'): return MCC ('m', 'i');
  5745. case MCC ('m', 'i'): return MCC ('p', 'l');
  5746. case MCC ('g', 'e'): return MCC ('l', 'e');
  5747. case MCC ('l', 't'): return MCC ('g', 't');
  5748. case MCC ('g', 't'): return MCC ('l', 't');
  5749. case MCC ('l', 'e'): return MCC ('g', 'e');
  5750. /* Issue a warning for conditions we can not swap. */
  5751. case MCC ('n', 'e'): return MCC ('n', 'e'); /* no problem here */
  5752. case MCC ('e', 'q'): return MCC ('e', 'q'); /* also no problem */
  5753. case MCC ('v', 'c'):
  5754. case MCC ('v', 's'):
  5755. default :
  5756. as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
  5757. (char) (cc >> 8), (char) (cc));
  5758. break;
  5759. }
  5760. return cc;
  5761. }
  5762. /* Reverse the sense of a condition. */
  5763. static int
  5764. reverse_mri_condition (int cc)
  5765. {
  5766. switch (cc)
  5767. {
  5768. case MCC ('h', 'i'): return MCC ('l', 's');
  5769. case MCC ('l', 's'): return MCC ('h', 'i');
  5770. /* <HS> is an alias for <CC> */
  5771. case MCC ('h', 's'): return MCC ('l', 'o');
  5772. case MCC ('c', 'c'): return MCC ('c', 's');
  5773. /* <LO> is an alias for <CS> */
  5774. case MCC ('l', 'o'): return MCC ('h', 's');
  5775. case MCC ('c', 's'): return MCC ('c', 'c');
  5776. case MCC ('n', 'e'): return MCC ('e', 'q');
  5777. case MCC ('e', 'q'): return MCC ('n', 'e');
  5778. case MCC ('v', 'c'): return MCC ('v', 's');
  5779. case MCC ('v', 's'): return MCC ('v', 'c');
  5780. case MCC ('p', 'l'): return MCC ('m', 'i');
  5781. case MCC ('m', 'i'): return MCC ('p', 'l');
  5782. case MCC ('g', 'e'): return MCC ('l', 't');
  5783. case MCC ('l', 't'): return MCC ('g', 'e');
  5784. case MCC ('g', 't'): return MCC ('l', 'e');
  5785. case MCC ('l', 'e'): return MCC ('g', 't');
  5786. }
  5787. return cc;
  5788. }
  5789. /* Build an MRI structured control expression. This generates test
  5790. and branch instructions. It goes to TRUELAB if the condition is
  5791. true, and to FALSELAB if the condition is false. Exactly one of
  5792. TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
  5793. is the size qualifier for the expression. EXTENT is the size to
  5794. use for the branch. */
  5795. static void
  5796. build_mri_control_operand (int qual, int cc, char *leftstart, char *leftstop,
  5797. char *rightstart, char *rightstop,
  5798. const char *truelab, const char *falselab,
  5799. int extent)
  5800. {
  5801. char *buf;
  5802. char *s;
  5803. if (leftstart != NULL)
  5804. {
  5805. struct m68k_op leftop, rightop;
  5806. char c;
  5807. /* Swap the compare operands, if necessary, to produce a legal
  5808. m68k compare instruction. Comparing a register operand with
  5809. a non-register operand requires the register to be on the
  5810. right (cmp, cmpa). Comparing an immediate value with
  5811. anything requires the immediate value to be on the left
  5812. (cmpi). */
  5813. c = *leftstop;
  5814. *leftstop = '\0';
  5815. (void) m68k_ip_op (leftstart, &leftop);
  5816. *leftstop = c;
  5817. c = *rightstop;
  5818. *rightstop = '\0';
  5819. (void) m68k_ip_op (rightstart, &rightop);
  5820. *rightstop = c;
  5821. if (rightop.mode == IMMED
  5822. || ((leftop.mode == DREG || leftop.mode == AREG)
  5823. && (rightop.mode != DREG && rightop.mode != AREG)))
  5824. {
  5825. char *temp;
  5826. /* Correct conditional handling:
  5827. if #1 <lt> d0 then ;means if (1 < d0)
  5828. ...
  5829. endi
  5830. should assemble to:
  5831. cmp #1,d0 if we do *not* swap the operands
  5832. bgt true we need the swapped condition!
  5833. ble false
  5834. true:
  5835. ...
  5836. false:
  5837. */
  5838. temp = leftstart;
  5839. leftstart = rightstart;
  5840. rightstart = temp;
  5841. temp = leftstop;
  5842. leftstop = rightstop;
  5843. rightstop = temp;
  5844. }
  5845. else
  5846. {
  5847. cc = swap_mri_condition (cc);
  5848. }
  5849. }
  5850. if (truelab == NULL)
  5851. {
  5852. cc = reverse_mri_condition (cc);
  5853. truelab = falselab;
  5854. }
  5855. if (leftstart != NULL)
  5856. {
  5857. buf = (char *) xmalloc (20
  5858. + (leftstop - leftstart)
  5859. + (rightstop - rightstart));
  5860. s = buf;
  5861. *s++ = 'c';
  5862. *s++ = 'm';
  5863. *s++ = 'p';
  5864. if (qual != '\0')
  5865. *s++ = TOLOWER (qual);
  5866. *s++ = ' ';
  5867. memcpy (s, leftstart, leftstop - leftstart);
  5868. s += leftstop - leftstart;
  5869. *s++ = ',';
  5870. memcpy (s, rightstart, rightstop - rightstart);
  5871. s += rightstop - rightstart;
  5872. *s = '\0';
  5873. mri_assemble (buf);
  5874. free (buf);
  5875. }
  5876. buf = (char *) xmalloc (20 + strlen (truelab));
  5877. s = buf;
  5878. *s++ = 'b';
  5879. *s++ = cc >> 8;
  5880. *s++ = cc & 0xff;
  5881. if (extent != '\0')
  5882. *s++ = TOLOWER (extent);
  5883. *s++ = ' ';
  5884. strcpy (s, truelab);
  5885. mri_assemble (buf);
  5886. free (buf);
  5887. }
  5888. /* Parse an MRI structured control expression. This generates test
  5889. and branch instructions. STOP is where the expression ends. It
  5890. goes to TRUELAB if the condition is true, and to FALSELAB if the
  5891. condition is false. Exactly one of TRUELAB and FALSELAB will be
  5892. NULL, meaning to fall through. QUAL is the size qualifier for the
  5893. expression. EXTENT is the size to use for the branch. */
  5894. static void
  5895. parse_mri_control_expression (char *stop, int qual, const char *truelab,
  5896. const char *falselab, int extent)
  5897. {
  5898. int c;
  5899. int cc;
  5900. char *leftstart;
  5901. char *leftstop;
  5902. char *rightstart;
  5903. char *rightstop;
  5904. c = *stop;
  5905. *stop = '\0';
  5906. if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
  5907. &rightstart, &rightstop))
  5908. {
  5909. *stop = c;
  5910. return;
  5911. }
  5912. if (strncasecmp (input_line_pointer, "AND", 3) == 0)
  5913. {
  5914. const char *flab;
  5915. if (falselab != NULL)
  5916. flab = falselab;
  5917. else
  5918. flab = mri_control_label ();
  5919. build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5920. rightstop, (const char *) NULL, flab, extent);
  5921. input_line_pointer += 3;
  5922. if (*input_line_pointer != '.'
  5923. || input_line_pointer[1] == '\0')
  5924. qual = '\0';
  5925. else
  5926. {
  5927. qual = input_line_pointer[1];
  5928. input_line_pointer += 2;
  5929. }
  5930. if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
  5931. &rightstart, &rightstop))
  5932. {
  5933. *stop = c;
  5934. return;
  5935. }
  5936. build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5937. rightstop, truelab, falselab, extent);
  5938. if (falselab == NULL)
  5939. colon (flab);
  5940. }
  5941. else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
  5942. {
  5943. const char *tlab;
  5944. if (truelab != NULL)
  5945. tlab = truelab;
  5946. else
  5947. tlab = mri_control_label ();
  5948. build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5949. rightstop, tlab, (const char *) NULL, extent);
  5950. input_line_pointer += 2;
  5951. if (*input_line_pointer != '.'
  5952. || input_line_pointer[1] == '\0')
  5953. qual = '\0';
  5954. else
  5955. {
  5956. qual = input_line_pointer[1];
  5957. input_line_pointer += 2;
  5958. }
  5959. if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
  5960. &rightstart, &rightstop))
  5961. {
  5962. *stop = c;
  5963. return;
  5964. }
  5965. build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5966. rightstop, truelab, falselab, extent);
  5967. if (truelab == NULL)
  5968. colon (tlab);
  5969. }
  5970. else
  5971. {
  5972. build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
  5973. rightstop, truelab, falselab, extent);
  5974. }
  5975. *stop = c;
  5976. if (input_line_pointer != stop)
  5977. as_bad (_("syntax error in structured control directive"));
  5978. }
  5979. /* Handle the MRI IF pseudo-op. This may be a structured control
  5980. directive, or it may be a regular assembler conditional, depending
  5981. on its operands. */
  5982. static void
  5983. s_mri_if (int qual)
  5984. {
  5985. char *s;
  5986. int c;
  5987. struct mri_control_info *n;
  5988. /* A structured control directive must end with THEN with an
  5989. optional qualifier. */
  5990. s = input_line_pointer;
  5991. /* We only accept '*' as introduction of comments if preceded by white space
  5992. or at first column of a line (I think this can't actually happen here?)
  5993. This is important when assembling:
  5994. if d0 <ne> 12(a0,d0*2) then
  5995. if d0 <ne> #CONST*20 then. */
  5996. while (! (is_end_of_line[(unsigned char) *s]
  5997. || (flag_mri
  5998. && *s == '*'
  5999. && (s == input_line_pointer
  6000. || *(s-1) == ' '
  6001. || *(s-1) == '\t'))))
  6002. ++s;
  6003. --s;
  6004. while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
  6005. --s;
  6006. if (s - input_line_pointer > 1
  6007. && s[-1] == '.')
  6008. s -= 2;
  6009. if (s - input_line_pointer < 3
  6010. || strncasecmp (s - 3, "THEN", 4) != 0)
  6011. {
  6012. if (qual != '\0')
  6013. {
  6014. as_bad (_("missing then"));
  6015. ignore_rest_of_line ();
  6016. return;
  6017. }
  6018. /* It's a conditional. */
  6019. s_if (O_ne);
  6020. return;
  6021. }
  6022. /* Since this might be a conditional if, this pseudo-op will be
  6023. called even if we are supported to be ignoring input. Double
  6024. check now. Clobber *input_line_pointer so that ignore_input
  6025. thinks that this is not a special pseudo-op. */
  6026. c = *input_line_pointer;
  6027. *input_line_pointer = 0;
  6028. if (ignore_input ())
  6029. {
  6030. *input_line_pointer = c;
  6031. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6032. ++input_line_pointer;
  6033. demand_empty_rest_of_line ();
  6034. return;
  6035. }
  6036. *input_line_pointer = c;
  6037. n = push_mri_control (mri_if);
  6038. parse_mri_control_expression (s - 3, qual, (const char *) NULL,
  6039. n->next, s[1] == '.' ? s[2] : '\0');
  6040. if (s[1] == '.')
  6041. input_line_pointer = s + 3;
  6042. else
  6043. input_line_pointer = s + 1;
  6044. if (flag_mri)
  6045. {
  6046. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6047. ++input_line_pointer;
  6048. }
  6049. demand_empty_rest_of_line ();
  6050. }
  6051. /* Handle the MRI else pseudo-op. If we are currently doing an MRI
  6052. structured IF, associate the ELSE with the IF. Otherwise, assume
  6053. it is a conditional else. */
  6054. static void
  6055. s_mri_else (int qual)
  6056. {
  6057. int c;
  6058. char *buf;
  6059. char q[2];
  6060. if (qual == '\0'
  6061. && (mri_control_stack == NULL
  6062. || mri_control_stack->type != mri_if
  6063. || mri_control_stack->else_seen))
  6064. {
  6065. s_else (0);
  6066. return;
  6067. }
  6068. c = *input_line_pointer;
  6069. *input_line_pointer = 0;
  6070. if (ignore_input ())
  6071. {
  6072. *input_line_pointer = c;
  6073. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6074. ++input_line_pointer;
  6075. demand_empty_rest_of_line ();
  6076. return;
  6077. }
  6078. *input_line_pointer = c;
  6079. if (mri_control_stack == NULL
  6080. || mri_control_stack->type != mri_if
  6081. || mri_control_stack->else_seen)
  6082. {
  6083. as_bad (_("else without matching if"));
  6084. ignore_rest_of_line ();
  6085. return;
  6086. }
  6087. mri_control_stack->else_seen = 1;
  6088. buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
  6089. q[0] = TOLOWER (qual);
  6090. q[1] = '\0';
  6091. sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
  6092. mri_assemble (buf);
  6093. free (buf);
  6094. colon (mri_control_stack->next);
  6095. if (flag_mri)
  6096. {
  6097. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6098. ++input_line_pointer;
  6099. }
  6100. demand_empty_rest_of_line ();
  6101. }
  6102. /* Handle the MRI ENDI pseudo-op. */
  6103. static void
  6104. s_mri_endi (int ignore ATTRIBUTE_UNUSED)
  6105. {
  6106. if (mri_control_stack == NULL
  6107. || mri_control_stack->type != mri_if)
  6108. {
  6109. as_bad (_("endi without matching if"));
  6110. ignore_rest_of_line ();
  6111. return;
  6112. }
  6113. /* ignore_input will not return true for ENDI, so we don't need to
  6114. worry about checking it again here. */
  6115. if (! mri_control_stack->else_seen)
  6116. colon (mri_control_stack->next);
  6117. colon (mri_control_stack->bottom);
  6118. pop_mri_control ();
  6119. if (flag_mri)
  6120. {
  6121. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6122. ++input_line_pointer;
  6123. }
  6124. demand_empty_rest_of_line ();
  6125. }
  6126. /* Handle the MRI BREAK pseudo-op. */
  6127. static void
  6128. s_mri_break (int extent)
  6129. {
  6130. struct mri_control_info *n;
  6131. char *buf;
  6132. char ex[2];
  6133. n = mri_control_stack;
  6134. while (n != NULL
  6135. && n->type != mri_for
  6136. && n->type != mri_repeat
  6137. && n->type != mri_while)
  6138. n = n->outer;
  6139. if (n == NULL)
  6140. {
  6141. as_bad (_("break outside of structured loop"));
  6142. ignore_rest_of_line ();
  6143. return;
  6144. }
  6145. buf = (char *) xmalloc (20 + strlen (n->bottom));
  6146. ex[0] = TOLOWER (extent);
  6147. ex[1] = '\0';
  6148. sprintf (buf, "bra%s %s", ex, n->bottom);
  6149. mri_assemble (buf);
  6150. free (buf);
  6151. if (flag_mri)
  6152. {
  6153. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6154. ++input_line_pointer;
  6155. }
  6156. demand_empty_rest_of_line ();
  6157. }
  6158. /* Handle the MRI NEXT pseudo-op. */
  6159. static void
  6160. s_mri_next (int extent)
  6161. {
  6162. struct mri_control_info *n;
  6163. char *buf;
  6164. char ex[2];
  6165. n = mri_control_stack;
  6166. while (n != NULL
  6167. && n->type != mri_for
  6168. && n->type != mri_repeat
  6169. && n->type != mri_while)
  6170. n = n->outer;
  6171. if (n == NULL)
  6172. {
  6173. as_bad (_("next outside of structured loop"));
  6174. ignore_rest_of_line ();
  6175. return;
  6176. }
  6177. buf = (char *) xmalloc (20 + strlen (n->next));
  6178. ex[0] = TOLOWER (extent);
  6179. ex[1] = '\0';
  6180. sprintf (buf, "bra%s %s", ex, n->next);
  6181. mri_assemble (buf);
  6182. free (buf);
  6183. if (flag_mri)
  6184. {
  6185. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6186. ++input_line_pointer;
  6187. }
  6188. demand_empty_rest_of_line ();
  6189. }
  6190. /* Handle the MRI FOR pseudo-op. */
  6191. static void
  6192. s_mri_for (int qual)
  6193. {
  6194. const char *varstart, *varstop;
  6195. const char *initstart, *initstop;
  6196. const char *endstart, *endstop;
  6197. const char *bystart, *bystop;
  6198. int up;
  6199. int by;
  6200. int extent;
  6201. struct mri_control_info *n;
  6202. char *buf;
  6203. char *s;
  6204. char ex[2];
  6205. /* The syntax is
  6206. FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
  6207. */
  6208. SKIP_WHITESPACE ();
  6209. varstart = input_line_pointer;
  6210. /* Look for the '='. */
  6211. while (! is_end_of_line[(unsigned char) *input_line_pointer]
  6212. && *input_line_pointer != '=')
  6213. ++input_line_pointer;
  6214. if (*input_line_pointer != '=')
  6215. {
  6216. as_bad (_("missing ="));
  6217. ignore_rest_of_line ();
  6218. return;
  6219. }
  6220. varstop = input_line_pointer;
  6221. if (varstop > varstart
  6222. && (varstop[-1] == ' ' || varstop[-1] == '\t'))
  6223. --varstop;
  6224. ++input_line_pointer;
  6225. initstart = input_line_pointer;
  6226. /* Look for TO or DOWNTO. */
  6227. up = 1;
  6228. initstop = NULL;
  6229. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6230. {
  6231. if (strncasecmp (input_line_pointer, "TO", 2) == 0
  6232. && ! is_part_of_name (input_line_pointer[2]))
  6233. {
  6234. initstop = input_line_pointer;
  6235. input_line_pointer += 2;
  6236. break;
  6237. }
  6238. if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
  6239. && ! is_part_of_name (input_line_pointer[6]))
  6240. {
  6241. initstop = input_line_pointer;
  6242. up = 0;
  6243. input_line_pointer += 6;
  6244. break;
  6245. }
  6246. ++input_line_pointer;
  6247. }
  6248. if (initstop == NULL)
  6249. {
  6250. as_bad (_("missing to or downto"));
  6251. ignore_rest_of_line ();
  6252. return;
  6253. }
  6254. if (initstop > initstart
  6255. && (initstop[-1] == ' ' || initstop[-1] == '\t'))
  6256. --initstop;
  6257. SKIP_WHITESPACE ();
  6258. endstart = input_line_pointer;
  6259. /* Look for BY or DO. */
  6260. by = 0;
  6261. endstop = NULL;
  6262. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6263. {
  6264. if (strncasecmp (input_line_pointer, "BY", 2) == 0
  6265. && ! is_part_of_name (input_line_pointer[2]))
  6266. {
  6267. endstop = input_line_pointer;
  6268. by = 1;
  6269. input_line_pointer += 2;
  6270. break;
  6271. }
  6272. if (strncasecmp (input_line_pointer, "DO", 2) == 0
  6273. && (input_line_pointer[2] == '.'
  6274. || ! is_part_of_name (input_line_pointer[2])))
  6275. {
  6276. endstop = input_line_pointer;
  6277. input_line_pointer += 2;
  6278. break;
  6279. }
  6280. ++input_line_pointer;
  6281. }
  6282. if (endstop == NULL)
  6283. {
  6284. as_bad (_("missing do"));
  6285. ignore_rest_of_line ();
  6286. return;
  6287. }
  6288. if (endstop > endstart
  6289. && (endstop[-1] == ' ' || endstop[-1] == '\t'))
  6290. --endstop;
  6291. if (! by)
  6292. {
  6293. bystart = "#1";
  6294. bystop = bystart + 2;
  6295. }
  6296. else
  6297. {
  6298. SKIP_WHITESPACE ();
  6299. bystart = input_line_pointer;
  6300. /* Look for DO. */
  6301. bystop = NULL;
  6302. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6303. {
  6304. if (strncasecmp (input_line_pointer, "DO", 2) == 0
  6305. && (input_line_pointer[2] == '.'
  6306. || ! is_part_of_name (input_line_pointer[2])))
  6307. {
  6308. bystop = input_line_pointer;
  6309. input_line_pointer += 2;
  6310. break;
  6311. }
  6312. ++input_line_pointer;
  6313. }
  6314. if (bystop == NULL)
  6315. {
  6316. as_bad (_("missing do"));
  6317. ignore_rest_of_line ();
  6318. return;
  6319. }
  6320. if (bystop > bystart
  6321. && (bystop[-1] == ' ' || bystop[-1] == '\t'))
  6322. --bystop;
  6323. }
  6324. if (*input_line_pointer != '.')
  6325. extent = '\0';
  6326. else
  6327. {
  6328. extent = input_line_pointer[1];
  6329. input_line_pointer += 2;
  6330. }
  6331. /* We have fully parsed the FOR operands. Now build the loop. */
  6332. n = push_mri_control (mri_for);
  6333. buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
  6334. /* Move init,var. */
  6335. s = buf;
  6336. *s++ = 'm';
  6337. *s++ = 'o';
  6338. *s++ = 'v';
  6339. *s++ = 'e';
  6340. if (qual != '\0')
  6341. *s++ = TOLOWER (qual);
  6342. *s++ = ' ';
  6343. memcpy (s, initstart, initstop - initstart);
  6344. s += initstop - initstart;
  6345. *s++ = ',';
  6346. memcpy (s, varstart, varstop - varstart);
  6347. s += varstop - varstart;
  6348. *s = '\0';
  6349. mri_assemble (buf);
  6350. colon (n->top);
  6351. /* cmp end,var. */
  6352. s = buf;
  6353. *s++ = 'c';
  6354. *s++ = 'm';
  6355. *s++ = 'p';
  6356. if (qual != '\0')
  6357. *s++ = TOLOWER (qual);
  6358. *s++ = ' ';
  6359. memcpy (s, endstart, endstop - endstart);
  6360. s += endstop - endstart;
  6361. *s++ = ',';
  6362. memcpy (s, varstart, varstop - varstart);
  6363. s += varstop - varstart;
  6364. *s = '\0';
  6365. mri_assemble (buf);
  6366. /* bcc bottom. */
  6367. ex[0] = TOLOWER (extent);
  6368. ex[1] = '\0';
  6369. if (up)
  6370. sprintf (buf, "blt%s %s", ex, n->bottom);
  6371. else
  6372. sprintf (buf, "bgt%s %s", ex, n->bottom);
  6373. mri_assemble (buf);
  6374. /* Put together the add or sub instruction used by ENDF. */
  6375. s = buf;
  6376. if (up)
  6377. strcpy (s, "add");
  6378. else
  6379. strcpy (s, "sub");
  6380. s += 3;
  6381. if (qual != '\0')
  6382. *s++ = TOLOWER (qual);
  6383. *s++ = ' ';
  6384. memcpy (s, bystart, bystop - bystart);
  6385. s += bystop - bystart;
  6386. *s++ = ',';
  6387. memcpy (s, varstart, varstop - varstart);
  6388. s += varstop - varstart;
  6389. *s = '\0';
  6390. n->incr = buf;
  6391. if (flag_mri)
  6392. {
  6393. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6394. ++input_line_pointer;
  6395. }
  6396. demand_empty_rest_of_line ();
  6397. }
  6398. /* Handle the MRI ENDF pseudo-op. */
  6399. static void
  6400. s_mri_endf (int ignore ATTRIBUTE_UNUSED)
  6401. {
  6402. if (mri_control_stack == NULL
  6403. || mri_control_stack->type != mri_for)
  6404. {
  6405. as_bad (_("endf without for"));
  6406. ignore_rest_of_line ();
  6407. return;
  6408. }
  6409. colon (mri_control_stack->next);
  6410. mri_assemble (mri_control_stack->incr);
  6411. sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
  6412. mri_assemble (mri_control_stack->incr);
  6413. free (mri_control_stack->incr);
  6414. colon (mri_control_stack->bottom);
  6415. pop_mri_control ();
  6416. if (flag_mri)
  6417. {
  6418. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6419. ++input_line_pointer;
  6420. }
  6421. demand_empty_rest_of_line ();
  6422. }
  6423. /* Handle the MRI REPEAT pseudo-op. */
  6424. static void
  6425. s_mri_repeat (int ignore ATTRIBUTE_UNUSED)
  6426. {
  6427. struct mri_control_info *n;
  6428. n = push_mri_control (mri_repeat);
  6429. colon (n->top);
  6430. if (flag_mri)
  6431. {
  6432. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6433. ++input_line_pointer;
  6434. }
  6435. demand_empty_rest_of_line ();
  6436. }
  6437. /* Handle the MRI UNTIL pseudo-op. */
  6438. static void
  6439. s_mri_until (int qual)
  6440. {
  6441. char *s;
  6442. if (mri_control_stack == NULL
  6443. || mri_control_stack->type != mri_repeat)
  6444. {
  6445. as_bad (_("until without repeat"));
  6446. ignore_rest_of_line ();
  6447. return;
  6448. }
  6449. colon (mri_control_stack->next);
  6450. for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
  6451. ;
  6452. parse_mri_control_expression (s, qual, (const char *) NULL,
  6453. mri_control_stack->top, '\0');
  6454. colon (mri_control_stack->bottom);
  6455. input_line_pointer = s;
  6456. pop_mri_control ();
  6457. if (flag_mri)
  6458. {
  6459. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6460. ++input_line_pointer;
  6461. }
  6462. demand_empty_rest_of_line ();
  6463. }
  6464. /* Handle the MRI WHILE pseudo-op. */
  6465. static void
  6466. s_mri_while (int qual)
  6467. {
  6468. char *s;
  6469. struct mri_control_info *n;
  6470. s = input_line_pointer;
  6471. /* We only accept '*' as introduction of comments if preceded by white space
  6472. or at first column of a line (I think this can't actually happen here?)
  6473. This is important when assembling:
  6474. while d0 <ne> 12(a0,d0*2) do
  6475. while d0 <ne> #CONST*20 do. */
  6476. while (! (is_end_of_line[(unsigned char) *s]
  6477. || (flag_mri
  6478. && *s == '*'
  6479. && (s == input_line_pointer
  6480. || *(s-1) == ' '
  6481. || *(s-1) == '\t'))))
  6482. s++;
  6483. --s;
  6484. while (*s == ' ' || *s == '\t')
  6485. --s;
  6486. if (s - input_line_pointer > 1
  6487. && s[-1] == '.')
  6488. s -= 2;
  6489. if (s - input_line_pointer < 2
  6490. || strncasecmp (s - 1, "DO", 2) != 0)
  6491. {
  6492. as_bad (_("missing do"));
  6493. ignore_rest_of_line ();
  6494. return;
  6495. }
  6496. n = push_mri_control (mri_while);
  6497. colon (n->next);
  6498. parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
  6499. s[1] == '.' ? s[2] : '\0');
  6500. input_line_pointer = s + 1;
  6501. if (*input_line_pointer == '.')
  6502. input_line_pointer += 2;
  6503. if (flag_mri)
  6504. {
  6505. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6506. ++input_line_pointer;
  6507. }
  6508. demand_empty_rest_of_line ();
  6509. }
  6510. /* Handle the MRI ENDW pseudo-op. */
  6511. static void
  6512. s_mri_endw (int ignore ATTRIBUTE_UNUSED)
  6513. {
  6514. char *buf;
  6515. if (mri_control_stack == NULL
  6516. || mri_control_stack->type != mri_while)
  6517. {
  6518. as_bad (_("endw without while"));
  6519. ignore_rest_of_line ();
  6520. return;
  6521. }
  6522. buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
  6523. sprintf (buf, "bra %s", mri_control_stack->next);
  6524. mri_assemble (buf);
  6525. free (buf);
  6526. colon (mri_control_stack->bottom);
  6527. pop_mri_control ();
  6528. if (flag_mri)
  6529. {
  6530. while (! is_end_of_line[(unsigned char) *input_line_pointer])
  6531. ++input_line_pointer;
  6532. }
  6533. demand_empty_rest_of_line ();
  6534. }
  6535. /* Parse a .cpu directive. */
  6536. static void
  6537. s_m68k_cpu (int ignored ATTRIBUTE_UNUSED)
  6538. {
  6539. char saved_char;
  6540. char *name;
  6541. if (initialized)
  6542. {
  6543. as_bad (_("already assembled instructions"));
  6544. ignore_rest_of_line ();
  6545. return;
  6546. }
  6547. name = input_line_pointer;
  6548. while (*input_line_pointer && !ISSPACE(*input_line_pointer))
  6549. input_line_pointer++;
  6550. saved_char = *input_line_pointer;
  6551. *input_line_pointer = 0;
  6552. m68k_set_cpu (name, 1, 0);
  6553. *input_line_pointer = saved_char;
  6554. demand_empty_rest_of_line ();
  6555. return;
  6556. }
  6557. /* Parse a .arch directive. */
  6558. static void
  6559. s_m68k_arch (int ignored ATTRIBUTE_UNUSED)
  6560. {
  6561. char saved_char;
  6562. char *name;
  6563. if (initialized)
  6564. {
  6565. as_bad (_("already assembled instructions"));
  6566. ignore_rest_of_line ();
  6567. return;
  6568. }
  6569. name = input_line_pointer;
  6570. while (*input_line_pointer && *input_line_pointer != ','
  6571. && !ISSPACE (*input_line_pointer))
  6572. input_line_pointer++;
  6573. saved_char = *input_line_pointer;
  6574. *input_line_pointer = 0;
  6575. if (m68k_set_arch (name, 1, 0))
  6576. {
  6577. /* Scan extensions. */
  6578. do
  6579. {
  6580. *input_line_pointer++ = saved_char;
  6581. if (!*input_line_pointer || ISSPACE (*input_line_pointer))
  6582. break;
  6583. name = input_line_pointer;
  6584. while (*input_line_pointer && *input_line_pointer != ','
  6585. && !ISSPACE (*input_line_pointer))
  6586. input_line_pointer++;
  6587. saved_char = *input_line_pointer;
  6588. *input_line_pointer = 0;
  6589. }
  6590. while (m68k_set_extension (name, 1, 0));
  6591. }
  6592. *input_line_pointer = saved_char;
  6593. demand_empty_rest_of_line ();
  6594. return;
  6595. }
  6596. /* Lookup a cpu name in TABLE and return the slot found. Return NULL
  6597. if none is found, the caller is responsible for emitting an error
  6598. message. If ALLOW_M is non-zero, we allow an initial 'm' on the
  6599. cpu name, if it begins with a '6' (possibly skipping an intervening
  6600. 'c'. We also allow a 'c' in the same place. if NEGATED is
  6601. non-zero, we accept a leading 'no-' and *NEGATED is set to true, if
  6602. the option is indeed negated. */
  6603. static const struct m68k_cpu *
  6604. m68k_lookup_cpu (const char *arg, const struct m68k_cpu *table,
  6605. int allow_m, int *negated)
  6606. {
  6607. /* allow negated value? */
  6608. if (negated)
  6609. {
  6610. *negated = 0;
  6611. if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
  6612. {
  6613. arg += 3;
  6614. *negated = 1;
  6615. }
  6616. }
  6617. /* Remove 'm' or 'mc' prefix from 68k variants. */
  6618. if (allow_m)
  6619. {
  6620. if (arg[0] == 'm')
  6621. {
  6622. if (arg[1] == '6')
  6623. arg += 1;
  6624. else if (arg[1] == 'c' && arg[2] == '6')
  6625. arg += 2;
  6626. }
  6627. }
  6628. else if (arg[0] == 'c' && arg[1] == '6')
  6629. arg += 1;
  6630. for (; table->name; table++)
  6631. if (!strcmp (arg, table->name))
  6632. {
  6633. if (table->alias < -1 || table->alias > 1)
  6634. as_bad (_("`%s' is deprecated, use `%s'"),
  6635. table->name, table[table->alias < 0 ? 1 : -1].name);
  6636. return table;
  6637. }
  6638. return 0;
  6639. }
  6640. /* Set the cpu, issuing errors if it is unrecognized. */
  6641. static int
  6642. m68k_set_cpu (char const *name, int allow_m, int silent)
  6643. {
  6644. const struct m68k_cpu *cpu;
  6645. cpu = m68k_lookup_cpu (name, m68k_cpus, allow_m, NULL);
  6646. if (!cpu)
  6647. {
  6648. if (!silent)
  6649. as_bad (_("cpu `%s' unrecognized"), name);
  6650. return 0;
  6651. }
  6652. selected_cpu = cpu;
  6653. return 1;
  6654. }
  6655. /* Set the architecture, issuing errors if it is unrecognized. */
  6656. static int
  6657. m68k_set_arch (char const *name, int allow_m, int silent)
  6658. {
  6659. const struct m68k_cpu *arch;
  6660. arch = m68k_lookup_cpu (name, m68k_archs, allow_m, NULL);
  6661. if (!arch)
  6662. {
  6663. if (!silent)
  6664. as_bad (_("architecture `%s' unrecognized"), name);
  6665. return 0;
  6666. }
  6667. selected_arch = arch;
  6668. return 1;
  6669. }
  6670. /* Set the architecture extension, issuing errors if it is
  6671. unrecognized, or invalid */
  6672. static int
  6673. m68k_set_extension (char const *name, int allow_m, int silent)
  6674. {
  6675. int negated;
  6676. const struct m68k_cpu *ext;
  6677. ext = m68k_lookup_cpu (name, m68k_extensions, allow_m, &negated);
  6678. if (!ext)
  6679. {
  6680. if (!silent)
  6681. as_bad (_("extension `%s' unrecognized"), name);
  6682. return 0;
  6683. }
  6684. if (negated)
  6685. not_current_architecture |= (ext->control_regs
  6686. ? *(unsigned *)ext->control_regs: ext->arch);
  6687. else
  6688. current_architecture |= ext->arch;
  6689. return 1;
  6690. }
  6691. /* md_parse_option
  6692. Invocation line includes a switch not recognized by the base assembler.
  6693. */
  6694. #ifdef OBJ_ELF
  6695. const char *md_shortopts = "lSA:m:kQ:V";
  6696. #else
  6697. const char *md_shortopts = "lSA:m:k";
  6698. #endif
  6699. struct option md_longopts[] = {
  6700. #define OPTION_PIC (OPTION_MD_BASE)
  6701. {"pic", no_argument, NULL, OPTION_PIC},
  6702. #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
  6703. {"register-prefix-optional", no_argument, NULL,
  6704. OPTION_REGISTER_PREFIX_OPTIONAL},
  6705. #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
  6706. {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
  6707. #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
  6708. {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
  6709. #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
  6710. {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
  6711. #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
  6712. {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
  6713. #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
  6714. {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
  6715. #define OPTION_PCREL (OPTION_MD_BASE + 7)
  6716. {"pcrel", no_argument, NULL, OPTION_PCREL},
  6717. {NULL, no_argument, NULL, 0}
  6718. };
  6719. size_t md_longopts_size = sizeof (md_longopts);
  6720. int
  6721. md_parse_option (int c, char *arg)
  6722. {
  6723. switch (c)
  6724. {
  6725. case 'l': /* -l means keep external to 2 bit offset
  6726. rather than 16 bit one. */
  6727. flag_short_refs = 1;
  6728. break;
  6729. case 'S': /* -S means that jbsr's always turn into
  6730. jsr's. */
  6731. flag_long_jumps = 1;
  6732. break;
  6733. case OPTION_PCREL: /* --pcrel means never turn PC-relative
  6734. branches into absolute jumps. */
  6735. flag_keep_pcrel = 1;
  6736. break;
  6737. case OPTION_PIC:
  6738. case 'k':
  6739. flag_want_pic = 1;
  6740. break; /* -pic, Position Independent Code. */
  6741. case OPTION_REGISTER_PREFIX_OPTIONAL:
  6742. flag_reg_prefix_optional = 1;
  6743. reg_prefix_optional_seen = 1;
  6744. break;
  6745. /* -V: SVR4 argument to print version ID. */
  6746. case 'V':
  6747. print_version_id ();
  6748. break;
  6749. /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
  6750. should be emitted or not. FIXME: Not implemented. */
  6751. case 'Q':
  6752. break;
  6753. case OPTION_BITWISE_OR:
  6754. {
  6755. char *n, *t;
  6756. const char *s;
  6757. n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
  6758. t = n;
  6759. for (s = m68k_comment_chars; *s != '\0'; s++)
  6760. if (*s != '|')
  6761. *t++ = *s;
  6762. *t = '\0';
  6763. m68k_comment_chars = n;
  6764. }
  6765. break;
  6766. case OPTION_BASE_SIZE_DEFAULT_16:
  6767. m68k_index_width_default = SIZE_WORD;
  6768. break;
  6769. case OPTION_BASE_SIZE_DEFAULT_32:
  6770. m68k_index_width_default = SIZE_LONG;
  6771. break;
  6772. case OPTION_DISP_SIZE_DEFAULT_16:
  6773. m68k_rel32 = 0;
  6774. m68k_rel32_from_cmdline = 1;
  6775. break;
  6776. case OPTION_DISP_SIZE_DEFAULT_32:
  6777. m68k_rel32 = 1;
  6778. m68k_rel32_from_cmdline = 1;
  6779. break;
  6780. case 'A':
  6781. #if WARN_DEPRECATED
  6782. as_tsktsk (_ ("option `-A%s' is deprecated: use `-%s'",
  6783. arg, arg));
  6784. #endif
  6785. /* Intentional fall-through. */
  6786. case 'm':
  6787. if (!strncmp (arg, "arch=", 5))
  6788. m68k_set_arch (arg + 5, 1, 0);
  6789. else if (!strncmp (arg, "cpu=", 4))
  6790. m68k_set_cpu (arg + 4, 1, 0);
  6791. else if (m68k_set_extension (arg, 0, 1))
  6792. ;
  6793. else if (m68k_set_arch (arg, 0, 1))
  6794. ;
  6795. else if (m68k_set_cpu (arg, 0, 1))
  6796. ;
  6797. else
  6798. return 0;
  6799. break;
  6800. default:
  6801. return 0;
  6802. }
  6803. return 1;
  6804. }
  6805. /* Setup tables from the selected arch and/or cpu */
  6806. static void
  6807. m68k_init_arch (void)
  6808. {
  6809. if (not_current_architecture & current_architecture)
  6810. {
  6811. as_bad (_("architecture features both enabled and disabled"));
  6812. not_current_architecture &= ~current_architecture;
  6813. }
  6814. if (selected_arch)
  6815. {
  6816. current_architecture |= selected_arch->arch;
  6817. control_regs = selected_arch->control_regs;
  6818. }
  6819. else
  6820. current_architecture |= selected_cpu->arch;
  6821. current_architecture &= ~not_current_architecture;
  6822. if ((current_architecture & (cfloat | m68881)) == (cfloat | m68881))
  6823. {
  6824. /* Determine which float is really meant. */
  6825. if (current_architecture & (m68k_mask & ~m68881))
  6826. current_architecture ^= cfloat;
  6827. else
  6828. current_architecture ^= m68881;
  6829. }
  6830. if (selected_cpu)
  6831. {
  6832. control_regs = selected_cpu->control_regs;
  6833. if (current_architecture & ~selected_cpu->arch)
  6834. {
  6835. as_bad (_("selected processor does not have all features of selected architecture"));
  6836. current_architecture
  6837. = selected_cpu->arch & ~not_current_architecture;
  6838. }
  6839. }
  6840. if ((current_architecture & m68k_mask)
  6841. && (current_architecture & ~m68k_mask))
  6842. {
  6843. as_bad (_ ("m68k and cf features both selected"));
  6844. if (current_architecture & m68k_mask)
  6845. current_architecture &= m68k_mask;
  6846. else
  6847. current_architecture &= ~m68k_mask;
  6848. }
  6849. /* Permit m68881 specification with all cpus; those that can't work
  6850. with a coprocessor could be doing emulation. */
  6851. if (current_architecture & m68851)
  6852. {
  6853. if (current_architecture & m68040)
  6854. as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
  6855. }
  6856. /* What other incompatibilities could we check for? */
  6857. if (cpu_of_arch (current_architecture) < m68020
  6858. || arch_coldfire_p (current_architecture))
  6859. md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
  6860. initialized = 1;
  6861. }
  6862. void
  6863. md_show_usage (FILE *stream)
  6864. {
  6865. const char *default_cpu = TARGET_CPU;
  6866. int i;
  6867. /* Get the canonical name for the default target CPU. */
  6868. if (*default_cpu == 'm')
  6869. default_cpu++;
  6870. for (i = 0; m68k_cpus[i].name; i++)
  6871. {
  6872. if (strcasecmp (default_cpu, m68k_cpus[i].name) == 0)
  6873. {
  6874. while (m68k_cpus[i].alias > 0)
  6875. i--;
  6876. while (m68k_cpus[i].alias < 0)
  6877. i++;
  6878. default_cpu = m68k_cpus[i].name;
  6879. }
  6880. }
  6881. fprintf (stream, _("\
  6882. -march=<arch> set architecture\n\
  6883. -mcpu=<cpu> set cpu [default %s]\n\
  6884. "), default_cpu);
  6885. for (i = 0; m68k_extensions[i].name; i++)
  6886. fprintf (stream, _("\
  6887. -m[no-]%-16s enable/disable%s architecture extension\n\
  6888. "), m68k_extensions[i].name,
  6889. m68k_extensions[i].alias > 0 ? " ColdFire"
  6890. : m68k_extensions[i].alias < 0 ? " m68k" : "");
  6891. fprintf (stream, _("\
  6892. -l use 1 word for refs to undefined symbols [default 2]\n\
  6893. -pic, -k generate position independent code\n\
  6894. -S turn jbsr into jsr\n\
  6895. --pcrel never turn PC-relative branches into absolute jumps\n\
  6896. --register-prefix-optional\n\
  6897. recognize register names without prefix character\n\
  6898. --bitwise-or do not treat `|' as a comment character\n\
  6899. --base-size-default-16 base reg without size is 16 bits\n\
  6900. --base-size-default-32 base reg without size is 32 bits (default)\n\
  6901. --disp-size-default-16 displacement with unknown size is 16 bits\n\
  6902. --disp-size-default-32 displacement with unknown size is 32 bits (default)\n\
  6903. "));
  6904. fprintf (stream, _("Architecture variants are: "));
  6905. for (i = 0; m68k_archs[i].name; i++)
  6906. {
  6907. if (i)
  6908. fprintf (stream, " | ");
  6909. fprintf (stream, "%s", m68k_archs[i].name);
  6910. }
  6911. fprintf (stream, "\n");
  6912. fprintf (stream, _("Processor variants are: "));
  6913. for (i = 0; m68k_cpus[i].name; i++)
  6914. {
  6915. if (i)
  6916. fprintf (stream, " | ");
  6917. fprintf (stream, "%s", m68k_cpus[i].name);
  6918. }
  6919. fprintf (stream, _("\n"));
  6920. }
  6921. #ifdef TEST2
  6922. /* TEST2: Test md_assemble() */
  6923. /* Warning, this routine probably doesn't work anymore. */
  6924. int
  6925. main (void)
  6926. {
  6927. struct m68k_it the_ins;
  6928. char buf[120];
  6929. char *cp;
  6930. int n;
  6931. m68k_ip_begin ();
  6932. for (;;)
  6933. {
  6934. if (!gets (buf) || !*buf)
  6935. break;
  6936. if (buf[0] == '|' || buf[1] == '.')
  6937. continue;
  6938. for (cp = buf; *cp; cp++)
  6939. if (*cp == '\t')
  6940. *cp = ' ';
  6941. if (is_label (buf))
  6942. continue;
  6943. memset (&the_ins, '\0', sizeof (the_ins));
  6944. m68k_ip (&the_ins, buf);
  6945. if (the_ins.error)
  6946. {
  6947. printf (_("Error %s in %s\n"), the_ins.error, buf);
  6948. }
  6949. else
  6950. {
  6951. printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
  6952. for (n = 0; n < the_ins.numo; n++)
  6953. printf (" 0x%x", the_ins.opcode[n] & 0xffff);
  6954. printf (" ");
  6955. print_the_insn (&the_ins.opcode[0], stdout);
  6956. (void) putchar ('\n');
  6957. }
  6958. for (n = 0; n < strlen (the_ins.args) / 2; n++)
  6959. {
  6960. if (the_ins.operands[n].error)
  6961. {
  6962. printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
  6963. continue;
  6964. }
  6965. printf ("mode %d, reg %d, ", the_ins.operands[n].mode,
  6966. the_ins.operands[n].reg);
  6967. if (the_ins.operands[n].b_const)
  6968. printf ("Constant: '%.*s', ",
  6969. 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const,
  6970. the_ins.operands[n].b_const);
  6971. printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg,
  6972. the_ins.operands[n].isiz, the_ins.operands[n].imul);
  6973. if (the_ins.operands[n].b_iadd)
  6974. printf ("Iadd: '%.*s',",
  6975. 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd,
  6976. the_ins.operands[n].b_iadd);
  6977. putchar ('\n');
  6978. }
  6979. }
  6980. m68k_ip_end ();
  6981. return 0;
  6982. }
  6983. int
  6984. is_label (char *str)
  6985. {
  6986. while (*str == ' ')
  6987. str++;
  6988. while (*str && *str != ' ')
  6989. str++;
  6990. if (str[-1] == ':' || str[1] == '=')
  6991. return 1;
  6992. return 0;
  6993. }
  6994. #endif
  6995. /* Possible states for relaxation:
  6996. 0 0 branch offset byte (bra, etc)
  6997. 0 1 word
  6998. 0 2 long
  6999. 1 0 indexed offsets byte a0@(32,d4:w:1) etc
  7000. 1 1 word
  7001. 1 2 long
  7002. 2 0 two-offset index word-word a0@(32,d4)@(45) etc
  7003. 2 1 word-long
  7004. 2 2 long-word
  7005. 2 3 long-long
  7006. */
  7007. /* We have no need to default values of symbols. */
  7008. symbolS *
  7009. md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
  7010. {
  7011. return 0;
  7012. }
  7013. /* Round up a section size to the appropriate boundary. */
  7014. valueT
  7015. md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
  7016. {
  7017. #ifdef OBJ_AOUT
  7018. /* For a.out, force the section size to be aligned. If we don't do
  7019. this, BFD will align it for us, but it will not write out the
  7020. final bytes of the section. This may be a bug in BFD, but it is
  7021. easier to fix it here since that is how the other a.out targets
  7022. work. */
  7023. int align;
  7024. align = bfd_get_section_alignment (stdoutput, segment);
  7025. size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
  7026. #endif
  7027. return size;
  7028. }
  7029. /* Exactly what point is a PC-relative offset relative TO?
  7030. On the 68k, it is relative to the address of the first extension
  7031. word. The difference between the addresses of the offset and the
  7032. first extension word is stored in fx_pcrel_adjust. */
  7033. long
  7034. md_pcrel_from (fixS *fixP)
  7035. {
  7036. int adjust;
  7037. adjust = fixP->fx_pcrel_adjust;
  7038. if (adjust == 64)
  7039. adjust = -1;
  7040. return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
  7041. }
  7042. #ifdef OBJ_ELF
  7043. void
  7044. m68k_elf_final_processing (void)
  7045. {
  7046. unsigned flags = 0;
  7047. if (arch_coldfire_fpu (current_architecture))
  7048. flags |= EF_M68K_CFV4E;
  7049. /* Set file-specific flags if this is a cpu32 processor. */
  7050. if (cpu_of_arch (current_architecture) & cpu32)
  7051. flags |= EF_M68K_CPU32;
  7052. else if (cpu_of_arch (current_architecture) & fido_a)
  7053. flags |= EF_M68K_FIDO;
  7054. else if ((cpu_of_arch (current_architecture) & m68000up)
  7055. && !(cpu_of_arch (current_architecture) & m68020up))
  7056. flags |= EF_M68K_M68000;
  7057. if (current_architecture & mcfisa_a)
  7058. {
  7059. static const unsigned isa_features[][2] =
  7060. {
  7061. {EF_M68K_CF_ISA_A_NODIV,mcfisa_a},
  7062. {EF_M68K_CF_ISA_A, mcfisa_a|mcfhwdiv},
  7063. {EF_M68K_CF_ISA_A_PLUS, mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp},
  7064. {EF_M68K_CF_ISA_B_NOUSP,mcfisa_a|mcfisa_b|mcfhwdiv},
  7065. {EF_M68K_CF_ISA_B, mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp},
  7066. {EF_M68K_CF_ISA_C, mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp},
  7067. {EF_M68K_CF_ISA_C_NODIV,mcfisa_a|mcfisa_c|mcfusp},
  7068. {0,0},
  7069. };
  7070. static const unsigned mac_features[][2] =
  7071. {
  7072. {EF_M68K_CF_MAC, mcfmac},
  7073. {EF_M68K_CF_EMAC, mcfemac},
  7074. {0,0},
  7075. };
  7076. unsigned ix;
  7077. unsigned pattern;
  7078. pattern = (current_architecture
  7079. & (mcfisa_a|mcfisa_aa|mcfisa_b|mcfisa_c|mcfhwdiv|mcfusp));
  7080. for (ix = 0; isa_features[ix][1]; ix++)
  7081. {
  7082. if (pattern == isa_features[ix][1])
  7083. {
  7084. flags |= isa_features[ix][0];
  7085. break;
  7086. }
  7087. }
  7088. if (!isa_features[ix][1])
  7089. {
  7090. cf_bad:
  7091. as_warn (_("Not a defined coldfire architecture"));
  7092. }
  7093. else
  7094. {
  7095. if (current_architecture & cfloat)
  7096. flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
  7097. pattern = current_architecture & (mcfmac|mcfemac);
  7098. if (pattern)
  7099. {
  7100. for (ix = 0; mac_features[ix][1]; ix++)
  7101. {
  7102. if (pattern == mac_features[ix][1])
  7103. {
  7104. flags |= mac_features[ix][0];
  7105. break;
  7106. }
  7107. }
  7108. if (!mac_features[ix][1])
  7109. goto cf_bad;
  7110. }
  7111. }
  7112. }
  7113. elf_elfheader (stdoutput)->e_flags |= flags;
  7114. }
  7115. /* Parse @TLSLDO and return the desired relocation. */
  7116. static bfd_reloc_code_real_type
  7117. m68k_elf_suffix (char **str_p, expressionS *exp_p)
  7118. {
  7119. char ident[20];
  7120. char *str = *str_p;
  7121. char *str2;
  7122. int ch;
  7123. int len;
  7124. if (*str++ != '@')
  7125. return BFD_RELOC_UNUSED;
  7126. for (ch = *str, str2 = ident;
  7127. (str2 < ident + sizeof (ident) - 1
  7128. && (ISALNUM (ch) || ch == '@'));
  7129. ch = *++str)
  7130. {
  7131. *str2++ = ch;
  7132. }
  7133. *str2 = '\0';
  7134. len = str2 - ident;
  7135. if (strncmp (ident, "TLSLDO", 6) == 0
  7136. && len == 6)
  7137. {
  7138. /* Now check for identifier@suffix+constant. */
  7139. if (*str == '-' || *str == '+')
  7140. {
  7141. char *orig_line = input_line_pointer;
  7142. expressionS new_exp;
  7143. input_line_pointer = str;
  7144. expression (&new_exp);
  7145. if (new_exp.X_op == O_constant)
  7146. {
  7147. exp_p->X_add_number += new_exp.X_add_number;
  7148. str = input_line_pointer;
  7149. }
  7150. if (&input_line_pointer != str_p)
  7151. input_line_pointer = orig_line;
  7152. }
  7153. *str_p = str;
  7154. return BFD_RELOC_68K_TLS_LDO32;
  7155. }
  7156. return BFD_RELOC_UNUSED;
  7157. }
  7158. /* Handles .long <tls_symbol>+0x8000 debug info.
  7159. Clobbers input_line_pointer, checks end-of-line.
  7160. Adapted from tc-ppc.c:ppc_elf_cons. */
  7161. static void
  7162. m68k_elf_cons (int nbytes /* 4=.long */)
  7163. {
  7164. if (is_it_end_of_statement ())
  7165. {
  7166. demand_empty_rest_of_line ();
  7167. return;
  7168. }
  7169. do
  7170. {
  7171. expressionS exp;
  7172. bfd_reloc_code_real_type reloc;
  7173. expression (&exp);
  7174. if (exp.X_op == O_symbol
  7175. && *input_line_pointer == '@'
  7176. && (reloc = m68k_elf_suffix (&input_line_pointer,
  7177. &exp)) != BFD_RELOC_UNUSED)
  7178. {
  7179. reloc_howto_type *reloc_howto;
  7180. int size;
  7181. reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
  7182. size = bfd_get_reloc_size (reloc_howto);
  7183. if (size > nbytes)
  7184. {
  7185. as_bad (_("%s relocations do not fit in %d bytes\n"),
  7186. reloc_howto->name, nbytes);
  7187. }
  7188. else
  7189. {
  7190. char *p;
  7191. int offset;
  7192. p = frag_more (nbytes);
  7193. offset = 0;
  7194. if (target_big_endian)
  7195. offset = nbytes - size;
  7196. fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
  7197. &exp, 0, reloc);
  7198. }
  7199. }
  7200. else
  7201. emit_expr (&exp, (unsigned int) nbytes);
  7202. }
  7203. while (*input_line_pointer++ == ',');
  7204. /* Put terminator back into stream. */
  7205. input_line_pointer--;
  7206. demand_empty_rest_of_line ();
  7207. }
  7208. #endif
  7209. int
  7210. tc_m68k_regname_to_dw2regnum (char *regname)
  7211. {
  7212. unsigned int regnum;
  7213. static const char *const regnames[] =
  7214. {
  7215. "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
  7216. "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
  7217. "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
  7218. "pc"
  7219. };
  7220. for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
  7221. if (strcmp (regname, regnames[regnum]) == 0)
  7222. return regnum;
  7223. return -1;
  7224. }
  7225. void
  7226. tc_m68k_frame_initial_instructions (void)
  7227. {
  7228. static int sp_regno = -1;
  7229. if (sp_regno < 0)
  7230. sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
  7231. cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
  7232. cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);
  7233. }
  7234. /* Check and emit error if broken-word handling has failed to fix up a
  7235. case-table. This is called from write.c, after doing everything it
  7236. knows about how to handle broken words. */
  7237. void
  7238. tc_m68k_check_adjusted_broken_word (offsetT new_offset, struct broken_word *brokwP)
  7239. {
  7240. if (new_offset > 32767 || new_offset < -32768)
  7241. as_bad_where (brokwP->frag->fr_file, brokwP->frag->fr_line,
  7242. _("Adjusted signed .word (%#lx) overflows: `switch'-statement too large."),
  7243. (long) new_offset);
  7244. }