uClibc-0.9.29-avr32.patch 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579
  1. diff --git a/.gitignore b/.gitignore
  2. new file mode 100644
  3. index 0000000..f474699
  4. --- /dev/null
  5. +++ b/.gitignore
  6. @@ -0,0 +1,63 @@
  7. +#
  8. +# NOTE! Don't add files that are generated in specific
  9. +# subdirectories here. Add them in the ".gitignore" file
  10. +# in that subdirectory instead.
  11. +#
  12. +# Normal rules
  13. +#
  14. +.*
  15. +*.o
  16. +*.a
  17. +*.so
  18. +*.os
  19. +*.oS
  20. +.config*
  21. +
  22. +#
  23. +# Top-level generic files
  24. +#
  25. +obj.*
  26. +
  27. +#
  28. +# Generated files
  29. +#
  30. +extra/config/conf
  31. +extra/config/lex.zconf.c
  32. +extra/config/lkc_defs.h
  33. +extra/config/mconf
  34. +extra/config/zconf.hash.c
  35. +extra/config/zconf.tab.c
  36. +extra/config/zconf.tab.h
  37. +
  38. +lib
  39. +
  40. +include/asm
  41. +include/asm-*
  42. +include/bits
  43. +include/linux
  44. +
  45. +include/sys/acct.h
  46. +include/sys/elf.h
  47. +include/sys/epoll.h
  48. +include/sys/inotify.h
  49. +include/sys/io.h
  50. +include/sys/prctl.h
  51. +include/sys/procfs.h
  52. +include/sys/ptrace.h
  53. +include/sys/ucontext.h
  54. +include/sys/user.h
  55. +
  56. +include/dl-osinfo.h
  57. +include/fpu_control.h
  58. +include/hp-timing.h
  59. +include/pthread.h
  60. +include/semaphore.h
  61. +include/thread_db.h
  62. +
  63. +ldso/include/dl-debug.h
  64. +ldso/include/dl-startup.h
  65. +ldso/include/dl-syscalls.h
  66. +ldso/include/dl-sysdep.h
  67. +ldso/include/elf.h
  68. +
  69. +libc/misc/internals/interp.c
  70. diff --git a/Rules.mak b/Rules.mak
  71. index d054bbb..55381cf 100644
  72. --- a/Rules.mak
  73. +++ b/Rules.mak
  74. @@ -313,6 +313,12 @@ ifeq ($(TARGET_ARCH),frv)
  75. UCLIBC_LDSO=ld.so.1
  76. endif
  77. +ifeq ($(strip $(TARGET_ARCH)),avr32)
  78. + CPU_CFLAGS-$(CONFIG_AVR32_AP7) += -march=ap
  79. + CPU_CFLAGS-$(CONFIG_LINKRELAX) += -mrelax
  80. + CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
  81. +endif
  82. +
  83. # Keep the check_gcc from being needlessly executed
  84. ifndef PIEFLAG
  85. ifneq ($(UCLIBC_BUILD_PIE),y)
  86. diff --git a/extra/Configs/Config.avr32 b/extra/Configs/Config.avr32
  87. new file mode 100644
  88. index 0000000..8d70e6e
  89. --- /dev/null
  90. +++ b/extra/Configs/Config.avr32
  91. @@ -0,0 +1,31 @@
  92. +#
  93. +# For a description of the syntax of this configuration file,
  94. +# see extra/config/Kconfig-language.txt
  95. +#
  96. +
  97. +config TARGET_ARCH
  98. + string
  99. + default "avr32"
  100. +
  101. +config FORCE_OPTIONS_FOR_ARCH
  102. + bool
  103. + default y
  104. + select ARCH_BIG_ENDIAN
  105. + select FORCE_SHAREABLE_TEXT_SEGMENTS
  106. +
  107. +config ARCH_CFLAGS
  108. + string
  109. +
  110. +choice
  111. + prompt "Target CPU Type"
  112. + default CONFIG_AVR32_AP7
  113. +
  114. +config CONFIG_AVR32_AP7
  115. + bool "AVR32 AP7"
  116. + select ARCH_HAS_MMU
  117. +
  118. +endchoice
  119. +
  120. +config LINKRELAX
  121. + bool "Enable linker optimizations"
  122. + default y
  123. diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
  124. index 8eab394..10c9f7b 100644
  125. --- a/extra/Configs/Config.in
  126. +++ b/extra/Configs/Config.in
  127. @@ -16,6 +16,9 @@ config TARGET_alpha
  128. config TARGET_arm
  129. bool "arm"
  130. +config TARGET_avr32
  131. + bool "avr32"
  132. +
  133. config TARGET_bfin
  134. bool "bfin"
  135. @@ -92,6 +95,10 @@ if TARGET_arm
  136. source "extra/Configs/Config.arm"
  137. endif
  138. +if TARGET_avr32
  139. +source "extra/Configs/Config.avr32"
  140. +endif
  141. +
  142. if TARGET_bfin
  143. source "extra/Configs/Config.bfin"
  144. endif
  145. diff --git a/extra/Configs/defconfigs/avr32 b/extra/Configs/defconfigs/avr32
  146. new file mode 100644
  147. index 0000000..0b890a2
  148. --- /dev/null
  149. +++ b/extra/Configs/defconfigs/avr32
  150. @@ -0,0 +1 @@
  151. +TARGET_avr32=y
  152. diff --git a/include/elf.h b/include/elf.h
  153. index 19805d7..ab90160 100644
  154. --- a/include/elf.h
  155. +++ b/include/elf.h
  156. @@ -354,6 +354,8 @@ typedef struct
  157. /* NIOS magic number - no EABI available. */
  158. #define EM_NIOS32 0xFEBB
  159. +#define EM_AVR32 0x18ad
  160. +
  161. /* V850 backend magic number. Written in the absense of an ABI. */
  162. #define EM_CYGNUS_V850 0x9080
  163. @@ -2828,6 +2830,55 @@ typedef Elf32_Addr Elf32_Conflict;
  164. /* Keep this the last entry. */
  165. #define R_V850_NUM 25
  166. +/* Atmel AVR32 relocations. */
  167. +#define R_AVR32_NONE 0
  168. +#define R_AVR32_32 1
  169. +#define R_AVR32_16 2
  170. +#define R_AVR32_8 3
  171. +#define R_AVR32_32_PCREL 4
  172. +#define R_AVR32_16_PCREL 5
  173. +#define R_AVR32_8_PCREL 6
  174. +#define R_AVR32_DIFF32 7
  175. +#define R_AVR32_DIFF16 8
  176. +#define R_AVR32_DIFF8 9
  177. +#define R_AVR32_GOT32 10
  178. +#define R_AVR32_GOT16 11
  179. +#define R_AVR32_GOT8 12
  180. +#define R_AVR32_21S 13
  181. +#define R_AVR32_16U 14
  182. +#define R_AVR32_16S 15
  183. +#define R_AVR32_8S 16
  184. +#define R_AVR32_8S_EXT 17
  185. +#define R_AVR32_22H_PCREL 18
  186. +#define R_AVR32_18W_PCREL 19
  187. +#define R_AVR32_16B_PCREL 20
  188. +#define R_AVR32_16N_PCREL 21
  189. +#define R_AVR32_14UW_PCREL 22
  190. +#define R_AVR32_11H_PCREL 23
  191. +#define R_AVR32_10UW_PCREL 24
  192. +#define R_AVR32_9H_PCREL 25
  193. +#define R_AVR32_9UW_PCREL 26
  194. +#define R_AVR32_HI16 27
  195. +#define R_AVR32_LO16 28
  196. +#define R_AVR32_GOTPC 29
  197. +#define R_AVR32_GOTCALL 30
  198. +#define R_AVR32_LDA_GOT 31
  199. +#define R_AVR32_GOT21S 32
  200. +#define R_AVR32_GOT18SW 33
  201. +#define R_AVR32_GOT16S 34
  202. +#define R_AVR32_GOT7UW 35
  203. +#define R_AVR32_32_CPENT 36
  204. +#define R_AVR32_CPCALL 37
  205. +#define R_AVR32_16_CP 38
  206. +#define R_AVR32_9W_CP 39
  207. +#define R_AVR32_RELATIVE 40
  208. +#define R_AVR32_GLOB_DAT 41
  209. +#define R_AVR32_JMP_SLOT 42
  210. +#define R_AVR32_ALIGN 43
  211. +#define R_AVR32_NUM 44
  212. +
  213. +/* AVR32 dynamic tags */
  214. +#define DT_AVR32_GOTSZ 0x70000001 /* Total size of GOT in bytes */
  215. /* Renesas H8/300 Relocations */
  216. #define R_H8_NONE 0
  217. diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h
  218. index 32c5bf8..eb43bd9 100644
  219. --- a/ldso/include/dl-string.h
  220. +++ b/ldso/include/dl-string.h
  221. @@ -285,7 +285,8 @@ static __always_inline char * _dl_simple_ltoahex(char * local, unsigned long i)
  222. /* On some arches constant strings are referenced through the GOT.
  223. * This requires that load_addr must already be defined... */
  224. #if defined(mc68000) || defined(__arm__) || defined(__thumb__) || \
  225. - defined(__mips__) || defined(__sh__) || defined(__powerpc__)
  226. + defined(__mips__) || defined(__sh__) || defined(__powerpc__) || \
  227. + defined(__avr32__)
  228. # define CONSTANT_STRING_GOT_FIXUP(X) \
  229. if ((X) < (const char *) load_addr) (X) += load_addr
  230. # define NO_EARLY_SEND_STDERR
  231. diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h
  232. index b42416a..4404219 100644
  233. --- a/ldso/include/dl-syscall.h
  234. +++ b/ldso/include/dl-syscall.h
  235. @@ -55,69 +55,69 @@
  236. dynamic linking at all, so we cannot return any error codes.
  237. We just punt if there is an error. */
  238. #define __NR__dl_exit __NR_exit
  239. -static inline _syscall1(void, _dl_exit, int, status);
  240. +static __always_inline _syscall1(void, _dl_exit, int, status);
  241. #define __NR__dl_close __NR_close
  242. -static inline _syscall1(int, _dl_close, int, fd);
  243. +static __always_inline _syscall1(int, _dl_close, int, fd);
  244. #define __NR__dl_open __NR_open
  245. -static inline _syscall3(int, _dl_open, const char *, fn, int, flags,
  246. +static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
  247. __kernel_mode_t, mode);
  248. #define __NR__dl_write __NR_write
  249. -static inline _syscall3(unsigned long, _dl_write, int, fd,
  250. +static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
  251. const void *, buf, unsigned long, count);
  252. #define __NR__dl_read __NR_read
  253. -static inline _syscall3(unsigned long, _dl_read, int, fd,
  254. +static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
  255. const void *, buf, unsigned long, count);
  256. #define __NR__dl_mprotect __NR_mprotect
  257. -static inline _syscall3(int, _dl_mprotect, const void *, addr,
  258. +static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
  259. unsigned long, len, int, prot);
  260. #define __NR__dl_stat __NR_stat
  261. -static inline _syscall2(int, _dl_stat, const char *, file_name,
  262. +static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
  263. struct stat *, buf);
  264. #define __NR__dl_fstat __NR_fstat
  265. -static inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
  266. +static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
  267. #define __NR__dl_munmap __NR_munmap
  268. -static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
  269. +static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
  270. #ifdef __NR_getxuid
  271. # define __NR_getuid __NR_getxuid
  272. #endif
  273. #define __NR__dl_getuid __NR_getuid
  274. -static inline _syscall0(uid_t, _dl_getuid);
  275. +static __always_inline _syscall0(uid_t, _dl_getuid);
  276. #ifndef __NR_geteuid
  277. # define __NR_geteuid __NR_getuid
  278. #endif
  279. #define __NR__dl_geteuid __NR_geteuid
  280. -static inline _syscall0(uid_t, _dl_geteuid);
  281. +static __always_inline _syscall0(uid_t, _dl_geteuid);
  282. #ifdef __NR_getxgid
  283. # define __NR_getgid __NR_getxgid
  284. #endif
  285. #define __NR__dl_getgid __NR_getgid
  286. -static inline _syscall0(gid_t, _dl_getgid);
  287. +static __always_inline _syscall0(gid_t, _dl_getgid);
  288. #ifndef __NR_getegid
  289. # define __NR_getegid __NR_getgid
  290. #endif
  291. #define __NR__dl_getegid __NR_getegid
  292. -static inline _syscall0(gid_t, _dl_getegid);
  293. +static __always_inline _syscall0(gid_t, _dl_getegid);
  294. #ifdef __NR_getxpid
  295. # define __NR_getpid __NR_getxpid
  296. #endif
  297. #define __NR__dl_getpid __NR_getpid
  298. -static inline _syscall0(gid_t, _dl_getpid);
  299. +static __always_inline _syscall0(gid_t, _dl_getpid);
  300. #define __NR__dl_readlink __NR_readlink
  301. -static inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
  302. +static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
  303. size_t, bufsiz);
  304. #ifdef __UCLIBC_HAS_SSP__
  305. @@ -146,14 +146,14 @@ static inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
  306. #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
  307. # define __NR__dl_mmap __NR_mmap
  308. -static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
  309. +static __always_inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
  310. int, prot, int, flags, int, fd, off_t, offset);
  311. /* then try mmap2() */
  312. #elif defined(__NR_mmap2)
  313. # define __NR___syscall_mmap2 __NR_mmap2
  314. -static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
  315. +static __always_inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
  316. int, prot, int, flags, int, fd, off_t, offset);
  317. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  318. @@ -164,7 +164,7 @@ static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
  319. # define MMAP2_PAGE_SHIFT 12
  320. #endif
  321. -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
  322. +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
  323. int flags, int fd, unsigned long offset)
  324. {
  325. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
  326. @@ -177,8 +177,8 @@ static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
  327. #elif defined(__NR_mmap)
  328. # define __NR__dl_mmap_real __NR_mmap
  329. -static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
  330. -static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
  331. +static __always_inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
  332. +static __always_inline void * _dl_mmap(void * addr, unsigned long size, int prot,
  333. int flags, int fd, unsigned long offset)
  334. {
  335. unsigned long buffer[6];
  336. diff --git a/ldso/ldso/avr32/dl-debug.h b/ldso/ldso/avr32/dl-debug.h
  337. new file mode 100644
  338. index 0000000..fe35539
  339. --- /dev/null
  340. +++ b/ldso/ldso/avr32/dl-debug.h
  341. @@ -0,0 +1,45 @@
  342. +/*
  343. + * AVR32 ELF shared libary loader support
  344. + *
  345. + * Copyright (C) 2005-2007 Atmel Corporation
  346. + * All rights reserved.
  347. + *
  348. + * Redistribution and use in source and binary forms, with or without
  349. + * modification, are permitted provided that the following conditions
  350. + * are met:
  351. + * 1. Redistributions of source code must retain the above copyright
  352. + * notice, this list of conditions and the following disclaimer.
  353. + * 2. The name of the above contributors may not be
  354. + * used to endorse or promote products derived from this software
  355. + * without specific prior written permission.
  356. + *
  357. + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  358. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  359. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  360. + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  361. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  362. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  363. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  364. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  365. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  366. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  367. + * SUCH DAMAGE.
  368. + */
  369. +
  370. +static const char *_dl_reltypes_tab[] = {
  371. + "R_AVR32_NONE",
  372. + "R_AVR32_32", "R_AVR32_16", "R_AVR32_8",
  373. + "R_AVR32_32_PCREL", "R_AVR32_16_PCREL", "R_AVR32_8_PCREL",
  374. + "R_AVR32_DIFF32", "R_AVR32_DIFF16", "R_AVR32_DIFF8",
  375. + "R_AVR32_GOT32", "R_AVR32_GOT16", "R_AVR32_GOT8",
  376. + "R_AVR32_21S", "R_AVR32_16U", "R_AVR32_16S", "R_AVR32_8S", "R_AVR32_8S_EXT",
  377. + "R_AVR32_22H_PCREL", "R_AVR32_18W_PCREL", "R_AVR32_16B_PCREL",
  378. + "R_AVR32_16N_PCREL", "R_AVR32_14UW_PCREL", "R_AVR32_11H_PCREL",
  379. + "R_AVR32_10UW_PCREL", "R_AVR32_9H_PCREL", "R_AVR32_9UW_PCREL",
  380. + "R_AVR32_HI16", "R_AVR32_LO16",
  381. + "R_AVR32_GOTPC", "R_AVR32_GOTCALL", "R_AVR32_LDA_GOT",
  382. + "R_AVR32_GOT21S", "R_AVR32_GOT18SW", "R_AVR32_GOT16S", "R_AVR32_GOT7UW",
  383. + "R_AVR32_32_CPENT", "R_AVR32_CPCALL", "R_AVR32_16_CP", "R_AVR32_9W_CP",
  384. + "R_AVR32_RELATIVE", "R_AVR32_GLOB_DAT", "R_AVR32_JMP_SLOT",
  385. + "R_AVR32_ALIGN",
  386. +};
  387. diff --git a/ldso/ldso/avr32/dl-startup.h b/ldso/ldso/avr32/dl-startup.h
  388. new file mode 100644
  389. index 0000000..3b9a641
  390. --- /dev/null
  391. +++ b/ldso/ldso/avr32/dl-startup.h
  392. @@ -0,0 +1,112 @@
  393. +/*
  394. + * Architecture specific code used by dl-startup.c
  395. + *
  396. + * Copyright (C) 2005-2007 Atmel Corporation
  397. + *
  398. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  399. + */
  400. +
  401. +/* This is the library loader's main entry point. Let _dl_boot2 do its
  402. + * initializations and jump to the application's entry point
  403. + * afterwards. */
  404. +asm( " .text\n"
  405. + " .global _start\n"
  406. + " .type _start,@function\n"
  407. + "_start:\n"
  408. + /* All arguments are on the stack initially */
  409. + " mov r12, sp\n"
  410. + " rcall _dl_start\n"
  411. + /* Returns user entry point in r12. Save it. */
  412. + " mov r0, r12\n"
  413. + /* We're PIC, so get the Global Offset Table */
  414. + " lddpc r6, .L_GOT\n"
  415. + ".L_RGOT:\n"
  416. + " rsub r6, pc\n"
  417. + /* Adjust argc and argv according to _dl_skip_args */
  418. + " ld.w r1, r6[_dl_skip_args@got]\n"
  419. + " ld.w r1, r1[0]\n"
  420. + " ld.w r2, sp++\n"
  421. + " sub r2, r1\n"
  422. + " add sp, sp, r1 << 2\n"
  423. + " st.w --sp, r2\n"
  424. + /* Load the finalizer function */
  425. + " ld.w r12, r6[_dl_fini@got]\n"
  426. + /* Jump to the user's entry point */
  427. + " mov pc, r0\n\n"
  428. +
  429. + " .align 2\n"
  430. + ".L_GOT:"
  431. + " .long .L_RGOT - _GLOBAL_OFFSET_TABLE_\n"
  432. + " .size _start, . - _start\n"
  433. + " .previous\n");
  434. +
  435. +/* Get a pointer to the argv array. On many platforms this can be just
  436. + * the address if the first argument, on other platforms we need to
  437. + * do something a little more subtle here. */
  438. +#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *)ARGS + 1)
  439. +
  440. +
  441. +/* We can't call functions before the GOT has been initialized */
  442. +#define NO_FUNCS_BEFORE_BOOTSTRAP
  443. +
  444. +/*
  445. + * Relocate the GOT during dynamic loader bootstrap. This will add
  446. + * the load address to all entries in the GOT, which is necessary
  447. + * because the linker doesn't generate R_AVR32_RELATIVE relocs for the
  448. + * GOT.
  449. + */
  450. +static __always_inline
  451. +void PERFORM_BOOTSTRAP_GOT(struct elf_resolve *tpnt)
  452. +{
  453. + Elf32_Addr i, nr_got;
  454. + register Elf32_Addr *__r6 __asm__("r6");
  455. + Elf32_Addr *got = __r6;
  456. +
  457. + nr_got = tpnt->dynamic_info[DT_AVR32_GOTSZ_IDX] / sizeof(*got);
  458. + for (i = 2; i < nr_got; i++)
  459. + got[i] += tpnt->loadaddr;
  460. +}
  461. +
  462. +#define PERFORM_BOOTSTRAP_GOT(tpnt) PERFORM_BOOTSTRAP_GOT(tpnt)
  463. +
  464. +/* Handle relocation of the symbols in the dynamic loader. */
  465. +static __always_inline
  466. +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
  467. + unsigned long symbol_addr,
  468. + unsigned long load_addr, Elf32_Sym *symtab)
  469. +{
  470. + switch(ELF32_R_TYPE(rpnt->r_info)) {
  471. + case R_AVR32_NONE:
  472. + break;
  473. + case R_AVR32_GLOB_DAT:
  474. + case R_AVR32_JMP_SLOT:
  475. + *reloc_addr = symbol_addr;
  476. + break;
  477. + case R_AVR32_RELATIVE:
  478. + SEND_STDERR_DEBUG("Applying RELATIVE relocation: ");
  479. + SEND_ADDRESS_STDERR_DEBUG(load_addr, 0);
  480. + SEND_STDERR_DEBUG(" + ");
  481. + SEND_ADDRESS_STDERR_DEBUG(rpnt->r_addend, 1);
  482. + *reloc_addr = load_addr + rpnt->r_addend;
  483. + break;
  484. + default:
  485. + SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc_type ");
  486. + SEND_NUMBER_STDERR(ELF32_R_TYPE(rpnt->r_info), 1);
  487. + SEND_STDERR("REL, SYMBOL, LOAD: ");
  488. + SEND_ADDRESS_STDERR(reloc_addr, 0);
  489. + SEND_STDERR(", ");
  490. + SEND_ADDRESS_STDERR(symbol_addr, 0);
  491. + SEND_STDERR(", ");
  492. + SEND_ADDRESS_STDERR(load_addr, 1);
  493. + _dl_exit(1);
  494. + }
  495. +}
  496. +
  497. +/* Transfer control to the user's application, once the dynamic loader
  498. + * is done. This routine has to exit the current function, then call
  499. + * the _dl_elf_main function.
  500. + *
  501. + * Since our _dl_boot will simply call whatever is returned by
  502. + * _dl_boot2, we can just return the address we're supposed to
  503. + * call. */
  504. +#define START() return _dl_elf_main;
  505. diff --git a/ldso/ldso/avr32/dl-syscalls.h b/ldso/ldso/avr32/dl-syscalls.h
  506. new file mode 100644
  507. index 0000000..996bb87
  508. --- /dev/null
  509. +++ b/ldso/ldso/avr32/dl-syscalls.h
  510. @@ -0,0 +1,6 @@
  511. +/* We can't use the real errno in ldso, since it has not yet
  512. + * been dynamicly linked in yet. */
  513. +#include "sys/syscall.h"
  514. +extern int _dl_errno;
  515. +#undef __set_errno
  516. +#define __set_errno(X) {(_dl_errno) = (X);}
  517. diff --git a/ldso/ldso/avr32/dl-sysdep.h b/ldso/ldso/avr32/dl-sysdep.h
  518. new file mode 100644
  519. index 0000000..1a30172
  520. --- /dev/null
  521. +++ b/ldso/ldso/avr32/dl-sysdep.h
  522. @@ -0,0 +1,105 @@
  523. +/*
  524. + * Various assembly language/system dependent hacks that are required
  525. + * so that we can minimize the amount of platform specific code.
  526. + *
  527. + * Copyright (C) 2004-2007 Atmel Corporation
  528. + *
  529. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  530. + */
  531. +
  532. +/* Define this if the system uses RELOCA. */
  533. +#define ELF_USES_RELOCA
  534. +
  535. +#include <elf.h>
  536. +
  537. +#define ARCH_NUM 1
  538. +#define DT_AVR32_GOTSZ_IDX (DT_NUM + OS_NUM)
  539. +
  540. +#define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \
  541. + do { \
  542. + if (dpnt->d_tag == DT_AVR32_GOTSZ) \
  543. + dynamic[DT_AVR32_GOTSZ_IDX] = dpnt->d_un.d_val; \
  544. + } while (0)
  545. +
  546. +/* Initialization sequence for the application/library GOT. */
  547. +#define INIT_GOT(GOT_BASE,MODULE) \
  548. + do { \
  549. + unsigned long i, nr_got; \
  550. + \
  551. + GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \
  552. + GOT_BASE[1] = (unsigned long) MODULE; \
  553. + \
  554. + /* Add load address displacement to all GOT entries */ \
  555. + nr_got = MODULE->dynamic_info[DT_AVR32_GOTSZ_IDX] / 4; \
  556. + for (i = 2; i < nr_got; i++) \
  557. + GOT_BASE[i] += (unsigned long)MODULE->loadaddr; \
  558. + } while (0)
  559. +
  560. +#define do_rem(result, n, base) ((result) = (n) % (base))
  561. +
  562. +/* Here we define the magic numbers that this dynamic loader should accept */
  563. +#define MAGIC1 EM_AVR32
  564. +#undef MAGIC2
  565. +
  566. +/* Used for error messages */
  567. +#define ELF_TARGET "AVR32"
  568. +
  569. +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got);
  570. +
  571. +/* 4096 bytes alignment */
  572. +#define PAGE_ALIGN 0xfffff000
  573. +#define ADDR_ALIGN 0xfff
  574. +#define OFFS_ALIGN 0x7ffff000
  575. +
  576. +#define elf_machine_type_class(type) \
  577. + ((type == R_AVR32_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)
  578. +
  579. +/* AVR32 doesn't need any COPY relocs */
  580. +#define DL_NO_COPY_RELOCS
  581. +
  582. +/* Return the link-time address of _DYNAMIC. Conveniently, this is the
  583. + first element of the GOT. This must be inlined in a function which
  584. + uses global data. */
  585. +static inline Elf32_Addr
  586. +elf_machine_dynamic (void)
  587. +{
  588. + register Elf32_Addr *got asm ("r6");
  589. + return *got;
  590. +}
  591. +
  592. +/* Return the run-time load address of the shared object. */
  593. +static inline Elf32_Addr
  594. +elf_machine_load_address (void)
  595. +{
  596. + extern void __dl_start asm("_dl_start");
  597. + Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
  598. + Elf32_Addr pcrel_addr;
  599. +
  600. + asm (" lddpc %0, 2f\n"
  601. + "1: add %0, pc\n"
  602. + " rjmp 3f\n"
  603. + " .align 2\n"
  604. + "2: .long _dl_start - 1b\n"
  605. + "3:\n"
  606. + : "=r"(pcrel_addr) : : "cc");
  607. +
  608. + return pcrel_addr - got_addr;
  609. +}
  610. +
  611. +/*
  612. + * Perform any RELATIVE relocations specified by DT_RELCOUNT.
  613. + * Currently, we don't use that tag, but we might in the future as
  614. + * this would reduce the startup time somewhat (although probably not by much).
  615. + */
  616. +static inline void
  617. +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  618. + Elf32_Word relative_count)
  619. +{
  620. + Elf32_Rela *rpnt = (void *)rel_addr;
  621. +
  622. + do {
  623. + Elf32_Addr *reloc_addr;
  624. + reloc_addr = (void *)(load_off + (rpnt++)->r_offset);
  625. + *reloc_addr = load_off + rpnt->r_addend;
  626. + } while (--relative_count);
  627. +}
  628. diff --git a/ldso/ldso/avr32/elfinterp.c b/ldso/ldso/avr32/elfinterp.c
  629. new file mode 100644
  630. index 0000000..196292b
  631. --- /dev/null
  632. +++ b/ldso/ldso/avr32/elfinterp.c
  633. @@ -0,0 +1,191 @@
  634. +/*
  635. + * AVR32 ELF shared library loader suppport
  636. + *
  637. + * Copyright (C) 2004-2006 Atmel Corporation
  638. + *
  639. + * All rights reserved.
  640. + *
  641. + * Redistribution and use in source and binary forms, with or without
  642. + * modification, are permitted provided that the following conditions
  643. + * are met:
  644. + * 1. Redistributions of source code must retain the above copyright
  645. + * notice, this list of conditions and the following disclaimer.
  646. + * 2. The name of the above contributors may not be
  647. + * used to endorse or promote products derived from this software
  648. + * without specific prior written permission.
  649. + *
  650. + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  651. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  652. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  653. + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  654. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  655. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  656. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  657. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  658. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  659. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  660. + * SUCH DAMAGE.
  661. + */
  662. +
  663. +unsigned long _dl_linux_resolver(unsigned long got_offset, unsigned long *got)
  664. +{
  665. + struct elf_resolve *tpnt = (struct elf_resolve *)got[1];
  666. + Elf32_Sym *sym;
  667. + unsigned long local_gotno;
  668. + unsigned long gotsym;
  669. + unsigned long new_addr;
  670. + char *strtab, *symname;
  671. + unsigned long *entry;
  672. + unsigned long sym_index = got_offset / 4;
  673. +
  674. +#if 0
  675. + local_gotno = tpnt->dynamic_info[DT_AVR32_LOCAL_GOTNO];
  676. + gotsym = tpnt->dynamic_info[DT_AVR32_GOTSYM];
  677. +
  678. + sym = ((Elf32_Sym *)(tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr))
  679. + + sym_index;
  680. + strtab = (char *)(tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);
  681. + symname = strtab + sym->st_name;
  682. +
  683. +#if 0
  684. + new_addr = (unsigned long) _dl_find_hash(strtab + sym->st_name,
  685. + tpnt->symbol_scope, tpnt,
  686. + resolver);
  687. +#endif
  688. +
  689. + entry = (unsigned long *)(got + local_gotno + sym_index - gotsym);
  690. + *entry = new_addr;
  691. +#endif
  692. +
  693. + return new_addr;
  694. +}
  695. +
  696. +static int
  697. +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope,
  698. + unsigned long rel_addr, unsigned long rel_size,
  699. + int (*reloc_func)(struct elf_resolve *tpnt, struct dyn_elf *scope,
  700. + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab))
  701. +{
  702. + Elf32_Sym *symtab;
  703. + Elf32_Rela *rpnt;
  704. + char *strtab;
  705. + int i;
  706. +
  707. + rpnt = (Elf32_Rela *)rel_addr;
  708. + rel_size /= sizeof(Elf32_Rela);
  709. + symtab = (Elf32_Sym *)tpnt->dynamic_info[DT_SYMTAB];
  710. + strtab = (char *)tpnt->dynamic_info[DT_STRTAB];
  711. +
  712. + for (i = 0; i < rel_size; i++, rpnt++) {
  713. + int symtab_index, res;
  714. +
  715. + symtab_index = ELF32_R_SYM(rpnt->r_info);
  716. +
  717. + debug_sym(symtab, strtab, symtab_index);
  718. + debug_reloc(symtab, strtab, rpnt);
  719. +
  720. + res = reloc_func(tpnt, scope, rpnt, symtab, strtab);
  721. +
  722. + if (res == 0)
  723. + continue;
  724. +
  725. + _dl_dprintf(2, "\n%s: ", _dl_progname);
  726. +
  727. + if (symtab_index)
  728. + _dl_dprintf(2, "symbol '%s': ",
  729. + strtab + symtab[symtab_index].st_name);
  730. +
  731. + if (res < 0) {
  732. + int reloc_type = ELF32_R_TYPE(rpnt->r_info);
  733. +#if defined(__SUPPORT_LD_DEBUG__)
  734. + _dl_dprintf(2, "can't handle reloc type %s\n",
  735. + _dl_reltypes(reloc_type));
  736. +#else
  737. + _dl_dprintf(2, "can't handle reloc type %x\n",
  738. + reloc_type);
  739. +#endif
  740. + _dl_exit(-res);
  741. + } else {
  742. + _dl_dprintf(2, "can't resolve symbol\n");
  743. + return res;
  744. + }
  745. + }
  746. +
  747. + return 0;
  748. +}
  749. +
  750. +static int _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
  751. + Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab)
  752. +{
  753. + int reloc_type;
  754. + int symtab_index;
  755. + char *symname;
  756. + unsigned long *reloc_addr;
  757. + unsigned long symbol_addr;
  758. +#if defined(__SUPPORT_LD_DEBUG__)
  759. + unsigned long old_val;
  760. +#endif
  761. +
  762. + reloc_addr = (unsigned long *)(tpnt->loadaddr + rpnt->r_offset);
  763. + reloc_type = ELF32_R_TYPE(rpnt->r_info);
  764. + symtab_index = ELF32_R_SYM(rpnt->r_info);
  765. + symbol_addr = 0;
  766. + symname = strtab + symtab[symtab_index].st_name;
  767. +
  768. + if (symtab_index) {
  769. + symbol_addr = (unsigned long)
  770. + _dl_find_hash(strtab + symtab[symtab_index].st_name,
  771. + tpnt->symbol_scope, tpnt,
  772. + elf_machine_type_class(reloc_type));
  773. +
  774. + /* Allow undefined references to weak symbols */
  775. + if (!symbol_addr &&
  776. + ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) {
  777. + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
  778. + _dl_progname, symname);
  779. + return 0;
  780. + }
  781. + }
  782. +
  783. +#if defined(__SUPPORT_LD_DEBUG__)
  784. + old_val = *reloc_addr;
  785. +#endif
  786. + switch (reloc_type) {
  787. + case R_AVR32_NONE:
  788. + break;
  789. + case R_AVR32_GLOB_DAT:
  790. + case R_AVR32_JMP_SLOT:
  791. + *reloc_addr = symbol_addr + rpnt->r_addend;
  792. + break;
  793. + case R_AVR32_RELATIVE:
  794. + *reloc_addr = (unsigned long)tpnt->loadaddr
  795. + + rpnt->r_addend;
  796. + break;
  797. + default:
  798. + return -1;
  799. + }
  800. +
  801. +#if defined(__SUPPORT_LD_DEBUG__)
  802. + if (_dl_debug_reloc && _dl_debug_detail)
  803. + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n",
  804. + old_val, *reloc_addr);
  805. +#endif
  806. +
  807. + return 0;
  808. +}
  809. +
  810. +void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
  811. + unsigned long rel_addr,
  812. + unsigned long rel_size)
  813. +{
  814. + /* TODO: Might want to support this in order to get faster
  815. + * startup times... */
  816. +}
  817. +
  818. +int _dl_parse_relocation_information(struct dyn_elf *rpnt,
  819. + unsigned long rel_addr,
  820. + unsigned long rel_size)
  821. +{
  822. + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size,
  823. + _dl_do_reloc);
  824. +}
  825. diff --git a/ldso/ldso/avr32/resolve.S b/ldso/ldso/avr32/resolve.S
  826. new file mode 100644
  827. index 0000000..e3cb7f4
  828. --- /dev/null
  829. +++ b/ldso/ldso/avr32/resolve.S
  830. @@ -0,0 +1,28 @@
  831. +/*
  832. + * Linux dynamic resolving code for AVR32. Fixes up the GOT entry as
  833. + * indicated in register r12 and jumps to the resolved address.
  834. + *
  835. + * This file is subject to the terms and conditions of the GNU Lesser General
  836. + * Public License. See the file "COPYING.LIB" in the main directory of this
  837. + * archive for more details.
  838. + *
  839. + * Copyright (C) 2004-2007 Atmel Corporation
  840. + */
  841. +
  842. +#define ip r5
  843. +
  844. + .text
  845. + .global _dl_linux_resolve
  846. + .type _dl_linux_resolve,@function
  847. +_dl_linux_resolve:
  848. + /* The PLT code pushed r8 for us. It contains the address of this
  849. + function's GOT entry, that is entry 0. ip contains the address
  850. + of the GOT entry of the function we wanted to call. */
  851. + stm --sp, r9-r12, lr
  852. + mov r11, r8
  853. + sub r12, ip, r8
  854. + rcall _dl_linux_resolver
  855. + mov ip, r12
  856. + popm r8-r12,lr
  857. + mov pc, ip
  858. + .size _dl_linux_resolve, . - _dl_linux_resolve
  859. diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
  860. index 5cf1d04..d4294ec 100644
  861. --- a/ldso/ldso/dl-startup.c
  862. +++ b/ldso/ldso/dl-startup.c
  863. @@ -217,7 +217,9 @@ DL_START(unsigned long args)
  864. /* some arches (like MIPS) we have to tweak the GOT before relocations */
  865. PERFORM_BOOTSTRAP_GOT(tpnt);
  866. -#else
  867. +#endif
  868. +
  869. +#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__)
  870. /* OK, now do the relocations. We do not do a lazy binding here, so
  871. that once we are done, we have considerably more flexibility. */
  872. diff --git a/libc/string/avr32/Makefile b/libc/string/avr32/Makefile
  873. new file mode 100644
  874. index 0000000..e19e9d9
  875. --- /dev/null
  876. +++ b/libc/string/avr32/Makefile
  877. @@ -0,0 +1,26 @@
  878. +# Makefile for uClibc
  879. +#
  880. +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
  881. +#
  882. +# This program is free software; you can redistribute it and/or modify it under
  883. +# the terms of the GNU Library General Public License as published by the Free
  884. +# Software Foundation; either version 2 of the License, or (at your option) any
  885. +# later version.
  886. +#
  887. +# This program is distributed in the hope that it will be useful, but WITHOUT
  888. +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  889. +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  890. +# details.
  891. +#
  892. +# You should have received a copy of the GNU Library General Public License
  893. +# along with this program; if not, write to the Free Software Foundation, Inc.,
  894. +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  895. +
  896. +top_srcdir := ../../../
  897. +top_builddir := ../../../
  898. +
  899. +all: objs
  900. +
  901. +include $(top_builddir)Rules.mak
  902. +include ../Makefile.in
  903. +include $(top_srcdir)Makerules
  904. diff --git a/libc/string/avr32/bcopy.S b/libc/string/avr32/bcopy.S
  905. new file mode 100644
  906. index 0000000..87c1e04
  907. --- /dev/null
  908. +++ b/libc/string/avr32/bcopy.S
  909. @@ -0,0 +1,26 @@
  910. +/*
  911. + * Copyright (C) 2004-2007 Atmel Corporation
  912. + *
  913. + * This file is subject to the terms and conditions of the GNU Lesser General
  914. + * Public License. See the file "COPYING.LIB" in the main directory of this
  915. + * archive for more details.
  916. + */
  917. +
  918. +#include <features.h>
  919. +
  920. +#ifdef __UCLIBC_SUSV3_LEGACY__
  921. +
  922. + .text
  923. + .global bcopy
  924. + .type bcopy, @function
  925. + .align 1
  926. +bcopy:
  927. + /* Swap the first two arguments */
  928. + eor r11, r12
  929. + eor r12, r11
  930. + eor r11, r12
  931. + rjmp __GI_memmove
  932. +
  933. + .size bcopy, . - bcopy
  934. +
  935. +#endif /* __UCLIBC_SUSV3_LEGACY__ */
  936. diff --git a/libc/string/avr32/bzero.S b/libc/string/avr32/bzero.S
  937. new file mode 100644
  938. index 0000000..c999e65
  939. --- /dev/null
  940. +++ b/libc/string/avr32/bzero.S
  941. @@ -0,0 +1,22 @@
  942. +/*
  943. + * Copyright (C) 2004-2007 Atmel Corporation
  944. + *
  945. + * This file is subject to the terms and conditions of the GNU Lesser General
  946. + * Public License. See the file "COPYING.LIB" in the main directory of this
  947. + * archive for more details.
  948. + */
  949. +
  950. +#ifdef __UCLIBC_SUSV3_LEGACY__
  951. +
  952. + .text
  953. + .global bzero
  954. + .type bzero, @function
  955. + .align 1
  956. +bzero:
  957. + mov r10, r11
  958. + mov r11, 0
  959. + rjmp __memset
  960. +
  961. + .size bzero, . - bzero
  962. +
  963. +#endif /* __UCLIBC_SUSV3_LEGACY__ */
  964. diff --git a/libc/string/avr32/memcmp.S b/libc/string/avr32/memcmp.S
  965. new file mode 100644
  966. index 0000000..7359a64
  967. --- /dev/null
  968. +++ b/libc/string/avr32/memcmp.S
  969. @@ -0,0 +1,58 @@
  970. +/*
  971. + * Copyright (C) 2004-2007 Atmel Corporation
  972. + *
  973. + * This file is subject to the terms and conditions of the GNU Lesser General
  974. + * Public License. See the file "COPYING.LIB" in the main directory of this
  975. + * archive for more details.
  976. + */
  977. +
  978. +#include <features.h>
  979. +
  980. +#define s1 r12
  981. +#define s2 r11
  982. +#define len r10
  983. +
  984. + .text
  985. + .global memcmp
  986. + .type memcmp, @function
  987. + .align 1
  988. +memcmp:
  989. + sub len, 4
  990. + brlt .Lless_than_4
  991. +
  992. +1: ld.w r8, s1++
  993. + ld.w r9, s2++
  994. + cp.w r8, r9
  995. + brne .Lfound_word
  996. + sub len, 4
  997. + brge 1b
  998. +
  999. +.Lless_than_4:
  1000. + sub len, -4
  1001. + reteq 0
  1002. +
  1003. +1: ld.ub r8, s1++
  1004. + ld.ub r9, s2++
  1005. + sub r8, r9
  1006. + retne r8
  1007. + sub len, 1
  1008. + brgt 1b
  1009. +
  1010. + retal 0
  1011. +
  1012. +.Lfound_word:
  1013. + psub.b r9, r8, r9
  1014. + bfextu r8, r9, 24, 8
  1015. + retne r8
  1016. + bfextu r8, r9, 16, 8
  1017. + retne r8
  1018. + bfextu r8, r9, 8, 8
  1019. + retne r8
  1020. + retal r9
  1021. +
  1022. + .size memcmp, . - memcmp
  1023. +
  1024. +libc_hidden_def(memcmp)
  1025. +#ifdef __UCLIBC_SUSV3_LEGACY__
  1026. +strong_alias(memcmp,bcmp)
  1027. +#endif
  1028. diff --git a/libc/string/avr32/memcpy.S b/libc/string/avr32/memcpy.S
  1029. new file mode 100644
  1030. index 0000000..bf091ab
  1031. --- /dev/null
  1032. +++ b/libc/string/avr32/memcpy.S
  1033. @@ -0,0 +1,111 @@
  1034. +/*
  1035. + * Copyright (C) 2004-2007 Atmel Corporation
  1036. + *
  1037. + * This file is subject to the terms and conditions of the GNU Lesser General
  1038. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1039. + * archive for more details.
  1040. + */
  1041. +
  1042. +/* Don't use r12 as dst since we must return it unmodified */
  1043. +#define dst r9
  1044. +#define src r11
  1045. +#define len r10
  1046. +
  1047. + .text
  1048. + .global memcpy
  1049. + .type memcpy, @function
  1050. +memcpy:
  1051. + pref src[0]
  1052. + mov dst, r12
  1053. +
  1054. + /* If we have less than 32 bytes, don't do anything fancy */
  1055. + cp.w len, 32
  1056. + brge .Lmore_than_31
  1057. +
  1058. + sub len, 1
  1059. + retlt r12
  1060. +1: ld.ub r8, src++
  1061. + st.b dst++, r8
  1062. + sub len, 1
  1063. + brge 1b
  1064. + retal r12
  1065. +
  1066. +.Lmore_than_31:
  1067. + pushm r0-r7, lr
  1068. +
  1069. + /* Check alignment */
  1070. + mov r8, src
  1071. + andl r8, 31, COH
  1072. + brne .Lunaligned_src
  1073. + mov r8, dst
  1074. + andl r8, 3, COH
  1075. + brne .Lunaligned_dst
  1076. +
  1077. +.Laligned_copy:
  1078. + sub len, 32
  1079. + brlt .Lless_than_32
  1080. +
  1081. +1: /* Copy 32 bytes at a time */
  1082. + ldm src, r0-r7
  1083. + sub src, -32
  1084. + stm dst, r0-r7
  1085. + sub dst, -32
  1086. + sub len, 32
  1087. + brge 1b
  1088. +
  1089. +.Lless_than_32:
  1090. + /* Copy 16 more bytes if possible */
  1091. + sub len, -16
  1092. + brlt .Lless_than_16
  1093. + ldm src, r0-r3
  1094. + sub src, -16
  1095. + sub len, 16
  1096. + stm dst, r0-r3
  1097. + sub dst, -16
  1098. +
  1099. +.Lless_than_16:
  1100. + /* Do the remaining as byte copies */
  1101. + neg len
  1102. + add pc, pc, len << 2
  1103. + .rept 15
  1104. + ld.ub r0, src++
  1105. + st.b dst++, r0
  1106. + .endr
  1107. +
  1108. + popm r0-r7, pc
  1109. +
  1110. +.Lunaligned_src:
  1111. + /* Make src cacheline-aligned. r8 = (src & 31) */
  1112. + rsub r8, r8, 32
  1113. + sub len, r8
  1114. +1: ld.ub r0, src++
  1115. + st.b dst++, r0
  1116. + sub r8, 1
  1117. + brne 1b
  1118. +
  1119. + /* If dst is word-aligned, we're ready to go */
  1120. + pref src[0]
  1121. + mov r8, 3
  1122. + tst dst, r8
  1123. + breq .Laligned_copy
  1124. +
  1125. +.Lunaligned_dst:
  1126. + /* src is aligned, but dst is not. Expect bad performance */
  1127. + sub len, 4
  1128. + brlt 2f
  1129. +1: ld.w r0, src++
  1130. + st.w dst++, r0
  1131. + sub len, 4
  1132. + brge 1b
  1133. +
  1134. +2: neg len
  1135. + add pc, pc, len << 2
  1136. + .rept 3
  1137. + ld.ub r0, src++
  1138. + st.b dst++, r0
  1139. + .endr
  1140. +
  1141. + popm r0-r7, pc
  1142. + .size memcpy, . - memcpy
  1143. +
  1144. +libc_hidden_def(memcpy)
  1145. diff --git a/libc/string/avr32/memmove.S b/libc/string/avr32/memmove.S
  1146. new file mode 100644
  1147. index 0000000..98287c5
  1148. --- /dev/null
  1149. +++ b/libc/string/avr32/memmove.S
  1150. @@ -0,0 +1,116 @@
  1151. +/*
  1152. + * Copyright (C) 2004-2007 Atmel Corporation
  1153. + *
  1154. + * This file is subject to the terms and conditions of the GNU Lesser General
  1155. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1156. + * archive for more details.
  1157. + */
  1158. +
  1159. +#define dst r12
  1160. +#define src r11
  1161. +#define len r10
  1162. +
  1163. + .text
  1164. + .global memmove
  1165. + .type memmove, @function
  1166. +memmove:
  1167. + cp.w src, dst
  1168. + brge __GI_memcpy
  1169. +
  1170. + add dst, len
  1171. + add src, len
  1172. + pref src[-1]
  1173. +
  1174. + /*
  1175. + * The rest is basically the same as in memcpy.S except that
  1176. + * the direction is reversed.
  1177. + */
  1178. + cp.w len, 32
  1179. + brge .Lmore_than_31
  1180. +
  1181. + sub len, 1
  1182. + retlt r12
  1183. +1: ld.ub r8, --src
  1184. + st.b --dst, r8
  1185. + sub len, 1
  1186. + brge 1b
  1187. + retal r12
  1188. +
  1189. +.Lmore_than_31:
  1190. + pushm r0-r7, lr
  1191. +
  1192. + /* Check alignment */
  1193. + mov r8, src
  1194. + andl r8, 31, COH
  1195. + brne .Lunaligned_src
  1196. + mov r8, r12
  1197. + andl r8, 3, COH
  1198. + brne .Lunaligned_dst
  1199. +
  1200. +.Laligned_copy:
  1201. + sub len, 32
  1202. + brlt .Lless_than_32
  1203. +
  1204. +1: /* Copy 32 bytes at a time */
  1205. + sub src, 32
  1206. + ldm src, r0-r7
  1207. + sub dst, 32
  1208. + sub len, 32
  1209. + stm dst, r0-r7
  1210. + brge 1b
  1211. +
  1212. +.Lless_than_32:
  1213. + /* Copy 16 more bytes if possible */
  1214. + sub len, -16
  1215. + brlt .Lless_than_16
  1216. + sub src, 16
  1217. + ldm src, r0-r3
  1218. + sub dst, 16
  1219. + sub len, 16
  1220. + stm dst, r0-r3
  1221. +
  1222. +.Lless_than_16:
  1223. + /* Do the remaining as byte copies */
  1224. + sub len, -16
  1225. + breq 2f
  1226. +1: ld.ub r0, --src
  1227. + st.b --dst, r0
  1228. + sub len, 1
  1229. + brne 1b
  1230. +
  1231. +2: popm r0-r7, pc
  1232. +
  1233. +.Lunaligned_src:
  1234. + /* Make src cacheline-aligned. r8 = (src & 31) */
  1235. + sub len, r8
  1236. +1: ld.ub r0, --src
  1237. + st.b --dst, r0
  1238. + sub r8, 1
  1239. + brne 1b
  1240. +
  1241. + /* If dst is word-aligned, we're ready to go */
  1242. + pref src[-4]
  1243. + mov r8, 3
  1244. + tst dst, r8
  1245. + breq .Laligned_copy
  1246. +
  1247. +.Lunaligned_dst:
  1248. + /* src is aligned, but dst is not. Expect bad performance */
  1249. + sub len, 4
  1250. + brlt 2f
  1251. +1: ld.w r0, --src
  1252. + st.w --dst, r0
  1253. + sub len, 4
  1254. + brge 1b
  1255. +
  1256. +2: neg len
  1257. + add pc, pc, len << 2
  1258. + .rept 3
  1259. + ld.ub r0, --src
  1260. + st.b --dst, r0
  1261. + .endr
  1262. +
  1263. + popm r0-r7, pc
  1264. + .size memmove, . - memmove
  1265. +
  1266. +libc_hidden_def(memmove)
  1267. diff --git a/libc/string/avr32/memset.S b/libc/string/avr32/memset.S
  1268. new file mode 100644
  1269. index 0000000..33cfaed
  1270. --- /dev/null
  1271. +++ b/libc/string/avr32/memset.S
  1272. @@ -0,0 +1,70 @@
  1273. +/*
  1274. + * Copyright (C) 2004-2007 Atmel Corporation
  1275. + *
  1276. + * This file is subject to the terms and conditions of the GNU Lesser General
  1277. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1278. + * archive for more details.
  1279. + */
  1280. +
  1281. +#include <features.h>
  1282. +
  1283. +#define s r12
  1284. +#define c r11
  1285. +#define n r10
  1286. +
  1287. + .text
  1288. + .global memset
  1289. + .type memset, @function
  1290. +
  1291. + .global __memset
  1292. + .hidden __memset
  1293. + .type __memset, @function
  1294. +
  1295. + .align 1
  1296. +memset:
  1297. +__memset:
  1298. + cp.w n, 32
  1299. + mov r9, s
  1300. + brge .Llarge_memset
  1301. +
  1302. + sub n, 1
  1303. + retlt s
  1304. +1: st.b s++, c
  1305. + sub n, 1
  1306. + brge 1b
  1307. +
  1308. + retal r9
  1309. +
  1310. +.Llarge_memset:
  1311. + mov r8, r11
  1312. + mov r11, 3
  1313. + bfins r8, r8, 8, 8
  1314. + bfins r8, r8, 16, 16
  1315. + tst s, r11
  1316. + breq 2f
  1317. +
  1318. +1: st.b s++, r8
  1319. + sub n, 1
  1320. + tst s, r11
  1321. + brne 1b
  1322. +
  1323. +2: mov r11, r9
  1324. + mov r9, r8
  1325. + sub n, 8
  1326. +
  1327. +3: st.d s++, r8
  1328. + sub n, 8
  1329. + brge 3b
  1330. +
  1331. + /* If we are done, n == -8 and we'll skip all st.b insns below */
  1332. + neg n
  1333. + lsl n, 1
  1334. + add pc, n
  1335. + .rept 7
  1336. + st.b s++, r8
  1337. + .endr
  1338. + retal r11
  1339. +
  1340. + .size memset, . - memset
  1341. +
  1342. +libc_hidden_def(memset)
  1343. diff --git a/libc/string/avr32/strcmp.S b/libc/string/avr32/strcmp.S
  1344. new file mode 100644
  1345. index 0000000..f73bd43
  1346. --- /dev/null
  1347. +++ b/libc/string/avr32/strcmp.S
  1348. @@ -0,0 +1,91 @@
  1349. +/*
  1350. + * Copyright (C) 2004-2007 Atmel Corporation
  1351. + *
  1352. + * This file is subject to the terms and conditions of the GNU Lesser General
  1353. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1354. + * archive for more details.
  1355. + */
  1356. +
  1357. +#include <features.h>
  1358. +
  1359. +#define s1 r12
  1360. +#define s2 r11
  1361. +#define len r10
  1362. +
  1363. + .text
  1364. + .global strcmp
  1365. + .type strcmp, @function
  1366. + .align 1
  1367. +strcmp:
  1368. + mov r8, 3
  1369. + tst s1, r8
  1370. + brne .Lunaligned_s1
  1371. + tst s2, r8
  1372. + brne .Lunaligned_s2
  1373. +
  1374. +1: ld.w r8, s1++
  1375. + ld.w r9, s2++
  1376. + cp.w r8, r9
  1377. + brne 2f
  1378. + tnbz r8
  1379. + brne 1b
  1380. + retal 0
  1381. +
  1382. +2: bfextu r12, r8, 24, 8
  1383. + bfextu r11, r9, 24, 8
  1384. + sub r12, r11
  1385. + retne r12
  1386. + cp.w r11, 0
  1387. + reteq 0
  1388. + bfextu r12, r8, 16, 8
  1389. + bfextu r11, r9, 16, 8
  1390. + sub r12, r11
  1391. + retne r12
  1392. + cp.w r11, 0
  1393. + reteq 0
  1394. + bfextu r12, r8, 8, 8
  1395. + bfextu r11, r9, 8, 8
  1396. + sub r12, r11
  1397. + retne r12
  1398. + cp.w r11, 0
  1399. + reteq 0
  1400. + bfextu r12, r8, 0, 8
  1401. + bfextu r11, r9, 0, 8
  1402. + sub r12, r11
  1403. + retal r12
  1404. +
  1405. +.Lunaligned_s1:
  1406. +3: tst s1, r8
  1407. + breq 4f
  1408. + ld.ub r10, s1++
  1409. + ld.ub r9, s2++
  1410. + sub r10, r9
  1411. + retne r10
  1412. + cp.w r9, 0
  1413. + brne 3b
  1414. + retal r10
  1415. +
  1416. +4: tst s2, r8
  1417. + breq 1b
  1418. +
  1419. +.Lunaligned_s2:
  1420. + /*
  1421. + * s1 and s2 can't both be aligned, and unaligned word loads
  1422. + * can trigger spurious exceptions if we cross a page boundary.
  1423. + * Do it the slow way...
  1424. + */
  1425. +1: ld.ub r8, s1++
  1426. + ld.ub r9, s2++
  1427. + sub r8, r9
  1428. + retne r8
  1429. + cp.w r9, 0
  1430. + brne 1b
  1431. + retal 0
  1432. +
  1433. + .size strcmp, . - strcmp
  1434. +
  1435. +libc_hidden_def(strcmp)
  1436. +#ifndef __UCLIBC_HAS_LOCALE__
  1437. +strong_alias(strcmp, strcoll)
  1438. +libc_hidden_def(strcoll)
  1439. +#endif
  1440. diff --git a/libc/string/avr32/strlen.S b/libc/string/avr32/strlen.S
  1441. new file mode 100644
  1442. index 0000000..5223e53
  1443. --- /dev/null
  1444. +++ b/libc/string/avr32/strlen.S
  1445. @@ -0,0 +1,62 @@
  1446. +/*
  1447. + * Copyright (C) 2004-2007 Atmel Corporation
  1448. + *
  1449. + * This file is subject to the terms and conditions of the GNU Lesser General
  1450. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1451. + * archive for more details.
  1452. + */
  1453. +
  1454. +#include <features.h>
  1455. +
  1456. +#define str r12
  1457. +
  1458. + .text
  1459. + .global strlen
  1460. + .type strlen, @function
  1461. +strlen:
  1462. + mov r11, r12
  1463. +
  1464. + mov r9, str
  1465. + andl r9, 3, COH
  1466. + brne .Lunaligned_str
  1467. +
  1468. +1: ld.w r8, str++
  1469. + tnbz r8
  1470. + brne 1b
  1471. +
  1472. + sub r12, r11
  1473. + bfextu r9, r8, 24, 8
  1474. + cp.w r9, 0
  1475. + subeq r12, 4
  1476. + reteq r12
  1477. + bfextu r9, r8, 16, 8
  1478. + cp.w r9, 0
  1479. + subeq r12, 3
  1480. + reteq r12
  1481. + bfextu r9, r8, 8, 8
  1482. + cp.w r9, 0
  1483. + subeq r12, 2
  1484. + reteq r12
  1485. + sub r12, 1
  1486. + retal r12
  1487. +
  1488. +.Lunaligned_str:
  1489. + add pc, pc, r9 << 3
  1490. + sub r0, r0, 0 /* 4-byte nop */
  1491. + ld.ub r8, str++
  1492. + sub r8, r8, 0
  1493. + breq 1f
  1494. + ld.ub r8, str++
  1495. + sub r8, r8, 0
  1496. + breq 1f
  1497. + ld.ub r8, str++
  1498. + sub r8, r8, 0
  1499. + brne 1b
  1500. +
  1501. +1: sub r12, 1
  1502. + sub r12, r11
  1503. + retal r12
  1504. +
  1505. + .size strlen, . - strlen
  1506. +
  1507. +libc_hidden_def(strlen)
  1508. diff --git a/libc/sysdeps/linux/avr32/Makefile b/libc/sysdeps/linux/avr32/Makefile
  1509. new file mode 100644
  1510. index 0000000..338abc0
  1511. --- /dev/null
  1512. +++ b/libc/sysdeps/linux/avr32/Makefile
  1513. @@ -0,0 +1,25 @@
  1514. +# Makefile for uClibc
  1515. +#
  1516. +# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
  1517. +#
  1518. +# This program is free software; you can redistribute it and/or modify it under
  1519. +# the terms of the GNU Library General Public License as published by the Free
  1520. +# Software Foundation; either version 2 of the License, or (at your option) any
  1521. +# later version.
  1522. +#
  1523. +# This program is distributed in the hope that it will be useful, but WITHOUT
  1524. +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1525. +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  1526. +# details.
  1527. +#
  1528. +# You should have received a copy of the GNU Library General Public License
  1529. +# along with this program; if not, write to the Free Software Foundation, Inc.,
  1530. +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  1531. +
  1532. +top_srcdir=../../../../
  1533. +top_builddir=../../../../
  1534. +all: objs
  1535. +
  1536. +include $(top_builddir)Rules.mak
  1537. +include Makefile.arch
  1538. +include $(top_srcdir)Makerules
  1539. diff --git a/libc/sysdeps/linux/avr32/Makefile.arch b/libc/sysdeps/linux/avr32/Makefile.arch
  1540. new file mode 100644
  1541. index 0000000..44fc01e
  1542. --- /dev/null
  1543. +++ b/libc/sysdeps/linux/avr32/Makefile.arch
  1544. @@ -0,0 +1,13 @@
  1545. +# Makefile for uClibc
  1546. +#
  1547. +# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  1548. +#
  1549. +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  1550. +#
  1551. +
  1552. +CSRC := brk.c clone.c mmap.c sigaction.c
  1553. +
  1554. +SSRC := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \
  1555. + sigrestorer.S syscall.S vfork.S
  1556. +
  1557. +include $(top_srcdir)/libc/sysdeps/linux/Makefile.commonarch
  1558. diff --git a/libc/sysdeps/linux/avr32/__longjmp.S b/libc/sysdeps/linux/avr32/__longjmp.S
  1559. new file mode 100644
  1560. index 0000000..6154bb2
  1561. --- /dev/null
  1562. +++ b/libc/sysdeps/linux/avr32/__longjmp.S
  1563. @@ -0,0 +1,21 @@
  1564. +/*
  1565. + * Copyright (C) 2004-2007 Atmel Corporation
  1566. + *
  1567. + * This file is subject to the terms and conditions of the GNU Lesser General
  1568. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1569. + * archive for more details.
  1570. + */
  1571. +
  1572. + .global __longjmp
  1573. + .type __longjmp,"function"
  1574. + .align 1
  1575. +__longjmp:
  1576. + ldm r12++, r0-r8,sp,lr
  1577. + mustr r8 /* restore status register (lower half) */
  1578. + cp r11, 0 /* can't return zero */
  1579. + frs
  1580. + moveq r11, 1
  1581. + retal r11
  1582. + .size __longjmp, . - __longjmp
  1583. +
  1584. +libc_hidden_def(__longjmp)
  1585. diff --git a/libc/sysdeps/linux/avr32/bits/atomic.h b/libc/sysdeps/linux/avr32/bits/atomic.h
  1586. new file mode 100644
  1587. index 0000000..e6be41f
  1588. --- /dev/null
  1589. +++ b/libc/sysdeps/linux/avr32/bits/atomic.h
  1590. @@ -0,0 +1,120 @@
  1591. +/*
  1592. + * Copyright (C) 2007 Atmel Corporation
  1593. + *
  1594. + * This file is subject to the terms and conditions of the GNU Lesser General
  1595. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1596. + * archive for more details.
  1597. + */
  1598. +#ifndef _AVR32_BITS_ATOMIC_H
  1599. +#define _AVR32_BITS_ATOMIC_H 1
  1600. +
  1601. +#include <inttypes.h>
  1602. +
  1603. +typedef int32_t atomic32_t;
  1604. +typedef uint32_t uatomic32_t;
  1605. +typedef int_fast32_t atomic_fast32_t;
  1606. +typedef uint_fast32_t uatomic_fast32_t;
  1607. +
  1608. +typedef intptr_t atomicptr_t;
  1609. +typedef uintptr_t uatomicptr_t;
  1610. +typedef intmax_t atomic_max_t;
  1611. +typedef uintmax_t uatomic_max_t;
  1612. +
  1613. +#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
  1614. + (abort(), 0)
  1615. +
  1616. +#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
  1617. + (abort(), 0)
  1618. +
  1619. +#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
  1620. + ({ \
  1621. + __typeof__(*(mem)) __prev; \
  1622. + __asm__ __volatile__( \
  1623. + "/* __arch_compare_and_exchange_val_32_acq */\n" \
  1624. + "1: ssrf 5\n" \
  1625. + " ld.w %[result], %[m]\n" \
  1626. + " cp.w %[result], %[old]\n" \
  1627. + " brne 2f\n" \
  1628. + " stcond %[m], %[new]\n" \
  1629. + " brne 1b\n" \
  1630. + "2:" \
  1631. + : [result] "=&r"(__result), [m] "=m"(*(mem)) \
  1632. + : "m"(*(mem)), [old] "ir"(oldval), \
  1633. + [new] "r"(newval) \
  1634. + : "memory", "cc"); \
  1635. + __prev; \
  1636. + })
  1637. +
  1638. +#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
  1639. + (abort(), 0)
  1640. +
  1641. +#define __arch_exchange_32_acq(mem, newval) \
  1642. + ({ \
  1643. + __typeof__(*(mem)) __oldval; \
  1644. + __asm__ __volatile__( \
  1645. + "/*__arch_exchange_32_acq */\n" \
  1646. + " xchg %[old], %[m], %[new]" \
  1647. + : [old] "=&r"(__oldval) \
  1648. + : [m] "r"(mem), [new] "r"(newval) \
  1649. + : "memory"); \
  1650. + __oldval; \
  1651. + })
  1652. +
  1653. +#define __arch_atomic_exchange_and_add_32(mem, value) \
  1654. + ({ \
  1655. + __typeof__(*(mem)) __oldval, __tmp; \
  1656. + __asm__ __volatile__( \
  1657. + "/* __arch_atomic_exchange_and_add_32 */\n" \
  1658. + "1: ssrf 5\n" \
  1659. + " ld.w %[old], %[m]\n" \
  1660. + " add %[tmp], %[old], %[val]\n" \
  1661. + " stcond %[m], %[tmp]\n" \
  1662. + " brne 1b" \
  1663. + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
  1664. + [m] "=m"(*(mem)) \
  1665. + : "m"(*(mem)), [val] "r"(value) \
  1666. + : "memory", "cc"); \
  1667. + __oldval; \
  1668. + })
  1669. +
  1670. +#define __arch_atomic_decrement_if_positive_32(mem) \
  1671. + ({ \
  1672. + __typeof__(*(mem)) __oldval, __tmp; \
  1673. + __asm__ __volatile__( \
  1674. + "/* __arch_atomic_decrement_if_positive_32 */\n" \
  1675. + "1: ssrf 5\n" \
  1676. + " ld.w %[old], %[m]\n" \
  1677. + " sub %[tmp], %[old], 1\n" \
  1678. + " brlt 2f\n" \
  1679. + " stcond %[m], %[tmp]\n" \
  1680. + " brne 1b" \
  1681. + "2:" \
  1682. + : [old] "=&r"(__oldval), [tmp] "=&r"(__tmp), \
  1683. + [m] "=m"(*(mem)) \
  1684. + : "m"(*(mem)) \
  1685. + : "memory", "cc"); \
  1686. + __oldval; \
  1687. + })
  1688. +
  1689. +#define atomic_exchange_acq(mem, newval) \
  1690. + ({ \
  1691. + if (sizeof(*(mem)) != 4) \
  1692. + abort(); \
  1693. + __arch_exchange_32_acq(mem, newval); \
  1694. + })
  1695. +
  1696. +#define atomic_exchange_and_add(mem, newval) \
  1697. + ({ \
  1698. + if (sizeof(*(mem)) != 4) \
  1699. + abort(); \
  1700. + __arch_atomic_exchange_and_add_32(mem, newval); \
  1701. + })
  1702. +
  1703. +#define atomic_decrement_if_positive(mem) \
  1704. + ({ \
  1705. + if (sizeof(*(mem)) != 4) \
  1706. + abort(); \
  1707. + __arch_atomic_decrement_if_positive_32(mem); \
  1708. + })
  1709. +
  1710. +#endif /* _AVR32_BITS_ATOMIC_H */
  1711. diff --git a/libc/sysdeps/linux/avr32/bits/byteswap.h b/libc/sysdeps/linux/avr32/bits/byteswap.h
  1712. new file mode 100644
  1713. index 0000000..1c030b9
  1714. --- /dev/null
  1715. +++ b/libc/sysdeps/linux/avr32/bits/byteswap.h
  1716. @@ -0,0 +1,70 @@
  1717. +/*
  1718. + * Copyright (C) 2005 Atmel Corporation
  1719. + *
  1720. + * This file is subject to the terms and conditions of the GNU Lesser General
  1721. + * Public License. See the file "COPYING.LIB" in the main directory of this
  1722. + * archive for more details.
  1723. + */
  1724. +
  1725. +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
  1726. +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
  1727. +#endif
  1728. +
  1729. +#ifndef _BITS_BYTESWAP_H
  1730. +#define _BITS_BYTESWAP_H 1
  1731. +
  1732. +/* Swap bytes in 16 bit value. */
  1733. +#if defined __GNUC__
  1734. +# define __bswap_16(x) (__extension__ __builtin_bswap_16(x))
  1735. +#else
  1736. +/* This is better than nothing. */
  1737. +static __inline unsigned short int
  1738. +__bswap_16 (unsigned short int __bsx)
  1739. +{
  1740. + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8));
  1741. +}
  1742. +#endif
  1743. +
  1744. +/* Swap bytes in 32 bit value. */
  1745. +#if defined __GNUC__
  1746. +# define __bswap_32(x) (__extension__ __builtin_bswap_32(x))
  1747. +#else
  1748. +static __inline unsigned int
  1749. +__bswap_32 (unsigned int __bsx)
  1750. +{
  1751. + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) |
  1752. + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24));
  1753. +}
  1754. +#endif
  1755. +
  1756. +#if defined __GNUC__
  1757. +/* Swap bytes in 64 bit value. */
  1758. +# define __bswap_constant_64(x) \
  1759. + ((((x) & 0xff00000000000000ull) >> 56) \
  1760. + | (((x) & 0x00ff000000000000ull) >> 40) \
  1761. + | (((x) & 0x0000ff0000000000ull) >> 24) \
  1762. + | (((x) & 0x000000ff00000000ull) >> 8) \
  1763. + | (((x) & 0x00000000ff000000ull) << 8) \
  1764. + | (((x) & 0x0000000000ff0000ull) << 24) \
  1765. + | (((x) & 0x000000000000ff00ull) << 40) \
  1766. + | (((x) & 0x00000000000000ffull) << 56))
  1767. +
  1768. +# define __bswap_64(x) \
  1769. + (__extension__ \
  1770. + ({ \
  1771. + union { \
  1772. + __extension__ unsigned long long int __ll; \
  1773. + unsigned int __l[2]; \
  1774. + } __w, __r; \
  1775. + if (__builtin_constant_p(x)) \
  1776. + __r.__ll = __bswap_constant_64(x); \
  1777. + else { \
  1778. + __w.__ll = (x); \
  1779. + __r.__l[0] = __bswap_32(__w.__l[1]); \
  1780. + __r.__l[1] = __bswap_32(__w.__l[0]); \
  1781. + } \
  1782. + __r.__ll; \
  1783. + }))
  1784. +#endif
  1785. +
  1786. +#endif /* _BITS_BYTESWAP_H */
  1787. diff --git a/libc/sysdeps/linux/avr32/bits/endian.h b/libc/sysdeps/linux/avr32/bits/endian.h
  1788. new file mode 100644
  1789. index 0000000..7bb6358
  1790. --- /dev/null
  1791. +++ b/libc/sysdeps/linux/avr32/bits/endian.h
  1792. @@ -0,0 +1,7 @@
  1793. +/* AVR32 is big-endian */
  1794. +
  1795. +#ifndef _ENDIAN_H
  1796. +# error "Never use <bits/endian.h> directly; include <endian.h> instead."
  1797. +#endif
  1798. +
  1799. +#define __BYTE_ORDER __BIG_ENDIAN
  1800. diff --git a/libc/sysdeps/linux/avr32/bits/fcntl.h b/libc/sysdeps/linux/avr32/bits/fcntl.h
  1801. new file mode 100644
  1802. index 0000000..1abff17
  1803. --- /dev/null
  1804. +++ b/libc/sysdeps/linux/avr32/bits/fcntl.h
  1805. @@ -0,0 +1,165 @@
  1806. +#ifndef _FCNTL_H
  1807. +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
  1808. +#endif
  1809. +
  1810. +#include <sys/types.h>
  1811. +
  1812. +/*
  1813. + * open/fcntl - O_SYNC is only implemented on blocks devices and on files
  1814. + * located on an ext2 file system
  1815. + */
  1816. +#define O_ACCMODE 00000003
  1817. +#define O_RDONLY 00000000
  1818. +#define O_WRONLY 00000001
  1819. +#define O_RDWR 00000002
  1820. +#define O_CREAT 00000100 /* not fcntl */
  1821. +#define O_EXCL 00000200 /* not fcntl */
  1822. +#define O_NOCTTY 00000400 /* not fcntl */
  1823. +#define O_TRUNC 00001000 /* not fcntl */
  1824. +#define O_APPEND 00002000
  1825. +#define O_NONBLOCK 00004000
  1826. +#define O_NDELAY O_NONBLOCK
  1827. +#define O_SYNC 00010000
  1828. +#define O_ASYNC 00020000
  1829. +
  1830. +#ifdef __USE_GNU
  1831. +# define O_DIRECT 00040000 /* must be a directory */
  1832. +# define O_DIRECTORY 00200000 /* direct disk access */
  1833. +# define O_NOFOLLOW 00400000 /* don't follow links */
  1834. +# define O_NOATIME 01000000 /* don't set atime */
  1835. +#endif
  1836. +
  1837. +#ifdef __USE_LARGEFILE64
  1838. +# define O_LARGEFILE 00100000
  1839. +#endif
  1840. +
  1841. +/* For now Linux has synchronisity options for data and read operations.
  1842. + We define the symbols here but let them do the same as O_SYNC since
  1843. + this is a superset. */
  1844. +#if defined __USE_POSIX199309 || defined __USE_UNIX98
  1845. +# define O_DSYNC O_SYNC /* Synchronize data. */
  1846. +# define O_RSYNC O_SYNC /* Synchronize read operations. */
  1847. +#endif
  1848. +
  1849. +#define F_DUPFD 0 /* dup */
  1850. +#define F_GETFD 1 /* get close_on_exec */
  1851. +#define F_SETFD 2 /* set/clear close_on_exec */
  1852. +#define F_GETFL 3 /* get file->f_flags */
  1853. +#define F_SETFL 4 /* set file->f_flags */
  1854. +
  1855. +#ifndef __USE_FILE_OFFSET64
  1856. +# define F_GETLK 5
  1857. +# define F_SETLK 6
  1858. +# define F_SETLKW 7
  1859. +#else
  1860. +# define F_GETLK F_GETLK64
  1861. +# define F_SETLK F_SETLK64
  1862. +# define F_SETLKW F_SETLKW64
  1863. +#endif
  1864. +#define F_GETLK64 12 /* using 'struct flock64' */
  1865. +#define F_SETLK64 13
  1866. +#define F_SETLKW64 14
  1867. +
  1868. +#if defined __USE_BSD || defined __USE_XOPEN2K
  1869. +# define F_SETOWN 8 /* for sockets. */
  1870. +# define F_GETOWN 9 /* for sockets. */
  1871. +#endif
  1872. +
  1873. +#ifdef __USE_GNU
  1874. +# define F_SETSIG 10 /* for sockets. */
  1875. +# define F_GETSIG 11 /* for sockets. */
  1876. +#endif
  1877. +
  1878. +#ifdef __USE_GNU
  1879. +# define F_SETLEASE 1024 /* Set a lease. */
  1880. +# define F_GETLEASE 1025 /* Enquire what lease is active. */
  1881. +# define F_NOTIFY 1026 /* Request notfications on a directory. */
  1882. +#endif
  1883. +
  1884. +/* for F_[GET|SET]FL */
  1885. +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
  1886. +
  1887. +/* for posix fcntl() and lockf() */
  1888. +#define F_RDLCK 0
  1889. +#define F_WRLCK 1
  1890. +#define F_UNLCK 2
  1891. +
  1892. +/* for old implementation of bsd flock () */
  1893. +#define F_EXLCK 4 /* or 3 */
  1894. +#define F_SHLCK 8 /* or 4 */
  1895. +
  1896. +/* for leases */
  1897. +#define F_INPROGRESS 16
  1898. +
  1899. +#ifdef __USE_BSD
  1900. +/* operations for bsd flock(), also used by the kernel implementation */
  1901. +# define LOCK_SH 1 /* shared lock */
  1902. +# define LOCK_EX 2 /* exclusive lock */
  1903. +# define LOCK_NB 4 /* or'd with one of the above to prevent
  1904. + blocking */
  1905. +# define LOCK_UN 8 /* remove lock */
  1906. +#endif
  1907. +
  1908. +#ifdef __USE_GNU
  1909. +# define LOCK_MAND 32 /* This is a mandatory flock */
  1910. +# define LOCK_READ 64 /* ... Which allows concurrent
  1911. + read operations */
  1912. +# define LOCK_WRITE 128 /* ... Which allows concurrent
  1913. + write operations */
  1914. +# define LOCK_RW 192 /* ... Which allows concurrent
  1915. + read & write ops */
  1916. +#endif
  1917. +
  1918. +#ifdef __USE_GNU
  1919. +/* Types of directory notifications that may be requested with F_NOTIFY. */
  1920. +# define DN_ACCESS 0x00000001 /* File accessed. */
  1921. +# define DN_MODIFY 0x00000002 /* File modified. */
  1922. +# define DN_CREATE 0x00000004 /* File created. */
  1923. +# define DN_DELETE 0x00000008 /* File removed. */
  1924. +# define DN_RENAME 0x00000010 /* File renamed. */
  1925. +# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
  1926. +# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
  1927. +#endif
  1928. +
  1929. +struct flock {
  1930. + short l_type;
  1931. + short l_whence;
  1932. +#ifndef __USE_FILE_OFFSET64
  1933. + __off_t l_start;
  1934. + __off_t l_len;
  1935. +#else
  1936. + __off64_t l_start;
  1937. + __off64_t l_len;
  1938. +#endif
  1939. + __pid_t l_pid;
  1940. +};
  1941. +
  1942. +#ifdef __USE_LARGEFILE64
  1943. +struct flock64 {
  1944. + short l_type;
  1945. + short l_whence;
  1946. + __off64_t l_start;
  1947. + __off64_t l_len;
  1948. + __pid_t l_pid;
  1949. +};
  1950. +#endif
  1951. +
  1952. +/* Define some more compatibility macros to be backward compatible with
  1953. + * BSD systems which did not managed to hide these kernel macros. */
  1954. +#ifdef __USE_BSD
  1955. +# define FAPPEND O_APPEND
  1956. +# define FFSYNC O_FSYNC
  1957. +# define FASYNC O_ASYNC
  1958. +# define FNONBLOCK O_NONBLOCK
  1959. +# define FNDELAY O_NDELAY
  1960. +#endif /* Use BSD. */
  1961. +
  1962. +/* Advise to `posix_fadvise'. */
  1963. +#ifdef __USE_XOPEN2K
  1964. +# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
  1965. +# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
  1966. +# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
  1967. +# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
  1968. +# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
  1969. +# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
  1970. +#endif
  1971. diff --git a/libc/sysdeps/linux/avr32/bits/kernel_stat.h b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
  1972. new file mode 100644
  1973. index 0000000..f97d23b
  1974. --- /dev/null
  1975. +++ b/libc/sysdeps/linux/avr32/bits/kernel_stat.h
  1976. @@ -0,0 +1,67 @@
  1977. +#ifndef _BITS_STAT_STRUCT_H
  1978. +#define _BITS_STAT_STRUCT_H
  1979. +
  1980. +#ifndef _LIBC
  1981. +#error bits/kernel_stat.h is for internal uClibc use only!
  1982. +#endif
  1983. +
  1984. +/*
  1985. + * This file provides struct stat, taken from kernel 2.6.4. Verified
  1986. + * to match kernel 2.6.22.
  1987. + */
  1988. +
  1989. +struct kernel_stat {
  1990. + unsigned long st_dev;
  1991. + unsigned long st_ino;
  1992. + unsigned short st_mode;
  1993. + unsigned short st_nlink;
  1994. + unsigned short st_uid;
  1995. + unsigned short st_gid;
  1996. + unsigned long st_rdev;
  1997. + unsigned long st_size;
  1998. + unsigned long st_blksize;
  1999. + unsigned long st_blocks;
  2000. + unsigned long st_atime;
  2001. + unsigned long st_atime_nsec;
  2002. + unsigned long st_mtime;
  2003. + unsigned long st_mtime_nsec;
  2004. + unsigned long st_ctime;
  2005. + unsigned long st_ctime_nsec;
  2006. + unsigned long __unused4;
  2007. + unsigned long __unused5;
  2008. +};
  2009. +
  2010. +#define STAT_HAVE_NSEC 1
  2011. +
  2012. +struct kernel_stat64 {
  2013. + unsigned long long st_dev;
  2014. +
  2015. + unsigned long long st_ino;
  2016. + unsigned int st_mode;
  2017. + unsigned int st_nlink;
  2018. +
  2019. + unsigned long st_uid;
  2020. + unsigned long st_gid;
  2021. +
  2022. + unsigned long long st_rdev;
  2023. +
  2024. + long long st_size;
  2025. + unsigned long __pad1;
  2026. + unsigned long st_blksize;
  2027. +
  2028. + unsigned long long st_blocks;
  2029. +
  2030. + unsigned long st_atime;
  2031. + unsigned long st_atime_nsec;
  2032. +
  2033. + unsigned long st_mtime;
  2034. + unsigned long st_mtime_nsec;
  2035. +
  2036. + unsigned long st_ctime;
  2037. + unsigned long st_ctime_nsec;
  2038. +
  2039. + unsigned long __unused1;
  2040. + unsigned long __unused2;
  2041. +};
  2042. +
  2043. +#endif /* _BITS_STAT_STRUCT_H */
  2044. diff --git a/libc/sysdeps/linux/avr32/bits/kernel_types.h b/libc/sysdeps/linux/avr32/bits/kernel_types.h
  2045. new file mode 100644
  2046. index 0000000..f7d8b52
  2047. --- /dev/null
  2048. +++ b/libc/sysdeps/linux/avr32/bits/kernel_types.h
  2049. @@ -0,0 +1,55 @@
  2050. +/* Note that we use the exact same include guard #define names
  2051. + * as asm/posix_types.h. This will avoid gratuitous conflicts
  2052. + * with the posix_types.h kernel header, and will ensure that
  2053. + * our private content, and not the kernel header, will win.
  2054. + * -Erik
  2055. + */
  2056. +#ifndef __ASM_AVR32_POSIX_TYPES_H
  2057. +#define __ASM_AVR32_POSIX_TYPES_H
  2058. +
  2059. +/*
  2060. + * This file is generally used by user-level software, so you need to
  2061. + * be a little careful about namespace pollution etc. Also, we cannot
  2062. + * assume GCC is being used.
  2063. + */
  2064. +
  2065. +typedef unsigned long __kernel_dev_t;
  2066. +typedef unsigned long __kernel_ino_t;
  2067. +typedef unsigned short __kernel_mode_t;
  2068. +typedef unsigned short __kernel_nlink_t;
  2069. +typedef long __kernel_off_t;
  2070. +typedef int __kernel_pid_t;
  2071. +typedef unsigned short __kernel_ipc_pid_t;
  2072. +typedef unsigned int __kernel_uid_t;
  2073. +typedef unsigned int __kernel_gid_t;
  2074. +typedef unsigned long __kernel_size_t;
  2075. +typedef long __kernel_ssize_t;
  2076. +typedef int __kernel_ptrdiff_t;
  2077. +typedef long __kernel_time_t;
  2078. +typedef long __kernel_suseconds_t;
  2079. +typedef long __kernel_clock_t;
  2080. +typedef int __kernel_timer_t;
  2081. +typedef int __kernel_clockid_t;
  2082. +typedef int __kernel_daddr_t;
  2083. +typedef char * __kernel_caddr_t;
  2084. +typedef unsigned short __kernel_uid16_t;
  2085. +typedef unsigned short __kernel_gid16_t;
  2086. +typedef unsigned int __kernel_uid32_t;
  2087. +typedef unsigned int __kernel_gid32_t;
  2088. +typedef unsigned short __kernel_old_uid_t;
  2089. +typedef unsigned short __kernel_old_gid_t;
  2090. +typedef unsigned short __kernel_old_dev_t;
  2091. +
  2092. +#ifdef __GNUC__
  2093. +typedef long long __kernel_loff_t;
  2094. +#endif
  2095. +
  2096. +typedef struct {
  2097. +#if defined(__USE_ALL)
  2098. + int val[2];
  2099. +#else
  2100. + int __val[2];
  2101. +#endif
  2102. +} __kernel_fsid_t;
  2103. +
  2104. +#endif /* __ASM_AVR32_POSIX_TYPES_H */
  2105. diff --git a/libc/sysdeps/linux/avr32/bits/mman.h b/libc/sysdeps/linux/avr32/bits/mman.h
  2106. new file mode 100644
  2107. index 0000000..5f6e3c3
  2108. --- /dev/null
  2109. +++ b/libc/sysdeps/linux/avr32/bits/mman.h
  2110. @@ -0,0 +1,103 @@
  2111. +/* Definitions for POSIX memory map interface. Linux/AVR32 version.
  2112. + Copyright (C) 1997, 2000 Free Software Foundation, Inc.
  2113. + This file is part of the GNU C Library.
  2114. +
  2115. + The GNU C Library is free software; you can redistribute it and/or
  2116. + modify it under the terms of the GNU Lesser General Public
  2117. + License as published by the Free Software Foundation; either
  2118. + version 2.1 of the License, or (at your option) any later version.
  2119. +
  2120. + The GNU C Library is distributed in the hope that it will be useful,
  2121. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2122. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2123. + Lesser General Public License for more details.
  2124. +
  2125. + You should have received a copy of the GNU Lesser General Public
  2126. + License along with the GNU C Library; if not, write to the Free
  2127. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2128. + 02111-1307 USA. */
  2129. +
  2130. +#ifndef _SYS_MMAN_H
  2131. +# error "Never include this file directly. Use <sys/mman.h> instead"
  2132. +#endif
  2133. +
  2134. +/* The following definitions basically come from the kernel headers.
  2135. + But the kernel header is not namespace clean. */
  2136. +
  2137. +
  2138. +/* Protections are chosen from these bits, OR'd together. The
  2139. + implementation does not necessarily support PROT_EXEC or PROT_WRITE
  2140. + without PROT_READ. The only guarantees are that no writing will be
  2141. + allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */
  2142. +
  2143. +#define PROT_READ 0x1 /* Page can be read. */
  2144. +#define PROT_WRITE 0x2 /* Page can be written. */
  2145. +#define PROT_EXEC 0x4 /* Page can be executed. */
  2146. +#define PROT_NONE 0x0 /* Page can not be accessed. */
  2147. +#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
  2148. + growsdown vma (mprotect only). */
  2149. +#define PROT_GROWSUP 0x02000000 /* Extend change to start of
  2150. + growsup vma (mprotect only). */
  2151. +
  2152. +/* Sharing types (must choose one and only one of these). */
  2153. +#define MAP_SHARED 0x01 /* Share changes. */
  2154. +#define MAP_PRIVATE 0x02 /* Changes are private. */
  2155. +#ifdef __USE_MISC
  2156. +# define MAP_TYPE 0x0f /* Mask for type of mapping. */
  2157. +#endif
  2158. +
  2159. +/* Other flags. */
  2160. +#define MAP_FIXED 0x10 /* Interpret addr exactly. */
  2161. +#ifdef __USE_MISC
  2162. +# define MAP_FILE 0
  2163. +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */
  2164. +# define MAP_ANON MAP_ANONYMOUS
  2165. +#endif
  2166. +
  2167. +/* These are Linux-specific. */
  2168. +#ifdef __USE_MISC
  2169. +# define MAP_GROWSDOWN 0x0100 /* Stack-like segment. */
  2170. +# define MAP_DENYWRITE 0x0800 /* ETXTBSY */
  2171. +# define MAP_EXECUTABLE 0x1000 /* Mark it as an executable. */
  2172. +# define MAP_LOCKED 0x2000 /* Lock the mapping. */
  2173. +# define MAP_NORESERVE 0x4000 /* Don't check for reservations. */
  2174. +# define MAP_POPULATE 0x8000 /* populate (prefault) pagetables */
  2175. +# define MAP_NONBLOCK 0x10000 /* do not block on IO */
  2176. +#endif
  2177. +
  2178. +/* Flags to `msync'. */
  2179. +#define MS_ASYNC 1 /* Sync memory asynchronously. */
  2180. +#define MS_SYNC 4 /* Synchronous memory sync. */
  2181. +#define MS_INVALIDATE 2 /* Invalidate the caches. */
  2182. +
  2183. +/* Flags for `mlockall'. */
  2184. +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */
  2185. +#define MCL_FUTURE 2 /* Lock all additions to address
  2186. + space. */
  2187. +
  2188. +/* Flags for `mremap'. */
  2189. +#ifdef __USE_GNU
  2190. +# define MREMAP_MAYMOVE 1
  2191. +# define MREMAP_FIXED 2
  2192. +#endif
  2193. +
  2194. +/* Advise to `madvise'. */
  2195. +#ifdef __USE_BSD
  2196. +# define MADV_NORMAL 0 /* No further special treatment. */
  2197. +# define MADV_RANDOM 1 /* Expect random page references. */
  2198. +# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
  2199. +# define MADV_WILLNEED 3 /* Will need these pages. */
  2200. +# define MADV_DONTNEED 4 /* Don't need these pages. */
  2201. +# define MADV_REMOVE 9 /* Remove these pages and resources. */
  2202. +# define MADV_DONTFORK 10 /* Do not inherit across fork. */
  2203. +# define MADV_DOFORK 11 /* Do inherit across fork. */
  2204. +#endif
  2205. +
  2206. +/* The POSIX people had to invent similar names for the same things. */
  2207. +#ifdef __USE_XOPEN2K
  2208. +# define POSIX_MADV_NORMAL 0 /* No further special treatment. */
  2209. +# define POSIX_MADV_RANDOM 1 /* Expect random page references. */
  2210. +# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */
  2211. +# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */
  2212. +# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */
  2213. +#endif
  2214. diff --git a/libc/sysdeps/linux/avr32/bits/setjmp.h b/libc/sysdeps/linux/avr32/bits/setjmp.h
  2215. new file mode 100644
  2216. index 0000000..78348a3
  2217. --- /dev/null
  2218. +++ b/libc/sysdeps/linux/avr32/bits/setjmp.h
  2219. @@ -0,0 +1,30 @@
  2220. +/*
  2221. + * Copyright (C) 2004-2005 Atmel Corporation
  2222. + *
  2223. + * This file is subject to the terms and conditions of the GNU Lesser General
  2224. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2225. + * archive for more details.
  2226. + */
  2227. +#ifndef _BITS_SETJMP_H
  2228. +#define _BITS_SETJMP_H 1
  2229. +
  2230. +#if !defined _SETJMP_H && !defined _PTHREAD_H
  2231. +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
  2232. +#endif
  2233. +
  2234. +#ifndef _ASM
  2235. +/*
  2236. + * The jump buffer contains r0-r7, sr, sp and lr. Other registers are
  2237. + * not saved.
  2238. + */
  2239. +typedef int __jmp_buf[11];
  2240. +#endif
  2241. +
  2242. +#define __JMP_BUF_SP 4
  2243. +
  2244. +/* Test if longjmp to JMPBUF would unwind the frame containing a local
  2245. + variable at ADDRESS. */
  2246. +#define _JMPBUF_UNWINDS(jmpbuf, address) \
  2247. + ((void *)(address) < (void *)(jmpbuf[__JMP_BUF_SP]))
  2248. +
  2249. +#endif /* _BITS_SETJMP_H */
  2250. diff --git a/libc/sysdeps/linux/avr32/bits/stackinfo.h b/libc/sysdeps/linux/avr32/bits/stackinfo.h
  2251. new file mode 100644
  2252. index 0000000..29b8452
  2253. --- /dev/null
  2254. +++ b/libc/sysdeps/linux/avr32/bits/stackinfo.h
  2255. @@ -0,0 +1,28 @@
  2256. +/* Copyright (C) 1999 Free Software Foundation, Inc.
  2257. + This file is part of the GNU C Library.
  2258. +
  2259. + The GNU C Library is free software; you can redistribute it and/or
  2260. + modify it under the terms of the GNU Lesser General Public
  2261. + License as published by the Free Software Foundation; either
  2262. + version 2.1 of the License, or (at your option) any later version.
  2263. +
  2264. + The GNU C Library is distributed in the hope that it will be useful,
  2265. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2266. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2267. + Lesser General Public License for more details.
  2268. +
  2269. + You should have received a copy of the GNU Lesser General Public
  2270. + License along with the GNU C Library; if not, write to the Free
  2271. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2272. + 02111-1307 USA. */
  2273. +
  2274. +/* This file contains a bit of information about the stack allocation
  2275. + of the processor. */
  2276. +
  2277. +#ifndef _STACKINFO_H
  2278. +#define _STACKINFO_H 1
  2279. +
  2280. +/* On AVR32 the stack grows down. */
  2281. +#define _STACK_GROWS_DOWN 1
  2282. +
  2283. +#endif /* stackinfo.h */
  2284. diff --git a/libc/sysdeps/linux/avr32/bits/syscalls.h b/libc/sysdeps/linux/avr32/bits/syscalls.h
  2285. new file mode 100644
  2286. index 0000000..22ac059
  2287. --- /dev/null
  2288. +++ b/libc/sysdeps/linux/avr32/bits/syscalls.h
  2289. @@ -0,0 +1,143 @@
  2290. +#ifndef _BITS_SYSCALLS_H
  2291. +#define _BITS_SYSCALLS_H
  2292. +#ifndef _SYSCALL_H
  2293. +# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  2294. +#endif
  2295. +
  2296. +/*
  2297. + * This includes the `__NR_<name>' syscall numbers taken from the
  2298. + * Linux kernel header files. It also defines the traditional
  2299. + * `SYS_<name>' macros for older programs.
  2300. + */
  2301. +#include <bits/sysnum.h>
  2302. +
  2303. +#ifndef __ASSEMBLER__
  2304. +
  2305. +#include <errno.h>
  2306. +
  2307. +#define SYS_ify(syscall_name) (__NR_##syscall_name)
  2308. +
  2309. +#undef _syscall0
  2310. +#define _syscall0(type,name) \
  2311. + type name(void) \
  2312. + { \
  2313. + return (type)(INLINE_SYSCALL(name, 0)); \
  2314. + }
  2315. +
  2316. +#undef _syscall1
  2317. +#define _syscall1(type,name,type1,arg1) \
  2318. + type name(type1 arg1) \
  2319. + { \
  2320. + return (type)(INLINE_SYSCALL(name, 1, arg1)); \
  2321. + }
  2322. +
  2323. +#undef _syscall2
  2324. +#define _syscall2(type,name,type1,arg1,type2,arg2) \
  2325. + type name(type1 arg1, type2 arg2) \
  2326. + { \
  2327. + return (type)(INLINE_SYSCALL(name, 2, arg1, arg2)); \
  2328. + }
  2329. +
  2330. +#undef _syscall3
  2331. +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  2332. + type name(type1 arg1, type2 arg2, type3 arg3) \
  2333. + { \
  2334. + return (type)(INLINE_SYSCALL(name, 3, arg1, \
  2335. + arg2, arg3)); \
  2336. + }
  2337. +
  2338. +#undef _syscall4
  2339. +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3, \
  2340. + type4,arg4) \
  2341. + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  2342. + { \
  2343. + return (type)(INLINE_SYSCALL(name, 4, arg1, arg2, \
  2344. + arg3, arg4)); \
  2345. + }
  2346. +
  2347. +#undef _syscall5
  2348. +#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3, \
  2349. + type4,arg4,type5,arg5) \
  2350. + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2351. + type5 arg5) \
  2352. + { \
  2353. + return (type)(INLINE_SYSCALL(name, 5, arg1, arg2, \
  2354. + arg3, arg4, arg5)); \
  2355. + }
  2356. +
  2357. +#undef _syscall6
  2358. +#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3, \
  2359. + type4,arg4,type5,arg5,type6,arg6) \
  2360. + type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  2361. + type5 arg5, type6 arg6) \
  2362. + { \
  2363. + return (type)(INLINE_SYSCALL(name, 6, arg1, arg2, arg3, \
  2364. + arg4, arg5, arg6)); \
  2365. + }
  2366. +
  2367. +#undef unlikely
  2368. +#define unlikely(x) __builtin_expect((x), 0)
  2369. +
  2370. +#undef INLINE_SYSCALL
  2371. +#define INLINE_SYSCALL(name, nr, args...) \
  2372. + ({ \
  2373. + unsigned _sys_result = INTERNAL_SYSCALL(name, , nr, args); \
  2374. + if (unlikely(INTERNAL_SYSCALL_ERROR_P(_sys_result, ))) { \
  2375. + __set_errno(INTERNAL_SYSCALL_ERRNO(_sys_result, )); \
  2376. + _sys_result = (unsigned int) -1; \
  2377. + } \
  2378. + (int) _sys_result; \
  2379. + })
  2380. +
  2381. +#undef INTERNAL_SYSCALL_DECL
  2382. +#define INTERNAL_SYSCALL_DECL(err) do { } while(0)
  2383. +
  2384. +#undef INTERNAL_SYSCALL
  2385. +#define INTERNAL_SYSCALL(name, err, nr, args...) \
  2386. + ({ \
  2387. + register int _a1 asm ("r12"); \
  2388. + register int _scno asm("r8") = SYS_ify(name); \
  2389. + LOAD_ARGS_##nr (args); \
  2390. + asm volatile ("scall /* syscall " #name " */" \
  2391. + : "=r" (_a1) \
  2392. + : "r"(_scno) ASM_ARGS_##nr \
  2393. + : "cc", "memory"); \
  2394. + _a1; \
  2395. + })
  2396. +
  2397. +#undef INTERNAL_SYSCALL_ERROR_P
  2398. +#define INTERNAL_SYSCALL_ERROR_P(val, err) \
  2399. + ((unsigned int)(val) >= 0xfffff001U)
  2400. +
  2401. +#undef INTERNAL_SYSCALL_ERRNO
  2402. +#define INTERNAL_SYSCALL_ERRNO(val, errr) (-(val))
  2403. +
  2404. +#define LOAD_ARGS_0() do { } while(0)
  2405. +#define ASM_ARGS_0
  2406. +#define LOAD_ARGS_1(a1) \
  2407. + _a1 = (int) (a1); \
  2408. + LOAD_ARGS_0()
  2409. +#define ASM_ARGS_1 ASM_ARGS_0, "r"(_a1)
  2410. +#define LOAD_ARGS_2(a1, a2) \
  2411. + register int _a2 asm("r11") = (int)(a2); \
  2412. + LOAD_ARGS_1(a1)
  2413. +#define ASM_ARGS_2 ASM_ARGS_1, "r"(_a2)
  2414. +#define LOAD_ARGS_3(a1, a2, a3) \
  2415. + register int _a3 asm("r10") = (int)(a3); \
  2416. + LOAD_ARGS_2(a1, a2)
  2417. +#define ASM_ARGS_3 ASM_ARGS_2, "r"(_a3)
  2418. +#define LOAD_ARGS_4(a1, a2, a3, a4) \
  2419. + register int _a4 asm("r9") = (int)(a4); \
  2420. + LOAD_ARGS_3(a1, a2, a3)
  2421. +#define ASM_ARGS_4 ASM_ARGS_3, "r"(_a4)
  2422. +#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  2423. + register int _a5 asm("r5") = (int)(a5); \
  2424. + LOAD_ARGS_4(a1, a2, a3, a4)
  2425. +#define ASM_ARGS_5 ASM_ARGS_4, "r"(_a5)
  2426. +#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  2427. + register int _a6 asm("r3") = (int)(a6); \
  2428. + LOAD_ARGS_5(a1, a2, a3, a4, a5)
  2429. +#define ASM_ARGS_6 ASM_ARGS_5, "r"(_a6)
  2430. +
  2431. +#endif /* __ASSEMBLER__ */
  2432. +#endif /* _BITS_SYSCALLS_H */
  2433. diff --git a/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
  2434. new file mode 100644
  2435. index 0000000..e95e8a5
  2436. --- /dev/null
  2437. +++ b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
  2438. @@ -0,0 +1,45 @@
  2439. +/*
  2440. + * Track misc arch-specific features that aren't config options
  2441. + */
  2442. +
  2443. +#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
  2444. +#define _BITS_UCLIBC_ARCH_FEATURES_H
  2445. +
  2446. +/* instruction used when calling abort() to kill yourself */
  2447. +/* trigger illegal instruction exception, same as BUG in Linux */
  2448. +#define __UCLIBC_ABORT_INSTRUCTION__ ".short 0x5df0"
  2449. +
  2450. +/* can your target use syscall6() for mmap ? */
  2451. +#define __UCLIBC_MMAP_HAS_6_ARGS__
  2452. +
  2453. +/* does your target use syscall4() for truncate64 ? (32bit arches only) */
  2454. +#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__
  2455. +
  2456. +/* does your target have a broken create_module() ? */
  2457. +#undef __UCLIBC_BROKEN_CREATE_MODULE__
  2458. +
  2459. +/* does your target have to worry about older [gs]etrlimit() ? */
  2460. +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
  2461. +
  2462. +/* does your target prefix all symbols with an _ ? */
  2463. +#define __UCLIBC_NO_UNDERSCORES__
  2464. +
  2465. +/* does your target have an asm .set ? */
  2466. +#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
  2467. +
  2468. +/* define if target doesn't like .global */
  2469. +#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
  2470. +
  2471. +/* define if target supports .weak */
  2472. +#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
  2473. +
  2474. +/* define if target supports .weakext */
  2475. +#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
  2476. +
  2477. +/* needed probably only for ppc64 */
  2478. +#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
  2479. +
  2480. +/* define if target supports IEEE signed zero floats */
  2481. +#define __UCLIBC_HAVE_SIGNED_ZERO__
  2482. +
  2483. +#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
  2484. diff --git a/libc/sysdeps/linux/avr32/bits/wordsize.h b/libc/sysdeps/linux/avr32/bits/wordsize.h
  2485. new file mode 100644
  2486. index 0000000..1b5842a
  2487. --- /dev/null
  2488. +++ b/libc/sysdeps/linux/avr32/bits/wordsize.h
  2489. @@ -0,0 +1 @@
  2490. +#define __WORDSIZE 32
  2491. diff --git a/libc/sysdeps/linux/avr32/brk.c b/libc/sysdeps/linux/avr32/brk.c
  2492. new file mode 100644
  2493. index 0000000..a54b49a
  2494. --- /dev/null
  2495. +++ b/libc/sysdeps/linux/avr32/brk.c
  2496. @@ -0,0 +1,31 @@
  2497. +/*
  2498. + * Copyright (C) 2004-2007 Atmel Corporation
  2499. + *
  2500. + * This file is subject to the terms and conditions of the GNU Lesser General
  2501. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2502. + * archive for more details.
  2503. + */
  2504. +#include <errno.h>
  2505. +#include <unistd.h>
  2506. +#include <sys/syscall.h>
  2507. +
  2508. +libc_hidden_proto(brk)
  2509. +
  2510. +void *__curbrk attribute_hidden = 0;
  2511. +
  2512. +int brk (void *addr)
  2513. +{
  2514. + void *newbrk;
  2515. +
  2516. + newbrk = (void *)INLINE_SYSCALL(brk, 1, addr);
  2517. +
  2518. + __curbrk = newbrk;
  2519. +
  2520. + if (newbrk < addr) {
  2521. + __set_errno (ENOMEM);
  2522. + return -1;
  2523. + }
  2524. +
  2525. + return 0;
  2526. +}
  2527. +libc_hidden_def(brk)
  2528. diff --git a/libc/sysdeps/linux/avr32/bsd-_setjmp.S b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
  2529. new file mode 100644
  2530. index 0000000..be66a10
  2531. --- /dev/null
  2532. +++ b/libc/sysdeps/linux/avr32/bsd-_setjmp.S
  2533. @@ -0,0 +1,16 @@
  2534. +/*
  2535. + * Copyright (C) 2004-2007 Atmel Corporation
  2536. + *
  2537. + * This file is subject to the terms and conditions of the GNU Lesser General
  2538. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2539. + * archive for more details.
  2540. + */
  2541. +
  2542. + /* This just does a tail-call to __sigsetjmp(env, 0) */
  2543. + .global _setjmp
  2544. + .type _setjmp,"function"
  2545. + .align 1
  2546. +_setjmp:
  2547. + mov r11, 0
  2548. + bral __GI___sigsetjmp
  2549. + .size _setjmp, . - _setjmp
  2550. diff --git a/libc/sysdeps/linux/avr32/bsd-setjmp.S b/libc/sysdeps/linux/avr32/bsd-setjmp.S
  2551. new file mode 100644
  2552. index 0000000..4635eeb
  2553. --- /dev/null
  2554. +++ b/libc/sysdeps/linux/avr32/bsd-setjmp.S
  2555. @@ -0,0 +1,16 @@
  2556. +/*
  2557. + * Copyright (C) 2004-2007 Atmel Corporation
  2558. + *
  2559. + * This file is subject to the terms and conditions of the GNU Lesser General
  2560. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2561. + * archive for more details.
  2562. + */
  2563. +
  2564. + /* This just does a tail-call to __sigsetjmp(env, 1) */
  2565. + .global setjmp
  2566. + .type setjmp,"function"
  2567. + .align 1
  2568. +setjmp:
  2569. + mov r11, 1
  2570. + bral __GI___sigsetjmp
  2571. + .size setjmp, . - setjmp
  2572. diff --git a/libc/sysdeps/linux/avr32/clone.c b/libc/sysdeps/linux/avr32/clone.c
  2573. new file mode 100644
  2574. index 0000000..e43b0f3
  2575. --- /dev/null
  2576. +++ b/libc/sysdeps/linux/avr32/clone.c
  2577. @@ -0,0 +1,41 @@
  2578. +/*
  2579. + * Copyright (C) 2004 Atmel Corporation
  2580. + *
  2581. + * This file is subject to the terms and conditions of the GNU Lesser General
  2582. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2583. + * archive for more details.
  2584. + */
  2585. +#include <errno.h>
  2586. +#include <sys/syscall.h>
  2587. +#include <unistd.h>
  2588. +
  2589. +/*
  2590. + * I don't know if we can be absolutely certain that the fn and arg
  2591. + * parameters are preserved when returning as the child. If the
  2592. + * compiler stores them in registers (r0-r7), they should be.
  2593. + */
  2594. +int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
  2595. +{
  2596. + register int (*_fn)(void *arg) = fn;
  2597. + register void *_arg = arg;
  2598. + int err;
  2599. +
  2600. + /* Sanity check the arguments */
  2601. + err = -EINVAL;
  2602. + if (!fn)
  2603. + goto syscall_error;
  2604. + if (!child_stack)
  2605. + goto syscall_error;
  2606. +
  2607. + err = INLINE_SYSCALL(clone, 2, flags, child_stack);
  2608. + if (err < 0)
  2609. + goto syscall_error;
  2610. + else if (err != 0)
  2611. + return err;
  2612. +
  2613. + _exit(_fn(_arg));
  2614. +
  2615. +syscall_error:
  2616. + __set_errno (-err);
  2617. + return -1;
  2618. +}
  2619. diff --git a/libc/sysdeps/linux/avr32/crt1.S b/libc/sysdeps/linux/avr32/crt1.S
  2620. new file mode 100644
  2621. index 0000000..ca1fa7a
  2622. --- /dev/null
  2623. +++ b/libc/sysdeps/linux/avr32/crt1.S
  2624. @@ -0,0 +1,97 @@
  2625. +/*
  2626. + * Copyright (C) 2004-2007 Atmel Corporation
  2627. + *
  2628. + * This file is subject to the terms and conditions of the GNU Lesser General
  2629. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2630. + * archive for more details.
  2631. + *
  2632. + * When we enter _start, the stack looks like this:
  2633. + * argc argument counter
  2634. + * argv[0] pointer to program name
  2635. + * argv[1..argc-1] pointers to program args
  2636. + * NULL
  2637. + * env[0..N] pointers to environment variables
  2638. + * NULL
  2639. + *
  2640. + * r12 contains a function pointer to be registered with `atexit'.
  2641. + * This is how the dynamic linker arranges to have DT_FINI functions
  2642. + * called for shared libraries that have been loaded before this
  2643. + * code runs.
  2644. + *
  2645. + * We're going to call the following function:
  2646. + * __uClibc_main(int (*main)(int, char **, char **), int argc,
  2647. + * char **argv, void (*app_init)(void), void (*app_fini)(void),
  2648. + * void (*rtld_fini)(void), void *stack_end)
  2649. + *
  2650. + * So we need to set up things as follows:
  2651. + * r12 = address of main
  2652. + * r11 = argc
  2653. + * r10 = &argv[0]
  2654. + * r9 = address of _init
  2655. + * r8 = address of _fini
  2656. + * sp[0] = whatever we got passed in r12
  2657. + */
  2658. +
  2659. +#include <features.h>
  2660. +
  2661. + .text
  2662. + .global _start
  2663. + .type _start, @function
  2664. +_start:
  2665. + /* Clear the frame pointer and link register since this is the outermost frame. */
  2666. + mov r7, 0
  2667. + mov lr, 0
  2668. +
  2669. + ld.w r11, sp++ /* argc */
  2670. + mov r10, sp /* &argv[0] */
  2671. +
  2672. + st.w --sp, r10 /* stack_end */
  2673. + st.w --sp, r12 /* rtld_fini */
  2674. +
  2675. +#ifdef __PIC__
  2676. + lddpc r6, .L_GOT
  2677. +.L_RGOT:
  2678. + rsub r6, pc
  2679. + lda.w r9, _init
  2680. + lda.w r8, _fini
  2681. + lda.w r12, main
  2682. +
  2683. + /* Ok, now run uClibc's main() -- should not return */
  2684. + call __uClibc_main
  2685. +
  2686. + .align 2
  2687. +.L_GOT:
  2688. + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
  2689. +#else
  2690. + lddpc r9, __init_addr /* app_init */
  2691. + lddpc r8, __fini_addr /* app_fini */
  2692. + lddpc r12, __main_addr /* main */
  2693. +
  2694. + /* Ok, now run uClibc's main() -- should not return */
  2695. + lddpc pc, ___uClibc_main_addr
  2696. +
  2697. + .align 2
  2698. +__init_addr:
  2699. + .long _init
  2700. +__fini_addr:
  2701. + .long _fini
  2702. +__main_addr:
  2703. + .long main
  2704. +___uClibc_main_addr:
  2705. + .long __uClibc_main
  2706. +#endif
  2707. + .size _start, . - _start
  2708. +
  2709. + /*
  2710. + * The LSB says we need this.
  2711. + */
  2712. + .section ".note.ABI-tag", "a"
  2713. + .align 4
  2714. + .long 2f - 1f /* namesz */
  2715. + .long 4f - 3f /* descsz */
  2716. + .long 1 /* type */
  2717. +1: .asciz "GNU" /* name */
  2718. +2: .align 4
  2719. +3: .long 0 /* Linux executable */
  2720. + .long 2,6,0 /* Earliest compatible kernel */
  2721. +4: .align 4
  2722. diff --git a/libc/sysdeps/linux/avr32/crti.S b/libc/sysdeps/linux/avr32/crti.S
  2723. new file mode 100644
  2724. index 0000000..3e132d0
  2725. --- /dev/null
  2726. +++ b/libc/sysdeps/linux/avr32/crti.S
  2727. @@ -0,0 +1,17 @@
  2728. +
  2729. + .section .init
  2730. + .align 2
  2731. + .global _init
  2732. + .type _init, @function
  2733. +_init:
  2734. + /* Use a four-byte instruction to avoid NOPs */
  2735. + stm --sp, r0-r7,lr
  2736. + .align 2
  2737. +
  2738. + .section .fini
  2739. + .align 2
  2740. + .global _fini
  2741. + .type _fini, @function
  2742. +_fini:
  2743. + stm --sp, r0-r7,lr
  2744. + .align 2
  2745. diff --git a/libc/sysdeps/linux/avr32/crtn.S b/libc/sysdeps/linux/avr32/crtn.S
  2746. new file mode 100644
  2747. index 0000000..577adcc
  2748. --- /dev/null
  2749. +++ b/libc/sysdeps/linux/avr32/crtn.S
  2750. @@ -0,0 +1,14 @@
  2751. +
  2752. + .section .init
  2753. + .align 2
  2754. + .global _init
  2755. + .type _init, @function
  2756. + ldm sp++, r0-r7,pc
  2757. + .size _init, . - _init
  2758. +
  2759. + .section .fini
  2760. + .align 2
  2761. + .global _fini
  2762. + .type _fini, @function
  2763. + ldm sp++, r0-r7,pc
  2764. + .size _fini, . - _fini
  2765. diff --git a/libc/sysdeps/linux/avr32/mmap.c b/libc/sysdeps/linux/avr32/mmap.c
  2766. new file mode 100644
  2767. index 0000000..2ee025a
  2768. --- /dev/null
  2769. +++ b/libc/sysdeps/linux/avr32/mmap.c
  2770. @@ -0,0 +1,33 @@
  2771. +/*
  2772. + * Copyright (C) 2004-2007 Atmel Corporation
  2773. + *
  2774. + * This file is subject to the terms and conditions of the GNU Lesser General
  2775. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2776. + * archive for more details.
  2777. + */
  2778. +
  2779. +#include <errno.h>
  2780. +#include <unistd.h>
  2781. +#include <sys/mman.h>
  2782. +#include <sys/syscall.h>
  2783. +
  2784. +libc_hidden_proto(mmap)
  2785. +
  2786. +static _syscall6(__ptr_t, mmap2, __ptr_t, addr, size_t, len, int, prot,
  2787. + int, flags, int, fd, __off_t, pgoff);
  2788. +
  2789. +__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
  2790. +{
  2791. + unsigned long page_size = sysconf(_SC_PAGESIZE);
  2792. + unsigned long pgoff;
  2793. +
  2794. + if (offset & (page_size - 1)) {
  2795. + __set_errno(EINVAL);
  2796. + return MAP_FAILED;
  2797. + }
  2798. +
  2799. + pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
  2800. +
  2801. + return mmap2(addr, len, prot, flags, fd, pgoff);
  2802. +}
  2803. +libc_hidden_def(mmap)
  2804. diff --git a/libc/sysdeps/linux/avr32/setjmp.S b/libc/sysdeps/linux/avr32/setjmp.S
  2805. new file mode 100644
  2806. index 0000000..7d0354b
  2807. --- /dev/null
  2808. +++ b/libc/sysdeps/linux/avr32/setjmp.S
  2809. @@ -0,0 +1,29 @@
  2810. +/*
  2811. + * Copyright (C) 2004-2007 Atmel Corporation
  2812. + *
  2813. + * This file is subject to the terms and conditions of the GNU Lesser General
  2814. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2815. + * archive for more details.
  2816. + */
  2817. +#define _SETJMP_H
  2818. +#define _ASM
  2819. +#include <bits/setjmp.h>
  2820. +
  2821. + .text
  2822. +
  2823. + .global __sigsetjmp
  2824. + .type __sigsetjmp,"function"
  2825. +
  2826. + .align 1
  2827. +__sigsetjmp:
  2828. + mustr r8
  2829. + stm r12, r0,r1,r2,r3,r4,r5,r6,r7,r8,sp,lr
  2830. +
  2831. + /*
  2832. + * Make a tail call to __sigjmp_save; it takes the same args
  2833. + * and is hidden so we don't need to mess around with the GOT.
  2834. + */
  2835. + rjmp __sigjmp_save
  2836. + .size __sigsetjmp, . - __sigsetjmp
  2837. +
  2838. +libc_hidden_def(__sigsetjmp)
  2839. diff --git a/libc/sysdeps/linux/avr32/sigaction.c b/libc/sysdeps/linux/avr32/sigaction.c
  2840. new file mode 100644
  2841. index 0000000..a97ff3d
  2842. --- /dev/null
  2843. +++ b/libc/sysdeps/linux/avr32/sigaction.c
  2844. @@ -0,0 +1,59 @@
  2845. +/*
  2846. + * Copyright (C) 2004-2007 Atmel Corporation
  2847. + *
  2848. + * This file is subject to the terms and conditions of the GNU Lesser General
  2849. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2850. + * archive for more details.
  2851. + */
  2852. +#include <errno.h>
  2853. +#include <signal.h>
  2854. +#include <string.h>
  2855. +#include <sys/syscall.h>
  2856. +#include <bits/kernel_sigaction.h>
  2857. +
  2858. +#define SA_RESTORER 0x04000000
  2859. +extern void __default_rt_sa_restorer(void);
  2860. +
  2861. +libc_hidden_proto(memcpy)
  2862. +
  2863. +/*
  2864. + * If act is not NULL, change the action for sig to *act.
  2865. + * If oact is not NULL, put the old action for sig in *oact.
  2866. + */
  2867. +int __libc_sigaction(int signum, const struct sigaction *act,
  2868. + struct sigaction *oldact)
  2869. +{
  2870. + struct kernel_sigaction kact, koact;
  2871. + int result;
  2872. +
  2873. + if (act) {
  2874. + kact.k_sa_handler = act->sa_handler;
  2875. + memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
  2876. + kact.sa_flags = act->sa_flags;
  2877. + if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK))
  2878. + kact.sa_restorer = act->sa_restorer;
  2879. + else
  2880. + kact.sa_restorer = __default_rt_sa_restorer;
  2881. + kact.sa_flags |= SA_RESTORER;
  2882. + }
  2883. +
  2884. + result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
  2885. + oldact ? __ptrvalue(&koact) : NULL,
  2886. + _NSIG / 8);
  2887. +
  2888. + if (oldact && result >= 0) {
  2889. + oldact->sa_handler = koact.k_sa_handler;
  2890. + memcpy(&oldact->sa_mask, &koact.sa_mask,
  2891. + sizeof(oldact->sa_mask));
  2892. + oldact->sa_flags = koact.sa_flags;
  2893. + oldact->sa_restorer = koact.sa_restorer;
  2894. + }
  2895. +
  2896. + return result;
  2897. +}
  2898. +
  2899. +#ifndef LIBC_SIGACTION
  2900. +libc_hidden_proto(sigaction)
  2901. +weak_alias(__libc_sigaction, sigaction)
  2902. +libc_hidden_weak(sigaction)
  2903. +#endif
  2904. diff --git a/libc/sysdeps/linux/avr32/sigrestorer.S b/libc/sysdeps/linux/avr32/sigrestorer.S
  2905. new file mode 100644
  2906. index 0000000..df6a1ba
  2907. --- /dev/null
  2908. +++ b/libc/sysdeps/linux/avr32/sigrestorer.S
  2909. @@ -0,0 +1,15 @@
  2910. +/*
  2911. + * Copyright (C) 2004 Atmel Corporation
  2912. + *
  2913. + * This file is subject to the terms and conditions of the GNU Lesser General
  2914. + * Public License. See the file "COPYING.LIB" in the main directory of this
  2915. + * archive for more details.
  2916. + */
  2917. +#include <sys/syscall.h>
  2918. +
  2919. + .global __default_rt_sa_restorer
  2920. + .type __default_rt_sa_restorer,"function"
  2921. + .align 1
  2922. +__default_rt_sa_restorer:
  2923. + mov r8, __NR_rt_sigreturn
  2924. + scall
  2925. diff --git a/libc/sysdeps/linux/avr32/sys/elf.h b/libc/sysdeps/linux/avr32/sys/elf.h
  2926. new file mode 100644
  2927. index 0000000..faa7310
  2928. --- /dev/null
  2929. +++ b/libc/sysdeps/linux/avr32/sys/elf.h
  2930. @@ -0,0 +1,26 @@
  2931. +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
  2932. + This file is part of the GNU C Library.
  2933. +
  2934. + The GNU C Library is free software; you can redistribute it and/or
  2935. + modify it under the terms of the GNU Lesser General Public
  2936. + License as published by the Free Software Foundation; either
  2937. + version 2.1 of the License, or (at your option) any later version.
  2938. +
  2939. + The GNU C Library is distributed in the hope that it will be useful,
  2940. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2941. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2942. + Lesser General Public License for more details.
  2943. +
  2944. + You should have received a copy of the GNU Lesser General Public
  2945. + License along with the GNU C Library; if not, write to the Free
  2946. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2947. + 02111-1307 USA. */
  2948. +
  2949. +#ifndef _SYS_ELF_H
  2950. +#define _SYS_ELF_H 1
  2951. +
  2952. +#warning "This header is obsolete; use <sys/procfs.h> instead."
  2953. +
  2954. +#include <sys/procfs.h>
  2955. +
  2956. +#endif /* sys/elf.h */
  2957. diff --git a/libc/sysdeps/linux/avr32/sys/procfs.h b/libc/sysdeps/linux/avr32/sys/procfs.h
  2958. new file mode 100644
  2959. index 0000000..3b37363
  2960. --- /dev/null
  2961. +++ b/libc/sysdeps/linux/avr32/sys/procfs.h
  2962. @@ -0,0 +1,123 @@
  2963. +/* Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
  2964. + This file is part of the GNU C Library.
  2965. +
  2966. + The GNU C Library is free software; you can redistribute it and/or
  2967. + modify it under the terms of the GNU Lesser General Public
  2968. + License as published by the Free Software Foundation; either
  2969. + version 2.1 of the License, or (at your option) any later version.
  2970. +
  2971. + The GNU C Library is distributed in the hope that it will be useful,
  2972. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2973. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2974. + Lesser General Public License for more details.
  2975. +
  2976. + You should have received a copy of the GNU Lesser General Public
  2977. + License along with the GNU C Library; if not, write to the Free
  2978. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2979. + 02111-1307 USA. */
  2980. +
  2981. +#ifndef _SYS_PROCFS_H
  2982. +#define _SYS_PROCFS_H 1
  2983. +
  2984. +/* This is somewhat modelled after the file of the same name on SVR4
  2985. + systems. It provides a definition of the core file format for ELF
  2986. + used on Linux. It doesn't have anything to do with the /proc file
  2987. + system, even though Linux has one.
  2988. +
  2989. + Anyway, the whole purpose of this file is for GDB and GDB only.
  2990. + Don't read too much into it. Don't use it for anything other than
  2991. + GDB unless you know what you are doing. */
  2992. +
  2993. +#include <features.h>
  2994. +#include <sys/time.h>
  2995. +#include <sys/types.h>
  2996. +#include <sys/user.h>
  2997. +
  2998. +__BEGIN_DECLS
  2999. +
  3000. +/* Type for a general-purpose register. */
  3001. +typedef unsigned long elf_greg_t;
  3002. +
  3003. +/* And the whole bunch of them. We could have used `struct
  3004. + user_regs' directly in the typedef, but tradition says that
  3005. + the register set is an array, which does have some peculiar
  3006. + semantics, so leave it that way. */
  3007. +#define ELF_NGREG (sizeof (struct user_regs) / sizeof(elf_greg_t))
  3008. +typedef elf_greg_t elf_gregset_t[ELF_NGREG];
  3009. +
  3010. +/* Register set for the floating-point registers. */
  3011. +typedef struct user_fpregs elf_fpregset_t;
  3012. +
  3013. +/* Signal info. */
  3014. +struct elf_siginfo
  3015. + {
  3016. + int si_signo; /* Signal number. */
  3017. + int si_code; /* Extra code. */
  3018. + int si_errno; /* Errno. */
  3019. + };
  3020. +
  3021. +/* Definitions to generate Intel SVR4-like core files. These mostly
  3022. + have the same names as the SVR4 types with "elf_" tacked on the
  3023. + front to prevent clashes with Linux definitions, and the typedef
  3024. + forms have been avoided. This is mostly like the SVR4 structure,
  3025. + but more Linuxy, with things that Linux does not support and which
  3026. + GDB doesn't really use excluded. */
  3027. +
  3028. +struct elf_prstatus
  3029. + {
  3030. + struct elf_siginfo pr_info; /* Info associated with signal. */
  3031. + short int pr_cursig; /* Current signal. */
  3032. + unsigned long int pr_sigpend; /* Set of pending signals. */
  3033. + unsigned long int pr_sighold; /* Set of held signals. */
  3034. + __pid_t pr_pid;
  3035. + __pid_t pr_ppid;
  3036. + __pid_t pr_pgrp;
  3037. + __pid_t pr_sid;
  3038. + struct timeval pr_utime; /* User time. */
  3039. + struct timeval pr_stime; /* System time. */
  3040. + struct timeval pr_cutime; /* Cumulative user time. */
  3041. + struct timeval pr_cstime; /* Cumulative system time. */
  3042. + elf_gregset_t pr_reg; /* GP registers. */
  3043. + int pr_fpvalid; /* True if math copro being used. */
  3044. + };
  3045. +
  3046. +
  3047. +#define ELF_PRARGSZ (80) /* Number of chars for args. */
  3048. +
  3049. +struct elf_prpsinfo
  3050. + {
  3051. + char pr_state; /* Numeric process state. */
  3052. + char pr_sname; /* Char for pr_state. */
  3053. + char pr_zomb; /* Zombie. */
  3054. + char pr_nice; /* Nice val. */
  3055. + unsigned long int pr_flag; /* Flags. */
  3056. + unsigned short int pr_uid;
  3057. + unsigned short int pr_gid;
  3058. + int pr_pid, pr_ppid, pr_pgrp, pr_sid;
  3059. + /* Lots missing */
  3060. + char pr_fname[16]; /* Filename of executable. */
  3061. + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
  3062. + };
  3063. +
  3064. +/* The rest of this file provides the types for emulation of the
  3065. + Solaris <proc_service.h> interfaces that should be implemented by
  3066. + users of libthread_db. */
  3067. +
  3068. +/* Addresses. */
  3069. +typedef void *psaddr_t;
  3070. +
  3071. +/* Register sets. Linux has different names. */
  3072. +typedef elf_gregset_t prgregset_t;
  3073. +typedef elf_fpregset_t prfpregset_t;
  3074. +
  3075. +/* We don't have any differences between processes and threads,
  3076. + therefore have only one PID type. */
  3077. +typedef __pid_t lwpid_t;
  3078. +
  3079. +/* Process status and info. In the end we do provide typedefs for them. */
  3080. +typedef struct elf_prstatus prstatus_t;
  3081. +typedef struct elf_prpsinfo prpsinfo_t;
  3082. +
  3083. +__END_DECLS
  3084. +
  3085. +#endif /* sys/procfs.h */
  3086. diff --git a/libc/sysdeps/linux/avr32/sys/ucontext.h b/libc/sysdeps/linux/avr32/sys/ucontext.h
  3087. new file mode 100644
  3088. index 0000000..82c7fe2
  3089. --- /dev/null
  3090. +++ b/libc/sysdeps/linux/avr32/sys/ucontext.h
  3091. @@ -0,0 +1,90 @@
  3092. +/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
  3093. + This file is part of the GNU C Library.
  3094. +
  3095. + The GNU C Library is free software; you can redistribute it and/or
  3096. + modify it under the terms of the GNU Lesser General Public
  3097. + License as published by the Free Software Foundation; either
  3098. + version 2.1 of the License, or (at your option) any later version.
  3099. +
  3100. + The GNU C Library is distributed in the hope that it will be useful,
  3101. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3102. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3103. + Lesser General Public License for more details.
  3104. +
  3105. + You should have received a copy of the GNU Lesser General Public
  3106. + License along with the GNU C Library; if not, write to the Free
  3107. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3108. + 02111-1307 USA. */
  3109. +
  3110. +/* Linux/AVR32 ABI compliant context switching support. */
  3111. +
  3112. +#ifndef _SYS_UCONTEXT_H
  3113. +#define _SYS_UCONTEXT_H 1
  3114. +
  3115. +#include <features.h>
  3116. +#include <signal.h>
  3117. +#include <sys/procfs.h>
  3118. +#include <bits/sigcontext.h>
  3119. +
  3120. +typedef int greg_t;
  3121. +
  3122. +/* Number of general registers. */
  3123. +#define NGREG 16
  3124. +
  3125. +/* Container for all general registers. */
  3126. +typedef elf_gregset_t gregset_t;
  3127. +
  3128. +/* Number of each register is the `gregset_t' array. */
  3129. +enum
  3130. +{
  3131. + R0 = 0,
  3132. +#define R0 R0
  3133. + R1 = 1,
  3134. +#define R1 R1
  3135. + R2 = 2,
  3136. +#define R2 R2
  3137. + R3 = 3,
  3138. +#define R3 R3
  3139. + R4 = 4,
  3140. +#define R4 R4
  3141. + R5 = 5,
  3142. +#define R5 R5
  3143. + R6 = 6,
  3144. +#define R6 R6
  3145. + R7 = 7,
  3146. +#define R7 R7
  3147. + R8 = 8,
  3148. +#define R8 R8
  3149. + R9 = 9,
  3150. +#define R9 R9
  3151. + R10 = 10,
  3152. +#define R10 R10
  3153. + R11 = 11,
  3154. +#define R11 R11
  3155. + R12 = 12,
  3156. +#define R12 R12
  3157. + R13 = 13,
  3158. +#define R13 R13
  3159. + R14 = 14,
  3160. +#define R14 R14
  3161. + R15 = 15
  3162. +#define R15 R15
  3163. +};
  3164. +
  3165. +/* Structure to describe FPU registers. */
  3166. +typedef elf_fpregset_t fpregset_t;
  3167. +
  3168. +/* Context to describe whole processor state. */
  3169. +typedef struct sigcontext mcontext_t;
  3170. +
  3171. +/* Userlevel context. */
  3172. +typedef struct ucontext
  3173. +{
  3174. + unsigned long uc_flags;
  3175. + struct ucontext *uc_link;
  3176. + stack_t uc_stack;
  3177. + mcontext_t uc_mcontext;
  3178. + sigset_t uc_sigmask; /* mask last for extensibility */
  3179. +} ucontext_t;
  3180. +
  3181. +#endif /* sys/ucontext.h */
  3182. diff --git a/libc/sysdeps/linux/avr32/sys/user.h b/libc/sysdeps/linux/avr32/sys/user.h
  3183. new file mode 100644
  3184. index 0000000..c0b3d38
  3185. --- /dev/null
  3186. +++ b/libc/sysdeps/linux/avr32/sys/user.h
  3187. @@ -0,0 +1,46 @@
  3188. +#ifndef _SYS_USER_H
  3189. +#define _SYS_USER_H
  3190. +
  3191. +struct user_fpregs
  3192. +{
  3193. +
  3194. +};
  3195. +
  3196. +struct user_regs
  3197. +{
  3198. + unsigned long sr;
  3199. + unsigned long pc;
  3200. + unsigned long lr;
  3201. + unsigned long sp;
  3202. + unsigned long r12;
  3203. + unsigned long r11;
  3204. + unsigned long r10;
  3205. + unsigned long r9;
  3206. + unsigned long r8;
  3207. + unsigned long r7;
  3208. + unsigned long r6;
  3209. + unsigned long r5;
  3210. + unsigned long r4;
  3211. + unsigned long r3;
  3212. + unsigned long r2;
  3213. + unsigned long r1;
  3214. + unsigned long r0;
  3215. + unsigned long r12_orig;
  3216. +};
  3217. +
  3218. +struct user
  3219. +{
  3220. + struct user_regs regs; /* general registers */
  3221. + size_t u_tsize; /* text size (pages) */
  3222. + size_t u_dsize; /* data size (pages) */
  3223. + size_t u_ssize; /* stack size (pages) */
  3224. + unsigned long start_code; /* text starting address */
  3225. + unsigned long start_data; /* data starting address */
  3226. + unsigned long start_stack; /* stack starting address */
  3227. + long int signal; /* signal causing core dump */
  3228. + struct user_regs * u_ar0; /* help gdb find registers */
  3229. + unsigned long magic; /* identifies a core file */
  3230. + char u_comm[32]; /* user command name */
  3231. +};
  3232. +
  3233. +#endif /* _SYS_USER_H */
  3234. diff --git a/libc/sysdeps/linux/avr32/syscall.S b/libc/sysdeps/linux/avr32/syscall.S
  3235. new file mode 100644
  3236. index 0000000..55c1b1f
  3237. --- /dev/null
  3238. +++ b/libc/sysdeps/linux/avr32/syscall.S
  3239. @@ -0,0 +1,71 @@
  3240. +/*
  3241. + * Copyright (C) 2004-2007 Atmel Corporation
  3242. + *
  3243. + * This file is subject to the terms and conditions of the GNU Lesser General
  3244. + * Public License. See the file "COPYING.LIB" in the main directory of this
  3245. + * archive for more details.
  3246. + */
  3247. +#include <features.h>
  3248. +
  3249. + .text
  3250. +
  3251. + /*
  3252. + * long int syscall(long int sysno, ...)
  3253. + */
  3254. + .global syscall
  3255. + .type syscall, @function
  3256. + .align 2
  3257. +syscall:
  3258. + stm --sp, r3,r5,r6,lr
  3259. + sub lr, sp, -16
  3260. + mov r8, r12
  3261. + ldm lr, r3,r5,r9-r12
  3262. + scall
  3263. + cp.w r12, -4095
  3264. + brlo .Ldone
  3265. +
  3266. +#ifdef __PIC__
  3267. + lddpc r6, .Lgot
  3268. +.Lgotcalc:
  3269. + rsub r6, pc
  3270. +# ifdef __UCLIBC_HAS_THREADS__
  3271. + rsub r3, r12, 0
  3272. + mcall r6[__errno_location@got]
  3273. + st.w r12[0], r3
  3274. +# else
  3275. + ld.w r3, r6[errno@got]
  3276. + neg r12
  3277. + st.w r3[0], r12
  3278. +# endif
  3279. +#else
  3280. +# ifdef __UCLIBC_HAS_THREADS__
  3281. + rsub r3, r12, 0
  3282. + mcall .Lerrno_location
  3283. + st.w r12[0], r3
  3284. +# else
  3285. + lddpc r3, .Lerrno
  3286. + neg r12
  3287. + st.w r3[0], r12
  3288. +# endif
  3289. +#endif
  3290. + mov r12, -1
  3291. +
  3292. +.Ldone:
  3293. + ldm sp++, r3,r5,r6,pc
  3294. +
  3295. + .align 2
  3296. +#ifdef __PIC__
  3297. +.Lgot:
  3298. + .long .Lgotcalc - _GLOBAL_OFFSET_TABLE_
  3299. +#else
  3300. +# ifdef __UCLIBC_HAS_THREADS__
  3301. +.Lerrno_location:
  3302. + .long __errno_location
  3303. +# else
  3304. +.Lerrno:
  3305. + .long errno
  3306. +# endif
  3307. +#endif
  3308. +
  3309. +
  3310. + .size syscall, . - syscall
  3311. diff --git a/libc/sysdeps/linux/avr32/vfork.S b/libc/sysdeps/linux/avr32/vfork.S
  3312. new file mode 100644
  3313. index 0000000..03ca99f
  3314. --- /dev/null
  3315. +++ b/libc/sysdeps/linux/avr32/vfork.S
  3316. @@ -0,0 +1,58 @@
  3317. +/*
  3318. + * Copyright (C) 2005 Atmel Corporation
  3319. + *
  3320. + * This file is subject to the terms and conditions of the GNU Lesser General
  3321. + * Public License. See the file "COPYING.LIB" in the main directory of this
  3322. + * archive for more details.
  3323. + */
  3324. +
  3325. +/*
  3326. + * Clone the process without copying the address space. The
  3327. + * calling process is suspended until the child either exits
  3328. + * or calls execve.
  3329. + *
  3330. + * This all means that we cannot rely on the stack to store
  3331. + * away registers, since they will be overwritten by the child
  3332. + * as soon as it makes another function call (e.g. execve()).
  3333. + * Fortunately, the Linux kernel preserves LR across system calls.
  3334. + */
  3335. +
  3336. +#include <features.h>
  3337. +#include <sys/syscall.h>
  3338. +
  3339. + .global __vfork
  3340. + .type __vfork,@function
  3341. + .align 1
  3342. +__vfork:
  3343. + mov r8, __NR_vfork
  3344. + scall
  3345. + cp.w r12, -4096
  3346. + retls r12
  3347. +
  3348. + /* vfork failed, so we may use the stack freely */
  3349. + pushm r4-r7,lr
  3350. +#ifdef __PIC__
  3351. + lddpc r6, .L_GOT
  3352. + rsub r4, r12, 0
  3353. +.L_RGOT:
  3354. + rsub r6, pc
  3355. + mcall r6[__errno_location@got]
  3356. +#else
  3357. + rsub r4, r12, 0
  3358. + mcall .L__errno_location
  3359. +#endif
  3360. + st.w r12[0], r4
  3361. + popm r4-r7,pc,r12=-1
  3362. +
  3363. + .align 2
  3364. +#ifdef __PIC__
  3365. +.L_GOT:
  3366. + .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
  3367. +#else
  3368. +.L__errno_location:
  3369. + .long __errno_location
  3370. +#endif
  3371. + .size __vfork, . - __vfork
  3372. +
  3373. +weak_alias(__vfork,vfork)
  3374. +libc_hidden_weak(vfork)
  3375. diff --git a/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
  3376. new file mode 100644
  3377. index 0000000..2e8a33b
  3378. --- /dev/null
  3379. +++ b/libpthread/linuxthreads.old/sysdeps/avr32/pt-machine.h
  3380. @@ -0,0 +1,73 @@
  3381. +/* Machine-dependent pthreads configuration and inline functions.
  3382. + *
  3383. + * Copyright (C) 2005-2007 Atmel Corporation
  3384. + *
  3385. + * This file is subject to the terms and conditions of the GNU Lesser General
  3386. + * Public License. See the file "COPYING.LIB" in the main directory of this
  3387. + * archive for more details.
  3388. + */
  3389. +#ifndef _PT_MACHINE_H
  3390. +#define _PT_MACHINE_H 1
  3391. +
  3392. +#include <features.h>
  3393. +
  3394. +static inline int
  3395. +_test_and_set (int *p, int v)
  3396. +{
  3397. + int result;
  3398. +
  3399. + __asm__ __volatile__(
  3400. + "/* Inline test and set */\n"
  3401. + " xchg %[old], %[mem], %[new]"
  3402. + : [old] "=&r"(result)
  3403. + : [mem] "r"(p), [new] "r"(v)
  3404. + : "memory");
  3405. +
  3406. + return result;
  3407. +}
  3408. +
  3409. +#ifndef PT_EI
  3410. +# define PT_EI extern inline
  3411. +#endif
  3412. +
  3413. +extern long int testandset (int *spinlock);
  3414. +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  3415. +
  3416. +/* Spinlock implementation; required. */
  3417. +PT_EI long int
  3418. +testandset (int *spinlock)
  3419. +{
  3420. + return _test_and_set(spinlock, 1);
  3421. +}
  3422. +
  3423. +
  3424. +/* Get some notion of the current stack. Need not be exactly the top
  3425. + of the stack, just something somewhere in the current frame. */
  3426. +#define CURRENT_STACK_FRAME stack_pointer
  3427. +register char * stack_pointer __asm__ ("sp");
  3428. +
  3429. +/* Compare-and-swap for semaphores. */
  3430. +
  3431. +#define HAS_COMPARE_AND_SWAP
  3432. +PT_EI int
  3433. +__compare_and_swap(long int *p, long int oldval, long int newval)
  3434. +{
  3435. + long int result;
  3436. +
  3437. + __asm__ __volatile__(
  3438. + "/* Inline compare and swap */\n"
  3439. + "1: ssrf 5\n"
  3440. + " ld.w %[result], %[mem]\n"
  3441. + " eor %[result], %[old]\n"
  3442. + " brne 2f\n"
  3443. + " stcond %[mem], %[new]\n"
  3444. + " brne 1b\n"
  3445. + "2:"
  3446. + : [result] "=&r"(result), [mem] "=m"(*p)
  3447. + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
  3448. + : "cc", "memory");
  3449. +
  3450. + return result;
  3451. +}
  3452. +
  3453. +#endif /* pt-machine.h */
  3454. diff --git a/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
  3455. new file mode 100644
  3456. index 0000000..fe12bf8
  3457. --- /dev/null
  3458. +++ b/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
  3459. @@ -0,0 +1,73 @@
  3460. +/* Machine-dependent pthreads configuration and inline functions.
  3461. + *
  3462. + * Copyright (C) 2005-2007 Atmel Corporation
  3463. + *
  3464. + * This file is subject to the terms and conditions of the GNU Lesser General
  3465. + * Public License. See the file "COPYING.LIB" in the main directory of this
  3466. + * archive for more details.
  3467. + */
  3468. +#ifndef _PT_MACHINE_H
  3469. +#define _PT_MACHINE_H 1
  3470. +
  3471. +#include <features.h>
  3472. +
  3473. +static inline int
  3474. +_test_and_set (int *p, int v) __THROW
  3475. +{
  3476. + int result;
  3477. +
  3478. + __asm__ __volatile__(
  3479. + "/* Inline test and set */\n"
  3480. + " xchg %[old], %[mem], %[new]"
  3481. + : [old] "=&r"(result)
  3482. + : [mem] "r"(p), [new] "r"(v)
  3483. + : "memory");
  3484. +
  3485. + return result;
  3486. +}
  3487. +
  3488. +#ifndef PT_EI
  3489. +# define PT_EI extern inline
  3490. +#endif
  3491. +
  3492. +extern long int testandset (int *spinlock);
  3493. +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  3494. +
  3495. +/* Spinlock implementation; required. */
  3496. +PT_EI long int
  3497. +testandset (int *spinlock)
  3498. +{
  3499. + return _test_and_set(spinlock, 1);
  3500. +}
  3501. +
  3502. +
  3503. +/* Get some notion of the current stack. Need not be exactly the top
  3504. + of the stack, just something somewhere in the current frame. */
  3505. +#define CURRENT_STACK_FRAME stack_pointer
  3506. +register char * stack_pointer __asm__ ("sp");
  3507. +
  3508. +/* Compare-and-swap for semaphores. */
  3509. +
  3510. +#define HAS_COMPARE_AND_SWAP
  3511. +PT_EI int
  3512. +__compare_and_swap(long int *p, long int oldval, long int newval)
  3513. +{
  3514. + int result;
  3515. +
  3516. + __asm__ __volatile__(
  3517. + "/* Inline compare and swap */\n"
  3518. + "1: ssrf 5\n"
  3519. + " ld.w %[result], %[mem]\n"
  3520. + " eor %[result], %[old]\n"
  3521. + " brne 2f\n"
  3522. + " stcond %[mem], %[new]\n"
  3523. + " brne 1b\n"
  3524. + "2:"
  3525. + : [result] "=&r"(result), [mem] "=m"(*p)
  3526. + : "m"(*p), [new] "r"(newval), [old] "r"(oldval)
  3527. + : "cc", "memory");
  3528. +
  3529. + return result == 0;
  3530. +}
  3531. +
  3532. +#endif /* pt-machine.h */
  3533. diff --git a/utils/ldd.c b/utils/ldd.c
  3534. index 75ad628..e34acd9 100644
  3535. --- a/utils/ldd.c
  3536. +++ b/utils/ldd.c
  3537. @@ -44,6 +44,11 @@
  3538. #define ELFCLASSM ELFCLASS32
  3539. #endif
  3540. +#if defined(__avr32__)
  3541. +#define MATCH_MACHINE(x) (x == EM_AVR32)
  3542. +#define ELFCLASSM ELFCLASS32
  3543. +#endif
  3544. +
  3545. #if defined(__s390__)
  3546. #define MATCH_MACHINE(x) (x == EM_S390)
  3547. #define ELFCLASSM ELFCLASS32