600-ubicom32-uClibc.patch 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407
  1. --- a/Rules.mak
  2. +++ b/Rules.mak
  3. @@ -411,6 +411,17 @@ ifeq ($(TARGET_ARCH),microblaze)
  4. SYMBOL_PREFIX=_
  5. endif
  6. +ifeq ($(TARGET_ARCH),ubicom32)
  7. + OPTIMIZATION+=-fstrict-aliasing
  8. + CPU_CFLAGS-$(CONFIG_UBICOM32_V3)+=-march=ubicom32v3
  9. + CPU_CFLAGS-$(CONFIG_UBICOM32_V4)+=-march=ubicom32v4
  10. +ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
  11. + CPU_CFLAGS-y:=-mfdpic
  12. + CPU_LDFLAGS-y += -Wl,-melf32ubicom32fdpic
  13. +endif
  14. +
  15. +endif
  16. +
  17. ifeq ($(TARGET_ARCH),v850)
  18. SYMBOL_PREFIX=_
  19. endif
  20. --- a/extra/Configs/Config.in
  21. +++ b/extra/Configs/Config.in
  22. @@ -73,6 +73,9 @@ config TARGET_sh64
  23. config TARGET_sparc
  24. bool "sparc"
  25. +config TARGET_ubicom32
  26. + bool "ubicom32"
  27. +
  28. config TARGET_v850
  29. bool "v850 (BROKEN)"
  30. @@ -174,6 +177,10 @@ if TARGET_sparc
  31. source "extra/Configs/Config.sparc"
  32. endif
  33. +if TARGET_ubicom32
  34. +source "extra/Configs/Config.ubicom32"
  35. +endif
  36. +
  37. if TARGET_v850
  38. source "extra/Configs/Config.v850"
  39. endif
  40. --- a/extra/Configs/Config.in.arch
  41. +++ b/extra/Configs/Config.in.arch
  42. @@ -148,7 +148,7 @@ config UCLIBC_HAS_SOFT_FLOAT
  43. config DO_C99_MATH
  44. bool "Enable full C99 math library support"
  45. depends on UCLIBC_HAS_FLOATS
  46. - default n
  47. + default y
  48. help
  49. If you want the uClibc math library to contain the full set C99
  50. math library features, then answer Y. If you leave this set to
  51. --- /dev/null
  52. +++ b/extra/Configs/Config.ubicom32
  53. @@ -0,0 +1,44 @@
  54. +#
  55. +# For a description of the syntax of this configuration file,
  56. +# see extra/config/Kconfig-language.txt
  57. +#
  58. +
  59. +config TARGET_ARCH
  60. + string
  61. + default "ubicom32"
  62. +
  63. +config FORCE_OPTIONS_FOR_ARCH
  64. + bool
  65. + default y
  66. + select ARCH_BIG_ENDIAN
  67. + select ARCH_HAS_NO_MMU
  68. +
  69. +choice
  70. + prompt "Target Processor Architecture"
  71. + default CONFIG_UC_UBICOM32_V3
  72. + help
  73. + This selects the instruction set architecture of your Ubicom32 CPU. This
  74. + information is used for optimizing purposes. To build a library that
  75. + will run on any Ubicom32 CPU, you can specify "v3" here.
  76. + If you pick anything other than "v3," there is no
  77. + guarantee that uClibc will even run on anything other than the
  78. + selected processor type.
  79. +
  80. + You should probably select the Ubicom32 ISA that best matches the
  81. + CPU you will be using on your device. uClibc will be tuned
  82. + for that architecture.
  83. +
  84. + If you don't know what to do, choose "v3"
  85. +
  86. +config CONFIG_UC_UBICOM32_V3
  87. + bool "ISA v3"
  88. +
  89. +config CONFIG_UC_UBICOM32_V4
  90. + bool "ISA v4"
  91. +endchoice
  92. +
  93. +config ARCH_CFLAGS
  94. + string
  95. +
  96. +config CROSS
  97. + string
  98. --- a/include/elf.h
  99. +++ b/include/elf.h
  100. @@ -331,6 +331,8 @@ typedef struct
  101. #define EM_XSTORMY16 0xad45
  102. +#define EM_UBICOM32 0xde3d /* Ubicom32; no ABI */
  103. +
  104. /* FRV magic number - no EABI available??. */
  105. #define EM_CYGNUS_FRV 0x5441
  106. @@ -3036,6 +3038,55 @@ typedef Elf32_Addr Elf32_Conflict;
  107. /* Keep this the last entry. */
  108. #define R_XTENSA_NUM 50
  109. +/* Ubicom32 ELF relocation types */
  110. +#define R_UBICOM32_NONE 0
  111. +#define R_UBICOM32_16 1
  112. +#define R_UBICOM32_32 2
  113. +#define R_UBICOM32_LO16 3
  114. +#define R_UBICOM32_HI16 4
  115. +#define R_UBICOM32_21_PCREL 5
  116. +#define R_UBICOM32_24_PCREL 6
  117. +#define R_UBICOM32_HI24 7
  118. +#define R_UBICOM32_LO7_S 8
  119. +#define R_UBICOM32_LO7_2_S 9
  120. +#define R_UBICOM32_LO7_4_S 10
  121. +#define R_UBICOM32_LO7_D 11
  122. +#define R_UBICOM32_LO7_2_D 12
  123. +#define R_UBICOM32_LO7_4_D 13
  124. +#define R_UBICOM32_32_HARVARD 14
  125. +#define R_UBICOM32_LO7_CALLI 15
  126. +#define R_UBICOM32_LO16_CALLI 16
  127. +#define R_UBICOM32_GOT_HI24 17
  128. +#define R_UBICOM32_GOT_LO7_S 18
  129. +#define R_UBICOM32_GOT_LO7_2_S 19
  130. +#define R_UBICOM32_GOT_LO7_4_S 20
  131. +#define R_UBICOM32_GOT_LO7_D 21
  132. +#define R_UBICOM32_GOT_LO7_2_D 22
  133. +#define R_UBICOM32_GOT_LO7_4_D 23
  134. +#define R_UBICOM32_FUNCDESC_GOT_HI24 24
  135. +#define R_UBICOM32_FUNCDESC_GOT_LO7_S 25
  136. +#define R_UBICOM32_FUNCDESC_GOT_LO7_2_S 26
  137. +#define R_UBICOM32_FUNCDESC_GOT_LO7_4_S 27
  138. +#define R_UBICOM32_FUNCDESC_GOT_LO7_D 28
  139. +#define R_UBICOM32_FUNCDESC_GOT_LO7_2_D 29
  140. +#define R_UBICOM32_FUNCDESC_GOT_LO7_4_D 30
  141. +#define R_UBICOM32_GOT_LO7_CALLI 31
  142. +#define R_UBICOM32_FUNCDESC_GOT_LO7_CALLI 32
  143. +#define R_UBICOM32_FUNCDESC_VALUE 33
  144. +#define R_UBICOM32_FUNCDESC 34
  145. +#define R_UBICOM32_GOTOFFSET_LO 35
  146. +#define R_UBICOM32_GOTOFFSET_HI 36
  147. +#define R_UBICOM32_FUNCDESC_GOTOFFSET_LO 37
  148. +#define R_UBICOM32_FUNCDESC_GOTOFFSET_HI 38
  149. +#define R_UBICOM32_GNU_VTINHERIT 200
  150. +#define R_UBICOM32_GNU_VTENTRY 201
  151. +
  152. +/* Ubicom32 Flags. */
  153. +#define EF_UBICOM32_V3 0x00000001 /* -fmarch=ubicom32v3 */
  154. +#define EF_UBICOM32_V4 0x00000002 /* -fmarch=ubicom32v4 */
  155. +#define EF_UBICOM32_PIC 0x80000000 /* -fpic */
  156. +#define EF_UBICOM32_FDPIC 0x40000000 /* -mfdpic */
  157. +
  158. __END_DECLS
  159. #endif /* elf.h */
  160. --- a/include/features.h
  161. +++ b/include/features.h
  162. @@ -422,4 +422,10 @@ uClibc was built without large file supp
  163. # define __linux__ 1
  164. #endif
  165. +#ifndef libc_hidden_proto
  166. +#define libc_hidden_proto(name, attrs...)
  167. +#endif
  168. +#ifndef libm_hidden_proto
  169. +#define libm_hidden_proto(name, attrs...)
  170. +#endif
  171. #endif /* features.h */
  172. --- a/ldso/ldso/dl-startup.c
  173. +++ b/ldso/ldso/dl-startup.c
  174. @@ -165,10 +165,13 @@ DL_START(unsigned long args)
  175. aux_dat += 2;
  176. }
  177. +#if !defined __FDPIC__
  178. /* locate the ELF header. We need this done as soon as possible
  179. * (esp since SEND_STDERR() needs this on some platforms... */
  180. if (!auxvt[AT_BASE].a_un.a_val)
  181. auxvt[AT_BASE].a_un.a_val = elf_machine_load_address();
  182. +#endif
  183. +
  184. DL_INIT_LOADADDR_BOOT(load_addr, auxvt[AT_BASE].a_un.a_val);
  185. header = (ElfW(Ehdr) *) auxvt[AT_BASE].a_un.a_val;
  186. --- a/ldso/ldso/ldso.c
  187. +++ b/ldso/ldso/ldso.c
  188. @@ -179,10 +179,12 @@ void _dl_get_ready_to_run(struct elf_res
  189. _dl_progname = argv[0];
  190. }
  191. +#if 0 // blackfin does this, we do to avoid die during reloc
  192. if (_start == (void *) auxvt[AT_ENTRY].a_un.a_val) {
  193. _dl_dprintf(_dl_debug_file, "Standalone execution is not supported yet\n");
  194. _dl_exit(1);
  195. }
  196. +#endif
  197. /* Start to build the tables of the modules that are required for
  198. * this beast to run. We start with the basic executable, and then
  199. --- /dev/null
  200. +++ b/ldso/ldso/ubicom32/dl-debug.h
  201. @@ -0,0 +1,72 @@
  202. +/* vi: set sw=4 ts=4: */
  203. +/* Ubicom32 ELF shared library loader suppport
  204. + *
  205. + * Copyright (c) 2009 Ubicom Inc.
  206. + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
  207. + * David Engel, Hongjiu Lu and Mitch D'Souza
  208. + * Copyright (C) 2001-2004 Erik Andersen
  209. + *
  210. + * All rights reserved.
  211. + *
  212. + * Redistribution and use in source and binary forms, with or without
  213. + * modification, are permitted provided that the following conditions
  214. + * are met:
  215. + * 1. Redistributions of source code must retain the above copyright
  216. + * notice, this list of conditions and the following disclaimer.
  217. + * 2. The name of the above contributors may not be
  218. + * used to endorse or promote products derived from this software
  219. + * without specific prior written permission.
  220. + *
  221. + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  222. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  223. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  224. + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  225. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  226. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  227. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  228. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  229. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  230. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  231. + * SUCH DAMAGE.
  232. + */
  233. +
  234. +static const char *_dl_reltypes_tab[] =
  235. +{
  236. + "R_UBICOM32_NONE", /* 0 */
  237. + "R_UBICOM32_16",
  238. + "R_UBICOM32_32",
  239. + "R_UBICOM32_LO16",
  240. + "R_UBICOM32_HI16",
  241. + "R_UBICOM32_21_PCREL", /* 5 */
  242. + "R_UBICOM32_24_PCREL",
  243. + "R_UBICOM32_HI24",
  244. + "R_UBICOM32_LO7_S",
  245. + "R_UBICOM32_LO7_2_S",
  246. + "R_UBICOM32_LO7_4_S", /* 10 */
  247. + "R_UBICOM32_LO7_D",
  248. + "R_UBICOM32_LO7_2_D",
  249. + "R_UBICOM32_LO7_4_D",
  250. + "R_UBICOM32_32_HARVARD",
  251. + "R_UBICOM32_LO7_CALLI", /* 15 */
  252. + "R_UBICOM32_LO16_CALLI",
  253. + "R_UBICOM32_GOT_HI24",
  254. + "R_UBICOM32_GOT_LO7_S",
  255. + "R_UBICOM32_GOT_LO7_2_S"
  256. + "R_UBICOM32_GOT_LO7_4_S", /* 20 */
  257. + "R_UBICOM32_GOT_LO7_D",
  258. + "R_UBICOM32_GOT_LO7_2_D",
  259. + "R_UBICOM32_GOT_LO7_4_D",
  260. + "R_UBICOM32_FUNCDESC_GOT_HI24 24",
  261. + "R_UBICOM32_FUNCDESC_GOT_LO7_S", /* 25 */
  262. + "R_UBICOM32_FUNCDESC_GOT_LO7_2_S",
  263. + "R_UBICOM32_FUNCDESC_GOT_LO7_4_S",
  264. + "R_UBICOM32_FUNCDESC_GOT_LO7_D",
  265. + "R_UBICOM32_FUNCDESC_GOT_LO7_2_D",
  266. + "R_UBICOM32_FUNCDESC_GOT_LO7_4_D", /* 30 */
  267. + "R_UBICOM32_GOT_LO7_CALLI",
  268. + "R_UBICOM32_FUNCDESC_VALUE",
  269. + "R_UBICOM32_FUNCDESC",
  270. +#if 1
  271. + [200] "R_UBICOM32_GNU_VTINHERIT" , "R_UBICOM32_GNU_VTENTRY"
  272. +#endif
  273. +};
  274. --- /dev/null
  275. +++ b/ldso/ldso/ubicom32/dl-inlines.h
  276. @@ -0,0 +1,582 @@
  277. + /* Copyright (C) 2003, 2004 Red Hat, Inc.
  278. + Contributed by Alexandre Oliva <[email protected]>
  279. +
  280. +This file is part of uClibc.
  281. +
  282. +uClibc is free software; you can redistribute it and/or modify it
  283. +under the terms of the GNU Lesser General Public License as
  284. +published by the Free Software Foundation; either version 2.1 of the
  285. +License, or (at your option) any later version.
  286. +
  287. +uClibc is distributed in the hope that it will be useful, but WITHOUT
  288. +ANY WARRANTY; without even the implied warranty of
  289. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  290. +Library General Public License for more details.
  291. +
  292. +You should have received a copy of the GNU Lesser General Public
  293. +License along with uClibc; see the file COPYING.LIB. If not, write to
  294. +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  295. +USA. */
  296. +
  297. +//#include <bfin_sram.h>
  298. +#define SRAM_TEST(x) 0
  299. +#ifndef _dl_assert
  300. +# define _dl_assert(expr)
  301. +#endif
  302. +
  303. +/* Initialize a DL_LOADADDR_TYPE given a got pointer and a complete
  304. + load map. */
  305. +static __always_inline void
  306. +__dl_init_loadaddr_map (struct elf32_fdpic_loadaddr *loadaddr, Elf32_Addr dl_boot_got_pointer,
  307. + struct elf32_fdpic_loadmap *map)
  308. +{
  309. + if (map->version != 0)
  310. + {
  311. + SEND_EARLY_STDERR ("Invalid loadmap version number\n");
  312. + _dl_exit(-1);
  313. + }
  314. + if (map->nsegs == 0)
  315. + {
  316. + SEND_EARLY_STDERR ("Invalid segment count in loadmap\n");
  317. + _dl_exit(-1);
  318. + }
  319. + loadaddr->got_value = (void*)dl_boot_got_pointer;
  320. + loadaddr->map = map;
  321. +}
  322. +
  323. +/* Figure out how many LOAD segments there are in the given headers,
  324. + and allocate a block for the load map big enough for them.
  325. + got_value will be properly initialized later on, with INIT_GOT. */
  326. +static __always_inline int
  327. +__dl_init_loadaddr (struct elf32_fdpic_loadaddr *loadaddr, Elf32_Phdr *ppnt,
  328. + int pcnt)
  329. +{
  330. + int count = 0, i;
  331. + size_t size;
  332. +
  333. + for (i = 0; i < pcnt; i++)
  334. + if (ppnt[i].p_type == PT_LOAD)
  335. + count++;
  336. +
  337. + loadaddr->got_value = 0;
  338. +
  339. + size = sizeof (struct elf32_fdpic_loadmap)
  340. + + sizeof (struct elf32_fdpic_loadseg) * count;
  341. + loadaddr->map = _dl_malloc (size);
  342. + if (! loadaddr->map)
  343. + _dl_exit (-1);
  344. +
  345. + loadaddr->map->version = 0;
  346. + loadaddr->map->nsegs = 0;
  347. +
  348. + return count;
  349. +}
  350. +
  351. +#if defined (__SUPPORT_LD_DEBUG__)
  352. +extern char *_dl_debug;
  353. +extern int _dl_debug_file;
  354. +#endif
  355. +
  356. +/* Incrementally initialize a load map. */
  357. +static __always_inline void
  358. +__dl_init_loadaddr_hdr (struct elf32_fdpic_loadaddr loadaddr, void *addr,
  359. + Elf32_Phdr *phdr, int maxsegs)
  360. +{
  361. + struct elf32_fdpic_loadseg *segdata;
  362. +
  363. + if (loadaddr.map->nsegs == maxsegs)
  364. + _dl_exit (-1);
  365. +
  366. + segdata = &loadaddr.map->segs[loadaddr.map->nsegs++];
  367. + segdata->addr = (Elf32_Addr) addr;
  368. + segdata->p_vaddr = phdr->p_vaddr;
  369. + segdata->p_memsz = phdr->p_memsz;
  370. +
  371. +#if defined (__SUPPORT_LD_DEBUG__)
  372. + {
  373. + if (_dl_debug)
  374. + _dl_dprintf(_dl_debug_file, "%i: mapped %x at %x, size %x\n",
  375. + loadaddr.map->nsegs-1,
  376. + segdata->p_vaddr, segdata->addr, segdata->p_memsz);
  377. + }
  378. +#endif
  379. +}
  380. +
  381. +static __always_inline void __dl_loadaddr_unmap
  382. +(struct elf32_fdpic_loadaddr loadaddr, struct funcdesc_ht *funcdesc_ht);
  383. +
  384. +/* Figure out whether the given address is in one of the mapped
  385. + segments. */
  386. +static __always_inline int
  387. +__dl_addr_in_loadaddr (void *p, struct elf32_fdpic_loadaddr loadaddr)
  388. +{
  389. + struct elf32_fdpic_loadmap *map = loadaddr.map;
  390. + int c;
  391. +
  392. + for (c = 0; c < map->nsegs; c++)
  393. + if ((void*)map->segs[c].addr <= p
  394. + && (char*)p < (char*)map->segs[c].addr + map->segs[c].p_memsz)
  395. + return 1;
  396. +
  397. + return 0;
  398. +}
  399. +
  400. +static __always_inline void * _dl_funcdesc_for (void *entry_point, void *got_value);
  401. +
  402. +/* The hashcode handling code below is heavily inspired in libiberty's
  403. + hashtab code, but with most adaptation points and support for
  404. + deleting elements removed.
  405. +
  406. + Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
  407. + Contributed by Vladimir Makarov ([email protected]). */
  408. +
  409. +static __always_inline unsigned long
  410. +higher_prime_number (unsigned long n)
  411. +{
  412. + /* These are primes that are near, but slightly smaller than, a
  413. + power of two. */
  414. + static const unsigned long primes[] = {
  415. + (unsigned long) 7,
  416. + (unsigned long) 13,
  417. + (unsigned long) 31,
  418. + (unsigned long) 61,
  419. + (unsigned long) 127,
  420. + (unsigned long) 251,
  421. + (unsigned long) 509,
  422. + (unsigned long) 1021,
  423. + (unsigned long) 2039,
  424. + (unsigned long) 4093,
  425. + (unsigned long) 8191,
  426. + (unsigned long) 16381,
  427. + (unsigned long) 32749,
  428. + (unsigned long) 65521,
  429. + (unsigned long) 131071,
  430. + (unsigned long) 262139,
  431. + (unsigned long) 524287,
  432. + (unsigned long) 1048573,
  433. + (unsigned long) 2097143,
  434. + (unsigned long) 4194301,
  435. + (unsigned long) 8388593,
  436. + (unsigned long) 16777213,
  437. + (unsigned long) 33554393,
  438. + (unsigned long) 67108859,
  439. + (unsigned long) 134217689,
  440. + (unsigned long) 268435399,
  441. + (unsigned long) 536870909,
  442. + (unsigned long) 1073741789,
  443. + (unsigned long) 2147483647,
  444. + /* 4294967291L */
  445. + ((unsigned long) 2147483647) + ((unsigned long) 2147483644),
  446. + };
  447. +
  448. + const unsigned long *low = &primes[0];
  449. + const unsigned long *high = &primes[sizeof(primes) / sizeof(primes[0])];
  450. +
  451. + while (low != high)
  452. + {
  453. + const unsigned long *mid = low + (high - low) / 2;
  454. + if (n > *mid)
  455. + low = mid + 1;
  456. + else
  457. + high = mid;
  458. + }
  459. +
  460. +#if 0
  461. + /* If we've run out of primes, abort. */
  462. + if (n > *low)
  463. + {
  464. + fprintf (stderr, "Cannot find prime bigger than %lu\n", n);
  465. + abort ();
  466. + }
  467. +#endif
  468. +
  469. + return *low;
  470. +}
  471. +
  472. +struct funcdesc_ht
  473. +{
  474. + /* Table itself. */
  475. + struct funcdesc_value **entries;
  476. +
  477. + /* Current size (in entries) of the hash table */
  478. + size_t size;
  479. +
  480. + /* Current number of elements. */
  481. + size_t n_elements;
  482. +};
  483. +
  484. +static __always_inline int
  485. +hash_pointer (const void *p)
  486. +{
  487. + return (int) ((long)p >> 3);
  488. +}
  489. +
  490. +static __always_inline struct funcdesc_ht *
  491. +htab_create (void)
  492. +{
  493. + struct funcdesc_ht *ht = _dl_malloc (sizeof (struct funcdesc_ht));
  494. +
  495. + if (! ht)
  496. + return NULL;
  497. + ht->size = 3;
  498. + ht->entries = _dl_malloc (sizeof (struct funcdesc_ht_value *) * ht->size);
  499. + if (! ht->entries)
  500. + return NULL;
  501. +
  502. + ht->n_elements = 0;
  503. +
  504. + _dl_memset (ht->entries, 0, sizeof (struct funcdesc_ht_value *) * ht->size);
  505. +
  506. + return ht;
  507. +}
  508. +
  509. +/* This is only called from _dl_loadaddr_unmap, so it's safe to call
  510. + _dl_free(). See the discussion below. */
  511. +static __always_inline void
  512. +htab_delete (struct funcdesc_ht *htab)
  513. +{
  514. + int i;
  515. +
  516. + for (i = htab->size - 1; i >= 0; i--)
  517. + if (htab->entries[i])
  518. + _dl_free (htab->entries[i]);
  519. +
  520. + _dl_free (htab->entries);
  521. + _dl_free (htab);
  522. +}
  523. +
  524. +/* Similar to htab_find_slot, but without several unwanted side effects:
  525. + - Does not call htab->eq_f when it finds an existing entry.
  526. + - Does not change the count of elements/searches/collisions in the
  527. + hash table.
  528. + This function also assumes there are no deleted entries in the table.
  529. + HASH is the hash value for the element to be inserted. */
  530. +
  531. +static __always_inline struct funcdesc_value **
  532. +find_empty_slot_for_expand (struct funcdesc_ht *htab, int hash)
  533. +{
  534. + size_t size = htab->size;
  535. + unsigned int index = hash % size;
  536. + struct funcdesc_value **slot = htab->entries + index;
  537. + int hash2;
  538. +
  539. + if (! *slot)
  540. + return slot;
  541. +
  542. + hash2 = 1 + hash % (size - 2);
  543. + for (;;)
  544. + {
  545. + index += hash2;
  546. + if (index >= size)
  547. + index -= size;
  548. +
  549. + slot = htab->entries + index;
  550. + if (! *slot)
  551. + return slot;
  552. + }
  553. +}
  554. +
  555. +/* The following function changes size of memory allocated for the
  556. + entries and repeatedly inserts the table elements. The occupancy
  557. + of the table after the call will be about 50%. Naturally the hash
  558. + table must already exist. Remember also that the place of the
  559. + table entries is changed. If memory allocation failures are allowed,
  560. + this function will return zero, indicating that the table could not be
  561. + expanded. If all goes well, it will return a non-zero value. */
  562. +
  563. +static __always_inline int
  564. +htab_expand (struct funcdesc_ht *htab)
  565. +{
  566. + struct funcdesc_value **oentries;
  567. + struct funcdesc_value **olimit;
  568. + struct funcdesc_value **p;
  569. + struct funcdesc_value **nentries;
  570. + size_t nsize;
  571. +
  572. + oentries = htab->entries;
  573. + olimit = oentries + htab->size;
  574. +
  575. + /* Resize only when table after removal of unused elements is either
  576. + too full or too empty. */
  577. + if (htab->n_elements * 2 > htab->size)
  578. + nsize = higher_prime_number (htab->n_elements * 2);
  579. + else
  580. + nsize = htab->size;
  581. +
  582. + nentries = _dl_malloc (sizeof (struct funcdesc_value *) * nsize);
  583. + _dl_memset (nentries, 0, sizeof (struct funcdesc_value *) * nsize);
  584. + if (nentries == NULL)
  585. + return 0;
  586. + htab->entries = nentries;
  587. + htab->size = nsize;
  588. +
  589. + p = oentries;
  590. + do
  591. + {
  592. + if (*p)
  593. + *find_empty_slot_for_expand (htab, hash_pointer ((*p)->entry_point))
  594. + = *p;
  595. +
  596. + p++;
  597. + }
  598. + while (p < olimit);
  599. +
  600. +#if 0 /* We can't tell whether this was allocated by the _dl_malloc()
  601. + built into ld.so or malloc() in the main executable or libc,
  602. + and calling free() for something that wasn't malloc()ed could
  603. + do Very Bad Things (TM). Take the conservative approach
  604. + here, potentially wasting as much memory as actually used by
  605. + the hash table, even if multiple growths occur. That's not
  606. + so bad as to require some overengineered solution that would
  607. + enable us to keep track of how it was allocated. */
  608. + _dl_free (oentries);
  609. +#endif
  610. + return 1;
  611. +}
  612. +
  613. +/* This function searches for a hash table slot containing an entry
  614. + equal to the given element. To delete an entry, call this with
  615. + INSERT = 0, then call htab_clear_slot on the slot returned (possibly
  616. + after doing some checks). To insert an entry, call this with
  617. + INSERT = 1, then write the value you want into the returned slot.
  618. + When inserting an entry, NULL may be returned if memory allocation
  619. + fails. */
  620. +
  621. +static __always_inline struct funcdesc_value **
  622. +htab_find_slot (struct funcdesc_ht *htab, void *ptr, int insert)
  623. +{
  624. + unsigned int index;
  625. + int hash, hash2;
  626. + size_t size;
  627. + struct funcdesc_value **entry;
  628. +
  629. + if (htab->size * 3 <= htab->n_elements * 4
  630. + && htab_expand (htab) == 0)
  631. + return NULL;
  632. +
  633. + hash = hash_pointer (ptr);
  634. +
  635. + size = htab->size;
  636. + index = hash % size;
  637. +
  638. + entry = &htab->entries[index];
  639. + if (!*entry)
  640. + goto empty_entry;
  641. + else if ((*entry)->entry_point == ptr)
  642. + return entry;
  643. +
  644. + hash2 = 1 + hash % (size - 2);
  645. + for (;;)
  646. + {
  647. + index += hash2;
  648. + if (index >= size)
  649. + index -= size;
  650. +
  651. + entry = &htab->entries[index];
  652. + if (!*entry)
  653. + goto empty_entry;
  654. + else if ((*entry)->entry_point == ptr)
  655. + return entry;
  656. + }
  657. +
  658. + empty_entry:
  659. + if (!insert)
  660. + return NULL;
  661. +
  662. + htab->n_elements++;
  663. + return entry;
  664. +}
  665. +
  666. +void *
  667. +_dl_funcdesc_for (void *entry_point, void *got_value)
  668. +{
  669. + struct elf_resolve *tpnt = ((void**)got_value)[2];
  670. + struct funcdesc_ht *ht = tpnt->funcdesc_ht;
  671. + struct funcdesc_value **entry;
  672. +
  673. + _dl_assert (got_value == tpnt->loadaddr.got_value);
  674. +
  675. + if (! ht)
  676. + {
  677. + ht = htab_create ();
  678. + if (! ht)
  679. + return (void*)-1;
  680. + tpnt->funcdesc_ht = ht;
  681. + }
  682. +
  683. + entry = htab_find_slot (ht, entry_point, 1);
  684. + if (*entry)
  685. + {
  686. + _dl_assert ((*entry)->entry_point == entry_point);
  687. + return _dl_stabilize_funcdesc (*entry);
  688. + }
  689. +
  690. + *entry = _dl_malloc (sizeof (struct funcdesc_value));
  691. + (*entry)->entry_point = entry_point;
  692. + (*entry)->got_value = got_value;
  693. +
  694. + return _dl_stabilize_funcdesc (*entry);
  695. +}
  696. +
  697. +static __always_inline void const *
  698. +_dl_lookup_address (void const *address)
  699. +{
  700. + struct elf_resolve *rpnt;
  701. + struct funcdesc_value const *fd;
  702. +
  703. + /* Make sure we don't make assumptions about its alignment. */
  704. + __asm__ ("" : "+r" (address));
  705. +
  706. + if ((Elf32_Addr)address & 7)
  707. + /* It's not a function descriptor. */
  708. + return address;
  709. +
  710. + fd = (struct funcdesc_value const *)address;
  711. +
  712. + for (rpnt = _dl_loaded_modules; rpnt; rpnt = rpnt->next)
  713. + {
  714. + if (! rpnt->funcdesc_ht)
  715. + continue;
  716. +
  717. + if (fd->got_value != rpnt->loadaddr.got_value)
  718. + continue;
  719. +
  720. + address = htab_find_slot (rpnt->funcdesc_ht, (void*)fd->entry_point, 0);
  721. +
  722. + if (address && *(struct funcdesc_value *const*)address == fd)
  723. + {
  724. + address = (*(struct funcdesc_value *const*)address)->entry_point;
  725. + break;
  726. + }
  727. + else
  728. + address = fd;
  729. + }
  730. +
  731. + return address;
  732. +}
  733. +
  734. +void
  735. +__dl_loadaddr_unmap (struct elf32_fdpic_loadaddr loadaddr,
  736. + struct funcdesc_ht *funcdesc_ht)
  737. +{
  738. + int i;
  739. +
  740. + for (i = 0; i < loadaddr.map->nsegs; i++)
  741. + {
  742. + struct elf32_fdpic_loadseg *segdata;
  743. + ssize_t offs;
  744. + segdata = loadaddr.map->segs + i;
  745. +
  746. +#if 0 /* SRAM */
  747. + /* FIXME:
  748. + A more cleaner way is to add type for struct elf32_fdpic_loadseg,
  749. + and release the memory according to the type.
  750. + Currently, we hardcode the memory address of L1 SRAM. */
  751. + if ((segdata->addr & 0xff800000) == 0xff800000)
  752. + {
  753. + _dl_sram_free ((void *)segdata->addr);
  754. + continue;
  755. + }
  756. +#endif
  757. + offs = (segdata->p_vaddr & ADDR_ALIGN);
  758. + _dl_munmap ((void*)segdata->addr - offs,
  759. + segdata->p_memsz + offs);
  760. + }
  761. + /* _dl_unmap is only called for dlopen()ed libraries, for which
  762. + calling free() is safe, or before we've completed the initial
  763. + relocation, in which case calling free() is probably pointless,
  764. + but still safe. */
  765. + _dl_free (loadaddr.map);
  766. + if (funcdesc_ht)
  767. + htab_delete (funcdesc_ht);
  768. +}
  769. +
  770. +#if 0 /* XXX TODO will look at enabling this if we decide to add support for OCM
  771. + * code/data */
  772. +// OLD BLACKFIN CODE
  773. +static __always_inline int
  774. +__dl_is_special_segment (Elf32_Ehdr *epnt,
  775. + Elf32_Phdr *ppnt)
  776. +{
  777. + if (ppnt->p_type != PT_LOAD)
  778. + return 0;
  779. +
  780. + if ((epnt->e_flags & EF_BFIN_CODE_IN_L1)
  781. + && !(ppnt->p_flags & PF_W)
  782. + && (ppnt->p_flags & PF_X))
  783. + return 1;
  784. +
  785. + if ((epnt->e_flags & EF_BFIN_DATA_IN_L1)
  786. + && (ppnt->p_flags & PF_W)
  787. + && !(ppnt->p_flags & PF_X))
  788. + return 1;
  789. +
  790. + /* 0xff700000, 0xff800000, 0xff900000 and 0xffa00000 are also used in
  791. + GNU ld and linux kernel. They need to be keep synchronized. */
  792. + if (ppnt->p_vaddr == 0xff700000
  793. + || ppnt->p_vaddr == 0xff800000
  794. + || ppnt->p_vaddr == 0xff900000
  795. + || ppnt->p_vaddr == 0xffa00000)
  796. + return 1;
  797. +
  798. + return 0;
  799. +}
  800. +
  801. +static __always_inline char *
  802. +__dl_map_segment (Elf32_Ehdr *epnt,
  803. + Elf32_Phdr *ppnt,
  804. + int infile,
  805. + int flags)
  806. +{
  807. + char *status, *tryaddr, *l1addr;
  808. + size_t size;
  809. +
  810. +
  811. + if (((epnt->e_flags & EF_BFIN_CODE_IN_L1) || ppnt->p_vaddr == 0xffa00000)
  812. + && !(ppnt->p_flags & PF_W)
  813. + && (ppnt->p_flags & PF_X)) {
  814. + status = (char *) _dl_mmap
  815. + (tryaddr = 0,
  816. + size = (ppnt->p_vaddr & ADDR_ALIGN) + ppnt->p_filesz,
  817. + LXFLAGS(ppnt->p_flags),
  818. + flags | MAP_EXECUTABLE | MAP_DENYWRITE,
  819. + infile, ppnt->p_offset & OFFS_ALIGN);
  820. + if (_dl_mmap_check_error(status)
  821. + || (tryaddr && tryaddr != status))
  822. + return NULL;
  823. + l1addr = (char *) _dl_sram_alloc (ppnt->p_filesz, L1_INST_SRAM);
  824. + if (l1addr != NULL)
  825. + _dl_dma_memcpy (l1addr, status + (ppnt->p_vaddr & ADDR_ALIGN), ppnt->p_filesz);
  826. + _dl_munmap (status, size);
  827. + if (l1addr == NULL)
  828. + _dl_dprintf(2, "%s:%i: L1 allocation failed\n", _dl_progname, __LINE__);
  829. + return l1addr;
  830. + }
  831. +
  832. + if (((epnt->e_flags & EF_BFIN_DATA_IN_L1)
  833. + || ppnt->p_vaddr == 0xff700000
  834. + || ppnt->p_vaddr == 0xff800000
  835. + || ppnt->p_vaddr == 0xff900000)
  836. + && (ppnt->p_flags & PF_W)
  837. + && !(ppnt->p_flags & PF_X)) {
  838. + if (ppnt->p_vaddr == 0xff800000)
  839. + l1addr = (char *) _dl_sram_alloc (ppnt->p_memsz, L1_DATA_A_SRAM);
  840. + else if (ppnt->p_vaddr == 0xff900000)
  841. + l1addr = (char *) _dl_sram_alloc (ppnt->p_memsz, L1_DATA_B_SRAM);
  842. + else
  843. + l1addr = (char *) _dl_sram_alloc (ppnt->p_memsz, L1_DATA_SRAM);
  844. + if (l1addr == NULL) {
  845. + _dl_dprintf(2, "%s:%i: L1 allocation failed\n", _dl_progname, __LINE__);
  846. + } else {
  847. + if (_DL_PREAD (infile, l1addr, ppnt->p_filesz, ppnt->p_offset) != ppnt->p_filesz) {
  848. + _dl_sram_free (l1addr);
  849. + return NULL;
  850. + }
  851. + if (ppnt->p_filesz < ppnt->p_memsz)
  852. + _dl_memset (l1addr + ppnt->p_filesz, 0, ppnt->p_memsz - ppnt->p_filesz);
  853. + }
  854. + return l1addr;
  855. + }
  856. + return 0;
  857. +}
  858. +#endif
  859. --- /dev/null
  860. +++ b/ldso/ldso/ubicom32/dl-startup.h
  861. @@ -0,0 +1,232 @@
  862. +/*
  863. + Copyright (C) 2009 Ubicom, Inc.
  864. + Copyright (C) 2003 Red Hat, Inc.
  865. + Contributed by Alexandre Oliva <[email protected]>
  866. +
  867. +This file is part of uClibc.
  868. +
  869. +uClibc is free software; you can redistribute it and/or modify it
  870. +under the terms of the GNU Lesser General Public License as
  871. +published by the Free Software Foundation; either version 2.1 of the
  872. +License, or (at your option) any later version.
  873. +
  874. +uClibc is distributed in the hope that it will be useful, but WITHOUT
  875. +ANY WARRANTY; without even the implied warranty of
  876. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  877. +Library General Public License for more details.
  878. +
  879. +You should have received a copy of the GNU Lesser General Public
  880. +License along with uClibc; see the file COPYING.LIB. If not, write to
  881. +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  882. +USA. */
  883. +
  884. +/* Any assembly language/system dependent hacks needed to setup
  885. + * boot1.c so it will work as expected and cope with whatever platform
  886. + * specific wierdness is needed for this architecture.
  887. +
  888. + * We override the default _dl_boot function, and replace it with a
  889. + * bit of asm. Then call the real _dl_boot function, which is now
  890. + * named _dl_boot2. */
  891. +
  892. +/* At program start-up, p0 contains a pointer to a
  893. + elf32_fdpic_loadmap that describes how the executable was loaded
  894. + into memory. p1 contains a pointer to the interpreter (our!)
  895. + loadmap, if there is an interpreter, or 0 if we're being run as an
  896. + executable. p2 holds a pointer to the interpreter's dynamic
  897. + section, if there is an interpreter, or to the executable's dynamic
  898. + section, otherwise. If the executable is not dynamic, gr18 is 0.
  899. +
  900. + We rely on the fact that the linker adds a pointer to the
  901. + _GLOBAL_OFFSET_TABLE_ as the last ROFIXUP entry, and that
  902. + __self_reloc returns the relocated pointer to us, so that we can
  903. + use this value to initialize the PIC register. */
  904. +
  905. +
  906. +/*
  907. + * _dl_boot is the entry point for ldso.
  908. + *
  909. + * The kernel leaves the main apps args on the stack (positive offsets), and
  910. + * communicates the load maps as follows
  911. + *
  912. + * - d1 is set to the exec_map_addr (struct elf32_fdpic_loadmap *), which is the
  913. + * current state of the mapped application.
  914. + *
  915. + * - d2 is set to interp_map_addr (struct elf32_fdpic_loadmap *), which is use
  916. + * by ldso to relocate itself.
  917. + *
  918. + * - d3 is dynamic_addr which as far as I can tell is the stack pointer.
  919. + *
  920. + * - a1 is set to zero and will later be initialised to ldso _dl_fini funcdesc
  921. + */
  922. +
  923. +__asm__(
  924. + " .text \n\t"
  925. + " .global _start \n\t"
  926. + " .type _start,@function \n\t"
  927. + "_start:\n\t"
  928. + /*
  929. + * Jump to .Lcall storing the location .Lcall in a5
  930. + */
  931. + " call a5, .Lcall \n\t"
  932. + ".Lcall: \n\t"
  933. + /*
  934. + * Reserve and Push inputs to stack.
  935. + * 32 byte stack layout as follows
  936. + * offset 0 exec_map_addr
  937. + * 4 interp_map_addr
  938. + * 8 dynamic_addr
  939. + * 12 not used
  940. + * 16 dl_main_funcdesc structure for _dl_boot
  941. + * (12 bytes sizeof funcdesc_value)
  942. + * 28 reserved
  943. + * 32 start of &original stack
  944. + */
  945. + " pdec sp, 32(sp); reserve stack space \n\t"
  946. + " move.4 0(sp), d1 ; exec_map_addr \n\t"
  947. + " move.4 4(sp), d2 ; interp_map_addr \n\t"
  948. + " move.4 8(sp), d3; dynamic_addr \n\t"
  949. +
  950. + /*
  951. + * Load linker version of .Lcall in to d0
  952. + */
  953. + " moveai a3, #%hi(.Lcall) \n\t"
  954. + " lea.1 d0, %lo(.Lcall)(a3) \n\t"
  955. +
  956. + /*
  957. + * Determine the offset from loaded .Lcall and put it in d0.
  958. + */
  959. + " sub.4 d0, a5, d0 \n\t"
  960. +
  961. + /*
  962. + * Load linker version of __ROFIXUP_LIST__ and __ROFIXUP_END__ in to d1
  963. + * and d2.
  964. + */
  965. + " moveai a3, #%hi(__ROFIXUP_LIST__) \n\t"
  966. + " lea.1 d1, %lo(__ROFIXUP_LIST__)(a3) \n\t"
  967. + " moveai a3, #%hi(__ROFIXUP_END__) \n\t"
  968. + " lea.1 d2, %lo(__ROFIXUP_END__)(a3) \n\t"
  969. + /*
  970. + * Use offset determined above to find the loaded versions.
  971. + */
  972. + " add.4 d1, d1, d0 \n\t"
  973. + " add.4 d2, d2, d0 \n\t"
  974. +
  975. + /*
  976. + * Load interp_map_addr into d0, if interp_map_addr is null use
  977. + * exec_map_addr.
  978. + */
  979. + " move.4 d0, 4(sp) ; load interp_map_addr \n\t"
  980. + " cmpi d0, #0 \n\t"
  981. + " jmpne.f 1f \n\t"
  982. + " move.4 d0, 0(sp) ; load exec_map_addr \n\t"
  983. +
  984. + /*
  985. + * call __self_reloc(map, void ***p, void ***e)
  986. + * it returns the the GOT in d0.
  987. + */
  988. + "1: call a5, __self_reloc ; returns a0 in d0 \n\t"
  989. + " move.4 a0, d0 ; set GOT \n\t"
  990. + " move.4 a2, d0 ; save GOT \n\t"
  991. +
  992. + /*
  993. + * now setup to call
  994. + * _dl_start (Elf32_Addr dl_boot_got_pointer, (d0)
  995. + * struct elf32_fdpic_loadmap *dl_boot_progmap, (d1)
  996. + * struct elf32_fdpic_loadmap *dl_boot_ldsomap, (d2)
  997. + * Elf32_Dyn *dl_boot_ldso_dyn_pointer, (d3)
  998. + * struct funcdesc_value *dl_main_funcdesc, (d4)
  999. + * unsigned long args (d5)
  1000. + *
  1001. + * NOTE: for dl_main_funcdesc we reserved space on the stack for this
  1002. + * structure.
  1003. + */
  1004. + " move.4 d1, 0(sp) ; d1 = exec_map_addr \n\t"
  1005. + " move.4 d2, 4(sp) ; d2 = interp_map_addr \n\t"
  1006. + " move.4 d3, 8(sp) ; d3 = dynamic_addr \n\t"
  1007. + " lea.1 d4, 16(sp) ; d4 = &dl_main_funcdesc \n\t"
  1008. + " lea.1 d5, 32(sp) ; d5 = original stack ptr (args)\n\t"
  1009. + " call a5, _dl_start \n\t"
  1010. +
  1011. + /*
  1012. + * Setup to call the main entry point, starting with passing our FINI
  1013. + * ptr() to the user in a1 (remember we saved the got in a2)
  1014. + */
  1015. + " movei d15, #%got_funcdesc_lo(_dl_fini) \n\t"
  1016. + " move.4 a1, (a2, d15) \n\t"
  1017. +
  1018. + /*
  1019. + * restore the load map from the kernel.
  1020. + */
  1021. + " move.4 d1, 0(sp) ; restore exec_map_addr \n\t"
  1022. + " move.4 d2, 4(sp) ; restore interp_map_addr \n\t"
  1023. + " move.4 d3, 8(sp) ; restore dynamic_addr \n\t"
  1024. +
  1025. + /*
  1026. + * _dl_start returned the main apps entry point in dl_main_funcdesc,
  1027. + * load that information now.
  1028. + */
  1029. + " move.4 a5, 16(sp) ; a5 = dl_main_funcdesc.entry_point \n\t"
  1030. + " move.4 a0, 20(sp) ; a0 = dl_main_funcdesc.got_value \n\t"
  1031. + " lea.1 sp, 32(sp); restore original stack ptr (args) \n\t"
  1032. + " calli a5, 0(a5) \n\t"
  1033. + " bkpt -1; should never get here \n\t"
  1034. + " .size _start, . - _start \n\t"
  1035. +);
  1036. +
  1037. +#undef DL_START
  1038. +#define DL_START(X) \
  1039. +static void __attribute__ ((used)) \
  1040. +_dl_start (Elf32_Addr dl_boot_got_pointer, \
  1041. + struct elf32_fdpic_loadmap *dl_boot_progmap, \
  1042. + struct elf32_fdpic_loadmap *dl_boot_ldsomap, \
  1043. + Elf32_Dyn *dl_boot_ldso_dyn_pointer, \
  1044. + struct funcdesc_value *dl_main_funcdesc, \
  1045. + X)
  1046. +
  1047. +struct elf32_fdpic_loadmap;
  1048. +
  1049. +/*
  1050. + * Get a pointer to the argv array. On many platforms this can be just
  1051. + * the address if the first argument, on other platforms we need to
  1052. + * do something a little more subtle here.
  1053. + */
  1054. +#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS) + 1)
  1055. +
  1056. +/*
  1057. + * Here is a macro to perform a relocation. This is only used when
  1058. + * bootstrapping the dynamic loader. RELP is the relocation that we
  1059. + * are performing, REL is the pointer to the address we are relocating.
  1060. + * SYMBOL is the symbol involved in the relocation, and LOAD is the
  1061. + * load address.
  1062. + */
  1063. +#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  1064. + switch(ELF32_R_TYPE((RELP)->r_info)){ \
  1065. + case R_UBICOM32_32: \
  1066. + *(REL) += (SYMBOL); \
  1067. + break; \
  1068. + case R_UBICOM32_FUNCDESC_VALUE: \
  1069. + { \
  1070. + struct funcdesc_value fv = { \
  1071. + (void*)((SYMBOL) + *(REL)), \
  1072. + (LOAD).got_value \
  1073. + }; \
  1074. + *(struct funcdesc_value volatile *)(REL) = fv; \
  1075. + break; \
  1076. + } \
  1077. + default: \
  1078. + _dl_exit(1); \
  1079. + }
  1080. +
  1081. +/*
  1082. + * Transfer control to the user's application, once the dynamic loader
  1083. + * is done. We return the address of the function's entry point to
  1084. + * _dl_boot, see boot1_arch.h.
  1085. + */
  1086. +#define START() do { \
  1087. + struct elf_resolve *exec_mod = _dl_loaded_modules; \
  1088. + dl_main_funcdesc->entry_point = _dl_elf_main; \
  1089. + while (exec_mod->libtype != elf_executable) \
  1090. + exec_mod = exec_mod->next; \
  1091. + dl_main_funcdesc->got_value = exec_mod->loadaddr.got_value; \
  1092. + return; \
  1093. +} while (0)
  1094. --- /dev/null
  1095. +++ b/ldso/ldso/ubicom32/dl-syscalls.h
  1096. @@ -0,0 +1,206 @@
  1097. +/* Copyright (C) 2003, 2004 Red Hat, Inc.
  1098. + Contributed by Alexandre Oliva <[email protected]>
  1099. +
  1100. +This file is part of uClibc.
  1101. +
  1102. +uClibc is free software; you can redistribute it and/or modify it
  1103. +under the terms of the GNU Lesser General Public License as
  1104. +published by the Free Software Foundation; either version 2.1 of the
  1105. +License, or (at your option) any later version.
  1106. +
  1107. +uClibc is distributed in the hope that it will be useful, but WITHOUT
  1108. +ANY WARRANTY; without even the implied warranty of
  1109. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1110. +Library General Public License for more details.
  1111. +
  1112. +You should have received a copy of the GNU Lesser General Public
  1113. +License along with uClibc; see the file COPYING.LIB. If not, write to
  1114. +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  1115. +USA. */
  1116. +
  1117. +/* We can't use the real errno in ldso, since it has not yet
  1118. + * been dynamicly linked in yet. */
  1119. +#include "sys/syscall.h"
  1120. +extern int _dl_errno;
  1121. +#undef __set_errno
  1122. +#define __set_errno(X) {(_dl_errno) = (X);}
  1123. +#include <sys/mman.h>
  1124. +
  1125. +/* The code below is extracted from libc/sysdeps/linux/frv/_mmap.c */
  1126. +
  1127. +#if defined(DYNAMIC_LOADER_IN_SIMULATOR) && DYNAMIC_LOADER_IN_SIMULATOR
  1128. +#define __NR___syscall_mmap2 __NR_mmap2
  1129. +static __inline__ _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
  1130. + size_t, len, int, prot, int, flags, int, fd, off_t, offset);
  1131. +
  1132. +/* Make sure we don't get another definition of _dl_mmap from the
  1133. + machine-independent code. */
  1134. +#undef __NR_mmap
  1135. +#undef __NR_mmap2
  1136. +
  1137. +/* This is always 12, even on architectures where PAGE_SHIFT != 12. */
  1138. +# ifndef MMAP2_PAGE_SHIFT
  1139. +# define MMAP2_PAGE_SHIFT 12
  1140. +# endif
  1141. +
  1142. +#include <bits/uClibc_page.h> /* for PAGE_SIZE */
  1143. +static __always_inline void *_dl_memset(void*,int,size_t);
  1144. +static __always_inline ssize_t _dl_pread(int fd, void *buf, size_t count, off_t offset);
  1145. +
  1146. +static __ptr_t
  1147. +_dl_mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
  1148. +{
  1149. + size_t plen = (len + PAGE_SIZE - 1) & -PAGE_SIZE;
  1150. +
  1151. +/* This is a hack to enable the dynamic loader to run within a
  1152. + simulator that doesn't support mmap, with a number of very ugly
  1153. + tricks. Also, it's not as useful as it sounds, since only dynamic
  1154. + executables without DT_NEEDED dependencies can be run. AFAIK, they
  1155. + can only be created with -pie. This trick suffices to enable the
  1156. + dynamic loader to obtain a blank page that it maps early in the
  1157. + bootstrap. */
  1158. + if ((flags & MAP_FIXED) == 0)
  1159. + {
  1160. + void *_dl_mmap_base = 0;
  1161. + __ptr_t *ret = 0;
  1162. +
  1163. + if (! _dl_mmap_base)
  1164. + {
  1165. + void *stack;
  1166. + __asm__ ("mov sp, %0" : "=r" (stack));
  1167. + _dl_mmap_base = (void *)(((long)stack + 2 * PAGE_SIZE) & -PAGE_SIZE);
  1168. + retry:
  1169. + if (((void **)_dl_mmap_base)[0] == _dl_mmap_base
  1170. + && ((void **)_dl_mmap_base)[1023] == _dl_mmap_base
  1171. + && (((void **)_dl_mmap_base)[177]
  1172. + == ((void **)_dl_mmap_base)[771]))
  1173. + {
  1174. + while (((void**)_dl_mmap_base)[177])
  1175. + {
  1176. + _dl_mmap_base = ((void**)_dl_mmap_base)[177];
  1177. + if (!(((void **)_dl_mmap_base)[0] == _dl_mmap_base
  1178. + && ((void **)_dl_mmap_base)[1023] == _dl_mmap_base
  1179. + && (((void **)_dl_mmap_base)[177]
  1180. + == ((void**)_dl_mmap_base)[771])))
  1181. + ((void(*)())0)();
  1182. + }
  1183. + }
  1184. + else
  1185. + {
  1186. + int i;
  1187. + for (i = 0; i < (int)PAGE_SIZE; i++)
  1188. + if (*(char*)(_dl_mmap_base + i))
  1189. + break;
  1190. + if (i != PAGE_SIZE)
  1191. + {
  1192. + _dl_mmap_base = (void*)((long)_dl_mmap_base + PAGE_SIZE);
  1193. + goto retry;
  1194. + }
  1195. + ((void**)_dl_mmap_base)[-1] =
  1196. + ((void**)_dl_mmap_base)[0] =
  1197. + ((void**)_dl_mmap_base)[1023] =
  1198. + _dl_mmap_base;
  1199. + }
  1200. + }
  1201. +
  1202. + if (_dl_mmap_base)
  1203. + {
  1204. + if (!(((void **)_dl_mmap_base)[0] == _dl_mmap_base
  1205. + && ((void **)_dl_mmap_base)[1023] == _dl_mmap_base
  1206. + && (((void **)_dl_mmap_base)[177]
  1207. + == ((void**)_dl_mmap_base)[771])))
  1208. + ((void(*)())0)();
  1209. + ret = (__ptr_t)((char*)_dl_mmap_base + PAGE_SIZE);
  1210. + _dl_mmap_base =
  1211. + ((void**)_dl_mmap_base)[177] =
  1212. + ((void**)_dl_mmap_base)[771] =
  1213. + (char*)_dl_mmap_base + plen + PAGE_SIZE;
  1214. + ((void**)_dl_mmap_base)[0] =
  1215. + ((void**)_dl_mmap_base)[1023] =
  1216. + _dl_mmap_base;
  1217. + }
  1218. +
  1219. + if ((flags & MAP_ANONYMOUS) != 0)
  1220. + {
  1221. + _dl_memset (ret, 0, plen);
  1222. + return ret;
  1223. + }
  1224. +
  1225. + flags |= MAP_FIXED;
  1226. + addr = ret;
  1227. + }
  1228. + if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  1229. +#if 0
  1230. + __set_errno (EINVAL);
  1231. +#endif
  1232. + return MAP_FAILED;
  1233. + }
  1234. + if ((flags & MAP_FIXED) != 0)
  1235. + {
  1236. + if (_dl_pread(fd, addr, len, offset) != (ssize_t)len)
  1237. + return (void*)MAP_FAILED;
  1238. + if (plen != len)
  1239. + _dl_memset (addr + len, 0, plen - len);
  1240. + return addr;
  1241. + }
  1242. + return(__syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)));
  1243. +}
  1244. +#endif
  1245. +
  1246. +#ifdef __NR_pread64
  1247. +#ifdef DYNAMIC_LOADER_IN_SIMULATOR
  1248. +#include <unistd.h>
  1249. +
  1250. +#define __NR___syscall_lseek __NR_lseek
  1251. +static __always_inline unsigned long _dl_read(int fd, const void *buf, unsigned long count);
  1252. +
  1253. +static __always_inline _syscall3(__off_t, __syscall_lseek, int, fd, __off_t, offset,
  1254. + int, whence);
  1255. +static __always_inline ssize_t
  1256. +_dl_pread(int fd, void *buf, size_t count, off_t offset)
  1257. +{
  1258. + __off_t orig = __syscall_lseek (fd, 0, SEEK_CUR);
  1259. + ssize_t ret;
  1260. +
  1261. + if (orig == -1)
  1262. + return -1;
  1263. +
  1264. + if (__syscall_lseek (fd, offset, SEEK_SET) != offset)
  1265. + return -1;
  1266. +
  1267. + ret = _dl_read (fd, buf, count);
  1268. +
  1269. + if (__syscall_lseek (fd, orig, SEEK_SET) != orig)
  1270. + ((void(*)())0)();
  1271. +
  1272. + return ret;
  1273. +}
  1274. +#else
  1275. +#define __NR___syscall_pread __NR_pread64
  1276. +static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
  1277. + size_t, count, off_t, offset_hi, off_t, offset_lo);
  1278. +
  1279. +static __always_inline ssize_t
  1280. +_dl_pread(int fd, void *buf, size_t count, off_t offset)
  1281. +{
  1282. + return(__syscall_pread(fd,buf,count,__LONG_LONG_PAIR (offset >> 31, offset)));
  1283. +}
  1284. +#endif
  1285. +#endif
  1286. +
  1287. +#ifdef __NR_sram_alloc
  1288. +#define __NR__dl_sram_alloc __NR_sram_alloc
  1289. +static __always_inline _syscall2(__ptr_t, _dl_sram_alloc,
  1290. + size_t, len, unsigned long, flags);
  1291. +#endif
  1292. +
  1293. +#ifdef __NR_sram_free
  1294. +#define __NR__dl_sram_free __NR_sram_free
  1295. +static __always_inline _syscall1(int, _dl_sram_free, __ptr_t, addr);
  1296. +#endif
  1297. +
  1298. +#ifdef __NR_dma_memcpy
  1299. +#define __NR__dl_dma_memcpy __NR_dma_memcpy
  1300. +static __always_inline _syscall3(__ptr_t, _dl_dma_memcpy,
  1301. + __ptr_t, dest, __ptr_t, src, size_t, len);
  1302. +#endif
  1303. --- /dev/null
  1304. +++ b/ldso/ldso/ubicom32/dl-sysdep.h
  1305. @@ -0,0 +1,243 @@
  1306. + /* Copyright (C) 2003, 2004 Red Hat, Inc.
  1307. + Contributed by Alexandre Oliva <[email protected]>
  1308. + Based on ../i386/dl-sysdep.h
  1309. +
  1310. +This file is part of uClibc.
  1311. +
  1312. +uClibc is free software; you can redistribute it and/or modify it
  1313. +under the terms of the GNU Lesser General Public License as
  1314. +published by the Free Software Foundation; either version 2.1 of the
  1315. +License, or (at your option) any later version.
  1316. +
  1317. +uClibc is distributed in the hope that it will be useful, but WITHOUT
  1318. +ANY WARRANTY; without even the implied warranty of
  1319. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1320. +Library General Public License for more details.
  1321. +
  1322. +You should have received a copy of the GNU Lesser General Public
  1323. +License along with uClibc; see the file COPYING.LIB. If not, write to
  1324. +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  1325. +USA. */
  1326. +
  1327. +/*
  1328. + * Various assembly language/system dependent hacks that are required
  1329. + * so that we can minimize the amount of platform specific code.
  1330. + */
  1331. +
  1332. +/*
  1333. + * Define this if the system uses RELOCA.
  1334. + */
  1335. +#undef ELF_USES_RELOCA
  1336. +
  1337. +/* JMPREL relocs are inside the DT_RELA table. */
  1338. +#define ELF_MACHINE_PLTREL_OVERLAP
  1339. +
  1340. +#define DL_NO_COPY_RELOCS
  1341. +
  1342. +#define HAVE_DL_INLINES_H
  1343. +
  1344. +/*
  1345. + * Initialization sequence for a GOT. Copy the resolver function
  1346. + * descriptor and the pointer to the elf_resolve/link_map data
  1347. + * structure. Initialize the got_value in the module while at that.
  1348. + */
  1349. +#define INIT_GOT(GOT_BASE,MODULE) \
  1350. +{ \
  1351. + (MODULE)->loadaddr.got_value = (GOT_BASE); \
  1352. + GOT_BASE[0] = ((unsigned long *)&_dl_linux_resolve)[0]; \
  1353. + GOT_BASE[1] = ((unsigned long *)&_dl_linux_resolve)[1]; \
  1354. + GOT_BASE[2] = (unsigned long) MODULE; \
  1355. +}
  1356. +
  1357. +/* Here we define the magic numbers that this dynamic loader should accept */
  1358. +#define MAGIC1 EM_UBICOM32
  1359. +#undef MAGIC2
  1360. +
  1361. +/* Used for error messages */
  1362. +#define ELF_TARGET "UBICOM32"
  1363. +
  1364. +struct elf_resolve;
  1365. +
  1366. +struct funcdesc_value
  1367. +{
  1368. + void *entry_point;
  1369. + void *got_value;
  1370. +/*int relocation; not sure if this required, but it does exist */
  1371. +};
  1372. +
  1373. +extern int _dl_linux_resolve(void) __attribute__((__visibility__("hidden")));
  1374. +extern struct funcdesc_value volatile *__attribute__((__visibility__("hidden")))
  1375. + _dl_linux_resolver (struct elf_resolve *tpnt, int reloc_entry);
  1376. +
  1377. +/* 4KiB page alignment. Should perhaps be made dynamic using
  1378. + getpagesize(), based on AT_PAGESZ from auxvt? */
  1379. +#define PAGE_ALIGN 0xfffff000
  1380. +#define ADDR_ALIGN 0xfff
  1381. +#define OFFS_ALIGN 0x7ffff000
  1382. +
  1383. +struct funcdesc_ht;
  1384. +
  1385. +/*
  1386. + * This asm does a quick relcation of string S (which is stored in the text
  1387. + * section as thats all we can use
  1388. + */
  1389. +#undef SEND_EARLY_STDERR
  1390. +#define SEND_EARLY_STDERR(S) \
  1391. +do { \
  1392. + static const char __attribute__((section(".text"))) __s[] = (S); \
  1393. + const char *__p, *__scratch; \
  1394. + __asm__ ( \
  1395. + " call a3, 1f; \n\t" \
  1396. + "1: movei %0, #%%got_lo(1b) \n\t" \
  1397. + " move.4 %0, (%3, %0) \n\t" \
  1398. + " sub.4 %1, a3, %0; \n\t" \
  1399. + " add.4 %1, %1, %2; \n\t" \
  1400. + : "=&d" (__scratch), "=&d" (__p) \
  1401. + : "d" (__s), "a" (dl_boot_got_pointer) \
  1402. + : "a3", "a4", "d15"); \
  1403. + SEND_STDERR (__p); \
  1404. + { int __t; \
  1405. + for (__t = 0; __t < 0x100000; __t++) __asm__ __volatile__ (""); } \
  1406. +} while (0)
  1407. +
  1408. +#define DL_LOADADDR_TYPE struct elf32_fdpic_loadaddr
  1409. +
  1410. +#define DL_RELOC_ADDR(LOADADDR, ADDR) \
  1411. + ((ElfW(Addr))__reloc_pointer ((void*)(ADDR), (LOADADDR).map))
  1412. +
  1413. +#define DL_ADDR_TO_FUNC_PTR(ADDR, LOADADDR) \
  1414. + ((void(*)(void)) _dl_funcdesc_for ((void*)(ADDR), (LOADADDR).got_value))
  1415. +
  1416. +#define _dl_stabilize_funcdesc(val) \
  1417. + ({ __asm__ ("" : "+m" (*(val))); (val); })
  1418. +
  1419. +#define DL_CALL_FUNC_AT_ADDR(ADDR, LOADADDR, SIGNATURE, ...) \
  1420. + ({ struct funcdesc_value fd = { (void*)(ADDR), (LOADADDR).got_value }; \
  1421. + void (*pf)(void) = (void*) _dl_stabilize_funcdesc (&fd); \
  1422. + (* SIGNATURE pf)(__VA_ARGS__); })
  1423. +
  1424. +#define DL_INIT_LOADADDR_BOOT(LOADADDR, BASEADDR) \
  1425. + (__dl_init_loadaddr_map (&(LOADADDR), dl_boot_got_pointer, \
  1426. + dl_boot_ldsomap ?: dl_boot_progmap))
  1427. +
  1428. +#define DL_INIT_LOADADDR_PROG(LOADADDR, BASEADDR) \
  1429. + (__dl_init_loadaddr_map (&(LOADADDR), 0, dl_boot_progmap))
  1430. +
  1431. +#define DL_INIT_LOADADDR_EXTRA_DECLS \
  1432. + int dl_init_loadaddr_load_count;
  1433. +#define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
  1434. + (dl_init_loadaddr_load_count = \
  1435. + __dl_init_loadaddr (&(LOADADDR), (PHDR), (PHDRCNT)))
  1436. +#define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \
  1437. + (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \
  1438. + dl_init_loadaddr_load_count))
  1439. +#define DL_LOADADDR_UNMAP(LOADADDR, LEN) \
  1440. + (__dl_loadaddr_unmap ((LOADADDR), (NULL)))
  1441. +#define DL_LIB_UNMAP(LIB, LEN) \
  1442. + (__dl_loadaddr_unmap ((LIB)->loadaddr, (LIB)->funcdesc_ht))
  1443. +#define DL_LOADADDR_BASE(LOADADDR) \
  1444. + ((LOADADDR).got_value)
  1445. +
  1446. +/* This is called from dladdr(), such that we map a function
  1447. + descriptor's address to the function's entry point before trying to
  1448. + find in which library it's defined. */
  1449. +#define DL_LOOKUP_ADDRESS(ADDRESS) (_dl_lookup_address (ADDRESS))
  1450. +
  1451. +#define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
  1452. + (! (TFROM) && __dl_addr_in_loadaddr ((void*)(ADDR), (TPNT)->loadaddr))
  1453. +
  1454. +/*
  1455. + * Compute the GOT address. On several platforms, we use assembly
  1456. + * here. on FR-V FDPIC, there's no way to compute the GOT address,
  1457. + * since the offset between text and data is not fixed, so we arrange
  1458. + * for the assembly _dl_boot to pass this value as an argument to
  1459. + * _dl_boot. */
  1460. +#define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
  1461. +
  1462. +#define DL_BOOT_COMPUTE_DYN(dpnt, got, load_addr) \
  1463. + ((dpnt) = dl_boot_ldso_dyn_pointer)
  1464. +
  1465. +/* We only support loading FDPIC independently-relocatable shared
  1466. + libraries. It probably wouldn't be too hard to support loading
  1467. + shared libraries that require relocation by the same amount, but we
  1468. + don't know that they exist or would be useful, and the dynamic
  1469. + loader code could leak the whole-library map unless we keeping a
  1470. + bit more state for DL_LOADADDR_UNMAP and DL_LIB_UNMAP, so let's
  1471. + keep things simple for now. */
  1472. +#define DL_CHECK_LIB_TYPE(epnt, piclib, _dl_progname, libname) \
  1473. +do \
  1474. +{ \
  1475. + if (((epnt)->e_flags & EF_UBICOM32_FDPIC) && ! ((epnt)->e_flags & EF_UBICOM32_PIC)) \
  1476. + (piclib) = 2; \
  1477. + else \
  1478. + { \
  1479. + _dl_internal_error_number = LD_ERROR_NOTDYN; \
  1480. + _dl_dprintf(2, "%s: '%s' is not an FDPIC shared library" \
  1481. + "\n", (_dl_progname), (libname)); \
  1482. + _dl_close(infile); \
  1483. + return NULL; \
  1484. + } \
  1485. +\
  1486. +} \
  1487. +while (0)
  1488. +
  1489. +/* We want want to apply all relocations in the interpreter during
  1490. + bootstrap. Because of this, we have to skip the interpreter
  1491. + relocations in _dl_parse_relocation_information(), see
  1492. + elfinterp.c. */
  1493. +#define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0
  1494. +
  1495. +#ifdef __NR_pread64
  1496. +#define _DL_PREAD(FD, BUF, SIZE, OFFSET) \
  1497. + (_dl_pread((FD), (BUF), (SIZE), (OFFSET)))
  1498. +#endif
  1499. +
  1500. +/* We want to return to dlsym() a function descriptor if the symbol
  1501. + turns out to be a function. */
  1502. +#define DL_FIND_HASH_VALUE(TPNT, TYPE_CLASS, SYM) \
  1503. + (((TYPE_CLASS) & ELF_RTYPE_CLASS_DLSYM) \
  1504. + && ELF32_ST_TYPE((SYM)->st_info) == STT_FUNC \
  1505. + ? _dl_funcdesc_for ((void *)DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value), \
  1506. + (TPNT)->loadaddr.got_value) \
  1507. + : DL_RELOC_ADDR ((TPNT)->loadaddr, (SYM)->st_value))
  1508. +
  1509. +#if 0 /* XXX TODO will look at enabling this if we decide to add support for OCM
  1510. + * code/data */
  1511. +
  1512. +#define DL_IS_SPECIAL_SEGMENT(EPNT, PPNT) \
  1513. + __dl_is_special_segment(EPNT, PPNT)
  1514. +#define DL_MAP_SEGMENT(EPNT, PPNT, INFILE, FLAGS) \
  1515. + __dl_map_segment (EPNT, PPNT, INFILE, FLAGS)
  1516. +
  1517. +#endif
  1518. +
  1519. +
  1520. +#define DL_GET_READY_TO_RUN_EXTRA_PARMS \
  1521. + , struct elf32_fdpic_loadmap *dl_boot_progmap, Elf32_Addr dl_boot_got_pointer
  1522. +#define DL_GET_READY_TO_RUN_EXTRA_ARGS \
  1523. + , dl_boot_progmap, dl_boot_got_pointer
  1524. +
  1525. +
  1526. +#ifdef __USE_GNU
  1527. +# include <link.h>
  1528. +#else
  1529. +# define __USE_GNU
  1530. +# include <link.h>
  1531. +# undef __USE_GNU
  1532. +#endif
  1533. +
  1534. +#include <elf.h>
  1535. +static __inline__ void
  1536. +elf_machine_relative (DL_LOADADDR_TYPE load_off, const Elf32_Addr rel_addr,
  1537. + Elf32_Word relative_count)
  1538. +{
  1539. +#if 0
  1540. + Elf32_Rel * rpnt = (void *) rel_addr;
  1541. + --rpnt;
  1542. + do {
  1543. + Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  1544. +
  1545. + *reloc_addr = DL_RELOC_ADDR (load_off, *reloc_addr);
  1546. + } while (--relative_count);
  1547. +#endif
  1548. +}
  1549. --- /dev/null
  1550. +++ b/ldso/ldso/ubicom32/elfinterp.c
  1551. @@ -0,0 +1,366 @@
  1552. +/* Blackfin ELF shared library loader suppport
  1553. + Copyright (C) 2003, 2004 Red Hat, Inc.
  1554. + Contributed by Alexandre Oliva <[email protected]>
  1555. + Lots of code copied from ../i386/elfinterp.c, so:
  1556. + Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
  1557. + David Engel, Hongjiu Lu and Mitch D'Souza
  1558. + Copyright (C) 2001-2002, Erik Andersen
  1559. + All rights reserved.
  1560. +
  1561. +This file is part of uClibc.
  1562. +
  1563. +uClibc is free software; you can redistribute it and/or modify it
  1564. +under the terms of the GNU Lesser General Public License as
  1565. +published by the Free Software Foundation; either version 2.1 of the
  1566. +License, or (at your option) any later version.
  1567. +
  1568. +uClibc is distributed in the hope that it will be useful, but WITHOUT
  1569. +ANY WARRANTY; without even the implied warranty of
  1570. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1571. +Library General Public License for more details.
  1572. +
  1573. +You should have received a copy of the GNU Lesser General Public
  1574. +License along with uClibc; see the file COPYING.LIB. If not, write to
  1575. +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  1576. +USA. */
  1577. +
  1578. +#include <sys/cdefs.h> /* __attribute_used__ */
  1579. +
  1580. +/* Program to load an ELF binary on a linux system, and run it.
  1581. + References to symbols in sharable libraries can be resolved by either
  1582. + an ELF sharable library or a linux style of shared library. */
  1583. +
  1584. +/* Disclaimer: I have never seen any AT&T source code for SVr4, nor have
  1585. + I ever taken any courses on internals. This program was developed using
  1586. + information available through the book "UNIX SYSTEM V RELEASE 4,
  1587. + Programmers guide: Ansi C and Programming Support Tools", which did
  1588. + a more than adequate job of explaining everything required to get this
  1589. + working. */
  1590. +extern int _dl_ubicom32_resolve_pending(void) __attribute__((__visibility__("hidden")));
  1591. +
  1592. +struct funcdesc_value volatile *__attribute__((__visibility__("hidden")))
  1593. +_dl_linux_resolver (struct elf_resolve *tpnt, int reloc_entry)
  1594. +{
  1595. + int reloc_type;
  1596. + ELF_RELOC *this_reloc;
  1597. + char *strtab;
  1598. + ElfW(Sym) *symtab;
  1599. + int symtab_index;
  1600. + char *rel_addr;
  1601. + struct elf_resolve *new_tpnt;
  1602. + char *new_addr;
  1603. + struct funcdesc_value funcval;
  1604. + struct funcdesc_value volatile *got_entry;
  1605. + char *symname;
  1606. +
  1607. + rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL];
  1608. +
  1609. + this_reloc = (ELF_RELOC *)(intptr_t)(rel_addr + reloc_entry);
  1610. + reloc_type = ELF_R_TYPE(this_reloc->r_info);
  1611. + symtab_index = ELF_R_SYM(this_reloc->r_info);
  1612. +
  1613. + symtab = (Elf32_Sym *) tpnt->dynamic_info[DT_SYMTAB];
  1614. + strtab = (char *) tpnt->dynamic_info[DT_STRTAB];
  1615. + symname= strtab + symtab[symtab_index].st_name;
  1616. +
  1617. + if (reloc_type != R_UBICOM32_FUNCDESC_VALUE) {
  1618. + _dl_dprintf(2, "%s: Incorrect relocation type in jump relocations\n",
  1619. + _dl_progname);
  1620. + _dl_exit(1);
  1621. + }
  1622. +
  1623. + /* Address of GOT entry fix up */
  1624. + got_entry = (struct funcdesc_value *) DL_RELOC_ADDR(tpnt->loadaddr, this_reloc->r_offset);
  1625. +
  1626. + /* Get the address to be used to fill in the GOT entry. */
  1627. + new_addr = _dl_lookup_hash(symname, tpnt->symbol_scope, NULL, 0, &new_tpnt);
  1628. + if (!new_addr) {
  1629. + new_addr = _dl_lookup_hash(symname, NULL, NULL, 0, &new_tpnt);
  1630. + if (!new_addr) {
  1631. + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
  1632. + _dl_progname, symname);
  1633. + _dl_exit(1);
  1634. + }
  1635. + }
  1636. +
  1637. + funcval.entry_point = new_addr;
  1638. + funcval.got_value = new_tpnt->loadaddr.got_value;
  1639. +
  1640. +#if defined (__SUPPORT_LD_DEBUG__)
  1641. + if (_dl_debug_bindings) {
  1642. + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname);
  1643. + if (_dl_debug_detail)
  1644. + _dl_dprintf(_dl_debug_file,
  1645. + "\n\tpatched (%x,%x) ==> (%x,%x) @ %x\n",
  1646. + got_entry->entry_point, got_entry->got_value,
  1647. + funcval.entry_point, funcval.got_value,
  1648. + got_entry);
  1649. + }
  1650. + if (1 || !_dl_debug_nofixups) {
  1651. + got_entry->entry_point = ((unsigned long *)&_dl_ubicom32_resolve_pending)[0];
  1652. + got_entry->got_value = funcval.got_value;
  1653. + got_entry->entry_point = funcval.entry_point;
  1654. + }
  1655. +#else
  1656. + /*
  1657. + * initially set the entry point to resolve pending before starting
  1658. + * the update. This has the effect of putting all other requests in a
  1659. + * holding pattern until the resolution is completed.
  1660. + */
  1661. + got_entry->entry_point = ((unsigned long *)&_dl_ubicom32_resolve_pending)[0];
  1662. + got_entry->got_value = funcval.got_value;
  1663. + got_entry->entry_point = funcval.entry_point;
  1664. +#endif
  1665. +
  1666. + return got_entry;
  1667. +}
  1668. +
  1669. +static int
  1670. +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope,
  1671. + unsigned long rel_addr, unsigned long rel_size,
  1672. + int (*reloc_fnc) (struct elf_resolve *tpnt, struct dyn_elf *scope,
  1673. + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab))
  1674. +{
  1675. + unsigned int i;
  1676. + char *strtab;
  1677. + ElfW(Sym) *symtab;
  1678. + ELF_RELOC *rpnt;
  1679. + int symtab_index;
  1680. +
  1681. + /* Now parse the relocation information */
  1682. + rpnt = (ELF_RELOC *) rel_addr;
  1683. + rel_size = rel_size / sizeof(ELF_RELOC);
  1684. +
  1685. + symtab = (ElfW(Sym) *) tpnt->dynamic_info[DT_SYMTAB];
  1686. + strtab = (char *) tpnt->dynamic_info[DT_STRTAB];
  1687. +
  1688. + for (i = 0; i < rel_size; i++, rpnt++) {
  1689. + int res;
  1690. +
  1691. + symtab_index = ELF_R_SYM(rpnt->r_info);
  1692. + debug_sym(symtab,strtab,symtab_index);
  1693. + debug_reloc(symtab,strtab,rpnt);
  1694. +
  1695. + res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab);
  1696. +
  1697. + if (res==0) continue;
  1698. +
  1699. + _dl_dprintf(2, "\n%s: ",_dl_progname);
  1700. +
  1701. + if (symtab_index)
  1702. + _dl_dprintf(2, "symbol '%s': ", strtab + symtab[symtab_index].st_name);
  1703. +
  1704. + if (res <0) {
  1705. + int reloc_type = ELF_R_TYPE(rpnt->r_info);
  1706. +#if defined (__SUPPORT_LD_DEBUG__)
  1707. + _dl_dprintf(2, "can't handle reloc type %s\n ", _dl_reltypes(reloc_type));
  1708. +#else
  1709. + _dl_dprintf(2, "can't handle reloc type %x\n", reloc_type);
  1710. +#endif
  1711. + _dl_exit(-res);
  1712. + } else if (res >0) {
  1713. + _dl_dprintf(2, "can't resolve symbol\n");
  1714. + return res;
  1715. + }
  1716. + }
  1717. + return 0;
  1718. +}
  1719. +
  1720. +static int
  1721. +_dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope,
  1722. + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab)
  1723. +{
  1724. + int reloc_type;
  1725. + int symtab_index;
  1726. + char *symname;
  1727. + unsigned long reloc_value = 0, *reloc_addr;
  1728. + struct { unsigned long v; } __attribute__((__packed__))
  1729. + *reloc_addr_packed;
  1730. + unsigned long symbol_addr;
  1731. + struct elf_resolve *symbol_tpnt;
  1732. + struct funcdesc_value funcval;
  1733. +#if defined (__SUPPORT_LD_DEBUG__)
  1734. + unsigned long old_val;
  1735. +#endif
  1736. +
  1737. + reloc_addr = (unsigned long *) DL_RELOC_ADDR(tpnt->loadaddr, rpnt->r_offset);
  1738. + __asm__ ("" : "=r" (reloc_addr_packed) : "0" (reloc_addr));
  1739. + reloc_type = ELF_R_TYPE(rpnt->r_info);
  1740. + symtab_index = ELF_R_SYM(rpnt->r_info);
  1741. + symbol_addr = 0;
  1742. + symname = strtab + symtab[symtab_index].st_name;
  1743. +
  1744. + if (ELF_ST_BIND (symtab[symtab_index].st_info) == STB_LOCAL) {
  1745. + symbol_addr = (unsigned long) DL_RELOC_ADDR(tpnt->loadaddr, symtab[symtab_index].st_value);
  1746. + symbol_tpnt = tpnt;
  1747. + } else {
  1748. +
  1749. + symbol_addr = (unsigned long)
  1750. + _dl_lookup_hash(symname, scope, NULL, 0, &symbol_tpnt);
  1751. +
  1752. + /*
  1753. + * We want to allow undefined references to weak symbols - this might
  1754. + * have been intentional. We should not be linking local symbols
  1755. + * here, so all bases should be covered.
  1756. + */
  1757. +
  1758. + if (!symbol_addr && ELF_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) {
  1759. + _dl_dprintf (2, "%s: can't resolve symbol '%s'\n",
  1760. + _dl_progname, strtab + symtab[symtab_index].st_name);
  1761. + _dl_exit (1);
  1762. + }
  1763. + }
  1764. +
  1765. +#if defined (__SUPPORT_LD_DEBUG__)
  1766. + if (_dl_debug_reloc && _dl_debug_detail)
  1767. + {
  1768. + if ((long)reloc_addr_packed & 3)
  1769. + old_val = reloc_addr_packed->v;
  1770. + else
  1771. + old_val = *reloc_addr;
  1772. + }
  1773. + else
  1774. + old_val = 0;
  1775. +#endif
  1776. + switch (reloc_type) {
  1777. + case R_UBICOM32_NONE:
  1778. + break;
  1779. + case R_UBICOM32_32:
  1780. + if ((long)reloc_addr_packed & 3)
  1781. + reloc_value = reloc_addr_packed->v += symbol_addr;
  1782. + else
  1783. + reloc_value = *reloc_addr += symbol_addr;
  1784. + break;
  1785. + case R_UBICOM32_FUNCDESC_VALUE:
  1786. + funcval.entry_point = (void*)symbol_addr;
  1787. + /* The addend of FUNCDESC_VALUE
  1788. + relocations referencing global
  1789. + symbols must be ignored, because it
  1790. + may hold the address of a lazy PLT
  1791. + entry. */
  1792. + if (ELF_ST_BIND(symtab[symtab_index].st_info) == STB_LOCAL)
  1793. + funcval.entry_point += *reloc_addr;
  1794. + reloc_value = (unsigned long)funcval.entry_point;
  1795. + if (symbol_addr)
  1796. + funcval.got_value
  1797. + = symbol_tpnt->loadaddr.got_value;
  1798. + else
  1799. + funcval.got_value = 0;
  1800. +
  1801. +/// XXX this is my best guess as to what I should be doing, but I'm
  1802. +/// putting a break-point here so I can inspect the first time this is
  1803. +/// used.
  1804. + __asm__ (
  1805. + " move.4 4(%0), 4(%1) \n\t"
  1806. + " move.4 0(%0), 0(%1) \n\t" /* Must to entry_point last */
  1807. + :
  1808. + : "a" (reloc_addr), "a" (&funcval)
  1809. + : "memory" );
  1810. + break;
  1811. + case R_UBICOM32_FUNCDESC:
  1812. + if ((long)reloc_addr_packed & 3)
  1813. + reloc_value = reloc_addr_packed->v;
  1814. + else
  1815. + reloc_value = *reloc_addr;
  1816. + if (symbol_addr)
  1817. + reloc_value = (unsigned long)_dl_funcdesc_for
  1818. + ((char *)symbol_addr + reloc_value,
  1819. + symbol_tpnt->loadaddr.got_value);
  1820. + else
  1821. + reloc_value = 0;
  1822. + if ((long)reloc_addr_packed & 3)
  1823. + reloc_addr_packed->v = reloc_value;
  1824. + else
  1825. + *reloc_addr = reloc_value;
  1826. + break;
  1827. + default:
  1828. + return -1;
  1829. + }
  1830. +#if defined (__SUPPORT_LD_DEBUG__)
  1831. + if (_dl_debug_reloc && _dl_debug_detail) {
  1832. + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x", old_val, reloc_value, reloc_addr);
  1833. + switch (reloc_type) {
  1834. + case R_UBICOM32_FUNCDESC_VALUE:
  1835. + _dl_dprintf(_dl_debug_file, " got %x", ((struct funcdesc_value *)reloc_value)->got_value);
  1836. + break;
  1837. + case R_UBICOM32_FUNCDESC:
  1838. + if (! reloc_value)
  1839. + break;
  1840. + _dl_dprintf(_dl_debug_file, " funcdesc (%x,%x)",
  1841. + ((struct funcdesc_value *)reloc_value)->entry_point,
  1842. + ((struct funcdesc_value *)reloc_value)->got_value);
  1843. + break;
  1844. + }
  1845. + }
  1846. +#endif
  1847. +
  1848. + return 0;
  1849. +}
  1850. +
  1851. +static int
  1852. +_dl_do_lazy_reloc (struct elf_resolve *tpnt,
  1853. + struct dyn_elf *scope __attribute__((unused)),
  1854. + ELF_RELOC *rpnt, ElfW(Sym) *symtab __attribute__((unused)),
  1855. + char *strtab __attribute__((unused)))
  1856. +{
  1857. + int reloc_type;
  1858. + struct funcdesc_value volatile *reloc_addr;
  1859. + struct funcdesc_value funcval;
  1860. +#if defined (__SUPPORT_LD_DEBUG__)
  1861. + unsigned long old_val;
  1862. +#endif
  1863. +
  1864. + reloc_addr = (struct funcdesc_value *) DL_RELOC_ADDR(tpnt->loadaddr, rpnt->r_offset);
  1865. + reloc_type = ELF_R_TYPE(rpnt->r_info);
  1866. +
  1867. +#if defined (__SUPPORT_LD_DEBUG__)
  1868. + old_val = (unsigned long)reloc_addr->entry_point;
  1869. +#endif
  1870. + switch (reloc_type) {
  1871. + case R_UBICOM32_NONE:
  1872. + break;
  1873. + case R_UBICOM32_FUNCDESC_VALUE:
  1874. + funcval = *reloc_addr;
  1875. + funcval.entry_point = (void*)DL_RELOC_ADDR(tpnt->loadaddr, funcval.entry_point);
  1876. + funcval.got_value = tpnt->loadaddr.got_value;
  1877. + *reloc_addr = funcval;
  1878. + break;
  1879. + default:
  1880. + return -1;
  1881. + }
  1882. +#if defined (__SUPPORT_LD_DEBUG__)
  1883. + if (_dl_debug_reloc && _dl_debug_detail)
  1884. + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x", old_val, reloc_addr->entry_point, reloc_addr);
  1885. +#endif
  1886. + return 0;
  1887. +
  1888. +}
  1889. +
  1890. +void
  1891. +_dl_parse_lazy_relocation_information
  1892. +(struct dyn_elf *rpnt, unsigned long rel_addr, unsigned long rel_size)
  1893. +{
  1894. + _dl_parse(rpnt->dyn, NULL, rel_addr, rel_size, _dl_do_lazy_reloc);
  1895. +}
  1896. +
  1897. +int
  1898. +_dl_parse_relocation_information
  1899. +(struct dyn_elf *rpnt, unsigned long rel_addr, unsigned long rel_size)
  1900. +{
  1901. + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size, _dl_do_reloc);
  1902. +}
  1903. +
  1904. +#if 0
  1905. +/* We don't have copy relocs. */
  1906. +int
  1907. +_dl_parse_copy_information
  1908. +(struct dyn_elf *rpnt __attribute__((unused)),
  1909. + unsigned long rel_addr __attribute__((unused)),
  1910. + unsigned long rel_size __attribute__((unused)))
  1911. +{
  1912. + return 0;
  1913. +}
  1914. +#endif
  1915. +#ifndef IS_IN_libdl
  1916. +# include "../../libc/sysdeps/linux/ubicom32/crtreloc.c"
  1917. +#endif
  1918. --- /dev/null
  1919. +++ b/ldso/ldso/ubicom32/resolve.S
  1920. @@ -0,0 +1,161 @@
  1921. + /* Copyright (C) 2003 Red Hat, Inc.
  1922. + Contributed by Alexandre Oliva <[email protected]>
  1923. +
  1924. + Copyright (C) 2009 Ubicom Inc.
  1925. + Ported to Ubicom32 by Ubicom Inc.
  1926. +
  1927. +This file is part of uClibc.
  1928. +
  1929. +uClibc is free software; you can redistribute it and/or modify it
  1930. +under the terms of the GNU Lesser General Public License as
  1931. +published by the Free Software Foundation; either version 2.1 of the
  1932. +License, or (at your option) any later version.
  1933. +
  1934. +uClibc is distributed in the hope that it will be useful, but WITHOUT
  1935. +ANY WARRANTY; without even the implied warranty of
  1936. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1937. +Library General Public License for more details.
  1938. +
  1939. +You should have received a copy of the GNU Lesser General Public
  1940. +License along with uClibc; see the file COPYING.LIB. If not, write to
  1941. +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  1942. +USA. */
  1943. +
  1944. +
  1945. +/*
  1946. + * The function below is tail-called by resolver stubs when a lazily-bound *
  1947. + * function is called. It must preserve all registers that could * be used to
  1948. + * pass arguments to the actual function.
  1949. + *
  1950. + * On entry to the function d0-d13 contain parameters to the actual function of
  1951. + * interest
  1952. + *
  1953. + * a5 contains the return address
  1954. + * a0 is pointing to the GOT table for the original function
  1955. + * (a0) _dl_linux_resolve
  1956. + * 4(a0) GOT for _dl_linux_resolve
  1957. + * 8(a0) is pointer to "structure elf_resolve" of the module where the call
  1958. + * originated from
  1959. + *
  1960. + * a3 is pointing to the function descriptor in the GOT table, and 8(a3) the
  1961. + * resolver lookup information.
  1962. + *
  1963. + * _dl_linux_resolve calls _dl_linux_resolver passing it pointer to
  1964. + * struct elf_resolve and the relocation entry.
  1965. + *
  1966. + * _dl_linux_resolver() figures out where the jump symbol is _really_ supposed
  1967. + * to have jumped to and returns that to us. Once we have that, we prepare to
  1968. + * tail-call the actual function, clean up after ourselves, restoring the
  1969. + * original arguments, then jump to the fixed up address.
  1970. + */
  1971. +
  1972. +#if 0
  1973. + /*
  1974. + * Here is what the linker will use for the PLT.
  1975. + */
  1976. +sample_PLT_functionX: /* (at entry a0 contains GOT for this library) */
  1977. + movei d15, # -%lo(got_funcdescX) ; load offset for GOT
  1978. + lea.4 a3, (a0, d15) ; a4 is now the function descriptor
  1979. + move.4 a4, 0(a3) ; get entry_point
  1980. + move.4 a0, 4(a3) ; set new GOT
  1981. +
  1982. + /*
  1983. + * jump to resovled function OR PLT_trampoline Nat had some code here
  1984. + * that uses the stack instead of a3 to reduces hazards.
  1985. + */
  1986. + calli a4, 0(a4)
  1987. +
  1988. +
  1989. +sample_PLT_trampoline:
  1990. + /*
  1991. + * find the old got by undoing what was done above. An alternative
  1992. + * could have been to ‘save’ the old got in say d14 but that would add 1
  1993. + * instruction to every PLT and there is only 1 PLT trampoline per library.
  1994. + */
  1995. + ret (a0) ; jump to _dl_linux_resolve
  1996. +#endif
  1997. +
  1998. + .text
  1999. + .p2align 4
  2000. +
  2001. + .hidden _dl_linux_resolve
  2002. + .global _dl_linux_resolve
  2003. + .type _dl_linux_resolve,@function
  2004. +_dl_linux_resolve:
  2005. + /* Preserve arguments and return address */
  2006. + move.4 -4(sp)++, d0
  2007. + move.4 -4(sp)++, d1
  2008. + move.4 -4(sp)++, d2
  2009. + move.4 -4(sp)++, d3
  2010. + move.4 -4(sp)++, d4
  2011. + move.4 -4(sp)++, d5
  2012. + move.4 -4(sp)++, d6
  2013. + move.4 -4(sp)++, d7
  2014. + move.4 -4(sp)++, d8
  2015. + move.4 -4(sp)++, d9
  2016. + move.4 -4(sp)++, d10
  2017. + move.4 -4(sp)++, d11
  2018. + move.4 -4(sp)++, d12
  2019. + move.4 -4(sp)++, d13
  2020. + move.4 -4(sp)++, a5
  2021. +
  2022. + /* Prepare to call _dl_linux_resolver. */
  2023. + move.4 d0, 8(a0) ; reference to elf_resolve
  2024. + /* Not aligned for space reasons. */
  2025. + move.4 d1, mac_hi ; reference to GOT table entry which
  2026. + ; contains the relocation information.
  2027. +
  2028. + move.4 a0, 4(a0) ; switch to GOT for _dl_linux_resolve
  2029. + call a5, _dl_linux_resolver;
  2030. +
  2031. + /* Move aside return value that contains the FUNCDESC_VALUE. */
  2032. + ;P3 = R0;
  2033. + move.4 a3, d0;
  2034. +
  2035. + /* Restore arguments. */
  2036. + move.4 a5, (sp)4++
  2037. + move.4 d13, (sp)4++
  2038. + move.4 d12, (sp)4++
  2039. + move.4 d11, (sp)4++
  2040. + move.4 d10, (sp)4++
  2041. + move.4 d9, (sp)4++
  2042. + move.4 d8, (sp)4++
  2043. + move.4 d7, (sp)4++
  2044. + move.4 d6, (sp)4++
  2045. + move.4 d5, (sp)4++
  2046. + move.4 d4, (sp)4++
  2047. + move.4 d3, (sp)4++
  2048. + move.4 d2, (sp)4++
  2049. + move.4 d1, (sp)4++
  2050. + move.4 d0, (sp)4++
  2051. +
  2052. + /* Now jump to the actual function. */
  2053. + /* a3 contains func_desc resolution */
  2054. + move.4 a4, 0(a3) ; address of function X
  2055. + move.4 a0, 4(a3) ; switch to GOT for function X
  2056. + calli a4, 0(a4) ; call through a4, a5 remains
  2057. +
  2058. + .size _dl_linux_resolve, . - _dl_linux_resolve
  2059. +
  2060. + .hidden _dl_ubicom32_resolve_pending
  2061. + .global _dl_ubicom32_resolve_pending
  2062. + .type _dl_ubicom32_resolve_pending,@function
  2063. +
  2064. +_dl_ubicom32_resolve_pending:
  2065. + /*
  2066. + * A special function that is used to ensure thread saftly when the fd
  2067. + * for a particular resolution is being updated.
  2068. + *
  2069. + * At entry, a3 must point to the FD. While the FD is being updated the
  2070. + * entry_point will continue to point to _dl_ubicom32_resolve_pending so
  2071. + * we will effectively spin until the resolver update is complete.
  2072. + */
  2073. +
  2074. + move.4 a4, 0(a3) ; get entry_point
  2075. + move.4 a0, 4(a3) ; set new GOT
  2076. +
  2077. + /*
  2078. + * jump to resovled function or back to _dl_ubicom32_resolve_pending.
  2079. + */
  2080. + calli a4, 0(a4)
  2081. + .size _dl_ubicom32_resolve_pending, . - _dl_ubicom32_resolve_pending
  2082. --- a/libc/misc/Makefile.in
  2083. +++ b/libc/misc/Makefile.in
  2084. @@ -12,7 +12,9 @@ include $(top_srcdir)libc/misc/assert/Ma
  2085. include $(top_srcdir)libc/misc/ctype/Makefile.in
  2086. include $(top_srcdir)libc/misc/dirent/Makefile.in
  2087. include $(top_srcdir)libc/misc/error/Makefile.in
  2088. +ifneq ($(ARCH_HAS_NO_LDSO),y)
  2089. include $(top_srcdir)libc/misc/elf/Makefile.in
  2090. +endif
  2091. include $(top_srcdir)libc/misc/file/Makefile.in
  2092. include $(top_srcdir)libc/misc/fnmatch/Makefile.in
  2093. include $(top_srcdir)libc/misc/ftw/Makefile.in
  2094. --- a/libc/misc/elf/dl-iterate-phdr.c
  2095. +++ b/libc/misc/elf/dl-iterate-phdr.c
  2096. @@ -14,7 +14,7 @@
  2097. #include <link.h>
  2098. #include <ldso.h>
  2099. -
  2100. +#include <memory.h>
  2101. /* we want this in libc but nowhere else */
  2102. #ifdef __USE_GNU
  2103. @@ -60,7 +60,11 @@ dl_iterate_phdr (int (*callback) (struct
  2104. /* This entry describes this statically-linked program itself. */
  2105. struct dl_phdr_info info;
  2106. int ret;
  2107. +#if !defined(__FDPIC__)
  2108. info.dlpi_addr = 0;
  2109. +#else
  2110. + memset(&info.dlpi_addr, 0, sizeof(info.dlpi_addr));
  2111. +#endif
  2112. info.dlpi_name = "";
  2113. info.dlpi_phdr = _dl_phdr;
  2114. info.dlpi_phnum = _dl_phnum;
  2115. --- a/libc/stdlib/malloc/malloc.c
  2116. +++ b/libc/stdlib/malloc/malloc.c
  2117. @@ -25,7 +25,7 @@ libc_hidden_proto(sbrk)
  2118. /* The malloc heap. We provide a bit of initial static space so that
  2119. programs can do a little mallocing without mmaping in more space. */
  2120. -HEAP_DECLARE_STATIC_FREE_AREA (initial_fa, 256);
  2121. +HEAP_DECLARE_STATIC_FREE_AREA (initial_fa, 32768);
  2122. struct heap_free_area *__malloc_heap = HEAP_INIT_WITH_FA (initial_fa);
  2123. #ifdef HEAP_USE_LOCKING
  2124. malloc_mutex_t __malloc_heap_lock = PTHREAD_MUTEX_INITIALIZER;
  2125. --- /dev/null
  2126. +++ b/libc/string/ubicom32/Makefile
  2127. @@ -0,0 +1,13 @@
  2128. +# Makefile for uClibc
  2129. +#
  2130. +# Copyright (C) 2000-2005 Erik Andersen <[email protected]>
  2131. +#
  2132. +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  2133. +#
  2134. +
  2135. +top_srcdir:=../../../
  2136. +top_builddir:=../../../
  2137. +all: objs
  2138. +include $(top_builddir)Rules.mak
  2139. +include ../Makefile.in
  2140. +include $(top_srcdir)Makerules
  2141. --- /dev/null
  2142. +++ b/libc/string/ubicom32/memcpy.c
  2143. @@ -0,0 +1,152 @@
  2144. +/* Copy memory to memory until the specified number of bytes
  2145. + has been copied. Overlap is NOT handled correctly.
  2146. + Copyright (C) 1991, 1997, 2003 Free Software Foundation, Inc.
  2147. + This file is part of the GNU C Library.
  2148. + Contributed by Torbjorn Granlund ([email protected]).
  2149. +
  2150. + The GNU C Library is free software; you can redistribute it and/or
  2151. + modify it under the terms of the GNU Lesser General Public
  2152. + License as published by the Free Software Foundation; either
  2153. + version 2.1 of the License, or (at your option) any later version.
  2154. +
  2155. + The GNU C Library is distributed in the hope that it will be useful,
  2156. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2157. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2158. + Lesser General Public License for more details.
  2159. +
  2160. + You should have received a copy of the GNU Lesser General Public
  2161. + License along with the GNU C Library; if not, write to the Free
  2162. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2163. + 02111-1307 USA. */
  2164. +
  2165. +#include <string.h>
  2166. +
  2167. +typedef unsigned long addr_t;
  2168. +
  2169. +libc_hidden_proto(memcpy)
  2170. +
  2171. +void *memcpy (void *dest, const void *src, size_t n)
  2172. +{
  2173. + void *dest_ret = dest;
  2174. + void *aligned_start;
  2175. +
  2176. + if (likely((((addr_t)dest ^ (addr_t)src) & 3) == 0) && likely(n > 6)) {
  2177. + size_t m;
  2178. + n -= (4 - (addr_t)dest) & 0x03;
  2179. + m = n >> 2;
  2180. + __asm__ volatile (
  2181. + " call %4, 99f \n\t" // load %4 with address of 99
  2182. + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
  2183. + " add.4 %4, %4, d15 \n\t" // add difference
  2184. +
  2185. + " sub.4 d15, #0, %2 \n\t" // set up for jump table
  2186. + " and.4 d15, #(32-1), d15 \n\t" // d15 = (-m) & (32 - 1)
  2187. + " lea.4 %4, (%4,d15) \n\t"
  2188. +
  2189. + " bfextu d15, %0, #2 \n\t" // d15 = (dest & 3)
  2190. + " jmpne.w.f 100f \n\t"
  2191. + " calli %4, 0(%4) \n\t" // 4-byte alignment
  2192. +
  2193. + "100: cmpi d15, #2 \n\t"
  2194. + " jmpne.s.f 101f \n\t"
  2195. + " move.2 (%0)2++, (%1)2++ \n\t"
  2196. + " calli %4, 0(%4) \n\t" // 2-byte alignment
  2197. +
  2198. + "101: move.1 (%0)1++, (%1)1++ \n\t"
  2199. + " jmpgt.s.f 102f \n\t" // 3-byte alignment
  2200. + " move.2 (%0)2++, (%1)2++ \n\t" // 1-byte alignment
  2201. + "102: calli %4, 0(%4) \n\t"
  2202. +
  2203. + "200: cmpi %3, #2 \n\t"
  2204. + " jmplt.s.f 201f \n\t"
  2205. + " move.2 (%0)2++, (%1)2++ \n\t"
  2206. + " jmpeq.s.t 2f \n\t"
  2207. + "201: move.1 (%0)1++, (%1)1++ \n\t"
  2208. + " jmpt.w.t 2f \n\t"
  2209. +
  2210. + "1: .rept 25 \n\t"
  2211. + " movea (%0)4++, (%1)4++ \n\t"
  2212. + " .endr \n\t"
  2213. + " .rept 7 \n\t"
  2214. + " move.4 (%0)4++, (%1)4++ \n\t"
  2215. + " .endr \n\t"
  2216. + " add.4 %2, #-32, %2 \n\t"
  2217. + " jmpgt.w.f 1b \n\t"
  2218. +
  2219. + " and.4 %3, #3, %3 \n\t" // check n
  2220. + " jmpne.w.f 200b \n\t"
  2221. + "2: \n\t"
  2222. + : "+a"(dest), "+a"(src), "+d"(m), "+d"(n), "=a"(aligned_start)
  2223. + :
  2224. + : "d15", "memory", "cc"
  2225. + );
  2226. +
  2227. + return dest_ret;
  2228. + }
  2229. +
  2230. + if (likely((((addr_t)dest ^ (addr_t)src) & 1) == 0) && likely(n > 2)) {
  2231. + size_t m;
  2232. + n -= (addr_t)dest & 0x01;
  2233. + m = n >> 1;
  2234. + __asm__ volatile (
  2235. + " call %4, 99f \n\t" // load %4 with address of 99
  2236. + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
  2237. + " add.4 %4, %4, d15 \n\t" // add difference
  2238. +
  2239. + " sub.4 d15, #0, %2 \n\t" // set up for jump table
  2240. + " and.4 d15, #(32-1), d15 \n\t" // d15 = (-m) & (32 - 1)
  2241. + " lea.4 %4, (%4,d15) \n\t"
  2242. +
  2243. + " btst %0, #0 \n\t" // check bit 0
  2244. + " jmpne.w.f 100f \n\t"
  2245. + " calli %4, 0(%4) \n\t" // 4-byte alignment
  2246. +
  2247. + "100: move.1 (%0)1++, (%1)1++ \n\t"
  2248. + " calli %4, 0(%4) \n\t"
  2249. +
  2250. + "200: move.1 (%0)1++, (%1)1++ \n\t"
  2251. + " jmpt.w.t 2f \n\t"
  2252. +
  2253. + "1: .rept 32 \n\t"
  2254. + " move.2 (%0)2++, (%1)2++ \n\t"
  2255. + " .endr \n\t"
  2256. + " add.4 %2, #-32, %2 \n\t"
  2257. + " jmpgt.w.f 1b \n\t"
  2258. +
  2259. + " and.4 %3, #1, %3 \n\t" // check n
  2260. + " jmpne.w.f 200b \n\t"
  2261. + "2: \n\t"
  2262. +
  2263. + : "+a"(dest), "+a"(src), "+d"(m), "+d"(n), "=a"(aligned_start)
  2264. + :
  2265. + : "d15", "memory", "cc"
  2266. + );
  2267. + return dest_ret;
  2268. + }
  2269. +
  2270. + __asm__ volatile (
  2271. + " call %3, 99f \n\t" // load %3 with address of 99
  2272. + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
  2273. + " add.4 %3, %3, d15 \n\t" // add difference
  2274. +
  2275. + " sub.4 d15, #0, %2 \n\t"
  2276. + " jmpeq.w.f 2f \n\t"
  2277. + " and.4 d15, #(16-1), d15 \n\t" // d15 = (-n) & (16 - 1)
  2278. + " lea.4 %3, (%3,d15) \n\t"
  2279. + " calli %3, 0(%3) \n\t"
  2280. +
  2281. + "1: .rept 16 \n\t"
  2282. + " move.1 (%0)1++, (%1)1++ \n\t"
  2283. + " .endr \n\t"
  2284. + " add.4 %2, #-16, %2 \n\t"
  2285. + " jmpgt.w.f 1b \n\t"
  2286. + "2: \n\t"
  2287. +
  2288. + : "+a"(dest), "+a"(src), "+d"(n), "=a"(aligned_start)
  2289. + :
  2290. + : "d15", "memory", "cc"
  2291. + );
  2292. +
  2293. + return dest_ret;
  2294. +}
  2295. +libc_hidden_def(memcpy)
  2296. --- /dev/null
  2297. +++ b/libc/string/ubicom32/memset.c
  2298. @@ -0,0 +1,107 @@
  2299. +/* Copyright (C) 1991, 1997, 2003 Free Software Foundation, Inc.
  2300. + This file is part of the GNU C Library.
  2301. +
  2302. + The GNU C Library is free software; you can redistribute it and/or
  2303. + modify it under the terms of the GNU Lesser General Public
  2304. + License as published by the Free Software Foundation; either
  2305. + version 2.1 of the License, or (at your option) any later version.
  2306. +
  2307. + The GNU C Library is distributed in the hope that it will be useful,
  2308. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2309. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2310. + Lesser General Public License for more details.
  2311. +
  2312. + You should have received a copy of the GNU Lesser General Public
  2313. + License along with the GNU C Library; if not, write to the Free
  2314. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2315. + 02111-1307 USA. */
  2316. +
  2317. +#include <string.h>
  2318. +
  2319. +typedef unsigned long addr_t;
  2320. +
  2321. +libc_hidden_proto(memset)
  2322. +void *memset (void *s, int c, size_t n)
  2323. +{
  2324. + void *s_ret = s;
  2325. + void *aligned_start;
  2326. + if (likely(n > 6)) {
  2327. + size_t m;
  2328. + n -= (4 - (addr_t)s) & 0x03;
  2329. + m = n >> 2;
  2330. + __asm__ volatile (
  2331. + " call %4, 99f \n\t" // load %4 with address of 99
  2332. + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
  2333. + " add.4 %4, %4, d15 \n\t" // add difference
  2334. +
  2335. + " sub.4 d15, #0, %2 \n\t" // set up for jump table
  2336. + " and.4 d15, #(32-1), d15 \n\t" // d15 = (-m) & (32 - 1)
  2337. + " shmrg.1 %1, %1, %1 \n\t"
  2338. + " shmrg.2 %1, %1, %1 \n\t" // %1 = (c<<24)|(c<<16)|(c<<8)|c
  2339. + " lea.4 %4, (%4,d15) \n\t"
  2340. +
  2341. + " bfextu d15, %0, #2 \n\t" // d15 = (s & 3)
  2342. + " jmpne.w.f 100f \n\t"
  2343. + " calli %4, 0(%4) \n\t" // 4-byte alignment
  2344. +
  2345. + "100: cmpi d15, #2 \n\t"
  2346. + " jmpne.s.f 101f \n\t"
  2347. + " move.2 (%0)2++, %1 \n\t"
  2348. + " calli %4, 0(%4) \n\t" // 2-byte alignment
  2349. +
  2350. + "101: move.1 (%0)1++, %1 \n\t"
  2351. + " jmpgt.s.f 102f \n\t" // 3-byte alignment
  2352. + " move.2 (%0)2++, %1 \n\t" // 1-byte alignment
  2353. + "102: calli %4, 0(%4) \n\t"
  2354. +
  2355. + "200: cmpi %3, #2 \n\t"
  2356. + " jmplt.s.f 201f \n\t"
  2357. + " move.2 (%0)2++, %1 \n\t"
  2358. + " jmpeq.s.t 2f \n\t"
  2359. + "201: move.1 (%0)1++, %1 \n\t"
  2360. + " jmpt.w.t 2f \n\t"
  2361. +
  2362. + "1: .rept 25 \n\t"
  2363. + " movea (%0)4++, %1 \n\t"
  2364. + " .endr \n\t"
  2365. + " .rept 7 \n\t"
  2366. + " move.4 (%0)4++, %1 \n\t"
  2367. + " .endr \n\t"
  2368. + " add.4 %2, #-32, %2 \n\t"
  2369. + " jmpgt.w.f 1b \n\t"
  2370. +
  2371. + " and.4 %3, #3, %3 \n\t" // test bit 1 of n
  2372. + " jmpne.w.f 200b \n\t"
  2373. + "2: \n\t"
  2374. + : "+a"(s), "+d"(c), "+d"(m), "+d"(n), "=a"(aligned_start)
  2375. + :
  2376. + : "d15", "memory", "cc"
  2377. + );
  2378. +
  2379. + return s_ret;
  2380. + }
  2381. +
  2382. + __asm__ volatile (
  2383. + " call %3, 99f \n\t" // load %3 with address of 99
  2384. + "99: movei d15, #%%lo(1f-99b) \n\t" // load d15 with offset to 1 from 99
  2385. + " add.4 %3, %3, d15 \n\t" // add difference
  2386. +
  2387. + " sub.4 d15, #0, %2 \n\t"
  2388. + " jmpeq.w.f 2f \n\t"
  2389. + " and.4 d15, #(8-1), d15 \n\t" // d15 = (-%2) & (16 - 1)
  2390. + " lea.4 %3, (%3,d15) \n\t"
  2391. + " calli %3, 0(%3) \n\t"
  2392. +
  2393. + "1: .rept 8 \n\t"
  2394. + " move.1 (%0)1++, %1 \n\t"
  2395. + " .endr \n\t"
  2396. + "2: \n\t"
  2397. +
  2398. + : "+a"(s), "+d"(c), "+d"(n), "=a"(aligned_start)
  2399. + :
  2400. + : "d15", "memory", "cc"
  2401. + );
  2402. +
  2403. + return s_ret;
  2404. +}
  2405. +libc_hidden_def(memset)
  2406. --- a/libc/sysdeps/linux/common/sys/user.h
  2407. +++ b/libc/sysdeps/linux/common/sys/user.h
  2408. @@ -1 +1,4 @@
  2409. +#if 0
  2410. +/* As of linux v2.6.25 this is not part of the exported linux headers */
  2411. #include <linux/user.h>
  2412. +#endif
  2413. --- /dev/null
  2414. +++ b/libc/sysdeps/linux/ubicom32/Makefile
  2415. @@ -0,0 +1,13 @@
  2416. +# Makefile for uClibc
  2417. +#
  2418. +# Copyright (C) 2000-2006 Erik Andersen <[email protected]>
  2419. +#
  2420. +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  2421. +#
  2422. +
  2423. +top_srcdir=../../../../
  2424. +top_builddir=../../../../
  2425. +all: objs
  2426. +include $(top_builddir)Rules.mak
  2427. +include Makefile.arch
  2428. +include $(top_srcdir)Makerules
  2429. --- /dev/null
  2430. +++ b/libc/sysdeps/linux/ubicom32/Makefile.arch
  2431. @@ -0,0 +1,28 @@
  2432. +# Makefile for uClibc
  2433. +#
  2434. +# Copyright (C) 2000-2006 Erik Andersen <[email protected]>
  2435. +#
  2436. +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  2437. +#
  2438. +
  2439. +#CSRC := \
  2440. +# brk.c \
  2441. +# crtbegin.c \
  2442. +# crtend.c
  2443. +#
  2444. +#SSRC := \
  2445. +# __longjmp.S \
  2446. +# bsd-_setjmp.S \
  2447. +# bsd-setjmp.S \
  2448. +# setjmp.S \
  2449. +# clone.S \
  2450. +# vfork.S
  2451. +
  2452. +CSRC := \
  2453. + syscall.c __syscall_error.c
  2454. +
  2455. +SSRC := \
  2456. + clone.S setjmp.S vfork.S
  2457. +
  2458. +ARCH_CFLAGS := $(CPU_CFLAGS-y)
  2459. +include $(top_srcdir)libc/sysdeps/linux/Makefile.commonarch
  2460. --- /dev/null
  2461. +++ b/libc/sysdeps/linux/ubicom32/__syscall_error.c
  2462. @@ -0,0 +1,11 @@
  2463. +#include <errno.h>
  2464. +#include <features.h>
  2465. +
  2466. +/* This routine is jumped to by some of the syscall handlers, to stash
  2467. + * an error number into errno. */
  2468. +int __syscall_error(int err_no) attribute_hidden;
  2469. +int __syscall_error(int err_no)
  2470. +{
  2471. + __set_errno(err_no);
  2472. + return -1;
  2473. +}
  2474. --- /dev/null
  2475. +++ b/libc/sysdeps/linux/ubicom32/bits/elf-fdpic.h
  2476. @@ -0,0 +1,115 @@
  2477. +/* Copyright 2003, 2004 Free Software Foundation, Inc.
  2478. +This file is part of the GNU C Library.
  2479. +
  2480. +The GNU C Library is free software; you can redistribute it and/or
  2481. +modify it under the terms of the GNU Lesser General Public License as
  2482. +published by the Free Software Foundation; either version 2.1 of the
  2483. +License, or (at your option) any later version.
  2484. +
  2485. +In addition to the permissions in the GNU Lesser General Public
  2486. +License, the Free Software Foundation gives you unlimited
  2487. +permission to link the compiled version of this file with other
  2488. +programs, and to distribute those programs without any restriction
  2489. +coming from the use of this file. (The GNU Lesser General Public
  2490. +License restrictions do apply in other respects; for example, they
  2491. +cover modification of the file, and distribution when not linked
  2492. +into another program.)
  2493. +
  2494. +The GNU C Library is distributed in the hope that it will be useful,
  2495. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  2496. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2497. +Library General Public License for more details.
  2498. +
  2499. +You should have received a copy of the GNU Lesser General Public
  2500. +License along with the GNU C Library; see the file COPYING.LIB. If
  2501. +not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  2502. +Cambridge, MA 02139, USA. */
  2503. +
  2504. +#ifndef _BITS_ELF_FDPIC_H
  2505. +#define _BITS_ELF_FDPIC_H
  2506. +
  2507. +/* These data structures are described in the FDPIC ABI extension.
  2508. + The kernel passes a process a memory map, such that for every LOAD
  2509. + segment there is an elf32_fdpic_loadseg entry. A pointer to an
  2510. + elf32_fdpic_loadmap is passed in d8 at start-up, and a pointer to
  2511. + an additional such map is passed in d9 for the interpreter, when
  2512. + there is one. */
  2513. +
  2514. +#include <elf.h>
  2515. +
  2516. +/* This data structure represents a PT_LOAD segment. */
  2517. +struct elf32_fdpic_loadseg
  2518. +{
  2519. + /* Core address to which the segment is mapped. */
  2520. + Elf32_Addr addr;
  2521. + /* VMA recorded in the program header. */
  2522. + Elf32_Addr p_vaddr;
  2523. + /* Size of this segment in memory. */
  2524. + Elf32_Word p_memsz;
  2525. +};
  2526. +
  2527. +struct elf32_fdpic_loadmap {
  2528. + /* Protocol version number, must be zero. */
  2529. + Elf32_Half version;
  2530. + /* Number of segments in this map. */
  2531. + Elf32_Half nsegs;
  2532. + /* The actual memory map. */
  2533. + struct elf32_fdpic_loadseg segs[/*nsegs*/];
  2534. +};
  2535. +
  2536. +struct elf32_fdpic_loadaddr {
  2537. + struct elf32_fdpic_loadmap *map;
  2538. + void *got_value;
  2539. +};
  2540. +
  2541. +/* Map a pointer's VMA to its corresponding address according to the
  2542. + load map. */
  2543. +static __always_inline void *
  2544. +__reloc_pointer (void *p,
  2545. + const struct elf32_fdpic_loadmap *map)
  2546. +{
  2547. + int c;
  2548. +
  2549. +#if 0
  2550. + if (map->version != 0)
  2551. + /* Crash. */
  2552. + ((void(*)())0)();
  2553. +#endif
  2554. +
  2555. + /* No special provision is made for NULL. We don't want NULL
  2556. + addresses to go through relocation, so they shouldn't be in
  2557. + .rofixup sections, and, if they're present in dynamic
  2558. + relocations, they shall be mapped to the NULL address without
  2559. + undergoing relocations. */
  2560. +
  2561. + for (c = 0;
  2562. + /* Take advantage of the fact that the loadmap is ordered by
  2563. + virtual addresses. In general there will only be 2 entries,
  2564. + so it's not profitable to do a binary search. */
  2565. + c < map->nsegs && p >= (void*)map->segs[c].p_vaddr;
  2566. + c++)
  2567. + {
  2568. + /* This should be computed as part of the pointer comparison
  2569. + above, but we want to use the carry in the comparison, so we
  2570. + can't convert it to an integer type beforehand. */
  2571. + unsigned long offset = p - (void*)map->segs[c].p_vaddr;
  2572. + /* We only check for one-past-the-end for the last segment,
  2573. + assumed to be the data segment, because other cases are
  2574. + ambiguous in the absence of padding between segments, and
  2575. + rofixup already serves as padding between text and data.
  2576. + Unfortunately, unless we special-case the last segment, we
  2577. + fail to relocate the _end symbol. */
  2578. + if (offset < map->segs[c].p_memsz
  2579. + || (offset == map->segs[c].p_memsz && c + 1 == map->nsegs))
  2580. + return (char*)map->segs[c].addr + offset;
  2581. + }
  2582. +
  2583. + /* We might want to crash instead. */
  2584. + return (void*)-1;
  2585. +}
  2586. +
  2587. +# define __RELOC_POINTER(ptr, loadaddr) \
  2588. + (__reloc_pointer ((void*)(ptr), \
  2589. + (loadaddr).map))
  2590. +
  2591. +#endif /* _BITS_ELF_FDPIC_H */
  2592. --- /dev/null
  2593. +++ b/libc/sysdeps/linux/ubicom32/bits/endian.h
  2594. @@ -0,0 +1,7 @@
  2595. +/* Ubicom32 is big-endian. */
  2596. +
  2597. +#ifndef _ENDIAN_H
  2598. +# error "Never use <bits/endian.h> directly; include <endian.h> instead."
  2599. +#endif
  2600. +
  2601. +#define __BYTE_ORDER __BIG_ENDIAN
  2602. --- /dev/null
  2603. +++ b/libc/sysdeps/linux/ubicom32/bits/fcntl.h
  2604. @@ -0,0 +1,224 @@
  2605. +/* O_*, F_*, FD_* bit values for Linux.
  2606. + Copyright (C) 2000 Free Software Foundation, Inc.
  2607. + This file is part of the GNU C Library.
  2608. +
  2609. + The GNU C Library is free software; you can redistribute it and/or
  2610. + modify it under the terms of the GNU Lesser General Public
  2611. + License as published by the Free Software Foundation; either
  2612. + version 2.1 of the License, or (at your option) any later version.
  2613. +
  2614. + The GNU C Library is distributed in the hope that it will be useful,
  2615. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2616. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2617. + Lesser General Public License for more details.
  2618. +
  2619. + You should have received a copy of the GNU Lesser General Public
  2620. + License along with the GNU C Library; if not, write to the Free
  2621. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2622. + 02111-1307 USA. */
  2623. +
  2624. +#ifndef _FCNTL_H
  2625. +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
  2626. +#endif
  2627. +
  2628. +
  2629. +#include <sys/types.h>
  2630. +#ifdef __USE_GNU
  2631. +# include <bits/uio.h>
  2632. +#endif
  2633. +
  2634. +/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
  2635. + located on an ext2 file system */
  2636. +#define O_ACCMODE 0003
  2637. +#define O_RDONLY 00
  2638. +#define O_WRONLY 01
  2639. +#define O_RDWR 02
  2640. +#define O_CREAT 0100 /* not fcntl */
  2641. +#define O_EXCL 0200 /* not fcntl */
  2642. +#define O_NOCTTY 0400 /* not fcntl */
  2643. +#define O_TRUNC 01000 /* not fcntl */
  2644. +#define O_APPEND 02000
  2645. +#define O_NONBLOCK 04000
  2646. +#define O_NDELAY O_NONBLOCK
  2647. +#define O_SYNC 010000
  2648. +#define O_FSYNC O_SYNC
  2649. +#define O_ASYNC 020000
  2650. +
  2651. +#ifdef __USE_GNU
  2652. +# define O_DIRECTORY 040000 /* Must be a directory. */
  2653. +# define O_NOFOLLOW 0100000 /* Do not follow links. */
  2654. +# define O_DIRECT 0200000 /* Direct disk access. */
  2655. +# define O_STREAMING 04000000/* streaming access */
  2656. +#endif
  2657. +
  2658. +/* For now Linux has synchronisity options for data and read operations.
  2659. + We define the symbols here but let them do the same as O_SYNC since
  2660. + this is a superset. */
  2661. +#if defined __USE_POSIX199309 || defined __USE_UNIX98
  2662. +# define O_DSYNC O_SYNC /* Synchronize data. */
  2663. +# define O_RSYNC O_SYNC /* Synchronize read operations. */
  2664. +#endif
  2665. +
  2666. +#ifdef __USE_LARGEFILE64
  2667. +# define O_LARGEFILE 0400000
  2668. +#endif
  2669. +
  2670. +/* Values for the second argument to `fcntl'. */
  2671. +#define F_DUPFD 0 /* Duplicate file descriptor. */
  2672. +#define F_GETFD 1 /* Get file descriptor flags. */
  2673. +#define F_SETFD 2 /* Set file descriptor flags. */
  2674. +#define F_GETFL 3 /* Get file status flags. */
  2675. +#define F_SETFL 4 /* Set file status flags. */
  2676. +#ifndef __USE_FILE_OFFSET64
  2677. +# define F_GETLK 5 /* Get record locking info. */
  2678. +# define F_SETLK 6 /* Set record locking info (non-blocking). */
  2679. +# define F_SETLKW 7 /* Set record locking info (blocking). */
  2680. +#else
  2681. +# define F_GETLK F_GETLK64 /* Get record locking info. */
  2682. +# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
  2683. +# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
  2684. +#endif
  2685. +#define F_GETLK64 12 /* Get record locking info. */
  2686. +#define F_SETLK64 13 /* Set record locking info (non-blocking). */
  2687. +#define F_SETLKW64 14 /* Set record locking info (blocking). */
  2688. +
  2689. +#if defined __USE_BSD || defined __USE_XOPEN2K
  2690. +# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
  2691. +# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
  2692. +#endif
  2693. +
  2694. +#ifdef __USE_GNU
  2695. +# define F_SETSIG 10 /* Set number of signal to be sent. */
  2696. +# define F_GETSIG 11 /* Get number of signal to be sent. */
  2697. +#endif
  2698. +
  2699. +#ifdef __USE_GNU
  2700. +# define F_SETLEASE 1024 /* Set a lease. */
  2701. +# define F_GETLEASE 1025 /* Enquire what lease is active. */
  2702. +# define F_NOTIFY 1026 /* Request notfications on a directory. */
  2703. +#endif
  2704. +
  2705. +/* For F_[GET|SET]FL. */
  2706. +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
  2707. +
  2708. +/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
  2709. +#define F_RDLCK 0 /* Read lock. */
  2710. +#define F_WRLCK 1 /* Write lock. */
  2711. +#define F_UNLCK 2 /* Remove lock. */
  2712. +
  2713. +/* For old implementation of bsd flock(). */
  2714. +#define F_EXLCK 4 /* or 3 */
  2715. +#define F_SHLCK 8 /* or 4 */
  2716. +
  2717. +#ifdef __USE_BSD
  2718. +/* Operations for bsd flock(), also used by the kernel implementation. */
  2719. +# define LOCK_SH 1 /* shared lock */
  2720. +# define LOCK_EX 2 /* exclusive lock */
  2721. +# define LOCK_NB 4 /* or'd with one of the above to prevent
  2722. + blocking */
  2723. +# define LOCK_UN 8 /* remove lock */
  2724. +#endif
  2725. +
  2726. +#ifdef __USE_GNU
  2727. +# define LOCK_MAND 32 /* This is a mandatory flock: */
  2728. +# define LOCK_READ 64 /* ... which allows concurrent read operations. */
  2729. +# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
  2730. +# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
  2731. +#endif
  2732. +
  2733. +#ifdef __USE_GNU
  2734. +/* Types of directory notifications that may be requested with F_NOTIFY. */
  2735. +# define DN_ACCESS 0x00000001 /* File accessed. */
  2736. +# define DN_MODIFY 0x00000002 /* File modified. */
  2737. +# define DN_CREATE 0x00000004 /* File created. */
  2738. +# define DN_DELETE 0x00000008 /* File removed. */
  2739. +# define DN_RENAME 0x00000010 /* File renamed. */
  2740. +# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
  2741. +# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
  2742. +#endif
  2743. +
  2744. +struct flock
  2745. + {
  2746. + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
  2747. + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
  2748. +#ifndef __USE_FILE_OFFSET64
  2749. + __off_t l_start; /* Offset where the lock begins. */
  2750. + __off_t l_len; /* Size of the locked area; zero means until EOF. */
  2751. +#else
  2752. + __off64_t l_start; /* Offset where the lock begins. */
  2753. + __off64_t l_len; /* Size of the locked area; zero means until EOF. */
  2754. +#endif
  2755. + __pid_t l_pid; /* Process holding the lock. */
  2756. + };
  2757. +
  2758. +#ifdef __USE_LARGEFILE64
  2759. +struct flock64
  2760. + {
  2761. + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
  2762. + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
  2763. + __off64_t l_start; /* Offset where the lock begins. */
  2764. + __off64_t l_len; /* Size of the locked area; zero means until EOF. */
  2765. + __pid_t l_pid; /* Process holding the lock. */
  2766. + };
  2767. +#endif
  2768. +
  2769. +/* Define some more compatibility macros to be backward compatible with
  2770. + BSD systems which did not managed to hide these kernel macros. */
  2771. +#ifdef __USE_BSD
  2772. +# define FAPPEND O_APPEND
  2773. +# define FFSYNC O_FSYNC
  2774. +# define FASYNC O_ASYNC
  2775. +# define FNONBLOCK O_NONBLOCK
  2776. +# define FNDELAY O_NDELAY
  2777. +#endif /* Use BSD. */
  2778. +
  2779. +/* Advise to `posix_fadvise'. */
  2780. +#ifdef __USE_XOPEN2K
  2781. +# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
  2782. +# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
  2783. +# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
  2784. +# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
  2785. +# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
  2786. +# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
  2787. +#endif
  2788. +
  2789. +#ifdef __USE_GNU
  2790. +# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
  2791. + in the range before performing the
  2792. + write. */
  2793. +# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
  2794. + dirty pages in the range which are
  2795. + not presently under writeback. */
  2796. +# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
  2797. + the range after performing the
  2798. + write. */
  2799. +#endif
  2800. +
  2801. +__BEGIN_DECLS
  2802. +
  2803. +#ifdef __USE_GNU
  2804. +
  2805. +/* Provide kernel hint to read ahead. */
  2806. +extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
  2807. + __THROW;
  2808. +
  2809. +/* Selective file content synch'ing. */
  2810. +extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
  2811. + unsigned int __flags);
  2812. +
  2813. +/* Splice address range into a pipe. */
  2814. +extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
  2815. + size_t __count, unsigned int __flags);
  2816. +
  2817. +/* Splice two files together. */
  2818. +extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
  2819. + __off64_t *__offout, size_t __len,
  2820. + unsigned int __flags);
  2821. +
  2822. +/* In-kernel implementation of tee for pipe buffers. */
  2823. +extern ssize_t tee (int __fdin, int __fdout, size_t __len,
  2824. + unsigned int __flags);
  2825. +
  2826. +#endif
  2827. +
  2828. +__END_DECLS
  2829. --- /dev/null
  2830. +++ b/libc/sysdeps/linux/ubicom32/bits/kernel_stat.h
  2831. @@ -0,0 +1,61 @@
  2832. +#ifndef _BITS_STAT_STRUCT_H
  2833. +#define _BITS_STAT_STRUCT_H
  2834. +
  2835. +#ifndef _LIBC
  2836. +#error bits/kernel_stat.h is for internal uClibc use only!
  2837. +#endif
  2838. +
  2839. +/* This file provides whatever this particular arch's kernel thinks
  2840. + * struct kernel_stat should look like... It turns out each arch has a
  2841. + * different opinion on the subject... */
  2842. +
  2843. +struct kernel_stat {
  2844. + unsigned short st_dev;
  2845. + unsigned short __pad1;
  2846. + unsigned long st_ino;
  2847. + unsigned short st_mode;
  2848. + unsigned short st_nlink;
  2849. + unsigned short st_uid;
  2850. + unsigned short st_gid;
  2851. + unsigned short st_rdev;
  2852. + unsigned short __pad2;
  2853. + unsigned long st_size;
  2854. + unsigned long st_blksize;
  2855. + unsigned long st_blocks;
  2856. + unsigned long st_atime;
  2857. + unsigned long __unused1;
  2858. + unsigned long st_mtime;
  2859. + unsigned long __unused2;
  2860. + unsigned long st_ctime;
  2861. + unsigned long __unused3;
  2862. + unsigned long __unused4;
  2863. + unsigned long __unused5;
  2864. +};
  2865. +
  2866. +struct kernel_stat64 {
  2867. + unsigned char __pad0[6];
  2868. + unsigned short st_dev;
  2869. + unsigned char __pad1[4];
  2870. +#define _HAVE_STAT64___ST_INO
  2871. + unsigned long __st_ino;
  2872. + unsigned int st_mode;
  2873. + unsigned int st_nlink;
  2874. + unsigned long st_uid;
  2875. + unsigned long st_gid;
  2876. + unsigned char __pad2[6];
  2877. + unsigned short st_rdev;
  2878. + unsigned char __pad3[4];
  2879. + long long st_size;
  2880. + unsigned long st_blksize;
  2881. + unsigned long st_blocks; /* Number 512-byte blocks allocated. */
  2882. + unsigned long __pad4; /* future possible st_blocks high bits */
  2883. + unsigned long st_atime;
  2884. + unsigned long __pad5;
  2885. + unsigned long st_mtime;
  2886. + unsigned long __pad6;
  2887. + unsigned long st_ctime;
  2888. + unsigned long __pad7; /* will be high 32 bits of ctime someday */
  2889. + unsigned long long st_ino;
  2890. +};
  2891. +
  2892. +#endif /* _BITS_STAT_STRUCT_H */
  2893. --- /dev/null
  2894. +++ b/libc/sysdeps/linux/ubicom32/bits/kernel_types.h
  2895. @@ -0,0 +1,44 @@
  2896. +/* Note that we use the exact same include guard #define names
  2897. + * as asm/posix_types.h. This will avoid gratuitous conflicts
  2898. + * with the posix_types.h kernel header, and will ensure that
  2899. + * our private content, and not the kernel header, will win.
  2900. + * -Erik
  2901. + */
  2902. +#ifndef __ARCH_UBICOM32_POSIX_TYPES_H
  2903. +#define __ARCH_UBICOM32_POSIX_TYPES_H
  2904. +
  2905. +typedef unsigned long __kernel_dev_t;
  2906. +typedef unsigned long __kernel_ino_t;
  2907. +typedef unsigned short __kernel_mode_t;
  2908. +typedef unsigned short __kernel_nlink_t;
  2909. +typedef long __kernel_off_t;
  2910. +typedef int __kernel_pid_t;
  2911. +typedef unsigned short __kernel_ipc_pid_t;
  2912. +typedef unsigned short __kernel_uid_t;
  2913. +typedef unsigned short __kernel_gid_t;
  2914. +typedef unsigned int __kernel_size_t;
  2915. +typedef int __kernel_ssize_t;
  2916. +typedef int __kernel_ptrdiff_t;
  2917. +typedef long __kernel_time_t;
  2918. +typedef long __kernel_suseconds_t;
  2919. +typedef long __kernel_clock_t;
  2920. +typedef int __kernel_daddr_t;
  2921. +typedef char * __kernel_caddr_t;
  2922. +typedef unsigned short __kernel_uid16_t;
  2923. +typedef unsigned short __kernel_gid16_t;
  2924. +typedef unsigned int __kernel_uid32_t;
  2925. +typedef unsigned int __kernel_gid32_t;
  2926. +typedef unsigned short __kernel_old_uid_t;
  2927. +typedef unsigned short __kernel_old_gid_t;
  2928. +typedef unsigned short __kernel_old_dev_t;
  2929. +typedef long long __kernel_loff_t;
  2930. +
  2931. +typedef struct {
  2932. +#ifdef __USE_ALL
  2933. + int val[2];
  2934. +#else
  2935. + int __val[2];
  2936. +#endif
  2937. +} __kernel_fsid_t;
  2938. +
  2939. +#endif /* __ARCH_UBICOM32_POSIX_TYPES_H */
  2940. --- /dev/null
  2941. +++ b/libc/sysdeps/linux/ubicom32/bits/mman.h
  2942. @@ -0,0 +1,102 @@
  2943. +/* Definitions for POSIX memory map interface. Linux/m68k version.
  2944. + Copyright (C) 1997, 2000, 2003, 2005 Free Software Foundation, Inc.
  2945. + This file is part of the GNU C Library.
  2946. +
  2947. + The GNU C Library is free software; you can redistribute it and/or
  2948. + modify it under the terms of the GNU Lesser General Public
  2949. + License as published by the Free Software Foundation; either
  2950. + version 2.1 of the License, or (at your option) any later version.
  2951. +
  2952. + The GNU C Library is distributed in the hope that it will be useful,
  2953. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2954. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2955. + Lesser General Public License for more details.
  2956. +
  2957. + You should have received a copy of the GNU Lesser General Public
  2958. + License along with the GNU C Library; if not, write to the Free
  2959. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2960. + 02111-1307 USA. */
  2961. +
  2962. +#ifndef _SYS_MMAN_H
  2963. +# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
  2964. +#endif
  2965. +
  2966. +/* The following definitions basically come from the kernel headers.
  2967. + But the kernel header is not namespace clean. */
  2968. +
  2969. +
  2970. +/* Protections are chosen from these bits, OR'd together. The
  2971. + implementation does not necessarily support PROT_EXEC or PROT_WRITE
  2972. + without PROT_READ. The only guarantees are that no writing will be
  2973. + allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
  2974. +
  2975. +#define PROT_READ 0x1 /* Page can be read. */
  2976. +#define PROT_WRITE 0x2 /* Page can be written. */
  2977. +#define PROT_EXEC 0x4 /* Page can be executed. */
  2978. +#define PROT_NONE 0x0 /* Page can not be accessed. */
  2979. +#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
  2980. + growsdown vma (mprotect only). */
  2981. +#define PROT_GROWSUP 0x02000000 /* Extend change to start of
  2982. + growsup vma (mprotect only). */
  2983. +
  2984. +/* Sharing types (must choose one and only one of these). */
  2985. +#define MAP_SHARED 0x01 /* Share changes. */
  2986. +#define MAP_PRIVATE 0x02 /* Changes are private. */
  2987. +#ifdef __USE_MISC
  2988. +# define MAP_TYPE 0x0f /* Mask for type of mapping. */
  2989. +#endif
  2990. +
  2991. +/* Other flags. */
  2992. +#define MAP_FIXED 0x10 /* Interpret addr exactly. */
  2993. +#ifdef __USE_MISC
  2994. +# define MAP_FILE 0
  2995. +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
  2996. +# define MAP_ANON MAP_ANONYMOUS
  2997. +#endif
  2998. +
  2999. +/* These are Linux-specific. */
  3000. +#ifdef __USE_MISC
  3001. +# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
  3002. +# define MAP_DENYWRITE 0x00800 /* ETXTBSY */
  3003. +# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
  3004. +# define MAP_LOCKED 0x02000 /* Lock the mapping. */
  3005. +# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
  3006. +# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
  3007. +# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
  3008. +#endif
  3009. +
  3010. +/* Flags to `msync'. */
  3011. +#define MS_ASYNC 1 /* Sync memory asynchronously. */
  3012. +#define MS_SYNC 4 /* Synchronous memory sync. */
  3013. +#define MS_INVALIDATE 2 /* Invalidate the caches. */
  3014. +
  3015. +/* Flags for `mlockall'. */
  3016. +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
  3017. +#define MCL_FUTURE 2 /* Lock all additions to address
  3018. + space. */
  3019. +
  3020. +/* Flags for `mremap'. */
  3021. +#ifdef __USE_GNU
  3022. +# define MREMAP_MAYMOVE 1
  3023. +# define MREMAP_FIXED 2
  3024. +#endif
  3025. +
  3026. +/* Advice to `madvise'. */
  3027. +#ifdef __USE_BSD
  3028. +# define MADV_NORMAL 0 /* No further special treatment. */
  3029. +# define MADV_RANDOM 1 /* Expect random page references. */
  3030. +# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
  3031. +# define MADV_WILLNEED 3 /* Will need these pages. */
  3032. +# define MADV_DONTNEED 4 /* Don't need these pages. */
  3033. +# define MADV_DONTFORK 10 /* Do not inherit across fork. */
  3034. +# define MADV_DOFORK 11 /* Do inherit across fork. */
  3035. +#endif
  3036. +
  3037. +/* The POSIX people had to invent similar names for the same things. */
  3038. +#ifdef __USE_XOPEN2K
  3039. +# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
  3040. +# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
  3041. +# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
  3042. +# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
  3043. +# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
  3044. +#endif
  3045. --- /dev/null
  3046. +++ b/libc/sysdeps/linux/ubicom32/bits/setjmp.h
  3047. @@ -0,0 +1,52 @@
  3048. +/* Define the machine-dependent type `jmp_buf'. Ubicom32 version.
  3049. + Copyright (C) 1992,93,95,97,2000 Free Software Foundation, Inc.
  3050. + This file is part of the GNU C Library.
  3051. +
  3052. + The GNU C Library is free software; you can redistribute it and/or
  3053. + modify it under the terms of the GNU Lesser General Public
  3054. + License as published by the Free Software Foundation; either
  3055. + version 2.1 of the License, or (at your option) any later version.
  3056. +
  3057. + The GNU C Library is distributed in the hope that it will be useful,
  3058. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3059. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3060. + Lesser General Public License for more details.
  3061. +
  3062. + You should have received a copy of the GNU Lesser General Public
  3063. + License along with the GNU C Library; if not, write to the Free
  3064. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3065. + 02111-1307 USA. */
  3066. +
  3067. +#ifndef _BITS_SETJMP_H
  3068. +#define _BITS_SETJMP_H 1
  3069. +
  3070. +#if !defined _SETJMP_H && !defined _PTHREAD_H
  3071. +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
  3072. +#endif
  3073. +
  3074. +#ifndef _ASM
  3075. +/*
  3076. + * This is the structure where we are going to save D10-D13, A0, A1, A2, A5, A6 and SP(A7).
  3077. + * A5 is the return address. Call to setjmp will save these. Call to longjmp will return
  3078. + * Control to the address in A5.
  3079. + */
  3080. +typedef struct setjmp_save_struct {
  3081. + unsigned long d10; /* D10 */
  3082. + unsigned long d11; /* D11 */
  3083. + unsigned long d12; /* D12 */
  3084. + unsigned long d13; /* D13 */
  3085. + unsigned long a1; /* A1 */
  3086. + unsigned long a2; /* A2 */
  3087. + unsigned long a5; /* A5 return address. */
  3088. + unsigned long a6; /* A6 */
  3089. + unsigned long sp; /* A7 stack pointer. */
  3090. +} __jmp_buf[1];
  3091. +
  3092. +#endif
  3093. +
  3094. +/* Test if longjmp to JMPBUF would unwind the frame
  3095. + containing a local variable at ADDRESS. */
  3096. +#define _JMPBUF_UNWINDS(jmpbuf, address) \
  3097. + ((void *) (address) < (void*)(jmpbuf)->sp)
  3098. +
  3099. +#endif /* bits/setjmp.h */
  3100. --- /dev/null
  3101. +++ b/libc/sysdeps/linux/ubicom32/bits/stackinfo.h
  3102. @@ -0,0 +1,28 @@
  3103. +/* Copyright (C) 1999 Free Software Foundation, Inc.
  3104. + This file is part of the GNU C Library.
  3105. +
  3106. + The GNU C Library is free software; you can redistribute it and/or
  3107. + modify it under the terms of the GNU Lesser General Public
  3108. + License as published by the Free Software Foundation; either
  3109. + version 2.1 of the License, or (at your option) any later version.
  3110. +
  3111. + The GNU C Library is distributed in the hope that it will be useful,
  3112. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3113. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3114. + Lesser General Public License for more details.
  3115. +
  3116. + You should have received a copy of the GNU Lesser General Public
  3117. + License along with the GNU C Library; if not, write to the Free
  3118. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3119. + 02111-1307 USA. */
  3120. +
  3121. +/* This file contains a bit of information about the stack allocation
  3122. + of the processor. */
  3123. +
  3124. +#ifndef _STACKINFO_H
  3125. +#define _STACKINFO_H 1
  3126. +
  3127. +/* On Ubicom32 the stack grows down. */
  3128. +#define _STACK_GROWS_DOWN 1
  3129. +
  3130. +#endif /* stackinfo.h */
  3131. --- /dev/null
  3132. +++ b/libc/sysdeps/linux/ubicom32/bits/syscalls.h
  3133. @@ -0,0 +1,169 @@
  3134. +#ifndef _BITS_SYSCALLS_H
  3135. +#define _BITS_SYSCALLS_H
  3136. +#ifndef _SYSCALL_H
  3137. +# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  3138. +#endif
  3139. +
  3140. +/* m68k headers does stupid stuff with __NR_iopl / __NR_vm86:
  3141. + * #define __NR_iopl not supported
  3142. + * #define __NR_vm86 not supported
  3143. + */
  3144. +#undef __NR_iopl
  3145. +#undef __NR_vm86
  3146. +
  3147. +#ifndef __ASSEMBLER__
  3148. +
  3149. +#include <errno.h>
  3150. +
  3151. +/* Linux takes system call arguments in registers:
  3152. +
  3153. + syscall number %d8
  3154. + arg 1 %d0
  3155. + arg 2 %d1
  3156. + arg 3 %d2
  3157. + arg 4 %d3
  3158. + arg 5 %d4
  3159. + arg 6 %d5
  3160. +*/
  3161. +
  3162. +#define __syscall_return(type, res) \
  3163. + do { \
  3164. + if (likely((unsigned long)(res) < (unsigned long)(-125))) { \
  3165. + return (type) (res); \
  3166. + } else { \
  3167. + /* avoid using res which is declared to be in register d0; \
  3168. + errno might expand to a function call and clobber it. */ \
  3169. + int __err = -(res); \
  3170. + __set_errno(__err); \
  3171. + return (type) -1; \
  3172. + } \
  3173. + } while (0)
  3174. +
  3175. +extern void __illegally_sized_syscall_arg1 (void);
  3176. +extern void __illegally_sized_syscall_arg2 (void);
  3177. +extern void __illegally_sized_syscall_arg3 (void);
  3178. +extern void __illegally_sized_syscall_arg4 (void);
  3179. +extern void __illegally_sized_syscall_arg5 (void);
  3180. +extern void __illegally_sized_syscall_arg6 (void);
  3181. +
  3182. +#define __loadargs_0(name, dummy) \
  3183. + d8 = name
  3184. +
  3185. +#define __loadargs_1(name, __arg1) \
  3186. + __loadargs_0(name, 0); \
  3187. + if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
  3188. + __illegally_sized_syscall_arg1 (); \
  3189. + d0_retval = (long int) __arg1
  3190. +#define __loadargs_2(name, __arg1, __arg2) \
  3191. + __loadargs_1(name, __arg1); \
  3192. + if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
  3193. + __illegally_sized_syscall_arg2 (); \
  3194. + d1 = (long int) __arg2
  3195. +
  3196. +#define __loadargs_3(name, __arg1, __arg2, __arg3) \
  3197. + __loadargs_2(name, __arg1, __arg2); \
  3198. + if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
  3199. + __illegally_sized_syscall_arg3 (); \
  3200. + d2 = (long int) __arg3
  3201. +
  3202. +#define __loadargs_4(name, __arg1, __arg2, __arg3, __arg4) \
  3203. + __loadargs_3(name, __arg1, __arg2, __arg3); \
  3204. + if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
  3205. + __illegally_sized_syscall_arg4 (); \
  3206. + d3 = (long int)__arg4
  3207. +
  3208. +#define __loadargs_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
  3209. + __loadargs_4(name, __arg1, __arg2, __arg3, __arg4); \
  3210. + if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
  3211. + __illegally_sized_syscall_arg5 (); \
  3212. + d4 = (long int)__arg5
  3213. +
  3214. +#define __loadargs_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
  3215. + __loadargs_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
  3216. + if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
  3217. + __illegally_sized_syscall_arg6 (); \
  3218. + d5 = (long int)__arg6
  3219. +
  3220. +#define __internal_syscall_body(name, nr, args...) \
  3221. + register long int d0_retval __asm__ ("d0"); \
  3222. + register long int d1 __asm__ ("d1"); \
  3223. + register long int d2 __asm__ ("d2"); \
  3224. + register long int d3 __asm__ ("d3"); \
  3225. + register long int d4 __asm__ ("d4"); \
  3226. + register long int d5 __asm__ ("d5"); \
  3227. + register long int d8 __asm__ ("d8"); \
  3228. + __loadargs_##nr (__NR_##name, args); \
  3229. + __asm__ __volatile__ ( \
  3230. + " moveai a5, #%%hi(0x40400000)\n\t" \
  3231. + " calli a5, 16(a5)\n\t" \
  3232. + : "+r" (d0_retval), "+r" (d1), "+r" (d2), "+r" (d3), \
  3233. + "+r" (d4), "+r" (d5), "+r" (d8) : \
  3234. + : "cc", "memory", \
  3235. + "acc0_lo", "acc0_hi", "acc1_lo", "acc1_hi", \
  3236. + "source3", \
  3237. + "a0", "a3", "a4", "a5", \
  3238. + "d6", "d7", "d9", "d14", "d15" \
  3239. + );
  3240. +
  3241. +#define INLINE_SYSCALL(name, nr, args...) \
  3242. + ({ \
  3243. + __internal_syscall_body(name, nr, args); \
  3244. + if (unlikely((unsigned long)(d0_retval) >= (unsigned long)(-125))) { \
  3245. + __set_errno (-d0_retval); \
  3246. + d0_retval = -1L; \
  3247. + } \
  3248. + d0_retval; \
  3249. + })
  3250. +
  3251. +
  3252. +#undef _syscall0
  3253. +#define _syscall0(type,name) \
  3254. +type name(void){ \
  3255. + __internal_syscall_body(name, 0); \
  3256. + __syscall_return(type, d0_retval); \
  3257. +}
  3258. +
  3259. +#undef _syscall1
  3260. +#define _syscall1(type,name,type1,arg1) \
  3261. +type name(type1 arg1){ \
  3262. + __internal_syscall_body(name, 1, arg1); \
  3263. + __syscall_return(type, d0_retval); \
  3264. +}
  3265. +
  3266. +#undef _syscall2
  3267. +#define _syscall2(type,name,type1,arg1,type2,arg2) \
  3268. +type name(type1 arg1, type2 arg2){ \
  3269. + __internal_syscall_body(name, 2, arg1, arg2); \
  3270. + __syscall_return(type, d0_retval); \
  3271. +}
  3272. +
  3273. +#undef _syscall3
  3274. +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  3275. +type name(type1 arg1, type2 arg2, type3 arg3){ \
  3276. + __internal_syscall_body(name, 3, arg1, arg2, arg3); \
  3277. + __syscall_return(type, d0_retval); \
  3278. +}
  3279. +
  3280. +#undef _syscall4
  3281. +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  3282. +type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4){ \
  3283. + __internal_syscall_body(name, 4, arg1, arg2, arg3, arg4); \
  3284. + __syscall_return(type, d0_retval); \
  3285. +}
  3286. +
  3287. +#undef _syscall5
  3288. +#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  3289. +type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5){ \
  3290. + __internal_syscall_body(name, 5, arg1, arg2, arg3, arg4, arg5); \
  3291. + __syscall_return(type, d0_retval); \
  3292. +}
  3293. +
  3294. +#undef _syscall6
  3295. +#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \
  3296. +type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6){ \
  3297. + __internal_syscall_body(name, 6, arg1, arg2, arg3, arg4, arg5, arg6); \
  3298. + __syscall_return(type, d0_retval); \
  3299. +}
  3300. +
  3301. +#endif /* __ASSEMBLER__ */
  3302. +#endif /* _BITS_SYSCALLS_H */
  3303. --- /dev/null
  3304. +++ b/libc/sysdeps/linux/ubicom32/bits/uClibc_arch_features.h
  3305. @@ -0,0 +1,45 @@
  3306. +/*
  3307. + * Track misc arch-specific features that aren't config options
  3308. + */
  3309. +
  3310. +#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
  3311. +#define _BITS_UCLIBC_ARCH_FEATURES_H
  3312. +
  3313. +/* instruction used when calling abort() to kill yourself */
  3314. +/*#define __UCLIBC_ABORT_INSTRUCTION__ "asm instruction"*/
  3315. +#undef __UCLIBC_ABORT_INSTRUCTION__
  3316. +
  3317. +/* can your target use syscall6() for mmap ? */
  3318. +#undef __UCLIBC_MMAP_HAS_6_ARGS__
  3319. +
  3320. +/* does your target use syscall4() for truncate64 ? (32bit arches only) */
  3321. +#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__
  3322. +
  3323. +/* does your target have a broken create_module() ? */
  3324. +#undef __UCLIBC_BROKEN_CREATE_MODULE__
  3325. +
  3326. +/* does your target have to worry about older [gs]etrlimit() ? */
  3327. +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
  3328. +
  3329. +/* does your target prefix all symbols with an _ ? */
  3330. +#define __UCLIBC_NO_UNDERSCORES__
  3331. +
  3332. +/* does your target have an asm .set ? */
  3333. +#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
  3334. +
  3335. +/* define if target doesn't like .global */
  3336. +#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
  3337. +
  3338. +/* define if target supports .weak */
  3339. +#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
  3340. +
  3341. +/* define if target supports .weakext */
  3342. +#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
  3343. +
  3344. +/* needed probably only for ppc64 */
  3345. +#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
  3346. +
  3347. +/* define if target supports IEEE signed zero floats */
  3348. +#define __UCLIBC_HAVE_SIGNED_ZERO__
  3349. +
  3350. +#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
  3351. --- /dev/null
  3352. +++ b/libc/sysdeps/linux/ubicom32/bits/wordsize.h
  3353. @@ -0,0 +1,19 @@
  3354. +/* Copyright (C) 1999 Free Software Foundation, Inc.
  3355. + This file is part of the GNU C Library.
  3356. +
  3357. + The GNU C Library is free software; you can redistribute it and/or
  3358. + modify it under the terms of the GNU Lesser General Public
  3359. + License as published by the Free Software Foundation; either
  3360. + version 2.1 of the License, or (at your option) any later version.
  3361. +
  3362. + The GNU C Library is distributed in the hope that it will be useful,
  3363. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3364. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3365. + Lesser General Public License for more details.
  3366. +
  3367. + You should have received a copy of the GNU Lesser General Public
  3368. + License along with the GNU C Library; if not, write to the Free
  3369. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3370. + 02111-1307 USA. */
  3371. +
  3372. +#define __WORDSIZE 32
  3373. --- /dev/null
  3374. +++ b/libc/sysdeps/linux/ubicom32/clone.S
  3375. @@ -0,0 +1,71 @@
  3376. +#include <sys/syscall.h>
  3377. +
  3378. + .global __syscall_error
  3379. +
  3380. +/* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  3381. + .text
  3382. + .type clone,@function
  3383. + .global clone
  3384. +clone:
  3385. + /* Sanity check arguments. */
  3386. + sub.4 #0, #0, d0 /* Test if fn is zero. */
  3387. + jmpeq.f 1f /* arg bad */
  3388. + sub.4 #0, #0, d1 /* Test if child_stack is zero. */
  3389. + jmpeq.f 1f /* arg bad */
  3390. +
  3391. + /* Set up child_stack frame.. arg and fn */
  3392. + move.4 a3, d1
  3393. + move.4 -4(a3)++, d3 /* push 'arg' to child stack */
  3394. + move.4 -4(a3)++, d0 /* push fn to child stack, this will become a5
  3395. + * on new child */
  3396. + move.4 d1, a3
  3397. + move.4 -4(sp)++, a5 /* push a5 to our stack */
  3398. +
  3399. + /*
  3400. + * The syscall clone is clone(int flags, void *child_stack) so we set
  3401. + * that up now
  3402. + */
  3403. + move.4 d0, d2 /* Move flags to d0 */
  3404. +
  3405. + /* Do Clone syscall */
  3406. + movei d8, #__NR_clone
  3407. + moveai a5, #%hi(0x40400000)
  3408. + calli a5, 0x10(a5)
  3409. + move.4 a5, (sp)4++ /* pop a5 from stack */
  3410. +
  3411. + /* Clone Complete */
  3412. + cmpi d0, #0 /* Test if d0 is less than zero. If it is we
  3413. + * return the error */
  3414. + jmplt.f 2f /* If return is less than we had an error */
  3415. + jmpeq.f 3f /* If return is 0 we are in the clone, jump to
  3416. + * thread start */
  3417. + ret a5 /* d0 is pid */
  3418. +
  3419. + /* Invalid Value */
  3420. +1: movei d0, #-22 /* EINVAL */
  3421. +
  3422. + /* Call syscall Error */
  3423. +2: sub.4 d0, #0, d0 /* d0 = -d0 */
  3424. +#if defined(__UBICOM32_FDPIC__)
  3425. + call a3, __syscall_error
  3426. +#else
  3427. + moveai a3, #%hi(__syscall_error)
  3428. + calli a3, %lo(__syscall_error)(a3)
  3429. +#endif
  3430. + /* Child Thread Start */
  3431. +3:
  3432. +#if defined(__UBICOM32_FDPIC__)
  3433. + /* a5 actually contains a function descriptor for fdpic */
  3434. + move.4 a0, 4(a5) /* set GOT for this function */
  3435. + move.4 a5, 0(a5) /* get address of entry point */
  3436. +#endif
  3437. + move.4 d0, (sp)4++ /* pop 'arg' to stack */
  3438. + calli a5, 0(a5)
  3439. + movei d8, #__NR_exit
  3440. + moveai a3, #%hi(0x40400000)
  3441. + calli a3, 0x10(a3)
  3442. +
  3443. + .size clone, . - clone
  3444. + .global __GI_clone
  3445. + .hidden __GI_clone
  3446. + .set __GI_clone,clone
  3447. --- /dev/null
  3448. +++ b/libc/sysdeps/linux/ubicom32/crt1.S
  3449. @@ -0,0 +1,179 @@
  3450. +/* Startup code compliant to the ELF m68k ABI.
  3451. + Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
  3452. + This file is part of the GNU C Library.
  3453. +
  3454. + The GNU C Library is free software; you can redistribute it and/or
  3455. + modify it under the terms of the GNU Lesser General Public
  3456. + License as published by the Free Software Foundation; either
  3457. + version 2.1 of the License, or (at your option) any later version.
  3458. +
  3459. + In addition to the permissions in the GNU Lesser General Public
  3460. + License, the Free Software Foundation gives you unlimited
  3461. + permission to link the compiled version of this file with other
  3462. + programs, and to distribute those programs without any restriction
  3463. + coming from the use of this file. (The GNU Lesser General Public
  3464. + License restrictions do apply in other respects; for example, they
  3465. + cover modification of the file, and distribution when not linked
  3466. + into another program.)
  3467. +
  3468. + Note that people who make modified versions of this file are not
  3469. + obligated to grant this special exception for their modified
  3470. + versions; it is their choice whether to do so. The GNU Lesser
  3471. + General Public License gives permission to release a modified
  3472. + version without this exception; this exception also makes it
  3473. + possible to release a modified version which carries forward this
  3474. + exception.
  3475. +
  3476. + The GNU C Library is distributed in the hope that it will be useful,
  3477. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3478. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3479. + Lesser General Public License for more details.
  3480. +
  3481. + You should have received a copy of the GNU Lesser General Public
  3482. + License along with the GNU C Library; if not, write to the Free
  3483. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3484. + 02111-1307 USA. */
  3485. +
  3486. +#include <features.h>
  3487. +
  3488. +/* This is the canonical entry point, usually the first thing in the text
  3489. + segment. The SVR4/m68k ABI says that when the entry point runs,
  3490. + most registers' values are unspecified, except for:
  3491. +
  3492. + %a1 Contains a function pointer to be registered with `atexit'.
  3493. + This is how the dynamic linker arranges to have DT_FINI
  3494. + functions called for shared libraries that have been loaded
  3495. + before this code runs.
  3496. +
  3497. + %sp The stack contains the arguments and environment:
  3498. + 0(%sp) argc
  3499. + 4(%sp) argv[0]
  3500. + ...
  3501. + (4*argc)(%sp) NULL
  3502. + (4*(argc+1))(%sp) envp[0]
  3503. + ...
  3504. + NULL
  3505. +
  3506. + The uclinux conventions are different. %a1 is not defined on entry
  3507. + and the stack is laid out as follows:
  3508. +
  3509. + 0(%sp) argc
  3510. + 4(%sp) argv
  3511. + 8(%sp) envp
  3512. +*/
  3513. +
  3514. +
  3515. + .text
  3516. + .type main,@function
  3517. + .type _init,%function
  3518. + .type _fini,%function
  3519. +#ifndef __UCLIBC_CTOR_DTOR__
  3520. + .weak _init
  3521. + .weak _fini
  3522. +#endif
  3523. + .globl _start
  3524. + .global __uClibc_main;
  3525. + .type __uClibc_main,@function;
  3526. + .type _start,@function
  3527. +_start:
  3528. +
  3529. +#if defined(__UBICOM32_FDPIC__) && !defined(L_Scrt1)
  3530. + /* P0 contains a pointer to the program's load map. */
  3531. + call a3, .Lcall;
  3532. +.Lcall:
  3533. + move.4 d0, d1 ; load exec_map_addr
  3534. + moveai a4, #%hi(.Lcall)
  3535. + lea.1 d15, %lo(.Lcall)(a4)
  3536. + sub.4 d15, a3, d15 ; difference between .Lcall and actual address of .Lcall
  3537. + moveai a3, #%hi(__ROFIXUP_LIST__)
  3538. + lea.1 d1, %lo(__ROFIXUP_LIST__)(a3)
  3539. + moveai a3, #%hi(__ROFIXUP_END__)
  3540. + lea.1 d2, %lo(__ROFIXUP_END__)(a3)
  3541. + add.4 d1, d1, d15
  3542. + add.4 d2, d2, d15
  3543. + call a5, __self_reloc ; returns GOT in d0
  3544. + move.4 a0, d0 ; set GOT
  3545. +#endif
  3546. +
  3547. +/*
  3548. + all this is setup to make the following call.
  3549. +
  3550. + void __uClibc_main(
  3551. + d0 - int (*main)(int, char **, char **),
  3552. + d1 - int argc, (d1)
  3553. + d2 - char **argv,
  3554. + d3 - void (*app_init)(void),
  3555. + d4 - void (*app_fini)(void),
  3556. + d5 - void (*rtld_fini)(void),
  3557. + d6 - void *stack_end
  3558. + );
  3559. + */
  3560. +
  3561. + /*
  3562. + * Load pointer to main into d0
  3563. + */
  3564. +#ifdef __UBICOM32_FDPIC__
  3565. + movei d0, #%got_funcdesc_lo(main)
  3566. + move.4 d0, (a0, d0)
  3567. +#else
  3568. + moveai a3, #%hi(main)
  3569. + lea.1 d0, %lo(main)(a3)
  3570. +#endif
  3571. +
  3572. + /*
  3573. + * Grab the environment stuff from stack and set up d1, d2 with it.
  3574. + */
  3575. + move.4 d1, (sp)
  3576. +#ifdef __UBICOM32_FDPIC__
  3577. + /* For FDPIC the calling convention is different than flat */
  3578. + lea.1 d2, 4(sp)
  3579. +#else
  3580. + move.4 d2, 4(sp)
  3581. +#endif
  3582. +
  3583. +#ifdef __UCLIBC_CTOR_DTOR__
  3584. + /*
  3585. + * Load pointer to _init into d3
  3586. + */
  3587. +#ifdef __UBICOM32_FDPIC__
  3588. + movei d3, #%got_funcdesc_lo(_init)
  3589. + move.4 d3, (a0, d3)
  3590. +#else
  3591. + moveai a3, #%hi(_init)
  3592. + lea.1 d3, %lo(_init)(a3)
  3593. +#endif
  3594. +
  3595. + /*
  3596. + * Load pointer to _fini into d4
  3597. + */
  3598. +#ifdef __UBICOM32_FDPIC__
  3599. + movei d4, #%got_funcdesc_lo(_fini)
  3600. + move.4 d4, (a0, d4)
  3601. +#else
  3602. + moveai a3, #%hi(_fini)
  3603. + lea.1 d4, %lo(_fini)(a3)
  3604. +#endif
  3605. +
  3606. +#else /* !__UCLIBC_CTOR_DTOR__ */
  3607. + move.4 d3, #0 ; _init
  3608. + move.4 d4, #0 ; _fini
  3609. +#endif
  3610. +
  3611. +#ifdef __UBICOM32_FDPIC__
  3612. + move.4 d5, a1 ; ldso _fini funcdesc (see dl-startup.h)
  3613. +#else
  3614. + movei d5, #0 ; rtld_fini (not used)
  3615. +#endif
  3616. +
  3617. + move.4 d6, sp ; Stack End.
  3618. +
  3619. + /* Call the user's main function, and exit with its value. But
  3620. + let the libc call main. */
  3621. +#ifdef __UBICOM32_FDPIC__
  3622. + call a5, __uClibc_main
  3623. +#else
  3624. + moveai a5, #%hi(__uClibc_main)
  3625. + calli a5, %lo(__uClibc_main)(a5)
  3626. +#endif
  3627. +
  3628. + bkpt #-1 ; Crash if somehow `exit' does return.
  3629. --- /dev/null
  3630. +++ b/libc/sysdeps/linux/ubicom32/crti.S
  3631. @@ -0,0 +1,54 @@
  3632. +/* Specialized code needed to support construction and destruction of
  3633. + file-scope objects in C++ and Java code, and to support exception handling.
  3634. + Copyright (C) 1999 Free Software Foundation, Inc.
  3635. + Contributed by Charles-Antoine Gauthier ([email protected]).
  3636. +
  3637. +This file is part of GCC.
  3638. +
  3639. +GCC is free software; you can redistribute it and/or modify
  3640. +it under the terms of the GNU General Public License as published by
  3641. +the Free Software Foundation; either version 2, or (at your option)
  3642. +any later version.
  3643. +
  3644. +GCC is distributed in the hope that it will be useful,
  3645. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  3646. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3647. +GNU General Public License for more details.
  3648. +
  3649. +You should have received a copy of the GNU General Public License
  3650. +along with GCC; see the file COPYING. If not, write to
  3651. +the Free Software Foundation, 59 Temple Place - Suite 330,
  3652. +Boston, MA 02111-1307, USA. */
  3653. +
  3654. +/* As a special exception, if you link this library with files
  3655. + compiled with GCC to produce an executable, this does not cause
  3656. + the resulting executable to be covered by the GNU General Public License.
  3657. + This exception does not however invalidate any other reasons why
  3658. + the executable file might be covered by the GNU General Public License. */
  3659. +
  3660. +/*
  3661. + * This file just supplies function prologues for the .init and .fini
  3662. + * sections. It is linked in before crtbegin.o.
  3663. + */
  3664. + .file "crti.o"
  3665. + .ident "GNU C crti.o"
  3666. +
  3667. + .section .init
  3668. + .align 2
  3669. + .globl _init
  3670. + .type _init, @function
  3671. +_init:
  3672. + move.4 -4(sp)++, a5
  3673. +#ifdef __UBICOM32_FDPIC__
  3674. + move.4 -4(sp)++, a0
  3675. +#endif
  3676. +
  3677. + .section .fini
  3678. + .align 2
  3679. + .globl _fini
  3680. + .type _fini, @function
  3681. +_fini:
  3682. + move.4 -4(sp)++, a5
  3683. +#ifdef __UBICOM32_FDPIC__
  3684. + move.4 -4(sp)++, a0
  3685. +#endif
  3686. --- /dev/null
  3687. +++ b/libc/sysdeps/linux/ubicom32/crtn.S
  3688. @@ -0,0 +1,47 @@
  3689. +/* Specialized code needed to support construction and destruction of
  3690. + file-scope objects in C++ and Java code, and to support exception handling.
  3691. + Copyright (C) 1999 Free Software Foundation, Inc.
  3692. + Contributed by Charles-Antoine Gauthier ([email protected]).
  3693. +
  3694. +This file is part of GCC.
  3695. +
  3696. +GCC is free software; you can redistribute it and/or modify
  3697. +it under the terms of the GNU General Public License as published by
  3698. +the Free Software Foundation; either version 2, or (at your option)
  3699. +any later version.
  3700. +
  3701. +GCC is distributed in the hope that it will be useful,
  3702. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  3703. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3704. +GNU General Public License for more details.
  3705. +
  3706. +You should have received a copy of the GNU General Public License
  3707. +along with GCC; see the file COPYING. If not, write to
  3708. +the Free Software Foundation, 59 Temple Place - Suite 330,
  3709. +Boston, MA 02111-1307, USA. */
  3710. +
  3711. +/* As a special exception, if you link this library with files
  3712. + compiled with GCC to produce an executable, this does not cause
  3713. + the resulting executable to be covered by the GNU General Public License.
  3714. + This exception does not however invalidate any other reasons why
  3715. + the executable file might be covered by the GNU General Public License. */
  3716. +
  3717. +/*
  3718. + * This file supplies function epilogues for the .init and .fini sections.
  3719. + * It is linked in after all other files.
  3720. + */
  3721. +
  3722. + .file "crtn.o"
  3723. + .ident "GNU C crtn.o"
  3724. +
  3725. + .section .init
  3726. +#ifdef __UBICOM32_FDPIC__
  3727. + move.4 a0, (sp)4++
  3728. +#endif
  3729. + ret (sp)4++
  3730. +
  3731. + .section .fini
  3732. +#ifdef __UBICOM32_FDPIC__
  3733. + move.4 a0, (sp)4++
  3734. +#endif
  3735. + ret (sp)4++
  3736. --- /dev/null
  3737. +++ b/libc/sysdeps/linux/ubicom32/crtreloc.c
  3738. @@ -0,0 +1,145 @@
  3739. +/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  3740. + written by Alexandre Oliva <[email protected]>
  3741. +This file is part of the GNU C Library.
  3742. +
  3743. +The GNU C Library is free software; you can redistribute it and/or
  3744. +modify it under the terms of the GNU Lesser General Public License as
  3745. +published by the Free Software Foundation; either version 2.1 of the
  3746. +License, or (at your option) any later version.
  3747. +
  3748. +In addition to the permissions in the GNU Lesser General Public
  3749. +License, the Free Software Foundation gives you unlimited
  3750. +permission to link the compiled version of this file with other
  3751. +programs, and to distribute those programs without any restriction
  3752. +coming from the use of this file. (The GNU Lesser General Public
  3753. +License restrictions do apply in other respects; for example, they
  3754. +cover modification of the file, and distribution when not linked
  3755. +into another program.)
  3756. +
  3757. +The GNU C Library is distributed in the hope that it will be useful,
  3758. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  3759. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3760. +Library General Public License for more details.
  3761. +
  3762. +You should have received a copy of the GNU Lesser General Public
  3763. +License along with the GNU C Library; see the file COPYING.LIB. If
  3764. +not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  3765. +Cambridge, MA 02139, USA. */
  3766. +
  3767. +#ifdef __UBICOM32_FDPIC__
  3768. +
  3769. +#include <sys/types.h>
  3770. +#include <link.h>
  3771. +
  3772. +/* This file is to be compiled into crt object files, to enable
  3773. + executables to easily self-relocate. */
  3774. +
  3775. +union word {
  3776. + char c[4];
  3777. + void *v;
  3778. +};
  3779. +
  3780. +/* Compute the runtime address of pointer in the range [p,e), and then
  3781. + map the pointer pointed by it. */
  3782. +static __always_inline void ***
  3783. +reloc_range_indirect (void ***p, void ***e,
  3784. + const struct elf32_fdpic_loadmap *map)
  3785. +{
  3786. + while (p < e)
  3787. + {
  3788. + if (*p != (void **)-1)
  3789. + {
  3790. + void *ptr = __reloc_pointer (*p, map);
  3791. + if (ptr != (void *)-1)
  3792. + {
  3793. + void *pt;
  3794. + if ((long)ptr & 3)
  3795. + {
  3796. + unsigned char *c = ptr;
  3797. + int i;
  3798. + unsigned long v = 0;
  3799. + for (i = 0; i < 4; i++)
  3800. + v |= c[i] << 8 * i;
  3801. + pt = (void *)v;
  3802. + }
  3803. + else
  3804. + pt = *(void**)ptr;
  3805. + pt = __reloc_pointer (pt, map);
  3806. + if ((long)ptr & 3)
  3807. + {
  3808. + unsigned char *c = ptr;
  3809. + int i;
  3810. + unsigned long v = (unsigned long)pt;
  3811. + for (i = 0; i < 4; i++, v >>= 8)
  3812. + c[i] = v;
  3813. + }
  3814. + else
  3815. + *(void**)ptr = pt;
  3816. + }
  3817. + }
  3818. + p++;
  3819. + }
  3820. + return p;
  3821. +}
  3822. +
  3823. +/* Call __reloc_range_indirect for the given range except for the last
  3824. + entry, whose contents are only relocated. It's expected to hold
  3825. + the GOT value. */
  3826. +void* attribute_hidden
  3827. +__self_reloc (const struct elf32_fdpic_loadmap *map,
  3828. + void ***p, void ***e)
  3829. +{
  3830. + p = reloc_range_indirect (p, e-1, map);
  3831. +
  3832. + if (p >= e)
  3833. + return (void*)-1;
  3834. +
  3835. + return __reloc_pointer (*p, map);
  3836. +}
  3837. +
  3838. +#if 0
  3839. +/* These are other functions that might be useful, but that we don't
  3840. + need. */
  3841. +
  3842. +/* Remap pointers in [p,e). */
  3843. +static __always_inline void**
  3844. +reloc_range (void **p, void **e,
  3845. + const struct elf32_fdpic_loadmap *map)
  3846. +{
  3847. + while (p < e)
  3848. + {
  3849. + *p = __reloc_pointer (*p, map);
  3850. + p++;
  3851. + }
  3852. + return p;
  3853. +}
  3854. +
  3855. +/* Remap p, adjust e by the same offset, then map the pointers in the
  3856. + range determined by them. */
  3857. +void attribute_hidden
  3858. +__reloc_range (const struct elf32_fdpic_loadmap *map,
  3859. + void **p, void **e)
  3860. +{
  3861. + void **old = p;
  3862. +
  3863. + p = __reloc_pointer (p, map);
  3864. + e += p - old;
  3865. + reloc_range (p, e, map);
  3866. +}
  3867. +
  3868. +/* Remap p, adjust e by the same offset, then map pointers referenced
  3869. + by the (unadjusted) pointers in the range. Return the relocated
  3870. + value of the last pointer in the range. */
  3871. +void* attribute_hidden
  3872. +__reloc_range_indirect (const struct elf32_fdpic_loadmap *map,
  3873. + void ***p, void ***e)
  3874. +{
  3875. + void ***old = p;
  3876. +
  3877. + p = __reloc_pointer (p, map);
  3878. + e += p - old;
  3879. + return reloc_range_indirect (p, e, map);
  3880. +}
  3881. +#endif
  3882. +
  3883. +#endif /* __UBICOM32_FDPIC__ */
  3884. --- /dev/null
  3885. +++ b/libc/sysdeps/linux/ubicom32/setjmp.S
  3886. @@ -0,0 +1,72 @@
  3887. +/* Setjmp for Ubicom32 */
  3888. + .text
  3889. + .global _setjmp
  3890. + .type _setjmp,@function
  3891. +_setjmp:
  3892. + movea a3, d0 ; A3 now holds the jmp buf that was passed in.
  3893. + move.4 (a3)4++, d10
  3894. + move.4 (a3)4++, d11
  3895. + move.4 (a3)4++, d12
  3896. + move.4 (a3)4++, d13
  3897. + move.4 (a3)4++, a1
  3898. + move.4 (a3)4++, a2
  3899. + move.4 (a3)4++, a5
  3900. + move.4 (a3)4++, a6
  3901. + move.4 (a3)4++, a7
  3902. + move.4 d0, #0
  3903. +
  3904. + calli a5, 0(a5)
  3905. + .size _setjmp, . - _setjmp
  3906. +
  3907. +/*
  3908. + * __sigsetjmp for Ubicom32
  3909. + * d0 holds sigjmp_buf and d1 holds the savemask. We will save the frame and then just call __sigjmp_save to do the mask save.
  3910. + */
  3911. + .global __sigsetjmp
  3912. + .type __sigsetjmp,@function
  3913. +__sigsetjmp:
  3914. + movea a3, d0 ; A3 now holds the jmp buf that was passed in.
  3915. + move.4 (a3)4++, d10
  3916. + move.4 (a3)4++, d11
  3917. + move.4 (a3)4++, d12
  3918. + move.4 (a3)4++, d13
  3919. + move.4 (a3)4++, a1
  3920. + move.4 (a3)4++, a2
  3921. + move.4 (a3)4++, a5
  3922. + move.4 (a3)4++, a6
  3923. + move.4 (a3)4++, a7
  3924. +
  3925. + ;; The frame has been saved. Call _sigjmp_save to get sigmask saved. a5 still has the return address and it will go back to that.
  3926. +#if defined(__UBICOM32_FDPIC__)
  3927. + call a3, __sigjmp_save
  3928. +#else
  3929. + moveai a3, #%hi(__sigjmp_save)
  3930. + calli a3, %lo(__sigjmp_save)(a3)
  3931. +#endif
  3932. + .size __sigjmp_save, . - __sigjmp_save
  3933. +
  3934. + .global __longjmp
  3935. + .type __longjmp,@function
  3936. +__longjmp:
  3937. + movea a3, d0 ; A3 now holds the jmp buf that was passed in.
  3938. + move.4 d10, (a3)4++
  3939. + move.4 d11, (a3)4++
  3940. + move.4 d12, (a3)4++
  3941. + move.4 d13, (a3)4++
  3942. + move.4 a1 , (a3)4++
  3943. + move.4 a2 , (a3)4++
  3944. + move.4 a5 , (a3)4++
  3945. + move.4 a6 , (a3)4++
  3946. + move.4 a7 , (a3)4++
  3947. +
  3948. + sub.4 #0, #0, d1 ; Test if d1 is zero. If it is we have to return 1 other wise return content of d1
  3949. + jmpeq.t 2f
  3950. + move.4 d0, d1 ; d1 is non zero load it into d0
  3951. + jmpt.t 3f
  3952. +
  3953. +2: move.4 d0, #1
  3954. +3: calli a5, 0(a5)
  3955. + .size __longjmp, . - __longjmp
  3956. + .global __GI___longjmp
  3957. + .hidden __GI___longjmp
  3958. + .set __GI___longjmp,__longjmp
  3959. --- /dev/null
  3960. +++ b/libc/sysdeps/linux/ubicom32/sys/procfs.h
  3961. @@ -0,0 +1,122 @@
  3962. +/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
  3963. + This file is part of the GNU C Library.
  3964. +
  3965. + The GNU C Library is free software; you can redistribute it and/or
  3966. + modify it under the terms of the GNU Lesser General Public
  3967. + License as published by the Free Software Foundation; either
  3968. + version 2.1 of the License, or (at your option) any later version.
  3969. +
  3970. + The GNU C Library is distributed in the hope that it will be useful,
  3971. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3972. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3973. + Lesser General Public License for more details.
  3974. +
  3975. + You should have received a copy of the GNU Lesser General Public
  3976. + License along with the GNU C Library; if not, write to the Free
  3977. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3978. + 02111-1307 USA. */
  3979. +
  3980. +#ifndef _SYS_PROCFS_H
  3981. +#define _SYS_PROCFS_H 1
  3982. +
  3983. +/* This is somehow modelled after the file of the same name on SysVr4
  3984. + systems. It provides a definition of the core file format for ELF
  3985. + used on Linux. */
  3986. +
  3987. +#include <features.h>
  3988. +#include <signal.h>
  3989. +#include <sys/time.h>
  3990. +#include <sys/types.h>
  3991. +#include <sys/ucontext.h>
  3992. +#include <bits/wordsize.h>
  3993. +
  3994. +__BEGIN_DECLS
  3995. +
  3996. +#define ELF_NGREG 38
  3997. +
  3998. +typedef struct
  3999. + {
  4000. + union
  4001. + {
  4002. + unsigned long pr_regs[32];
  4003. + double pr_dregs[16];
  4004. + } pr_fr;
  4005. + unsigned long __unused;
  4006. + unsigned long pr_fsr;
  4007. + unsigned char pr_qcnt;
  4008. + unsigned char pr_q_entrysize;
  4009. + unsigned char pr_en;
  4010. + unsigned int pr_q[64];
  4011. + } elf_fpregset_t;
  4012. +
  4013. +typedef unsigned long elf_greg_t;
  4014. +typedef elf_greg_t elf_gregset_t[ELF_NGREG];
  4015. +
  4016. +struct elf_siginfo
  4017. + {
  4018. + int si_signo; /* Signal number. */
  4019. + int si_code; /* Extra code. */
  4020. + int si_errno; /* Errno. */
  4021. + };
  4022. +
  4023. +/* Definitions to generate Intel SVR4-like core files. These mostly
  4024. + have the same names as the SVR4 types with "elf_" tacked on the
  4025. + front to prevent clashes with linux definitions, and the typedef
  4026. + forms have been avoided. This is mostly like the SVR4 structure,
  4027. + but more Linuxy, with things that Linux does not support and which
  4028. + gdb doesn't really use excluded. Fields present but not used are
  4029. + marked with "XXX". */
  4030. +struct elf_prstatus
  4031. + {
  4032. + struct elf_siginfo pr_info; /* Info associated with signal. */
  4033. + short int pr_cursig; /* Current signal. */
  4034. + unsigned long int pr_sigpend; /* Set of pending signals. */
  4035. + unsigned long int pr_sighold; /* Set of held signals. */
  4036. + __pid_t pr_pid;
  4037. + __pid_t pr_ppid;
  4038. + __pid_t pr_pgrp;
  4039. + __pid_t pr_sid;
  4040. + struct timeval pr_utime; /* User time. */
  4041. + struct timeval pr_stime; /* System time. */
  4042. + struct timeval pr_cutime; /* Cumulative user time. */
  4043. + struct timeval pr_cstime; /* Cumulative system time. */
  4044. + elf_gregset_t pr_reg; /* GP registers. */
  4045. + int pr_fpvalid; /* True if math copro being used. */
  4046. + };
  4047. +
  4048. +
  4049. +#define ELF_PRARGSZ (80) /* Number of chars for args */
  4050. +
  4051. +struct elf_prpsinfo
  4052. + {
  4053. + char pr_state; /* Numeric process state. */
  4054. + char pr_sname; /* Char for pr_state. */
  4055. + char pr_zomb; /* Zombie. */
  4056. + char pr_nice; /* Nice val. */
  4057. + unsigned long int pr_flag; /* Flags. */
  4058. + unsigned short int pr_uid;
  4059. + unsigned short int pr_gid;
  4060. + int pr_pid, pr_ppid, pr_pgrp, pr_sid;
  4061. + /* Lots missing */
  4062. + char pr_fname[16]; /* Filename of executable. */
  4063. + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
  4064. + };
  4065. +
  4066. +/* Addresses. */
  4067. +typedef void *psaddr_t;
  4068. +
  4069. +/* Register sets. Linux has different names. */
  4070. +typedef elf_gregset_t prgregset_t;
  4071. +typedef elf_fpregset_t prfpregset_t;
  4072. +
  4073. +/* We don't have any differences between processes and threads,
  4074. + therefore have only one PID type. */
  4075. +typedef __pid_t lwpid_t;
  4076. +
  4077. +
  4078. +typedef struct elf_prstatus prstatus_t;
  4079. +typedef struct elf_prpsinfo prpsinfo_t;
  4080. +
  4081. +__END_DECLS
  4082. +
  4083. +#endif /* sys/procfs.h */
  4084. --- /dev/null
  4085. +++ b/libc/sysdeps/linux/ubicom32/sys/ucontext.h
  4086. @@ -0,0 +1,104 @@
  4087. +/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
  4088. + This file is part of the GNU C Library.
  4089. +
  4090. + The GNU C Library is free software; you can redistribute it and/or
  4091. + modify it under the terms of the GNU Lesser General Public
  4092. + License as published by the Free Software Foundation; either
  4093. + version 2.1 of the License, or (at your option) any later version.
  4094. +
  4095. + The GNU C Library is distributed in the hope that it will be useful,
  4096. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  4097. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  4098. + Lesser General Public License for more details.
  4099. +
  4100. + You should have received a copy of the GNU Lesser General Public
  4101. + License along with the GNU C Library; if not, write to the Free
  4102. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  4103. + 02111-1307 USA. */
  4104. +
  4105. +#ifndef _SYS_UCONTEXT_H
  4106. +#define _SYS_UCONTEXT_H 1
  4107. +
  4108. +#include <features.h>
  4109. +#include <signal.h>
  4110. +/*
  4111. + * Location of the users' stored registers relative to R0.
  4112. + * Usage is as an index into a gregset_t array or as u.u_ar0[XX].
  4113. + */
  4114. +#define REG_PSR (0)
  4115. +#define REG_PC (1)
  4116. +#define REG_SPARE (2)
  4117. +#define REG_WVALID (3)
  4118. +#define REG_G1 (4)
  4119. +#define REG_G2 (5)
  4120. +#define REG_G3 (6)
  4121. +#define REG_G4 (7)
  4122. +#define REG_G5 (8)
  4123. +#define REG_G6 (9)
  4124. +#define REG_G7 (10)
  4125. +#define REG_O0 (11)
  4126. +#define REG_O1 (12)
  4127. +#define REG_O2 (13)
  4128. +#define REG_O3 (14)
  4129. +#define REG_O4 (15)
  4130. +#define REG_O5 (16)
  4131. +#define REG_O6 (17)
  4132. +#define REG_O7 (18)
  4133. +#define REG_GLOBALS (19)
  4134. +
  4135. +/*
  4136. + * A gregset_t is defined as an array type for compatibility with the reference
  4137. + * source. This is important due to differences in the way the C language
  4138. + * treats arrays and structures as parameters.
  4139. + *
  4140. + * Note that NGREG is really (sizeof (struct regs) / sizeof (greg_t)),
  4141. + * but that the ABI defines it absolutely to be 21 (resp. 19).
  4142. + */
  4143. +
  4144. +#define NGREG 20
  4145. +typedef int greg_t;
  4146. +
  4147. +typedef greg_t gregset_t[NGREG];
  4148. +
  4149. +/*
  4150. + * The following structures define how a register window can appear on the
  4151. + * stack. This structure is available (when required) through the `gwins'
  4152. + * field of an mcontext (nested within ucontext). NIOS_MAXWINDOW is the
  4153. + * maximum number of outstanding register windows defined in the NIOS
  4154. + * architecture (*not* implementation).
  4155. + */
  4156. +#define NIOS_MAXREGWINDOW 31 /* max windows in NIOS arch. */
  4157. +struct rwindow
  4158. + {
  4159. + greg_t rw_local[8]; /* locals */
  4160. + greg_t rw_in[8]; /* ins */
  4161. + };
  4162. +
  4163. +#define rw_fp rw_in[6] /* frame pointer */
  4164. +#define rw_rtn rw_in[7] /* return address */
  4165. +
  4166. +typedef struct gwindows
  4167. + {
  4168. + int wbcnt;
  4169. + int *spbuf[NIOS_MAXREGWINDOW];
  4170. + struct rwindow wbuf[NIOS_MAXREGWINDOW];
  4171. + } gwindows_t;
  4172. +
  4173. +typedef struct
  4174. + {
  4175. + gregset_t gregs; /* general register set */
  4176. + gwindows_t *gwins; /* POSSIBLE pointer to register windows */
  4177. + } mcontext_t;
  4178. +
  4179. +
  4180. +/* Userlevel context. */
  4181. +typedef struct ucontext
  4182. + {
  4183. + unsigned long uc_flags;
  4184. + struct ucontext *uc_link;
  4185. + __sigset_t uc_sigmask;
  4186. + stack_t uc_stack;
  4187. + mcontext_t uc_mcontext;
  4188. + } ucontext_t;
  4189. +
  4190. +#endif /* sys/ucontext.h */
  4191. --- /dev/null
  4192. +++ b/libc/sysdeps/linux/ubicom32/syscall.c
  4193. @@ -0,0 +1,32 @@
  4194. +/* vi: set sw=4 ts=4: */
  4195. +/* syscall for ubicom32/uClibc
  4196. + *
  4197. + * Copyright (C) 2008 by Ubicom Inc.
  4198. + * Copyright (C) 2002 by Erik Andersen <[email protected]>
  4199. + *
  4200. + * This program is free software; you can redistribute it and/or modify it
  4201. + * under the terms of the GNU Library General Public License as published by
  4202. + * the Free Software Foundation; either version 2 of the License, or (at your
  4203. + * option) any later version.
  4204. + *
  4205. + * This program is distributed in the hope that it will be useful, but WITHOUT
  4206. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4207. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  4208. + * for more details.
  4209. + *
  4210. + * You should have received a copy of the GNU Library General Public License
  4211. + * along with this program; if not, write to the Free Software Foundation,
  4212. + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4213. + */
  4214. +
  4215. +#include <features.h>
  4216. +#include <errno.h>
  4217. +#include <sys/types.h>
  4218. +#include <sys/syscall.h>
  4219. +
  4220. +extern long syscall(long sysnum, long a, long b, long c, long d, long e, long f);
  4221. +long syscall(long sysnum, long a, long b, long c, long d, long e, long f)
  4222. +{
  4223. + int __NR_syscall_number = sysnum;
  4224. + return (long) INLINE_SYSCALL(syscall_number, 6, a, b, c, d, e, f);
  4225. +}
  4226. --- /dev/null
  4227. +++ b/libc/sysdeps/linux/ubicom32/vfork.S
  4228. @@ -0,0 +1,35 @@
  4229. +#include <sys/syscall.h>
  4230. +
  4231. + .text
  4232. + .type vfork,@function
  4233. + .global vfork
  4234. +vfork:
  4235. + move.4 -4(sp)++, a5 ; Save return address on the stack.
  4236. + movei d8, #__NR_vfork
  4237. + moveai a3, #%hi(0x40400000)
  4238. + calli a5, 0x10(a3)
  4239. +
  4240. + /*
  4241. + * You get here only if the syscall bombed. If things had worked out the
  4242. + * parent and child would have both returned to the instruction after
  4243. + * the vfork call.
  4244. + */
  4245. + move.4 a5, (sp)4++ ; Pop the return address off the stack.
  4246. + movei d1, #-125
  4247. + sub.4 #0, d0, d1
  4248. + jmplt.t 1f
  4249. +
  4250. + ;; We have an error.
  4251. + sub.4 d0, #0, d0 ; d0 = -res. Call __set_errno with that.
  4252. +#if defined(__UBICOM32_FDPIC__)
  4253. + call a3, __syscall_error
  4254. +#else
  4255. + moveai a3, #%hi(__syscall_error)
  4256. + calli a3, %lo(__syscall_error)(a3) ; __syscall_error will return -1 and not come back here.
  4257. +#endif
  4258. +1:
  4259. + calli a5, 0(a5)
  4260. + .size vfork, . - vfork
  4261. + .global __GI_vfork
  4262. + .hidden __GI_vfork
  4263. + .set __GI_vfork,vfork
  4264. --- a/libpthread/linuxthreads.old/pthread.c
  4265. +++ b/libpthread/linuxthreads.old/pthread.c
  4266. @@ -393,6 +393,10 @@ void __pthread_initialize_minimal(void)
  4267. #endif
  4268. __libc_multiple_threads_ptr = __libc_pthread_init (ptr_pthread_functions);
  4269. +#ifndef __ARCH_USE_MMU__
  4270. + __pthread_initial_thread_tos =
  4271. + (char *)(((long)CURRENT_STACK_FRAME + getpagesize()) & ~(getpagesize() - 1));
  4272. +#endif /* __ARCH_USE_MMU__ */
  4273. }
  4274. @@ -461,8 +465,11 @@ static void pthread_initialize(void)
  4275. * __pthread_initial_thread_bos at address 0. These bounds are refined as we
  4276. * malloc other stack frames such that they don't overlap. -StS
  4277. */
  4278. - __pthread_initial_thread_tos =
  4279. - (char *)(((long)CURRENT_STACK_FRAME + getpagesize()) & ~(getpagesize() - 1));
  4280. + if (__pthread_initial_thread_tos == NULL) {
  4281. + __pthread_initial_thread_tos =
  4282. + (char *)(((long)CURRENT_STACK_FRAME + getpagesize()) & ~(getpagesize() - 1));
  4283. + }
  4284. +
  4285. __pthread_initial_thread_bos = (char *) 1; /* set it non-zero so we know we have been here */
  4286. PDEBUG("initial thread stack bounds: bos=%p, tos=%p\n",
  4287. __pthread_initial_thread_bos, __pthread_initial_thread_tos);
  4288. --- /dev/null
  4289. +++ b/libpthread/linuxthreads.old/sysdeps/ubicom32/pt-machine.h
  4290. @@ -0,0 +1,68 @@
  4291. +/* Machine-dependent pthreads configuration and inline functions.
  4292. +
  4293. + Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004
  4294. + Free Software Foundation, Inc.
  4295. + This file is part of the GNU C Library.
  4296. + Contributed by Ralf Baechle <[email protected]>.
  4297. + Based on the Alpha version by Richard Henderson <[email protected]>.
  4298. +
  4299. + The GNU C Library is free software; you can redistribute it and/or
  4300. + modify it under the terms of the GNU Lesser General Public License as
  4301. + published by the Free Software Foundation; either version 2.1 of the
  4302. + License, or (at your option) any later version.
  4303. +
  4304. + The GNU C Library is distributed in the hope that it will be useful,
  4305. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  4306. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  4307. + Lesser General Public License for more details.
  4308. +
  4309. + You should have received a copy of the GNU Lesser General Public
  4310. + License along with the GNU C Library; see the file COPYING.LIB. If
  4311. + not, write to the Free Software Foundation, Inc.,
  4312. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  4313. +
  4314. +#ifndef _PT_MACHINE_H
  4315. +#define _PT_MACHINE_H 1
  4316. +
  4317. +#include <features.h>
  4318. +
  4319. +/*
  4320. + * XXX try to make this inline
  4321. + */
  4322. +extern long int testandset (int *spinlock);
  4323. +
  4324. +#ifndef PT_EI
  4325. +#define PT_EI
  4326. +#else
  4327. +/* Spinlock implementation; required. */
  4328. +
  4329. +/*
  4330. + * testandset() is the basis for the pthread spin lock.
  4331. + *
  4332. + * This implementation only requires that we 'set' the state of *spinlock. As
  4333. + * bset is allows us to atomically 'testandset' a single bit define our 'set' is
  4334. + * such that we will set bit 0 (ignoring all other bits, which should also be
  4335. + * zero).
  4336. + * Return value of 1 implies that the bit was already set and is still
  4337. + * set.
  4338. + * Return value of 0 implies that the bit was not previously set but it
  4339. + * now is.
  4340. + */
  4341. +long int
  4342. +testandset (int *spinlock)
  4343. +{
  4344. + int ret;
  4345. + __asm__ volatile (
  4346. + " move.4 %0, #0 \n\t" /* Assume that the bit is not currently set */
  4347. + " bset %1, %1, #0 \n\t" /* Attempt to 'set' bit 0 */
  4348. + " jmpeq.t 1f \n\t"
  4349. + " move.4 %0, #1 \n\t" /* Bit was already set, so return 1 */
  4350. + " 1: \n\t"
  4351. + : "=r"(ret), "+U4"(*spinlock)
  4352. + :
  4353. + : "memory", "cc"
  4354. + );
  4355. + return ret;
  4356. +}
  4357. +#endif
  4358. +#endif /* pt-machine.h */
  4359. --- /dev/null
  4360. +++ b/libpthread/linuxthreads.old/sysdeps/ubicom32/tls.h
  4361. @@ -0,0 +1,26 @@
  4362. +/* Definitions for thread-local data handling. linuxthreads/MIPS version.
  4363. + Copyright (C) 2005 Free Software Foundation, Inc.
  4364. + This file is part of the GNU C Library.
  4365. +
  4366. + The GNU C Library is free software; you can redistribute it and/or
  4367. + modify it under the terms of the GNU Lesser General Public
  4368. + License as published by the Free Software Foundation; either
  4369. + version 2.1 of the License, or (at your option) any later version.
  4370. +
  4371. + The GNU C Library is distributed in the hope that it will be useful,
  4372. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  4373. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  4374. + Lesser General Public License for more details.
  4375. +
  4376. + You should have received a copy of the GNU Lesser General Public
  4377. + License along with the GNU C Library; if not, write to the Free
  4378. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  4379. + 02111-1307 USA. */
  4380. +
  4381. +#ifndef _TLS_H
  4382. +#define _TLS_H
  4383. +#ifdef HAVE_TLS_SUPPORT
  4384. +#warning no tls support
  4385. +#undef USE_TLS
  4386. +#endif
  4387. +#endif /* tls.h */