read.c 153 KB

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