cris-tdep.c 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063
  1. /* Target dependent code for CRIS, for GDB, the GNU debugger.
  2. Copyright (C) 2001-2022 Free Software Foundation, Inc.
  3. Contributed by Axis Communications AB.
  4. Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
  5. This file is part of GDB.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include "defs.h"
  17. #include "frame.h"
  18. #include "frame-unwind.h"
  19. #include "frame-base.h"
  20. #include "trad-frame.h"
  21. #include "dwarf2/frame.h"
  22. #include "symtab.h"
  23. #include "inferior.h"
  24. #include "gdbtypes.h"
  25. #include "gdbcore.h"
  26. #include "gdbcmd.h"
  27. #include "target.h"
  28. #include "value.h"
  29. #include "opcode/cris.h"
  30. #include "osabi.h"
  31. #include "arch-utils.h"
  32. #include "regcache.h"
  33. #include "regset.h"
  34. #include "objfiles.h"
  35. #include "solib.h" /* Support for shared libraries. */
  36. #include "solib-svr4.h"
  37. #include "dis-asm.h"
  38. #include "cris-tdep.h"
  39. enum cris_num_regs
  40. {
  41. /* There are no floating point registers. Used in gdbserver low-linux.c. */
  42. NUM_FREGS = 0,
  43. /* There are 16 general registers. */
  44. NUM_GENREGS = 16,
  45. /* There are 16 special registers. */
  46. NUM_SPECREGS = 16,
  47. /* CRISv32 has a pseudo PC register, not noted here. */
  48. /* CRISv32 has 16 support registers. */
  49. NUM_SUPPREGS = 16
  50. };
  51. /* Register numbers of various important registers.
  52. CRIS_FP_REGNUM Contains address of executing stack frame.
  53. STR_REGNUM Contains the address of structure return values.
  54. RET_REGNUM Contains the return value when shorter than or equal to 32 bits
  55. ARG1_REGNUM Contains the first parameter to a function.
  56. ARG2_REGNUM Contains the second parameter to a function.
  57. ARG3_REGNUM Contains the third parameter to a function.
  58. ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
  59. gdbarch_sp_regnum Contains address of top of stack.
  60. gdbarch_pc_regnum Contains address of next instruction.
  61. SRP_REGNUM Subroutine return pointer register.
  62. BRP_REGNUM Breakpoint return pointer register. */
  63. enum cris_regnums
  64. {
  65. /* Enums with respect to the general registers, valid for all
  66. CRIS versions. The frame pointer is always in R8. */
  67. CRIS_FP_REGNUM = 8,
  68. /* ABI related registers. */
  69. STR_REGNUM = 9,
  70. RET_REGNUM = 10,
  71. ARG1_REGNUM = 10,
  72. ARG2_REGNUM = 11,
  73. ARG3_REGNUM = 12,
  74. ARG4_REGNUM = 13,
  75. /* Registers which happen to be common. */
  76. VR_REGNUM = 17,
  77. MOF_REGNUM = 23,
  78. SRP_REGNUM = 27,
  79. /* CRISv10 et al. specific registers. */
  80. P0_REGNUM = 16,
  81. P4_REGNUM = 20,
  82. CCR_REGNUM = 21,
  83. P8_REGNUM = 24,
  84. IBR_REGNUM = 25,
  85. IRP_REGNUM = 26,
  86. BAR_REGNUM = 28,
  87. DCCR_REGNUM = 29,
  88. BRP_REGNUM = 30,
  89. USP_REGNUM = 31,
  90. /* CRISv32 specific registers. */
  91. ACR_REGNUM = 15,
  92. BZ_REGNUM = 16,
  93. PID_REGNUM = 18,
  94. SRS_REGNUM = 19,
  95. WZ_REGNUM = 20,
  96. EXS_REGNUM = 21,
  97. EDA_REGNUM = 22,
  98. DZ_REGNUM = 24,
  99. EBP_REGNUM = 25,
  100. ERP_REGNUM = 26,
  101. NRP_REGNUM = 28,
  102. CCS_REGNUM = 29,
  103. CRISV32USP_REGNUM = 30, /* Shares name but not number with CRISv10. */
  104. SPC_REGNUM = 31,
  105. CRISV32PC_REGNUM = 32, /* Shares name but not number with CRISv10. */
  106. S0_REGNUM = 33,
  107. S1_REGNUM = 34,
  108. S2_REGNUM = 35,
  109. S3_REGNUM = 36,
  110. S4_REGNUM = 37,
  111. S5_REGNUM = 38,
  112. S6_REGNUM = 39,
  113. S7_REGNUM = 40,
  114. S8_REGNUM = 41,
  115. S9_REGNUM = 42,
  116. S10_REGNUM = 43,
  117. S11_REGNUM = 44,
  118. S12_REGNUM = 45,
  119. S13_REGNUM = 46,
  120. S14_REGNUM = 47,
  121. S15_REGNUM = 48,
  122. };
  123. extern const struct cris_spec_reg cris_spec_regs[];
  124. /* CRIS version, set via the user command 'set cris-version'. Affects
  125. register names and sizes. */
  126. static unsigned int usr_cmd_cris_version;
  127. /* Indicates whether to trust the above variable. */
  128. static bool usr_cmd_cris_version_valid = false;
  129. static const char cris_mode_normal[] = "normal";
  130. static const char cris_mode_guru[] = "guru";
  131. static const char *const cris_modes[] = {
  132. cris_mode_normal,
  133. cris_mode_guru,
  134. 0
  135. };
  136. /* CRIS mode, set via the user command 'set cris-mode'. Affects
  137. type of break instruction among other things. */
  138. static const char *usr_cmd_cris_mode = cris_mode_normal;
  139. /* Whether to make use of Dwarf-2 CFI (default on). */
  140. static bool usr_cmd_cris_dwarf2_cfi = true;
  141. /* Sigtramp identification code copied from i386-linux-tdep.c. */
  142. #define SIGTRAMP_INSN0 0x9c5f /* movu.w 0xXX, $r9 */
  143. #define SIGTRAMP_OFFSET0 0
  144. #define SIGTRAMP_INSN1 0xe93d /* break 13 */
  145. #define SIGTRAMP_OFFSET1 4
  146. static const unsigned short sigtramp_code[] =
  147. {
  148. SIGTRAMP_INSN0, 0x0077, /* movu.w $0x77, $r9 */
  149. SIGTRAMP_INSN1 /* break 13 */
  150. };
  151. #define SIGTRAMP_LEN (sizeof sigtramp_code)
  152. /* Note: same length as normal sigtramp code. */
  153. static const unsigned short rt_sigtramp_code[] =
  154. {
  155. SIGTRAMP_INSN0, 0x00ad, /* movu.w $0xad, $r9 */
  156. SIGTRAMP_INSN1 /* break 13 */
  157. };
  158. /* If PC is in a sigtramp routine, return the address of the start of
  159. the routine. Otherwise, return 0. */
  160. static CORE_ADDR
  161. cris_sigtramp_start (struct frame_info *this_frame)
  162. {
  163. CORE_ADDR pc = get_frame_pc (this_frame);
  164. gdb_byte buf[SIGTRAMP_LEN];
  165. if (!safe_frame_unwind_memory (this_frame, pc, buf))
  166. return 0;
  167. if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
  168. {
  169. if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
  170. return 0;
  171. pc -= SIGTRAMP_OFFSET1;
  172. if (!safe_frame_unwind_memory (this_frame, pc, buf))
  173. return 0;
  174. }
  175. if (memcmp (buf, sigtramp_code, SIGTRAMP_LEN) != 0)
  176. return 0;
  177. return pc;
  178. }
  179. /* If PC is in a RT sigtramp routine, return the address of the start of
  180. the routine. Otherwise, return 0. */
  181. static CORE_ADDR
  182. cris_rt_sigtramp_start (struct frame_info *this_frame)
  183. {
  184. CORE_ADDR pc = get_frame_pc (this_frame);
  185. gdb_byte buf[SIGTRAMP_LEN];
  186. if (!safe_frame_unwind_memory (this_frame, pc, buf))
  187. return 0;
  188. if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0)
  189. {
  190. if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1)
  191. return 0;
  192. pc -= SIGTRAMP_OFFSET1;
  193. if (!safe_frame_unwind_memory (this_frame, pc, buf))
  194. return 0;
  195. }
  196. if (memcmp (buf, rt_sigtramp_code, SIGTRAMP_LEN) != 0)
  197. return 0;
  198. return pc;
  199. }
  200. /* Assuming THIS_FRAME is a frame for a GNU/Linux sigtramp routine,
  201. return the address of the associated sigcontext structure. */
  202. static CORE_ADDR
  203. cris_sigcontext_addr (struct frame_info *this_frame)
  204. {
  205. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  206. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  207. CORE_ADDR pc;
  208. CORE_ADDR sp;
  209. gdb_byte buf[4];
  210. get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
  211. sp = extract_unsigned_integer (buf, 4, byte_order);
  212. /* Look for normal sigtramp frame first. */
  213. pc = cris_sigtramp_start (this_frame);
  214. if (pc)
  215. {
  216. /* struct signal_frame (arch/cris/kernel/signal.c) contains
  217. struct sigcontext as its first member, meaning the SP points to
  218. it already. */
  219. return sp;
  220. }
  221. pc = cris_rt_sigtramp_start (this_frame);
  222. if (pc)
  223. {
  224. /* struct rt_signal_frame (arch/cris/kernel/signal.c) contains
  225. a struct ucontext, which in turn contains a struct sigcontext.
  226. Magic digging:
  227. 4 + 4 + 128 to struct ucontext, then
  228. 4 + 4 + 12 to struct sigcontext. */
  229. return (sp + 156);
  230. }
  231. error (_("Couldn't recognize signal trampoline."));
  232. return 0;
  233. }
  234. struct cris_unwind_cache
  235. {
  236. /* The previous frame's inner most stack address. Used as this
  237. frame ID's stack_addr. */
  238. CORE_ADDR prev_sp;
  239. /* The frame's base, optionally used by the high-level debug info. */
  240. CORE_ADDR base;
  241. int size;
  242. /* How far the SP and r8 (FP) have been offset from the start of
  243. the stack frame (as defined by the previous frame's stack
  244. pointer). */
  245. LONGEST sp_offset;
  246. LONGEST r8_offset;
  247. int uses_frame;
  248. /* From old frame_extra_info struct. */
  249. CORE_ADDR return_pc;
  250. int leaf_function;
  251. /* Table indicating the location of each and every register. */
  252. trad_frame_saved_reg *saved_regs;
  253. };
  254. static struct cris_unwind_cache *
  255. cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
  256. void **this_cache)
  257. {
  258. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  259. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  260. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  261. struct cris_unwind_cache *info;
  262. CORE_ADDR addr;
  263. gdb_byte buf[4];
  264. int i;
  265. if ((*this_cache))
  266. return (struct cris_unwind_cache *) (*this_cache);
  267. info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
  268. (*this_cache) = info;
  269. info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
  270. /* Zero all fields. */
  271. info->prev_sp = 0;
  272. info->base = 0;
  273. info->size = 0;
  274. info->sp_offset = 0;
  275. info->r8_offset = 0;
  276. info->uses_frame = 0;
  277. info->return_pc = 0;
  278. info->leaf_function = 0;
  279. get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf);
  280. info->base = extract_unsigned_integer (buf, 4, byte_order);
  281. addr = cris_sigcontext_addr (this_frame);
  282. /* Layout of the sigcontext struct:
  283. struct sigcontext {
  284. struct pt_regs regs;
  285. unsigned long oldmask;
  286. unsigned long usp;
  287. }; */
  288. if (tdep->cris_version == 10)
  289. {
  290. /* R0 to R13 are stored in reverse order at offset (2 * 4) in
  291. struct pt_regs. */
  292. for (i = 0; i <= 13; i++)
  293. info->saved_regs[i].set_addr (addr + ((15 - i) * 4));
  294. info->saved_regs[MOF_REGNUM].set_addr (addr + (16 * 4));
  295. info->saved_regs[DCCR_REGNUM].set_addr (addr + (17 * 4));
  296. info->saved_regs[SRP_REGNUM].set_addr (addr + (18 * 4));
  297. /* Note: IRP is off by 2 at this point. There's no point in correcting
  298. it though since that will mean that the backtrace will show a PC
  299. different from what is shown when stopped. */
  300. info->saved_regs[IRP_REGNUM].set_addr (addr + (19 * 4));
  301. info->saved_regs[gdbarch_pc_regnum (gdbarch)]
  302. = info->saved_regs[IRP_REGNUM];
  303. info->saved_regs[gdbarch_sp_regnum (gdbarch)].set_addr (addr + (24 * 4));
  304. }
  305. else
  306. {
  307. /* CRISv32. */
  308. /* R0 to R13 are stored in order at offset (1 * 4) in
  309. struct pt_regs. */
  310. for (i = 0; i <= 13; i++)
  311. info->saved_regs[i].set_addr (addr + ((i + 1) * 4));
  312. info->saved_regs[ACR_REGNUM].set_addr (addr + (15 * 4));
  313. info->saved_regs[SRS_REGNUM].set_addr (addr + (16 * 4));
  314. info->saved_regs[MOF_REGNUM].set_addr (addr + (17 * 4));
  315. info->saved_regs[SPC_REGNUM].set_addr (addr + (18 * 4));
  316. info->saved_regs[CCS_REGNUM].set_addr (addr + (19 * 4));
  317. info->saved_regs[SRP_REGNUM].set_addr (addr + (20 * 4));
  318. info->saved_regs[ERP_REGNUM].set_addr (addr + (21 * 4));
  319. info->saved_regs[EXS_REGNUM].set_addr (addr + (22 * 4));
  320. info->saved_regs[EDA_REGNUM].set_addr (addr + (23 * 4));
  321. /* FIXME: If ERP is in a delay slot at this point then the PC will
  322. be wrong at this point. This problem manifests itself in the
  323. sigaltstack.exp test case, which occasionally generates FAILs when
  324. the signal is received while in a delay slot.
  325. This could be solved by a couple of read_memory_unsigned_integer and a
  326. trad_frame_set_value. */
  327. info->saved_regs[gdbarch_pc_regnum (gdbarch)]
  328. = info->saved_regs[ERP_REGNUM];
  329. info->saved_regs[gdbarch_sp_regnum (gdbarch)].set_addr (addr + (25 * 4));
  330. }
  331. return info;
  332. }
  333. static void
  334. cris_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache,
  335. struct frame_id *this_id)
  336. {
  337. struct cris_unwind_cache *cache =
  338. cris_sigtramp_frame_unwind_cache (this_frame, this_cache);
  339. (*this_id) = frame_id_build (cache->base, get_frame_pc (this_frame));
  340. }
  341. /* Forward declaration. */
  342. static struct value *cris_frame_prev_register (struct frame_info *this_frame,
  343. void **this_cache, int regnum);
  344. static struct value *
  345. cris_sigtramp_frame_prev_register (struct frame_info *this_frame,
  346. void **this_cache, int regnum)
  347. {
  348. /* Make sure we've initialized the cache. */
  349. cris_sigtramp_frame_unwind_cache (this_frame, this_cache);
  350. return cris_frame_prev_register (this_frame, this_cache, regnum);
  351. }
  352. static int
  353. cris_sigtramp_frame_sniffer (const struct frame_unwind *self,
  354. struct frame_info *this_frame,
  355. void **this_cache)
  356. {
  357. if (cris_sigtramp_start (this_frame)
  358. || cris_rt_sigtramp_start (this_frame))
  359. return 1;
  360. return 0;
  361. }
  362. static const struct frame_unwind cris_sigtramp_frame_unwind =
  363. {
  364. "cris sigtramp",
  365. SIGTRAMP_FRAME,
  366. default_frame_unwind_stop_reason,
  367. cris_sigtramp_frame_this_id,
  368. cris_sigtramp_frame_prev_register,
  369. NULL,
  370. cris_sigtramp_frame_sniffer
  371. };
  372. static int
  373. crisv32_single_step_through_delay (struct gdbarch *gdbarch,
  374. struct frame_info *this_frame)
  375. {
  376. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  377. ULONGEST erp;
  378. int ret = 0;
  379. if (tdep->cris_mode == cris_mode_guru)
  380. erp = get_frame_register_unsigned (this_frame, NRP_REGNUM);
  381. else
  382. erp = get_frame_register_unsigned (this_frame, ERP_REGNUM);
  383. if (erp & 0x1)
  384. {
  385. /* In delay slot - check if there's a breakpoint at the preceding
  386. instruction. */
  387. if (breakpoint_here_p (get_frame_address_space (this_frame), erp & ~0x1))
  388. ret = 1;
  389. }
  390. return ret;
  391. }
  392. /* The instruction environment needed to find single-step breakpoints. */
  393. typedef
  394. struct instruction_environment
  395. {
  396. unsigned long reg[NUM_GENREGS];
  397. unsigned long preg[NUM_SPECREGS];
  398. unsigned long branch_break_address;
  399. unsigned long delay_slot_pc;
  400. unsigned long prefix_value;
  401. int branch_found;
  402. int prefix_found;
  403. int invalid;
  404. int slot_needed;
  405. int delay_slot_pc_active;
  406. int xflag_found;
  407. int disable_interrupt;
  408. enum bfd_endian byte_order;
  409. } inst_env_type;
  410. /* Machine-dependencies in CRIS for opcodes. */
  411. /* Instruction sizes. */
  412. enum cris_instruction_sizes
  413. {
  414. INST_BYTE_SIZE = 0,
  415. INST_WORD_SIZE = 1,
  416. INST_DWORD_SIZE = 2
  417. };
  418. /* Addressing modes. */
  419. enum cris_addressing_modes
  420. {
  421. REGISTER_MODE = 1,
  422. INDIRECT_MODE = 2,
  423. AUTOINC_MODE = 3
  424. };
  425. /* Prefix addressing modes. */
  426. enum cris_prefix_addressing_modes
  427. {
  428. PREFIX_INDEX_MODE = 2,
  429. PREFIX_ASSIGN_MODE = 3,
  430. /* Handle immediate byte offset addressing mode prefix format. */
  431. PREFIX_OFFSET_MODE = 2
  432. };
  433. /* Masks for opcodes. */
  434. enum cris_opcode_masks
  435. {
  436. BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
  437. SIGNED_EXTEND_BIT_MASK = 0x2,
  438. SIGNED_BYTE_MASK = 0x80,
  439. SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
  440. SIGNED_WORD_MASK = 0x8000,
  441. SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
  442. SIGNED_DWORD_MASK = 0x80000000,
  443. SIGNED_QUICK_VALUE_MASK = 0x20,
  444. SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
  445. };
  446. /* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
  447. Bit 15 - 12 Operand2
  448. 11 - 10 Mode
  449. 9 - 6 Opcode
  450. 5 - 4 Size
  451. 3 - 0 Operand1 */
  452. static int
  453. cris_get_operand2 (unsigned short insn)
  454. {
  455. return ((insn & 0xF000) >> 12);
  456. }
  457. static int
  458. cris_get_mode (unsigned short insn)
  459. {
  460. return ((insn & 0x0C00) >> 10);
  461. }
  462. static int
  463. cris_get_opcode (unsigned short insn)
  464. {
  465. return ((insn & 0x03C0) >> 6);
  466. }
  467. static int
  468. cris_get_size (unsigned short insn)
  469. {
  470. return ((insn & 0x0030) >> 4);
  471. }
  472. static int
  473. cris_get_operand1 (unsigned short insn)
  474. {
  475. return (insn & 0x000F);
  476. }
  477. /* Additional functions in order to handle opcodes. */
  478. static int
  479. cris_get_quick_value (unsigned short insn)
  480. {
  481. return (insn & 0x003F);
  482. }
  483. static int
  484. cris_get_bdap_quick_offset (unsigned short insn)
  485. {
  486. return (insn & 0x00FF);
  487. }
  488. static int
  489. cris_get_branch_short_offset (unsigned short insn)
  490. {
  491. return (insn & 0x00FF);
  492. }
  493. static int
  494. cris_get_asr_shift_steps (unsigned long value)
  495. {
  496. return (value & 0x3F);
  497. }
  498. static int
  499. cris_get_clear_size (unsigned short insn)
  500. {
  501. return ((insn) & 0xC000);
  502. }
  503. static int
  504. cris_is_signed_extend_bit_on (unsigned short insn)
  505. {
  506. return (((insn) & 0x20) == 0x20);
  507. }
  508. static int
  509. cris_is_xflag_bit_on (unsigned short insn)
  510. {
  511. return (((insn) & 0x1000) == 0x1000);
  512. }
  513. static void
  514. cris_set_size_to_dword (unsigned short *insn)
  515. {
  516. *insn &= 0xFFCF;
  517. *insn |= 0x20;
  518. }
  519. static signed char
  520. cris_get_signed_offset (unsigned short insn)
  521. {
  522. return ((signed char) (insn & 0x00FF));
  523. }
  524. /* Calls an op function given the op-type, working on the insn and the
  525. inst_env. */
  526. static void cris_gdb_func (struct gdbarch *, enum cris_op_type, unsigned short,
  527. inst_env_type *);
  528. static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
  529. struct gdbarch_list *);
  530. static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
  531. static void set_cris_version (const char *ignore_args, int from_tty,
  532. struct cmd_list_element *c);
  533. static void set_cris_mode (const char *ignore_args, int from_tty,
  534. struct cmd_list_element *c);
  535. static void set_cris_dwarf2_cfi (const char *ignore_args, int from_tty,
  536. struct cmd_list_element *c);
  537. static CORE_ADDR cris_scan_prologue (CORE_ADDR pc,
  538. struct frame_info *this_frame,
  539. struct cris_unwind_cache *info);
  540. static CORE_ADDR crisv32_scan_prologue (CORE_ADDR pc,
  541. struct frame_info *this_frame,
  542. struct cris_unwind_cache *info);
  543. /* When arguments must be pushed onto the stack, they go on in reverse
  544. order. The below implements a FILO (stack) to do this.
  545. Copied from d10v-tdep.c. */
  546. struct stack_item
  547. {
  548. int len;
  549. struct stack_item *prev;
  550. gdb_byte *data;
  551. };
  552. static struct stack_item *
  553. push_stack_item (struct stack_item *prev, const gdb_byte *contents, int len)
  554. {
  555. struct stack_item *si = XNEW (struct stack_item);
  556. si->data = (gdb_byte *) xmalloc (len);
  557. si->len = len;
  558. si->prev = prev;
  559. memcpy (si->data, contents, len);
  560. return si;
  561. }
  562. static struct stack_item *
  563. pop_stack_item (struct stack_item *si)
  564. {
  565. struct stack_item *dead = si;
  566. si = si->prev;
  567. xfree (dead->data);
  568. xfree (dead);
  569. return si;
  570. }
  571. /* Put here the code to store, into fi->saved_regs, the addresses of
  572. the saved registers of frame described by FRAME_INFO. This
  573. includes special registers such as pc and fp saved in special ways
  574. in the stack frame. sp is even more special: the address we return
  575. for it IS the sp for the next frame. */
  576. static struct cris_unwind_cache *
  577. cris_frame_unwind_cache (struct frame_info *this_frame,
  578. void **this_prologue_cache)
  579. {
  580. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  581. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  582. struct cris_unwind_cache *info;
  583. if ((*this_prologue_cache))
  584. return (struct cris_unwind_cache *) (*this_prologue_cache);
  585. info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache);
  586. (*this_prologue_cache) = info;
  587. info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
  588. /* Zero all fields. */
  589. info->prev_sp = 0;
  590. info->base = 0;
  591. info->size = 0;
  592. info->sp_offset = 0;
  593. info->r8_offset = 0;
  594. info->uses_frame = 0;
  595. info->return_pc = 0;
  596. info->leaf_function = 0;
  597. /* Prologue analysis does the rest... */
  598. if (tdep->cris_version == 32)
  599. crisv32_scan_prologue (get_frame_func (this_frame), this_frame, info);
  600. else
  601. cris_scan_prologue (get_frame_func (this_frame), this_frame, info);
  602. return info;
  603. }
  604. /* Given a GDB frame, determine the address of the calling function's
  605. frame. This will be used to create a new GDB frame struct. */
  606. static void
  607. cris_frame_this_id (struct frame_info *this_frame,
  608. void **this_prologue_cache,
  609. struct frame_id *this_id)
  610. {
  611. struct cris_unwind_cache *info
  612. = cris_frame_unwind_cache (this_frame, this_prologue_cache);
  613. CORE_ADDR base;
  614. CORE_ADDR func;
  615. struct frame_id id;
  616. /* The FUNC is easy. */
  617. func = get_frame_func (this_frame);
  618. /* Hopefully the prologue analysis either correctly determined the
  619. frame's base (which is the SP from the previous frame), or set
  620. that base to "NULL". */
  621. base = info->prev_sp;
  622. if (base == 0)
  623. return;
  624. id = frame_id_build (base, func);
  625. (*this_id) = id;
  626. }
  627. static struct value *
  628. cris_frame_prev_register (struct frame_info *this_frame,
  629. void **this_prologue_cache, int regnum)
  630. {
  631. struct cris_unwind_cache *info
  632. = cris_frame_unwind_cache (this_frame, this_prologue_cache);
  633. return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
  634. }
  635. static CORE_ADDR
  636. cris_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
  637. {
  638. /* Align to the size of an instruction (so that they can safely be
  639. pushed onto the stack). */
  640. return sp & ~3;
  641. }
  642. static CORE_ADDR
  643. cris_push_dummy_code (struct gdbarch *gdbarch,
  644. CORE_ADDR sp, CORE_ADDR funaddr,
  645. struct value **args, int nargs,
  646. struct type *value_type,
  647. CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
  648. struct regcache *regcache)
  649. {
  650. /* Allocate space sufficient for a breakpoint. */
  651. sp = (sp - 4) & ~3;
  652. /* Store the address of that breakpoint */
  653. *bp_addr = sp;
  654. /* CRIS always starts the call at the callee's entry point. */
  655. *real_pc = funaddr;
  656. return sp;
  657. }
  658. static CORE_ADDR
  659. cris_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  660. struct regcache *regcache, CORE_ADDR bp_addr,
  661. int nargs, struct value **args, CORE_ADDR sp,
  662. function_call_return_method return_method,
  663. CORE_ADDR struct_addr)
  664. {
  665. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  666. int argreg;
  667. int argnum;
  668. struct stack_item *si = NULL;
  669. /* Push the return address. */
  670. regcache_cooked_write_unsigned (regcache, SRP_REGNUM, bp_addr);
  671. /* Are we returning a value using a structure return or a normal value
  672. return? struct_addr is the address of the reserved space for the return
  673. structure to be written on the stack. */
  674. if (return_method == return_method_struct)
  675. regcache_cooked_write_unsigned (regcache, STR_REGNUM, struct_addr);
  676. /* Now load as many as possible of the first arguments into registers,
  677. and push the rest onto the stack. */
  678. argreg = ARG1_REGNUM;
  679. for (argnum = 0; argnum < nargs; argnum++)
  680. {
  681. int len;
  682. const gdb_byte *val;
  683. int reg_demand;
  684. int i;
  685. len = TYPE_LENGTH (value_type (args[argnum]));
  686. val = value_contents (args[argnum]).data ();
  687. /* How may registers worth of storage do we need for this argument? */
  688. reg_demand = (len / 4) + (len % 4 != 0 ? 1 : 0);
  689. if (len <= (2 * 4) && (argreg + reg_demand - 1 <= ARG4_REGNUM))
  690. {
  691. /* Data passed by value. Fits in available register(s). */
  692. for (i = 0; i < reg_demand; i++)
  693. {
  694. regcache->cooked_write (argreg, val);
  695. argreg++;
  696. val += 4;
  697. }
  698. }
  699. else if (len <= (2 * 4) && argreg <= ARG4_REGNUM)
  700. {
  701. /* Data passed by value. Does not fit in available register(s).
  702. Use the register(s) first, then the stack. */
  703. for (i = 0; i < reg_demand; i++)
  704. {
  705. if (argreg <= ARG4_REGNUM)
  706. {
  707. regcache->cooked_write (argreg, val);
  708. argreg++;
  709. val += 4;
  710. }
  711. else
  712. {
  713. /* Push item for later so that pushed arguments
  714. come in the right order. */
  715. si = push_stack_item (si, val, 4);
  716. val += 4;
  717. }
  718. }
  719. }
  720. else if (len > (2 * 4))
  721. {
  722. /* Data passed by reference. Push copy of data onto stack
  723. and pass pointer to this copy as argument. */
  724. sp = (sp - len) & ~3;
  725. write_memory (sp, val, len);
  726. if (argreg <= ARG4_REGNUM)
  727. {
  728. regcache_cooked_write_unsigned (regcache, argreg, sp);
  729. argreg++;
  730. }
  731. else
  732. {
  733. gdb_byte buf[4];
  734. store_unsigned_integer (buf, 4, byte_order, sp);
  735. si = push_stack_item (si, buf, 4);
  736. }
  737. }
  738. else
  739. {
  740. /* Data passed by value. No available registers. Put it on
  741. the stack. */
  742. si = push_stack_item (si, val, len);
  743. }
  744. }
  745. while (si)
  746. {
  747. /* fp_arg must be word-aligned (i.e., don't += len) to match
  748. the function prologue. */
  749. sp = (sp - si->len) & ~3;
  750. write_memory (sp, si->data, si->len);
  751. si = pop_stack_item (si);
  752. }
  753. /* Finally, update the SP register. */
  754. regcache_cooked_write_unsigned (regcache, gdbarch_sp_regnum (gdbarch), sp);
  755. return sp;
  756. }
  757. static const struct frame_unwind cris_frame_unwind =
  758. {
  759. "cris prologue",
  760. NORMAL_FRAME,
  761. default_frame_unwind_stop_reason,
  762. cris_frame_this_id,
  763. cris_frame_prev_register,
  764. NULL,
  765. default_frame_sniffer
  766. };
  767. static CORE_ADDR
  768. cris_frame_base_address (struct frame_info *this_frame, void **this_cache)
  769. {
  770. struct cris_unwind_cache *info
  771. = cris_frame_unwind_cache (this_frame, this_cache);
  772. return info->base;
  773. }
  774. static const struct frame_base cris_frame_base =
  775. {
  776. &cris_frame_unwind,
  777. cris_frame_base_address,
  778. cris_frame_base_address,
  779. cris_frame_base_address
  780. };
  781. /* Frames information. The definition of the struct frame_info is
  782. CORE_ADDR frame
  783. CORE_ADDR pc
  784. enum frame_type type;
  785. CORE_ADDR return_pc
  786. int leaf_function
  787. If the compilation option -fno-omit-frame-pointer is present the
  788. variable frame will be set to the content of R8 which is the frame
  789. pointer register.
  790. The variable pc contains the address where execution is performed
  791. in the present frame. The innermost frame contains the current content
  792. of the register PC. All other frames contain the content of the
  793. register PC in the next frame.
  794. The variable `type' indicates the frame's type: normal, SIGTRAMP
  795. (associated with a signal handler), dummy (associated with a dummy
  796. frame).
  797. The variable return_pc contains the address where execution should be
  798. resumed when the present frame has finished, the return address.
  799. The variable leaf_function is 1 if the return address is in the register
  800. SRP, and 0 if it is on the stack.
  801. Prologue instructions C-code.
  802. The prologue may consist of (-fno-omit-frame-pointer)
  803. 1) 2)
  804. push srp
  805. push r8 push r8
  806. move.d sp,r8 move.d sp,r8
  807. subq X,sp subq X,sp
  808. movem rY,[sp] movem rY,[sp]
  809. move.S rZ,[r8-U] move.S rZ,[r8-U]
  810. where 1 is a non-terminal function, and 2 is a leaf-function.
  811. Note that this assumption is extremely brittle, and will break at the
  812. slightest change in GCC's prologue.
  813. If local variables are declared or register contents are saved on stack
  814. the subq-instruction will be present with X as the number of bytes
  815. needed for storage. The reshuffle with respect to r8 may be performed
  816. with any size S (b, w, d) and any of the general registers Z={0..13}.
  817. The offset U should be representable by a signed 8-bit value in all cases.
  818. Thus, the prefix word is assumed to be immediate byte offset mode followed
  819. by another word containing the instruction.
  820. Degenerate cases:
  821. 3)
  822. push r8
  823. move.d sp,r8
  824. move.d r8,sp
  825. pop r8
  826. Prologue instructions C++-code.
  827. Case 1) and 2) in the C-code may be followed by
  828. move.d r10,rS ; this
  829. move.d r11,rT ; P1
  830. move.d r12,rU ; P2
  831. move.d r13,rV ; P3
  832. move.S [r8+U],rZ ; P4
  833. if any of the call parameters are stored. The host expects these
  834. instructions to be executed in order to get the call parameters right. */
  835. /* Examine the prologue of a function. The variable ip is the address of
  836. the first instruction of the prologue. The variable limit is the address
  837. of the first instruction after the prologue. The variable fi contains the
  838. information in struct frame_info. The variable frameless_p controls whether
  839. the entire prologue is examined (0) or just enough instructions to
  840. determine that it is a prologue (1). */
  841. static CORE_ADDR
  842. cris_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
  843. struct cris_unwind_cache *info)
  844. {
  845. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  846. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  847. /* Present instruction. */
  848. unsigned short insn;
  849. /* Next instruction, lookahead. */
  850. unsigned short insn_next;
  851. int regno;
  852. /* Number of byte on stack used for local variables and movem. */
  853. int val;
  854. /* Highest register number in a movem. */
  855. int regsave;
  856. /* move.d r<source_register>,rS */
  857. short source_register;
  858. /* Scan limit. */
  859. int limit;
  860. /* This frame is with respect to a leaf until a push srp is found. */
  861. if (info)
  862. {
  863. info->leaf_function = 1;
  864. }
  865. /* Assume nothing on stack. */
  866. val = 0;
  867. regsave = -1;
  868. /* If we were called without a this_frame, that means we were called
  869. from cris_skip_prologue which already tried to find the end of the
  870. prologue through the symbol information. 64 instructions past current
  871. pc is arbitrarily chosen, but at least it means we'll stop eventually. */
  872. limit = this_frame ? get_frame_pc (this_frame) : pc + 64;
  873. /* Find the prologue instructions. */
  874. while (pc > 0 && pc < limit)
  875. {
  876. insn = read_memory_unsigned_integer (pc, 2, byte_order);
  877. pc += 2;
  878. if (insn == 0xE1FC)
  879. {
  880. /* push <reg> 32 bit instruction. */
  881. insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
  882. pc += 2;
  883. regno = cris_get_operand2 (insn_next);
  884. if (info)
  885. {
  886. info->sp_offset += 4;
  887. }
  888. /* This check, meant to recognize srp, used to be regno ==
  889. (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
  890. if (insn_next == 0xBE7E)
  891. {
  892. if (info)
  893. {
  894. info->leaf_function = 0;
  895. }
  896. }
  897. else if (insn_next == 0x8FEE)
  898. {
  899. /* push $r8 */
  900. if (info)
  901. {
  902. info->r8_offset = info->sp_offset;
  903. }
  904. }
  905. }
  906. else if (insn == 0x866E)
  907. {
  908. /* move.d sp,r8 */
  909. if (info)
  910. {
  911. info->uses_frame = 1;
  912. }
  913. continue;
  914. }
  915. else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
  916. && cris_get_mode (insn) == 0x0000
  917. && cris_get_opcode (insn) == 0x000A)
  918. {
  919. /* subq <val>,sp */
  920. if (info)
  921. {
  922. info->sp_offset += cris_get_quick_value (insn);
  923. }
  924. }
  925. else if (cris_get_mode (insn) == 0x0002
  926. && cris_get_opcode (insn) == 0x000F
  927. && cris_get_size (insn) == 0x0003
  928. && cris_get_operand1 (insn) == gdbarch_sp_regnum (gdbarch))
  929. {
  930. /* movem r<regsave>,[sp] */
  931. regsave = cris_get_operand2 (insn);
  932. }
  933. else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch)
  934. && ((insn & 0x0F00) >> 8) == 0x0001
  935. && (cris_get_signed_offset (insn) < 0))
  936. {
  937. /* Immediate byte offset addressing prefix word with sp as base
  938. register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
  939. is between 64 and 128.
  940. movem r<regsave>,[sp=sp-<val>] */
  941. if (info)
  942. {
  943. info->sp_offset += -cris_get_signed_offset (insn);
  944. }
  945. insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
  946. pc += 2;
  947. if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
  948. && cris_get_opcode (insn_next) == 0x000F
  949. && cris_get_size (insn_next) == 0x0003
  950. && cris_get_operand1 (insn_next) == gdbarch_sp_regnum
  951. (gdbarch))
  952. {
  953. regsave = cris_get_operand2 (insn_next);
  954. }
  955. else
  956. {
  957. /* The prologue ended before the limit was reached. */
  958. pc -= 4;
  959. break;
  960. }
  961. }
  962. else if (cris_get_mode (insn) == 0x0001
  963. && cris_get_opcode (insn) == 0x0009
  964. && cris_get_size (insn) == 0x0002)
  965. {
  966. /* move.d r<10..13>,r<0..15> */
  967. source_register = cris_get_operand1 (insn);
  968. /* FIXME? In the glibc solibs, the prologue might contain something
  969. like (this example taken from relocate_doit):
  970. move.d $pc,$r0
  971. sub.d 0xfffef426,$r0
  972. which isn't covered by the source_register check below. Question
  973. is whether to add a check for this combo, or make better use of
  974. the limit variable instead. */
  975. if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
  976. {
  977. /* The prologue ended before the limit was reached. */
  978. pc -= 2;
  979. break;
  980. }
  981. }
  982. else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
  983. /* The size is a fixed-size. */
  984. && ((insn & 0x0F00) >> 8) == 0x0001
  985. /* A negative offset. */
  986. && (cris_get_signed_offset (insn) < 0))
  987. {
  988. /* move.S rZ,[r8-U] (?) */
  989. insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
  990. pc += 2;
  991. regno = cris_get_operand2 (insn_next);
  992. if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
  993. && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
  994. && cris_get_opcode (insn_next) == 0x000F)
  995. {
  996. /* move.S rZ,[r8-U] */
  997. continue;
  998. }
  999. else
  1000. {
  1001. /* The prologue ended before the limit was reached. */
  1002. pc -= 4;
  1003. break;
  1004. }
  1005. }
  1006. else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM
  1007. /* The size is a fixed-size. */
  1008. && ((insn & 0x0F00) >> 8) == 0x0001
  1009. /* A positive offset. */
  1010. && (cris_get_signed_offset (insn) > 0))
  1011. {
  1012. /* move.S [r8+U],rZ (?) */
  1013. insn_next = read_memory_unsigned_integer (pc, 2, byte_order);
  1014. pc += 2;
  1015. regno = cris_get_operand2 (insn_next);
  1016. if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
  1017. && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
  1018. && cris_get_opcode (insn_next) == 0x0009
  1019. && cris_get_operand1 (insn_next) == regno)
  1020. {
  1021. /* move.S [r8+U],rZ */
  1022. continue;
  1023. }
  1024. else
  1025. {
  1026. /* The prologue ended before the limit was reached. */
  1027. pc -= 4;
  1028. break;
  1029. }
  1030. }
  1031. else
  1032. {
  1033. /* The prologue ended before the limit was reached. */
  1034. pc -= 2;
  1035. break;
  1036. }
  1037. }
  1038. /* We only want to know the end of the prologue when this_frame and info
  1039. are NULL (called from cris_skip_prologue i.e.). */
  1040. if (this_frame == NULL && info == NULL)
  1041. {
  1042. return pc;
  1043. }
  1044. info->size = info->sp_offset;
  1045. /* Compute the previous frame's stack pointer (which is also the
  1046. frame's ID's stack address), and this frame's base pointer. */
  1047. if (info->uses_frame)
  1048. {
  1049. ULONGEST this_base;
  1050. /* The SP was moved to the FP. This indicates that a new frame
  1051. was created. Get THIS frame's FP value by unwinding it from
  1052. the next frame. */
  1053. this_base = get_frame_register_unsigned (this_frame, CRIS_FP_REGNUM);
  1054. info->base = this_base;
  1055. info->saved_regs[CRIS_FP_REGNUM].set_addr (info->base);
  1056. /* The FP points at the last saved register. Adjust the FP back
  1057. to before the first saved register giving the SP. */
  1058. info->prev_sp = info->base + info->r8_offset;
  1059. }
  1060. else
  1061. {
  1062. ULONGEST this_base;
  1063. /* Assume that the FP is this frame's SP but with that pushed
  1064. stack space added back. */
  1065. this_base = get_frame_register_unsigned (this_frame,
  1066. gdbarch_sp_regnum (gdbarch));
  1067. info->base = this_base;
  1068. info->prev_sp = info->base + info->size;
  1069. }
  1070. /* Calculate the addresses for the saved registers on the stack. */
  1071. /* FIXME: The address calculation should really be done on the fly while
  1072. we're analyzing the prologue (we only hold one regsave value as it is
  1073. now). */
  1074. val = info->sp_offset;
  1075. for (regno = regsave; regno >= 0; regno--)
  1076. {
  1077. info->saved_regs[regno].set_addr (info->base + info->r8_offset - val);
  1078. val -= 4;
  1079. }
  1080. /* The previous frame's SP needed to be computed. Save the computed
  1081. value. */
  1082. info->saved_regs[gdbarch_sp_regnum (gdbarch)].set_value (info->prev_sp);
  1083. if (!info->leaf_function)
  1084. {
  1085. /* SRP saved on the stack. But where? */
  1086. if (info->r8_offset == 0)
  1087. {
  1088. /* R8 not pushed yet. */
  1089. info->saved_regs[SRP_REGNUM].set_addr (info->base);
  1090. }
  1091. else
  1092. {
  1093. /* R8 pushed, but SP may or may not be moved to R8 yet. */
  1094. info->saved_regs[SRP_REGNUM].set_addr (info->base + 4);
  1095. }
  1096. }
  1097. /* The PC is found in SRP (the actual register or located on the stack). */
  1098. info->saved_regs[gdbarch_pc_regnum (gdbarch)]
  1099. = info->saved_regs[SRP_REGNUM];
  1100. return pc;
  1101. }
  1102. static CORE_ADDR
  1103. crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
  1104. struct cris_unwind_cache *info)
  1105. {
  1106. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1107. ULONGEST this_base;
  1108. /* Unlike the CRISv10 prologue scanner (cris_scan_prologue), this is not
  1109. meant to be a full-fledged prologue scanner. It is only needed for
  1110. the cases where we end up in code always lacking DWARF-2 CFI, notably:
  1111. * PLT stubs (library calls)
  1112. * call dummys
  1113. * signal trampolines
  1114. For those cases, it is assumed that there is no actual prologue; that
  1115. the stack pointer is not adjusted, and (as a consequence) the return
  1116. address is not pushed onto the stack. */
  1117. /* We only want to know the end of the prologue when this_frame and info
  1118. are NULL (called from cris_skip_prologue i.e.). */
  1119. if (this_frame == NULL && info == NULL)
  1120. {
  1121. return pc;
  1122. }
  1123. /* The SP is assumed to be unaltered. */
  1124. this_base = get_frame_register_unsigned (this_frame,
  1125. gdbarch_sp_regnum (gdbarch));
  1126. info->base = this_base;
  1127. info->prev_sp = this_base;
  1128. /* The PC is assumed to be found in SRP. */
  1129. info->saved_regs[gdbarch_pc_regnum (gdbarch)]
  1130. = info->saved_regs[SRP_REGNUM];
  1131. return pc;
  1132. }
  1133. /* Advance pc beyond any function entry prologue instructions at pc
  1134. to reach some "real" code. */
  1135. /* Given a PC value corresponding to the start of a function, return the PC
  1136. of the first instruction after the function prologue. */
  1137. static CORE_ADDR
  1138. cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  1139. {
  1140. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1141. CORE_ADDR func_addr, func_end;
  1142. struct symtab_and_line sal;
  1143. CORE_ADDR pc_after_prologue;
  1144. /* If we have line debugging information, then the end of the prologue
  1145. should the first assembly instruction of the first source line. */
  1146. if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
  1147. {
  1148. sal = find_pc_line (func_addr, 0);
  1149. if (sal.end > 0 && sal.end < func_end)
  1150. return sal.end;
  1151. }
  1152. if (tdep->cris_version == 32)
  1153. pc_after_prologue = crisv32_scan_prologue (pc, NULL, NULL);
  1154. else
  1155. pc_after_prologue = cris_scan_prologue (pc, NULL, NULL);
  1156. return pc_after_prologue;
  1157. }
  1158. /* Implement the breakpoint_kind_from_pc gdbarch method. */
  1159. static int
  1160. cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
  1161. {
  1162. return 2;
  1163. }
  1164. /* Implement the sw_breakpoint_from_kind gdbarch method. */
  1165. static const gdb_byte *
  1166. cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
  1167. {
  1168. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1169. static unsigned char break8_insn[] = {0x38, 0xe9};
  1170. static unsigned char break15_insn[] = {0x3f, 0xe9};
  1171. *size = kind;
  1172. if (tdep->cris_mode == cris_mode_guru)
  1173. return break15_insn;
  1174. else
  1175. return break8_insn;
  1176. }
  1177. /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
  1178. 0 otherwise. */
  1179. static int
  1180. cris_spec_reg_applicable (struct gdbarch *gdbarch,
  1181. struct cris_spec_reg spec_reg)
  1182. {
  1183. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1184. unsigned int version = tdep->cris_version;
  1185. switch (spec_reg.applicable_version)
  1186. {
  1187. case cris_ver_version_all:
  1188. return 1;
  1189. case cris_ver_warning:
  1190. /* Indeterminate/obsolete. */
  1191. return 0;
  1192. case cris_ver_v0_3:
  1193. return in_inclusive_range (version, 0U, 3U);
  1194. case cris_ver_v3p:
  1195. return (version >= 3);
  1196. case cris_ver_v8:
  1197. return in_inclusive_range (version, 8U, 9U);
  1198. case cris_ver_v8p:
  1199. return (version >= 8);
  1200. case cris_ver_v0_10:
  1201. return in_inclusive_range (version, 0U, 10U);
  1202. case cris_ver_v3_10:
  1203. return in_inclusive_range (version, 3U, 10U);
  1204. case cris_ver_v8_10:
  1205. return in_inclusive_range (version, 8U, 10U);
  1206. case cris_ver_v10:
  1207. return (version == 10);
  1208. case cris_ver_v10p:
  1209. return (version >= 10);
  1210. case cris_ver_v32p:
  1211. return (version >= 32);
  1212. default:
  1213. /* Invalid cris version. */
  1214. return 0;
  1215. }
  1216. }
  1217. /* Returns the register size in unit byte. Returns 0 for an unimplemented
  1218. register, -1 for an invalid register. */
  1219. static int
  1220. cris_register_size (struct gdbarch *gdbarch, int regno)
  1221. {
  1222. int i;
  1223. int spec_regno;
  1224. if (regno >= 0 && regno < NUM_GENREGS)
  1225. {
  1226. /* General registers (R0 - R15) are 32 bits. */
  1227. return 4;
  1228. }
  1229. else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
  1230. {
  1231. /* Special register (R16 - R31). cris_spec_regs is zero-based.
  1232. Adjust regno accordingly. */
  1233. spec_regno = regno - NUM_GENREGS;
  1234. for (i = 0; cris_spec_regs[i].name != NULL; i++)
  1235. {
  1236. if (cris_spec_regs[i].number == spec_regno
  1237. && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
  1238. /* Go with the first applicable register. */
  1239. return cris_spec_regs[i].reg_size;
  1240. }
  1241. /* Special register not applicable to this CRIS version. */
  1242. return 0;
  1243. }
  1244. else if (regno >= gdbarch_pc_regnum (gdbarch)
  1245. && regno < gdbarch_num_regs (gdbarch))
  1246. {
  1247. /* This will apply to CRISv32 only where there are additional registers
  1248. after the special registers (pseudo PC and support registers). */
  1249. return 4;
  1250. }
  1251. return -1;
  1252. }
  1253. /* Nonzero if regno should not be fetched from the target. This is the case
  1254. for unimplemented (size 0) and non-existant registers. */
  1255. static int
  1256. cris_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
  1257. {
  1258. return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
  1259. || (cris_register_size (gdbarch, regno) == 0));
  1260. }
  1261. /* Nonzero if regno should not be written to the target, for various
  1262. reasons. */
  1263. static int
  1264. cris_cannot_store_register (struct gdbarch *gdbarch, int regno)
  1265. {
  1266. /* There are three kinds of registers we refuse to write to.
  1267. 1. Those that not implemented.
  1268. 2. Those that are read-only (depends on the processor mode).
  1269. 3. Those registers to which a write has no effect. */
  1270. if (regno < 0
  1271. || regno >= gdbarch_num_regs (gdbarch)
  1272. || cris_register_size (gdbarch, regno) == 0)
  1273. /* Not implemented. */
  1274. return 1;
  1275. else if (regno == VR_REGNUM)
  1276. /* Read-only. */
  1277. return 1;
  1278. else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
  1279. /* Writing has no effect. */
  1280. return 1;
  1281. /* IBR, BAR, BRP and IRP are read-only in user mode. Let the debug
  1282. agent decide whether they are writable. */
  1283. return 0;
  1284. }
  1285. /* Nonzero if regno should not be fetched from the target. This is the case
  1286. for unimplemented (size 0) and non-existant registers. */
  1287. static int
  1288. crisv32_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
  1289. {
  1290. return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch))
  1291. || (cris_register_size (gdbarch, regno) == 0));
  1292. }
  1293. /* Nonzero if regno should not be written to the target, for various
  1294. reasons. */
  1295. static int
  1296. crisv32_cannot_store_register (struct gdbarch *gdbarch, int regno)
  1297. {
  1298. /* There are three kinds of registers we refuse to write to.
  1299. 1. Those that not implemented.
  1300. 2. Those that are read-only (depends on the processor mode).
  1301. 3. Those registers to which a write has no effect. */
  1302. if (regno < 0
  1303. || regno >= gdbarch_num_regs (gdbarch)
  1304. || cris_register_size (gdbarch, regno) == 0)
  1305. /* Not implemented. */
  1306. return 1;
  1307. else if (regno == VR_REGNUM)
  1308. /* Read-only. */
  1309. return 1;
  1310. else if (regno == BZ_REGNUM || regno == WZ_REGNUM || regno == DZ_REGNUM)
  1311. /* Writing has no effect. */
  1312. return 1;
  1313. /* Many special registers are read-only in user mode. Let the debug
  1314. agent decide whether they are writable. */
  1315. return 0;
  1316. }
  1317. /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
  1318. of data in register regno. */
  1319. static struct type *
  1320. cris_register_type (struct gdbarch *gdbarch, int regno)
  1321. {
  1322. if (regno == gdbarch_pc_regnum (gdbarch))
  1323. return builtin_type (gdbarch)->builtin_func_ptr;
  1324. else if (regno == gdbarch_sp_regnum (gdbarch)
  1325. || regno == CRIS_FP_REGNUM)
  1326. return builtin_type (gdbarch)->builtin_data_ptr;
  1327. else if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch))
  1328. || (regno >= MOF_REGNUM && regno <= USP_REGNUM))
  1329. /* Note: R8 taken care of previous clause. */
  1330. return builtin_type (gdbarch)->builtin_uint32;
  1331. else if (regno >= P4_REGNUM && regno <= CCR_REGNUM)
  1332. return builtin_type (gdbarch)->builtin_uint16;
  1333. else if (regno >= P0_REGNUM && regno <= VR_REGNUM)
  1334. return builtin_type (gdbarch)->builtin_uint8;
  1335. else
  1336. /* Invalid (unimplemented) register. */
  1337. return builtin_type (gdbarch)->builtin_int0;
  1338. }
  1339. static struct type *
  1340. crisv32_register_type (struct gdbarch *gdbarch, int regno)
  1341. {
  1342. if (regno == gdbarch_pc_regnum (gdbarch))
  1343. return builtin_type (gdbarch)->builtin_func_ptr;
  1344. else if (regno == gdbarch_sp_regnum (gdbarch)
  1345. || regno == CRIS_FP_REGNUM)
  1346. return builtin_type (gdbarch)->builtin_data_ptr;
  1347. else if ((regno >= 0 && regno <= ACR_REGNUM)
  1348. || (regno >= EXS_REGNUM && regno <= SPC_REGNUM)
  1349. || (regno == PID_REGNUM)
  1350. || (regno >= S0_REGNUM && regno <= S15_REGNUM))
  1351. /* Note: R8 and SP taken care of by previous clause. */
  1352. return builtin_type (gdbarch)->builtin_uint32;
  1353. else if (regno == WZ_REGNUM)
  1354. return builtin_type (gdbarch)->builtin_uint16;
  1355. else if (regno == BZ_REGNUM || regno == VR_REGNUM || regno == SRS_REGNUM)
  1356. return builtin_type (gdbarch)->builtin_uint8;
  1357. else
  1358. {
  1359. /* Invalid (unimplemented) register. Should not happen as there are
  1360. no unimplemented CRISv32 registers. */
  1361. warning (_("crisv32_register_type: unknown regno %d"), regno);
  1362. return builtin_type (gdbarch)->builtin_int0;
  1363. }
  1364. }
  1365. /* Stores a function return value of type type, where valbuf is the address
  1366. of the value to be stored. */
  1367. /* In the CRIS ABI, R10 and R11 are used to store return values. */
  1368. static void
  1369. cris_store_return_value (struct type *type, struct regcache *regcache,
  1370. const gdb_byte *valbuf)
  1371. {
  1372. struct gdbarch *gdbarch = regcache->arch ();
  1373. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1374. ULONGEST val;
  1375. int len = TYPE_LENGTH (type);
  1376. if (len <= 4)
  1377. {
  1378. /* Put the return value in R10. */
  1379. val = extract_unsigned_integer (valbuf, len, byte_order);
  1380. regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
  1381. }
  1382. else if (len <= 8)
  1383. {
  1384. /* Put the return value in R10 and R11. */
  1385. val = extract_unsigned_integer (valbuf, 4, byte_order);
  1386. regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val);
  1387. val = extract_unsigned_integer (valbuf + 4, len - 4, byte_order);
  1388. regcache_cooked_write_unsigned (regcache, ARG2_REGNUM, val);
  1389. }
  1390. else
  1391. error (_("cris_store_return_value: type length too large."));
  1392. }
  1393. /* Return the name of register regno as a string. Return NULL for an
  1394. invalid or unimplemented register. */
  1395. static const char *
  1396. cris_special_register_name (struct gdbarch *gdbarch, int regno)
  1397. {
  1398. int spec_regno;
  1399. int i;
  1400. /* Special register (R16 - R31). cris_spec_regs is zero-based.
  1401. Adjust regno accordingly. */
  1402. spec_regno = regno - NUM_GENREGS;
  1403. /* Assume nothing about the layout of the cris_spec_regs struct
  1404. when searching. */
  1405. for (i = 0; cris_spec_regs[i].name != NULL; i++)
  1406. {
  1407. if (cris_spec_regs[i].number == spec_regno
  1408. && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i]))
  1409. /* Go with the first applicable register. */
  1410. return cris_spec_regs[i].name;
  1411. }
  1412. /* Special register not applicable to this CRIS version. */
  1413. return NULL;
  1414. }
  1415. static const char *
  1416. cris_register_name (struct gdbarch *gdbarch, int regno)
  1417. {
  1418. static const char *cris_genreg_names[] =
  1419. { "r0", "r1", "r2", "r3", \
  1420. "r4", "r5", "r6", "r7", \
  1421. "r8", "r9", "r10", "r11", \
  1422. "r12", "r13", "sp", "pc" };
  1423. if (regno >= 0 && regno < NUM_GENREGS)
  1424. {
  1425. /* General register. */
  1426. return cris_genreg_names[regno];
  1427. }
  1428. else if (regno >= NUM_GENREGS && regno < gdbarch_num_regs (gdbarch))
  1429. {
  1430. return cris_special_register_name (gdbarch, regno);
  1431. }
  1432. else
  1433. {
  1434. /* Invalid register. */
  1435. return NULL;
  1436. }
  1437. }
  1438. static const char *
  1439. crisv32_register_name (struct gdbarch *gdbarch, int regno)
  1440. {
  1441. static const char *crisv32_genreg_names[] =
  1442. { "r0", "r1", "r2", "r3", \
  1443. "r4", "r5", "r6", "r7", \
  1444. "r8", "r9", "r10", "r11", \
  1445. "r12", "r13", "sp", "acr"
  1446. };
  1447. static const char *crisv32_sreg_names[] =
  1448. { "s0", "s1", "s2", "s3", \
  1449. "s4", "s5", "s6", "s7", \
  1450. "s8", "s9", "s10", "s11", \
  1451. "s12", "s13", "s14", "s15"
  1452. };
  1453. if (regno >= 0 && regno < NUM_GENREGS)
  1454. {
  1455. /* General register. */
  1456. return crisv32_genreg_names[regno];
  1457. }
  1458. else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS))
  1459. {
  1460. return cris_special_register_name (gdbarch, regno);
  1461. }
  1462. else if (regno == gdbarch_pc_regnum (gdbarch))
  1463. {
  1464. return "pc";
  1465. }
  1466. else if (regno >= S0_REGNUM && regno <= S15_REGNUM)
  1467. {
  1468. return crisv32_sreg_names[regno - S0_REGNUM];
  1469. }
  1470. else
  1471. {
  1472. /* Invalid register. */
  1473. return NULL;
  1474. }
  1475. }
  1476. /* Convert DWARF register number REG to the appropriate register
  1477. number used by GDB. */
  1478. static int
  1479. cris_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
  1480. {
  1481. /* We need to re-map a couple of registers (SRP is 16 in Dwarf-2 register
  1482. numbering, MOF is 18).
  1483. Adapted from gcc/config/cris/cris.h. */
  1484. static int cris_dwarf_regmap[] = {
  1485. 0, 1, 2, 3,
  1486. 4, 5, 6, 7,
  1487. 8, 9, 10, 11,
  1488. 12, 13, 14, 15,
  1489. 27, -1, -1, -1,
  1490. -1, -1, -1, 23,
  1491. -1, -1, -1, 27,
  1492. -1, -1, -1, -1
  1493. };
  1494. int regnum = -1;
  1495. if (reg >= 0 && reg < ARRAY_SIZE (cris_dwarf_regmap))
  1496. regnum = cris_dwarf_regmap[reg];
  1497. return regnum;
  1498. }
  1499. /* DWARF-2 frame support. */
  1500. static void
  1501. cris_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
  1502. struct dwarf2_frame_state_reg *reg,
  1503. struct frame_info *this_frame)
  1504. {
  1505. /* The return address column. */
  1506. if (regnum == gdbarch_pc_regnum (gdbarch))
  1507. reg->how = DWARF2_FRAME_REG_RA;
  1508. /* The call frame address. */
  1509. else if (regnum == gdbarch_sp_regnum (gdbarch))
  1510. reg->how = DWARF2_FRAME_REG_CFA;
  1511. }
  1512. /* Extract from an array regbuf containing the raw register state a function
  1513. return value of type type, and copy that, in virtual format, into
  1514. valbuf. */
  1515. /* In the CRIS ABI, R10 and R11 are used to store return values. */
  1516. static void
  1517. cris_extract_return_value (struct type *type, struct regcache *regcache,
  1518. gdb_byte *valbuf)
  1519. {
  1520. struct gdbarch *gdbarch = regcache->arch ();
  1521. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1522. ULONGEST val;
  1523. int len = TYPE_LENGTH (type);
  1524. if (len <= 4)
  1525. {
  1526. /* Get the return value from R10. */
  1527. regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
  1528. store_unsigned_integer (valbuf, len, byte_order, val);
  1529. }
  1530. else if (len <= 8)
  1531. {
  1532. /* Get the return value from R10 and R11. */
  1533. regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val);
  1534. store_unsigned_integer (valbuf, 4, byte_order, val);
  1535. regcache_cooked_read_unsigned (regcache, ARG2_REGNUM, &val);
  1536. store_unsigned_integer (valbuf + 4, len - 4, byte_order, val);
  1537. }
  1538. else
  1539. error (_("cris_extract_return_value: type length too large"));
  1540. }
  1541. /* Handle the CRIS return value convention. */
  1542. static enum return_value_convention
  1543. cris_return_value (struct gdbarch *gdbarch, struct value *function,
  1544. struct type *type, struct regcache *regcache,
  1545. gdb_byte *readbuf, const gdb_byte *writebuf)
  1546. {
  1547. if (type->code () == TYPE_CODE_STRUCT
  1548. || type->code () == TYPE_CODE_UNION
  1549. || TYPE_LENGTH (type) > 8)
  1550. /* Structs, unions, and anything larger than 8 bytes (2 registers)
  1551. goes on the stack. */
  1552. return RETURN_VALUE_STRUCT_CONVENTION;
  1553. if (readbuf)
  1554. cris_extract_return_value (type, regcache, readbuf);
  1555. if (writebuf)
  1556. cris_store_return_value (type, regcache, writebuf);
  1557. return RETURN_VALUE_REGISTER_CONVENTION;
  1558. }
  1559. /* Calculates a value that measures how good inst_args constraints an
  1560. instruction. It stems from cris_constraint, found in cris-dis.c. */
  1561. static int
  1562. constraint (unsigned int insn, const char *inst_args,
  1563. inst_env_type *inst_env)
  1564. {
  1565. int retval = 0;
  1566. int tmp, i;
  1567. const gdb_byte *s = (const gdb_byte *) inst_args;
  1568. for (; *s; s++)
  1569. switch (*s)
  1570. {
  1571. case 'm':
  1572. if ((insn & 0x30) == 0x30)
  1573. return -1;
  1574. break;
  1575. case 'S':
  1576. /* A prefix operand. */
  1577. if (inst_env->prefix_found)
  1578. break;
  1579. else
  1580. return -1;
  1581. case 'B':
  1582. /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
  1583. valid "push" size. In case of special register, it may be != 4. */
  1584. if (inst_env->prefix_found)
  1585. break;
  1586. else
  1587. return -1;
  1588. case 'D':
  1589. retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
  1590. if (!retval)
  1591. return -1;
  1592. else
  1593. retval += 4;
  1594. break;
  1595. case 'P':
  1596. tmp = (insn >> 0xC) & 0xF;
  1597. for (i = 0; cris_spec_regs[i].name != NULL; i++)
  1598. {
  1599. /* Since we match four bits, we will give a value of
  1600. 4 - 1 = 3 in a match. If there is a corresponding
  1601. exact match of a special register in another pattern, it
  1602. will get a value of 4, which will be higher. This should
  1603. be correct in that an exact pattern would match better that
  1604. a general pattern.
  1605. Note that there is a reason for not returning zero; the
  1606. pattern for "clear" is partly matched in the bit-pattern
  1607. (the two lower bits must be zero), while the bit-pattern
  1608. for a move from a special register is matched in the
  1609. register constraint.
  1610. This also means we will will have a race condition if
  1611. there is a partly match in three bits in the bit pattern. */
  1612. if (tmp == cris_spec_regs[i].number)
  1613. {
  1614. retval += 3;
  1615. break;
  1616. }
  1617. }
  1618. if (cris_spec_regs[i].name == NULL)
  1619. return -1;
  1620. break;
  1621. }
  1622. return retval;
  1623. }
  1624. /* Returns the number of bits set in the variable value. */
  1625. static int
  1626. number_of_bits (unsigned int value)
  1627. {
  1628. int number_of_bits = 0;
  1629. while (value != 0)
  1630. {
  1631. number_of_bits += 1;
  1632. value &= (value - 1);
  1633. }
  1634. return number_of_bits;
  1635. }
  1636. /* Finds the address that should contain the single step breakpoint(s).
  1637. It stems from code in cris-dis.c. */
  1638. static int
  1639. find_cris_op (unsigned short insn, inst_env_type *inst_env)
  1640. {
  1641. int i;
  1642. int max_level_of_match = -1;
  1643. int max_matched = -1;
  1644. int level_of_match;
  1645. for (i = 0; cris_opcodes[i].name != NULL; i++)
  1646. {
  1647. if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
  1648. && ((cris_opcodes[i].lose & insn) == 0)
  1649. /* Only CRISv10 instructions, please. */
  1650. && (cris_opcodes[i].applicable_version != cris_ver_v32p))
  1651. {
  1652. level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
  1653. if (level_of_match >= 0)
  1654. {
  1655. level_of_match +=
  1656. number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
  1657. if (level_of_match > max_level_of_match)
  1658. {
  1659. max_matched = i;
  1660. max_level_of_match = level_of_match;
  1661. if (level_of_match == 16)
  1662. {
  1663. /* All bits matched, cannot find better. */
  1664. break;
  1665. }
  1666. }
  1667. }
  1668. }
  1669. }
  1670. return max_matched;
  1671. }
  1672. /* Attempts to find single-step breakpoints. Returns -1 on failure which is
  1673. actually an internal error. */
  1674. static int
  1675. find_step_target (struct regcache *regcache, inst_env_type *inst_env)
  1676. {
  1677. int i;
  1678. int offset;
  1679. unsigned short insn;
  1680. struct gdbarch *gdbarch = regcache->arch ();
  1681. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1682. /* Create a local register image and set the initial state. */
  1683. for (i = 0; i < NUM_GENREGS; i++)
  1684. {
  1685. inst_env->reg[i] =
  1686. (unsigned long) regcache_raw_get_unsigned (regcache, i);
  1687. }
  1688. offset = NUM_GENREGS;
  1689. for (i = 0; i < NUM_SPECREGS; i++)
  1690. {
  1691. inst_env->preg[i] =
  1692. (unsigned long) regcache_raw_get_unsigned (regcache, offset + i);
  1693. }
  1694. inst_env->branch_found = 0;
  1695. inst_env->slot_needed = 0;
  1696. inst_env->delay_slot_pc_active = 0;
  1697. inst_env->prefix_found = 0;
  1698. inst_env->invalid = 0;
  1699. inst_env->xflag_found = 0;
  1700. inst_env->disable_interrupt = 0;
  1701. inst_env->byte_order = byte_order;
  1702. /* Look for a step target. */
  1703. do
  1704. {
  1705. /* Read an instruction from the client. */
  1706. insn = read_memory_unsigned_integer
  1707. (inst_env->reg[gdbarch_pc_regnum (gdbarch)], 2, byte_order);
  1708. /* If the instruction is not in a delay slot the new content of the
  1709. PC is [PC] + 2. If the instruction is in a delay slot it is not
  1710. that simple. Since a instruction in a delay slot cannot change
  1711. the content of the PC, it does not matter what value PC will have.
  1712. Just make sure it is a valid instruction. */
  1713. if (!inst_env->delay_slot_pc_active)
  1714. {
  1715. inst_env->reg[gdbarch_pc_regnum (gdbarch)] += 2;
  1716. }
  1717. else
  1718. {
  1719. inst_env->delay_slot_pc_active = 0;
  1720. inst_env->reg[gdbarch_pc_regnum (gdbarch)]
  1721. = inst_env->delay_slot_pc;
  1722. }
  1723. /* Analyse the present instruction. */
  1724. i = find_cris_op (insn, inst_env);
  1725. if (i == -1)
  1726. {
  1727. inst_env->invalid = 1;
  1728. }
  1729. else
  1730. {
  1731. cris_gdb_func (gdbarch, cris_opcodes[i].op, insn, inst_env);
  1732. }
  1733. } while (!inst_env->invalid
  1734. && (inst_env->prefix_found || inst_env->xflag_found
  1735. || inst_env->slot_needed));
  1736. return i;
  1737. }
  1738. /* There is no hardware single-step support. The function find_step_target
  1739. digs through the opcodes in order to find all possible targets.
  1740. Either one ordinary target or two targets for branches may be found. */
  1741. static std::vector<CORE_ADDR>
  1742. cris_software_single_step (struct regcache *regcache)
  1743. {
  1744. struct gdbarch *gdbarch = regcache->arch ();
  1745. inst_env_type inst_env;
  1746. std::vector<CORE_ADDR> next_pcs;
  1747. /* Analyse the present instruction environment and insert
  1748. breakpoints. */
  1749. int status = find_step_target (regcache, &inst_env);
  1750. if (status == -1)
  1751. {
  1752. /* Could not find a target. Things are likely to go downhill
  1753. from here. */
  1754. warning (_("CRIS software single step could not find a step target."));
  1755. }
  1756. else
  1757. {
  1758. /* Insert at most two breakpoints. One for the next PC content
  1759. and possibly another one for a branch, jump, etc. */
  1760. CORE_ADDR next_pc
  1761. = (CORE_ADDR) inst_env.reg[gdbarch_pc_regnum (gdbarch)];
  1762. next_pcs.push_back (next_pc);
  1763. if (inst_env.branch_found
  1764. && (CORE_ADDR) inst_env.branch_break_address != next_pc)
  1765. {
  1766. CORE_ADDR branch_target_address
  1767. = (CORE_ADDR) inst_env.branch_break_address;
  1768. next_pcs.push_back (branch_target_address);
  1769. }
  1770. }
  1771. return next_pcs;
  1772. }
  1773. /* Calculates the prefix value for quick offset addressing mode. */
  1774. static void
  1775. quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
  1776. {
  1777. /* It's invalid to be in a delay slot. You can't have a prefix to this
  1778. instruction (not 100% sure). */
  1779. if (inst_env->slot_needed || inst_env->prefix_found)
  1780. {
  1781. inst_env->invalid = 1;
  1782. return;
  1783. }
  1784. inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
  1785. inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
  1786. /* A prefix doesn't change the xflag_found. But the rest of the flags
  1787. need updating. */
  1788. inst_env->slot_needed = 0;
  1789. inst_env->prefix_found = 1;
  1790. }
  1791. /* Updates the autoincrement register. The size of the increment is derived
  1792. from the size of the operation. The PC is always kept aligned on even
  1793. word addresses. */
  1794. static void
  1795. process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
  1796. {
  1797. if (size == INST_BYTE_SIZE)
  1798. {
  1799. inst_env->reg[cris_get_operand1 (inst)] += 1;
  1800. /* The PC must be word aligned, so increase the PC with one
  1801. word even if the size is byte. */
  1802. if (cris_get_operand1 (inst) == REG_PC)
  1803. {
  1804. inst_env->reg[REG_PC] += 1;
  1805. }
  1806. }
  1807. else if (size == INST_WORD_SIZE)
  1808. {
  1809. inst_env->reg[cris_get_operand1 (inst)] += 2;
  1810. }
  1811. else if (size == INST_DWORD_SIZE)
  1812. {
  1813. inst_env->reg[cris_get_operand1 (inst)] += 4;
  1814. }
  1815. else
  1816. {
  1817. /* Invalid size. */
  1818. inst_env->invalid = 1;
  1819. }
  1820. }
  1821. /* Just a forward declaration. */
  1822. static unsigned long get_data_from_address (unsigned short *inst,
  1823. CORE_ADDR address,
  1824. enum bfd_endian byte_order);
  1825. /* Calculates the prefix value for the general case of offset addressing
  1826. mode. */
  1827. static void
  1828. bdap_prefix (unsigned short inst, inst_env_type *inst_env)
  1829. {
  1830. /* It's invalid to be in a delay slot. */
  1831. if (inst_env->slot_needed || inst_env->prefix_found)
  1832. {
  1833. inst_env->invalid = 1;
  1834. return;
  1835. }
  1836. /* The calculation of prefix_value used to be after process_autoincrement,
  1837. but that fails for an instruction such as jsr [$r0+12] which is encoded
  1838. as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
  1839. mustn't be incremented until we have read it and what it points at. */
  1840. inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
  1841. /* The offset is an indirection of the contents of the operand1 register. */
  1842. inst_env->prefix_value +=
  1843. get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)],
  1844. inst_env->byte_order);
  1845. if (cris_get_mode (inst) == AUTOINC_MODE)
  1846. {
  1847. process_autoincrement (cris_get_size (inst), inst, inst_env);
  1848. }
  1849. /* A prefix doesn't change the xflag_found. But the rest of the flags
  1850. need updating. */
  1851. inst_env->slot_needed = 0;
  1852. inst_env->prefix_found = 1;
  1853. }
  1854. /* Calculates the prefix value for the index addressing mode. */
  1855. static void
  1856. biap_prefix (unsigned short inst, inst_env_type *inst_env)
  1857. {
  1858. /* It's invalid to be in a delay slot. I can't see that it's possible to
  1859. have a prefix to this instruction. So I will treat this as invalid. */
  1860. if (inst_env->slot_needed || inst_env->prefix_found)
  1861. {
  1862. inst_env->invalid = 1;
  1863. return;
  1864. }
  1865. inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
  1866. /* The offset is the operand2 value shifted the size of the instruction
  1867. to the left. */
  1868. inst_env->prefix_value +=
  1869. inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
  1870. /* If the PC is operand1 (base) the address used is the address after
  1871. the main instruction, i.e. address + 2 (the PC is already compensated
  1872. for the prefix operation). */
  1873. if (cris_get_operand1 (inst) == REG_PC)
  1874. {
  1875. inst_env->prefix_value += 2;
  1876. }
  1877. /* A prefix doesn't change the xflag_found. But the rest of the flags
  1878. need updating. */
  1879. inst_env->slot_needed = 0;
  1880. inst_env->xflag_found = 0;
  1881. inst_env->prefix_found = 1;
  1882. }
  1883. /* Calculates the prefix value for the double indirect addressing mode. */
  1884. static void
  1885. dip_prefix (unsigned short inst, inst_env_type *inst_env)
  1886. {
  1887. CORE_ADDR address;
  1888. /* It's invalid to be in a delay slot. */
  1889. if (inst_env->slot_needed || inst_env->prefix_found)
  1890. {
  1891. inst_env->invalid = 1;
  1892. return;
  1893. }
  1894. /* The prefix value is one dereference of the contents of the operand1
  1895. register. */
  1896. address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
  1897. inst_env->prefix_value
  1898. = read_memory_unsigned_integer (address, 4, inst_env->byte_order);
  1899. /* Check if the mode is autoincrement. */
  1900. if (cris_get_mode (inst) == AUTOINC_MODE)
  1901. {
  1902. inst_env->reg[cris_get_operand1 (inst)] += 4;
  1903. }
  1904. /* A prefix doesn't change the xflag_found. But the rest of the flags
  1905. need updating. */
  1906. inst_env->slot_needed = 0;
  1907. inst_env->xflag_found = 0;
  1908. inst_env->prefix_found = 1;
  1909. }
  1910. /* Finds the destination for a branch with 8-bits offset. */
  1911. static void
  1912. eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
  1913. {
  1914. short offset;
  1915. /* If we have a prefix or are in a delay slot it's bad. */
  1916. if (inst_env->slot_needed || inst_env->prefix_found)
  1917. {
  1918. inst_env->invalid = 1;
  1919. return;
  1920. }
  1921. /* We have a branch, find out where the branch will land. */
  1922. offset = cris_get_branch_short_offset (inst);
  1923. /* Check if the offset is signed. */
  1924. if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
  1925. {
  1926. offset |= 0xFF00;
  1927. }
  1928. /* The offset ends with the sign bit, set it to zero. The address
  1929. should always be word aligned. */
  1930. offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
  1931. inst_env->branch_found = 1;
  1932. inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
  1933. inst_env->slot_needed = 1;
  1934. inst_env->prefix_found = 0;
  1935. inst_env->xflag_found = 0;
  1936. inst_env->disable_interrupt = 1;
  1937. }
  1938. /* Finds the destination for a branch with 16-bits offset. */
  1939. static void
  1940. sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
  1941. {
  1942. short offset;
  1943. /* If we have a prefix or is in a delay slot it's bad. */
  1944. if (inst_env->slot_needed || inst_env->prefix_found)
  1945. {
  1946. inst_env->invalid = 1;
  1947. return;
  1948. }
  1949. /* We have a branch, find out the offset for the branch. */
  1950. offset = read_memory_integer (inst_env->reg[REG_PC], 2,
  1951. inst_env->byte_order);
  1952. /* The instruction is one word longer than normal, so add one word
  1953. to the PC. */
  1954. inst_env->reg[REG_PC] += 2;
  1955. inst_env->branch_found = 1;
  1956. inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
  1957. inst_env->slot_needed = 1;
  1958. inst_env->prefix_found = 0;
  1959. inst_env->xflag_found = 0;
  1960. inst_env->disable_interrupt = 1;
  1961. }
  1962. /* Handles the ABS instruction. */
  1963. static void
  1964. abs_op (unsigned short inst, inst_env_type *inst_env)
  1965. {
  1966. long value;
  1967. /* ABS can't have a prefix, so it's bad if it does. */
  1968. if (inst_env->prefix_found)
  1969. {
  1970. inst_env->invalid = 1;
  1971. return;
  1972. }
  1973. /* Check if the operation affects the PC. */
  1974. if (cris_get_operand2 (inst) == REG_PC)
  1975. {
  1976. /* It's invalid to change to the PC if we are in a delay slot. */
  1977. if (inst_env->slot_needed)
  1978. {
  1979. inst_env->invalid = 1;
  1980. return;
  1981. }
  1982. value = (long) inst_env->reg[REG_PC];
  1983. /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
  1984. if (value != SIGNED_DWORD_MASK)
  1985. {
  1986. value = -value;
  1987. inst_env->reg[REG_PC] = (long) value;
  1988. }
  1989. }
  1990. inst_env->slot_needed = 0;
  1991. inst_env->prefix_found = 0;
  1992. inst_env->xflag_found = 0;
  1993. inst_env->disable_interrupt = 0;
  1994. }
  1995. /* Handles the ADDI instruction. */
  1996. static void
  1997. addi_op (unsigned short inst, inst_env_type *inst_env)
  1998. {
  1999. /* It's invalid to have the PC as base register. And ADDI can't have
  2000. a prefix. */
  2001. if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
  2002. {
  2003. inst_env->invalid = 1;
  2004. return;
  2005. }
  2006. inst_env->slot_needed = 0;
  2007. inst_env->prefix_found = 0;
  2008. inst_env->xflag_found = 0;
  2009. inst_env->disable_interrupt = 0;
  2010. }
  2011. /* Handles the ASR instruction. */
  2012. static void
  2013. asr_op (unsigned short inst, inst_env_type *inst_env)
  2014. {
  2015. int shift_steps;
  2016. unsigned long value;
  2017. unsigned long signed_extend_mask = 0;
  2018. /* ASR can't have a prefix, so check that it doesn't. */
  2019. if (inst_env->prefix_found)
  2020. {
  2021. inst_env->invalid = 1;
  2022. return;
  2023. }
  2024. /* Check if the PC is the target register. */
  2025. if (cris_get_operand2 (inst) == REG_PC)
  2026. {
  2027. /* It's invalid to change the PC in a delay slot. */
  2028. if (inst_env->slot_needed)
  2029. {
  2030. inst_env->invalid = 1;
  2031. return;
  2032. }
  2033. /* Get the number of bits to shift. */
  2034. shift_steps
  2035. = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
  2036. value = inst_env->reg[REG_PC];
  2037. /* Find out how many bits the operation should apply to. */
  2038. if (cris_get_size (inst) == INST_BYTE_SIZE)
  2039. {
  2040. if (value & SIGNED_BYTE_MASK)
  2041. {
  2042. signed_extend_mask = 0xFF;
  2043. signed_extend_mask = signed_extend_mask >> shift_steps;
  2044. signed_extend_mask = ~signed_extend_mask;
  2045. }
  2046. value = value >> shift_steps;
  2047. value |= signed_extend_mask;
  2048. value &= 0xFF;
  2049. inst_env->reg[REG_PC] &= 0xFFFFFF00;
  2050. inst_env->reg[REG_PC] |= value;
  2051. }
  2052. else if (cris_get_size (inst) == INST_WORD_SIZE)
  2053. {
  2054. if (value & SIGNED_WORD_MASK)
  2055. {
  2056. signed_extend_mask = 0xFFFF;
  2057. signed_extend_mask = signed_extend_mask >> shift_steps;
  2058. signed_extend_mask = ~signed_extend_mask;
  2059. }
  2060. value = value >> shift_steps;
  2061. value |= signed_extend_mask;
  2062. value &= 0xFFFF;
  2063. inst_env->reg[REG_PC] &= 0xFFFF0000;
  2064. inst_env->reg[REG_PC] |= value;
  2065. }
  2066. else if (cris_get_size (inst) == INST_DWORD_SIZE)
  2067. {
  2068. if (value & SIGNED_DWORD_MASK)
  2069. {
  2070. signed_extend_mask = 0xFFFFFFFF;
  2071. signed_extend_mask = signed_extend_mask >> shift_steps;
  2072. signed_extend_mask = ~signed_extend_mask;
  2073. }
  2074. value = value >> shift_steps;
  2075. value |= signed_extend_mask;
  2076. inst_env->reg[REG_PC] = value;
  2077. }
  2078. }
  2079. inst_env->slot_needed = 0;
  2080. inst_env->prefix_found = 0;
  2081. inst_env->xflag_found = 0;
  2082. inst_env->disable_interrupt = 0;
  2083. }
  2084. /* Handles the ASRQ instruction. */
  2085. static void
  2086. asrq_op (unsigned short inst, inst_env_type *inst_env)
  2087. {
  2088. int shift_steps;
  2089. unsigned long value;
  2090. unsigned long signed_extend_mask = 0;
  2091. /* ASRQ can't have a prefix, so check that it doesn't. */
  2092. if (inst_env->prefix_found)
  2093. {
  2094. inst_env->invalid = 1;
  2095. return;
  2096. }
  2097. /* Check if the PC is the target register. */
  2098. if (cris_get_operand2 (inst) == REG_PC)
  2099. {
  2100. /* It's invalid to change the PC in a delay slot. */
  2101. if (inst_env->slot_needed)
  2102. {
  2103. inst_env->invalid = 1;
  2104. return;
  2105. }
  2106. /* The shift size is given as a 5 bit quick value, i.e. we don't
  2107. want the sign bit of the quick value. */
  2108. shift_steps = cris_get_asr_shift_steps (inst);
  2109. value = inst_env->reg[REG_PC];
  2110. if (value & SIGNED_DWORD_MASK)
  2111. {
  2112. signed_extend_mask = 0xFFFFFFFF;
  2113. signed_extend_mask = signed_extend_mask >> shift_steps;
  2114. signed_extend_mask = ~signed_extend_mask;
  2115. }
  2116. value = value >> shift_steps;
  2117. value |= signed_extend_mask;
  2118. inst_env->reg[REG_PC] = value;
  2119. }
  2120. inst_env->slot_needed = 0;
  2121. inst_env->prefix_found = 0;
  2122. inst_env->xflag_found = 0;
  2123. inst_env->disable_interrupt = 0;
  2124. }
  2125. /* Handles the AX, EI and SETF instruction. */
  2126. static void
  2127. ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
  2128. {
  2129. if (inst_env->prefix_found)
  2130. {
  2131. inst_env->invalid = 1;
  2132. return;
  2133. }
  2134. /* Check if the instruction is setting the X flag. */
  2135. if (cris_is_xflag_bit_on (inst))
  2136. {
  2137. inst_env->xflag_found = 1;
  2138. }
  2139. else
  2140. {
  2141. inst_env->xflag_found = 0;
  2142. }
  2143. inst_env->slot_needed = 0;
  2144. inst_env->prefix_found = 0;
  2145. inst_env->disable_interrupt = 1;
  2146. }
  2147. /* Checks if the instruction is in assign mode. If so, it updates the assign
  2148. register. Note that check_assign assumes that the caller has checked that
  2149. there is a prefix to this instruction. The mode check depends on this. */
  2150. static void
  2151. check_assign (unsigned short inst, inst_env_type *inst_env)
  2152. {
  2153. /* Check if it's an assign addressing mode. */
  2154. if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
  2155. {
  2156. /* Assign the prefix value to operand 1. */
  2157. inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
  2158. }
  2159. }
  2160. /* Handles the 2-operand BOUND instruction. */
  2161. static void
  2162. two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
  2163. {
  2164. /* It's invalid to have the PC as the index operand. */
  2165. if (cris_get_operand2 (inst) == REG_PC)
  2166. {
  2167. inst_env->invalid = 1;
  2168. return;
  2169. }
  2170. /* Check if we have a prefix. */
  2171. if (inst_env->prefix_found)
  2172. {
  2173. check_assign (inst, inst_env);
  2174. }
  2175. /* Check if this is an autoincrement mode. */
  2176. else if (cris_get_mode (inst) == AUTOINC_MODE)
  2177. {
  2178. /* It's invalid to change the PC in a delay slot. */
  2179. if (inst_env->slot_needed)
  2180. {
  2181. inst_env->invalid = 1;
  2182. return;
  2183. }
  2184. process_autoincrement (cris_get_size (inst), inst, inst_env);
  2185. }
  2186. inst_env->slot_needed = 0;
  2187. inst_env->prefix_found = 0;
  2188. inst_env->xflag_found = 0;
  2189. inst_env->disable_interrupt = 0;
  2190. }
  2191. /* Handles the 3-operand BOUND instruction. */
  2192. static void
  2193. three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
  2194. {
  2195. /* It's an error if we haven't got a prefix. And it's also an error
  2196. if the PC is the destination register. */
  2197. if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
  2198. {
  2199. inst_env->invalid = 1;
  2200. return;
  2201. }
  2202. inst_env->slot_needed = 0;
  2203. inst_env->prefix_found = 0;
  2204. inst_env->xflag_found = 0;
  2205. inst_env->disable_interrupt = 0;
  2206. }
  2207. /* Clears the status flags in inst_env. */
  2208. static void
  2209. btst_nop_op (unsigned short inst, inst_env_type *inst_env)
  2210. {
  2211. /* It's an error if we have got a prefix. */
  2212. if (inst_env->prefix_found)
  2213. {
  2214. inst_env->invalid = 1;
  2215. return;
  2216. }
  2217. inst_env->slot_needed = 0;
  2218. inst_env->prefix_found = 0;
  2219. inst_env->xflag_found = 0;
  2220. inst_env->disable_interrupt = 0;
  2221. }
  2222. /* Clears the status flags in inst_env. */
  2223. static void
  2224. clearf_di_op (unsigned short inst, inst_env_type *inst_env)
  2225. {
  2226. /* It's an error if we have got a prefix. */
  2227. if (inst_env->prefix_found)
  2228. {
  2229. inst_env->invalid = 1;
  2230. return;
  2231. }
  2232. inst_env->slot_needed = 0;
  2233. inst_env->prefix_found = 0;
  2234. inst_env->xflag_found = 0;
  2235. inst_env->disable_interrupt = 1;
  2236. }
  2237. /* Handles the CLEAR instruction if it's in register mode. */
  2238. static void
  2239. reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
  2240. {
  2241. /* Check if the target is the PC. */
  2242. if (cris_get_operand2 (inst) == REG_PC)
  2243. {
  2244. /* The instruction will clear the instruction's size bits. */
  2245. int clear_size = cris_get_clear_size (inst);
  2246. if (clear_size == INST_BYTE_SIZE)
  2247. {
  2248. inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
  2249. }
  2250. if (clear_size == INST_WORD_SIZE)
  2251. {
  2252. inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
  2253. }
  2254. if (clear_size == INST_DWORD_SIZE)
  2255. {
  2256. inst_env->delay_slot_pc = 0x0;
  2257. }
  2258. /* The jump will be delayed with one delay slot. So we need a delay
  2259. slot. */
  2260. inst_env->slot_needed = 1;
  2261. inst_env->delay_slot_pc_active = 1;
  2262. }
  2263. else
  2264. {
  2265. /* The PC will not change => no delay slot. */
  2266. inst_env->slot_needed = 0;
  2267. }
  2268. inst_env->prefix_found = 0;
  2269. inst_env->xflag_found = 0;
  2270. inst_env->disable_interrupt = 0;
  2271. }
  2272. /* Handles the TEST instruction if it's in register mode. */
  2273. static void
  2274. reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
  2275. {
  2276. /* It's an error if we have got a prefix. */
  2277. if (inst_env->prefix_found)
  2278. {
  2279. inst_env->invalid = 1;
  2280. return;
  2281. }
  2282. inst_env->slot_needed = 0;
  2283. inst_env->prefix_found = 0;
  2284. inst_env->xflag_found = 0;
  2285. inst_env->disable_interrupt = 0;
  2286. }
  2287. /* Handles the CLEAR and TEST instruction if the instruction isn't
  2288. in register mode. */
  2289. static void
  2290. none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
  2291. {
  2292. /* Check if we are in a prefix mode. */
  2293. if (inst_env->prefix_found)
  2294. {
  2295. /* The only way the PC can change is if this instruction is in
  2296. assign addressing mode. */
  2297. check_assign (inst, inst_env);
  2298. }
  2299. /* Indirect mode can't change the PC so just check if the mode is
  2300. autoincrement. */
  2301. else if (cris_get_mode (inst) == AUTOINC_MODE)
  2302. {
  2303. process_autoincrement (cris_get_size (inst), inst, inst_env);
  2304. }
  2305. inst_env->slot_needed = 0;
  2306. inst_env->prefix_found = 0;
  2307. inst_env->xflag_found = 0;
  2308. inst_env->disable_interrupt = 0;
  2309. }
  2310. /* Checks that the PC isn't the destination register or the instructions has
  2311. a prefix. */
  2312. static void
  2313. dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
  2314. {
  2315. /* It's invalid to have the PC as the destination. The instruction can't
  2316. have a prefix. */
  2317. if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
  2318. {
  2319. inst_env->invalid = 1;
  2320. return;
  2321. }
  2322. inst_env->slot_needed = 0;
  2323. inst_env->prefix_found = 0;
  2324. inst_env->xflag_found = 0;
  2325. inst_env->disable_interrupt = 0;
  2326. }
  2327. /* Checks that the instruction doesn't have a prefix. */
  2328. static void
  2329. break_op (unsigned short inst, inst_env_type *inst_env)
  2330. {
  2331. /* The instruction can't have a prefix. */
  2332. if (inst_env->prefix_found)
  2333. {
  2334. inst_env->invalid = 1;
  2335. return;
  2336. }
  2337. inst_env->slot_needed = 0;
  2338. inst_env->prefix_found = 0;
  2339. inst_env->xflag_found = 0;
  2340. inst_env->disable_interrupt = 1;
  2341. }
  2342. /* Checks that the PC isn't the destination register and that the instruction
  2343. doesn't have a prefix. */
  2344. static void
  2345. scc_op (unsigned short inst, inst_env_type *inst_env)
  2346. {
  2347. /* It's invalid to have the PC as the destination. The instruction can't
  2348. have a prefix. */
  2349. if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
  2350. {
  2351. inst_env->invalid = 1;
  2352. return;
  2353. }
  2354. inst_env->slot_needed = 0;
  2355. inst_env->prefix_found = 0;
  2356. inst_env->xflag_found = 0;
  2357. inst_env->disable_interrupt = 1;
  2358. }
  2359. /* Handles the register mode JUMP instruction. */
  2360. static void
  2361. reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
  2362. {
  2363. /* It's invalid to do a JUMP in a delay slot. The mode is register, so
  2364. you can't have a prefix. */
  2365. if ((inst_env->slot_needed) || (inst_env->prefix_found))
  2366. {
  2367. inst_env->invalid = 1;
  2368. return;
  2369. }
  2370. /* Just change the PC. */
  2371. inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
  2372. inst_env->slot_needed = 0;
  2373. inst_env->prefix_found = 0;
  2374. inst_env->xflag_found = 0;
  2375. inst_env->disable_interrupt = 1;
  2376. }
  2377. /* Handles the JUMP instruction for all modes except register. */
  2378. static void
  2379. none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
  2380. {
  2381. unsigned long newpc;
  2382. CORE_ADDR address;
  2383. /* It's invalid to do a JUMP in a delay slot. */
  2384. if (inst_env->slot_needed)
  2385. {
  2386. inst_env->invalid = 1;
  2387. }
  2388. else
  2389. {
  2390. /* Check if we have a prefix. */
  2391. if (inst_env->prefix_found)
  2392. {
  2393. check_assign (inst, inst_env);
  2394. /* Get the new value for the PC. */
  2395. newpc =
  2396. read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
  2397. 4, inst_env->byte_order);
  2398. }
  2399. else
  2400. {
  2401. /* Get the new value for the PC. */
  2402. address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
  2403. newpc = read_memory_unsigned_integer (address,
  2404. 4, inst_env->byte_order);
  2405. /* Check if we should increment a register. */
  2406. if (cris_get_mode (inst) == AUTOINC_MODE)
  2407. {
  2408. inst_env->reg[cris_get_operand1 (inst)] += 4;
  2409. }
  2410. }
  2411. inst_env->reg[REG_PC] = newpc;
  2412. }
  2413. inst_env->slot_needed = 0;
  2414. inst_env->prefix_found = 0;
  2415. inst_env->xflag_found = 0;
  2416. inst_env->disable_interrupt = 1;
  2417. }
  2418. /* Handles moves to special registers (aka P-register) for all modes. */
  2419. static void
  2420. move_to_preg_op (struct gdbarch *gdbarch, unsigned short inst,
  2421. inst_env_type *inst_env)
  2422. {
  2423. if (inst_env->prefix_found)
  2424. {
  2425. /* The instruction has a prefix that means we are only interested if
  2426. the instruction is in assign mode. */
  2427. if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
  2428. {
  2429. /* The prefix handles the problem if we are in a delay slot. */
  2430. if (cris_get_operand1 (inst) == REG_PC)
  2431. {
  2432. /* Just take care of the assign. */
  2433. check_assign (inst, inst_env);
  2434. }
  2435. }
  2436. }
  2437. else if (cris_get_mode (inst) == AUTOINC_MODE)
  2438. {
  2439. /* The instruction doesn't have a prefix, the only case left that we
  2440. are interested in is the autoincrement mode. */
  2441. if (cris_get_operand1 (inst) == REG_PC)
  2442. {
  2443. /* If the PC is to be incremented it's invalid to be in a
  2444. delay slot. */
  2445. if (inst_env->slot_needed)
  2446. {
  2447. inst_env->invalid = 1;
  2448. return;
  2449. }
  2450. /* The increment depends on the size of the special register. */
  2451. if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
  2452. {
  2453. process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
  2454. }
  2455. else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
  2456. {
  2457. process_autoincrement (INST_WORD_SIZE, inst, inst_env);
  2458. }
  2459. else
  2460. {
  2461. process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
  2462. }
  2463. }
  2464. }
  2465. inst_env->slot_needed = 0;
  2466. inst_env->prefix_found = 0;
  2467. inst_env->xflag_found = 0;
  2468. inst_env->disable_interrupt = 1;
  2469. }
  2470. /* Handles moves from special registers (aka P-register) for all modes
  2471. except register. */
  2472. static void
  2473. none_reg_mode_move_from_preg_op (struct gdbarch *gdbarch, unsigned short inst,
  2474. inst_env_type *inst_env)
  2475. {
  2476. if (inst_env->prefix_found)
  2477. {
  2478. /* The instruction has a prefix that means we are only interested if
  2479. the instruction is in assign mode. */
  2480. if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
  2481. {
  2482. /* The prefix handles the problem if we are in a delay slot. */
  2483. if (cris_get_operand1 (inst) == REG_PC)
  2484. {
  2485. /* Just take care of the assign. */
  2486. check_assign (inst, inst_env);
  2487. }
  2488. }
  2489. }
  2490. /* The instruction doesn't have a prefix, the only case left that we
  2491. are interested in is the autoincrement mode. */
  2492. else if (cris_get_mode (inst) == AUTOINC_MODE)
  2493. {
  2494. if (cris_get_operand1 (inst) == REG_PC)
  2495. {
  2496. /* If the PC is to be incremented it's invalid to be in a
  2497. delay slot. */
  2498. if (inst_env->slot_needed)
  2499. {
  2500. inst_env->invalid = 1;
  2501. return;
  2502. }
  2503. /* The increment depends on the size of the special register. */
  2504. if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1)
  2505. {
  2506. process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
  2507. }
  2508. else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2)
  2509. {
  2510. process_autoincrement (INST_WORD_SIZE, inst, inst_env);
  2511. }
  2512. else
  2513. {
  2514. process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
  2515. }
  2516. }
  2517. }
  2518. inst_env->slot_needed = 0;
  2519. inst_env->prefix_found = 0;
  2520. inst_env->xflag_found = 0;
  2521. inst_env->disable_interrupt = 1;
  2522. }
  2523. /* Handles moves from special registers (aka P-register) when the mode
  2524. is register. */
  2525. static void
  2526. reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
  2527. {
  2528. /* Register mode move from special register can't have a prefix. */
  2529. if (inst_env->prefix_found)
  2530. {
  2531. inst_env->invalid = 1;
  2532. return;
  2533. }
  2534. if (cris_get_operand1 (inst) == REG_PC)
  2535. {
  2536. /* It's invalid to change the PC in a delay slot. */
  2537. if (inst_env->slot_needed)
  2538. {
  2539. inst_env->invalid = 1;
  2540. return;
  2541. }
  2542. /* The destination is the PC, the jump will have a delay slot. */
  2543. inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
  2544. inst_env->slot_needed = 1;
  2545. inst_env->delay_slot_pc_active = 1;
  2546. }
  2547. else
  2548. {
  2549. /* If the destination isn't PC, there will be no jump. */
  2550. inst_env->slot_needed = 0;
  2551. }
  2552. inst_env->prefix_found = 0;
  2553. inst_env->xflag_found = 0;
  2554. inst_env->disable_interrupt = 1;
  2555. }
  2556. /* Handles the MOVEM from memory to general register instruction. */
  2557. static void
  2558. move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
  2559. {
  2560. if (inst_env->prefix_found)
  2561. {
  2562. /* The prefix handles the problem if we are in a delay slot. Is the
  2563. MOVEM instruction going to change the PC? */
  2564. if (cris_get_operand2 (inst) >= REG_PC)
  2565. {
  2566. inst_env->reg[REG_PC] =
  2567. read_memory_unsigned_integer (inst_env->prefix_value,
  2568. 4, inst_env->byte_order);
  2569. }
  2570. /* The assign value is the value after the increment. Normally, the
  2571. assign value is the value before the increment. */
  2572. if ((cris_get_operand1 (inst) == REG_PC)
  2573. && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
  2574. {
  2575. inst_env->reg[REG_PC] = inst_env->prefix_value;
  2576. inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
  2577. }
  2578. }
  2579. else
  2580. {
  2581. /* Is the MOVEM instruction going to change the PC? */
  2582. if (cris_get_operand2 (inst) == REG_PC)
  2583. {
  2584. /* It's invalid to change the PC in a delay slot. */
  2585. if (inst_env->slot_needed)
  2586. {
  2587. inst_env->invalid = 1;
  2588. return;
  2589. }
  2590. inst_env->reg[REG_PC] =
  2591. read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
  2592. 4, inst_env->byte_order);
  2593. }
  2594. /* The increment is not depending on the size, instead it's depending
  2595. on the number of registers loaded from memory. */
  2596. if ((cris_get_operand1 (inst) == REG_PC)
  2597. && (cris_get_mode (inst) == AUTOINC_MODE))
  2598. {
  2599. /* It's invalid to change the PC in a delay slot. */
  2600. if (inst_env->slot_needed)
  2601. {
  2602. inst_env->invalid = 1;
  2603. return;
  2604. }
  2605. inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
  2606. }
  2607. }
  2608. inst_env->slot_needed = 0;
  2609. inst_env->prefix_found = 0;
  2610. inst_env->xflag_found = 0;
  2611. inst_env->disable_interrupt = 0;
  2612. }
  2613. /* Handles the MOVEM to memory from general register instruction. */
  2614. static void
  2615. move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
  2616. {
  2617. if (inst_env->prefix_found)
  2618. {
  2619. /* The assign value is the value after the increment. Normally, the
  2620. assign value is the value before the increment. */
  2621. if ((cris_get_operand1 (inst) == REG_PC)
  2622. && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
  2623. {
  2624. /* The prefix handles the problem if we are in a delay slot. */
  2625. inst_env->reg[REG_PC] = inst_env->prefix_value;
  2626. inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
  2627. }
  2628. }
  2629. else
  2630. {
  2631. /* The increment is not depending on the size, instead it's depending
  2632. on the number of registers loaded to memory. */
  2633. if ((cris_get_operand1 (inst) == REG_PC)
  2634. && (cris_get_mode (inst) == AUTOINC_MODE))
  2635. {
  2636. /* It's invalid to change the PC in a delay slot. */
  2637. if (inst_env->slot_needed)
  2638. {
  2639. inst_env->invalid = 1;
  2640. return;
  2641. }
  2642. inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
  2643. }
  2644. }
  2645. inst_env->slot_needed = 0;
  2646. inst_env->prefix_found = 0;
  2647. inst_env->xflag_found = 0;
  2648. inst_env->disable_interrupt = 0;
  2649. }
  2650. /* Handles the instructions that's not yet implemented, by setting
  2651. inst_env->invalid to true. */
  2652. static void
  2653. not_implemented_op (unsigned short inst, inst_env_type *inst_env)
  2654. {
  2655. inst_env->invalid = 1;
  2656. }
  2657. /* Handles the XOR instruction. */
  2658. static void
  2659. xor_op (unsigned short inst, inst_env_type *inst_env)
  2660. {
  2661. /* XOR can't have a prefix. */
  2662. if (inst_env->prefix_found)
  2663. {
  2664. inst_env->invalid = 1;
  2665. return;
  2666. }
  2667. /* Check if the PC is the target. */
  2668. if (cris_get_operand2 (inst) == REG_PC)
  2669. {
  2670. /* It's invalid to change the PC in a delay slot. */
  2671. if (inst_env->slot_needed)
  2672. {
  2673. inst_env->invalid = 1;
  2674. return;
  2675. }
  2676. inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
  2677. }
  2678. inst_env->slot_needed = 0;
  2679. inst_env->prefix_found = 0;
  2680. inst_env->xflag_found = 0;
  2681. inst_env->disable_interrupt = 0;
  2682. }
  2683. /* Handles the MULS instruction. */
  2684. static void
  2685. muls_op (unsigned short inst, inst_env_type *inst_env)
  2686. {
  2687. /* MULS/U can't have a prefix. */
  2688. if (inst_env->prefix_found)
  2689. {
  2690. inst_env->invalid = 1;
  2691. return;
  2692. }
  2693. /* Consider it invalid if the PC is the target. */
  2694. if (cris_get_operand2 (inst) == REG_PC)
  2695. {
  2696. inst_env->invalid = 1;
  2697. return;
  2698. }
  2699. inst_env->slot_needed = 0;
  2700. inst_env->prefix_found = 0;
  2701. inst_env->xflag_found = 0;
  2702. inst_env->disable_interrupt = 0;
  2703. }
  2704. /* Handles the MULU instruction. */
  2705. static void
  2706. mulu_op (unsigned short inst, inst_env_type *inst_env)
  2707. {
  2708. /* MULS/U can't have a prefix. */
  2709. if (inst_env->prefix_found)
  2710. {
  2711. inst_env->invalid = 1;
  2712. return;
  2713. }
  2714. /* Consider it invalid if the PC is the target. */
  2715. if (cris_get_operand2 (inst) == REG_PC)
  2716. {
  2717. inst_env->invalid = 1;
  2718. return;
  2719. }
  2720. inst_env->slot_needed = 0;
  2721. inst_env->prefix_found = 0;
  2722. inst_env->xflag_found = 0;
  2723. inst_env->disable_interrupt = 0;
  2724. }
  2725. /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
  2726. The MOVE instruction is the move from source to register. */
  2727. static void
  2728. add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
  2729. unsigned long source1, unsigned long source2)
  2730. {
  2731. unsigned long pc_mask;
  2732. unsigned long operation_mask;
  2733. /* Find out how many bits the operation should apply to. */
  2734. if (cris_get_size (inst) == INST_BYTE_SIZE)
  2735. {
  2736. pc_mask = 0xFFFFFF00;
  2737. operation_mask = 0xFF;
  2738. }
  2739. else if (cris_get_size (inst) == INST_WORD_SIZE)
  2740. {
  2741. pc_mask = 0xFFFF0000;
  2742. operation_mask = 0xFFFF;
  2743. }
  2744. else if (cris_get_size (inst) == INST_DWORD_SIZE)
  2745. {
  2746. pc_mask = 0x0;
  2747. operation_mask = 0xFFFFFFFF;
  2748. }
  2749. else
  2750. {
  2751. /* The size is out of range. */
  2752. inst_env->invalid = 1;
  2753. return;
  2754. }
  2755. /* The instruction just works on uw_operation_mask bits. */
  2756. source2 &= operation_mask;
  2757. source1 &= operation_mask;
  2758. /* Now calculate the result. The opcode's 3 first bits separates
  2759. the different actions. */
  2760. switch (cris_get_opcode (inst) & 7)
  2761. {
  2762. case 0: /* add */
  2763. source1 += source2;
  2764. break;
  2765. case 1: /* move */
  2766. source1 = source2;
  2767. break;
  2768. case 2: /* subtract */
  2769. source1 -= source2;
  2770. break;
  2771. case 3: /* compare */
  2772. break;
  2773. case 4: /* and */
  2774. source1 &= source2;
  2775. break;
  2776. case 5: /* or */
  2777. source1 |= source2;
  2778. break;
  2779. default:
  2780. inst_env->invalid = 1;
  2781. return;
  2782. break;
  2783. }
  2784. /* Make sure that the result doesn't contain more than the instruction
  2785. size bits. */
  2786. source2 &= operation_mask;
  2787. /* Calculate the new breakpoint address. */
  2788. inst_env->reg[REG_PC] &= pc_mask;
  2789. inst_env->reg[REG_PC] |= source1;
  2790. }
  2791. /* Extends the value from either byte or word size to a dword. If the mode
  2792. is zero extend then the value is extended with zero. If instead the mode
  2793. is signed extend the sign bit of the value is taken into consideration. */
  2794. static unsigned long
  2795. do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
  2796. {
  2797. /* The size can be either byte or word, check which one it is.
  2798. Don't check the highest bit, it's indicating if it's a zero
  2799. or sign extend. */
  2800. if (cris_get_size (*inst) & INST_WORD_SIZE)
  2801. {
  2802. /* Word size. */
  2803. value &= 0xFFFF;
  2804. /* Check if the instruction is signed extend. If so, check if value has
  2805. the sign bit on. */
  2806. if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
  2807. {
  2808. value |= SIGNED_WORD_EXTEND_MASK;
  2809. }
  2810. }
  2811. else
  2812. {
  2813. /* Byte size. */
  2814. value &= 0xFF;
  2815. /* Check if the instruction is signed extend. If so, check if value has
  2816. the sign bit on. */
  2817. if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
  2818. {
  2819. value |= SIGNED_BYTE_EXTEND_MASK;
  2820. }
  2821. }
  2822. /* The size should now be dword. */
  2823. cris_set_size_to_dword (inst);
  2824. return value;
  2825. }
  2826. /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
  2827. instruction. The MOVE instruction is the move from source to register. */
  2828. static void
  2829. reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
  2830. inst_env_type *inst_env)
  2831. {
  2832. unsigned long operand1;
  2833. unsigned long operand2;
  2834. /* It's invalid to have a prefix to the instruction. This is a register
  2835. mode instruction and can't have a prefix. */
  2836. if (inst_env->prefix_found)
  2837. {
  2838. inst_env->invalid = 1;
  2839. return;
  2840. }
  2841. /* Check if the instruction has PC as its target. */
  2842. if (cris_get_operand2 (inst) == REG_PC)
  2843. {
  2844. if (inst_env->slot_needed)
  2845. {
  2846. inst_env->invalid = 1;
  2847. return;
  2848. }
  2849. /* The instruction has the PC as its target register. */
  2850. operand1 = inst_env->reg[cris_get_operand1 (inst)];
  2851. operand2 = inst_env->reg[REG_PC];
  2852. /* Check if it's a extend, signed or zero instruction. */
  2853. if (cris_get_opcode (inst) < 4)
  2854. {
  2855. operand1 = do_sign_or_zero_extend (operand1, &inst);
  2856. }
  2857. /* Calculate the PC value after the instruction, i.e. where the
  2858. breakpoint should be. The order of the udw_operands is vital. */
  2859. add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
  2860. }
  2861. inst_env->slot_needed = 0;
  2862. inst_env->prefix_found = 0;
  2863. inst_env->xflag_found = 0;
  2864. inst_env->disable_interrupt = 0;
  2865. }
  2866. /* Returns the data contained at address. The size of the data is derived from
  2867. the size of the operation. If the instruction is a zero or signed
  2868. extend instruction, the size field is changed in instruction. */
  2869. static unsigned long
  2870. get_data_from_address (unsigned short *inst, CORE_ADDR address,
  2871. enum bfd_endian byte_order)
  2872. {
  2873. int size = cris_get_size (*inst);
  2874. unsigned long value;
  2875. /* If it's an extend instruction we don't want the signed extend bit,
  2876. because it influences the size. */
  2877. if (cris_get_opcode (*inst) < 4)
  2878. {
  2879. size &= ~SIGNED_EXTEND_BIT_MASK;
  2880. }
  2881. /* Is there a need for checking the size? Size should contain the number of
  2882. bytes to read. */
  2883. size = 1 << size;
  2884. value = read_memory_unsigned_integer (address, size, byte_order);
  2885. /* Check if it's an extend, signed or zero instruction. */
  2886. if (cris_get_opcode (*inst) < 4)
  2887. {
  2888. value = do_sign_or_zero_extend (value, inst);
  2889. }
  2890. return value;
  2891. }
  2892. /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
  2893. instructions. The MOVE instruction is the move from source to register. */
  2894. static void
  2895. handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
  2896. inst_env_type *inst_env)
  2897. {
  2898. unsigned long operand2;
  2899. unsigned long operand3;
  2900. check_assign (inst, inst_env);
  2901. if (cris_get_operand2 (inst) == REG_PC)
  2902. {
  2903. operand2 = inst_env->reg[REG_PC];
  2904. /* Get the value of the third operand. */
  2905. operand3 = get_data_from_address (&inst, inst_env->prefix_value,
  2906. inst_env->byte_order);
  2907. /* Calculate the PC value after the instruction, i.e. where the
  2908. breakpoint should be. The order of the udw_operands is vital. */
  2909. add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
  2910. }
  2911. inst_env->slot_needed = 0;
  2912. inst_env->prefix_found = 0;
  2913. inst_env->xflag_found = 0;
  2914. inst_env->disable_interrupt = 0;
  2915. }
  2916. /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
  2917. OR instructions. Note that for this to work as expected, the calling
  2918. function must have made sure that there is a prefix to this instruction. */
  2919. static void
  2920. three_operand_add_sub_cmp_and_or_op (unsigned short inst,
  2921. inst_env_type *inst_env)
  2922. {
  2923. unsigned long operand2;
  2924. unsigned long operand3;
  2925. if (cris_get_operand1 (inst) == REG_PC)
  2926. {
  2927. /* The PC will be changed by the instruction. */
  2928. operand2 = inst_env->reg[cris_get_operand2 (inst)];
  2929. /* Get the value of the third operand. */
  2930. operand3 = get_data_from_address (&inst, inst_env->prefix_value,
  2931. inst_env->byte_order);
  2932. /* Calculate the PC value after the instruction, i.e. where the
  2933. breakpoint should be. */
  2934. add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
  2935. }
  2936. inst_env->slot_needed = 0;
  2937. inst_env->prefix_found = 0;
  2938. inst_env->xflag_found = 0;
  2939. inst_env->disable_interrupt = 0;
  2940. }
  2941. /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
  2942. instructions. The MOVE instruction is the move from source to register. */
  2943. static void
  2944. handle_prefix_index_mode_for_aritm_op (unsigned short inst,
  2945. inst_env_type *inst_env)
  2946. {
  2947. if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
  2948. {
  2949. /* If the instruction is MOVE it's invalid. If the instruction is ADD,
  2950. SUB, AND or OR something weird is going on (if everything works these
  2951. instructions should end up in the three operand version). */
  2952. inst_env->invalid = 1;
  2953. return;
  2954. }
  2955. else
  2956. {
  2957. /* three_operand_add_sub_cmp_and_or does the same as we should do here
  2958. so use it. */
  2959. three_operand_add_sub_cmp_and_or_op (inst, inst_env);
  2960. }
  2961. inst_env->slot_needed = 0;
  2962. inst_env->prefix_found = 0;
  2963. inst_env->xflag_found = 0;
  2964. inst_env->disable_interrupt = 0;
  2965. }
  2966. /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
  2967. CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
  2968. source to register. */
  2969. static void
  2970. handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
  2971. inst_env_type *inst_env)
  2972. {
  2973. unsigned long operand1;
  2974. unsigned long operand2;
  2975. unsigned long operand3;
  2976. int size;
  2977. /* The instruction is either an indirect or autoincrement addressing mode.
  2978. Check if the destination register is the PC. */
  2979. if (cris_get_operand2 (inst) == REG_PC)
  2980. {
  2981. /* Must be done here, get_data_from_address may change the size
  2982. field. */
  2983. size = cris_get_size (inst);
  2984. operand2 = inst_env->reg[REG_PC];
  2985. /* Get the value of the third operand, i.e. the indirect operand. */
  2986. operand1 = inst_env->reg[cris_get_operand1 (inst)];
  2987. operand3 = get_data_from_address (&inst, operand1, inst_env->byte_order);
  2988. /* Calculate the PC value after the instruction, i.e. where the
  2989. breakpoint should be. The order of the udw_operands is vital. */
  2990. add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
  2991. }
  2992. /* If this is an autoincrement addressing mode, check if the increment
  2993. changes the PC. */
  2994. if ((cris_get_operand1 (inst) == REG_PC)
  2995. && (cris_get_mode (inst) == AUTOINC_MODE))
  2996. {
  2997. /* Get the size field. */
  2998. size = cris_get_size (inst);
  2999. /* If it's an extend instruction we don't want the signed extend bit,
  3000. because it influences the size. */
  3001. if (cris_get_opcode (inst) < 4)
  3002. {
  3003. size &= ~SIGNED_EXTEND_BIT_MASK;
  3004. }
  3005. process_autoincrement (size, inst, inst_env);
  3006. }
  3007. inst_env->slot_needed = 0;
  3008. inst_env->prefix_found = 0;
  3009. inst_env->xflag_found = 0;
  3010. inst_env->disable_interrupt = 0;
  3011. }
  3012. /* Handles the two-operand addressing mode, all modes except register, for
  3013. the ADD, SUB CMP, AND and OR instruction. */
  3014. static void
  3015. none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
  3016. inst_env_type *inst_env)
  3017. {
  3018. if (inst_env->prefix_found)
  3019. {
  3020. if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
  3021. {
  3022. handle_prefix_index_mode_for_aritm_op (inst, inst_env);
  3023. }
  3024. else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
  3025. {
  3026. handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
  3027. }
  3028. else
  3029. {
  3030. /* The mode is invalid for a prefixed base instruction. */
  3031. inst_env->invalid = 1;
  3032. return;
  3033. }
  3034. }
  3035. else
  3036. {
  3037. handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
  3038. }
  3039. }
  3040. /* Handles the quick addressing mode for the ADD and SUB instruction. */
  3041. static void
  3042. quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
  3043. {
  3044. unsigned long operand1;
  3045. unsigned long operand2;
  3046. /* It's a bad idea to be in a prefix instruction now. This is a quick mode
  3047. instruction and can't have a prefix. */
  3048. if (inst_env->prefix_found)
  3049. {
  3050. inst_env->invalid = 1;
  3051. return;
  3052. }
  3053. /* Check if the instruction has PC as its target. */
  3054. if (cris_get_operand2 (inst) == REG_PC)
  3055. {
  3056. if (inst_env->slot_needed)
  3057. {
  3058. inst_env->invalid = 1;
  3059. return;
  3060. }
  3061. operand1 = cris_get_quick_value (inst);
  3062. operand2 = inst_env->reg[REG_PC];
  3063. /* The size should now be dword. */
  3064. cris_set_size_to_dword (&inst);
  3065. /* Calculate the PC value after the instruction, i.e. where the
  3066. breakpoint should be. */
  3067. add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
  3068. }
  3069. inst_env->slot_needed = 0;
  3070. inst_env->prefix_found = 0;
  3071. inst_env->xflag_found = 0;
  3072. inst_env->disable_interrupt = 0;
  3073. }
  3074. /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
  3075. static void
  3076. quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
  3077. {
  3078. unsigned long operand1;
  3079. unsigned long operand2;
  3080. /* It's a bad idea to be in a prefix instruction now. This is a quick mode
  3081. instruction and can't have a prefix. */
  3082. if (inst_env->prefix_found)
  3083. {
  3084. inst_env->invalid = 1;
  3085. return;
  3086. }
  3087. /* Check if the instruction has PC as its target. */
  3088. if (cris_get_operand2 (inst) == REG_PC)
  3089. {
  3090. if (inst_env->slot_needed)
  3091. {
  3092. inst_env->invalid = 1;
  3093. return;
  3094. }
  3095. /* The instruction has the PC as its target register. */
  3096. operand1 = cris_get_quick_value (inst);
  3097. operand2 = inst_env->reg[REG_PC];
  3098. /* The quick value is signed, so check if we must do a signed extend. */
  3099. if (operand1 & SIGNED_QUICK_VALUE_MASK)
  3100. {
  3101. /* sign extend */
  3102. operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
  3103. }
  3104. /* The size should now be dword. */
  3105. cris_set_size_to_dword (&inst);
  3106. /* Calculate the PC value after the instruction, i.e. where the
  3107. breakpoint should be. */
  3108. add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
  3109. }
  3110. inst_env->slot_needed = 0;
  3111. inst_env->prefix_found = 0;
  3112. inst_env->xflag_found = 0;
  3113. inst_env->disable_interrupt = 0;
  3114. }
  3115. /* Translate op_type to a function and call it. */
  3116. static void
  3117. cris_gdb_func (struct gdbarch *gdbarch, enum cris_op_type op_type,
  3118. unsigned short inst, inst_env_type *inst_env)
  3119. {
  3120. switch (op_type)
  3121. {
  3122. case cris_not_implemented_op:
  3123. not_implemented_op (inst, inst_env);
  3124. break;
  3125. case cris_abs_op:
  3126. abs_op (inst, inst_env);
  3127. break;
  3128. case cris_addi_op:
  3129. addi_op (inst, inst_env);
  3130. break;
  3131. case cris_asr_op:
  3132. asr_op (inst, inst_env);
  3133. break;
  3134. case cris_asrq_op:
  3135. asrq_op (inst, inst_env);
  3136. break;
  3137. case cris_ax_ei_setf_op:
  3138. ax_ei_setf_op (inst, inst_env);
  3139. break;
  3140. case cris_bdap_prefix:
  3141. bdap_prefix (inst, inst_env);
  3142. break;
  3143. case cris_biap_prefix:
  3144. biap_prefix (inst, inst_env);
  3145. break;
  3146. case cris_break_op:
  3147. break_op (inst, inst_env);
  3148. break;
  3149. case cris_btst_nop_op:
  3150. btst_nop_op (inst, inst_env);
  3151. break;
  3152. case cris_clearf_di_op:
  3153. clearf_di_op (inst, inst_env);
  3154. break;
  3155. case cris_dip_prefix:
  3156. dip_prefix (inst, inst_env);
  3157. break;
  3158. case cris_dstep_logshift_mstep_neg_not_op:
  3159. dstep_logshift_mstep_neg_not_op (inst, inst_env);
  3160. break;
  3161. case cris_eight_bit_offset_branch_op:
  3162. eight_bit_offset_branch_op (inst, inst_env);
  3163. break;
  3164. case cris_move_mem_to_reg_movem_op:
  3165. move_mem_to_reg_movem_op (inst, inst_env);
  3166. break;
  3167. case cris_move_reg_to_mem_movem_op:
  3168. move_reg_to_mem_movem_op (inst, inst_env);
  3169. break;
  3170. case cris_move_to_preg_op:
  3171. move_to_preg_op (gdbarch, inst, inst_env);
  3172. break;
  3173. case cris_muls_op:
  3174. muls_op (inst, inst_env);
  3175. break;
  3176. case cris_mulu_op:
  3177. mulu_op (inst, inst_env);
  3178. break;
  3179. case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
  3180. none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
  3181. break;
  3182. case cris_none_reg_mode_clear_test_op:
  3183. none_reg_mode_clear_test_op (inst, inst_env);
  3184. break;
  3185. case cris_none_reg_mode_jump_op:
  3186. none_reg_mode_jump_op (inst, inst_env);
  3187. break;
  3188. case cris_none_reg_mode_move_from_preg_op:
  3189. none_reg_mode_move_from_preg_op (gdbarch, inst, inst_env);
  3190. break;
  3191. case cris_quick_mode_add_sub_op:
  3192. quick_mode_add_sub_op (inst, inst_env);
  3193. break;
  3194. case cris_quick_mode_and_cmp_move_or_op:
  3195. quick_mode_and_cmp_move_or_op (inst, inst_env);
  3196. break;
  3197. case cris_quick_mode_bdap_prefix:
  3198. quick_mode_bdap_prefix (inst, inst_env);
  3199. break;
  3200. case cris_reg_mode_add_sub_cmp_and_or_move_op:
  3201. reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
  3202. break;
  3203. case cris_reg_mode_clear_op:
  3204. reg_mode_clear_op (inst, inst_env);
  3205. break;
  3206. case cris_reg_mode_jump_op:
  3207. reg_mode_jump_op (inst, inst_env);
  3208. break;
  3209. case cris_reg_mode_move_from_preg_op:
  3210. reg_mode_move_from_preg_op (inst, inst_env);
  3211. break;
  3212. case cris_reg_mode_test_op:
  3213. reg_mode_test_op (inst, inst_env);
  3214. break;
  3215. case cris_scc_op:
  3216. scc_op (inst, inst_env);
  3217. break;
  3218. case cris_sixteen_bit_offset_branch_op:
  3219. sixteen_bit_offset_branch_op (inst, inst_env);
  3220. break;
  3221. case cris_three_operand_add_sub_cmp_and_or_op:
  3222. three_operand_add_sub_cmp_and_or_op (inst, inst_env);
  3223. break;
  3224. case cris_three_operand_bound_op:
  3225. three_operand_bound_op (inst, inst_env);
  3226. break;
  3227. case cris_two_operand_bound_op:
  3228. two_operand_bound_op (inst, inst_env);
  3229. break;
  3230. case cris_xor_op:
  3231. xor_op (inst, inst_env);
  3232. break;
  3233. }
  3234. }
  3235. /* Originally from <asm/elf.h>. */
  3236. typedef unsigned char cris_elf_greg_t[4];
  3237. /* Same as user_regs_struct struct in <asm/user.h>. */
  3238. #define CRISV10_ELF_NGREG 35
  3239. typedef cris_elf_greg_t cris_elf_gregset_t[CRISV10_ELF_NGREG];
  3240. #define CRISV32_ELF_NGREG 32
  3241. typedef cris_elf_greg_t crisv32_elf_gregset_t[CRISV32_ELF_NGREG];
  3242. /* Unpack a cris_elf_gregset_t into GDB's register cache. */
  3243. static void
  3244. cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
  3245. int regnum, const void *gregs, size_t len)
  3246. {
  3247. struct gdbarch *gdbarch = regcache->arch ();
  3248. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3249. int i;
  3250. const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
  3251. if (len != sizeof (cris_elf_gregset_t)
  3252. && len != sizeof (crisv32_elf_gregset_t))
  3253. warning (_("wrong size gregset struct in core file"));
  3254. gdb_assert (len >= sizeof (crisv32_elf_gregset_t));
  3255. /* The kernel dumps all 32 registers as unsigned longs, but supply_register
  3256. knows about the actual size of each register so that's no problem. */
  3257. for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
  3258. {
  3259. if (regnum == -1 || regnum == i)
  3260. regcache->raw_supply (i, (char *)&regp[i]);
  3261. }
  3262. if (tdep->cris_version == 32 && (regnum == -1 || regnum == ERP_REGNUM))
  3263. {
  3264. /* Needed to set pseudo-register PC for CRISv32. */
  3265. /* FIXME: If ERP is in a delay slot at this point then the PC will
  3266. be wrong. Issue a warning to alert the user. */
  3267. regcache->raw_supply (gdbarch_pc_regnum (gdbarch),
  3268. (char *)&regp[ERP_REGNUM]);
  3269. if (*(char *)&regp[ERP_REGNUM] & 0x1)
  3270. gdb_printf (gdb_stderr, "Warning: PC in delay slot\n");
  3271. }
  3272. }
  3273. static const struct regset cris_regset = {
  3274. nullptr,
  3275. cris_supply_gregset,
  3276. /* We don't need a collect function because we only use this for core files
  3277. (via iterate_over_regset_sections). */
  3278. nullptr,
  3279. REGSET_VARIABLE_SIZE
  3280. };
  3281. static void cris_iterate_over_regset_sections (struct gdbarch *gdbarch,
  3282. iterate_over_regset_sections_cb *cb,
  3283. void *cb_data,
  3284. const struct regcache *regcache)
  3285. {
  3286. cb (".reg", sizeof (crisv32_elf_gregset_t), sizeof (crisv32_elf_gregset_t),
  3287. &cris_regset, NULL, cb_data);
  3288. }
  3289. void _initialize_cris_tdep ();
  3290. void
  3291. _initialize_cris_tdep ()
  3292. {
  3293. gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
  3294. /* CRIS-specific user-commands. */
  3295. add_setshow_zuinteger_cmd ("cris-version", class_support,
  3296. &usr_cmd_cris_version,
  3297. _("Set the current CRIS version."),
  3298. _("Show the current CRIS version."),
  3299. _("\
  3300. Set to 10 for CRISv10 or 32 for CRISv32 if autodetection fails.\n\
  3301. Defaults to 10. "),
  3302. set_cris_version,
  3303. NULL, /* FIXME: i18n: Current CRIS version
  3304. is %s. */
  3305. &setlist, &showlist);
  3306. add_setshow_enum_cmd ("cris-mode", class_support,
  3307. cris_modes, &usr_cmd_cris_mode,
  3308. _("Set the current CRIS mode."),
  3309. _("Show the current CRIS mode."),
  3310. _("\
  3311. Set to CRIS_MODE_GURU when debugging in guru mode.\n\
  3312. Makes GDB use the NRP register instead of the ERP register in certain cases."),
  3313. set_cris_mode,
  3314. NULL, /* FIXME: i18n: Current CRIS version is %s. */
  3315. &setlist, &showlist);
  3316. add_setshow_boolean_cmd ("cris-dwarf2-cfi", class_support,
  3317. &usr_cmd_cris_dwarf2_cfi,
  3318. _("Set the usage of Dwarf-2 CFI for CRIS."),
  3319. _("Show the usage of Dwarf-2 CFI for CRIS."),
  3320. _("Set this to \"off\" if using gcc-cris < R59."),
  3321. set_cris_dwarf2_cfi,
  3322. NULL, /* FIXME: i18n: Usage of Dwarf-2 CFI
  3323. for CRIS is %d. */
  3324. &setlist, &showlist);
  3325. }
  3326. /* Prints out all target specific values. */
  3327. static void
  3328. cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
  3329. {
  3330. cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3331. if (tdep != NULL)
  3332. {
  3333. gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
  3334. tdep->cris_version);
  3335. gdb_printf (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
  3336. tdep->cris_mode);
  3337. gdb_printf (file, "cris_dump_tdep: tdep->cris_dwarf2_cfi = %i\n",
  3338. tdep->cris_dwarf2_cfi);
  3339. }
  3340. }
  3341. static void
  3342. set_cris_version (const char *ignore_args, int from_tty,
  3343. struct cmd_list_element *c)
  3344. {
  3345. struct gdbarch_info info;
  3346. usr_cmd_cris_version_valid = 1;
  3347. /* Update the current architecture, if needed. */
  3348. if (!gdbarch_update_p (info))
  3349. internal_error (__FILE__, __LINE__,
  3350. _("cris_gdbarch_update: failed to update architecture."));
  3351. }
  3352. static void
  3353. set_cris_mode (const char *ignore_args, int from_tty,
  3354. struct cmd_list_element *c)
  3355. {
  3356. struct gdbarch_info info;
  3357. /* Update the current architecture, if needed. */
  3358. if (!gdbarch_update_p (info))
  3359. internal_error (__FILE__, __LINE__,
  3360. "cris_gdbarch_update: failed to update architecture.");
  3361. }
  3362. static void
  3363. set_cris_dwarf2_cfi (const char *ignore_args, int from_tty,
  3364. struct cmd_list_element *c)
  3365. {
  3366. struct gdbarch_info info;
  3367. /* Update the current architecture, if needed. */
  3368. if (!gdbarch_update_p (info))
  3369. internal_error (__FILE__, __LINE__,
  3370. _("cris_gdbarch_update: failed to update architecture."));
  3371. }
  3372. static struct gdbarch *
  3373. cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  3374. {
  3375. struct gdbarch *gdbarch;
  3376. unsigned int cris_version;
  3377. if (usr_cmd_cris_version_valid)
  3378. {
  3379. /* Trust the user's CRIS version setting. */
  3380. cris_version = usr_cmd_cris_version;
  3381. }
  3382. else if (info.abfd && bfd_get_mach (info.abfd) == bfd_mach_cris_v32)
  3383. {
  3384. cris_version = 32;
  3385. }
  3386. else
  3387. {
  3388. /* Assume it's CRIS version 10. */
  3389. cris_version = 10;
  3390. }
  3391. /* Make the current settings visible to the user. */
  3392. usr_cmd_cris_version = cris_version;
  3393. /* Find a candidate among the list of pre-declared architectures. */
  3394. for (arches = gdbarch_list_lookup_by_info (arches, &info);
  3395. arches != NULL;
  3396. arches = gdbarch_list_lookup_by_info (arches->next, &info))
  3397. {
  3398. cris_gdbarch_tdep *tdep
  3399. = (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
  3400. if (tdep->cris_version == usr_cmd_cris_version
  3401. && tdep->cris_mode == usr_cmd_cris_mode
  3402. && tdep->cris_dwarf2_cfi == usr_cmd_cris_dwarf2_cfi)
  3403. return arches->gdbarch;
  3404. }
  3405. /* No matching architecture was found. Create a new one. */
  3406. cris_gdbarch_tdep *tdep = new cris_gdbarch_tdep;
  3407. info.byte_order = BFD_ENDIAN_LITTLE;
  3408. gdbarch = gdbarch_alloc (&info, tdep);
  3409. tdep->cris_version = usr_cmd_cris_version;
  3410. tdep->cris_mode = usr_cmd_cris_mode;
  3411. tdep->cris_dwarf2_cfi = usr_cmd_cris_dwarf2_cfi;
  3412. set_gdbarch_return_value (gdbarch, cris_return_value);
  3413. set_gdbarch_sp_regnum (gdbarch, 14);
  3414. /* Length of ordinary registers used in push_word and a few other
  3415. places. register_size() is the real way to know how big a
  3416. register is. */
  3417. set_gdbarch_double_bit (gdbarch, 64);
  3418. /* The default definition of a long double is 2 * gdbarch_double_bit,
  3419. which means we have to set this explicitly. */
  3420. set_gdbarch_long_double_bit (gdbarch, 64);
  3421. /* The total amount of space needed to store (in an array called registers)
  3422. GDB's copy of the machine's register state. Note: We can not use
  3423. cris_register_size at this point, since it relies on gdbarch
  3424. being set. */
  3425. switch (tdep->cris_version)
  3426. {
  3427. case 0:
  3428. case 1:
  3429. case 2:
  3430. case 3:
  3431. case 8:
  3432. case 9:
  3433. /* Old versions; not supported. */
  3434. return 0;
  3435. case 10:
  3436. case 11:
  3437. /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
  3438. P7 (32 bits), and P15 (32 bits) have been implemented. */
  3439. set_gdbarch_pc_regnum (gdbarch, 15);
  3440. set_gdbarch_register_type (gdbarch, cris_register_type);
  3441. /* There are 32 registers (some of which may not be implemented). */
  3442. set_gdbarch_num_regs (gdbarch, 32);
  3443. set_gdbarch_register_name (gdbarch, cris_register_name);
  3444. set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
  3445. set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
  3446. set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
  3447. break;
  3448. case 32:
  3449. /* CRIS v32. General registers R0 - R15 (32 bits), special registers
  3450. P0 - P15 (32 bits) except P0, P1, P3 (8 bits) and P4 (16 bits)
  3451. and pseudo-register PC (32 bits). */
  3452. set_gdbarch_pc_regnum (gdbarch, 32);
  3453. set_gdbarch_register_type (gdbarch, crisv32_register_type);
  3454. /* 32 registers + pseudo-register PC + 16 support registers. */
  3455. set_gdbarch_num_regs (gdbarch, 32 + 1 + 16);
  3456. set_gdbarch_register_name (gdbarch, crisv32_register_name);
  3457. set_gdbarch_cannot_store_register
  3458. (gdbarch, crisv32_cannot_store_register);
  3459. set_gdbarch_cannot_fetch_register
  3460. (gdbarch, crisv32_cannot_fetch_register);
  3461. set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
  3462. set_gdbarch_single_step_through_delay
  3463. (gdbarch, crisv32_single_step_through_delay);
  3464. break;
  3465. default:
  3466. /* Unknown version. */
  3467. return 0;
  3468. }
  3469. /* Dummy frame functions (shared between CRISv10 and CRISv32 since they
  3470. have the same ABI). */
  3471. set_gdbarch_push_dummy_code (gdbarch, cris_push_dummy_code);
  3472. set_gdbarch_push_dummy_call (gdbarch, cris_push_dummy_call);
  3473. set_gdbarch_frame_align (gdbarch, cris_frame_align);
  3474. set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
  3475. /* The stack grows downward. */
  3476. set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  3477. set_gdbarch_breakpoint_kind_from_pc (gdbarch, cris_breakpoint_kind_from_pc);
  3478. set_gdbarch_sw_breakpoint_from_kind (gdbarch, cris_sw_breakpoint_from_kind);
  3479. set_gdbarch_iterate_over_regset_sections (gdbarch, cris_iterate_over_regset_sections);
  3480. if (tdep->cris_dwarf2_cfi == 1)
  3481. {
  3482. /* Hook in the Dwarf-2 frame sniffer. */
  3483. set_gdbarch_dwarf2_reg_to_regnum (gdbarch, cris_dwarf2_reg_to_regnum);
  3484. dwarf2_frame_set_init_reg (gdbarch, cris_dwarf2_frame_init_reg);
  3485. dwarf2_append_unwinders (gdbarch);
  3486. }
  3487. if (tdep->cris_mode != cris_mode_guru)
  3488. {
  3489. frame_unwind_append_unwinder (gdbarch, &cris_sigtramp_frame_unwind);
  3490. }
  3491. frame_unwind_append_unwinder (gdbarch, &cris_frame_unwind);
  3492. frame_base_set_default (gdbarch, &cris_frame_base);
  3493. /* Hook in ABI-specific overrides, if they have been registered. */
  3494. gdbarch_init_osabi (info, gdbarch);
  3495. return gdbarch;
  3496. }