600-ubicom32-uClibc.patch 135 KB

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