read.c 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179
  1. /* read.c - read a source file -
  2. Copyright (C) 1986-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. /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
  17. But then, GNU isn't spozed to run on your machine anyway.
  18. (RMS is so shortsighted sometimes.) */
  19. #define MASK_CHAR ((int)(unsigned char) -1)
  20. /* This is the largest known floating point format (for now). It will
  21. grow when we do 4361 style flonums. */
  22. #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
  23. /* Routines that read assembler source text to build spaghetti in memory.
  24. Another group of these functions is in the expr.c module. */
  25. #include "as.h"
  26. #include "safe-ctype.h"
  27. #include "subsegs.h"
  28. #include "sb.h"
  29. #include "macro.h"
  30. #include "obstack.h"
  31. #include "ecoff.h"
  32. #include "dw2gencfi.h"
  33. #include "wchar.h"
  34. #ifndef TC_START_LABEL
  35. #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':')
  36. #endif
  37. /* Set by the object-format or the target. */
  38. #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
  39. #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
  40. do \
  41. { \
  42. if ((SIZE) >= 8) \
  43. (P2VAR) = 3; \
  44. else if ((SIZE) >= 4) \
  45. (P2VAR) = 2; \
  46. else if ((SIZE) >= 2) \
  47. (P2VAR) = 1; \
  48. else \
  49. (P2VAR) = 0; \
  50. } \
  51. while (0)
  52. #endif
  53. char *input_line_pointer; /*->next char of source file to parse. */
  54. #if BITS_PER_CHAR != 8
  55. /* The following table is indexed by[(char)] and will break if
  56. a char does not have exactly 256 states (hopefully 0:255!)! */
  57. die horribly;
  58. #endif
  59. #ifndef LEX_AT
  60. #define LEX_AT 0
  61. #endif
  62. #ifndef LEX_BR
  63. /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
  64. #define LEX_BR 0
  65. #endif
  66. #ifndef LEX_PCT
  67. /* The Delta 68k assembler permits % inside label names. */
  68. #define LEX_PCT 0
  69. #endif
  70. #ifndef LEX_QM
  71. /* The PowerPC Windows NT assemblers permits ? inside label names. */
  72. #define LEX_QM 0
  73. #endif
  74. #ifndef LEX_HASH
  75. /* The IA-64 assembler uses # as a suffix designating a symbol. We include
  76. it in the symbol and strip it out in tc_canonicalize_symbol_name. */
  77. #define LEX_HASH 0
  78. #endif
  79. #ifndef LEX_DOLLAR
  80. #define LEX_DOLLAR 3
  81. #endif
  82. #ifndef LEX_TILDE
  83. /* The Delta 68k assembler permits ~ at start of label names. */
  84. #define LEX_TILDE 0
  85. #endif
  86. /* Used by is_... macros. our ctype[]. */
  87. char lex_type[256] = {
  88. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
  89. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
  90. 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
  91. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
  92. LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
  93. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
  94. 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
  95. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
  96. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  97. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  98. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  99. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  100. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  101. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  102. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  103. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
  104. };
  105. /* In: a character.
  106. Out: 1 if this character ends a line.
  107. 2 if this character is a line separator. */
  108. char is_end_of_line[256] = {
  109. #ifdef CR_EOL
  110. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
  111. #else
  112. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
  113. #endif
  114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
  116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
  117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
  128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
  129. };
  130. #ifndef TC_CASE_SENSITIVE
  131. char original_case_string[128];
  132. #endif
  133. /* Functions private to this file. */
  134. static char *buffer; /* 1st char of each buffer of lines is here. */
  135. static char *buffer_limit; /*->1 + last char in buffer. */
  136. /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
  137. in the tc-<CPU>.h file. See the "Porting GAS" section of the
  138. internals manual. */
  139. int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
  140. /* Variables for handling include file directory table. */
  141. /* Table of pointers to directories to search for .include's. */
  142. char **include_dirs;
  143. /* How many are in the table. */
  144. int include_dir_count;
  145. /* Length of longest in table. */
  146. int include_dir_maxlen = 1;
  147. #ifndef WORKING_DOT_WORD
  148. struct broken_word *broken_words;
  149. int new_broken_words;
  150. #endif
  151. /* The current offset into the absolute section. We don't try to
  152. build frags in the absolute section, since no data can be stored
  153. there. We just keep track of the current offset. */
  154. addressT abs_section_offset;
  155. /* If this line had an MRI style label, it is stored in this variable.
  156. This is used by some of the MRI pseudo-ops. */
  157. symbolS *line_label;
  158. /* This global variable is used to support MRI common sections. We
  159. translate such sections into a common symbol. This variable is
  160. non-NULL when we are in an MRI common section. */
  161. symbolS *mri_common_symbol;
  162. /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
  163. need to align to an even byte boundary unless the next pseudo-op is
  164. dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
  165. may be needed. */
  166. static int mri_pending_align;
  167. #ifndef NO_LISTING
  168. #ifdef OBJ_ELF
  169. /* This variable is set to be non-zero if the next string we see might
  170. be the name of the source file in DWARF debugging information. See
  171. the comment in emit_expr for the format we look for. */
  172. static int dwarf_file_string;
  173. #endif
  174. #endif
  175. /* If the target defines the md_frag_max_var hook then we know
  176. enough to implement the .bundle_align_mode features. */
  177. #ifdef md_frag_max_var
  178. # define HANDLE_BUNDLE
  179. #endif
  180. #ifdef HANDLE_BUNDLE
  181. /* .bundle_align_mode sets this. Normally it's zero. When nonzero,
  182. it's the exponent of the bundle size, and aligned instruction bundle
  183. mode is in effect. */
  184. static unsigned int bundle_align_p2;
  185. /* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
  186. bundle_lock_frag to frag_now and then starts a new frag with
  187. frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
  188. so that .bundle_unlock can verify that we didn't change segments.
  189. .bundle_unlock resets both to NULL. If we detect a bundling violation,
  190. then we reset bundle_lock_frchain to NULL as an indicator that we've
  191. already diagnosed the error with as_bad and don't need a cascade of
  192. redundant errors, but bundle_lock_frag remains set to indicate that
  193. we are expecting to see .bundle_unlock. */
  194. static fragS *bundle_lock_frag;
  195. static frchainS *bundle_lock_frchain;
  196. /* This is incremented by .bundle_lock and decremented by .bundle_unlock,
  197. to allow nesting. */
  198. static unsigned int bundle_lock_depth;
  199. #endif
  200. static void do_s_func (int end_p, const char *default_prefix);
  201. static void do_align (int, char *, int, int);
  202. static void s_align (int, int);
  203. static void s_altmacro (int);
  204. static void s_bad_end (int);
  205. static void s_reloc (int);
  206. static int hex_float (int, char *);
  207. static segT get_known_segmented_expression (expressionS * expP);
  208. static void pobegin (void);
  209. static size_t get_non_macro_line_sb (sb *);
  210. static void generate_file_debug (void);
  211. static char *_find_end_of_line (char *, int, int, int);
  212. void
  213. read_begin (void)
  214. {
  215. const char *p;
  216. pobegin ();
  217. obj_read_begin_hook ();
  218. /* Something close -- but not too close -- to a multiple of 1024.
  219. The debugging malloc I'm using has 24 bytes of overhead. */
  220. obstack_begin (&notes, chunksize);
  221. obstack_begin (&cond_obstack, chunksize);
  222. #ifndef tc_line_separator_chars
  223. #define tc_line_separator_chars line_separator_chars
  224. #endif
  225. /* Use machine dependent syntax. */
  226. for (p = tc_line_separator_chars; *p; p++)
  227. is_end_of_line[(unsigned char) *p] = 2;
  228. /* Use more. FIXME-SOMEDAY. */
  229. if (flag_mri)
  230. lex_type['?'] = 3;
  231. }
  232. #ifndef TC_ADDRESS_BYTES
  233. #define TC_ADDRESS_BYTES address_bytes
  234. static inline int
  235. address_bytes (void)
  236. {
  237. /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
  238. contain an address. */
  239. int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
  240. n |= n >> 1;
  241. n |= n >> 2;
  242. n += 1;
  243. return n;
  244. }
  245. #endif
  246. /* Set up pseudo-op tables. */
  247. static struct hash_control *po_hash;
  248. static const pseudo_typeS potable[] = {
  249. {"abort", s_abort, 0},
  250. {"align", s_align_ptwo, 0},
  251. {"altmacro", s_altmacro, 1},
  252. {"ascii", stringer, 8+0},
  253. {"asciz", stringer, 8+1},
  254. {"balign", s_align_bytes, 0},
  255. {"balignw", s_align_bytes, -2},
  256. {"balignl", s_align_bytes, -4},
  257. /* block */
  258. #ifdef HANDLE_BUNDLE
  259. {"bundle_align_mode", s_bundle_align_mode, 0},
  260. {"bundle_lock", s_bundle_lock, 0},
  261. {"bundle_unlock", s_bundle_unlock, 0},
  262. #endif
  263. {"byte", cons, 1},
  264. {"comm", s_comm, 0},
  265. {"common", s_mri_common, 0},
  266. {"common.s", s_mri_common, 1},
  267. {"data", s_data, 0},
  268. {"dc", cons, 2},
  269. #ifdef TC_ADDRESS_BYTES
  270. {"dc.a", cons, 0},
  271. #endif
  272. {"dc.b", cons, 1},
  273. {"dc.d", float_cons, 'd'},
  274. {"dc.l", cons, 4},
  275. {"dc.s", float_cons, 'f'},
  276. {"dc.w", cons, 2},
  277. {"dc.x", float_cons, 'x'},
  278. {"dcb", s_space, 2},
  279. {"dcb.b", s_space, 1},
  280. {"dcb.d", s_float_space, 'd'},
  281. {"dcb.l", s_space, 4},
  282. {"dcb.s", s_float_space, 'f'},
  283. {"dcb.w", s_space, 2},
  284. {"dcb.x", s_float_space, 'x'},
  285. {"ds", s_space, 2},
  286. {"ds.b", s_space, 1},
  287. {"ds.d", s_space, 8},
  288. {"ds.l", s_space, 4},
  289. {"ds.p", s_space, 12},
  290. {"ds.s", s_space, 4},
  291. {"ds.w", s_space, 2},
  292. {"ds.x", s_space, 12},
  293. {"debug", s_ignore, 0},
  294. #ifdef S_SET_DESC
  295. {"desc", s_desc, 0},
  296. #endif
  297. /* dim */
  298. {"double", float_cons, 'd'},
  299. /* dsect */
  300. {"eject", listing_eject, 0}, /* Formfeed listing. */
  301. {"else", s_else, 0},
  302. {"elsec", s_else, 0},
  303. {"elseif", s_elseif, (int) O_ne},
  304. {"end", s_end, 0},
  305. {"endc", s_endif, 0},
  306. {"endfunc", s_func, 1},
  307. {"endif", s_endif, 0},
  308. {"endm", s_bad_end, 0},
  309. {"endr", s_bad_end, 1},
  310. /* endef */
  311. {"equ", s_set, 0},
  312. {"equiv", s_set, 1},
  313. {"eqv", s_set, -1},
  314. {"err", s_err, 0},
  315. {"error", s_errwarn, 1},
  316. {"exitm", s_mexit, 0},
  317. /* extend */
  318. {"extern", s_ignore, 0}, /* We treat all undef as ext. */
  319. {"appfile", s_app_file, 1},
  320. {"appline", s_app_line, 1},
  321. {"fail", s_fail, 0},
  322. {"file", s_app_file, 0},
  323. {"fill", s_fill, 0},
  324. {"float", float_cons, 'f'},
  325. {"format", s_ignore, 0},
  326. {"func", s_func, 0},
  327. {"global", s_globl, 0},
  328. {"globl", s_globl, 0},
  329. {"hword", cons, 2},
  330. {"if", s_if, (int) O_ne},
  331. {"ifb", s_ifb, 1},
  332. {"ifc", s_ifc, 0},
  333. {"ifdef", s_ifdef, 0},
  334. {"ifeq", s_if, (int) O_eq},
  335. {"ifeqs", s_ifeqs, 0},
  336. {"ifge", s_if, (int) O_ge},
  337. {"ifgt", s_if, (int) O_gt},
  338. {"ifle", s_if, (int) O_le},
  339. {"iflt", s_if, (int) O_lt},
  340. {"ifnb", s_ifb, 0},
  341. {"ifnc", s_ifc, 1},
  342. {"ifndef", s_ifdef, 1},
  343. {"ifne", s_if, (int) O_ne},
  344. {"ifnes", s_ifeqs, 1},
  345. {"ifnotdef", s_ifdef, 1},
  346. {"incbin", s_incbin, 0},
  347. {"include", s_include, 0},
  348. {"int", cons, 4},
  349. {"irp", s_irp, 0},
  350. {"irep", s_irp, 0},
  351. {"irpc", s_irp, 1},
  352. {"irepc", s_irp, 1},
  353. {"lcomm", s_lcomm, 0},
  354. {"lflags", s_ignore, 0}, /* Listing flags. */
  355. {"linefile", s_app_line, 0},
  356. {"linkonce", s_linkonce, 0},
  357. {"list", listing_list, 1}, /* Turn listing on. */
  358. {"llen", listing_psize, 1},
  359. {"long", cons, 4},
  360. {"lsym", s_lsym, 0},
  361. {"macro", s_macro, 0},
  362. {"mexit", s_mexit, 0},
  363. {"mri", s_mri, 0},
  364. {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
  365. {"name", s_ignore, 0},
  366. {"noaltmacro", s_altmacro, 0},
  367. {"noformat", s_ignore, 0},
  368. {"nolist", listing_list, 0}, /* Turn listing off. */
  369. {"nopage", listing_nopage, 0},
  370. {"octa", cons, 16},
  371. {"offset", s_struct, 0},
  372. {"org", s_org, 0},
  373. {"p2align", s_align_ptwo, 0},
  374. {"p2alignw", s_align_ptwo, -2},
  375. {"p2alignl", s_align_ptwo, -4},
  376. {"page", listing_eject, 0},
  377. {"plen", listing_psize, 0},
  378. {"print", s_print, 0},
  379. {"psize", listing_psize, 0}, /* Set paper size. */
  380. {"purgem", s_purgem, 0},
  381. {"quad", cons, 8},
  382. {"reloc", s_reloc, 0},
  383. {"rep", s_rept, 0},
  384. {"rept", s_rept, 0},
  385. {"rva", s_rva, 4},
  386. {"sbttl", listing_title, 1}, /* Subtitle of listing. */
  387. /* scl */
  388. /* sect */
  389. {"set", s_set, 0},
  390. {"short", cons, 2},
  391. {"single", float_cons, 'f'},
  392. /* size */
  393. {"space", s_space, 0},
  394. {"skip", s_space, 0},
  395. {"sleb128", s_leb128, 1},
  396. {"spc", s_ignore, 0},
  397. {"stabd", s_stab, 'd'},
  398. {"stabn", s_stab, 'n'},
  399. {"stabs", s_stab, 's'},
  400. {"string", stringer, 8+1},
  401. {"string8", stringer, 8+1},
  402. {"string16", stringer, 16+1},
  403. {"string32", stringer, 32+1},
  404. {"string64", stringer, 64+1},
  405. {"struct", s_struct, 0},
  406. /* tag */
  407. {"text", s_text, 0},
  408. /* This is for gcc to use. It's only just been added (2/94), so gcc
  409. won't be able to use it for a while -- probably a year or more.
  410. But once this has been released, check with gcc maintainers
  411. before deleting it or even changing the spelling. */
  412. {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
  413. /* If we're folding case -- done for some targets, not necessarily
  414. all -- the above string in an input file will be converted to
  415. this one. Match it either way... */
  416. {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
  417. {"title", listing_title, 0}, /* Listing title. */
  418. {"ttl", listing_title, 0},
  419. /* type */
  420. {"uleb128", s_leb128, 0},
  421. /* use */
  422. /* val */
  423. {"xcom", s_comm, 0},
  424. {"xdef", s_globl, 0},
  425. {"xref", s_ignore, 0},
  426. {"xstabs", s_xstab, 's'},
  427. {"warning", s_errwarn, 0},
  428. {"weakref", s_weakref, 0},
  429. {"word", cons, 2},
  430. {"zero", s_space, 0},
  431. {NULL, NULL, 0} /* End sentinel. */
  432. };
  433. static offsetT
  434. get_absolute_expr (expressionS *exp)
  435. {
  436. expression_and_evaluate (exp);
  437. if (exp->X_op != O_constant)
  438. {
  439. if (exp->X_op != O_absent)
  440. as_bad (_("bad or irreducible absolute expression"));
  441. exp->X_add_number = 0;
  442. }
  443. return exp->X_add_number;
  444. }
  445. offsetT
  446. get_absolute_expression (void)
  447. {
  448. expressionS exp;
  449. return get_absolute_expr (&exp);
  450. }
  451. static int pop_override_ok = 0;
  452. static const char *pop_table_name;
  453. void
  454. pop_insert (const pseudo_typeS *table)
  455. {
  456. const char *errtxt;
  457. const pseudo_typeS *pop;
  458. for (pop = table; pop->poc_name; pop++)
  459. {
  460. errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
  461. if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
  462. as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
  463. errtxt);
  464. }
  465. }
  466. #ifndef md_pop_insert
  467. #define md_pop_insert() pop_insert(md_pseudo_table)
  468. #endif
  469. #ifndef obj_pop_insert
  470. #define obj_pop_insert() pop_insert(obj_pseudo_table)
  471. #endif
  472. #ifndef cfi_pop_insert
  473. #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
  474. #endif
  475. static void
  476. pobegin (void)
  477. {
  478. po_hash = hash_new ();
  479. /* Do the target-specific pseudo ops. */
  480. pop_table_name = "md";
  481. md_pop_insert ();
  482. /* Now object specific. Skip any that were in the target table. */
  483. pop_table_name = "obj";
  484. pop_override_ok = 1;
  485. obj_pop_insert ();
  486. /* Now portable ones. Skip any that we've seen already. */
  487. pop_table_name = "standard";
  488. pop_insert (potable);
  489. /* Now CFI ones. */
  490. pop_table_name = "cfi";
  491. pop_override_ok = 1;
  492. cfi_pop_insert ();
  493. }
  494. #define HANDLE_CONDITIONAL_ASSEMBLY(num_read) \
  495. if (ignore_input ()) \
  496. { \
  497. char *eol = find_end_of_line (input_line_pointer - (num_read), \
  498. flag_m68k_mri); \
  499. input_line_pointer = (input_line_pointer <= buffer_limit \
  500. && eol >= buffer_limit) \
  501. ? buffer_limit \
  502. : eol + 1; \
  503. continue; \
  504. }
  505. /* This function is used when scrubbing the characters between #APP
  506. and #NO_APP. */
  507. static char *scrub_string;
  508. static char *scrub_string_end;
  509. static size_t
  510. scrub_from_string (char *buf, size_t buflen)
  511. {
  512. size_t copy;
  513. copy = scrub_string_end - scrub_string;
  514. if (copy > buflen)
  515. copy = buflen;
  516. memcpy (buf, scrub_string, copy);
  517. scrub_string += copy;
  518. return copy;
  519. }
  520. /* Helper function of read_a_source_file, which tries to expand a macro. */
  521. static int
  522. try_macro (char term, const char *line)
  523. {
  524. sb out;
  525. const char *err;
  526. macro_entry *macro;
  527. if (check_macro (line, &out, &err, &macro))
  528. {
  529. if (err != NULL)
  530. as_bad ("%s", err);
  531. *input_line_pointer++ = term;
  532. input_scrub_include_sb (&out,
  533. input_line_pointer, 1);
  534. sb_kill (&out);
  535. buffer_limit =
  536. input_scrub_next_buffer (&input_line_pointer);
  537. #ifdef md_macro_info
  538. md_macro_info (macro);
  539. #endif
  540. return 1;
  541. }
  542. return 0;
  543. }
  544. #ifdef HANDLE_BUNDLE
  545. /* Start a new instruction bundle. Returns the rs_align_code frag that
  546. will be used to align the new bundle. */
  547. static fragS *
  548. start_bundle (void)
  549. {
  550. fragS *frag = frag_now;
  551. frag_align_code (0, 0);
  552. while (frag->fr_type != rs_align_code)
  553. frag = frag->fr_next;
  554. gas_assert (frag != frag_now);
  555. return frag;
  556. }
  557. /* Calculate the maximum size after relaxation of the region starting
  558. at the given frag and extending through frag_now (which is unfinished). */
  559. static unsigned int
  560. pending_bundle_size (fragS *frag)
  561. {
  562. unsigned int offset = frag->fr_fix;
  563. unsigned int size = 0;
  564. gas_assert (frag != frag_now);
  565. gas_assert (frag->fr_type == rs_align_code);
  566. while (frag != frag_now)
  567. {
  568. /* This should only happen in what will later become an error case. */
  569. if (frag == NULL)
  570. return 0;
  571. size += frag->fr_fix;
  572. if (frag->fr_type == rs_machine_dependent)
  573. size += md_frag_max_var (frag);
  574. frag = frag->fr_next;
  575. }
  576. gas_assert (frag == frag_now);
  577. size += frag_now_fix ();
  578. if (frag->fr_type == rs_machine_dependent)
  579. size += md_frag_max_var (frag);
  580. gas_assert (size >= offset);
  581. return size - offset;
  582. }
  583. /* Finish off the frag created to ensure bundle alignment. */
  584. static void
  585. finish_bundle (fragS *frag, unsigned int size)
  586. {
  587. gas_assert (bundle_align_p2 > 0);
  588. gas_assert (frag->fr_type == rs_align_code);
  589. if (size > 1)
  590. {
  591. /* If there is more than a single byte, then we need to set up the
  592. alignment frag. Otherwise we leave it at its initial state from
  593. calling frag_align_code (0, 0), so that it does nothing. */
  594. frag->fr_offset = bundle_align_p2;
  595. frag->fr_subtype = size - 1;
  596. }
  597. /* We do this every time rather than just in s_bundle_align_mode
  598. so that we catch any affected section without needing hooks all
  599. over for all paths that do section changes. It's cheap enough. */
  600. record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
  601. }
  602. /* Assemble one instruction. This takes care of the bundle features
  603. around calling md_assemble. */
  604. static void
  605. assemble_one (char *line)
  606. {
  607. fragS *insn_start_frag = NULL;
  608. if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
  609. {
  610. as_bad (_("cannot change section or subsection inside .bundle_lock"));
  611. /* Clearing this serves as a marker that we have already complained. */
  612. bundle_lock_frchain = NULL;
  613. }
  614. if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
  615. insn_start_frag = start_bundle ();
  616. md_assemble (line);
  617. if (bundle_lock_frchain != NULL)
  618. {
  619. /* Make sure this hasn't pushed the locked sequence
  620. past the bundle size. */
  621. unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
  622. if (bundle_size > (1U << bundle_align_p2))
  623. as_bad (_("\
  624. .bundle_lock sequence at %u bytes but .bundle_align_mode limit is %u bytes"),
  625. bundle_size, 1U << bundle_align_p2);
  626. }
  627. else if (bundle_align_p2 > 0)
  628. {
  629. unsigned int insn_size = pending_bundle_size (insn_start_frag);
  630. if (insn_size > (1U << bundle_align_p2))
  631. as_bad (_("\
  632. single instruction is %u bytes long but .bundle_align_mode limit is %u"),
  633. (unsigned int) insn_size, 1U << bundle_align_p2);
  634. finish_bundle (insn_start_frag, insn_size);
  635. }
  636. }
  637. #else /* !HANDLE_BUNDLE */
  638. # define assemble_one(line) md_assemble(line)
  639. #endif /* HANDLE_BUNDLE */
  640. /* We read the file, putting things into a web that represents what we
  641. have been reading. */
  642. void
  643. read_a_source_file (char *name)
  644. {
  645. char nul_char;
  646. char next_char;
  647. char *s; /* String of symbol, '\0' appended. */
  648. int temp;
  649. pseudo_typeS *pop;
  650. #ifdef WARN_COMMENTS
  651. found_comment = 0;
  652. #endif
  653. buffer = input_scrub_new_file (name);
  654. listing_file (name);
  655. listing_newline (NULL);
  656. register_dependency (name);
  657. /* Generate debugging information before we've read anything in to denote
  658. this file as the "main" source file and not a subordinate one
  659. (e.g. N_SO vs N_SOL in stabs). */
  660. generate_file_debug ();
  661. while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
  662. { /* We have another line to parse. */
  663. #ifndef NO_LISTING
  664. /* In order to avoid listing macro expansion lines with labels
  665. multiple times, keep track of which line was last issued. */
  666. static char *last_eol;
  667. last_eol = NULL;
  668. #endif
  669. while (input_line_pointer < buffer_limit)
  670. {
  671. bfd_boolean was_new_line;
  672. /* We have more of this buffer to parse. */
  673. /* We now have input_line_pointer->1st char of next line.
  674. If input_line_pointer [-1] == '\n' then we just
  675. scanned another line: so bump line counters. */
  676. was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
  677. if (was_new_line)
  678. {
  679. symbol_set_value_now (&dot_symbol);
  680. #ifdef md_start_line_hook
  681. md_start_line_hook ();
  682. #endif
  683. if (input_line_pointer[-1] == '\n')
  684. bump_line_counters ();
  685. }
  686. #ifndef NO_LISTING
  687. /* If listing is on, and we are expanding a macro, then give
  688. the listing code the contents of the expanded line. */
  689. if (listing)
  690. {
  691. if ((listing & LISTING_MACEXP) && macro_nest > 0)
  692. {
  693. /* Find the end of the current expanded macro line. */
  694. s = find_end_of_line (input_line_pointer, flag_m68k_mri);
  695. if (s != last_eol)
  696. {
  697. char *copy;
  698. int len;
  699. last_eol = s;
  700. /* Copy it for safe keeping. Also give an indication of
  701. how much macro nesting is involved at this point. */
  702. len = s - input_line_pointer;
  703. copy = (char *) xmalloc (len + macro_nest + 2);
  704. memset (copy, '>', macro_nest);
  705. copy[macro_nest] = ' ';
  706. memcpy (copy + macro_nest + 1, input_line_pointer, len);
  707. copy[macro_nest + 1 + len] = '\0';
  708. /* Install the line with the listing facility. */
  709. listing_newline (copy);
  710. }
  711. }
  712. else
  713. listing_newline (NULL);
  714. }
  715. #endif
  716. if (was_new_line)
  717. {
  718. line_label = NULL;
  719. if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
  720. {
  721. next_char = * input_line_pointer;
  722. /* Text at the start of a line must be a label, we
  723. run down and stick a colon in. */
  724. if (is_name_beginner (next_char) || next_char == '"')
  725. {
  726. char *line_start;
  727. int mri_line_macro;
  728. HANDLE_CONDITIONAL_ASSEMBLY (0);
  729. nul_char = get_symbol_name (& line_start);
  730. next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
  731. /* In MRI mode, the EQU and MACRO pseudoops must
  732. be handled specially. */
  733. mri_line_macro = 0;
  734. if (flag_m68k_mri)
  735. {
  736. char *rest = input_line_pointer + 1;
  737. if (*rest == ':')
  738. ++rest;
  739. if (*rest == ' ' || *rest == '\t')
  740. ++rest;
  741. if ((strncasecmp (rest, "EQU", 3) == 0
  742. || strncasecmp (rest, "SET", 3) == 0)
  743. && (rest[3] == ' ' || rest[3] == '\t'))
  744. {
  745. input_line_pointer = rest + 3;
  746. equals (line_start,
  747. strncasecmp (rest, "SET", 3) == 0);
  748. continue;
  749. }
  750. if (strncasecmp (rest, "MACRO", 5) == 0
  751. && (rest[5] == ' '
  752. || rest[5] == '\t'
  753. || is_end_of_line[(unsigned char) rest[5]]))
  754. mri_line_macro = 1;
  755. }
  756. /* In MRI mode, we need to handle the MACRO
  757. pseudo-op specially: we don't want to put the
  758. symbol in the symbol table. */
  759. if (!mri_line_macro
  760. #ifdef TC_START_LABEL_WITHOUT_COLON
  761. && TC_START_LABEL_WITHOUT_COLON (nul_char, next_char)
  762. #endif
  763. )
  764. line_label = colon (line_start);
  765. else
  766. line_label = symbol_create (line_start,
  767. absolute_section,
  768. (valueT) 0,
  769. &zero_address_frag);
  770. next_char = restore_line_pointer (nul_char);
  771. if (next_char == ':')
  772. input_line_pointer++;
  773. }
  774. }
  775. }
  776. /* We are at the beginning of a line, or similar place.
  777. We expect a well-formed assembler statement.
  778. A "symbol-name:" is a statement.
  779. Depending on what compiler is used, the order of these tests
  780. may vary to catch most common case 1st.
  781. Each test is independent of all other tests at the (top)
  782. level. */
  783. do
  784. nul_char = next_char = *input_line_pointer++;
  785. while (next_char == '\t' || next_char == ' ' || next_char == '\f');
  786. /* C is the 1st significant character.
  787. Input_line_pointer points after that character. */
  788. if (is_name_beginner (next_char) || next_char == '"')
  789. {
  790. char *rest;
  791. /* Want user-defined label or pseudo/opcode. */
  792. HANDLE_CONDITIONAL_ASSEMBLY (1);
  793. --input_line_pointer;
  794. nul_char = get_symbol_name (& s); /* name's delimiter. */
  795. next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
  796. rest = input_line_pointer + (nul_char == '"' ? 2 : 1);
  797. /* NEXT_CHAR is character after symbol.
  798. The end of symbol in the input line is now '\0'.
  799. S points to the beginning of the symbol.
  800. [In case of pseudo-op, s->'.'.]
  801. Input_line_pointer->'\0' where NUL_CHAR was. */
  802. if (TC_START_LABEL (s, nul_char, next_char))
  803. {
  804. if (flag_m68k_mri)
  805. {
  806. /* In MRI mode, \tsym: set 0 is permitted. */
  807. if (*rest == ':')
  808. ++rest;
  809. if (*rest == ' ' || *rest == '\t')
  810. ++rest;
  811. if ((strncasecmp (rest, "EQU", 3) == 0
  812. || strncasecmp (rest, "SET", 3) == 0)
  813. && (rest[3] == ' ' || rest[3] == '\t'))
  814. {
  815. input_line_pointer = rest + 3;
  816. equals (s, 1);
  817. continue;
  818. }
  819. }
  820. line_label = colon (s); /* User-defined label. */
  821. restore_line_pointer (nul_char);
  822. ++ input_line_pointer;
  823. #ifdef tc_check_label
  824. tc_check_label (line_label);
  825. #endif
  826. /* Input_line_pointer->after ':'. */
  827. SKIP_WHITESPACE ();
  828. }
  829. else if ((next_char == '=' && *rest == '=')
  830. || ((next_char == ' ' || next_char == '\t')
  831. && rest[0] == '='
  832. && rest[1] == '='))
  833. {
  834. equals (s, -1);
  835. demand_empty_rest_of_line ();
  836. }
  837. else if ((next_char == '='
  838. || ((next_char == ' ' || next_char == '\t')
  839. && *rest == '='))
  840. #ifdef TC_EQUAL_IN_INSN
  841. && !TC_EQUAL_IN_INSN (next_char, s)
  842. #endif
  843. )
  844. {
  845. equals (s, 1);
  846. demand_empty_rest_of_line ();
  847. }
  848. else
  849. {
  850. /* Expect pseudo-op or machine instruction. */
  851. pop = NULL;
  852. #ifndef TC_CASE_SENSITIVE
  853. {
  854. char *s2 = s;
  855. strncpy (original_case_string, s2, sizeof (original_case_string));
  856. original_case_string[sizeof (original_case_string) - 1] = 0;
  857. while (*s2)
  858. {
  859. *s2 = TOLOWER (*s2);
  860. s2++;
  861. }
  862. }
  863. #endif
  864. if (NO_PSEUDO_DOT || flag_m68k_mri)
  865. {
  866. /* The MRI assembler uses pseudo-ops without
  867. a period. */
  868. pop = (pseudo_typeS *) hash_find (po_hash, s);
  869. if (pop != NULL && pop->poc_handler == NULL)
  870. pop = NULL;
  871. }
  872. if (pop != NULL
  873. || (!flag_m68k_mri && *s == '.'))
  874. {
  875. /* PSEUDO - OP.
  876. WARNING: next_char may be end-of-line.
  877. We lookup the pseudo-op table with s+1 because we
  878. already know that the pseudo-op begins with a '.'. */
  879. if (pop == NULL)
  880. pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
  881. if (pop && !pop->poc_handler)
  882. pop = NULL;
  883. /* In MRI mode, we may need to insert an
  884. automatic alignment directive. What a hack
  885. this is. */
  886. if (mri_pending_align
  887. && (pop == NULL
  888. || !((pop->poc_handler == cons
  889. && pop->poc_val == 1)
  890. || (pop->poc_handler == s_space
  891. && pop->poc_val == 1)
  892. #ifdef tc_conditional_pseudoop
  893. || tc_conditional_pseudoop (pop)
  894. #endif
  895. || pop->poc_handler == s_if
  896. || pop->poc_handler == s_ifdef
  897. || pop->poc_handler == s_ifc
  898. || pop->poc_handler == s_ifeqs
  899. || pop->poc_handler == s_else
  900. || pop->poc_handler == s_endif
  901. || pop->poc_handler == s_globl
  902. || pop->poc_handler == s_ignore)))
  903. {
  904. do_align (1, (char *) NULL, 0, 0);
  905. mri_pending_align = 0;
  906. if (line_label != NULL)
  907. {
  908. symbol_set_frag (line_label, frag_now);
  909. S_SET_VALUE (line_label, frag_now_fix ());
  910. }
  911. }
  912. /* Print the error msg now, while we still can. */
  913. if (pop == NULL)
  914. {
  915. char *end = input_line_pointer;
  916. (void) restore_line_pointer (nul_char);
  917. s_ignore (0);
  918. nul_char = next_char = *--input_line_pointer;
  919. *input_line_pointer = '\0';
  920. if (! macro_defined || ! try_macro (next_char, s))
  921. {
  922. *end = '\0';
  923. as_bad (_("unknown pseudo-op: `%s'"), s);
  924. *input_line_pointer++ = nul_char;
  925. }
  926. continue;
  927. }
  928. /* Put it back for error messages etc. */
  929. next_char = restore_line_pointer (nul_char);
  930. /* The following skip of whitespace is compulsory.
  931. A well shaped space is sometimes all that separates
  932. keyword from operands. */
  933. if (next_char == ' ' || next_char == '\t')
  934. input_line_pointer++;
  935. /* Input_line is restored.
  936. Input_line_pointer->1st non-blank char
  937. after pseudo-operation. */
  938. (*pop->poc_handler) (pop->poc_val);
  939. /* If that was .end, just get out now. */
  940. if (pop->poc_handler == s_end)
  941. goto quit;
  942. }
  943. else
  944. {
  945. /* WARNING: next_char may be end-of-line. */
  946. /* Also: input_line_pointer->`\0` where nul_char was. */
  947. (void) restore_line_pointer (nul_char);
  948. input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
  949. next_char = nul_char = *input_line_pointer;
  950. *input_line_pointer = '\0';
  951. generate_lineno_debug ();
  952. if (macro_defined && try_macro (next_char, s))
  953. continue;
  954. if (mri_pending_align)
  955. {
  956. do_align (1, (char *) NULL, 0, 0);
  957. mri_pending_align = 0;
  958. if (line_label != NULL)
  959. {
  960. symbol_set_frag (line_label, frag_now);
  961. S_SET_VALUE (line_label, frag_now_fix ());
  962. }
  963. }
  964. assemble_one (s); /* Assemble 1 instruction. */
  965. *input_line_pointer++ = nul_char;
  966. /* We resume loop AFTER the end-of-line from
  967. this instruction. */
  968. }
  969. }
  970. continue;
  971. }
  972. /* Empty statement? */
  973. if (is_end_of_line[(unsigned char) next_char])
  974. continue;
  975. if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
  976. {
  977. /* local label ("4:") */
  978. char *backup = input_line_pointer;
  979. HANDLE_CONDITIONAL_ASSEMBLY (1);
  980. temp = next_char - '0';
  981. if (nul_char == '"')
  982. ++ input_line_pointer;
  983. /* Read the whole number. */
  984. while (ISDIGIT (*input_line_pointer))
  985. {
  986. temp = (temp * 10) + *input_line_pointer - '0';
  987. ++input_line_pointer;
  988. }
  989. if (LOCAL_LABELS_DOLLAR
  990. && *input_line_pointer == '$'
  991. && *(input_line_pointer + 1) == ':')
  992. {
  993. input_line_pointer += 2;
  994. if (dollar_label_defined (temp))
  995. {
  996. as_fatal (_("label \"%d$\" redefined"), temp);
  997. }
  998. define_dollar_label (temp);
  999. colon (dollar_label_name (temp, 0));
  1000. continue;
  1001. }
  1002. if (LOCAL_LABELS_FB
  1003. && *input_line_pointer++ == ':')
  1004. {
  1005. fb_label_instance_inc (temp);
  1006. colon (fb_label_name (temp, 0));
  1007. continue;
  1008. }
  1009. input_line_pointer = backup;
  1010. }
  1011. if (next_char && strchr (line_comment_chars, next_char))
  1012. { /* Its a comment. Better say APP or NO_APP. */
  1013. sb sbuf;
  1014. char *ends;
  1015. char *new_buf;
  1016. char *new_tmp;
  1017. unsigned int new_length;
  1018. char *tmp_buf = 0;
  1019. s = input_line_pointer;
  1020. if (strncmp (s, "APP\n", 4))
  1021. {
  1022. /* We ignore it. */
  1023. ignore_rest_of_line ();
  1024. continue;
  1025. }
  1026. bump_line_counters ();
  1027. s += 4;
  1028. ends = strstr (s, "#NO_APP\n");
  1029. if (!ends)
  1030. {
  1031. unsigned int tmp_len;
  1032. unsigned int num;
  1033. /* The end of the #APP wasn't in this buffer. We
  1034. keep reading in buffers until we find the #NO_APP
  1035. that goes with this #APP There is one. The specs
  1036. guarantee it... */
  1037. tmp_len = buffer_limit - s;
  1038. tmp_buf = (char *) xmalloc (tmp_len + 1);
  1039. memcpy (tmp_buf, s, tmp_len);
  1040. do
  1041. {
  1042. new_tmp = input_scrub_next_buffer (&buffer);
  1043. if (!new_tmp)
  1044. break;
  1045. else
  1046. buffer_limit = new_tmp;
  1047. input_line_pointer = buffer;
  1048. ends = strstr (buffer, "#NO_APP\n");
  1049. if (ends)
  1050. num = ends - buffer;
  1051. else
  1052. num = buffer_limit - buffer;
  1053. tmp_buf = (char *) xrealloc (tmp_buf, tmp_len + num);
  1054. memcpy (tmp_buf + tmp_len, buffer, num);
  1055. tmp_len += num;
  1056. }
  1057. while (!ends);
  1058. input_line_pointer = ends ? ends + 8 : NULL;
  1059. s = tmp_buf;
  1060. ends = s + tmp_len;
  1061. }
  1062. else
  1063. {
  1064. input_line_pointer = ends + 8;
  1065. }
  1066. scrub_string = s;
  1067. scrub_string_end = ends;
  1068. new_length = ends - s;
  1069. new_buf = (char *) xmalloc (new_length);
  1070. new_tmp = new_buf;
  1071. for (;;)
  1072. {
  1073. size_t space;
  1074. size_t size;
  1075. space = (new_buf + new_length) - new_tmp;
  1076. size = do_scrub_chars (scrub_from_string, new_tmp, space);
  1077. if (size < space)
  1078. {
  1079. new_tmp[size] = 0;
  1080. break;
  1081. }
  1082. new_buf = (char *) xrealloc (new_buf, new_length + 100);
  1083. new_tmp = new_buf + new_length;
  1084. new_length += 100;
  1085. }
  1086. if (tmp_buf)
  1087. free (tmp_buf);
  1088. /* We've "scrubbed" input to the preferred format. In the
  1089. process we may have consumed the whole of the remaining
  1090. file (and included files). We handle this formatted
  1091. input similar to that of macro expansion, letting
  1092. actual macro expansion (possibly nested) and other
  1093. input expansion work. Beware that in messages, line
  1094. numbers and possibly file names will be incorrect. */
  1095. new_length = strlen (new_buf);
  1096. sb_build (&sbuf, new_length);
  1097. sb_add_buffer (&sbuf, new_buf, new_length);
  1098. input_scrub_include_sb (&sbuf, input_line_pointer, 0);
  1099. sb_kill (&sbuf);
  1100. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  1101. free (new_buf);
  1102. continue;
  1103. }
  1104. HANDLE_CONDITIONAL_ASSEMBLY (1);
  1105. #ifdef tc_unrecognized_line
  1106. if (tc_unrecognized_line (next_char))
  1107. continue;
  1108. #endif
  1109. input_line_pointer--;
  1110. /* Report unknown char as error. */
  1111. demand_empty_rest_of_line ();
  1112. }
  1113. }
  1114. quit:
  1115. symbol_set_value_now (&dot_symbol);
  1116. #ifdef HANDLE_BUNDLE
  1117. if (bundle_lock_frag != NULL)
  1118. {
  1119. as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
  1120. _(".bundle_lock with no matching .bundle_unlock"));
  1121. bundle_lock_frag = NULL;
  1122. bundle_lock_frchain = NULL;
  1123. bundle_lock_depth = 0;
  1124. }
  1125. #endif
  1126. #ifdef md_cleanup
  1127. md_cleanup ();
  1128. #endif
  1129. /* Close the input file. */
  1130. input_scrub_close ();
  1131. #ifdef WARN_COMMENTS
  1132. {
  1133. if (warn_comment && found_comment)
  1134. as_warn_where (found_comment_file, found_comment,
  1135. "first comment found here");
  1136. }
  1137. #endif
  1138. }
  1139. /* Convert O_constant expression EXP into the equivalent O_big representation.
  1140. Take the sign of the number from SIGN rather than X_add_number. */
  1141. static void
  1142. convert_to_bignum (expressionS *exp, int sign)
  1143. {
  1144. valueT value;
  1145. unsigned int i;
  1146. value = exp->X_add_number;
  1147. for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
  1148. {
  1149. generic_bignum[i] = value & LITTLENUM_MASK;
  1150. value >>= LITTLENUM_NUMBER_OF_BITS;
  1151. }
  1152. /* Add a sequence of sign bits if the top bit of X_add_number is not
  1153. the sign of the original value. */
  1154. if ((exp->X_add_number < 0) == !sign)
  1155. generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
  1156. exp->X_op = O_big;
  1157. exp->X_add_number = i;
  1158. }
  1159. /* For most MRI pseudo-ops, the line actually ends at the first
  1160. nonquoted space. This function looks for that point, stuffs a null
  1161. in, and sets *STOPCP to the character that used to be there, and
  1162. returns the location.
  1163. Until I hear otherwise, I am going to assume that this is only true
  1164. for the m68k MRI assembler. */
  1165. char *
  1166. mri_comment_field (char *stopcp)
  1167. {
  1168. char *s;
  1169. #ifdef TC_M68K
  1170. int inquote = 0;
  1171. know (flag_m68k_mri);
  1172. for (s = input_line_pointer;
  1173. ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
  1174. || inquote);
  1175. s++)
  1176. {
  1177. if (*s == '\'')
  1178. inquote = !inquote;
  1179. }
  1180. #else
  1181. for (s = input_line_pointer;
  1182. !is_end_of_line[(unsigned char) *s];
  1183. s++)
  1184. ;
  1185. #endif
  1186. *stopcp = *s;
  1187. *s = '\0';
  1188. return s;
  1189. }
  1190. /* Skip to the end of an MRI comment field. */
  1191. void
  1192. mri_comment_end (char *stop, int stopc)
  1193. {
  1194. know (flag_mri);
  1195. input_line_pointer = stop;
  1196. *stop = stopc;
  1197. while (!is_end_of_line[(unsigned char) *input_line_pointer])
  1198. ++input_line_pointer;
  1199. }
  1200. void
  1201. s_abort (int ignore ATTRIBUTE_UNUSED)
  1202. {
  1203. as_fatal (_(".abort detected. Abandoning ship."));
  1204. }
  1205. /* Guts of .align directive. N is the power of two to which to align.
  1206. FILL may be NULL, or it may point to the bytes of the fill pattern.
  1207. LEN is the length of whatever FILL points to, if anything. MAX is
  1208. the maximum number of characters to skip when doing the alignment,
  1209. or 0 if there is no maximum. */
  1210. static void
  1211. do_align (int n, char *fill, int len, int max)
  1212. {
  1213. if (now_seg == absolute_section)
  1214. {
  1215. if (fill != NULL)
  1216. while (len-- > 0)
  1217. if (*fill++ != '\0')
  1218. {
  1219. as_warn (_("ignoring fill value in absolute section"));
  1220. break;
  1221. }
  1222. fill = NULL;
  1223. len = 0;
  1224. }
  1225. #ifdef md_flush_pending_output
  1226. md_flush_pending_output ();
  1227. #endif
  1228. #ifdef md_do_align
  1229. md_do_align (n, fill, len, max, just_record_alignment);
  1230. #endif
  1231. /* Only make a frag if we HAVE to... */
  1232. if (n != 0 && !need_pass_2)
  1233. {
  1234. if (fill == NULL)
  1235. {
  1236. if (subseg_text_p (now_seg))
  1237. frag_align_code (n, max);
  1238. else
  1239. frag_align (n, 0, max);
  1240. }
  1241. else if (len <= 1)
  1242. frag_align (n, *fill, max);
  1243. else
  1244. frag_align_pattern (n, fill, len, max);
  1245. }
  1246. #ifdef md_do_align
  1247. just_record_alignment: ATTRIBUTE_UNUSED_LABEL
  1248. #endif
  1249. record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
  1250. }
  1251. /* Handle the .align pseudo-op. A positive ARG is a default alignment
  1252. (in bytes). A negative ARG is the negative of the length of the
  1253. fill pattern. BYTES_P is non-zero if the alignment value should be
  1254. interpreted as the byte boundary, rather than the power of 2. */
  1255. #ifndef TC_ALIGN_LIMIT
  1256. #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
  1257. #endif
  1258. static void
  1259. s_align (int arg, int bytes_p)
  1260. {
  1261. unsigned int align_limit = TC_ALIGN_LIMIT;
  1262. unsigned int align;
  1263. char *stop = NULL;
  1264. char stopc = 0;
  1265. offsetT fill = 0;
  1266. int max;
  1267. int fill_p;
  1268. if (flag_mri)
  1269. stop = mri_comment_field (&stopc);
  1270. if (is_end_of_line[(unsigned char) *input_line_pointer])
  1271. {
  1272. if (arg < 0)
  1273. align = 0;
  1274. else
  1275. align = arg; /* Default value from pseudo-op table. */
  1276. }
  1277. else
  1278. {
  1279. align = get_absolute_expression ();
  1280. SKIP_WHITESPACE ();
  1281. #ifdef TC_ALIGN_ZERO_IS_DEFAULT
  1282. if (arg > 0 && align == 0)
  1283. align = arg;
  1284. #endif
  1285. }
  1286. if (bytes_p)
  1287. {
  1288. /* Convert to a power of 2. */
  1289. if (align != 0)
  1290. {
  1291. unsigned int i;
  1292. for (i = 0; (align & 1) == 0; align >>= 1, ++i)
  1293. ;
  1294. if (align != 1)
  1295. as_bad (_("alignment not a power of 2"));
  1296. align = i;
  1297. }
  1298. }
  1299. if (align > align_limit)
  1300. {
  1301. align = align_limit;
  1302. as_warn (_("alignment too large: %u assumed"), align);
  1303. }
  1304. if (*input_line_pointer != ',')
  1305. {
  1306. fill_p = 0;
  1307. max = 0;
  1308. }
  1309. else
  1310. {
  1311. ++input_line_pointer;
  1312. if (*input_line_pointer == ',')
  1313. fill_p = 0;
  1314. else
  1315. {
  1316. fill = get_absolute_expression ();
  1317. SKIP_WHITESPACE ();
  1318. fill_p = 1;
  1319. }
  1320. if (*input_line_pointer != ',')
  1321. max = 0;
  1322. else
  1323. {
  1324. ++input_line_pointer;
  1325. max = get_absolute_expression ();
  1326. }
  1327. }
  1328. if (!fill_p)
  1329. {
  1330. if (arg < 0)
  1331. as_warn (_("expected fill pattern missing"));
  1332. do_align (align, (char *) NULL, 0, max);
  1333. }
  1334. else
  1335. {
  1336. int fill_len;
  1337. if (arg >= 0)
  1338. fill_len = 1;
  1339. else
  1340. fill_len = -arg;
  1341. if (fill_len <= 1)
  1342. {
  1343. char fill_char;
  1344. fill_char = fill;
  1345. do_align (align, &fill_char, fill_len, max);
  1346. }
  1347. else
  1348. {
  1349. char ab[16];
  1350. if ((size_t) fill_len > sizeof ab)
  1351. abort ();
  1352. md_number_to_chars (ab, fill, fill_len);
  1353. do_align (align, ab, fill_len, max);
  1354. }
  1355. }
  1356. demand_empty_rest_of_line ();
  1357. if (flag_mri)
  1358. mri_comment_end (stop, stopc);
  1359. }
  1360. /* Handle the .align pseudo-op on machines where ".align 4" means
  1361. align to a 4 byte boundary. */
  1362. void
  1363. s_align_bytes (int arg)
  1364. {
  1365. s_align (arg, 1);
  1366. }
  1367. /* Handle the .align pseudo-op on machines where ".align 4" means align
  1368. to a 2**4 boundary. */
  1369. void
  1370. s_align_ptwo (int arg)
  1371. {
  1372. s_align (arg, 0);
  1373. }
  1374. /* Switch in and out of alternate macro mode. */
  1375. static void
  1376. s_altmacro (int on)
  1377. {
  1378. demand_empty_rest_of_line ();
  1379. macro_set_alternate (on);
  1380. }
  1381. /* Read a symbol name from input_line_pointer.
  1382. Stores the symbol name in a buffer and returns a pointer to this buffer.
  1383. The buffer is xalloc'ed. It is the caller's responsibility to free
  1384. this buffer.
  1385. The name is not left in the i_l_p buffer as it may need processing
  1386. to handle escape characters.
  1387. Advances i_l_p to the next non-whitespace character.
  1388. If a symbol name could not be read, the routine issues an error
  1389. messages, skips to the end of the line and returns NULL. */
  1390. char *
  1391. read_symbol_name (void)
  1392. {
  1393. char * name;
  1394. char * start;
  1395. char c;
  1396. c = *input_line_pointer++;
  1397. if (c == '"')
  1398. {
  1399. #define SYM_NAME_CHUNK_LEN 128
  1400. ptrdiff_t len = SYM_NAME_CHUNK_LEN;
  1401. char * name_end;
  1402. unsigned int C;
  1403. start = name = xmalloc (len + 1);
  1404. name_end = name + SYM_NAME_CHUNK_LEN;
  1405. while (is_a_char (C = next_char_of_string ()))
  1406. {
  1407. if (name >= name_end)
  1408. {
  1409. ptrdiff_t sofar;
  1410. sofar = name - start;
  1411. len += SYM_NAME_CHUNK_LEN;
  1412. start = xrealloc (start, len + 1);
  1413. name_end = start + len;
  1414. name = start + sofar;
  1415. }
  1416. *name++ = (char) C;
  1417. }
  1418. *name = 0;
  1419. /* Since quoted symbol names can contain non-ASCII characters,
  1420. check the string and warn if it cannot be recognised by the
  1421. current character set. */
  1422. if (mbstowcs (NULL, name, len) == (size_t) -1)
  1423. as_warn (_("symbol name not recognised in the current locale"));
  1424. }
  1425. else if (is_name_beginner (c) || c == '\001')
  1426. {
  1427. ptrdiff_t len;
  1428. name = input_line_pointer - 1;
  1429. /* We accept \001 in a name in case this is
  1430. being called with a constructed string. */
  1431. while (is_part_of_name (c = *input_line_pointer++)
  1432. || c == '\001')
  1433. ;
  1434. len = (input_line_pointer - name) - 1;
  1435. start = xmalloc (len + 1);
  1436. memcpy (start, name, len);
  1437. start[len] = 0;
  1438. /* Skip a name ender char if one is present. */
  1439. if (! is_name_ender (c))
  1440. --input_line_pointer;
  1441. }
  1442. else
  1443. name = start = NULL;
  1444. if (name == start)
  1445. {
  1446. as_bad (_("expected symbol name"));
  1447. ignore_rest_of_line ();
  1448. return NULL;
  1449. }
  1450. SKIP_WHITESPACE ();
  1451. return start;
  1452. }
  1453. symbolS *
  1454. s_comm_internal (int param,
  1455. symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
  1456. {
  1457. char *name;
  1458. offsetT temp, size;
  1459. symbolS *symbolP = NULL;
  1460. char *stop = NULL;
  1461. char stopc = 0;
  1462. expressionS exp;
  1463. if (flag_mri)
  1464. stop = mri_comment_field (&stopc);
  1465. if ((name = read_symbol_name ()) == NULL)
  1466. goto out;
  1467. /* Accept an optional comma after the name. The comma used to be
  1468. required, but Irix 5 cc does not generate it for .lcomm. */
  1469. if (*input_line_pointer == ',')
  1470. input_line_pointer++;
  1471. temp = get_absolute_expr (&exp);
  1472. size = temp;
  1473. size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
  1474. if (exp.X_op == O_absent)
  1475. {
  1476. as_bad (_("missing size expression"));
  1477. ignore_rest_of_line ();
  1478. goto out;
  1479. }
  1480. else if (temp != size || !exp.X_unsigned)
  1481. {
  1482. as_warn (_("size (%ld) out of range, ignored"), (long) temp);
  1483. ignore_rest_of_line ();
  1484. goto out;
  1485. }
  1486. symbolP = symbol_find_or_make (name);
  1487. if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
  1488. && !S_IS_COMMON (symbolP))
  1489. {
  1490. if (!S_IS_VOLATILE (symbolP))
  1491. {
  1492. symbolP = NULL;
  1493. as_bad (_("symbol `%s' is already defined"), name);
  1494. ignore_rest_of_line ();
  1495. goto out;
  1496. }
  1497. symbolP = symbol_clone (symbolP, 1);
  1498. S_SET_SEGMENT (symbolP, undefined_section);
  1499. S_SET_VALUE (symbolP, 0);
  1500. symbol_set_frag (symbolP, &zero_address_frag);
  1501. S_CLEAR_VOLATILE (symbolP);
  1502. }
  1503. size = S_GET_VALUE (symbolP);
  1504. if (size == 0)
  1505. size = temp;
  1506. else if (size != temp)
  1507. as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
  1508. name, (long) size, (long) temp);
  1509. if (comm_parse_extra != NULL)
  1510. symbolP = (*comm_parse_extra) (param, symbolP, size);
  1511. else
  1512. {
  1513. S_SET_VALUE (symbolP, (valueT) size);
  1514. S_SET_EXTERNAL (symbolP);
  1515. S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
  1516. }
  1517. demand_empty_rest_of_line ();
  1518. out:
  1519. if (flag_mri)
  1520. mri_comment_end (stop, stopc);
  1521. if (name != NULL)
  1522. free (name);
  1523. return symbolP;
  1524. }
  1525. void
  1526. s_comm (int ignore)
  1527. {
  1528. s_comm_internal (ignore, NULL);
  1529. }
  1530. /* The MRI COMMON pseudo-op. We handle this by creating a common
  1531. symbol with the appropriate name. We make s_space do the right
  1532. thing by increasing the size. */
  1533. void
  1534. s_mri_common (int small ATTRIBUTE_UNUSED)
  1535. {
  1536. char *name;
  1537. char c;
  1538. char *alc = NULL;
  1539. symbolS *sym;
  1540. offsetT align;
  1541. char *stop = NULL;
  1542. char stopc = 0;
  1543. if (!flag_mri)
  1544. {
  1545. s_comm (0);
  1546. return;
  1547. }
  1548. stop = mri_comment_field (&stopc);
  1549. SKIP_WHITESPACE ();
  1550. name = input_line_pointer;
  1551. if (!ISDIGIT (*name))
  1552. c = get_symbol_name (& name);
  1553. else
  1554. {
  1555. do
  1556. {
  1557. ++input_line_pointer;
  1558. }
  1559. while (ISDIGIT (*input_line_pointer));
  1560. c = *input_line_pointer;
  1561. *input_line_pointer = '\0';
  1562. if (line_label != NULL)
  1563. {
  1564. alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
  1565. + (input_line_pointer - name)
  1566. + 1);
  1567. sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
  1568. name = alc;
  1569. }
  1570. }
  1571. sym = symbol_find_or_make (name);
  1572. c = restore_line_pointer (c);
  1573. if (alc != NULL)
  1574. free (alc);
  1575. if (*input_line_pointer != ',')
  1576. align = 0;
  1577. else
  1578. {
  1579. ++input_line_pointer;
  1580. align = get_absolute_expression ();
  1581. }
  1582. if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
  1583. {
  1584. as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
  1585. ignore_rest_of_line ();
  1586. mri_comment_end (stop, stopc);
  1587. return;
  1588. }
  1589. S_SET_EXTERNAL (sym);
  1590. S_SET_SEGMENT (sym, bfd_com_section_ptr);
  1591. mri_common_symbol = sym;
  1592. #ifdef S_SET_ALIGN
  1593. if (align != 0)
  1594. S_SET_ALIGN (sym, align);
  1595. #else
  1596. (void) align;
  1597. #endif
  1598. if (line_label != NULL)
  1599. {
  1600. expressionS exp;
  1601. exp.X_op = O_symbol;
  1602. exp.X_add_symbol = sym;
  1603. exp.X_add_number = 0;
  1604. symbol_set_value_expression (line_label, &exp);
  1605. symbol_set_frag (line_label, &zero_address_frag);
  1606. S_SET_SEGMENT (line_label, expr_section);
  1607. }
  1608. /* FIXME: We just ignore the small argument, which distinguishes
  1609. COMMON and COMMON.S. I don't know what we can do about it. */
  1610. /* Ignore the type and hptype. */
  1611. if (*input_line_pointer == ',')
  1612. input_line_pointer += 2;
  1613. if (*input_line_pointer == ',')
  1614. input_line_pointer += 2;
  1615. demand_empty_rest_of_line ();
  1616. mri_comment_end (stop, stopc);
  1617. }
  1618. void
  1619. s_data (int ignore ATTRIBUTE_UNUSED)
  1620. {
  1621. segT section;
  1622. int temp;
  1623. temp = get_absolute_expression ();
  1624. if (flag_readonly_data_in_text)
  1625. {
  1626. section = text_section;
  1627. temp += 1000;
  1628. }
  1629. else
  1630. section = data_section;
  1631. subseg_set (section, (subsegT) temp);
  1632. demand_empty_rest_of_line ();
  1633. }
  1634. /* Handle the .appfile pseudo-op. This is automatically generated by
  1635. do_scrub_chars when a preprocessor # line comment is seen with a
  1636. file name. This default definition may be overridden by the object
  1637. or CPU specific pseudo-ops. This function is also the default
  1638. definition for .file; the APPFILE argument is 1 for .appfile, 0 for
  1639. .file. */
  1640. void
  1641. s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
  1642. {
  1643. #ifdef LISTING
  1644. if (listing)
  1645. listing_source_file (file);
  1646. #endif
  1647. register_dependency (file);
  1648. #ifdef obj_app_file
  1649. obj_app_file (file, appfile);
  1650. #endif
  1651. }
  1652. void
  1653. s_app_file (int appfile)
  1654. {
  1655. char *s;
  1656. int length;
  1657. /* Some assemblers tolerate immediately following '"'. */
  1658. if ((s = demand_copy_string (&length)) != 0)
  1659. {
  1660. int may_omit
  1661. = (!new_logical_line_flags (s, -1, 1) && appfile);
  1662. /* In MRI mode, the preprocessor may have inserted an extraneous
  1663. backquote. */
  1664. if (flag_m68k_mri
  1665. && *input_line_pointer == '\''
  1666. && is_end_of_line[(unsigned char) input_line_pointer[1]])
  1667. ++input_line_pointer;
  1668. demand_empty_rest_of_line ();
  1669. if (!may_omit)
  1670. s_app_file_string (s, appfile);
  1671. }
  1672. }
  1673. static int
  1674. get_linefile_number (int *flag)
  1675. {
  1676. SKIP_WHITESPACE ();
  1677. if (*input_line_pointer < '0' || *input_line_pointer > '9')
  1678. return 0;
  1679. *flag = get_absolute_expression ();
  1680. return 1;
  1681. }
  1682. /* Handle the .appline pseudo-op. This is automatically generated by
  1683. do_scrub_chars when a preprocessor # line comment is seen. This
  1684. default definition may be overridden by the object or CPU specific
  1685. pseudo-ops. */
  1686. void
  1687. s_app_line (int appline)
  1688. {
  1689. char *file = NULL;
  1690. int l;
  1691. /* The given number is that of the next line. */
  1692. if (appline)
  1693. l = get_absolute_expression ();
  1694. else if (!get_linefile_number (&l))
  1695. {
  1696. ignore_rest_of_line ();
  1697. return;
  1698. }
  1699. l--;
  1700. if (l < -1)
  1701. /* Some of the back ends can't deal with non-positive line numbers.
  1702. Besides, it's silly. GCC however will generate a line number of
  1703. zero when it is pre-processing builtins for assembler-with-cpp files:
  1704. # 0 "<built-in>"
  1705. We do not want to barf on this, especially since such files are used
  1706. in the GCC and GDB testsuites. So we check for negative line numbers
  1707. rather than non-positive line numbers. */
  1708. as_warn (_("line numbers must be positive; line number %d rejected"),
  1709. l + 1);
  1710. else
  1711. {
  1712. int flags = 0;
  1713. int length = 0;
  1714. if (!appline)
  1715. {
  1716. SKIP_WHITESPACE ();
  1717. if (*input_line_pointer == '"')
  1718. file = demand_copy_string (&length);
  1719. if (file)
  1720. {
  1721. int this_flag;
  1722. while (get_linefile_number (&this_flag))
  1723. switch (this_flag)
  1724. {
  1725. /* From GCC's cpp documentation:
  1726. 1: start of a new file.
  1727. 2: returning to a file after having included
  1728. another file.
  1729. 3: following text comes from a system header file.
  1730. 4: following text should be treated as extern "C".
  1731. 4 is nonsensical for the assembler; 3, we don't
  1732. care about, so we ignore it just in case a
  1733. system header file is included while
  1734. preprocessing assembly. So 1 and 2 are all we
  1735. care about, and they are mutually incompatible.
  1736. new_logical_line_flags() demands this. */
  1737. case 1:
  1738. case 2:
  1739. if (flags && flags != (1 << this_flag))
  1740. as_warn (_("incompatible flag %i in line directive"),
  1741. this_flag);
  1742. else
  1743. flags |= 1 << this_flag;
  1744. break;
  1745. case 3:
  1746. case 4:
  1747. /* We ignore these. */
  1748. break;
  1749. default:
  1750. as_warn (_("unsupported flag %i in line directive"),
  1751. this_flag);
  1752. break;
  1753. }
  1754. if (!is_end_of_line[(unsigned char)*input_line_pointer])
  1755. file = 0;
  1756. }
  1757. }
  1758. if (appline || file)
  1759. {
  1760. new_logical_line_flags (file, l, flags);
  1761. #ifdef LISTING
  1762. if (listing)
  1763. listing_source_line (l);
  1764. #endif
  1765. }
  1766. }
  1767. if (appline || file)
  1768. demand_empty_rest_of_line ();
  1769. else
  1770. ignore_rest_of_line ();
  1771. }
  1772. /* Handle the .end pseudo-op. Actually, the real work is done in
  1773. read_a_source_file. */
  1774. void
  1775. s_end (int ignore ATTRIBUTE_UNUSED)
  1776. {
  1777. if (flag_mri)
  1778. {
  1779. /* The MRI assembler permits the start symbol to follow .end,
  1780. but we don't support that. */
  1781. SKIP_WHITESPACE ();
  1782. if (!is_end_of_line[(unsigned char) *input_line_pointer]
  1783. && *input_line_pointer != '*'
  1784. && *input_line_pointer != '!')
  1785. as_warn (_("start address not supported"));
  1786. }
  1787. }
  1788. /* Handle the .err pseudo-op. */
  1789. void
  1790. s_err (int ignore ATTRIBUTE_UNUSED)
  1791. {
  1792. as_bad (_(".err encountered"));
  1793. demand_empty_rest_of_line ();
  1794. }
  1795. /* Handle the .error and .warning pseudo-ops. */
  1796. void
  1797. s_errwarn (int err)
  1798. {
  1799. int len;
  1800. /* The purpose for the conditional assignment is not to
  1801. internationalize the directive itself, but that we need a
  1802. self-contained message, one that can be passed like the
  1803. demand_copy_C_string return value, and with no assumption on the
  1804. location of the name of the directive within the message. */
  1805. char *msg
  1806. = (err ? _(".error directive invoked in source file")
  1807. : _(".warning directive invoked in source file"));
  1808. if (!is_it_end_of_statement ())
  1809. {
  1810. if (*input_line_pointer != '\"')
  1811. {
  1812. as_bad (_("%s argument must be a string"),
  1813. err ? ".error" : ".warning");
  1814. ignore_rest_of_line ();
  1815. return;
  1816. }
  1817. msg = demand_copy_C_string (&len);
  1818. if (msg == NULL)
  1819. return;
  1820. }
  1821. if (err)
  1822. as_bad ("%s", msg);
  1823. else
  1824. as_warn ("%s", msg);
  1825. demand_empty_rest_of_line ();
  1826. }
  1827. /* Handle the MRI fail pseudo-op. */
  1828. void
  1829. s_fail (int ignore ATTRIBUTE_UNUSED)
  1830. {
  1831. offsetT temp;
  1832. char *stop = NULL;
  1833. char stopc = 0;
  1834. if (flag_mri)
  1835. stop = mri_comment_field (&stopc);
  1836. temp = get_absolute_expression ();
  1837. if (temp >= 500)
  1838. as_warn (_(".fail %ld encountered"), (long) temp);
  1839. else
  1840. as_bad (_(".fail %ld encountered"), (long) temp);
  1841. demand_empty_rest_of_line ();
  1842. if (flag_mri)
  1843. mri_comment_end (stop, stopc);
  1844. }
  1845. void
  1846. s_fill (int ignore ATTRIBUTE_UNUSED)
  1847. {
  1848. expressionS rep_exp;
  1849. long size = 1;
  1850. long fill = 0;
  1851. char *p;
  1852. #ifdef md_flush_pending_output
  1853. md_flush_pending_output ();
  1854. #endif
  1855. #ifdef md_cons_align
  1856. md_cons_align (1);
  1857. #endif
  1858. get_known_segmented_expression (&rep_exp);
  1859. if (*input_line_pointer == ',')
  1860. {
  1861. input_line_pointer++;
  1862. size = get_absolute_expression ();
  1863. if (*input_line_pointer == ',')
  1864. {
  1865. input_line_pointer++;
  1866. fill = get_absolute_expression ();
  1867. }
  1868. }
  1869. /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
  1870. #define BSD_FILL_SIZE_CROCK_8 (8)
  1871. if (size > BSD_FILL_SIZE_CROCK_8)
  1872. {
  1873. as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
  1874. size = BSD_FILL_SIZE_CROCK_8;
  1875. }
  1876. if (size < 0)
  1877. {
  1878. as_warn (_("size negative; .fill ignored"));
  1879. size = 0;
  1880. }
  1881. else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
  1882. {
  1883. if (rep_exp.X_add_number < 0)
  1884. as_warn (_("repeat < 0; .fill ignored"));
  1885. size = 0;
  1886. }
  1887. if (size && !need_pass_2)
  1888. {
  1889. if (rep_exp.X_op == O_constant)
  1890. {
  1891. p = frag_var (rs_fill, (int) size, (int) size,
  1892. (relax_substateT) 0, (symbolS *) 0,
  1893. (offsetT) rep_exp.X_add_number,
  1894. (char *) 0);
  1895. }
  1896. else
  1897. {
  1898. /* We don't have a constant repeat count, so we can't use
  1899. rs_fill. We can get the same results out of rs_space,
  1900. but its argument is in bytes, so we must multiply the
  1901. repeat count by size. */
  1902. symbolS *rep_sym;
  1903. rep_sym = make_expr_symbol (&rep_exp);
  1904. if (size != 1)
  1905. {
  1906. expressionS size_exp;
  1907. size_exp.X_op = O_constant;
  1908. size_exp.X_add_number = size;
  1909. rep_exp.X_op = O_multiply;
  1910. rep_exp.X_add_symbol = rep_sym;
  1911. rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
  1912. rep_exp.X_add_number = 0;
  1913. rep_sym = make_expr_symbol (&rep_exp);
  1914. }
  1915. p = frag_var (rs_space, (int) size, (int) size,
  1916. (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
  1917. }
  1918. memset (p, 0, (unsigned int) size);
  1919. /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
  1920. flavoured AS. The following bizarre behaviour is to be
  1921. compatible with above. I guess they tried to take up to 8
  1922. bytes from a 4-byte expression and they forgot to sign
  1923. extend. */
  1924. #define BSD_FILL_SIZE_CROCK_4 (4)
  1925. md_number_to_chars (p, (valueT) fill,
  1926. (size > BSD_FILL_SIZE_CROCK_4
  1927. ? BSD_FILL_SIZE_CROCK_4
  1928. : (int) size));
  1929. /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
  1930. but emits no error message because it seems a legal thing to do.
  1931. It is a degenerate case of .fill but could be emitted by a
  1932. compiler. */
  1933. }
  1934. demand_empty_rest_of_line ();
  1935. }
  1936. void
  1937. s_globl (int ignore ATTRIBUTE_UNUSED)
  1938. {
  1939. char *name;
  1940. int c;
  1941. symbolS *symbolP;
  1942. char *stop = NULL;
  1943. char stopc = 0;
  1944. if (flag_mri)
  1945. stop = mri_comment_field (&stopc);
  1946. do
  1947. {
  1948. if ((name = read_symbol_name ()) == NULL)
  1949. return;
  1950. symbolP = symbol_find_or_make (name);
  1951. S_SET_EXTERNAL (symbolP);
  1952. SKIP_WHITESPACE ();
  1953. c = *input_line_pointer;
  1954. if (c == ',')
  1955. {
  1956. input_line_pointer++;
  1957. SKIP_WHITESPACE ();
  1958. if (is_end_of_line[(unsigned char) *input_line_pointer])
  1959. c = '\n';
  1960. }
  1961. free (name);
  1962. }
  1963. while (c == ',');
  1964. demand_empty_rest_of_line ();
  1965. if (flag_mri)
  1966. mri_comment_end (stop, stopc);
  1967. }
  1968. /* Handle the MRI IRP and IRPC pseudo-ops. */
  1969. void
  1970. s_irp (int irpc)
  1971. {
  1972. char *file, *eol;
  1973. unsigned int line;
  1974. sb s;
  1975. const char *err;
  1976. sb out;
  1977. as_where (&file, &line);
  1978. eol = find_end_of_line (input_line_pointer, 0);
  1979. sb_build (&s, eol - input_line_pointer);
  1980. sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
  1981. input_line_pointer = eol;
  1982. sb_new (&out);
  1983. err = expand_irp (irpc, 0, &s, &out, get_non_macro_line_sb);
  1984. if (err != NULL)
  1985. as_bad_where (file, line, "%s", err);
  1986. sb_kill (&s);
  1987. input_scrub_include_sb (&out, input_line_pointer, 1);
  1988. sb_kill (&out);
  1989. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  1990. }
  1991. /* Handle the .linkonce pseudo-op. This tells the assembler to mark
  1992. the section to only be linked once. However, this is not supported
  1993. by most object file formats. This takes an optional argument,
  1994. which is what to do about duplicates. */
  1995. void
  1996. s_linkonce (int ignore ATTRIBUTE_UNUSED)
  1997. {
  1998. enum linkonce_type type;
  1999. SKIP_WHITESPACE ();
  2000. type = LINKONCE_DISCARD;
  2001. if (!is_end_of_line[(unsigned char) *input_line_pointer])
  2002. {
  2003. char *s;
  2004. char c;
  2005. c = get_symbol_name (& s);
  2006. if (strcasecmp (s, "discard") == 0)
  2007. type = LINKONCE_DISCARD;
  2008. else if (strcasecmp (s, "one_only") == 0)
  2009. type = LINKONCE_ONE_ONLY;
  2010. else if (strcasecmp (s, "same_size") == 0)
  2011. type = LINKONCE_SAME_SIZE;
  2012. else if (strcasecmp (s, "same_contents") == 0)
  2013. type = LINKONCE_SAME_CONTENTS;
  2014. else
  2015. as_warn (_("unrecognized .linkonce type `%s'"), s);
  2016. (void) restore_line_pointer (c);
  2017. }
  2018. #ifdef obj_handle_link_once
  2019. obj_handle_link_once (type);
  2020. #else /* ! defined (obj_handle_link_once) */
  2021. {
  2022. flagword flags;
  2023. if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
  2024. as_warn (_(".linkonce is not supported for this object file format"));
  2025. flags = bfd_get_section_flags (stdoutput, now_seg);
  2026. flags |= SEC_LINK_ONCE;
  2027. switch (type)
  2028. {
  2029. default:
  2030. abort ();
  2031. case LINKONCE_DISCARD:
  2032. flags |= SEC_LINK_DUPLICATES_DISCARD;
  2033. break;
  2034. case LINKONCE_ONE_ONLY:
  2035. flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
  2036. break;
  2037. case LINKONCE_SAME_SIZE:
  2038. flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
  2039. break;
  2040. case LINKONCE_SAME_CONTENTS:
  2041. flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
  2042. break;
  2043. }
  2044. if (!bfd_set_section_flags (stdoutput, now_seg, flags))
  2045. as_bad (_("bfd_set_section_flags: %s"),
  2046. bfd_errmsg (bfd_get_error ()));
  2047. }
  2048. #endif /* ! defined (obj_handle_link_once) */
  2049. demand_empty_rest_of_line ();
  2050. }
  2051. void
  2052. bss_alloc (symbolS *symbolP, addressT size, int align)
  2053. {
  2054. char *pfrag;
  2055. segT current_seg = now_seg;
  2056. subsegT current_subseg = now_subseg;
  2057. segT bss_seg = bss_section;
  2058. #if defined (TC_MIPS) || defined (TC_ALPHA)
  2059. if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
  2060. || OUTPUT_FLAVOR == bfd_target_elf_flavour)
  2061. {
  2062. /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
  2063. if (size <= bfd_get_gp_size (stdoutput))
  2064. {
  2065. bss_seg = subseg_new (".sbss", 1);
  2066. seg_info (bss_seg)->bss = 1;
  2067. if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
  2068. as_warn (_("error setting flags for \".sbss\": %s"),
  2069. bfd_errmsg (bfd_get_error ()));
  2070. }
  2071. }
  2072. #endif
  2073. subseg_set (bss_seg, 1);
  2074. if (align)
  2075. {
  2076. record_alignment (bss_seg, align);
  2077. frag_align (align, 0, 0);
  2078. }
  2079. /* Detach from old frag. */
  2080. if (S_GET_SEGMENT (symbolP) == bss_seg)
  2081. symbol_get_frag (symbolP)->fr_symbol = NULL;
  2082. symbol_set_frag (symbolP, frag_now);
  2083. pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
  2084. *pfrag = 0;
  2085. #ifdef S_SET_SIZE
  2086. S_SET_SIZE (symbolP, size);
  2087. #endif
  2088. S_SET_SEGMENT (symbolP, bss_seg);
  2089. #ifdef OBJ_COFF
  2090. /* The symbol may already have been created with a preceding
  2091. ".globl" directive -- be careful not to step on storage class
  2092. in that case. Otherwise, set it to static. */
  2093. if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
  2094. S_SET_STORAGE_CLASS (symbolP, C_STAT);
  2095. #endif /* OBJ_COFF */
  2096. subseg_set (current_seg, current_subseg);
  2097. }
  2098. offsetT
  2099. parse_align (int align_bytes)
  2100. {
  2101. expressionS exp;
  2102. addressT align;
  2103. SKIP_WHITESPACE ();
  2104. if (*input_line_pointer != ',')
  2105. {
  2106. no_align:
  2107. as_bad (_("expected alignment after size"));
  2108. ignore_rest_of_line ();
  2109. return -1;
  2110. }
  2111. input_line_pointer++;
  2112. SKIP_WHITESPACE ();
  2113. align = get_absolute_expr (&exp);
  2114. if (exp.X_op == O_absent)
  2115. goto no_align;
  2116. if (!exp.X_unsigned)
  2117. {
  2118. as_warn (_("alignment negative; 0 assumed"));
  2119. align = 0;
  2120. }
  2121. if (align_bytes && align != 0)
  2122. {
  2123. /* convert to a power of 2 alignment */
  2124. unsigned int alignp2 = 0;
  2125. while ((align & 1) == 0)
  2126. align >>= 1, ++alignp2;
  2127. if (align != 1)
  2128. {
  2129. as_bad (_("alignment not a power of 2"));
  2130. ignore_rest_of_line ();
  2131. return -1;
  2132. }
  2133. align = alignp2;
  2134. }
  2135. return align;
  2136. }
  2137. /* Called from s_comm_internal after symbol name and size have been
  2138. parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
  2139. 1 if this was a ".bss" directive which has a 3rd argument
  2140. (alignment as a power of 2), or 2 if this was a ".bss" directive
  2141. with alignment in bytes. */
  2142. symbolS *
  2143. s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
  2144. {
  2145. addressT align = 0;
  2146. if (needs_align)
  2147. {
  2148. align = parse_align (needs_align - 1);
  2149. if (align == (addressT) -1)
  2150. return NULL;
  2151. }
  2152. else
  2153. /* Assume some objects may require alignment on some systems. */
  2154. TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
  2155. bss_alloc (symbolP, size, align);
  2156. return symbolP;
  2157. }
  2158. void
  2159. s_lcomm (int needs_align)
  2160. {
  2161. s_comm_internal (needs_align, s_lcomm_internal);
  2162. }
  2163. void
  2164. s_lcomm_bytes (int needs_align)
  2165. {
  2166. s_comm_internal (needs_align * 2, s_lcomm_internal);
  2167. }
  2168. void
  2169. s_lsym (int ignore ATTRIBUTE_UNUSED)
  2170. {
  2171. char *name;
  2172. expressionS exp;
  2173. symbolS *symbolP;
  2174. /* We permit ANY defined expression: BSD4.2 demands constants. */
  2175. if ((name = read_symbol_name ()) == NULL)
  2176. return;
  2177. if (*input_line_pointer != ',')
  2178. {
  2179. as_bad (_("expected comma after \"%s\""), name);
  2180. goto err_out;
  2181. }
  2182. input_line_pointer++;
  2183. expression_and_evaluate (&exp);
  2184. if (exp.X_op != O_constant
  2185. && exp.X_op != O_register)
  2186. {
  2187. as_bad (_("bad expression"));
  2188. goto err_out;
  2189. }
  2190. symbolP = symbol_find_or_make (name);
  2191. if (S_GET_SEGMENT (symbolP) == undefined_section)
  2192. {
  2193. /* The name might be an undefined .global symbol; be sure to
  2194. keep the "external" bit. */
  2195. S_SET_SEGMENT (symbolP,
  2196. (exp.X_op == O_constant
  2197. ? absolute_section
  2198. : reg_section));
  2199. S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
  2200. }
  2201. else
  2202. {
  2203. as_bad (_("symbol `%s' is already defined"), name);
  2204. }
  2205. demand_empty_rest_of_line ();
  2206. free (name);
  2207. return;
  2208. err_out:
  2209. ignore_rest_of_line ();
  2210. free (name);
  2211. return;
  2212. }
  2213. /* Read a line into an sb. Returns the character that ended the line
  2214. or zero if there are no more lines. */
  2215. static int
  2216. get_line_sb (sb *line, int in_macro)
  2217. {
  2218. char *eol;
  2219. if (input_line_pointer[-1] == '\n')
  2220. bump_line_counters ();
  2221. if (input_line_pointer >= buffer_limit)
  2222. {
  2223. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  2224. if (buffer_limit == 0)
  2225. return 0;
  2226. }
  2227. eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
  2228. sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
  2229. input_line_pointer = eol;
  2230. /* Don't skip multiple end-of-line characters, because that breaks support
  2231. for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
  2232. characters but isn't. Instead just skip one end of line character and
  2233. return the character skipped so that the caller can re-insert it if
  2234. necessary. */
  2235. return *input_line_pointer++;
  2236. }
  2237. static size_t
  2238. get_non_macro_line_sb (sb *line)
  2239. {
  2240. return get_line_sb (line, 0);
  2241. }
  2242. static size_t
  2243. get_macro_line_sb (sb *line)
  2244. {
  2245. return get_line_sb (line, 1);
  2246. }
  2247. /* Define a macro. This is an interface to macro.c. */
  2248. void
  2249. s_macro (int ignore ATTRIBUTE_UNUSED)
  2250. {
  2251. char *file, *eol;
  2252. unsigned int line;
  2253. sb s;
  2254. const char *err;
  2255. const char *name;
  2256. as_where (&file, &line);
  2257. eol = find_end_of_line (input_line_pointer, 0);
  2258. sb_build (&s, eol - input_line_pointer);
  2259. sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
  2260. input_line_pointer = eol;
  2261. if (line_label != NULL)
  2262. {
  2263. sb label;
  2264. size_t len;
  2265. name = S_GET_NAME (line_label);
  2266. len = strlen (name);
  2267. sb_build (&label, len);
  2268. sb_add_buffer (&label, name, len);
  2269. err = define_macro (0, &s, &label, get_macro_line_sb, file, line, &name);
  2270. sb_kill (&label);
  2271. }
  2272. else
  2273. err = define_macro (0, &s, NULL, get_macro_line_sb, file, line, &name);
  2274. if (err != NULL)
  2275. as_bad_where (file, line, err, name);
  2276. else
  2277. {
  2278. if (line_label != NULL)
  2279. {
  2280. S_SET_SEGMENT (line_label, absolute_section);
  2281. S_SET_VALUE (line_label, 0);
  2282. symbol_set_frag (line_label, &zero_address_frag);
  2283. }
  2284. if (((NO_PSEUDO_DOT || flag_m68k_mri)
  2285. && hash_find (po_hash, name) != NULL)
  2286. || (!flag_m68k_mri
  2287. && *name == '.'
  2288. && hash_find (po_hash, name + 1) != NULL))
  2289. as_warn_where (file,
  2290. line,
  2291. _("attempt to redefine pseudo-op `%s' ignored"),
  2292. name);
  2293. }
  2294. sb_kill (&s);
  2295. }
  2296. /* Handle the .mexit pseudo-op, which immediately exits a macro
  2297. expansion. */
  2298. void
  2299. s_mexit (int ignore ATTRIBUTE_UNUSED)
  2300. {
  2301. if (macro_nest)
  2302. {
  2303. cond_exit_macro (macro_nest);
  2304. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  2305. }
  2306. else
  2307. as_warn (_("ignoring macro exit outside a macro definition."));
  2308. }
  2309. /* Switch in and out of MRI mode. */
  2310. void
  2311. s_mri (int ignore ATTRIBUTE_UNUSED)
  2312. {
  2313. int on;
  2314. #ifdef MRI_MODE_CHANGE
  2315. int old_flag;
  2316. #endif
  2317. on = get_absolute_expression ();
  2318. #ifdef MRI_MODE_CHANGE
  2319. old_flag = flag_mri;
  2320. #endif
  2321. if (on != 0)
  2322. {
  2323. flag_mri = 1;
  2324. #ifdef TC_M68K
  2325. flag_m68k_mri = 1;
  2326. #endif
  2327. macro_mri_mode (1);
  2328. }
  2329. else
  2330. {
  2331. flag_mri = 0;
  2332. #ifdef TC_M68K
  2333. flag_m68k_mri = 0;
  2334. #endif
  2335. macro_mri_mode (0);
  2336. }
  2337. /* Operator precedence changes in m68k MRI mode, so we need to
  2338. update the operator rankings. */
  2339. expr_set_precedence ();
  2340. #ifdef MRI_MODE_CHANGE
  2341. if (on != old_flag)
  2342. MRI_MODE_CHANGE (on);
  2343. #endif
  2344. demand_empty_rest_of_line ();
  2345. }
  2346. /* Handle changing the location counter. */
  2347. static void
  2348. do_org (segT segment, expressionS *exp, int fill)
  2349. {
  2350. if (segment != now_seg
  2351. && segment != absolute_section
  2352. && segment != expr_section)
  2353. as_bad (_("invalid segment \"%s\""), segment_name (segment));
  2354. if (now_seg == absolute_section)
  2355. {
  2356. if (fill != 0)
  2357. as_warn (_("ignoring fill value in absolute section"));
  2358. if (exp->X_op != O_constant)
  2359. {
  2360. as_bad (_("only constant offsets supported in absolute section"));
  2361. exp->X_add_number = 0;
  2362. }
  2363. abs_section_offset = exp->X_add_number;
  2364. }
  2365. else
  2366. {
  2367. char *p;
  2368. symbolS *sym = exp->X_add_symbol;
  2369. offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
  2370. if (exp->X_op != O_constant && exp->X_op != O_symbol)
  2371. {
  2372. /* Handle complex expressions. */
  2373. sym = make_expr_symbol (exp);
  2374. off = 0;
  2375. }
  2376. p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
  2377. *p = fill;
  2378. }
  2379. }
  2380. void
  2381. s_org (int ignore ATTRIBUTE_UNUSED)
  2382. {
  2383. segT segment;
  2384. expressionS exp;
  2385. long temp_fill;
  2386. #ifdef md_flush_pending_output
  2387. md_flush_pending_output ();
  2388. #endif
  2389. /* The m68k MRI assembler has a different meaning for .org. It
  2390. means to create an absolute section at a given address. We can't
  2391. support that--use a linker script instead. */
  2392. if (flag_m68k_mri)
  2393. {
  2394. as_bad (_("MRI style ORG pseudo-op not supported"));
  2395. ignore_rest_of_line ();
  2396. return;
  2397. }
  2398. /* Don't believe the documentation of BSD 4.2 AS. There is no such
  2399. thing as a sub-segment-relative origin. Any absolute origin is
  2400. given a warning, then assumed to be segment-relative. Any
  2401. segmented origin expression ("foo+42") had better be in the right
  2402. segment or the .org is ignored.
  2403. BSD 4.2 AS warns if you try to .org backwards. We cannot because
  2404. we never know sub-segment sizes when we are reading code. BSD
  2405. will crash trying to emit negative numbers of filler bytes in
  2406. certain .orgs. We don't crash, but see as-write for that code.
  2407. Don't make frag if need_pass_2==1. */
  2408. segment = get_known_segmented_expression (&exp);
  2409. if (*input_line_pointer == ',')
  2410. {
  2411. input_line_pointer++;
  2412. temp_fill = get_absolute_expression ();
  2413. }
  2414. else
  2415. temp_fill = 0;
  2416. if (!need_pass_2)
  2417. do_org (segment, &exp, temp_fill);
  2418. demand_empty_rest_of_line ();
  2419. }
  2420. /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
  2421. called by the obj-format routine which handles section changing
  2422. when in MRI mode. It will create a new section, and return it. It
  2423. will set *TYPE to the section type: one of 'C' (code), 'D' (data),
  2424. 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
  2425. void
  2426. s_mri_sect (char *type ATTRIBUTE_UNUSED)
  2427. {
  2428. #ifdef TC_M68K
  2429. char *name;
  2430. char c;
  2431. segT seg;
  2432. SKIP_WHITESPACE ();
  2433. name = input_line_pointer;
  2434. if (!ISDIGIT (*name))
  2435. c = get_symbol_name (& name);
  2436. else
  2437. {
  2438. do
  2439. {
  2440. ++input_line_pointer;
  2441. }
  2442. while (ISDIGIT (*input_line_pointer));
  2443. c = *input_line_pointer;
  2444. *input_line_pointer = '\0';
  2445. }
  2446. name = xstrdup (name);
  2447. c = restore_line_pointer (c);
  2448. seg = subseg_new (name, 0);
  2449. if (c == ',')
  2450. {
  2451. int align;
  2452. ++input_line_pointer;
  2453. align = get_absolute_expression ();
  2454. record_alignment (seg, align);
  2455. }
  2456. *type = 'C';
  2457. if (*input_line_pointer == ',')
  2458. {
  2459. c = *++input_line_pointer;
  2460. c = TOUPPER (c);
  2461. if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
  2462. *type = c;
  2463. else
  2464. as_bad (_("unrecognized section type"));
  2465. ++input_line_pointer;
  2466. {
  2467. flagword flags;
  2468. flags = SEC_NO_FLAGS;
  2469. if (*type == 'C')
  2470. flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
  2471. else if (*type == 'D' || *type == 'M')
  2472. flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
  2473. else if (*type == 'R')
  2474. flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
  2475. if (flags != SEC_NO_FLAGS)
  2476. {
  2477. if (!bfd_set_section_flags (stdoutput, seg, flags))
  2478. as_warn (_("error setting flags for \"%s\": %s"),
  2479. bfd_section_name (stdoutput, seg),
  2480. bfd_errmsg (bfd_get_error ()));
  2481. }
  2482. }
  2483. }
  2484. /* Ignore the HP type. */
  2485. if (*input_line_pointer == ',')
  2486. input_line_pointer += 2;
  2487. demand_empty_rest_of_line ();
  2488. #else /* ! TC_M68K */
  2489. #ifdef TC_I960
  2490. char *name;
  2491. char c;
  2492. segT seg;
  2493. SKIP_WHITESPACE ();
  2494. c = get_symbol_name (& name);
  2495. name = xstrdup (name);
  2496. c = restore_line_pointer (c);
  2497. seg = subseg_new (name, 0);
  2498. if (c != ',')
  2499. *type = 'C';
  2500. else
  2501. {
  2502. char *sectype;
  2503. ++input_line_pointer;
  2504. SKIP_WHITESPACE ();
  2505. c = get_symbol_name (& sectype);
  2506. if (*sectype == '\0')
  2507. *type = 'C';
  2508. else if (strcasecmp (sectype, "text") == 0)
  2509. *type = 'C';
  2510. else if (strcasecmp (sectype, "data") == 0)
  2511. *type = 'D';
  2512. else if (strcasecmp (sectype, "romdata") == 0)
  2513. *type = 'R';
  2514. else
  2515. as_warn (_("unrecognized section type `%s'"), sectype);
  2516. (void) restore_line_pointer (c);
  2517. }
  2518. if (*input_line_pointer == ',')
  2519. {
  2520. char *seccmd;
  2521. ++input_line_pointer;
  2522. SKIP_WHITESPACE ();
  2523. c = get_symbol_name (& seccmd);
  2524. if (strcasecmp (seccmd, "absolute") == 0)
  2525. {
  2526. as_bad (_("absolute sections are not supported"));
  2527. *input_line_pointer = c;
  2528. ignore_rest_of_line ();
  2529. return;
  2530. }
  2531. else if (strcasecmp (seccmd, "align") == 0)
  2532. {
  2533. int align;
  2534. (void) restore_line_pointer (c);
  2535. align = get_absolute_expression ();
  2536. record_alignment (seg, align);
  2537. }
  2538. else
  2539. {
  2540. as_warn (_("unrecognized section command `%s'"), seccmd);
  2541. (void) restore_line_pointer (c);
  2542. }
  2543. }
  2544. demand_empty_rest_of_line ();
  2545. #else /* ! TC_I960 */
  2546. /* The MRI assembler seems to use different forms of .sect for
  2547. different targets. */
  2548. as_bad ("MRI mode not supported for this target");
  2549. ignore_rest_of_line ();
  2550. #endif /* ! TC_I960 */
  2551. #endif /* ! TC_M68K */
  2552. }
  2553. /* Handle the .print pseudo-op. */
  2554. void
  2555. s_print (int ignore ATTRIBUTE_UNUSED)
  2556. {
  2557. char *s;
  2558. int len;
  2559. s = demand_copy_C_string (&len);
  2560. if (s != NULL)
  2561. printf ("%s\n", s);
  2562. demand_empty_rest_of_line ();
  2563. }
  2564. /* Handle the .purgem pseudo-op. */
  2565. void
  2566. s_purgem (int ignore ATTRIBUTE_UNUSED)
  2567. {
  2568. if (is_it_end_of_statement ())
  2569. {
  2570. demand_empty_rest_of_line ();
  2571. return;
  2572. }
  2573. do
  2574. {
  2575. char *name;
  2576. char c;
  2577. SKIP_WHITESPACE ();
  2578. c = get_symbol_name (& name);
  2579. delete_macro (name);
  2580. *input_line_pointer = c;
  2581. SKIP_WHITESPACE_AFTER_NAME ();
  2582. }
  2583. while (*input_line_pointer++ == ',');
  2584. --input_line_pointer;
  2585. demand_empty_rest_of_line ();
  2586. }
  2587. /* Handle the .endm/.endr pseudo-ops. */
  2588. static void
  2589. s_bad_end (int endr)
  2590. {
  2591. as_warn (_(".end%c encountered without preceding %s"),
  2592. endr ? 'r' : 'm',
  2593. endr ? ".rept, .irp, or .irpc" : ".macro");
  2594. demand_empty_rest_of_line ();
  2595. }
  2596. /* Handle the .rept pseudo-op. */
  2597. void
  2598. s_rept (int ignore ATTRIBUTE_UNUSED)
  2599. {
  2600. int count;
  2601. count = get_absolute_expression ();
  2602. do_repeat (count, "REPT", "ENDR");
  2603. }
  2604. /* This function provides a generic repeat block implementation. It allows
  2605. different directives to be used as the start/end keys. */
  2606. void
  2607. do_repeat (int count, const char *start, const char *end)
  2608. {
  2609. sb one;
  2610. sb many;
  2611. sb_new (&one);
  2612. if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
  2613. {
  2614. as_bad (_("%s without %s"), start, end);
  2615. return;
  2616. }
  2617. sb_build (&many, count * one.len);
  2618. while (count-- > 0)
  2619. sb_add_sb (&many, &one);
  2620. sb_kill (&one);
  2621. input_scrub_include_sb (&many, input_line_pointer, 1);
  2622. sb_kill (&many);
  2623. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  2624. }
  2625. /* Like do_repeat except that any text matching EXPANDER in the
  2626. block is replaced by the itteration count. */
  2627. void
  2628. do_repeat_with_expander (int count,
  2629. const char * start,
  2630. const char * end,
  2631. const char * expander)
  2632. {
  2633. sb one;
  2634. sb many;
  2635. sb_new (&one);
  2636. if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
  2637. {
  2638. as_bad (_("%s without %s"), start, end);
  2639. return;
  2640. }
  2641. sb_new (&many);
  2642. if (expander != NULL && strstr (one.ptr, expander) != NULL)
  2643. {
  2644. while (count -- > 0)
  2645. {
  2646. int len;
  2647. char * sub;
  2648. sb processed;
  2649. sb_build (& processed, one.len);
  2650. sb_add_sb (& processed, & one);
  2651. sub = strstr (processed.ptr, expander);
  2652. len = sprintf (sub, "%d", count);
  2653. gas_assert (len < 8);
  2654. strcpy (sub + len, sub + 8);
  2655. processed.len -= (8 - len);
  2656. sb_add_sb (& many, & processed);
  2657. sb_kill (& processed);
  2658. }
  2659. }
  2660. else
  2661. while (count-- > 0)
  2662. sb_add_sb (&many, &one);
  2663. sb_kill (&one);
  2664. input_scrub_include_sb (&many, input_line_pointer, 1);
  2665. sb_kill (&many);
  2666. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  2667. }
  2668. /* Skip to end of current repeat loop; EXTRA indicates how many additional
  2669. input buffers to skip. Assumes that conditionals preceding the loop end
  2670. are properly nested.
  2671. This function makes it easier to implement a premature "break" out of the
  2672. loop. The EXTRA arg accounts for other buffers we might have inserted,
  2673. such as line substitutions. */
  2674. void
  2675. end_repeat (int extra)
  2676. {
  2677. cond_exit_macro (macro_nest);
  2678. while (extra-- >= 0)
  2679. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  2680. }
  2681. static void
  2682. assign_symbol (char *name, int mode)
  2683. {
  2684. symbolS *symbolP;
  2685. if (name[0] == '.' && name[1] == '\0')
  2686. {
  2687. /* Turn '. = mumble' into a .org mumble. */
  2688. segT segment;
  2689. expressionS exp;
  2690. segment = get_known_segmented_expression (&exp);
  2691. if (!need_pass_2)
  2692. do_org (segment, &exp, 0);
  2693. return;
  2694. }
  2695. if ((symbolP = symbol_find (name)) == NULL
  2696. && (symbolP = md_undefined_symbol (name)) == NULL)
  2697. {
  2698. symbolP = symbol_find_or_make (name);
  2699. #ifndef NO_LISTING
  2700. /* When doing symbol listings, play games with dummy fragments living
  2701. outside the normal fragment chain to record the file and line info
  2702. for this symbol. */
  2703. if (listing & LISTING_SYMBOLS)
  2704. {
  2705. extern struct list_info_struct *listing_tail;
  2706. fragS *dummy_frag = (fragS *) xcalloc (1, sizeof (fragS));
  2707. dummy_frag->line = listing_tail;
  2708. dummy_frag->fr_symbol = symbolP;
  2709. symbol_set_frag (symbolP, dummy_frag);
  2710. }
  2711. #endif
  2712. #if defined (OBJ_COFF) && !defined (TE_PE)
  2713. /* "set" symbols are local unless otherwise specified. */
  2714. SF_SET_LOCAL (symbolP);
  2715. #endif
  2716. }
  2717. if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
  2718. {
  2719. if ((mode != 0 || !S_IS_VOLATILE (symbolP))
  2720. && !S_CAN_BE_REDEFINED (symbolP))
  2721. {
  2722. as_bad (_("symbol `%s' is already defined"), name);
  2723. symbolP = symbol_clone (symbolP, 0);
  2724. }
  2725. /* If the symbol is volatile, copy the symbol and replace the
  2726. original with the copy, so that previous uses of the symbol will
  2727. retain the value of the symbol at the point of use. */
  2728. else if (S_IS_VOLATILE (symbolP))
  2729. symbolP = symbol_clone (symbolP, 1);
  2730. }
  2731. if (mode == 0)
  2732. S_SET_VOLATILE (symbolP);
  2733. else if (mode < 0)
  2734. S_SET_FORWARD_REF (symbolP);
  2735. pseudo_set (symbolP);
  2736. }
  2737. /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
  2738. then this is .equiv, and it is an error if the symbol is already
  2739. defined. If EQUIV is -1, the symbol additionally is a forward
  2740. reference. */
  2741. void
  2742. s_set (int equiv)
  2743. {
  2744. char *name;
  2745. /* Especial apologies for the random logic:
  2746. this just grew, and could be parsed much more simply!
  2747. Dean in haste. */
  2748. if ((name = read_symbol_name ()) == NULL)
  2749. return;
  2750. if (*input_line_pointer != ',')
  2751. {
  2752. as_bad (_("expected comma after \"%s\""), name);
  2753. ignore_rest_of_line ();
  2754. free (name);
  2755. return;
  2756. }
  2757. input_line_pointer++;
  2758. assign_symbol (name, equiv);
  2759. demand_empty_rest_of_line ();
  2760. free (name);
  2761. }
  2762. void
  2763. s_space (int mult)
  2764. {
  2765. expressionS exp;
  2766. expressionS val;
  2767. char *p = 0;
  2768. char *stop = NULL;
  2769. char stopc = 0;
  2770. int bytes;
  2771. #ifdef md_flush_pending_output
  2772. md_flush_pending_output ();
  2773. #endif
  2774. #ifdef md_cons_align
  2775. md_cons_align (1);
  2776. #endif
  2777. if (flag_mri)
  2778. stop = mri_comment_field (&stopc);
  2779. /* In m68k MRI mode, we need to align to a word boundary, unless
  2780. this is ds.b. */
  2781. if (flag_m68k_mri && mult > 1)
  2782. {
  2783. if (now_seg == absolute_section)
  2784. {
  2785. abs_section_offset += abs_section_offset & 1;
  2786. if (line_label != NULL)
  2787. S_SET_VALUE (line_label, abs_section_offset);
  2788. }
  2789. else if (mri_common_symbol != NULL)
  2790. {
  2791. valueT mri_val;
  2792. mri_val = S_GET_VALUE (mri_common_symbol);
  2793. if ((mri_val & 1) != 0)
  2794. {
  2795. S_SET_VALUE (mri_common_symbol, mri_val + 1);
  2796. if (line_label != NULL)
  2797. {
  2798. expressionS *symexp;
  2799. symexp = symbol_get_value_expression (line_label);
  2800. know (symexp->X_op == O_symbol);
  2801. know (symexp->X_add_symbol == mri_common_symbol);
  2802. symexp->X_add_number += 1;
  2803. }
  2804. }
  2805. }
  2806. else
  2807. {
  2808. do_align (1, (char *) NULL, 0, 0);
  2809. if (line_label != NULL)
  2810. {
  2811. symbol_set_frag (line_label, frag_now);
  2812. S_SET_VALUE (line_label, frag_now_fix ());
  2813. }
  2814. }
  2815. }
  2816. bytes = mult;
  2817. expression (&exp);
  2818. SKIP_WHITESPACE ();
  2819. if (*input_line_pointer == ',')
  2820. {
  2821. ++input_line_pointer;
  2822. expression (&val);
  2823. }
  2824. else
  2825. {
  2826. val.X_op = O_constant;
  2827. val.X_add_number = 0;
  2828. }
  2829. if (val.X_op != O_constant
  2830. || val.X_add_number < - 0x80
  2831. || val.X_add_number > 0xff
  2832. || (mult != 0 && mult != 1 && val.X_add_number != 0))
  2833. {
  2834. resolve_expression (&exp);
  2835. if (exp.X_op != O_constant)
  2836. as_bad (_("unsupported variable size or fill value"));
  2837. else
  2838. {
  2839. offsetT i;
  2840. if (mult == 0)
  2841. mult = 1;
  2842. bytes = mult * exp.X_add_number;
  2843. for (i = 0; i < exp.X_add_number; i++)
  2844. emit_expr (&val, mult);
  2845. }
  2846. }
  2847. else
  2848. {
  2849. if (now_seg == absolute_section || mri_common_symbol != NULL)
  2850. resolve_expression (&exp);
  2851. if (exp.X_op == O_constant)
  2852. {
  2853. offsetT repeat;
  2854. repeat = exp.X_add_number;
  2855. if (mult)
  2856. repeat *= mult;
  2857. bytes = repeat;
  2858. if (repeat <= 0)
  2859. {
  2860. if (!flag_mri)
  2861. as_warn (_(".space repeat count is zero, ignored"));
  2862. else if (repeat < 0)
  2863. as_warn (_(".space repeat count is negative, ignored"));
  2864. goto getout;
  2865. }
  2866. /* If we are in the absolute section, just bump the offset. */
  2867. if (now_seg == absolute_section)
  2868. {
  2869. abs_section_offset += repeat;
  2870. goto getout;
  2871. }
  2872. /* If we are secretly in an MRI common section, then
  2873. creating space just increases the size of the common
  2874. symbol. */
  2875. if (mri_common_symbol != NULL)
  2876. {
  2877. S_SET_VALUE (mri_common_symbol,
  2878. S_GET_VALUE (mri_common_symbol) + repeat);
  2879. goto getout;
  2880. }
  2881. if (!need_pass_2)
  2882. p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
  2883. (offsetT) repeat, (char *) 0);
  2884. }
  2885. else
  2886. {
  2887. if (now_seg == absolute_section)
  2888. {
  2889. as_bad (_("space allocation too complex in absolute section"));
  2890. subseg_set (text_section, 0);
  2891. }
  2892. if (mri_common_symbol != NULL)
  2893. {
  2894. as_bad (_("space allocation too complex in common section"));
  2895. mri_common_symbol = NULL;
  2896. }
  2897. if (!need_pass_2)
  2898. p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
  2899. make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
  2900. }
  2901. if (p)
  2902. *p = val.X_add_number;
  2903. }
  2904. getout:
  2905. /* In MRI mode, after an odd number of bytes, we must align to an
  2906. even word boundary, unless the next instruction is a dc.b, ds.b
  2907. or dcb.b. */
  2908. if (flag_mri && (bytes & 1) != 0)
  2909. mri_pending_align = 1;
  2910. demand_empty_rest_of_line ();
  2911. if (flag_mri)
  2912. mri_comment_end (stop, stopc);
  2913. }
  2914. /* This is like s_space, but the value is a floating point number with
  2915. the given precision. This is for the MRI dcb.s pseudo-op and
  2916. friends. */
  2917. void
  2918. s_float_space (int float_type)
  2919. {
  2920. offsetT count;
  2921. int flen;
  2922. char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
  2923. char *stop = NULL;
  2924. char stopc = 0;
  2925. #ifdef md_cons_align
  2926. md_cons_align (1);
  2927. #endif
  2928. if (flag_mri)
  2929. stop = mri_comment_field (&stopc);
  2930. count = get_absolute_expression ();
  2931. SKIP_WHITESPACE ();
  2932. if (*input_line_pointer != ',')
  2933. {
  2934. as_bad (_("missing value"));
  2935. ignore_rest_of_line ();
  2936. if (flag_mri)
  2937. mri_comment_end (stop, stopc);
  2938. return;
  2939. }
  2940. ++input_line_pointer;
  2941. SKIP_WHITESPACE ();
  2942. /* Skip any 0{letter} that may be present. Don't even check if the
  2943. * letter is legal. */
  2944. if (input_line_pointer[0] == '0'
  2945. && ISALPHA (input_line_pointer[1]))
  2946. input_line_pointer += 2;
  2947. /* Accept :xxxx, where the x's are hex digits, for a floating point
  2948. with the exact digits specified. */
  2949. if (input_line_pointer[0] == ':')
  2950. {
  2951. flen = hex_float (float_type, temp);
  2952. if (flen < 0)
  2953. {
  2954. ignore_rest_of_line ();
  2955. if (flag_mri)
  2956. mri_comment_end (stop, stopc);
  2957. return;
  2958. }
  2959. }
  2960. else
  2961. {
  2962. char *err;
  2963. err = md_atof (float_type, temp, &flen);
  2964. know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
  2965. know (err != NULL || flen > 0);
  2966. if (err)
  2967. {
  2968. as_bad (_("bad floating literal: %s"), err);
  2969. ignore_rest_of_line ();
  2970. if (flag_mri)
  2971. mri_comment_end (stop, stopc);
  2972. return;
  2973. }
  2974. }
  2975. while (--count >= 0)
  2976. {
  2977. char *p;
  2978. p = frag_more (flen);
  2979. memcpy (p, temp, (unsigned int) flen);
  2980. }
  2981. demand_empty_rest_of_line ();
  2982. if (flag_mri)
  2983. mri_comment_end (stop, stopc);
  2984. }
  2985. /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
  2986. void
  2987. s_struct (int ignore ATTRIBUTE_UNUSED)
  2988. {
  2989. char *stop = NULL;
  2990. char stopc = 0;
  2991. if (flag_mri)
  2992. stop = mri_comment_field (&stopc);
  2993. abs_section_offset = get_absolute_expression ();
  2994. #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
  2995. /* The ELF backend needs to know that we are changing sections, so
  2996. that .previous works correctly. */
  2997. if (IS_ELF)
  2998. obj_elf_section_change_hook ();
  2999. #endif
  3000. subseg_set (absolute_section, 0);
  3001. demand_empty_rest_of_line ();
  3002. if (flag_mri)
  3003. mri_comment_end (stop, stopc);
  3004. }
  3005. void
  3006. s_text (int ignore ATTRIBUTE_UNUSED)
  3007. {
  3008. int temp;
  3009. temp = get_absolute_expression ();
  3010. subseg_set (text_section, (subsegT) temp);
  3011. demand_empty_rest_of_line ();
  3012. }
  3013. /* .weakref x, y sets x as an alias to y that, as long as y is not
  3014. referenced directly, will cause y to become a weak symbol. */
  3015. void
  3016. s_weakref (int ignore ATTRIBUTE_UNUSED)
  3017. {
  3018. char *name;
  3019. symbolS *symbolP;
  3020. symbolS *symbolP2;
  3021. expressionS exp;
  3022. if ((name = read_symbol_name ()) == NULL)
  3023. return;
  3024. symbolP = symbol_find_or_make (name);
  3025. if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
  3026. {
  3027. if (!S_IS_VOLATILE (symbolP))
  3028. {
  3029. as_bad (_("symbol `%s' is already defined"), name);
  3030. goto err_out;
  3031. }
  3032. symbolP = symbol_clone (symbolP, 1);
  3033. S_CLEAR_VOLATILE (symbolP);
  3034. }
  3035. SKIP_WHITESPACE ();
  3036. if (*input_line_pointer != ',')
  3037. {
  3038. as_bad (_("expected comma after \"%s\""), name);
  3039. goto err_out;
  3040. }
  3041. input_line_pointer++;
  3042. SKIP_WHITESPACE ();
  3043. free (name);
  3044. if ((name = read_symbol_name ()) == NULL)
  3045. return;
  3046. if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
  3047. && (symbolP2 = md_undefined_symbol (name)) == NULL)
  3048. {
  3049. symbolP2 = symbol_find_or_make (name);
  3050. S_SET_WEAKREFD (symbolP2);
  3051. }
  3052. else
  3053. {
  3054. symbolS *symp = symbolP2;
  3055. while (S_IS_WEAKREFR (symp) && symp != symbolP)
  3056. {
  3057. expressionS *expP = symbol_get_value_expression (symp);
  3058. gas_assert (expP->X_op == O_symbol
  3059. && expP->X_add_number == 0);
  3060. symp = expP->X_add_symbol;
  3061. }
  3062. if (symp == symbolP)
  3063. {
  3064. char *loop;
  3065. loop = concat (S_GET_NAME (symbolP),
  3066. " => ", S_GET_NAME (symbolP2), (const char *) NULL);
  3067. symp = symbolP2;
  3068. while (symp != symbolP)
  3069. {
  3070. char *old_loop = loop;
  3071. symp = symbol_get_value_expression (symp)->X_add_symbol;
  3072. loop = concat (loop, " => ", S_GET_NAME (symp),
  3073. (const char *) NULL);
  3074. free (old_loop);
  3075. }
  3076. as_bad (_("%s: would close weakref loop: %s"),
  3077. S_GET_NAME (symbolP), loop);
  3078. free (loop);
  3079. free (name);
  3080. ignore_rest_of_line ();
  3081. return;
  3082. }
  3083. /* Short-circuiting instead of just checking here might speed
  3084. things up a tiny little bit, but loop error messages would
  3085. miss intermediate links. */
  3086. /* symbolP2 = symp; */
  3087. }
  3088. memset (&exp, 0, sizeof (exp));
  3089. exp.X_op = O_symbol;
  3090. exp.X_add_symbol = symbolP2;
  3091. S_SET_SEGMENT (symbolP, undefined_section);
  3092. symbol_set_value_expression (symbolP, &exp);
  3093. symbol_set_frag (symbolP, &zero_address_frag);
  3094. S_SET_WEAKREFR (symbolP);
  3095. demand_empty_rest_of_line ();
  3096. free (name);
  3097. return;
  3098. err_out:
  3099. ignore_rest_of_line ();
  3100. free (name);
  3101. return;
  3102. }
  3103. /* Verify that we are at the end of a line. If not, issue an error and
  3104. skip to EOL. */
  3105. void
  3106. demand_empty_rest_of_line (void)
  3107. {
  3108. SKIP_WHITESPACE ();
  3109. if (is_end_of_line[(unsigned char) *input_line_pointer])
  3110. input_line_pointer++;
  3111. else
  3112. {
  3113. if (ISPRINT (*input_line_pointer))
  3114. as_bad (_("junk at end of line, first unrecognized character is `%c'"),
  3115. *input_line_pointer);
  3116. else
  3117. as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
  3118. *input_line_pointer);
  3119. ignore_rest_of_line ();
  3120. }
  3121. /* Return pointing just after end-of-line. */
  3122. know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
  3123. }
  3124. /* Silently advance to the end of line. Use this after already having
  3125. issued an error about something bad. */
  3126. void
  3127. ignore_rest_of_line (void)
  3128. {
  3129. while (input_line_pointer < buffer_limit
  3130. && !is_end_of_line[(unsigned char) *input_line_pointer])
  3131. input_line_pointer++;
  3132. input_line_pointer++;
  3133. /* Return pointing just after end-of-line. */
  3134. know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
  3135. }
  3136. /* Sets frag for given symbol to zero_address_frag, except when the
  3137. symbol frag is already set to a dummy listing frag. */
  3138. static void
  3139. set_zero_frag (symbolS *symbolP)
  3140. {
  3141. if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
  3142. symbol_set_frag (symbolP, &zero_address_frag);
  3143. }
  3144. /* In: Pointer to a symbol.
  3145. Input_line_pointer->expression.
  3146. Out: Input_line_pointer->just after any whitespace after expression.
  3147. Tried to set symbol to value of expression.
  3148. Will change symbols type, value, and frag; */
  3149. void
  3150. pseudo_set (symbolS *symbolP)
  3151. {
  3152. expressionS exp;
  3153. segT seg;
  3154. know (symbolP); /* NULL pointer is logic error. */
  3155. if (!S_IS_FORWARD_REF (symbolP))
  3156. (void) expression (&exp);
  3157. else
  3158. (void) deferred_expression (&exp);
  3159. if (exp.X_op == O_illegal)
  3160. as_bad (_("illegal expression"));
  3161. else if (exp.X_op == O_absent)
  3162. as_bad (_("missing expression"));
  3163. else if (exp.X_op == O_big)
  3164. {
  3165. if (exp.X_add_number > 0)
  3166. as_bad (_("bignum invalid"));
  3167. else
  3168. as_bad (_("floating point number invalid"));
  3169. }
  3170. else if (exp.X_op == O_subtract
  3171. && !S_IS_FORWARD_REF (symbolP)
  3172. && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
  3173. && (symbol_get_frag (exp.X_add_symbol)
  3174. == symbol_get_frag (exp.X_op_symbol)))
  3175. {
  3176. exp.X_op = O_constant;
  3177. exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
  3178. - S_GET_VALUE (exp.X_op_symbol));
  3179. }
  3180. if (symbol_section_p (symbolP))
  3181. {
  3182. as_bad ("attempt to set value of section symbol");
  3183. return;
  3184. }
  3185. switch (exp.X_op)
  3186. {
  3187. case O_illegal:
  3188. case O_absent:
  3189. case O_big:
  3190. exp.X_add_number = 0;
  3191. /* Fall through. */
  3192. case O_constant:
  3193. S_SET_SEGMENT (symbolP, absolute_section);
  3194. S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
  3195. set_zero_frag (symbolP);
  3196. break;
  3197. case O_register:
  3198. #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
  3199. if (S_IS_EXTERNAL (symbolP))
  3200. {
  3201. as_bad ("can't equate global symbol `%s' with register name",
  3202. S_GET_NAME (symbolP));
  3203. return;
  3204. }
  3205. #endif
  3206. S_SET_SEGMENT (symbolP, reg_section);
  3207. S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
  3208. set_zero_frag (symbolP);
  3209. symbol_get_value_expression (symbolP)->X_op = O_register;
  3210. break;
  3211. case O_symbol:
  3212. seg = S_GET_SEGMENT (exp.X_add_symbol);
  3213. /* For x=undef+const, create an expression symbol.
  3214. For x=x+const, just update x except when x is an undefined symbol
  3215. For x=defined+const, evaluate x. */
  3216. if (symbolP == exp.X_add_symbol
  3217. && (seg != undefined_section
  3218. || !symbol_constant_p (symbolP)))
  3219. {
  3220. *symbol_X_add_number (symbolP) += exp.X_add_number;
  3221. break;
  3222. }
  3223. else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
  3224. {
  3225. symbolS *s = exp.X_add_symbol;
  3226. if (S_IS_COMMON (s))
  3227. as_bad (_("`%s' can't be equated to common symbol '%s'"),
  3228. S_GET_NAME (symbolP), S_GET_NAME (s));
  3229. S_SET_SEGMENT (symbolP, seg);
  3230. S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
  3231. symbol_set_frag (symbolP, symbol_get_frag (s));
  3232. copy_symbol_attributes (symbolP, s);
  3233. break;
  3234. }
  3235. S_SET_SEGMENT (symbolP, undefined_section);
  3236. symbol_set_value_expression (symbolP, &exp);
  3237. copy_symbol_attributes (symbolP, exp.X_add_symbol);
  3238. set_zero_frag (symbolP);
  3239. break;
  3240. default:
  3241. /* The value is some complex expression. */
  3242. S_SET_SEGMENT (symbolP, expr_section);
  3243. symbol_set_value_expression (symbolP, &exp);
  3244. set_zero_frag (symbolP);
  3245. break;
  3246. }
  3247. }
  3248. /* cons()
  3249. CONStruct more frag of .bytes, or .words etc.
  3250. Should need_pass_2 be 1 then emit no frag(s).
  3251. This understands EXPRESSIONS.
  3252. Bug (?)
  3253. This has a split personality. We use expression() to read the
  3254. value. We can detect if the value won't fit in a byte or word.
  3255. But we can't detect if expression() discarded significant digits
  3256. in the case of a long. Not worth the crocks required to fix it. */
  3257. /* Select a parser for cons expressions. */
  3258. /* Some targets need to parse the expression in various fancy ways.
  3259. You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
  3260. (for example, the HPPA does this). Otherwise, you can define
  3261. BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
  3262. REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
  3263. are defined, which is the normal case, then only simple expressions
  3264. are permitted. */
  3265. #ifdef TC_M68K
  3266. static void
  3267. parse_mri_cons (expressionS *exp, unsigned int nbytes);
  3268. #endif
  3269. #ifndef TC_PARSE_CONS_EXPRESSION
  3270. #ifdef BITFIELD_CONS_EXPRESSIONS
  3271. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
  3272. (parse_bitfield_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
  3273. static void
  3274. parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
  3275. #endif
  3276. #ifdef REPEAT_CONS_EXPRESSIONS
  3277. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
  3278. (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
  3279. static void
  3280. parse_repeat_cons (expressionS *exp, unsigned int nbytes);
  3281. #endif
  3282. /* If we haven't gotten one yet, just call expression. */
  3283. #ifndef TC_PARSE_CONS_EXPRESSION
  3284. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
  3285. (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
  3286. #endif
  3287. #endif
  3288. void
  3289. do_parse_cons_expression (expressionS *exp,
  3290. int nbytes ATTRIBUTE_UNUSED)
  3291. {
  3292. (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
  3293. }
  3294. /* Worker to do .byte etc statements.
  3295. Clobbers input_line_pointer and checks end-of-line. */
  3296. static void
  3297. cons_worker (int nbytes, /* 1=.byte, 2=.word, 4=.long. */
  3298. int rva)
  3299. {
  3300. int c;
  3301. expressionS exp;
  3302. char *stop = NULL;
  3303. char stopc = 0;
  3304. #ifdef md_flush_pending_output
  3305. md_flush_pending_output ();
  3306. #endif
  3307. if (flag_mri)
  3308. stop = mri_comment_field (&stopc);
  3309. if (is_it_end_of_statement ())
  3310. {
  3311. demand_empty_rest_of_line ();
  3312. if (flag_mri)
  3313. mri_comment_end (stop, stopc);
  3314. return;
  3315. }
  3316. #ifdef TC_ADDRESS_BYTES
  3317. if (nbytes == 0)
  3318. nbytes = TC_ADDRESS_BYTES ();
  3319. #endif
  3320. #ifdef md_cons_align
  3321. md_cons_align (nbytes);
  3322. #endif
  3323. c = 0;
  3324. do
  3325. {
  3326. TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
  3327. #ifdef TC_CONS_FIX_CHECK
  3328. fixS **cur_fix = &frchain_now->fix_tail;
  3329. if (*cur_fix != NULL)
  3330. cur_fix = &(*cur_fix)->fx_next;
  3331. #endif
  3332. #ifdef TC_M68K
  3333. if (flag_m68k_mri)
  3334. parse_mri_cons (&exp, (unsigned int) nbytes);
  3335. else
  3336. #endif
  3337. {
  3338. #if 0
  3339. if (*input_line_pointer == '"')
  3340. {
  3341. as_bad (_("unexpected `\"' in expression"));
  3342. ignore_rest_of_line ();
  3343. return;
  3344. }
  3345. #endif
  3346. ret = TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
  3347. }
  3348. if (rva)
  3349. {
  3350. if (exp.X_op == O_symbol)
  3351. exp.X_op = O_symbol_rva;
  3352. else
  3353. as_fatal (_("rva without symbol"));
  3354. }
  3355. emit_expr_with_reloc (&exp, (unsigned int) nbytes, ret);
  3356. #ifdef TC_CONS_FIX_CHECK
  3357. TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
  3358. #endif
  3359. ++c;
  3360. }
  3361. while (*input_line_pointer++ == ',');
  3362. /* In MRI mode, after an odd number of bytes, we must align to an
  3363. even word boundary, unless the next instruction is a dc.b, ds.b
  3364. or dcb.b. */
  3365. if (flag_mri && nbytes == 1 && (c & 1) != 0)
  3366. mri_pending_align = 1;
  3367. input_line_pointer--; /* Put terminator back into stream. */
  3368. demand_empty_rest_of_line ();
  3369. if (flag_mri)
  3370. mri_comment_end (stop, stopc);
  3371. }
  3372. void
  3373. cons (int size)
  3374. {
  3375. cons_worker (size, 0);
  3376. }
  3377. void
  3378. s_rva (int size)
  3379. {
  3380. cons_worker (size, 1);
  3381. }
  3382. /* .reloc offset, reloc_name, symbol+addend. */
  3383. static void
  3384. s_reloc (int ignore ATTRIBUTE_UNUSED)
  3385. {
  3386. char *stop = NULL;
  3387. char stopc = 0;
  3388. expressionS exp;
  3389. char *r_name;
  3390. int c;
  3391. struct reloc_list *reloc;
  3392. struct _bfd_rel { char *name; bfd_reloc_code_real_type code; };
  3393. static struct _bfd_rel bfd_relocs[] = {
  3394. { "NONE", BFD_RELOC_NONE },
  3395. { "8", BFD_RELOC_8 },
  3396. { "16", BFD_RELOC_16 },
  3397. { "32", BFD_RELOC_32 },
  3398. { "64", BFD_RELOC_64 }
  3399. };
  3400. reloc = (struct reloc_list *) xmalloc (sizeof (*reloc));
  3401. if (flag_mri)
  3402. stop = mri_comment_field (&stopc);
  3403. expression (&exp);
  3404. switch (exp.X_op)
  3405. {
  3406. case O_illegal:
  3407. case O_absent:
  3408. case O_big:
  3409. case O_register:
  3410. as_bad (_("missing or bad offset expression"));
  3411. goto err_out;
  3412. case O_constant:
  3413. exp.X_add_symbol = section_symbol (now_seg);
  3414. exp.X_op = O_symbol;
  3415. /* Fall thru */
  3416. case O_symbol:
  3417. if (exp.X_add_number == 0)
  3418. {
  3419. reloc->u.a.offset_sym = exp.X_add_symbol;
  3420. break;
  3421. }
  3422. /* Fall thru */
  3423. default:
  3424. reloc->u.a.offset_sym = make_expr_symbol (&exp);
  3425. break;
  3426. }
  3427. SKIP_WHITESPACE ();
  3428. if (*input_line_pointer != ',')
  3429. {
  3430. as_bad (_("missing reloc type"));
  3431. goto err_out;
  3432. }
  3433. ++input_line_pointer;
  3434. SKIP_WHITESPACE ();
  3435. c = get_symbol_name (& r_name);
  3436. if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
  3437. {
  3438. unsigned int i;
  3439. for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
  3440. if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
  3441. {
  3442. reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
  3443. bfd_relocs[i].code);
  3444. break;
  3445. }
  3446. }
  3447. else
  3448. reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
  3449. *input_line_pointer = c;
  3450. if (reloc->u.a.howto == NULL)
  3451. {
  3452. as_bad (_("unrecognized reloc type"));
  3453. goto err_out;
  3454. }
  3455. exp.X_op = O_absent;
  3456. SKIP_WHITESPACE_AFTER_NAME ();
  3457. if (*input_line_pointer == ',')
  3458. {
  3459. ++input_line_pointer;
  3460. expression (&exp);
  3461. }
  3462. switch (exp.X_op)
  3463. {
  3464. case O_illegal:
  3465. case O_big:
  3466. case O_register:
  3467. as_bad (_("bad reloc expression"));
  3468. err_out:
  3469. ignore_rest_of_line ();
  3470. free (reloc);
  3471. if (flag_mri)
  3472. mri_comment_end (stop, stopc);
  3473. return;
  3474. case O_absent:
  3475. reloc->u.a.sym = NULL;
  3476. reloc->u.a.addend = 0;
  3477. break;
  3478. case O_constant:
  3479. reloc->u.a.sym = NULL;
  3480. reloc->u.a.addend = exp.X_add_number;
  3481. break;
  3482. case O_symbol:
  3483. reloc->u.a.sym = exp.X_add_symbol;
  3484. reloc->u.a.addend = exp.X_add_number;
  3485. break;
  3486. default:
  3487. reloc->u.a.sym = make_expr_symbol (&exp);
  3488. reloc->u.a.addend = 0;
  3489. break;
  3490. }
  3491. as_where (&reloc->file, &reloc->line);
  3492. reloc->next = reloc_list;
  3493. reloc_list = reloc;
  3494. demand_empty_rest_of_line ();
  3495. if (flag_mri)
  3496. mri_comment_end (stop, stopc);
  3497. }
  3498. /* Put the contents of expression EXP into the object file using
  3499. NBYTES bytes. If need_pass_2 is 1, this does nothing. */
  3500. void
  3501. emit_expr (expressionS *exp, unsigned int nbytes)
  3502. {
  3503. emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
  3504. }
  3505. void
  3506. emit_expr_with_reloc (expressionS *exp,
  3507. unsigned int nbytes,
  3508. TC_PARSE_CONS_RETURN_TYPE reloc)
  3509. {
  3510. operatorT op;
  3511. char *p;
  3512. valueT extra_digit = 0;
  3513. /* Don't do anything if we are going to make another pass. */
  3514. if (need_pass_2)
  3515. return;
  3516. frag_grow (nbytes);
  3517. dot_value = frag_now_fix ();
  3518. dot_frag = frag_now;
  3519. #ifndef NO_LISTING
  3520. #ifdef OBJ_ELF
  3521. /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
  3522. appear as a four byte positive constant in the .line section,
  3523. followed by a 2 byte 0xffff. Look for that case here. */
  3524. {
  3525. static int dwarf_line = -1;
  3526. if (strcmp (segment_name (now_seg), ".line") != 0)
  3527. dwarf_line = -1;
  3528. else if (dwarf_line >= 0
  3529. && nbytes == 2
  3530. && exp->X_op == O_constant
  3531. && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
  3532. listing_source_line ((unsigned int) dwarf_line);
  3533. else if (nbytes == 4
  3534. && exp->X_op == O_constant
  3535. && exp->X_add_number >= 0)
  3536. dwarf_line = exp->X_add_number;
  3537. else
  3538. dwarf_line = -1;
  3539. }
  3540. /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
  3541. appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
  3542. AT_sibling (0x12) followed by a four byte address of the sibling
  3543. followed by a 2 byte AT_name (0x38) followed by the name of the
  3544. file. We look for that case here. */
  3545. {
  3546. static int dwarf_file = 0;
  3547. if (strcmp (segment_name (now_seg), ".debug") != 0)
  3548. dwarf_file = 0;
  3549. else if (dwarf_file == 0
  3550. && nbytes == 2
  3551. && exp->X_op == O_constant
  3552. && exp->X_add_number == 0x11)
  3553. dwarf_file = 1;
  3554. else if (dwarf_file == 1
  3555. && nbytes == 2
  3556. && exp->X_op == O_constant
  3557. && exp->X_add_number == 0x12)
  3558. dwarf_file = 2;
  3559. else if (dwarf_file == 2
  3560. && nbytes == 4)
  3561. dwarf_file = 3;
  3562. else if (dwarf_file == 3
  3563. && nbytes == 2
  3564. && exp->X_op == O_constant
  3565. && exp->X_add_number == 0x38)
  3566. dwarf_file = 4;
  3567. else
  3568. dwarf_file = 0;
  3569. /* The variable dwarf_file_string tells stringer that the string
  3570. may be the name of the source file. */
  3571. if (dwarf_file == 4)
  3572. dwarf_file_string = 1;
  3573. else
  3574. dwarf_file_string = 0;
  3575. }
  3576. #endif
  3577. #endif
  3578. if (check_eh_frame (exp, &nbytes))
  3579. return;
  3580. op = exp->X_op;
  3581. /* Allow `.word 0' in the absolute section. */
  3582. if (now_seg == absolute_section)
  3583. {
  3584. if (op != O_constant || exp->X_add_number != 0)
  3585. as_bad (_("attempt to store value in absolute section"));
  3586. abs_section_offset += nbytes;
  3587. return;
  3588. }
  3589. /* Handle a negative bignum. */
  3590. if (op == O_uminus
  3591. && exp->X_add_number == 0
  3592. && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
  3593. && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
  3594. {
  3595. int i;
  3596. unsigned long carry;
  3597. exp = symbol_get_value_expression (exp->X_add_symbol);
  3598. /* Negate the bignum: one's complement each digit and add 1. */
  3599. carry = 1;
  3600. for (i = 0; i < exp->X_add_number; i++)
  3601. {
  3602. unsigned long next;
  3603. next = (((~(generic_bignum[i] & LITTLENUM_MASK))
  3604. & LITTLENUM_MASK)
  3605. + carry);
  3606. generic_bignum[i] = next & LITTLENUM_MASK;
  3607. carry = next >> LITTLENUM_NUMBER_OF_BITS;
  3608. }
  3609. /* We can ignore any carry out, because it will be handled by
  3610. extra_digit if it is needed. */
  3611. extra_digit = (valueT) -1;
  3612. op = O_big;
  3613. }
  3614. if (op == O_absent || op == O_illegal)
  3615. {
  3616. as_warn (_("zero assumed for missing expression"));
  3617. exp->X_add_number = 0;
  3618. op = O_constant;
  3619. }
  3620. else if (op == O_big && exp->X_add_number <= 0)
  3621. {
  3622. as_bad (_("floating point number invalid"));
  3623. exp->X_add_number = 0;
  3624. op = O_constant;
  3625. }
  3626. else if (op == O_register)
  3627. {
  3628. as_warn (_("register value used as expression"));
  3629. op = O_constant;
  3630. }
  3631. p = frag_more ((int) nbytes);
  3632. if (reloc != TC_PARSE_CONS_RETURN_NONE)
  3633. {
  3634. emit_expr_fix (exp, nbytes, frag_now, p, reloc);
  3635. return;
  3636. }
  3637. #ifndef WORKING_DOT_WORD
  3638. /* If we have the difference of two symbols in a word, save it on
  3639. the broken_words list. See the code in write.c. */
  3640. if (op == O_subtract && nbytes == 2)
  3641. {
  3642. struct broken_word *x;
  3643. x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
  3644. x->next_broken_word = broken_words;
  3645. broken_words = x;
  3646. x->seg = now_seg;
  3647. x->subseg = now_subseg;
  3648. x->frag = frag_now;
  3649. x->word_goes_here = p;
  3650. x->dispfrag = 0;
  3651. x->add = exp->X_add_symbol;
  3652. x->sub = exp->X_op_symbol;
  3653. x->addnum = exp->X_add_number;
  3654. x->added = 0;
  3655. x->use_jump = 0;
  3656. new_broken_words++;
  3657. return;
  3658. }
  3659. #endif
  3660. /* If we have an integer, but the number of bytes is too large to
  3661. pass to md_number_to_chars, handle it as a bignum. */
  3662. if (op == O_constant && nbytes > sizeof (valueT))
  3663. {
  3664. extra_digit = exp->X_unsigned ? 0 : -1;
  3665. convert_to_bignum (exp, !exp->X_unsigned);
  3666. op = O_big;
  3667. }
  3668. if (op == O_constant)
  3669. {
  3670. valueT get;
  3671. valueT use;
  3672. valueT mask;
  3673. valueT hibit;
  3674. valueT unmask;
  3675. /* JF << of >= number of bits in the object is undefined. In
  3676. particular SPARC (Sun 4) has problems. */
  3677. if (nbytes >= sizeof (valueT))
  3678. {
  3679. mask = 0;
  3680. if (nbytes > sizeof (valueT))
  3681. hibit = 0;
  3682. else
  3683. hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
  3684. }
  3685. else
  3686. {
  3687. /* Don't store these bits. */
  3688. mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
  3689. hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
  3690. }
  3691. unmask = ~mask; /* Do store these bits. */
  3692. #ifdef NEVER
  3693. "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
  3694. mask = ~(unmask >> 1); /* Includes sign bit now. */
  3695. #endif
  3696. get = exp->X_add_number;
  3697. use = get & unmask;
  3698. if ((get & mask) != 0
  3699. && ((get & mask) != mask
  3700. || (get & hibit) == 0))
  3701. { /* Leading bits contain both 0s & 1s. */
  3702. #if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
  3703. #ifndef __MSVCRT__
  3704. as_warn (_("value 0x%llx truncated to 0x%llx"),
  3705. (unsigned long long) get, (unsigned long long) use);
  3706. #else
  3707. as_warn (_("value 0x%I64x truncated to 0x%I64x"),
  3708. (unsigned long long) get, (unsigned long long) use);
  3709. #endif
  3710. #else
  3711. as_warn (_("value 0x%lx truncated to 0x%lx"),
  3712. (unsigned long) get, (unsigned long) use);
  3713. #endif
  3714. }
  3715. /* Put bytes in right order. */
  3716. md_number_to_chars (p, use, (int) nbytes);
  3717. }
  3718. else if (op == O_big)
  3719. {
  3720. unsigned int size;
  3721. LITTLENUM_TYPE *nums;
  3722. size = exp->X_add_number * CHARS_PER_LITTLENUM;
  3723. if (nbytes < size)
  3724. {
  3725. int i = nbytes / CHARS_PER_LITTLENUM;
  3726. if (i != 0)
  3727. {
  3728. LITTLENUM_TYPE sign = 0;
  3729. if ((generic_bignum[--i]
  3730. & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
  3731. sign = ~(LITTLENUM_TYPE) 0;
  3732. while (++i < exp->X_add_number)
  3733. if (generic_bignum[i] != sign)
  3734. break;
  3735. }
  3736. if (i < exp->X_add_number)
  3737. as_warn (_("bignum truncated to %d bytes"), nbytes);
  3738. size = nbytes;
  3739. }
  3740. if (nbytes == 1)
  3741. {
  3742. md_number_to_chars (p, (valueT) generic_bignum[0], 1);
  3743. return;
  3744. }
  3745. know (nbytes % CHARS_PER_LITTLENUM == 0);
  3746. if (target_big_endian)
  3747. {
  3748. while (nbytes > size)
  3749. {
  3750. md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
  3751. nbytes -= CHARS_PER_LITTLENUM;
  3752. p += CHARS_PER_LITTLENUM;
  3753. }
  3754. nums = generic_bignum + size / CHARS_PER_LITTLENUM;
  3755. while (size >= CHARS_PER_LITTLENUM)
  3756. {
  3757. --nums;
  3758. md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
  3759. size -= CHARS_PER_LITTLENUM;
  3760. p += CHARS_PER_LITTLENUM;
  3761. }
  3762. }
  3763. else
  3764. {
  3765. nums = generic_bignum;
  3766. while (size >= CHARS_PER_LITTLENUM)
  3767. {
  3768. md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
  3769. ++nums;
  3770. size -= CHARS_PER_LITTLENUM;
  3771. p += CHARS_PER_LITTLENUM;
  3772. nbytes -= CHARS_PER_LITTLENUM;
  3773. }
  3774. while (nbytes >= CHARS_PER_LITTLENUM)
  3775. {
  3776. md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
  3777. nbytes -= CHARS_PER_LITTLENUM;
  3778. p += CHARS_PER_LITTLENUM;
  3779. }
  3780. }
  3781. }
  3782. else
  3783. emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
  3784. }
  3785. void
  3786. emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
  3787. TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
  3788. {
  3789. int offset = 0;
  3790. unsigned int size = nbytes;
  3791. memset (p, 0, size);
  3792. /* Generate a fixS to record the symbol value. */
  3793. #ifdef TC_CONS_FIX_NEW
  3794. TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
  3795. #else
  3796. if (r != TC_PARSE_CONS_RETURN_NONE)
  3797. {
  3798. reloc_howto_type *reloc_howto;
  3799. reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
  3800. size = bfd_get_reloc_size (reloc_howto);
  3801. if (size > nbytes)
  3802. {
  3803. as_bad (_("%s relocations do not fit in %u bytes\n"),
  3804. reloc_howto->name, nbytes);
  3805. return;
  3806. }
  3807. else if (target_big_endian)
  3808. offset = nbytes - size;
  3809. }
  3810. else
  3811. switch (size)
  3812. {
  3813. case 1:
  3814. r = BFD_RELOC_8;
  3815. break;
  3816. case 2:
  3817. r = BFD_RELOC_16;
  3818. break;
  3819. case 3:
  3820. r = BFD_RELOC_24;
  3821. break;
  3822. case 4:
  3823. r = BFD_RELOC_32;
  3824. break;
  3825. case 8:
  3826. r = BFD_RELOC_64;
  3827. break;
  3828. default:
  3829. as_bad (_("unsupported BFD relocation size %u"), size);
  3830. return;
  3831. }
  3832. fix_new_exp (frag, p - frag->fr_literal + offset, size,
  3833. exp, 0, r);
  3834. #endif
  3835. }
  3836. #ifdef BITFIELD_CONS_EXPRESSIONS
  3837. /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
  3838. w:x,y:z, where w and y are bitwidths and x and y are values. They
  3839. then pack them all together. We do a little better in that we allow
  3840. them in words, longs, etc. and we'll pack them in target byte order
  3841. for you.
  3842. The rules are: pack least significant bit first, if a field doesn't
  3843. entirely fit, put it in the next unit. Overflowing the bitfield is
  3844. explicitly *not* even a warning. The bitwidth should be considered
  3845. a "mask".
  3846. To use this function the tc-XXX.h file should define
  3847. BITFIELD_CONS_EXPRESSIONS. */
  3848. static void
  3849. parse_bitfield_cons (exp, nbytes)
  3850. expressionS *exp;
  3851. unsigned int nbytes;
  3852. {
  3853. unsigned int bits_available = BITS_PER_CHAR * nbytes;
  3854. char *hold = input_line_pointer;
  3855. (void) expression (exp);
  3856. if (*input_line_pointer == ':')
  3857. {
  3858. /* Bitfields. */
  3859. long value = 0;
  3860. for (;;)
  3861. {
  3862. unsigned long width;
  3863. if (*input_line_pointer != ':')
  3864. {
  3865. input_line_pointer = hold;
  3866. break;
  3867. } /* Next piece is not a bitfield. */
  3868. /* In the general case, we can't allow
  3869. full expressions with symbol
  3870. differences and such. The relocation
  3871. entries for symbols not defined in this
  3872. assembly would require arbitrary field
  3873. widths, positions, and masks which most
  3874. of our current object formats don't
  3875. support.
  3876. In the specific case where a symbol
  3877. *is* defined in this assembly, we
  3878. *could* build fixups and track it, but
  3879. this could lead to confusion for the
  3880. backends. I'm lazy. I'll take any
  3881. SEG_ABSOLUTE. I think that means that
  3882. you can use a previous .set or
  3883. .equ type symbol. xoxorich. */
  3884. if (exp->X_op == O_absent)
  3885. {
  3886. as_warn (_("using a bit field width of zero"));
  3887. exp->X_add_number = 0;
  3888. exp->X_op = O_constant;
  3889. } /* Implied zero width bitfield. */
  3890. if (exp->X_op != O_constant)
  3891. {
  3892. *input_line_pointer = '\0';
  3893. as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
  3894. *input_line_pointer = ':';
  3895. demand_empty_rest_of_line ();
  3896. return;
  3897. } /* Too complex. */
  3898. if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
  3899. {
  3900. as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
  3901. width, nbytes, (BITS_PER_CHAR * nbytes));
  3902. width = BITS_PER_CHAR * nbytes;
  3903. } /* Too big. */
  3904. if (width > bits_available)
  3905. {
  3906. /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
  3907. input_line_pointer = hold;
  3908. exp->X_add_number = value;
  3909. break;
  3910. } /* Won't fit. */
  3911. /* Skip ':'. */
  3912. hold = ++input_line_pointer;
  3913. (void) expression (exp);
  3914. if (exp->X_op != O_constant)
  3915. {
  3916. char cache = *input_line_pointer;
  3917. *input_line_pointer = '\0';
  3918. as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
  3919. *input_line_pointer = cache;
  3920. demand_empty_rest_of_line ();
  3921. return;
  3922. } /* Too complex. */
  3923. value |= ((~(-1 << width) & exp->X_add_number)
  3924. << ((BITS_PER_CHAR * nbytes) - bits_available));
  3925. if ((bits_available -= width) == 0
  3926. || is_it_end_of_statement ()
  3927. || *input_line_pointer != ',')
  3928. {
  3929. break;
  3930. } /* All the bitfields we're gonna get. */
  3931. hold = ++input_line_pointer;
  3932. (void) expression (exp);
  3933. }
  3934. exp->X_add_number = value;
  3935. exp->X_op = O_constant;
  3936. exp->X_unsigned = 1;
  3937. exp->X_extrabit = 0;
  3938. }
  3939. }
  3940. #endif /* BITFIELD_CONS_EXPRESSIONS */
  3941. /* Handle an MRI style string expression. */
  3942. #ifdef TC_M68K
  3943. static void
  3944. parse_mri_cons (expressionS *exp, unsigned int nbytes)
  3945. {
  3946. if (*input_line_pointer != '\''
  3947. && (input_line_pointer[1] != '\''
  3948. || (*input_line_pointer != 'A'
  3949. && *input_line_pointer != 'E')))
  3950. (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
  3951. else
  3952. {
  3953. unsigned int scan;
  3954. unsigned int result = 0;
  3955. /* An MRI style string. Cut into as many bytes as will fit into
  3956. a nbyte chunk, left justify if necessary, and separate with
  3957. commas so we can try again later. */
  3958. if (*input_line_pointer == 'A')
  3959. ++input_line_pointer;
  3960. else if (*input_line_pointer == 'E')
  3961. {
  3962. as_bad (_("EBCDIC constants are not supported"));
  3963. ++input_line_pointer;
  3964. }
  3965. input_line_pointer++;
  3966. for (scan = 0; scan < nbytes; scan++)
  3967. {
  3968. if (*input_line_pointer == '\'')
  3969. {
  3970. if (input_line_pointer[1] == '\'')
  3971. {
  3972. input_line_pointer++;
  3973. }
  3974. else
  3975. break;
  3976. }
  3977. result = (result << 8) | (*input_line_pointer++);
  3978. }
  3979. /* Left justify. */
  3980. while (scan < nbytes)
  3981. {
  3982. result <<= 8;
  3983. scan++;
  3984. }
  3985. /* Create correct expression. */
  3986. exp->X_op = O_constant;
  3987. exp->X_add_number = result;
  3988. /* Fake it so that we can read the next char too. */
  3989. if (input_line_pointer[0] != '\'' ||
  3990. (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
  3991. {
  3992. input_line_pointer -= 2;
  3993. input_line_pointer[0] = ',';
  3994. input_line_pointer[1] = '\'';
  3995. }
  3996. else
  3997. input_line_pointer++;
  3998. }
  3999. }
  4000. #endif /* TC_M68K */
  4001. #ifdef REPEAT_CONS_EXPRESSIONS
  4002. /* Parse a repeat expression for cons. This is used by the MIPS
  4003. assembler. The format is NUMBER:COUNT; NUMBER appears in the
  4004. object file COUNT times.
  4005. To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
  4006. static void
  4007. parse_repeat_cons (exp, nbytes)
  4008. expressionS *exp;
  4009. unsigned int nbytes;
  4010. {
  4011. expressionS count;
  4012. int i;
  4013. expression (exp);
  4014. if (*input_line_pointer != ':')
  4015. {
  4016. /* No repeat count. */
  4017. return;
  4018. }
  4019. ++input_line_pointer;
  4020. expression (&count);
  4021. if (count.X_op != O_constant
  4022. || count.X_add_number <= 0)
  4023. {
  4024. as_warn (_("unresolvable or nonpositive repeat count; using 1"));
  4025. return;
  4026. }
  4027. /* The cons function is going to output this expression once. So we
  4028. output it count - 1 times. */
  4029. for (i = count.X_add_number - 1; i > 0; i--)
  4030. emit_expr (exp, nbytes);
  4031. }
  4032. #endif /* REPEAT_CONS_EXPRESSIONS */
  4033. /* Parse a floating point number represented as a hex constant. This
  4034. permits users to specify the exact bits they want in the floating
  4035. point number. */
  4036. static int
  4037. hex_float (int float_type, char *bytes)
  4038. {
  4039. int length;
  4040. int i;
  4041. switch (float_type)
  4042. {
  4043. case 'f':
  4044. case 'F':
  4045. case 's':
  4046. case 'S':
  4047. length = 4;
  4048. break;
  4049. case 'd':
  4050. case 'D':
  4051. case 'r':
  4052. case 'R':
  4053. length = 8;
  4054. break;
  4055. case 'x':
  4056. case 'X':
  4057. length = 12;
  4058. break;
  4059. case 'p':
  4060. case 'P':
  4061. length = 12;
  4062. break;
  4063. default:
  4064. as_bad (_("unknown floating type type '%c'"), float_type);
  4065. return -1;
  4066. }
  4067. /* It would be nice if we could go through expression to parse the
  4068. hex constant, but if we get a bignum it's a pain to sort it into
  4069. the buffer correctly. */
  4070. i = 0;
  4071. while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
  4072. {
  4073. int d;
  4074. /* The MRI assembler accepts arbitrary underscores strewn about
  4075. through the hex constant, so we ignore them as well. */
  4076. if (*input_line_pointer == '_')
  4077. {
  4078. ++input_line_pointer;
  4079. continue;
  4080. }
  4081. if (i >= length)
  4082. {
  4083. as_warn (_("floating point constant too large"));
  4084. return -1;
  4085. }
  4086. d = hex_value (*input_line_pointer) << 4;
  4087. ++input_line_pointer;
  4088. while (*input_line_pointer == '_')
  4089. ++input_line_pointer;
  4090. if (hex_p (*input_line_pointer))
  4091. {
  4092. d += hex_value (*input_line_pointer);
  4093. ++input_line_pointer;
  4094. }
  4095. if (target_big_endian)
  4096. bytes[i] = d;
  4097. else
  4098. bytes[length - i - 1] = d;
  4099. ++i;
  4100. }
  4101. if (i < length)
  4102. {
  4103. if (target_big_endian)
  4104. memset (bytes + i, 0, length - i);
  4105. else
  4106. memset (bytes, 0, length - i);
  4107. }
  4108. return length;
  4109. }
  4110. /* float_cons()
  4111. CONStruct some more frag chars of .floats .ffloats etc.
  4112. Makes 0 or more new frags.
  4113. If need_pass_2 == 1, no frags are emitted.
  4114. This understands only floating literals, not expressions. Sorry.
  4115. A floating constant is defined by atof_generic(), except it is preceded
  4116. by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
  4117. reading, I decided to be incompatible. This always tries to give you
  4118. rounded bits to the precision of the pseudo-op. Former AS did premature
  4119. truncation, restored noisy bits instead of trailing 0s AND gave you
  4120. a choice of 2 flavours of noise according to which of 2 floating-point
  4121. scanners you directed AS to use.
  4122. In: input_line_pointer->whitespace before, or '0' of flonum. */
  4123. void
  4124. float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
  4125. int float_type /* 'f':.ffloat ... 'F':.float ... */)
  4126. {
  4127. char *p;
  4128. int length; /* Number of chars in an object. */
  4129. char *err; /* Error from scanning floating literal. */
  4130. char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
  4131. if (is_it_end_of_statement ())
  4132. {
  4133. demand_empty_rest_of_line ();
  4134. return;
  4135. }
  4136. #ifdef md_flush_pending_output
  4137. md_flush_pending_output ();
  4138. #endif
  4139. #ifdef md_cons_align
  4140. md_cons_align (1);
  4141. #endif
  4142. do
  4143. {
  4144. /* input_line_pointer->1st char of a flonum (we hope!). */
  4145. SKIP_WHITESPACE ();
  4146. /* Skip any 0{letter} that may be present. Don't even check if the
  4147. letter is legal. Someone may invent a "z" format and this routine
  4148. has no use for such information. Lusers beware: you get
  4149. diagnostics if your input is ill-conditioned. */
  4150. if (input_line_pointer[0] == '0'
  4151. && ISALPHA (input_line_pointer[1]))
  4152. input_line_pointer += 2;
  4153. /* Accept :xxxx, where the x's are hex digits, for a floating
  4154. point with the exact digits specified. */
  4155. if (input_line_pointer[0] == ':')
  4156. {
  4157. ++input_line_pointer;
  4158. length = hex_float (float_type, temp);
  4159. if (length < 0)
  4160. {
  4161. ignore_rest_of_line ();
  4162. return;
  4163. }
  4164. }
  4165. else
  4166. {
  4167. err = md_atof (float_type, temp, &length);
  4168. know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
  4169. know (err != NULL || length > 0);
  4170. if (err)
  4171. {
  4172. as_bad (_("bad floating literal: %s"), err);
  4173. ignore_rest_of_line ();
  4174. return;
  4175. }
  4176. }
  4177. if (!need_pass_2)
  4178. {
  4179. int count;
  4180. count = 1;
  4181. #ifdef REPEAT_CONS_EXPRESSIONS
  4182. if (*input_line_pointer == ':')
  4183. {
  4184. expressionS count_exp;
  4185. ++input_line_pointer;
  4186. expression (&count_exp);
  4187. if (count_exp.X_op != O_constant
  4188. || count_exp.X_add_number <= 0)
  4189. as_warn (_("unresolvable or nonpositive repeat count; using 1"));
  4190. else
  4191. count = count_exp.X_add_number;
  4192. }
  4193. #endif
  4194. while (--count >= 0)
  4195. {
  4196. p = frag_more (length);
  4197. memcpy (p, temp, (unsigned int) length);
  4198. }
  4199. }
  4200. SKIP_WHITESPACE ();
  4201. }
  4202. while (*input_line_pointer++ == ',');
  4203. /* Put terminator back into stream. */
  4204. --input_line_pointer;
  4205. demand_empty_rest_of_line ();
  4206. }
  4207. /* Return the size of a LEB128 value. */
  4208. static inline int
  4209. sizeof_sleb128 (offsetT value)
  4210. {
  4211. int size = 0;
  4212. unsigned byte;
  4213. do
  4214. {
  4215. byte = (value & 0x7f);
  4216. /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
  4217. Fortunately, we can structure things so that the extra work reduces
  4218. to a noop on systems that do things "properly". */
  4219. value = (value >> 7) | ~(-(offsetT)1 >> 7);
  4220. size += 1;
  4221. }
  4222. while (!(((value == 0) && ((byte & 0x40) == 0))
  4223. || ((value == -1) && ((byte & 0x40) != 0))));
  4224. return size;
  4225. }
  4226. static inline int
  4227. sizeof_uleb128 (valueT value)
  4228. {
  4229. int size = 0;
  4230. do
  4231. {
  4232. value >>= 7;
  4233. size += 1;
  4234. }
  4235. while (value != 0);
  4236. return size;
  4237. }
  4238. int
  4239. sizeof_leb128 (valueT value, int sign)
  4240. {
  4241. if (sign)
  4242. return sizeof_sleb128 ((offsetT) value);
  4243. else
  4244. return sizeof_uleb128 (value);
  4245. }
  4246. /* Output a LEB128 value. */
  4247. static inline int
  4248. output_sleb128 (char *p, offsetT value)
  4249. {
  4250. char *orig = p;
  4251. int more;
  4252. do
  4253. {
  4254. unsigned byte = (value & 0x7f);
  4255. /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
  4256. Fortunately, we can structure things so that the extra work reduces
  4257. to a noop on systems that do things "properly". */
  4258. value = (value >> 7) | ~(-(offsetT)1 >> 7);
  4259. more = !((((value == 0) && ((byte & 0x40) == 0))
  4260. || ((value == -1) && ((byte & 0x40) != 0))));
  4261. if (more)
  4262. byte |= 0x80;
  4263. *p++ = byte;
  4264. }
  4265. while (more);
  4266. return p - orig;
  4267. }
  4268. static inline int
  4269. output_uleb128 (char *p, valueT value)
  4270. {
  4271. char *orig = p;
  4272. do
  4273. {
  4274. unsigned byte = (value & 0x7f);
  4275. value >>= 7;
  4276. if (value != 0)
  4277. /* More bytes to follow. */
  4278. byte |= 0x80;
  4279. *p++ = byte;
  4280. }
  4281. while (value != 0);
  4282. return p - orig;
  4283. }
  4284. int
  4285. output_leb128 (char *p, valueT value, int sign)
  4286. {
  4287. if (sign)
  4288. return output_sleb128 (p, (offsetT) value);
  4289. else
  4290. return output_uleb128 (p, value);
  4291. }
  4292. /* Do the same for bignums. We combine sizeof with output here in that
  4293. we don't output for NULL values of P. It isn't really as critical as
  4294. for "normal" values that this be streamlined. */
  4295. static inline int
  4296. output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
  4297. {
  4298. char *orig = p;
  4299. valueT val = 0;
  4300. int loaded = 0;
  4301. unsigned byte;
  4302. /* Strip leading sign extensions off the bignum. */
  4303. while (size > 1
  4304. && bignum[size - 1] == LITTLENUM_MASK
  4305. && bignum[size - 2] > LITTLENUM_MASK / 2)
  4306. size--;
  4307. do
  4308. {
  4309. /* OR in the next part of the littlenum. */
  4310. val |= (*bignum << loaded);
  4311. loaded += LITTLENUM_NUMBER_OF_BITS;
  4312. size--;
  4313. bignum++;
  4314. /* Add bytes until there are less than 7 bits left in VAL
  4315. or until every non-sign bit has been written. */
  4316. do
  4317. {
  4318. byte = val & 0x7f;
  4319. loaded -= 7;
  4320. val >>= 7;
  4321. if (size > 0
  4322. || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
  4323. byte |= 0x80;
  4324. if (orig)
  4325. *p = byte;
  4326. p++;
  4327. }
  4328. while ((byte & 0x80) != 0 && loaded >= 7);
  4329. }
  4330. while (size > 0);
  4331. /* Mop up any left-over bits (of which there will be less than 7). */
  4332. if ((byte & 0x80) != 0)
  4333. {
  4334. /* Sign-extend VAL. */
  4335. if (val & (1 << (loaded - 1)))
  4336. val |= ~0U << loaded;
  4337. if (orig)
  4338. *p = val & 0x7f;
  4339. p++;
  4340. }
  4341. return p - orig;
  4342. }
  4343. static inline int
  4344. output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
  4345. {
  4346. char *orig = p;
  4347. valueT val = 0;
  4348. int loaded = 0;
  4349. unsigned byte;
  4350. /* Strip leading zeros off the bignum. */
  4351. /* XXX: Is this needed? */
  4352. while (size > 0 && bignum[size - 1] == 0)
  4353. size--;
  4354. do
  4355. {
  4356. if (loaded < 7 && size > 0)
  4357. {
  4358. val |= (*bignum << loaded);
  4359. loaded += 8 * CHARS_PER_LITTLENUM;
  4360. size--;
  4361. bignum++;
  4362. }
  4363. byte = val & 0x7f;
  4364. loaded -= 7;
  4365. val >>= 7;
  4366. if (size > 0 || val)
  4367. byte |= 0x80;
  4368. if (orig)
  4369. *p = byte;
  4370. p++;
  4371. }
  4372. while (byte & 0x80);
  4373. return p - orig;
  4374. }
  4375. static int
  4376. output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
  4377. {
  4378. if (sign)
  4379. return output_big_sleb128 (p, bignum, size);
  4380. else
  4381. return output_big_uleb128 (p, bignum, size);
  4382. }
  4383. /* Generate the appropriate fragments for a given expression to emit a
  4384. leb128 value. */
  4385. static void
  4386. emit_leb128_expr (expressionS *exp, int sign)
  4387. {
  4388. operatorT op = exp->X_op;
  4389. unsigned int nbytes;
  4390. if (op == O_absent || op == O_illegal)
  4391. {
  4392. as_warn (_("zero assumed for missing expression"));
  4393. exp->X_add_number = 0;
  4394. op = O_constant;
  4395. }
  4396. else if (op == O_big && exp->X_add_number <= 0)
  4397. {
  4398. as_bad (_("floating point number invalid"));
  4399. exp->X_add_number = 0;
  4400. op = O_constant;
  4401. }
  4402. else if (op == O_register)
  4403. {
  4404. as_warn (_("register value used as expression"));
  4405. op = O_constant;
  4406. }
  4407. else if (op == O_constant
  4408. && sign
  4409. && (exp->X_add_number < 0) == !exp->X_extrabit)
  4410. {
  4411. /* We're outputting a signed leb128 and the sign of X_add_number
  4412. doesn't reflect the sign of the original value. Convert EXP
  4413. to a correctly-extended bignum instead. */
  4414. convert_to_bignum (exp, exp->X_extrabit);
  4415. op = O_big;
  4416. }
  4417. /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
  4418. a signal that this is leb128 data. It shouldn't optimize this away. */
  4419. nbytes = (unsigned int) -1;
  4420. if (check_eh_frame (exp, &nbytes))
  4421. abort ();
  4422. /* Let the backend know that subsequent data may be byte aligned. */
  4423. #ifdef md_cons_align
  4424. md_cons_align (1);
  4425. #endif
  4426. if (op == O_constant)
  4427. {
  4428. /* If we've got a constant, emit the thing directly right now. */
  4429. valueT value = exp->X_add_number;
  4430. int size;
  4431. char *p;
  4432. size = sizeof_leb128 (value, sign);
  4433. p = frag_more (size);
  4434. output_leb128 (p, value, sign);
  4435. }
  4436. else if (op == O_big)
  4437. {
  4438. /* O_big is a different sort of constant. */
  4439. int size;
  4440. char *p;
  4441. size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
  4442. p = frag_more (size);
  4443. output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
  4444. }
  4445. else
  4446. {
  4447. /* Otherwise, we have to create a variable sized fragment and
  4448. resolve things later. */
  4449. frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
  4450. make_expr_symbol (exp), 0, (char *) NULL);
  4451. }
  4452. }
  4453. /* Parse the .sleb128 and .uleb128 pseudos. */
  4454. void
  4455. s_leb128 (int sign)
  4456. {
  4457. expressionS exp;
  4458. #ifdef md_flush_pending_output
  4459. md_flush_pending_output ();
  4460. #endif
  4461. do
  4462. {
  4463. expression (&exp);
  4464. emit_leb128_expr (&exp, sign);
  4465. }
  4466. while (*input_line_pointer++ == ',');
  4467. input_line_pointer--;
  4468. demand_empty_rest_of_line ();
  4469. }
  4470. static void
  4471. stringer_append_char (int c, int bitsize)
  4472. {
  4473. if (!target_big_endian)
  4474. FRAG_APPEND_1_CHAR (c);
  4475. switch (bitsize)
  4476. {
  4477. case 64:
  4478. FRAG_APPEND_1_CHAR (0);
  4479. FRAG_APPEND_1_CHAR (0);
  4480. FRAG_APPEND_1_CHAR (0);
  4481. FRAG_APPEND_1_CHAR (0);
  4482. /* Fall through. */
  4483. case 32:
  4484. FRAG_APPEND_1_CHAR (0);
  4485. FRAG_APPEND_1_CHAR (0);
  4486. /* Fall through. */
  4487. case 16:
  4488. FRAG_APPEND_1_CHAR (0);
  4489. /* Fall through. */
  4490. case 8:
  4491. break;
  4492. default:
  4493. /* Called with invalid bitsize argument. */
  4494. abort ();
  4495. break;
  4496. }
  4497. if (target_big_endian)
  4498. FRAG_APPEND_1_CHAR (c);
  4499. }
  4500. /* Worker to do .ascii etc statements.
  4501. Reads 0 or more ',' separated, double-quoted strings.
  4502. Caller should have checked need_pass_2 is FALSE because we don't
  4503. check it.
  4504. Checks for end-of-line.
  4505. BITS_APPENDZERO says how many bits are in a target char.
  4506. The bottom bit is set if a NUL char should be appended to the strings. */
  4507. void
  4508. stringer (int bits_appendzero)
  4509. {
  4510. const int bitsize = bits_appendzero & ~7;
  4511. const int append_zero = bits_appendzero & 1;
  4512. unsigned int c;
  4513. #if !defined(NO_LISTING) && defined (OBJ_ELF)
  4514. char *start;
  4515. #endif
  4516. #ifdef md_flush_pending_output
  4517. md_flush_pending_output ();
  4518. #endif
  4519. #ifdef md_cons_align
  4520. md_cons_align (1);
  4521. #endif
  4522. /* The following awkward logic is to parse ZERO or more strings,
  4523. comma separated. Recall a string expression includes spaces
  4524. before the opening '\"' and spaces after the closing '\"'.
  4525. We fake a leading ',' if there is (supposed to be)
  4526. a 1st, expression. We keep demanding expressions for each ','. */
  4527. if (is_it_end_of_statement ())
  4528. {
  4529. c = 0; /* Skip loop. */
  4530. ++input_line_pointer; /* Compensate for end of loop. */
  4531. }
  4532. else
  4533. {
  4534. c = ','; /* Do loop. */
  4535. }
  4536. /* If we have been switched into the abs_section then we
  4537. will not have an obstack onto which we can hang strings. */
  4538. if (now_seg == absolute_section)
  4539. {
  4540. as_bad (_("strings must be placed into a section"));
  4541. c = 0;
  4542. ignore_rest_of_line ();
  4543. }
  4544. while (c == ',' || c == '<' || c == '"')
  4545. {
  4546. SKIP_WHITESPACE ();
  4547. switch (*input_line_pointer)
  4548. {
  4549. case '\"':
  4550. ++input_line_pointer; /*->1st char of string. */
  4551. #if !defined(NO_LISTING) && defined (OBJ_ELF)
  4552. start = input_line_pointer;
  4553. #endif
  4554. while (is_a_char (c = next_char_of_string ()))
  4555. stringer_append_char (c, bitsize);
  4556. if (append_zero)
  4557. stringer_append_char (0, bitsize);
  4558. know (input_line_pointer[-1] == '\"');
  4559. #if !defined(NO_LISTING) && defined (OBJ_ELF)
  4560. /* In ELF, when gcc is emitting DWARF 1 debugging output, it
  4561. will emit .string with a filename in the .debug section
  4562. after a sequence of constants. See the comment in
  4563. emit_expr for the sequence. emit_expr will set
  4564. dwarf_file_string to non-zero if this string might be a
  4565. source file name. */
  4566. if (strcmp (segment_name (now_seg), ".debug") != 0)
  4567. dwarf_file_string = 0;
  4568. else if (dwarf_file_string)
  4569. {
  4570. c = input_line_pointer[-1];
  4571. input_line_pointer[-1] = '\0';
  4572. listing_source_file (start);
  4573. input_line_pointer[-1] = c;
  4574. }
  4575. #endif
  4576. break;
  4577. case '<':
  4578. input_line_pointer++;
  4579. c = get_single_number ();
  4580. stringer_append_char (c, bitsize);
  4581. if (*input_line_pointer != '>')
  4582. as_bad (_("expected <nn>"));
  4583. input_line_pointer++;
  4584. break;
  4585. case ',':
  4586. input_line_pointer++;
  4587. break;
  4588. }
  4589. SKIP_WHITESPACE ();
  4590. c = *input_line_pointer;
  4591. }
  4592. demand_empty_rest_of_line ();
  4593. }
  4594. /* FIXME-SOMEDAY: I had trouble here on characters with the
  4595. high bits set. We'll probably also have trouble with
  4596. multibyte chars, wide chars, etc. Also be careful about
  4597. returning values bigger than 1 byte. xoxorich. */
  4598. unsigned int
  4599. next_char_of_string (void)
  4600. {
  4601. unsigned int c;
  4602. c = *input_line_pointer++ & CHAR_MASK;
  4603. switch (c)
  4604. {
  4605. case '\"':
  4606. c = NOT_A_CHAR;
  4607. break;
  4608. case '\n':
  4609. as_warn (_("unterminated string; newline inserted"));
  4610. bump_line_counters ();
  4611. break;
  4612. #ifndef NO_STRING_ESCAPES
  4613. case '\\':
  4614. switch (c = *input_line_pointer++ & CHAR_MASK)
  4615. {
  4616. case 'b':
  4617. c = '\b';
  4618. break;
  4619. case 'f':
  4620. c = '\f';
  4621. break;
  4622. case 'n':
  4623. c = '\n';
  4624. break;
  4625. case 'r':
  4626. c = '\r';
  4627. break;
  4628. case 't':
  4629. c = '\t';
  4630. break;
  4631. case 'v':
  4632. c = '\013';
  4633. break;
  4634. case '\\':
  4635. case '"':
  4636. break; /* As itself. */
  4637. case '0':
  4638. case '1':
  4639. case '2':
  4640. case '3':
  4641. case '4':
  4642. case '5':
  4643. case '6':
  4644. case '7':
  4645. case '8':
  4646. case '9':
  4647. {
  4648. long number;
  4649. int i;
  4650. for (i = 0, number = 0;
  4651. ISDIGIT (c) && i < 3;
  4652. c = *input_line_pointer++, i++)
  4653. {
  4654. number = number * 8 + c - '0';
  4655. }
  4656. c = number & CHAR_MASK;
  4657. }
  4658. --input_line_pointer;
  4659. break;
  4660. case 'x':
  4661. case 'X':
  4662. {
  4663. long number;
  4664. number = 0;
  4665. c = *input_line_pointer++;
  4666. while (ISXDIGIT (c))
  4667. {
  4668. if (ISDIGIT (c))
  4669. number = number * 16 + c - '0';
  4670. else if (ISUPPER (c))
  4671. number = number * 16 + c - 'A' + 10;
  4672. else
  4673. number = number * 16 + c - 'a' + 10;
  4674. c = *input_line_pointer++;
  4675. }
  4676. c = number & CHAR_MASK;
  4677. --input_line_pointer;
  4678. }
  4679. break;
  4680. case '\n':
  4681. /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
  4682. as_warn (_("unterminated string; newline inserted"));
  4683. c = '\n';
  4684. bump_line_counters ();
  4685. break;
  4686. default:
  4687. #ifdef ONLY_STANDARD_ESCAPES
  4688. as_bad (_("bad escaped character in string"));
  4689. c = '?';
  4690. #endif /* ONLY_STANDARD_ESCAPES */
  4691. break;
  4692. }
  4693. break;
  4694. #endif /* ! defined (NO_STRING_ESCAPES) */
  4695. default:
  4696. break;
  4697. }
  4698. return (c);
  4699. }
  4700. static segT
  4701. get_segmented_expression (expressionS *expP)
  4702. {
  4703. segT retval;
  4704. retval = expression (expP);
  4705. if (expP->X_op == O_illegal
  4706. || expP->X_op == O_absent
  4707. || expP->X_op == O_big)
  4708. {
  4709. as_bad (_("expected address expression"));
  4710. expP->X_op = O_constant;
  4711. expP->X_add_number = 0;
  4712. retval = absolute_section;
  4713. }
  4714. return retval;
  4715. }
  4716. static segT
  4717. get_known_segmented_expression (expressionS *expP)
  4718. {
  4719. segT retval = get_segmented_expression (expP);
  4720. if (retval == undefined_section)
  4721. {
  4722. /* There is no easy way to extract the undefined symbol from the
  4723. expression. */
  4724. if (expP->X_add_symbol != NULL
  4725. && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
  4726. as_warn (_("symbol \"%s\" undefined; zero assumed"),
  4727. S_GET_NAME (expP->X_add_symbol));
  4728. else
  4729. as_warn (_("some symbol undefined; zero assumed"));
  4730. retval = absolute_section;
  4731. expP->X_op = O_constant;
  4732. expP->X_add_number = 0;
  4733. }
  4734. return retval;
  4735. }
  4736. char /* Return terminator. */
  4737. get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
  4738. {
  4739. /* FIXME: val_pointer should probably be offsetT *. */
  4740. *val_pointer = (long) get_absolute_expression ();
  4741. return (*input_line_pointer++);
  4742. }
  4743. /* Like demand_copy_string, but return NULL if the string contains any '\0's.
  4744. Give a warning if that happens. */
  4745. char *
  4746. demand_copy_C_string (int *len_pointer)
  4747. {
  4748. char *s;
  4749. if ((s = demand_copy_string (len_pointer)) != 0)
  4750. {
  4751. int len;
  4752. for (len = *len_pointer; len > 0; len--)
  4753. {
  4754. if (*s == 0)
  4755. {
  4756. s = 0;
  4757. len = 1;
  4758. *len_pointer = 0;
  4759. as_bad (_("this string may not contain \'\\0\'"));
  4760. }
  4761. }
  4762. }
  4763. return s;
  4764. }
  4765. /* Demand string, but return a safe (=private) copy of the string.
  4766. Return NULL if we can't read a string here. */
  4767. char *
  4768. demand_copy_string (int *lenP)
  4769. {
  4770. unsigned int c;
  4771. int len;
  4772. char *retval;
  4773. len = 0;
  4774. SKIP_WHITESPACE ();
  4775. if (*input_line_pointer == '\"')
  4776. {
  4777. input_line_pointer++; /* Skip opening quote. */
  4778. while (is_a_char (c = next_char_of_string ()))
  4779. {
  4780. obstack_1grow (&notes, c);
  4781. len++;
  4782. }
  4783. /* JF this next line is so demand_copy_C_string will return a
  4784. null terminated string. */
  4785. obstack_1grow (&notes, '\0');
  4786. retval = (char *) obstack_finish (&notes);
  4787. }
  4788. else
  4789. {
  4790. as_bad (_("missing string"));
  4791. retval = NULL;
  4792. ignore_rest_of_line ();
  4793. }
  4794. *lenP = len;
  4795. return (retval);
  4796. }
  4797. /* In: Input_line_pointer->next character.
  4798. Do: Skip input_line_pointer over all whitespace.
  4799. Out: 1 if input_line_pointer->end-of-line. */
  4800. int
  4801. is_it_end_of_statement (void)
  4802. {
  4803. SKIP_WHITESPACE ();
  4804. return (is_end_of_line[(unsigned char) *input_line_pointer]);
  4805. }
  4806. void
  4807. equals (char *sym_name, int reassign)
  4808. {
  4809. char *stop = NULL;
  4810. char stopc = 0;
  4811. input_line_pointer++;
  4812. if (*input_line_pointer == '=')
  4813. input_line_pointer++;
  4814. if (reassign < 0 && *input_line_pointer == '=')
  4815. input_line_pointer++;
  4816. while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
  4817. input_line_pointer++;
  4818. if (flag_mri)
  4819. stop = mri_comment_field (&stopc);
  4820. assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
  4821. if (flag_mri)
  4822. {
  4823. demand_empty_rest_of_line ();
  4824. mri_comment_end (stop, stopc);
  4825. }
  4826. }
  4827. /* .incbin -- include a file verbatim at the current location. */
  4828. void
  4829. s_incbin (int x ATTRIBUTE_UNUSED)
  4830. {
  4831. FILE * binfile;
  4832. char * path;
  4833. char * filename;
  4834. char * binfrag;
  4835. long skip = 0;
  4836. long count = 0;
  4837. long bytes;
  4838. int len;
  4839. #ifdef md_flush_pending_output
  4840. md_flush_pending_output ();
  4841. #endif
  4842. #ifdef md_cons_align
  4843. md_cons_align (1);
  4844. #endif
  4845. SKIP_WHITESPACE ();
  4846. filename = demand_copy_string (& len);
  4847. if (filename == NULL)
  4848. return;
  4849. SKIP_WHITESPACE ();
  4850. /* Look for optional skip and count. */
  4851. if (* input_line_pointer == ',')
  4852. {
  4853. ++ input_line_pointer;
  4854. skip = get_absolute_expression ();
  4855. SKIP_WHITESPACE ();
  4856. if (* input_line_pointer == ',')
  4857. {
  4858. ++ input_line_pointer;
  4859. count = get_absolute_expression ();
  4860. if (count == 0)
  4861. as_warn (_(".incbin count zero, ignoring `%s'"), filename);
  4862. SKIP_WHITESPACE ();
  4863. }
  4864. }
  4865. demand_empty_rest_of_line ();
  4866. /* Try opening absolute path first, then try include dirs. */
  4867. binfile = fopen (filename, FOPEN_RB);
  4868. if (binfile == NULL)
  4869. {
  4870. int i;
  4871. path = (char *) xmalloc ((unsigned long) len + include_dir_maxlen + 5);
  4872. for (i = 0; i < include_dir_count; i++)
  4873. {
  4874. sprintf (path, "%s/%s", include_dirs[i], filename);
  4875. binfile = fopen (path, FOPEN_RB);
  4876. if (binfile != NULL)
  4877. break;
  4878. }
  4879. if (binfile == NULL)
  4880. as_bad (_("file not found: %s"), filename);
  4881. }
  4882. else
  4883. path = xstrdup (filename);
  4884. if (binfile)
  4885. {
  4886. long file_len;
  4887. register_dependency (path);
  4888. /* Compute the length of the file. */
  4889. if (fseek (binfile, 0, SEEK_END) != 0)
  4890. {
  4891. as_bad (_("seek to end of .incbin file failed `%s'"), path);
  4892. goto done;
  4893. }
  4894. file_len = ftell (binfile);
  4895. /* If a count was not specified use the remainder of the file. */
  4896. if (count == 0)
  4897. count = file_len - skip;
  4898. if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
  4899. {
  4900. as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
  4901. skip, count, file_len);
  4902. goto done;
  4903. }
  4904. if (fseek (binfile, skip, SEEK_SET) != 0)
  4905. {
  4906. as_bad (_("could not skip to %ld in file `%s'"), skip, path);
  4907. goto done;
  4908. }
  4909. /* Allocate frag space and store file contents in it. */
  4910. binfrag = frag_more (count);
  4911. bytes = fread (binfrag, 1, count, binfile);
  4912. if (bytes < count)
  4913. as_warn (_("truncated file `%s', %ld of %ld bytes read"),
  4914. path, bytes, count);
  4915. }
  4916. done:
  4917. if (binfile != NULL)
  4918. fclose (binfile);
  4919. if (path)
  4920. free (path);
  4921. }
  4922. /* .include -- include a file at this point. */
  4923. void
  4924. s_include (int arg ATTRIBUTE_UNUSED)
  4925. {
  4926. char *filename;
  4927. int i;
  4928. FILE *try_file;
  4929. char *path;
  4930. if (!flag_m68k_mri)
  4931. {
  4932. filename = demand_copy_string (&i);
  4933. if (filename == NULL)
  4934. {
  4935. /* demand_copy_string has already printed an error and
  4936. called ignore_rest_of_line. */
  4937. return;
  4938. }
  4939. }
  4940. else
  4941. {
  4942. SKIP_WHITESPACE ();
  4943. i = 0;
  4944. while (!is_end_of_line[(unsigned char) *input_line_pointer]
  4945. && *input_line_pointer != ' '
  4946. && *input_line_pointer != '\t')
  4947. {
  4948. obstack_1grow (&notes, *input_line_pointer);
  4949. ++input_line_pointer;
  4950. ++i;
  4951. }
  4952. obstack_1grow (&notes, '\0');
  4953. filename = (char *) obstack_finish (&notes);
  4954. while (!is_end_of_line[(unsigned char) *input_line_pointer])
  4955. ++input_line_pointer;
  4956. }
  4957. demand_empty_rest_of_line ();
  4958. path = (char *) xmalloc ((unsigned long) i
  4959. + include_dir_maxlen + 5 /* slop */ );
  4960. for (i = 0; i < include_dir_count; i++)
  4961. {
  4962. strcpy (path, include_dirs[i]);
  4963. strcat (path, "/");
  4964. strcat (path, filename);
  4965. if (0 != (try_file = fopen (path, FOPEN_RT)))
  4966. {
  4967. fclose (try_file);
  4968. goto gotit;
  4969. }
  4970. }
  4971. free (path);
  4972. path = filename;
  4973. gotit:
  4974. /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
  4975. register_dependency (path);
  4976. input_scrub_insert_file (path);
  4977. }
  4978. void
  4979. add_include_dir (char *path)
  4980. {
  4981. int i;
  4982. if (include_dir_count == 0)
  4983. {
  4984. include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
  4985. include_dirs[0] = "."; /* Current dir. */
  4986. include_dir_count = 2;
  4987. }
  4988. else
  4989. {
  4990. include_dir_count++;
  4991. include_dirs =
  4992. (char **) xrealloc (include_dirs,
  4993. include_dir_count * sizeof (*include_dirs));
  4994. }
  4995. include_dirs[include_dir_count - 1] = path; /* New one. */
  4996. i = strlen (path);
  4997. if (i > include_dir_maxlen)
  4998. include_dir_maxlen = i;
  4999. }
  5000. /* Output debugging information to denote the source file. */
  5001. static void
  5002. generate_file_debug (void)
  5003. {
  5004. if (debug_type == DEBUG_STABS)
  5005. stabs_generate_asm_file ();
  5006. }
  5007. /* Output line number debugging information for the current source line. */
  5008. void
  5009. generate_lineno_debug (void)
  5010. {
  5011. switch (debug_type)
  5012. {
  5013. case DEBUG_UNSPECIFIED:
  5014. case DEBUG_NONE:
  5015. case DEBUG_DWARF:
  5016. break;
  5017. case DEBUG_STABS:
  5018. stabs_generate_asm_lineno ();
  5019. break;
  5020. case DEBUG_ECOFF:
  5021. ecoff_generate_asm_lineno ();
  5022. break;
  5023. case DEBUG_DWARF2:
  5024. /* ??? We could here indicate to dwarf2dbg.c that something
  5025. has changed. However, since there is additional backend
  5026. support that is required (calling dwarf2_emit_insn), we
  5027. let dwarf2dbg.c call as_where on its own. */
  5028. break;
  5029. }
  5030. }
  5031. /* Output debugging information to mark a function entry point or end point.
  5032. END_P is zero for .func, and non-zero for .endfunc. */
  5033. void
  5034. s_func (int end_p)
  5035. {
  5036. do_s_func (end_p, NULL);
  5037. }
  5038. /* Subroutine of s_func so targets can choose a different default prefix.
  5039. If DEFAULT_PREFIX is NULL, use the target's "leading char". */
  5040. static void
  5041. do_s_func (int end_p, const char *default_prefix)
  5042. {
  5043. /* Record the current function so that we can issue an error message for
  5044. misplaced .func,.endfunc, and also so that .endfunc needs no
  5045. arguments. */
  5046. static char *current_name;
  5047. static char *current_label;
  5048. if (end_p)
  5049. {
  5050. if (current_name == NULL)
  5051. {
  5052. as_bad (_("missing .func"));
  5053. ignore_rest_of_line ();
  5054. return;
  5055. }
  5056. if (debug_type == DEBUG_STABS)
  5057. stabs_generate_asm_endfunc (current_name, current_label);
  5058. current_name = current_label = NULL;
  5059. }
  5060. else /* ! end_p */
  5061. {
  5062. char *name, *label;
  5063. char delim1, delim2;
  5064. if (current_name != NULL)
  5065. {
  5066. as_bad (_(".endfunc missing for previous .func"));
  5067. ignore_rest_of_line ();
  5068. return;
  5069. }
  5070. delim1 = get_symbol_name (& name);
  5071. name = xstrdup (name);
  5072. *input_line_pointer = delim1;
  5073. SKIP_WHITESPACE_AFTER_NAME ();
  5074. if (*input_line_pointer != ',')
  5075. {
  5076. if (default_prefix)
  5077. {
  5078. if (asprintf (&label, "%s%s", default_prefix, name) == -1)
  5079. as_fatal ("%s", xstrerror (errno));
  5080. }
  5081. else
  5082. {
  5083. char leading_char = bfd_get_symbol_leading_char (stdoutput);
  5084. /* Missing entry point, use function's name with the leading
  5085. char prepended. */
  5086. if (leading_char)
  5087. {
  5088. if (asprintf (&label, "%c%s", leading_char, name) == -1)
  5089. as_fatal ("%s", xstrerror (errno));
  5090. }
  5091. else
  5092. label = name;
  5093. }
  5094. }
  5095. else
  5096. {
  5097. ++input_line_pointer;
  5098. SKIP_WHITESPACE ();
  5099. delim2 = get_symbol_name (& label);
  5100. label = xstrdup (label);
  5101. restore_line_pointer (delim2);
  5102. }
  5103. if (debug_type == DEBUG_STABS)
  5104. stabs_generate_asm_func (name, label);
  5105. current_name = name;
  5106. current_label = label;
  5107. }
  5108. demand_empty_rest_of_line ();
  5109. }
  5110. #ifdef HANDLE_BUNDLE
  5111. void
  5112. s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
  5113. {
  5114. unsigned int align = get_absolute_expression ();
  5115. SKIP_WHITESPACE ();
  5116. demand_empty_rest_of_line ();
  5117. if (align > (unsigned int) TC_ALIGN_LIMIT)
  5118. as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
  5119. (unsigned int) TC_ALIGN_LIMIT);
  5120. if (bundle_lock_frag != NULL)
  5121. {
  5122. as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
  5123. return;
  5124. }
  5125. bundle_align_p2 = align;
  5126. }
  5127. void
  5128. s_bundle_lock (int arg ATTRIBUTE_UNUSED)
  5129. {
  5130. demand_empty_rest_of_line ();
  5131. if (bundle_align_p2 == 0)
  5132. {
  5133. as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
  5134. return;
  5135. }
  5136. if (bundle_lock_depth == 0)
  5137. {
  5138. bundle_lock_frchain = frchain_now;
  5139. bundle_lock_frag = start_bundle ();
  5140. }
  5141. ++bundle_lock_depth;
  5142. }
  5143. void
  5144. s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
  5145. {
  5146. unsigned int size;
  5147. demand_empty_rest_of_line ();
  5148. if (bundle_lock_frag == NULL)
  5149. {
  5150. as_bad (_(".bundle_unlock without preceding .bundle_lock"));
  5151. return;
  5152. }
  5153. gas_assert (bundle_align_p2 > 0);
  5154. gas_assert (bundle_lock_depth > 0);
  5155. if (--bundle_lock_depth > 0)
  5156. return;
  5157. size = pending_bundle_size (bundle_lock_frag);
  5158. if (size > (1U << bundle_align_p2))
  5159. as_bad (_(".bundle_lock sequence is %u bytes, but bundle size only %u"),
  5160. size, 1 << bundle_align_p2);
  5161. else
  5162. finish_bundle (bundle_lock_frag, size);
  5163. bundle_lock_frag = NULL;
  5164. bundle_lock_frchain = NULL;
  5165. }
  5166. #endif /* HANDLE_BUNDLE */
  5167. void
  5168. s_ignore (int arg ATTRIBUTE_UNUSED)
  5169. {
  5170. ignore_rest_of_line ();
  5171. }
  5172. void
  5173. read_print_statistics (FILE *file)
  5174. {
  5175. hash_print_statistics (file, "pseudo-op table", po_hash);
  5176. }
  5177. /* Inserts the given line into the input stream.
  5178. This call avoids macro/conditionals nesting checking, since the contents of
  5179. the line are assumed to replace the contents of a line already scanned.
  5180. An appropriate use of this function would be substitution of input lines when
  5181. called by md_start_line_hook(). The given line is assumed to already be
  5182. properly scrubbed. */
  5183. void
  5184. input_scrub_insert_line (const char *line)
  5185. {
  5186. sb newline;
  5187. size_t len = strlen (line);
  5188. sb_build (&newline, len);
  5189. sb_add_buffer (&newline, line, len);
  5190. input_scrub_include_sb (&newline, input_line_pointer, 0);
  5191. sb_kill (&newline);
  5192. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  5193. }
  5194. /* Insert a file into the input stream; the path must resolve to an actual
  5195. file; no include path searching or dependency registering is performed. */
  5196. void
  5197. input_scrub_insert_file (char *path)
  5198. {
  5199. input_scrub_include_file (path, input_line_pointer);
  5200. buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  5201. }
  5202. /* Find the end of a line, considering quotation and escaping of quotes. */
  5203. #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
  5204. # define TC_SINGLE_QUOTE_STRINGS 1
  5205. #endif
  5206. static char *
  5207. _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
  5208. int in_macro)
  5209. {
  5210. char inquote = '\0';
  5211. int inescape = 0;
  5212. while (!is_end_of_line[(unsigned char) *s]
  5213. || (inquote && !ISCNTRL (*s))
  5214. || (inquote == '\'' && flag_mri)
  5215. #ifdef TC_EOL_IN_INSN
  5216. || (insn && TC_EOL_IN_INSN (s))
  5217. #endif
  5218. /* PR 6926: When we are parsing the body of a macro the sequence
  5219. \@ is special - it refers to the invocation count. If the @
  5220. character happens to be registered as a line-separator character
  5221. by the target, then the is_end_of_line[] test above will have
  5222. returned true, but we need to ignore the line separating
  5223. semantics in this particular case. */
  5224. || (in_macro && inescape && *s == '@')
  5225. )
  5226. {
  5227. if (mri_string && *s == '\'')
  5228. inquote ^= *s;
  5229. else if (inescape)
  5230. inescape = 0;
  5231. else if (*s == '\\')
  5232. inescape = 1;
  5233. else if (!inquote
  5234. ? *s == '"'
  5235. #ifdef TC_SINGLE_QUOTE_STRINGS
  5236. || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
  5237. #endif
  5238. : *s == inquote)
  5239. inquote ^= *s;
  5240. ++s;
  5241. }
  5242. if (inquote)
  5243. as_warn (_("missing closing `%c'"), inquote);
  5244. if (inescape && !ignore_input ())
  5245. as_warn (_("stray `\\'"));
  5246. return s;
  5247. }
  5248. char *
  5249. find_end_of_line (char *s, int mri_string)
  5250. {
  5251. return _find_end_of_line (s, mri_string, 0, 0);
  5252. }