head.S 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957
  1. /* -*- mode: asm -*-
  2. **
  3. ** head.S -- This file contains the initial boot code for the
  4. ** Linux/68k kernel.
  5. **
  6. ** Copyright 1993 by Hamish Macdonald
  7. **
  8. ** 68040 fixes by Michael Rausch
  9. ** 68060 fixes by Roman Hodek
  10. ** MMU cleanup by Randy Thelen
  11. ** Final MMU cleanup by Roman Zippel
  12. **
  13. ** Atari support by Andreas Schwab, using ideas of Robert de Vries
  14. ** and Bjoern Brauel
  15. ** VME Support by Richard Hirst
  16. **
  17. ** 94/11/14 Andreas Schwab: put kernel at PAGESIZE
  18. ** 94/11/18 Andreas Schwab: remove identity mapping of STRAM for Atari
  19. ** ++ Bjoern & Roman: ATARI-68040 support for the Medusa
  20. ** 95/11/18 Richard Hirst: Added MVME166 support
  21. ** 96/04/26 Guenther Kelleter: fixed identity mapping for Falcon with
  22. ** Magnum- and FX-alternate ram
  23. ** 98/04/25 Phil Blundell: added HP300 support
  24. ** 1998/08/30 David Kilzer: Added support for font_desc structures
  25. ** for linux-2.1.115
  26. ** 1999/02/11 Richard Zidlicky: added Q40 support (initial version 99/01/01)
  27. ** 2004/05/13 Kars de Jong: Finalised HP300 support
  28. **
  29. ** This file is subject to the terms and conditions of the GNU General Public
  30. ** License. See the file README.legal in the main directory of this archive
  31. ** for more details.
  32. **
  33. */
  34. /*
  35. * Linux startup code.
  36. *
  37. * At this point, the boot loader has:
  38. * Disabled interrupts
  39. * Disabled caches
  40. * Put us in supervisor state.
  41. *
  42. * The kernel setup code takes the following steps:
  43. * . Raise interrupt level
  44. * . Set up initial kernel memory mapping.
  45. * . This sets up a mapping of the 4M of memory the kernel is located in.
  46. * . It also does a mapping of any initial machine specific areas.
  47. * . Enable the MMU
  48. * . Enable cache memories
  49. * . Jump to kernel startup
  50. *
  51. * Much of the file restructuring was to accomplish:
  52. * 1) Remove register dependency through-out the file.
  53. * 2) Increase use of subroutines to perform functions
  54. * 3) Increase readability of the code
  55. *
  56. * Of course, readability is a subjective issue, so it will never be
  57. * argued that that goal was accomplished. It was merely a goal.
  58. * A key way to help make code more readable is to give good
  59. * documentation. So, the first thing you will find is exaustive
  60. * write-ups on the structure of the file, and the features of the
  61. * functional subroutines.
  62. *
  63. * General Structure:
  64. * ------------------
  65. * Without a doubt the single largest chunk of head.S is spent
  66. * mapping the kernel and I/O physical space into the logical range
  67. * for the kernel.
  68. * There are new subroutines and data structures to make MMU
  69. * support cleaner and easier to understand.
  70. * First, you will find a routine call "mmu_map" which maps
  71. * a logical to a physical region for some length given a cache
  72. * type on behalf of the caller. This routine makes writing the
  73. * actual per-machine specific code very simple.
  74. * A central part of the code, but not a subroutine in itself,
  75. * is the mmu_init code which is broken down into mapping the kernel
  76. * (the same for all machines) and mapping machine-specific I/O
  77. * regions.
  78. * Also, there will be a description of engaging the MMU and
  79. * caches.
  80. * You will notice that there is a chunk of code which
  81. * can emit the entire MMU mapping of the machine. This is present
  82. * only in debug modes and can be very helpful.
  83. * Further, there is a new console driver in head.S that is
  84. * also only engaged in debug mode. Currently, it's only supported
  85. * on the Macintosh class of machines. However, it is hoped that
  86. * others will plug-in support for specific machines.
  87. *
  88. * ######################################################################
  89. *
  90. * mmu_map
  91. * -------
  92. * mmu_map was written for two key reasons. First, it was clear
  93. * that it was very difficult to read the previous code for mapping
  94. * regions of memory. Second, the Macintosh required such extensive
  95. * memory allocations that it didn't make sense to propagate the
  96. * existing code any further.
  97. * mmu_map requires some parameters:
  98. *
  99. * mmu_map (logical, physical, length, cache_type)
  100. *
  101. * While this essentially describes the function in the abstract, you'll
  102. * find more indepth description of other parameters at the implementation site.
  103. *
  104. * mmu_get_root_table_entry
  105. * ------------------------
  106. * mmu_get_ptr_table_entry
  107. * -----------------------
  108. * mmu_get_page_table_entry
  109. * ------------------------
  110. *
  111. * These routines are used by other mmu routines to get a pointer into
  112. * a table, if necessary a new table is allocated. These routines are working
  113. * basically like pmd_alloc() and pte_alloc() in <asm/pgtable.h>. The root
  114. * table needs of course only to be allocated once in mmu_get_root_table_entry,
  115. * so that here also some mmu specific initialization is done. The second page
  116. * at the start of the kernel (the first page is unmapped later) is used for
  117. * the kernel_pg_dir. It must be at a position known at link time (as it's used
  118. * to initialize the init task struct) and since it needs special cache
  119. * settings, it's the easiest to use this page, the rest of the page is used
  120. * for further pointer tables.
  121. * mmu_get_page_table_entry allocates always a whole page for page tables, this
  122. * means 1024 pages and so 4MB of memory can be mapped. It doesn't make sense
  123. * to manage page tables in smaller pieces as nearly all mappings have that
  124. * size.
  125. *
  126. * ######################################################################
  127. *
  128. *
  129. * ######################################################################
  130. *
  131. * mmu_engage
  132. * ----------
  133. * Thanks to a small helping routine enabling the mmu got quite simple
  134. * and there is only one way left. mmu_engage makes a complete a new mapping
  135. * that only includes the absolute necessary to be able to jump to the final
  136. * position and to restore the original mapping.
  137. * As this code doesn't need a transparent translation register anymore this
  138. * means all registers are free to be used by machines that needs them for
  139. * other purposes.
  140. *
  141. * ######################################################################
  142. *
  143. * mmu_print
  144. * ---------
  145. * This algorithm will print out the page tables of the system as
  146. * appropriate for an 030 or an 040. This is useful for debugging purposes
  147. * and as such is enclosed in #ifdef MMU_PRINT/#endif clauses.
  148. *
  149. * ######################################################################
  150. *
  151. * console_init
  152. * ------------
  153. * The console is also able to be turned off. The console in head.S
  154. * is specifically for debugging and can be very useful. It is surrounded by
  155. * #ifdef CONSOLE/#endif clauses so it doesn't have to ship in known-good
  156. * kernels. It's basic algorithm is to determine the size of the screen
  157. * (in height/width and bit depth) and then use that information for
  158. * displaying an 8x8 font or an 8x16 (widthxheight). I prefer the 8x8 for
  159. * debugging so I can see more good data. But it was trivial to add support
  160. * for both fonts, so I included it.
  161. * Also, the algorithm for plotting pixels is abstracted so that in
  162. * theory other platforms could add support for different kinds of frame
  163. * buffers. This could be very useful.
  164. *
  165. * console_put_penguin
  166. * -------------------
  167. * An important part of any Linux bring up is the penguin and there's
  168. * nothing like getting the Penguin on the screen! This algorithm will work
  169. * on any machine for which there is a console_plot_pixel.
  170. *
  171. * console_scroll
  172. * --------------
  173. * My hope is that the scroll algorithm does the right thing on the
  174. * various platforms, but it wouldn't be hard to add the test conditions
  175. * and new code if it doesn't.
  176. *
  177. * console_putc
  178. * -------------
  179. *
  180. * ######################################################################
  181. *
  182. * Register usage has greatly simplified within head.S. Every subroutine
  183. * saves and restores all registers that it modifies (except it returns a
  184. * value in there of course). So the only register that needs to be initialized
  185. * is the stack pointer.
  186. * All other init code and data is now placed in the init section, so it will
  187. * be automatically freed at the end of the kernel initialization.
  188. *
  189. * ######################################################################
  190. *
  191. * options
  192. * -------
  193. * There are many options available in a build of this file. I've
  194. * taken the time to describe them here to save you the time of searching
  195. * for them and trying to understand what they mean.
  196. *
  197. * CONFIG_xxx: These are the obvious machine configuration defines created
  198. * during configuration. These are defined in autoconf.h.
  199. *
  200. * CONSOLE: There is support for head.S console in this file. This
  201. * console can talk to a Mac frame buffer, but could easily be extrapolated
  202. * to extend it to support other platforms.
  203. *
  204. * TEST_MMU: This is a test harness for running on any given machine but
  205. * getting an MMU dump for another class of machine. The classes of machines
  206. * that can be tested are any of the makes (Atari, Amiga, Mac, VME, etc.)
  207. * and any of the models (030, 040, 060, etc.).
  208. *
  209. * NOTE: TEST_MMU is NOT permanent! It is scheduled to be removed
  210. * When head.S boots on Atari, Amiga, Macintosh, and VME
  211. * machines. At that point the underlying logic will be
  212. * believed to be solid enough to be trusted, and TEST_MMU
  213. * can be dropped. Do note that that will clean up the
  214. * head.S code significantly as large blocks of #if/#else
  215. * clauses can be removed.
  216. *
  217. * MMU_NOCACHE_KERNEL: On the Macintosh platform there was an inquiry into
  218. * determing why devices don't appear to work. A test case was to remove
  219. * the cacheability of the kernel bits.
  220. *
  221. * MMU_PRINT: There is a routine built into head.S that can display the
  222. * MMU data structures. It outputs its result through the serial_putc
  223. * interface. So where ever that winds up driving data, that's where the
  224. * mmu struct will appear. On the Macintosh that's typically the console.
  225. *
  226. * SERIAL_DEBUG: There are a series of putc() macro statements
  227. * scattered through out the code to give progress of status to the
  228. * person sitting at the console. This constant determines whether those
  229. * are used.
  230. *
  231. * DEBUG: This is the standard DEBUG flag that can be set for building
  232. * the kernel. It has the effect adding additional tests into
  233. * the code.
  234. *
  235. * FONT_6x11:
  236. * FONT_8x8:
  237. * FONT_8x16:
  238. * In theory these could be determined at run time or handed
  239. * over by the booter. But, let's be real, it's a fine hard
  240. * coded value. (But, you will notice the code is run-time
  241. * flexible!) A pointer to the font's struct font_desc
  242. * is kept locally in Lconsole_font. It is used to determine
  243. * font size information dynamically.
  244. *
  245. * Atari constants:
  246. * USE_PRINTER: Use the printer port for serial debug.
  247. * USE_SCC_B: Use the SCC port A (Serial2) for serial debug.
  248. * USE_SCC_A: Use the SCC port B (Modem2) for serial debug.
  249. * USE_MFP: Use the ST-MFP port (Modem1) for serial debug.
  250. *
  251. * Macintosh constants:
  252. * MAC_USE_SCC_A: Use SCC port A (modem) for serial debug and early console.
  253. * MAC_USE_SCC_B: Use SCC port B (printer) for serial debug and early console.
  254. */
  255. #include <linux/linkage.h>
  256. #include <linux/init.h>
  257. #include <asm/bootinfo.h>
  258. #include <asm/bootinfo-amiga.h>
  259. #include <asm/bootinfo-atari.h>
  260. #include <asm/bootinfo-hp300.h>
  261. #include <asm/bootinfo-mac.h>
  262. #include <asm/bootinfo-q40.h>
  263. #include <asm/bootinfo-vme.h>
  264. #include <asm/setup.h>
  265. #include <asm/entry.h>
  266. #include <asm/pgtable.h>
  267. #include <asm/page.h>
  268. #include <asm/asm-offsets.h>
  269. #ifdef CONFIG_MAC
  270. #include <asm/machw.h>
  271. #ifdef CONFIG_FRAMEBUFFER_CONSOLE
  272. #define CONSOLE
  273. #define CONSOLE_PENGUIN
  274. #endif
  275. #ifdef CONFIG_EARLY_PRINTK
  276. #define SERIAL_DEBUG
  277. #else
  278. #undef SERIAL_DEBUG
  279. #endif
  280. #else /* !CONFIG_MAC */
  281. #define SERIAL_DEBUG
  282. #endif /* !CONFIG_MAC */
  283. #undef MMU_PRINT
  284. #undef MMU_NOCACHE_KERNEL
  285. #undef DEBUG
  286. /*
  287. * For the head.S console, there are three supported fonts, 6x11, 8x16 and 8x8.
  288. * The 8x8 font is harder to read but fits more on the screen.
  289. */
  290. #define FONT_8x8 /* default */
  291. /* #define FONT_8x16 */ /* 2nd choice */
  292. /* #define FONT_6x11 */ /* 3rd choice */
  293. .globl kernel_pg_dir
  294. .globl availmem
  295. .globl m68k_pgtable_cachemode
  296. .globl m68k_supervisor_cachemode
  297. #ifdef CONFIG_MVME16x
  298. .globl mvme_bdid
  299. #endif
  300. #ifdef CONFIG_Q40
  301. .globl q40_mem_cptr
  302. #endif
  303. CPUTYPE_040 = 1 /* indicates an 040 */
  304. CPUTYPE_060 = 2 /* indicates an 060 */
  305. CPUTYPE_0460 = 3 /* if either above are set, this is set */
  306. CPUTYPE_020 = 4 /* indicates an 020 */
  307. /* Translation control register */
  308. TC_ENABLE = 0x8000
  309. TC_PAGE8K = 0x4000
  310. TC_PAGE4K = 0x0000
  311. /* Transparent translation registers */
  312. TTR_ENABLE = 0x8000 /* enable transparent translation */
  313. TTR_ANYMODE = 0x4000 /* user and kernel mode access */
  314. TTR_KERNELMODE = 0x2000 /* only kernel mode access */
  315. TTR_USERMODE = 0x0000 /* only user mode access */
  316. TTR_CI = 0x0400 /* inhibit cache */
  317. TTR_RW = 0x0200 /* read/write mode */
  318. TTR_RWM = 0x0100 /* read/write mask */
  319. TTR_FCB2 = 0x0040 /* function code base bit 2 */
  320. TTR_FCB1 = 0x0020 /* function code base bit 1 */
  321. TTR_FCB0 = 0x0010 /* function code base bit 0 */
  322. TTR_FCM2 = 0x0004 /* function code mask bit 2 */
  323. TTR_FCM1 = 0x0002 /* function code mask bit 1 */
  324. TTR_FCM0 = 0x0001 /* function code mask bit 0 */
  325. /* Cache Control registers */
  326. CC6_ENABLE_D = 0x80000000 /* enable data cache (680[46]0) */
  327. CC6_FREEZE_D = 0x40000000 /* freeze data cache (68060) */
  328. CC6_ENABLE_SB = 0x20000000 /* enable store buffer (68060) */
  329. CC6_PUSH_DPI = 0x10000000 /* disable CPUSH invalidation (68060) */
  330. CC6_HALF_D = 0x08000000 /* half-cache mode for data cache (68060) */
  331. CC6_ENABLE_B = 0x00800000 /* enable branch cache (68060) */
  332. CC6_CLRA_B = 0x00400000 /* clear all entries in branch cache (68060) */
  333. CC6_CLRU_B = 0x00200000 /* clear user entries in branch cache (68060) */
  334. CC6_ENABLE_I = 0x00008000 /* enable instruction cache (680[46]0) */
  335. CC6_FREEZE_I = 0x00004000 /* freeze instruction cache (68060) */
  336. CC6_HALF_I = 0x00002000 /* half-cache mode for instruction cache (68060) */
  337. CC3_ALLOC_WRITE = 0x00002000 /* write allocate mode(68030) */
  338. CC3_ENABLE_DB = 0x00001000 /* enable data burst (68030) */
  339. CC3_CLR_D = 0x00000800 /* clear data cache (68030) */
  340. CC3_CLRE_D = 0x00000400 /* clear entry in data cache (68030) */
  341. CC3_FREEZE_D = 0x00000200 /* freeze data cache (68030) */
  342. CC3_ENABLE_D = 0x00000100 /* enable data cache (68030) */
  343. CC3_ENABLE_IB = 0x00000010 /* enable instruction burst (68030) */
  344. CC3_CLR_I = 0x00000008 /* clear instruction cache (68030) */
  345. CC3_CLRE_I = 0x00000004 /* clear entry in instruction cache (68030) */
  346. CC3_FREEZE_I = 0x00000002 /* freeze instruction cache (68030) */
  347. CC3_ENABLE_I = 0x00000001 /* enable instruction cache (68030) */
  348. /* Miscellaneous definitions */
  349. PAGESIZE = 4096
  350. PAGESHIFT = 12
  351. ROOT_TABLE_SIZE = 128
  352. PTR_TABLE_SIZE = 128
  353. PAGE_TABLE_SIZE = 64
  354. ROOT_INDEX_SHIFT = 25
  355. PTR_INDEX_SHIFT = 18
  356. PAGE_INDEX_SHIFT = 12
  357. #ifdef DEBUG
  358. /* When debugging use readable names for labels */
  359. #ifdef __STDC__
  360. #define L(name) .head.S.##name
  361. #else
  362. #define L(name) .head.S./**/name
  363. #endif
  364. #else
  365. #ifdef __STDC__
  366. #define L(name) .L##name
  367. #else
  368. #define L(name) .L/**/name
  369. #endif
  370. #endif
  371. /* The __INITDATA stuff is a no-op when ftrace or kgdb are turned on */
  372. #ifndef __INITDATA
  373. #define __INITDATA .data
  374. #define __FINIT .previous
  375. #endif
  376. /* Several macros to make the writing of subroutines easier:
  377. * - func_start marks the beginning of the routine which setups the frame
  378. * register and saves the registers, it also defines another macro
  379. * to automatically restore the registers again.
  380. * - func_return marks the end of the routine and simply calls the prepared
  381. * macro to restore registers and jump back to the caller.
  382. * - func_define generates another macro to automatically put arguments
  383. * onto the stack call the subroutine and cleanup the stack again.
  384. */
  385. /* Within subroutines these macros can be used to access the arguments
  386. * on the stack. With STACK some allocated memory on the stack can be
  387. * accessed and ARG0 points to the return address (used by mmu_engage).
  388. */
  389. #define STACK %a6@(stackstart)
  390. #define ARG0 %a6@(4)
  391. #define ARG1 %a6@(8)
  392. #define ARG2 %a6@(12)
  393. #define ARG3 %a6@(16)
  394. #define ARG4 %a6@(20)
  395. .macro func_start name,saveregs,stack=0
  396. L(\name):
  397. linkw %a6,#-\stack
  398. moveml \saveregs,%sp@-
  399. .set stackstart,-\stack
  400. .macro func_return_\name
  401. moveml %sp@+,\saveregs
  402. unlk %a6
  403. rts
  404. .endm
  405. .endm
  406. .macro func_return name
  407. func_return_\name
  408. .endm
  409. .macro func_call name
  410. jbsr L(\name)
  411. .endm
  412. .macro move_stack nr,arg1,arg2,arg3,arg4
  413. .if \nr
  414. move_stack "(\nr-1)",\arg2,\arg3,\arg4
  415. movel \arg1,%sp@-
  416. .endif
  417. .endm
  418. .macro func_define name,nr=0
  419. .macro \name arg1,arg2,arg3,arg4
  420. move_stack \nr,\arg1,\arg2,\arg3,\arg4
  421. func_call \name
  422. .if \nr
  423. lea %sp@(\nr*4),%sp
  424. .endif
  425. .endm
  426. .endm
  427. func_define mmu_map,4
  428. func_define mmu_map_tt,4
  429. func_define mmu_fixup_page_mmu_cache,1
  430. func_define mmu_temp_map,2
  431. func_define mmu_engage
  432. func_define mmu_get_root_table_entry,1
  433. func_define mmu_get_ptr_table_entry,2
  434. func_define mmu_get_page_table_entry,2
  435. func_define mmu_print
  436. func_define get_new_page
  437. #if defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
  438. func_define set_leds
  439. #endif
  440. .macro mmu_map_eq arg1,arg2,arg3
  441. mmu_map \arg1,\arg1,\arg2,\arg3
  442. .endm
  443. .macro get_bi_record record
  444. pea \record
  445. func_call get_bi_record
  446. addql #4,%sp
  447. .endm
  448. func_define serial_putc,1
  449. func_define console_putc,1
  450. func_define console_init
  451. func_define console_put_stats
  452. func_define console_put_penguin
  453. func_define console_plot_pixel,3
  454. func_define console_scroll
  455. .macro putc ch
  456. #if defined(CONSOLE) || defined(SERIAL_DEBUG)
  457. pea \ch
  458. #endif
  459. #ifdef CONSOLE
  460. func_call console_putc
  461. #endif
  462. #ifdef SERIAL_DEBUG
  463. func_call serial_putc
  464. #endif
  465. #if defined(CONSOLE) || defined(SERIAL_DEBUG)
  466. addql #4,%sp
  467. #endif
  468. .endm
  469. .macro dputc ch
  470. #ifdef DEBUG
  471. putc \ch
  472. #endif
  473. .endm
  474. func_define putn,1
  475. .macro dputn nr
  476. #ifdef DEBUG
  477. putn \nr
  478. #endif
  479. .endm
  480. .macro puts string
  481. #if defined(CONSOLE) || defined(SERIAL_DEBUG)
  482. __INITDATA
  483. .Lstr\@:
  484. .string "\string"
  485. __FINIT
  486. pea %pc@(.Lstr\@)
  487. func_call puts
  488. addql #4,%sp
  489. #endif
  490. .endm
  491. .macro dputs string
  492. #ifdef DEBUG
  493. puts "\string"
  494. #endif
  495. .endm
  496. #define is_not_amiga(lab) cmpl &MACH_AMIGA,%pc@(m68k_machtype); jne lab
  497. #define is_not_atari(lab) cmpl &MACH_ATARI,%pc@(m68k_machtype); jne lab
  498. #define is_not_mac(lab) cmpl &MACH_MAC,%pc@(m68k_machtype); jne lab
  499. #define is_not_mvme147(lab) cmpl &MACH_MVME147,%pc@(m68k_machtype); jne lab
  500. #define is_not_mvme16x(lab) cmpl &MACH_MVME16x,%pc@(m68k_machtype); jne lab
  501. #define is_not_bvme6000(lab) cmpl &MACH_BVME6000,%pc@(m68k_machtype); jne lab
  502. #define is_mvme147(lab) cmpl &MACH_MVME147,%pc@(m68k_machtype); jeq lab
  503. #define is_mvme16x(lab) cmpl &MACH_MVME16x,%pc@(m68k_machtype); jeq lab
  504. #define is_bvme6000(lab) cmpl &MACH_BVME6000,%pc@(m68k_machtype); jeq lab
  505. #define is_not_hp300(lab) cmpl &MACH_HP300,%pc@(m68k_machtype); jne lab
  506. #define is_not_apollo(lab) cmpl &MACH_APOLLO,%pc@(m68k_machtype); jne lab
  507. #define is_not_q40(lab) cmpl &MACH_Q40,%pc@(m68k_machtype); jne lab
  508. #define is_not_sun3x(lab) cmpl &MACH_SUN3X,%pc@(m68k_machtype); jne lab
  509. #define hasnt_leds(lab) cmpl &MACH_HP300,%pc@(m68k_machtype); \
  510. jeq 42f; \
  511. cmpl &MACH_APOLLO,%pc@(m68k_machtype); \
  512. jne lab ;\
  513. 42:\
  514. #define is_040_or_060(lab) btst &CPUTYPE_0460,%pc@(L(cputype)+3); jne lab
  515. #define is_not_040_or_060(lab) btst &CPUTYPE_0460,%pc@(L(cputype)+3); jeq lab
  516. #define is_040(lab) btst &CPUTYPE_040,%pc@(L(cputype)+3); jne lab
  517. #define is_060(lab) btst &CPUTYPE_060,%pc@(L(cputype)+3); jne lab
  518. #define is_not_060(lab) btst &CPUTYPE_060,%pc@(L(cputype)+3); jeq lab
  519. #define is_020(lab) btst &CPUTYPE_020,%pc@(L(cputype)+3); jne lab
  520. #define is_not_020(lab) btst &CPUTYPE_020,%pc@(L(cputype)+3); jeq lab
  521. /* On the HP300 we use the on-board LEDs for debug output before
  522. the console is running. Writing a 1 bit turns the corresponding LED
  523. _off_ - on the 340 bit 7 is towards the back panel of the machine. */
  524. .macro leds mask
  525. #if defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
  526. hasnt_leds(.Lled\@)
  527. pea \mask
  528. func_call set_leds
  529. addql #4,%sp
  530. .Lled\@:
  531. #endif
  532. .endm
  533. __HEAD
  534. ENTRY(_stext)
  535. /*
  536. * Version numbers of the bootinfo interface
  537. * The area from _stext to _start will later be used as kernel pointer table
  538. */
  539. bras 1f /* Jump over bootinfo version numbers */
  540. .long BOOTINFOV_MAGIC
  541. .long MACH_AMIGA, AMIGA_BOOTI_VERSION
  542. .long MACH_ATARI, ATARI_BOOTI_VERSION
  543. .long MACH_MVME147, MVME147_BOOTI_VERSION
  544. .long MACH_MVME16x, MVME16x_BOOTI_VERSION
  545. .long MACH_BVME6000, BVME6000_BOOTI_VERSION
  546. .long MACH_MAC, MAC_BOOTI_VERSION
  547. .long MACH_Q40, Q40_BOOTI_VERSION
  548. .long MACH_HP300, HP300_BOOTI_VERSION
  549. .long 0
  550. 1: jra __start
  551. .equ kernel_pg_dir,_stext
  552. .equ .,_stext+PAGESIZE
  553. ENTRY(_start)
  554. jra __start
  555. __INIT
  556. ENTRY(__start)
  557. /*
  558. * Setup initial stack pointer
  559. */
  560. lea %pc@(_stext),%sp
  561. /*
  562. * Record the CPU and machine type.
  563. */
  564. get_bi_record BI_MACHTYPE
  565. lea %pc@(m68k_machtype),%a1
  566. movel %a0@,%a1@
  567. get_bi_record BI_FPUTYPE
  568. lea %pc@(m68k_fputype),%a1
  569. movel %a0@,%a1@
  570. get_bi_record BI_MMUTYPE
  571. lea %pc@(m68k_mmutype),%a1
  572. movel %a0@,%a1@
  573. get_bi_record BI_CPUTYPE
  574. lea %pc@(m68k_cputype),%a1
  575. movel %a0@,%a1@
  576. leds 0x1
  577. #ifdef CONFIG_MAC
  578. /*
  579. * For Macintosh, we need to determine the display parameters early (at least
  580. * while debugging it).
  581. */
  582. is_not_mac(L(test_notmac))
  583. get_bi_record BI_MAC_VADDR
  584. lea %pc@(L(mac_videobase)),%a1
  585. movel %a0@,%a1@
  586. get_bi_record BI_MAC_VDEPTH
  587. lea %pc@(L(mac_videodepth)),%a1
  588. movel %a0@,%a1@
  589. get_bi_record BI_MAC_VDIM
  590. lea %pc@(L(mac_dimensions)),%a1
  591. movel %a0@,%a1@
  592. get_bi_record BI_MAC_VROW
  593. lea %pc@(L(mac_rowbytes)),%a1
  594. movel %a0@,%a1@
  595. #ifdef SERIAL_DEBUG
  596. get_bi_record BI_MAC_SCCBASE
  597. lea %pc@(L(mac_sccbase)),%a1
  598. movel %a0@,%a1@
  599. #endif
  600. #if 0
  601. /*
  602. * Clear the screen
  603. */
  604. lea %pc@(L(mac_videobase)),%a0
  605. movel %a0@,%a1
  606. lea %pc@(L(mac_dimensions)),%a0
  607. movel %a0@,%d1
  608. swap %d1 /* #rows is high bytes */
  609. andl #0xFFFF,%d1 /* rows */
  610. subl #10,%d1
  611. lea %pc@(L(mac_rowbytes)),%a0
  612. loopy2:
  613. movel %a0@,%d0
  614. subql #1,%d0
  615. loopx2:
  616. moveb #0x55, %a1@+
  617. dbra %d0,loopx2
  618. dbra %d1,loopy2
  619. #endif
  620. L(test_notmac):
  621. #endif /* CONFIG_MAC */
  622. /*
  623. * There are ultimately two pieces of information we want for all kinds of
  624. * processors CpuType and CacheBits. The CPUTYPE was passed in from booter
  625. * and is converted here from a booter type definition to a separate bit
  626. * number which allows for the standard is_0x0 macro tests.
  627. */
  628. movel %pc@(m68k_cputype),%d0
  629. /*
  630. * Assume it's an 030
  631. */
  632. clrl %d1
  633. /*
  634. * Test the BootInfo cputype for 060
  635. */
  636. btst #CPUB_68060,%d0
  637. jeq 1f
  638. bset #CPUTYPE_060,%d1
  639. bset #CPUTYPE_0460,%d1
  640. jra 3f
  641. 1:
  642. /*
  643. * Test the BootInfo cputype for 040
  644. */
  645. btst #CPUB_68040,%d0
  646. jeq 2f
  647. bset #CPUTYPE_040,%d1
  648. bset #CPUTYPE_0460,%d1
  649. jra 3f
  650. 2:
  651. /*
  652. * Test the BootInfo cputype for 020
  653. */
  654. btst #CPUB_68020,%d0
  655. jeq 3f
  656. bset #CPUTYPE_020,%d1
  657. jra 3f
  658. 3:
  659. /*
  660. * Record the cpu type
  661. */
  662. lea %pc@(L(cputype)),%a0
  663. movel %d1,%a0@
  664. /*
  665. * NOTE:
  666. *
  667. * Now the macros are valid:
  668. * is_040_or_060
  669. * is_not_040_or_060
  670. * is_040
  671. * is_060
  672. * is_not_060
  673. */
  674. /*
  675. * Determine the cache mode for pages holding MMU tables
  676. * and for supervisor mode, unused for '020 and '030
  677. */
  678. clrl %d0
  679. clrl %d1
  680. is_not_040_or_060(L(save_cachetype))
  681. /*
  682. * '040 or '060
  683. * d1 := cacheable write-through
  684. * NOTE: The 68040 manual strongly recommends non-cached for MMU tables,
  685. * but we have been using write-through since at least 2.0.29 so I
  686. * guess it is OK.
  687. */
  688. #ifdef CONFIG_060_WRITETHROUGH
  689. /*
  690. * If this is a 68060 board using drivers with cache coherency
  691. * problems, then supervisor memory accesses need to be write-through
  692. * also; otherwise, we want copyback.
  693. */
  694. is_not_060(1f)
  695. movel #_PAGE_CACHE040W,%d0
  696. jra L(save_cachetype)
  697. #endif /* CONFIG_060_WRITETHROUGH */
  698. 1:
  699. movew #_PAGE_CACHE040,%d0
  700. movel #_PAGE_CACHE040W,%d1
  701. L(save_cachetype):
  702. /* Save cache mode for supervisor mode and page tables
  703. */
  704. lea %pc@(m68k_supervisor_cachemode),%a0
  705. movel %d0,%a0@
  706. lea %pc@(m68k_pgtable_cachemode),%a0
  707. movel %d1,%a0@
  708. /*
  709. * raise interrupt level
  710. */
  711. movew #0x2700,%sr
  712. /*
  713. If running on an Atari, determine the I/O base of the
  714. serial port and test if we are running on a Medusa or Hades.
  715. This test is necessary here, because on the Hades the serial
  716. port is only accessible in the high I/O memory area.
  717. The test whether it is a Medusa is done by writing to the byte at
  718. phys. 0x0. This should result in a bus error on all other machines.
  719. ...should, but doesn't. The Afterburner040 for the Falcon has the
  720. same behaviour (0x0..0x7 are no ROM shadow). So we have to do
  721. another test to distinguish Medusa and AB040. This is a
  722. read attempt for 0x00ff82fe phys. that should bus error on a Falcon
  723. (+AB040), but is in the range where the Medusa always asserts DTACK.
  724. The test for the Hades is done by reading address 0xb0000000. This
  725. should give a bus error on the Medusa.
  726. */
  727. #ifdef CONFIG_ATARI
  728. is_not_atari(L(notypetest))
  729. /* get special machine type (Medusa/Hades/AB40) */
  730. moveq #0,%d3 /* default if tag doesn't exist */
  731. get_bi_record BI_ATARI_MCH_TYPE
  732. tstl %d0
  733. jbmi 1f
  734. movel %a0@,%d3
  735. lea %pc@(atari_mch_type),%a0
  736. movel %d3,%a0@
  737. 1:
  738. /* On the Hades, the iobase must be set up before opening the
  739. * serial port. There are no I/O regs at 0x00ffxxxx at all. */
  740. moveq #0,%d0
  741. cmpl #ATARI_MACH_HADES,%d3
  742. jbne 1f
  743. movel #0xff000000,%d0 /* Hades I/O base addr: 0xff000000 */
  744. 1: lea %pc@(L(iobase)),%a0
  745. movel %d0,%a0@
  746. L(notypetest):
  747. #endif
  748. #ifdef CONFIG_VME
  749. is_mvme147(L(getvmetype))
  750. is_bvme6000(L(getvmetype))
  751. is_not_mvme16x(L(gvtdone))
  752. /* See if the loader has specified the BI_VME_TYPE tag. Recent
  753. * versions of VMELILO and TFTPLILO do this. We have to do this
  754. * early so we know how to handle console output. If the tag
  755. * doesn't exist then we use the Bug for output on MVME16x.
  756. */
  757. L(getvmetype):
  758. get_bi_record BI_VME_TYPE
  759. tstl %d0
  760. jbmi 1f
  761. movel %a0@,%d3
  762. lea %pc@(vme_brdtype),%a0
  763. movel %d3,%a0@
  764. 1:
  765. #ifdef CONFIG_MVME16x
  766. is_not_mvme16x(L(gvtdone))
  767. /* Need to get the BRD_ID info to differentiate between 162, 167,
  768. * etc. This is available as a BI_VME_BRDINFO tag with later
  769. * versions of VMELILO and TFTPLILO, otherwise we call the Bug.
  770. */
  771. get_bi_record BI_VME_BRDINFO
  772. tstl %d0
  773. jpl 1f
  774. /* Get pointer to board ID data from Bug */
  775. movel %d2,%sp@-
  776. trap #15
  777. .word 0x70 /* trap 0x70 - .BRD_ID */
  778. movel %sp@+,%a0
  779. 1:
  780. lea %pc@(mvme_bdid),%a1
  781. /* Structure is 32 bytes long */
  782. movel %a0@+,%a1@+
  783. movel %a0@+,%a1@+
  784. movel %a0@+,%a1@+
  785. movel %a0@+,%a1@+
  786. movel %a0@+,%a1@+
  787. movel %a0@+,%a1@+
  788. movel %a0@+,%a1@+
  789. movel %a0@+,%a1@+
  790. #endif
  791. L(gvtdone):
  792. #endif
  793. #ifdef CONFIG_HP300
  794. is_not_hp300(L(nothp))
  795. /* Get the address of the UART for serial debugging */
  796. get_bi_record BI_HP300_UART_ADDR
  797. tstl %d0
  798. jbmi 1f
  799. movel %a0@,%d3
  800. lea %pc@(L(uartbase)),%a0
  801. movel %d3,%a0@
  802. get_bi_record BI_HP300_UART_SCODE
  803. tstl %d0
  804. jbmi 1f
  805. movel %a0@,%d3
  806. lea %pc@(L(uart_scode)),%a0
  807. movel %d3,%a0@
  808. 1:
  809. L(nothp):
  810. #endif
  811. /*
  812. * Initialize serial port
  813. */
  814. jbsr L(serial_init)
  815. /*
  816. * Initialize console
  817. */
  818. #ifdef CONFIG_MAC
  819. is_not_mac(L(nocon))
  820. #ifdef CONSOLE
  821. console_init
  822. #ifdef CONSOLE_PENGUIN
  823. console_put_penguin
  824. #endif /* CONSOLE_PENGUIN */
  825. console_put_stats
  826. #endif /* CONSOLE */
  827. L(nocon):
  828. #endif /* CONFIG_MAC */
  829. putc '\n'
  830. putc 'A'
  831. leds 0x2
  832. dputn %pc@(L(cputype))
  833. dputn %pc@(m68k_supervisor_cachemode)
  834. dputn %pc@(m68k_pgtable_cachemode)
  835. dputc '\n'
  836. /*
  837. * Save physical start address of kernel
  838. */
  839. lea %pc@(L(phys_kernel_start)),%a0
  840. lea %pc@(_stext),%a1
  841. subl #_stext,%a1
  842. addl #PAGE_OFFSET,%a1
  843. movel %a1,%a0@
  844. putc 'B'
  845. leds 0x4
  846. /*
  847. * mmu_init
  848. *
  849. * This block of code does what's necessary to map in the various kinds
  850. * of machines for execution of Linux.
  851. * First map the first 4 MB of kernel code & data
  852. */
  853. mmu_map #PAGE_OFFSET,%pc@(L(phys_kernel_start)),#4*1024*1024,\
  854. %pc@(m68k_supervisor_cachemode)
  855. putc 'C'
  856. #ifdef CONFIG_AMIGA
  857. L(mmu_init_amiga):
  858. is_not_amiga(L(mmu_init_not_amiga))
  859. /*
  860. * mmu_init_amiga
  861. */
  862. putc 'D'
  863. is_not_040_or_060(1f)
  864. /*
  865. * 040: Map the 16Meg range physical 0x0 up to logical 0x8000.0000
  866. */
  867. mmu_map #0x80000000,#0,#0x01000000,#_PAGE_NOCACHE_S
  868. /*
  869. * Map the Zorro III I/O space with transparent translation
  870. * for frame buffer memory etc.
  871. */
  872. mmu_map_tt #1,#0x40000000,#0x20000000,#_PAGE_NOCACHE_S
  873. jbra L(mmu_init_done)
  874. 1:
  875. /*
  876. * 030: Map the 32Meg range physical 0x0 up to logical 0x8000.0000
  877. */
  878. mmu_map #0x80000000,#0,#0x02000000,#_PAGE_NOCACHE030
  879. mmu_map_tt #1,#0x40000000,#0x20000000,#_PAGE_NOCACHE030
  880. jbra L(mmu_init_done)
  881. L(mmu_init_not_amiga):
  882. #endif
  883. #ifdef CONFIG_ATARI
  884. L(mmu_init_atari):
  885. is_not_atari(L(mmu_init_not_atari))
  886. putc 'E'
  887. /* On the Atari, we map the I/O region (phys. 0x00ffxxxx) by mapping
  888. the last 16 MB of virtual address space to the first 16 MB (i.e.
  889. 0xffxxxxxx -> 0x00xxxxxx). For this, an additional pointer table is
  890. needed. I/O ranges are marked non-cachable.
  891. For the Medusa it is better to map the I/O region transparently
  892. (i.e. 0xffxxxxxx -> 0xffxxxxxx), because some I/O registers are
  893. accessible only in the high area.
  894. On the Hades all I/O registers are only accessible in the high
  895. area.
  896. */
  897. /* I/O base addr for non-Medusa, non-Hades: 0x00000000 */
  898. moveq #0,%d0
  899. movel %pc@(atari_mch_type),%d3
  900. cmpl #ATARI_MACH_MEDUSA,%d3
  901. jbeq 2f
  902. cmpl #ATARI_MACH_HADES,%d3
  903. jbne 1f
  904. 2: movel #0xff000000,%d0 /* Medusa/Hades base addr: 0xff000000 */
  905. 1: movel %d0,%d3
  906. is_040_or_060(L(spata68040))
  907. /* Map everything non-cacheable, though not all parts really
  908. * need to disable caches (crucial only for 0xff8000..0xffffff
  909. * (standard I/O) and 0xf00000..0xf3ffff (IDE)). The remainder
  910. * isn't really used, except for sometimes peeking into the
  911. * ROMs (mirror at phys. 0x0), so caching isn't necessary for
  912. * this. */
  913. mmu_map #0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE030
  914. jbra L(mmu_init_done)
  915. L(spata68040):
  916. mmu_map #0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE_S
  917. jbra L(mmu_init_done)
  918. L(mmu_init_not_atari):
  919. #endif
  920. #ifdef CONFIG_Q40
  921. is_not_q40(L(notq40))
  922. /*
  923. * add transparent mapping for 0xff00 0000 - 0xffff ffff
  924. * non-cached serialized etc..
  925. * this includes master chip, DAC, RTC and ISA ports
  926. * 0xfe000000-0xfeffffff is for screen and ROM
  927. */
  928. putc 'Q'
  929. mmu_map_tt #0,#0xfe000000,#0x01000000,#_PAGE_CACHE040W
  930. mmu_map_tt #1,#0xff000000,#0x01000000,#_PAGE_NOCACHE_S
  931. jbra L(mmu_init_done)
  932. L(notq40):
  933. #endif
  934. #ifdef CONFIG_HP300
  935. is_not_hp300(L(nothp300))
  936. /* On the HP300, we map the ROM, INTIO and DIO regions (phys. 0x00xxxxxx)
  937. * by mapping 32MB (on 020/030) or 16 MB (on 040) from 0xf0xxxxxx -> 0x00xxxxxx).
  938. * The ROM mapping is needed because the LEDs are mapped there too.
  939. */
  940. is_040(1f)
  941. /*
  942. * 030: Map the 32Meg range physical 0x0 up to logical 0xf000.0000
  943. */
  944. mmu_map #0xf0000000,#0,#0x02000000,#_PAGE_NOCACHE030
  945. jbra L(mmu_init_done)
  946. 1:
  947. /*
  948. * 040: Map the 16Meg range physical 0x0 up to logical 0xf000.0000
  949. */
  950. mmu_map #0xf0000000,#0,#0x01000000,#_PAGE_NOCACHE_S
  951. jbra L(mmu_init_done)
  952. L(nothp300):
  953. #endif /* CONFIG_HP300 */
  954. #ifdef CONFIG_MVME147
  955. is_not_mvme147(L(not147))
  956. /*
  957. * On MVME147 we have already created kernel page tables for
  958. * 4MB of RAM at address 0, so now need to do a transparent
  959. * mapping of the top of memory space. Make it 0.5GByte for now,
  960. * so we can access on-board i/o areas.
  961. */
  962. mmu_map_tt #1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE030
  963. jbra L(mmu_init_done)
  964. L(not147):
  965. #endif /* CONFIG_MVME147 */
  966. #ifdef CONFIG_MVME16x
  967. is_not_mvme16x(L(not16x))
  968. /*
  969. * On MVME16x we have already created kernel page tables for
  970. * 4MB of RAM at address 0, so now need to do a transparent
  971. * mapping of the top of memory space. Make it 0.5GByte for now.
  972. * Supervisor only access, so transparent mapping doesn't
  973. * clash with User code virtual address space.
  974. * this covers IO devices, PROM and SRAM. The PROM and SRAM
  975. * mapping is needed to allow 167Bug to run.
  976. * IO is in the range 0xfff00000 to 0xfffeffff.
  977. * PROM is 0xff800000->0xffbfffff and SRAM is
  978. * 0xffe00000->0xffe1ffff.
  979. */
  980. mmu_map_tt #1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
  981. jbra L(mmu_init_done)
  982. L(not16x):
  983. #endif /* CONFIG_MVME162 | CONFIG_MVME167 */
  984. #ifdef CONFIG_BVME6000
  985. is_not_bvme6000(L(not6000))
  986. /*
  987. * On BVME6000 we have already created kernel page tables for
  988. * 4MB of RAM at address 0, so now need to do a transparent
  989. * mapping of the top of memory space. Make it 0.5GByte for now,
  990. * so we can access on-board i/o areas.
  991. * Supervisor only access, so transparent mapping doesn't
  992. * clash with User code virtual address space.
  993. */
  994. mmu_map_tt #1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
  995. jbra L(mmu_init_done)
  996. L(not6000):
  997. #endif /* CONFIG_BVME6000 */
  998. /*
  999. * mmu_init_mac
  1000. *
  1001. * The Macintosh mappings are less clear.
  1002. *
  1003. * Even as of this writing, it is unclear how the
  1004. * Macintosh mappings will be done. However, as
  1005. * the first author of this code I'm proposing the
  1006. * following model:
  1007. *
  1008. * Map the kernel (that's already done),
  1009. * Map the I/O (on most machines that's the
  1010. * 0x5000.0000 ... 0x5300.0000 range,
  1011. * Map the video frame buffer using as few pages
  1012. * as absolutely (this requirement mostly stems from
  1013. * the fact that when the frame buffer is at
  1014. * 0x0000.0000 then we know there is valid RAM just
  1015. * above the screen that we don't want to waste!).
  1016. *
  1017. * By the way, if the frame buffer is at 0x0000.0000
  1018. * then the Macintosh is known as an RBV based Mac.
  1019. *
  1020. * By the way 2, the code currently maps in a bunch of
  1021. * regions. But I'd like to cut that out. (And move most
  1022. * of the mappings up into the kernel proper ... or only
  1023. * map what's necessary.)
  1024. */
  1025. #ifdef CONFIG_MAC
  1026. L(mmu_init_mac):
  1027. is_not_mac(L(mmu_init_not_mac))
  1028. putc 'F'
  1029. is_not_040_or_060(1f)
  1030. moveq #_PAGE_NOCACHE_S,%d3
  1031. jbra 2f
  1032. 1:
  1033. moveq #_PAGE_NOCACHE030,%d3
  1034. 2:
  1035. /*
  1036. * Mac Note: screen address of logical 0xF000.0000 -> <screen physical>
  1037. * we simply map the 4MB that contains the videomem
  1038. */
  1039. movel #VIDEOMEMMASK,%d0
  1040. andl %pc@(L(mac_videobase)),%d0
  1041. mmu_map #VIDEOMEMBASE,%d0,#VIDEOMEMSIZE,%d3
  1042. /* ROM from 4000 0000 to 4200 0000 (only for mac_reset()) */
  1043. mmu_map_eq #0x40000000,#0x02000000,%d3
  1044. /* IO devices (incl. serial port) from 5000 0000 to 5300 0000 */
  1045. mmu_map_eq #0x50000000,#0x03000000,%d3
  1046. /* Nubus slot space (video at 0xF0000000, rom at 0xF0F80000) */
  1047. mmu_map_tt #1,#0xf8000000,#0x08000000,%d3
  1048. jbra L(mmu_init_done)
  1049. L(mmu_init_not_mac):
  1050. #endif
  1051. #ifdef CONFIG_SUN3X
  1052. is_not_sun3x(L(notsun3x))
  1053. /* oh, the pain.. We're gonna want the prom code after
  1054. * starting the MMU, so we copy the mappings, translating
  1055. * from 8k -> 4k pages as we go.
  1056. */
  1057. /* copy maps from 0xfee00000 to 0xff000000 */
  1058. movel #0xfee00000, %d0
  1059. moveq #ROOT_INDEX_SHIFT, %d1
  1060. lsrl %d1,%d0
  1061. mmu_get_root_table_entry %d0
  1062. movel #0xfee00000, %d0
  1063. moveq #PTR_INDEX_SHIFT, %d1
  1064. lsrl %d1,%d0
  1065. andl #PTR_TABLE_SIZE-1, %d0
  1066. mmu_get_ptr_table_entry %a0,%d0
  1067. movel #0xfee00000, %d0
  1068. moveq #PAGE_INDEX_SHIFT, %d1
  1069. lsrl %d1,%d0
  1070. andl #PAGE_TABLE_SIZE-1, %d0
  1071. mmu_get_page_table_entry %a0,%d0
  1072. /* this is where the prom page table lives */
  1073. movel 0xfefe00d4, %a1
  1074. movel %a1@, %a1
  1075. movel #((0x200000 >> 13)-1), %d1
  1076. 1:
  1077. movel %a1@+, %d3
  1078. movel %d3,%a0@+
  1079. addl #0x1000,%d3
  1080. movel %d3,%a0@+
  1081. dbra %d1,1b
  1082. /* setup tt1 for I/O */
  1083. mmu_map_tt #1,#0x40000000,#0x40000000,#_PAGE_NOCACHE_S
  1084. jbra L(mmu_init_done)
  1085. L(notsun3x):
  1086. #endif
  1087. #ifdef CONFIG_APOLLO
  1088. is_not_apollo(L(notapollo))
  1089. putc 'P'
  1090. mmu_map #0x80000000,#0,#0x02000000,#_PAGE_NOCACHE030
  1091. L(notapollo):
  1092. jbra L(mmu_init_done)
  1093. #endif
  1094. L(mmu_init_done):
  1095. putc 'G'
  1096. leds 0x8
  1097. /*
  1098. * mmu_fixup
  1099. *
  1100. * On the 040 class machines, all pages that are used for the
  1101. * mmu have to be fixed up. According to Motorola, pages holding mmu
  1102. * tables should be non-cacheable on a '040 and write-through on a
  1103. * '060. But analysis of the reasons for this, and practical
  1104. * experience, showed that write-through also works on a '040.
  1105. *
  1106. * Allocated memory so far goes from kernel_end to memory_start that
  1107. * is used for all kind of tables, for that the cache attributes
  1108. * are now fixed.
  1109. */
  1110. L(mmu_fixup):
  1111. is_not_040_or_060(L(mmu_fixup_done))
  1112. #ifdef MMU_NOCACHE_KERNEL
  1113. jbra L(mmu_fixup_done)
  1114. #endif
  1115. /* first fix the page at the start of the kernel, that
  1116. * contains also kernel_pg_dir.
  1117. */
  1118. movel %pc@(L(phys_kernel_start)),%d0
  1119. subl #PAGE_OFFSET,%d0
  1120. lea %pc@(_stext),%a0
  1121. subl %d0,%a0
  1122. mmu_fixup_page_mmu_cache %a0
  1123. movel %pc@(L(kernel_end)),%a0
  1124. subl %d0,%a0
  1125. movel %pc@(L(memory_start)),%a1
  1126. subl %d0,%a1
  1127. bra 2f
  1128. 1:
  1129. mmu_fixup_page_mmu_cache %a0
  1130. addw #PAGESIZE,%a0
  1131. 2:
  1132. cmpl %a0,%a1
  1133. jgt 1b
  1134. L(mmu_fixup_done):
  1135. #ifdef MMU_PRINT
  1136. mmu_print
  1137. #endif
  1138. /*
  1139. * mmu_engage
  1140. *
  1141. * This chunk of code performs the gruesome task of engaging the MMU.
  1142. * The reason its gruesome is because when the MMU becomes engaged it
  1143. * maps logical addresses to physical addresses. The Program Counter
  1144. * register is then passed through the MMU before the next instruction
  1145. * is fetched (the instruction following the engage MMU instruction).
  1146. * This may mean one of two things:
  1147. * 1. The Program Counter falls within the logical address space of
  1148. * the kernel of which there are two sub-possibilities:
  1149. * A. The PC maps to the correct instruction (logical PC == physical
  1150. * code location), or
  1151. * B. The PC does not map through and the processor will read some
  1152. * data (or instruction) which is not the logically next instr.
  1153. * As you can imagine, A is good and B is bad.
  1154. * Alternatively,
  1155. * 2. The Program Counter does not map through the MMU. The processor
  1156. * will take a Bus Error.
  1157. * Clearly, 2 is bad.
  1158. * It doesn't take a wiz kid to figure you want 1.A.
  1159. * This code creates that possibility.
  1160. * There are two possible 1.A. states (we now ignore the other above states):
  1161. * A. The kernel is located at physical memory addressed the same as
  1162. * the logical memory for the kernel, i.e., 0x01000.
  1163. * B. The kernel is located some where else. e.g., 0x0400.0000
  1164. *
  1165. * Under some conditions the Macintosh can look like A or B.
  1166. * [A friend and I once noted that Apple hardware engineers should be
  1167. * wacked twice each day: once when they show up at work (as in, Whack!,
  1168. * "This is for the screwy hardware we know you're going to design today."),
  1169. * and also at the end of the day (as in, Whack! "I don't know what
  1170. * you designed today, but I'm sure it wasn't good."). -- rst]
  1171. *
  1172. * This code works on the following premise:
  1173. * If the kernel start (%d5) is within the first 16 Meg of RAM,
  1174. * then create a mapping for the kernel at logical 0x8000.0000 to
  1175. * the physical location of the pc. And, create a transparent
  1176. * translation register for the first 16 Meg. Then, after the MMU
  1177. * is engaged, the PC can be moved up into the 0x8000.0000 range
  1178. * and then the transparent translation can be turned off and then
  1179. * the PC can jump to the correct logical location and it will be
  1180. * home (finally). This is essentially the code that the Amiga used
  1181. * to use. Now, it's generalized for all processors. Which means
  1182. * that a fresh (but temporary) mapping has to be created. The mapping
  1183. * is made in page 0 (an as of yet unused location -- except for the
  1184. * stack!). This temporary mapping will only require 1 pointer table
  1185. * and a single page table (it can map 256K).
  1186. *
  1187. * OK, alternatively, imagine that the Program Counter is not within
  1188. * the first 16 Meg. Then, just use Transparent Translation registers
  1189. * to do the right thing.
  1190. *
  1191. * Last, if _start is already at 0x01000, then there's nothing special
  1192. * to do (in other words, in a degenerate case of the first case above,
  1193. * do nothing).
  1194. *
  1195. * Let's do it.
  1196. *
  1197. *
  1198. */
  1199. putc 'H'
  1200. mmu_engage
  1201. /*
  1202. * After this point no new memory is allocated and
  1203. * the start of available memory is stored in availmem.
  1204. * (The bootmem allocator requires now the physicall address.)
  1205. */
  1206. movel L(memory_start),availmem
  1207. #ifdef CONFIG_AMIGA
  1208. is_not_amiga(1f)
  1209. /* fixup the Amiga custom register location before printing */
  1210. clrl L(custom)
  1211. 1:
  1212. #endif
  1213. #ifdef CONFIG_ATARI
  1214. is_not_atari(1f)
  1215. /* fixup the Atari iobase register location before printing */
  1216. movel #0xff000000,L(iobase)
  1217. 1:
  1218. #endif
  1219. #ifdef CONFIG_MAC
  1220. is_not_mac(1f)
  1221. movel #~VIDEOMEMMASK,%d0
  1222. andl L(mac_videobase),%d0
  1223. addl #VIDEOMEMBASE,%d0
  1224. movel %d0,L(mac_videobase)
  1225. #if defined(CONSOLE)
  1226. movel %pc@(L(phys_kernel_start)),%d0
  1227. subl #PAGE_OFFSET,%d0
  1228. subl %d0,L(console_font)
  1229. subl %d0,L(console_font_data)
  1230. #endif
  1231. #ifdef SERIAL_DEBUG
  1232. orl #0x50000000,L(mac_sccbase)
  1233. #endif
  1234. 1:
  1235. #endif
  1236. #ifdef CONFIG_HP300
  1237. is_not_hp300(2f)
  1238. /*
  1239. * Fix up the iobase register to point to the new location of the LEDs.
  1240. */
  1241. movel #0xf0000000,L(iobase)
  1242. /*
  1243. * Energise the FPU and caches.
  1244. */
  1245. is_040(1f)
  1246. movel #0x60,0xf05f400c
  1247. jbra 2f
  1248. /*
  1249. * 040: slightly different, apparently.
  1250. */
  1251. 1: movew #0,0xf05f400e
  1252. movew #0x64,0xf05f400e
  1253. 2:
  1254. #endif
  1255. #ifdef CONFIG_SUN3X
  1256. is_not_sun3x(1f)
  1257. /* enable copro */
  1258. oriw #0x4000,0x61000000
  1259. 1:
  1260. #endif
  1261. #ifdef CONFIG_APOLLO
  1262. is_not_apollo(1f)
  1263. /*
  1264. * Fix up the iobase before printing
  1265. */
  1266. movel #0x80000000,L(iobase)
  1267. 1:
  1268. #endif
  1269. putc 'I'
  1270. leds 0x10
  1271. /*
  1272. * Enable caches
  1273. */
  1274. is_not_040_or_060(L(cache_not_680460))
  1275. L(cache680460):
  1276. .chip 68040
  1277. nop
  1278. cpusha %bc
  1279. nop
  1280. is_060(L(cache68060))
  1281. movel #CC6_ENABLE_D+CC6_ENABLE_I,%d0
  1282. /* MMU stuff works in copyback mode now, so enable the cache */
  1283. movec %d0,%cacr
  1284. jra L(cache_done)
  1285. L(cache68060):
  1286. movel #CC6_ENABLE_D+CC6_ENABLE_I+CC6_ENABLE_SB+CC6_PUSH_DPI+CC6_ENABLE_B+CC6_CLRA_B,%d0
  1287. /* MMU stuff works in copyback mode now, so enable the cache */
  1288. movec %d0,%cacr
  1289. /* enable superscalar dispatch in PCR */
  1290. moveq #1,%d0
  1291. .chip 68060
  1292. movec %d0,%pcr
  1293. jbra L(cache_done)
  1294. L(cache_not_680460):
  1295. L(cache68030):
  1296. .chip 68030
  1297. movel #CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
  1298. movec %d0,%cacr
  1299. jra L(cache_done)
  1300. .chip 68k
  1301. L(cache_done):
  1302. putc 'J'
  1303. /*
  1304. * Setup initial stack pointer
  1305. */
  1306. lea init_task,%curptr
  1307. lea init_thread_union+THREAD_SIZE,%sp
  1308. putc 'K'
  1309. subl %a6,%a6 /* clear a6 for gdb */
  1310. /*
  1311. * The new 64bit printf support requires an early exception initialization.
  1312. */
  1313. jbsr base_trap_init
  1314. /* jump to the kernel start */
  1315. putc '\n'
  1316. leds 0x55
  1317. jbsr start_kernel
  1318. /*
  1319. * Find a tag record in the bootinfo structure
  1320. * The bootinfo structure is located right after the kernel
  1321. * Returns: d0: size (-1 if not found)
  1322. * a0: data pointer (end-of-records if not found)
  1323. */
  1324. func_start get_bi_record,%d1
  1325. movel ARG1,%d0
  1326. lea %pc@(_end),%a0
  1327. 1: tstw %a0@(BIR_TAG)
  1328. jeq 3f
  1329. cmpw %a0@(BIR_TAG),%d0
  1330. jeq 2f
  1331. addw %a0@(BIR_SIZE),%a0
  1332. jra 1b
  1333. 2: moveq #0,%d0
  1334. movew %a0@(BIR_SIZE),%d0
  1335. lea %a0@(BIR_DATA),%a0
  1336. jra 4f
  1337. 3: moveq #-1,%d0
  1338. lea %a0@(BIR_SIZE),%a0
  1339. 4:
  1340. func_return get_bi_record
  1341. /*
  1342. * MMU Initialization Begins Here
  1343. *
  1344. * The structure of the MMU tables on the 68k machines
  1345. * is thus:
  1346. * Root Table
  1347. * Logical addresses are translated through
  1348. * a hierarchical translation mechanism where the high-order
  1349. * seven bits of the logical address (LA) are used as an
  1350. * index into the "root table." Each entry in the root
  1351. * table has a bit which specifies if it's a valid pointer to a
  1352. * pointer table. Each entry defines a 32KMeg range of memory.
  1353. * If an entry is invalid then that logical range of 32M is
  1354. * invalid and references to that range of memory (when the MMU
  1355. * is enabled) will fault. If the entry is valid, then it does
  1356. * one of two things. On 040/060 class machines, it points to
  1357. * a pointer table which then describes more finely the memory
  1358. * within that 32M range. On 020/030 class machines, a technique
  1359. * called "early terminating descriptors" are used. This technique
  1360. * allows an entire 32Meg to be described by a single entry in the
  1361. * root table. Thus, this entry in the root table, contains the
  1362. * physical address of the memory or I/O at the logical address
  1363. * which the entry represents and it also contains the necessary
  1364. * cache bits for this region.
  1365. *
  1366. * Pointer Tables
  1367. * Per the Root Table, there will be one or more
  1368. * pointer tables. Each pointer table defines a 32M range.
  1369. * Not all of the 32M range need be defined. Again, the next
  1370. * seven bits of the logical address are used an index into
  1371. * the pointer table to point to page tables (if the pointer
  1372. * is valid). There will undoubtedly be more than one
  1373. * pointer table for the kernel because each pointer table
  1374. * defines a range of only 32M. Valid pointer table entries
  1375. * point to page tables, or are early terminating entries
  1376. * themselves.
  1377. *
  1378. * Page Tables
  1379. * Per the Pointer Tables, each page table entry points
  1380. * to the physical page in memory that supports the logical
  1381. * address that translates to the particular index.
  1382. *
  1383. * In short, the Logical Address gets translated as follows:
  1384. * bits 31..26 - index into the Root Table
  1385. * bits 25..18 - index into the Pointer Table
  1386. * bits 17..12 - index into the Page Table
  1387. * bits 11..0 - offset into a particular 4K page
  1388. *
  1389. * The algorithms which follows do one thing: they abstract
  1390. * the MMU hardware. For example, there are three kinds of
  1391. * cache settings that are relevant. Either, memory is
  1392. * being mapped in which case it is either Kernel Code (or
  1393. * the RamDisk) or it is MMU data. On the 030, the MMU data
  1394. * option also describes the kernel. Or, I/O is being mapped
  1395. * in which case it has its own kind of cache bits. There
  1396. * are constants which abstract these notions from the code that
  1397. * actually makes the call to map some range of memory.
  1398. *
  1399. *
  1400. *
  1401. */
  1402. #ifdef MMU_PRINT
  1403. /*
  1404. * mmu_print
  1405. *
  1406. * This algorithm will print out the current MMU mappings.
  1407. *
  1408. * Input:
  1409. * %a5 points to the root table. Everything else is calculated
  1410. * from this.
  1411. */
  1412. #define mmu_next_valid 0
  1413. #define mmu_start_logical 4
  1414. #define mmu_next_logical 8
  1415. #define mmu_start_physical 12
  1416. #define mmu_next_physical 16
  1417. #define MMU_PRINT_INVALID -1
  1418. #define MMU_PRINT_VALID 1
  1419. #define MMU_PRINT_UNINITED 0
  1420. #define putZc(z,n) jbne 1f; putc z; jbra 2f; 1: putc n; 2:
  1421. func_start mmu_print,%a0-%a6/%d0-%d7
  1422. movel %pc@(L(kernel_pgdir_ptr)),%a5
  1423. lea %pc@(L(mmu_print_data)),%a0
  1424. movel #MMU_PRINT_UNINITED,%a0@(mmu_next_valid)
  1425. is_not_040_or_060(mmu_030_print)
  1426. mmu_040_print:
  1427. puts "\nMMU040\n"
  1428. puts "rp:"
  1429. putn %a5
  1430. putc '\n'
  1431. #if 0
  1432. /*
  1433. * The following #if/#endif block is a tight algorithm for dumping the 040
  1434. * MMU Map in gory detail. It really isn't that practical unless the
  1435. * MMU Map algorithm appears to go awry and you need to debug it at the
  1436. * entry per entry level.
  1437. */
  1438. movel #ROOT_TABLE_SIZE,%d5
  1439. #if 0
  1440. movel %a5@+,%d7 | Burn an entry to skip the kernel mappings,
  1441. subql #1,%d5 | they (might) work
  1442. #endif
  1443. 1: tstl %d5
  1444. jbeq mmu_print_done
  1445. subq #1,%d5
  1446. movel %a5@+,%d7
  1447. btst #1,%d7
  1448. jbeq 1b
  1449. 2: putn %d7
  1450. andil #0xFFFFFE00,%d7
  1451. movel %d7,%a4
  1452. movel #PTR_TABLE_SIZE,%d4
  1453. putc ' '
  1454. 3: tstl %d4
  1455. jbeq 11f
  1456. subq #1,%d4
  1457. movel %a4@+,%d7
  1458. btst #1,%d7
  1459. jbeq 3b
  1460. 4: putn %d7
  1461. andil #0xFFFFFF00,%d7
  1462. movel %d7,%a3
  1463. movel #PAGE_TABLE_SIZE,%d3
  1464. 5: movel #8,%d2
  1465. 6: tstl %d3
  1466. jbeq 31f
  1467. subq #1,%d3
  1468. movel %a3@+,%d6
  1469. btst #0,%d6
  1470. jbeq 6b
  1471. 7: tstl %d2
  1472. jbeq 8f
  1473. subq #1,%d2
  1474. putc ' '
  1475. jbra 91f
  1476. 8: putc '\n'
  1477. movel #8+1+8+1+1,%d2
  1478. 9: putc ' '
  1479. dbra %d2,9b
  1480. movel #7,%d2
  1481. 91: putn %d6
  1482. jbra 6b
  1483. 31: putc '\n'
  1484. movel #8+1,%d2
  1485. 32: putc ' '
  1486. dbra %d2,32b
  1487. jbra 3b
  1488. 11: putc '\n'
  1489. jbra 1b
  1490. #endif /* MMU 040 Dumping code that's gory and detailed */
  1491. lea %pc@(kernel_pg_dir),%a5
  1492. movel %a5,%a0 /* a0 has the address of the root table ptr */
  1493. movel #0x00000000,%a4 /* logical address */
  1494. moveql #0,%d0
  1495. 40:
  1496. /* Increment the logical address and preserve in d5 */
  1497. movel %a4,%d5
  1498. addil #PAGESIZE<<13,%d5
  1499. movel %a0@+,%d6
  1500. btst #1,%d6
  1501. jbne 41f
  1502. jbsr mmu_print_tuple_invalidate
  1503. jbra 48f
  1504. 41:
  1505. movel #0,%d1
  1506. andil #0xfffffe00,%d6
  1507. movel %d6,%a1
  1508. 42:
  1509. movel %a4,%d5
  1510. addil #PAGESIZE<<6,%d5
  1511. movel %a1@+,%d6
  1512. btst #1,%d6
  1513. jbne 43f
  1514. jbsr mmu_print_tuple_invalidate
  1515. jbra 47f
  1516. 43:
  1517. movel #0,%d2
  1518. andil #0xffffff00,%d6
  1519. movel %d6,%a2
  1520. 44:
  1521. movel %a4,%d5
  1522. addil #PAGESIZE,%d5
  1523. movel %a2@+,%d6
  1524. btst #0,%d6
  1525. jbne 45f
  1526. jbsr mmu_print_tuple_invalidate
  1527. jbra 46f
  1528. 45:
  1529. moveml %d0-%d1,%sp@-
  1530. movel %a4,%d0
  1531. movel %d6,%d1
  1532. andil #0xfffff4e0,%d1
  1533. lea %pc@(mmu_040_print_flags),%a6
  1534. jbsr mmu_print_tuple
  1535. moveml %sp@+,%d0-%d1
  1536. 46:
  1537. movel %d5,%a4
  1538. addq #1,%d2
  1539. cmpib #64,%d2
  1540. jbne 44b
  1541. 47:
  1542. movel %d5,%a4
  1543. addq #1,%d1
  1544. cmpib #128,%d1
  1545. jbne 42b
  1546. 48:
  1547. movel %d5,%a4 /* move to the next logical address */
  1548. addq #1,%d0
  1549. cmpib #128,%d0
  1550. jbne 40b
  1551. .chip 68040
  1552. movec %dtt1,%d0
  1553. movel %d0,%d1
  1554. andiw #0x8000,%d1 /* is it valid ? */
  1555. jbeq 1f /* No, bail out */
  1556. movel %d0,%d1
  1557. andil #0xff000000,%d1 /* Get the address */
  1558. putn %d1
  1559. puts "=="
  1560. putn %d1
  1561. movel %d0,%d6
  1562. jbsr mmu_040_print_flags_tt
  1563. 1:
  1564. movec %dtt0,%d0
  1565. movel %d0,%d1
  1566. andiw #0x8000,%d1 /* is it valid ? */
  1567. jbeq 1f /* No, bail out */
  1568. movel %d0,%d1
  1569. andil #0xff000000,%d1 /* Get the address */
  1570. putn %d1
  1571. puts "=="
  1572. putn %d1
  1573. movel %d0,%d6
  1574. jbsr mmu_040_print_flags_tt
  1575. 1:
  1576. .chip 68k
  1577. jbra mmu_print_done
  1578. mmu_040_print_flags:
  1579. btstl #10,%d6
  1580. putZc(' ','G') /* global bit */
  1581. btstl #7,%d6
  1582. putZc(' ','S') /* supervisor bit */
  1583. mmu_040_print_flags_tt:
  1584. btstl #6,%d6
  1585. jbne 3f
  1586. putc 'C'
  1587. btstl #5,%d6
  1588. putZc('w','c') /* write through or copy-back */
  1589. jbra 4f
  1590. 3:
  1591. putc 'N'
  1592. btstl #5,%d6
  1593. putZc('s',' ') /* serialized non-cacheable, or non-cacheable */
  1594. 4:
  1595. rts
  1596. mmu_030_print_flags:
  1597. btstl #6,%d6
  1598. putZc('C','I') /* write through or copy-back */
  1599. rts
  1600. mmu_030_print:
  1601. puts "\nMMU030\n"
  1602. puts "\nrp:"
  1603. putn %a5
  1604. putc '\n'
  1605. movel %a5,%d0
  1606. andil #0xfffffff0,%d0
  1607. movel %d0,%a0
  1608. movel #0x00000000,%a4 /* logical address */
  1609. movel #0,%d0
  1610. 30:
  1611. movel %a4,%d5
  1612. addil #PAGESIZE<<13,%d5
  1613. movel %a0@+,%d6
  1614. btst #1,%d6 /* is it a table ptr? */
  1615. jbne 31f /* yes */
  1616. btst #0,%d6 /* is it early terminating? */
  1617. jbeq 1f /* no */
  1618. jbsr mmu_030_print_helper
  1619. jbra 38f
  1620. 1:
  1621. jbsr mmu_print_tuple_invalidate
  1622. jbra 38f
  1623. 31:
  1624. movel #0,%d1
  1625. andil #0xfffffff0,%d6
  1626. movel %d6,%a1
  1627. 32:
  1628. movel %a4,%d5
  1629. addil #PAGESIZE<<6,%d5
  1630. movel %a1@+,%d6
  1631. btst #1,%d6 /* is it a table ptr? */
  1632. jbne 33f /* yes */
  1633. btst #0,%d6 /* is it a page descriptor? */
  1634. jbeq 1f /* no */
  1635. jbsr mmu_030_print_helper
  1636. jbra 37f
  1637. 1:
  1638. jbsr mmu_print_tuple_invalidate
  1639. jbra 37f
  1640. 33:
  1641. movel #0,%d2
  1642. andil #0xfffffff0,%d6
  1643. movel %d6,%a2
  1644. 34:
  1645. movel %a4,%d5
  1646. addil #PAGESIZE,%d5
  1647. movel %a2@+,%d6
  1648. btst #0,%d6
  1649. jbne 35f
  1650. jbsr mmu_print_tuple_invalidate
  1651. jbra 36f
  1652. 35:
  1653. jbsr mmu_030_print_helper
  1654. 36:
  1655. movel %d5,%a4
  1656. addq #1,%d2
  1657. cmpib #64,%d2
  1658. jbne 34b
  1659. 37:
  1660. movel %d5,%a4
  1661. addq #1,%d1
  1662. cmpib #128,%d1
  1663. jbne 32b
  1664. 38:
  1665. movel %d5,%a4 /* move to the next logical address */
  1666. addq #1,%d0
  1667. cmpib #128,%d0
  1668. jbne 30b
  1669. mmu_print_done:
  1670. puts "\n"
  1671. func_return mmu_print
  1672. mmu_030_print_helper:
  1673. moveml %d0-%d1,%sp@-
  1674. movel %a4,%d0
  1675. movel %d6,%d1
  1676. lea %pc@(mmu_030_print_flags),%a6
  1677. jbsr mmu_print_tuple
  1678. moveml %sp@+,%d0-%d1
  1679. rts
  1680. mmu_print_tuple_invalidate:
  1681. moveml %a0/%d7,%sp@-
  1682. lea %pc@(L(mmu_print_data)),%a0
  1683. tstl %a0@(mmu_next_valid)
  1684. jbmi mmu_print_tuple_invalidate_exit
  1685. movel #MMU_PRINT_INVALID,%a0@(mmu_next_valid)
  1686. putn %a4
  1687. puts "##\n"
  1688. mmu_print_tuple_invalidate_exit:
  1689. moveml %sp@+,%a0/%d7
  1690. rts
  1691. mmu_print_tuple:
  1692. moveml %d0-%d7/%a0,%sp@-
  1693. lea %pc@(L(mmu_print_data)),%a0
  1694. tstl %a0@(mmu_next_valid)
  1695. jble mmu_print_tuple_print
  1696. cmpl %a0@(mmu_next_physical),%d1
  1697. jbeq mmu_print_tuple_increment
  1698. mmu_print_tuple_print:
  1699. putn %d0
  1700. puts "->"
  1701. putn %d1
  1702. movel %d1,%d6
  1703. jbsr %a6@
  1704. mmu_print_tuple_record:
  1705. movel #MMU_PRINT_VALID,%a0@(mmu_next_valid)
  1706. movel %d1,%a0@(mmu_next_physical)
  1707. mmu_print_tuple_increment:
  1708. movel %d5,%d7
  1709. subl %a4,%d7
  1710. addl %d7,%a0@(mmu_next_physical)
  1711. mmu_print_tuple_exit:
  1712. moveml %sp@+,%d0-%d7/%a0
  1713. rts
  1714. mmu_print_machine_cpu_types:
  1715. puts "machine: "
  1716. is_not_amiga(1f)
  1717. puts "amiga"
  1718. jbra 9f
  1719. 1:
  1720. is_not_atari(2f)
  1721. puts "atari"
  1722. jbra 9f
  1723. 2:
  1724. is_not_mac(3f)
  1725. puts "macintosh"
  1726. jbra 9f
  1727. 3: puts "unknown"
  1728. 9: putc '\n'
  1729. puts "cputype: 0"
  1730. is_not_060(1f)
  1731. putc '6'
  1732. jbra 9f
  1733. 1:
  1734. is_not_040_or_060(2f)
  1735. putc '4'
  1736. jbra 9f
  1737. 2: putc '3'
  1738. 9: putc '0'
  1739. putc '\n'
  1740. rts
  1741. #endif /* MMU_PRINT */
  1742. /*
  1743. * mmu_map_tt
  1744. *
  1745. * This is a specific function which works on all 680x0 machines.
  1746. * On 030, 040 & 060 it will attempt to use Transparent Translation
  1747. * registers (tt1).
  1748. * On 020 it will call the standard mmu_map which will use early
  1749. * terminating descriptors.
  1750. */
  1751. func_start mmu_map_tt,%d0/%d1/%a0,4
  1752. dputs "mmu_map_tt:"
  1753. dputn ARG1
  1754. dputn ARG2
  1755. dputn ARG3
  1756. dputn ARG4
  1757. dputc '\n'
  1758. is_020(L(do_map))
  1759. /* Extract the highest bit set
  1760. */
  1761. bfffo ARG3{#0,#32},%d1
  1762. cmpw #8,%d1
  1763. jcc L(do_map)
  1764. /* And get the mask
  1765. */
  1766. moveq #-1,%d0
  1767. lsrl %d1,%d0
  1768. lsrl #1,%d0
  1769. /* Mask the address
  1770. */
  1771. movel %d0,%d1
  1772. notl %d1
  1773. andl ARG2,%d1
  1774. /* Generate the upper 16bit of the tt register
  1775. */
  1776. lsrl #8,%d0
  1777. orl %d0,%d1
  1778. clrw %d1
  1779. is_040_or_060(L(mmu_map_tt_040))
  1780. /* set 030 specific bits (read/write access for supervisor mode
  1781. * (highest function code set, lower two bits masked))
  1782. */
  1783. orw #TTR_ENABLE+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d1
  1784. movel ARG4,%d0
  1785. btst #6,%d0
  1786. jeq 1f
  1787. orw #TTR_CI,%d1
  1788. 1: lea STACK,%a0
  1789. dputn %d1
  1790. movel %d1,%a0@
  1791. .chip 68030
  1792. tstl ARG1
  1793. jne 1f
  1794. pmove %a0@,%tt0
  1795. jra 2f
  1796. 1: pmove %a0@,%tt1
  1797. 2: .chip 68k
  1798. jra L(mmu_map_tt_done)
  1799. /* set 040 specific bits
  1800. */
  1801. L(mmu_map_tt_040):
  1802. orw #TTR_ENABLE+TTR_KERNELMODE,%d1
  1803. orl ARG4,%d1
  1804. dputn %d1
  1805. .chip 68040
  1806. tstl ARG1
  1807. jne 1f
  1808. movec %d1,%itt0
  1809. movec %d1,%dtt0
  1810. jra 2f
  1811. 1: movec %d1,%itt1
  1812. movec %d1,%dtt1
  1813. 2: .chip 68k
  1814. jra L(mmu_map_tt_done)
  1815. L(do_map):
  1816. mmu_map_eq ARG2,ARG3,ARG4
  1817. L(mmu_map_tt_done):
  1818. func_return mmu_map_tt
  1819. /*
  1820. * mmu_map
  1821. *
  1822. * This routine will map a range of memory using a pointer
  1823. * table and allocating the pages on the fly from the kernel.
  1824. * The pointer table does not have to be already linked into
  1825. * the root table, this routine will do that if necessary.
  1826. *
  1827. * NOTE
  1828. * This routine will assert failure and use the serial_putc
  1829. * routines in the case of a run-time error. For example,
  1830. * if the address is already mapped.
  1831. *
  1832. * NOTE-2
  1833. * This routine will use early terminating descriptors
  1834. * where possible for the 68020+68851 and 68030 type
  1835. * processors.
  1836. */
  1837. func_start mmu_map,%d0-%d4/%a0-%a4
  1838. dputs "\nmmu_map:"
  1839. dputn ARG1
  1840. dputn ARG2
  1841. dputn ARG3
  1842. dputn ARG4
  1843. dputc '\n'
  1844. /* Get logical address and round it down to 256KB
  1845. */
  1846. movel ARG1,%d0
  1847. andl #-(PAGESIZE*PAGE_TABLE_SIZE),%d0
  1848. movel %d0,%a3
  1849. /* Get the end address
  1850. */
  1851. movel ARG1,%a4
  1852. addl ARG3,%a4
  1853. subql #1,%a4
  1854. /* Get physical address and round it down to 256KB
  1855. */
  1856. movel ARG2,%d0
  1857. andl #-(PAGESIZE*PAGE_TABLE_SIZE),%d0
  1858. movel %d0,%a2
  1859. /* Add page attributes to the physical address
  1860. */
  1861. movel ARG4,%d0
  1862. orw #_PAGE_PRESENT+_PAGE_ACCESSED+_PAGE_DIRTY,%d0
  1863. addw %d0,%a2
  1864. dputn %a2
  1865. dputn %a3
  1866. dputn %a4
  1867. is_not_040_or_060(L(mmu_map_030))
  1868. addw #_PAGE_GLOBAL040,%a2
  1869. /*
  1870. * MMU 040 & 060 Support
  1871. *
  1872. * The MMU usage for the 040 and 060 is different enough from
  1873. * the 030 and 68851 that there is separate code. This comment
  1874. * block describes the data structures and algorithms built by
  1875. * this code.
  1876. *
  1877. * The 040 does not support early terminating descriptors, as
  1878. * the 030 does. Therefore, a third level of table is needed
  1879. * for the 040, and that would be the page table. In Linux,
  1880. * page tables are allocated directly from the memory above the
  1881. * kernel.
  1882. *
  1883. */
  1884. L(mmu_map_040):
  1885. /* Calculate the offset into the root table
  1886. */
  1887. movel %a3,%d0
  1888. moveq #ROOT_INDEX_SHIFT,%d1
  1889. lsrl %d1,%d0
  1890. mmu_get_root_table_entry %d0
  1891. /* Calculate the offset into the pointer table
  1892. */
  1893. movel %a3,%d0
  1894. moveq #PTR_INDEX_SHIFT,%d1
  1895. lsrl %d1,%d0
  1896. andl #PTR_TABLE_SIZE-1,%d0
  1897. mmu_get_ptr_table_entry %a0,%d0
  1898. /* Calculate the offset into the page table
  1899. */
  1900. movel %a3,%d0
  1901. moveq #PAGE_INDEX_SHIFT,%d1
  1902. lsrl %d1,%d0
  1903. andl #PAGE_TABLE_SIZE-1,%d0
  1904. mmu_get_page_table_entry %a0,%d0
  1905. /* The page table entry must not no be busy
  1906. */
  1907. tstl %a0@
  1908. jne L(mmu_map_error)
  1909. /* Do the mapping and advance the pointers
  1910. */
  1911. movel %a2,%a0@
  1912. 2:
  1913. addw #PAGESIZE,%a2
  1914. addw #PAGESIZE,%a3
  1915. /* Ready with mapping?
  1916. */
  1917. lea %a3@(-1),%a0
  1918. cmpl %a0,%a4
  1919. jhi L(mmu_map_040)
  1920. jra L(mmu_map_done)
  1921. L(mmu_map_030):
  1922. /* Calculate the offset into the root table
  1923. */
  1924. movel %a3,%d0
  1925. moveq #ROOT_INDEX_SHIFT,%d1
  1926. lsrl %d1,%d0
  1927. mmu_get_root_table_entry %d0
  1928. /* Check if logical address 32MB aligned,
  1929. * so we can try to map it once
  1930. */
  1931. movel %a3,%d0
  1932. andl #(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE-1)&(-ROOT_TABLE_SIZE),%d0
  1933. jne 1f
  1934. /* Is there enough to map for 32MB at once
  1935. */
  1936. lea %a3@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE-1),%a1
  1937. cmpl %a1,%a4
  1938. jcs 1f
  1939. addql #1,%a1
  1940. /* The root table entry must not no be busy
  1941. */
  1942. tstl %a0@
  1943. jne L(mmu_map_error)
  1944. /* Do the mapping and advance the pointers
  1945. */
  1946. dputs "early term1"
  1947. dputn %a2
  1948. dputn %a3
  1949. dputn %a1
  1950. dputc '\n'
  1951. movel %a2,%a0@
  1952. movel %a1,%a3
  1953. lea %a2@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE),%a2
  1954. jra L(mmu_mapnext_030)
  1955. 1:
  1956. /* Calculate the offset into the pointer table
  1957. */
  1958. movel %a3,%d0
  1959. moveq #PTR_INDEX_SHIFT,%d1
  1960. lsrl %d1,%d0
  1961. andl #PTR_TABLE_SIZE-1,%d0
  1962. mmu_get_ptr_table_entry %a0,%d0
  1963. /* The pointer table entry must not no be busy
  1964. */
  1965. tstl %a0@
  1966. jne L(mmu_map_error)
  1967. /* Do the mapping and advance the pointers
  1968. */
  1969. dputs "early term2"
  1970. dputn %a2
  1971. dputn %a3
  1972. dputc '\n'
  1973. movel %a2,%a0@
  1974. addl #PAGE_TABLE_SIZE*PAGESIZE,%a2
  1975. addl #PAGE_TABLE_SIZE*PAGESIZE,%a3
  1976. L(mmu_mapnext_030):
  1977. /* Ready with mapping?
  1978. */
  1979. lea %a3@(-1),%a0
  1980. cmpl %a0,%a4
  1981. jhi L(mmu_map_030)
  1982. jra L(mmu_map_done)
  1983. L(mmu_map_error):
  1984. dputs "mmu_map error:"
  1985. dputn %a2
  1986. dputn %a3
  1987. dputc '\n'
  1988. L(mmu_map_done):
  1989. func_return mmu_map
  1990. /*
  1991. * mmu_fixup
  1992. *
  1993. * On the 040 class machines, all pages that are used for the
  1994. * mmu have to be fixed up.
  1995. */
  1996. func_start mmu_fixup_page_mmu_cache,%d0/%a0
  1997. dputs "mmu_fixup_page_mmu_cache"
  1998. dputn ARG1
  1999. /* Calculate the offset into the root table
  2000. */
  2001. movel ARG1,%d0
  2002. moveq #ROOT_INDEX_SHIFT,%d1
  2003. lsrl %d1,%d0
  2004. mmu_get_root_table_entry %d0
  2005. /* Calculate the offset into the pointer table
  2006. */
  2007. movel ARG1,%d0
  2008. moveq #PTR_INDEX_SHIFT,%d1
  2009. lsrl %d1,%d0
  2010. andl #PTR_TABLE_SIZE-1,%d0
  2011. mmu_get_ptr_table_entry %a0,%d0
  2012. /* Calculate the offset into the page table
  2013. */
  2014. movel ARG1,%d0
  2015. moveq #PAGE_INDEX_SHIFT,%d1
  2016. lsrl %d1,%d0
  2017. andl #PAGE_TABLE_SIZE-1,%d0
  2018. mmu_get_page_table_entry %a0,%d0
  2019. movel %a0@,%d0
  2020. andil #_CACHEMASK040,%d0
  2021. orl %pc@(m68k_pgtable_cachemode),%d0
  2022. movel %d0,%a0@
  2023. dputc '\n'
  2024. func_return mmu_fixup_page_mmu_cache
  2025. /*
  2026. * mmu_temp_map
  2027. *
  2028. * create a temporary mapping to enable the mmu,
  2029. * this we don't need any transparation translation tricks.
  2030. */
  2031. func_start mmu_temp_map,%d0/%d1/%a0/%a1
  2032. dputs "mmu_temp_map"
  2033. dputn ARG1
  2034. dputn ARG2
  2035. dputc '\n'
  2036. lea %pc@(L(temp_mmap_mem)),%a1
  2037. /* Calculate the offset in the root table
  2038. */
  2039. movel ARG2,%d0
  2040. moveq #ROOT_INDEX_SHIFT,%d1
  2041. lsrl %d1,%d0
  2042. mmu_get_root_table_entry %d0
  2043. /* Check if the table is temporary allocated, so we have to reuse it
  2044. */
  2045. movel %a0@,%d0
  2046. cmpl %pc@(L(memory_start)),%d0
  2047. jcc 1f
  2048. /* Temporary allocate a ptr table and insert it into the root table
  2049. */
  2050. movel %a1@,%d0
  2051. addl #PTR_TABLE_SIZE*4,%a1@
  2052. orw #_PAGE_TABLE+_PAGE_ACCESSED,%d0
  2053. movel %d0,%a0@
  2054. dputs " (new)"
  2055. 1:
  2056. dputn %d0
  2057. /* Mask the root table entry for the ptr table
  2058. */
  2059. andw #-ROOT_TABLE_SIZE,%d0
  2060. movel %d0,%a0
  2061. /* Calculate the offset into the pointer table
  2062. */
  2063. movel ARG2,%d0
  2064. moveq #PTR_INDEX_SHIFT,%d1
  2065. lsrl %d1,%d0
  2066. andl #PTR_TABLE_SIZE-1,%d0
  2067. lea %a0@(%d0*4),%a0
  2068. dputn %a0
  2069. /* Check if a temporary page table is already allocated
  2070. */
  2071. movel %a0@,%d0
  2072. jne 1f
  2073. /* Temporary allocate a page table and insert it into the ptr table
  2074. */
  2075. movel %a1@,%d0
  2076. /* The 512 should be PAGE_TABLE_SIZE*4, but that violates the
  2077. alignment restriction for pointer tables on the '0[46]0. */
  2078. addl #512,%a1@
  2079. orw #_PAGE_TABLE+_PAGE_ACCESSED,%d0
  2080. movel %d0,%a0@
  2081. dputs " (new)"
  2082. 1:
  2083. dputn %d0
  2084. /* Mask the ptr table entry for the page table
  2085. */
  2086. andw #-PTR_TABLE_SIZE,%d0
  2087. movel %d0,%a0
  2088. /* Calculate the offset into the page table
  2089. */
  2090. movel ARG2,%d0
  2091. moveq #PAGE_INDEX_SHIFT,%d1
  2092. lsrl %d1,%d0
  2093. andl #PAGE_TABLE_SIZE-1,%d0
  2094. lea %a0@(%d0*4),%a0
  2095. dputn %a0
  2096. /* Insert the address into the page table
  2097. */
  2098. movel ARG1,%d0
  2099. andw #-PAGESIZE,%d0
  2100. orw #_PAGE_PRESENT+_PAGE_ACCESSED+_PAGE_DIRTY,%d0
  2101. movel %d0,%a0@
  2102. dputn %d0
  2103. dputc '\n'
  2104. func_return mmu_temp_map
  2105. func_start mmu_engage,%d0-%d2/%a0-%a3
  2106. moveq #ROOT_TABLE_SIZE-1,%d0
  2107. /* Temporarily use a different root table. */
  2108. lea %pc@(L(kernel_pgdir_ptr)),%a0
  2109. movel %a0@,%a2
  2110. movel %pc@(L(memory_start)),%a1
  2111. movel %a1,%a0@
  2112. movel %a2,%a0
  2113. 1:
  2114. movel %a0@+,%a1@+
  2115. dbra %d0,1b
  2116. lea %pc@(L(temp_mmap_mem)),%a0
  2117. movel %a1,%a0@
  2118. movew #PAGESIZE-1,%d0
  2119. 1:
  2120. clrl %a1@+
  2121. dbra %d0,1b
  2122. lea %pc@(1b),%a0
  2123. movel #1b,%a1
  2124. /* Skip temp mappings if phys == virt */
  2125. cmpl %a0,%a1
  2126. jeq 1f
  2127. mmu_temp_map %a0,%a0
  2128. mmu_temp_map %a0,%a1
  2129. addw #PAGESIZE,%a0
  2130. addw #PAGESIZE,%a1
  2131. mmu_temp_map %a0,%a0
  2132. mmu_temp_map %a0,%a1
  2133. 1:
  2134. movel %pc@(L(memory_start)),%a3
  2135. movel %pc@(L(phys_kernel_start)),%d2
  2136. is_not_040_or_060(L(mmu_engage_030))
  2137. L(mmu_engage_040):
  2138. .chip 68040
  2139. nop
  2140. cinva %bc
  2141. nop
  2142. pflusha
  2143. nop
  2144. movec %a3,%srp
  2145. movel #TC_ENABLE+TC_PAGE4K,%d0
  2146. movec %d0,%tc /* enable the MMU */
  2147. jmp 1f:l
  2148. 1: nop
  2149. movec %a2,%srp
  2150. nop
  2151. cinva %bc
  2152. nop
  2153. pflusha
  2154. .chip 68k
  2155. jra L(mmu_engage_cleanup)
  2156. L(mmu_engage_030_temp):
  2157. .space 12
  2158. L(mmu_engage_030):
  2159. .chip 68030
  2160. lea %pc@(L(mmu_engage_030_temp)),%a0
  2161. movel #0x80000002,%a0@
  2162. movel %a3,%a0@(4)
  2163. movel #0x0808,%d0
  2164. movec %d0,%cacr
  2165. pmove %a0@,%srp
  2166. pflusha
  2167. /*
  2168. * enable,super root enable,4096 byte pages,7 bit root index,
  2169. * 7 bit pointer index, 6 bit page table index.
  2170. */
  2171. movel #0x82c07760,%a0@(8)
  2172. pmove %a0@(8),%tc /* enable the MMU */
  2173. jmp 1f:l
  2174. 1: movel %a2,%a0@(4)
  2175. movel #0x0808,%d0
  2176. movec %d0,%cacr
  2177. pmove %a0@,%srp
  2178. pflusha
  2179. .chip 68k
  2180. L(mmu_engage_cleanup):
  2181. subl #PAGE_OFFSET,%d2
  2182. subl %d2,%a2
  2183. movel %a2,L(kernel_pgdir_ptr)
  2184. subl %d2,%fp
  2185. subl %d2,%sp
  2186. subl %d2,ARG0
  2187. func_return mmu_engage
  2188. func_start mmu_get_root_table_entry,%d0/%a1
  2189. #if 0
  2190. dputs "mmu_get_root_table_entry:"
  2191. dputn ARG1
  2192. dputs " ="
  2193. #endif
  2194. movel %pc@(L(kernel_pgdir_ptr)),%a0
  2195. tstl %a0
  2196. jne 2f
  2197. dputs "\nmmu_init:"
  2198. /* Find the start of free memory, get_bi_record does this for us,
  2199. * as the bootinfo structure is located directly behind the kernel
  2200. * and and we simply search for the last entry.
  2201. */
  2202. get_bi_record BI_LAST
  2203. addw #PAGESIZE-1,%a0
  2204. movel %a0,%d0
  2205. andw #-PAGESIZE,%d0
  2206. dputn %d0
  2207. lea %pc@(L(memory_start)),%a0
  2208. movel %d0,%a0@
  2209. lea %pc@(L(kernel_end)),%a0
  2210. movel %d0,%a0@
  2211. /* we have to return the first page at _stext since the init code
  2212. * in mm/init.c simply expects kernel_pg_dir there, the rest of
  2213. * page is used for further ptr tables in get_ptr_table.
  2214. */
  2215. lea %pc@(_stext),%a0
  2216. lea %pc@(L(mmu_cached_pointer_tables)),%a1
  2217. movel %a0,%a1@
  2218. addl #ROOT_TABLE_SIZE*4,%a1@
  2219. lea %pc@(L(mmu_num_pointer_tables)),%a1
  2220. addql #1,%a1@
  2221. /* clear the page
  2222. */
  2223. movel %a0,%a1
  2224. movew #PAGESIZE/4-1,%d0
  2225. 1:
  2226. clrl %a1@+
  2227. dbra %d0,1b
  2228. lea %pc@(L(kernel_pgdir_ptr)),%a1
  2229. movel %a0,%a1@
  2230. dputn %a0
  2231. dputc '\n'
  2232. 2:
  2233. movel ARG1,%d0
  2234. lea %a0@(%d0*4),%a0
  2235. #if 0
  2236. dputn %a0
  2237. dputc '\n'
  2238. #endif
  2239. func_return mmu_get_root_table_entry
  2240. func_start mmu_get_ptr_table_entry,%d0/%a1
  2241. #if 0
  2242. dputs "mmu_get_ptr_table_entry:"
  2243. dputn ARG1
  2244. dputn ARG2
  2245. dputs " ="
  2246. #endif
  2247. movel ARG1,%a0
  2248. movel %a0@,%d0
  2249. jne 2f
  2250. /* Keep track of the number of pointer tables we use
  2251. */
  2252. dputs "\nmmu_get_new_ptr_table:"
  2253. lea %pc@(L(mmu_num_pointer_tables)),%a0
  2254. movel %a0@,%d0
  2255. addql #1,%a0@
  2256. /* See if there is a free pointer table in our cache of pointer tables
  2257. */
  2258. lea %pc@(L(mmu_cached_pointer_tables)),%a1
  2259. andw #7,%d0
  2260. jne 1f
  2261. /* Get a new pointer table page from above the kernel memory
  2262. */
  2263. get_new_page
  2264. movel %a0,%a1@
  2265. 1:
  2266. /* There is an unused pointer table in our cache... use it
  2267. */
  2268. movel %a1@,%d0
  2269. addl #PTR_TABLE_SIZE*4,%a1@
  2270. dputn %d0
  2271. dputc '\n'
  2272. /* Insert the new pointer table into the root table
  2273. */
  2274. movel ARG1,%a0
  2275. orw #_PAGE_TABLE+_PAGE_ACCESSED,%d0
  2276. movel %d0,%a0@
  2277. 2:
  2278. /* Extract the pointer table entry
  2279. */
  2280. andw #-PTR_TABLE_SIZE,%d0
  2281. movel %d0,%a0
  2282. movel ARG2,%d0
  2283. lea %a0@(%d0*4),%a0
  2284. #if 0
  2285. dputn %a0
  2286. dputc '\n'
  2287. #endif
  2288. func_return mmu_get_ptr_table_entry
  2289. func_start mmu_get_page_table_entry,%d0/%a1
  2290. #if 0
  2291. dputs "mmu_get_page_table_entry:"
  2292. dputn ARG1
  2293. dputn ARG2
  2294. dputs " ="
  2295. #endif
  2296. movel ARG1,%a0
  2297. movel %a0@,%d0
  2298. jne 2f
  2299. /* If the page table entry doesn't exist, we allocate a complete new
  2300. * page and use it as one continues big page table which can cover
  2301. * 4MB of memory, nearly almost all mappings have that alignment.
  2302. */
  2303. get_new_page
  2304. addw #_PAGE_TABLE+_PAGE_ACCESSED,%a0
  2305. /* align pointer table entry for a page of page tables
  2306. */
  2307. movel ARG1,%d0
  2308. andw #-(PAGESIZE/PAGE_TABLE_SIZE),%d0
  2309. movel %d0,%a1
  2310. /* Insert the page tables into the pointer entries
  2311. */
  2312. moveq #PAGESIZE/PAGE_TABLE_SIZE/4-1,%d0
  2313. 1:
  2314. movel %a0,%a1@+
  2315. lea %a0@(PAGE_TABLE_SIZE*4),%a0
  2316. dbra %d0,1b
  2317. /* Now we can get the initialized pointer table entry
  2318. */
  2319. movel ARG1,%a0
  2320. movel %a0@,%d0
  2321. 2:
  2322. /* Extract the page table entry
  2323. */
  2324. andw #-PAGE_TABLE_SIZE,%d0
  2325. movel %d0,%a0
  2326. movel ARG2,%d0
  2327. lea %a0@(%d0*4),%a0
  2328. #if 0
  2329. dputn %a0
  2330. dputc '\n'
  2331. #endif
  2332. func_return mmu_get_page_table_entry
  2333. /*
  2334. * get_new_page
  2335. *
  2336. * Return a new page from the memory start and clear it.
  2337. */
  2338. func_start get_new_page,%d0/%a1
  2339. dputs "\nget_new_page:"
  2340. /* allocate the page and adjust memory_start
  2341. */
  2342. lea %pc@(L(memory_start)),%a0
  2343. movel %a0@,%a1
  2344. addl #PAGESIZE,%a0@
  2345. /* clear the new page
  2346. */
  2347. movel %a1,%a0
  2348. movew #PAGESIZE/4-1,%d0
  2349. 1:
  2350. clrl %a1@+
  2351. dbra %d0,1b
  2352. dputn %a0
  2353. dputc '\n'
  2354. func_return get_new_page
  2355. /*
  2356. * Debug output support
  2357. * Atarians have a choice between the parallel port, the serial port
  2358. * from the MFP or a serial port of the SCC
  2359. */
  2360. #ifdef CONFIG_MAC
  2361. L(scc_initable_mac):
  2362. .byte 4,0x44 /* x16, 1 stopbit, no parity */
  2363. .byte 3,0xc0 /* receiver: 8 bpc */
  2364. .byte 5,0xe2 /* transmitter: 8 bpc, assert dtr/rts */
  2365. .byte 10,0 /* NRZ */
  2366. .byte 11,0x50 /* use baud rate generator */
  2367. .byte 12,1,13,0 /* 38400 baud */
  2368. .byte 14,1 /* Baud rate generator enable */
  2369. .byte 3,0xc1 /* enable receiver */
  2370. .byte 5,0xea /* enable transmitter */
  2371. .byte -1
  2372. .even
  2373. #endif
  2374. #ifdef CONFIG_ATARI
  2375. /* #define USE_PRINTER */
  2376. /* #define USE_SCC_B */
  2377. /* #define USE_SCC_A */
  2378. #define USE_MFP
  2379. #if defined(USE_SCC_A) || defined(USE_SCC_B)
  2380. #define USE_SCC
  2381. /* Initialisation table for SCC */
  2382. L(scc_initable):
  2383. .byte 9,12 /* Reset */
  2384. .byte 4,0x44 /* x16, 1 stopbit, no parity */
  2385. .byte 3,0xc0 /* receiver: 8 bpc */
  2386. .byte 5,0xe2 /* transmitter: 8 bpc, assert dtr/rts */
  2387. .byte 9,0 /* no interrupts */
  2388. .byte 10,0 /* NRZ */
  2389. .byte 11,0x50 /* use baud rate generator */
  2390. .byte 12,24,13,0 /* 9600 baud */
  2391. .byte 14,2,14,3 /* use master clock for BRG, enable */
  2392. .byte 3,0xc1 /* enable receiver */
  2393. .byte 5,0xea /* enable transmitter */
  2394. .byte -1
  2395. .even
  2396. #endif
  2397. #ifdef USE_PRINTER
  2398. LPSG_SELECT = 0xff8800
  2399. LPSG_READ = 0xff8800
  2400. LPSG_WRITE = 0xff8802
  2401. LPSG_IO_A = 14
  2402. LPSG_IO_B = 15
  2403. LPSG_CONTROL = 7
  2404. LSTMFP_GPIP = 0xfffa01
  2405. LSTMFP_DDR = 0xfffa05
  2406. LSTMFP_IERB = 0xfffa09
  2407. #elif defined(USE_SCC_B)
  2408. LSCC_CTRL = 0xff8c85
  2409. LSCC_DATA = 0xff8c87
  2410. #elif defined(USE_SCC_A)
  2411. LSCC_CTRL = 0xff8c81
  2412. LSCC_DATA = 0xff8c83
  2413. #elif defined(USE_MFP)
  2414. LMFP_UCR = 0xfffa29
  2415. LMFP_TDCDR = 0xfffa1d
  2416. LMFP_TDDR = 0xfffa25
  2417. LMFP_TSR = 0xfffa2d
  2418. LMFP_UDR = 0xfffa2f
  2419. #endif
  2420. #endif /* CONFIG_ATARI */
  2421. /*
  2422. * Serial port output support.
  2423. */
  2424. /*
  2425. * Initialize serial port hardware for 9600/8/1
  2426. */
  2427. func_start serial_init,%d0/%d1/%a0/%a1
  2428. /*
  2429. * Some of the register usage that follows
  2430. * CONFIG_AMIGA
  2431. * a0 = pointer to boot info record
  2432. * d0 = boot info offset
  2433. * CONFIG_ATARI
  2434. * a0 = address of SCC
  2435. * a1 = Liobase address/address of scc_initable
  2436. * d0 = init data for serial port
  2437. * CONFIG_MAC
  2438. * a0 = address of SCC
  2439. * a1 = address of scc_initable_mac
  2440. * d0 = init data for serial port
  2441. */
  2442. #ifdef CONFIG_AMIGA
  2443. #define SERIAL_DTR 7
  2444. #define SERIAL_CNTRL CIABBASE+C_PRA
  2445. is_not_amiga(1f)
  2446. lea %pc@(L(custom)),%a0
  2447. movel #-ZTWOBASE,%a0@
  2448. bclr #SERIAL_DTR,SERIAL_CNTRL-ZTWOBASE
  2449. get_bi_record BI_AMIGA_SERPER
  2450. movew %a0@,CUSTOMBASE+C_SERPER-ZTWOBASE
  2451. | movew #61,CUSTOMBASE+C_SERPER-ZTWOBASE
  2452. 1:
  2453. #endif
  2454. #ifdef CONFIG_ATARI
  2455. is_not_atari(4f)
  2456. movel %pc@(L(iobase)),%a1
  2457. #if defined(USE_PRINTER)
  2458. bclr #0,%a1@(LSTMFP_IERB)
  2459. bclr #0,%a1@(LSTMFP_DDR)
  2460. moveb #LPSG_CONTROL,%a1@(LPSG_SELECT)
  2461. moveb #0xff,%a1@(LPSG_WRITE)
  2462. moveb #LPSG_IO_B,%a1@(LPSG_SELECT)
  2463. clrb %a1@(LPSG_WRITE)
  2464. moveb #LPSG_IO_A,%a1@(LPSG_SELECT)
  2465. moveb %a1@(LPSG_READ),%d0
  2466. bset #5,%d0
  2467. moveb %d0,%a1@(LPSG_WRITE)
  2468. #elif defined(USE_SCC)
  2469. lea %a1@(LSCC_CTRL),%a0
  2470. lea %pc@(L(scc_initable)),%a1
  2471. 2: moveb %a1@+,%d0
  2472. jmi 3f
  2473. moveb %d0,%a0@
  2474. moveb %a1@+,%a0@
  2475. jra 2b
  2476. 3: clrb %a0@
  2477. #elif defined(USE_MFP)
  2478. bclr #1,%a1@(LMFP_TSR)
  2479. moveb #0x88,%a1@(LMFP_UCR)
  2480. andb #0x70,%a1@(LMFP_TDCDR)
  2481. moveb #2,%a1@(LMFP_TDDR)
  2482. orb #1,%a1@(LMFP_TDCDR)
  2483. bset #1,%a1@(LMFP_TSR)
  2484. #endif
  2485. jra L(serial_init_done)
  2486. 4:
  2487. #endif
  2488. #ifdef CONFIG_MAC
  2489. is_not_mac(L(serial_init_not_mac))
  2490. #ifdef SERIAL_DEBUG
  2491. /* You may define either or both of these. */
  2492. #define MAC_USE_SCC_A /* Modem port */
  2493. #define MAC_USE_SCC_B /* Printer port */
  2494. #define mac_scc_cha_b_ctrl_offset 0x0
  2495. #define mac_scc_cha_a_ctrl_offset 0x2
  2496. #define mac_scc_cha_b_data_offset 0x4
  2497. #define mac_scc_cha_a_data_offset 0x6
  2498. #if defined(MAC_USE_SCC_A) || defined(MAC_USE_SCC_B)
  2499. movel %pc@(L(mac_sccbase)),%a0
  2500. /* Reset SCC register pointer */
  2501. moveb %a0@(mac_scc_cha_a_ctrl_offset),%d0
  2502. /* Reset SCC device: write register pointer then register value */
  2503. moveb #9,%a0@(mac_scc_cha_a_ctrl_offset)
  2504. moveb #0xc0,%a0@(mac_scc_cha_a_ctrl_offset)
  2505. /* Wait for 5 PCLK cycles, which is about 68 CPU cycles */
  2506. /* 5 / 3.6864 MHz = approx. 1.36 us = 68 / 50 MHz */
  2507. movel #35,%d0
  2508. 5:
  2509. subq #1,%d0
  2510. jne 5b
  2511. #endif
  2512. #ifdef MAC_USE_SCC_A
  2513. /* Initialize channel A */
  2514. lea %pc@(L(scc_initable_mac)),%a1
  2515. 5: moveb %a1@+,%d0
  2516. jmi 6f
  2517. moveb %d0,%a0@(mac_scc_cha_a_ctrl_offset)
  2518. moveb %a1@+,%a0@(mac_scc_cha_a_ctrl_offset)
  2519. jra 5b
  2520. 6:
  2521. #endif /* MAC_USE_SCC_A */
  2522. #ifdef MAC_USE_SCC_B
  2523. /* Initialize channel B */
  2524. lea %pc@(L(scc_initable_mac)),%a1
  2525. 7: moveb %a1@+,%d0
  2526. jmi 8f
  2527. moveb %d0,%a0@(mac_scc_cha_b_ctrl_offset)
  2528. moveb %a1@+,%a0@(mac_scc_cha_b_ctrl_offset)
  2529. jra 7b
  2530. 8:
  2531. #endif /* MAC_USE_SCC_B */
  2532. #endif /* SERIAL_DEBUG */
  2533. jra L(serial_init_done)
  2534. L(serial_init_not_mac):
  2535. #endif /* CONFIG_MAC */
  2536. #ifdef CONFIG_Q40
  2537. is_not_q40(2f)
  2538. /* debug output goes into SRAM, so we don't do it unless requested
  2539. - check for '%LX$' signature in SRAM */
  2540. lea %pc@(q40_mem_cptr),%a1
  2541. move.l #0xff020010,%a1@ /* must be inited - also used by debug=mem */
  2542. move.l #0xff020000,%a1
  2543. cmp.b #'%',%a1@
  2544. bne 2f /*nodbg*/
  2545. addq.w #4,%a1
  2546. cmp.b #'L',%a1@
  2547. bne 2f /*nodbg*/
  2548. addq.w #4,%a1
  2549. cmp.b #'X',%a1@
  2550. bne 2f /*nodbg*/
  2551. addq.w #4,%a1
  2552. cmp.b #'$',%a1@
  2553. bne 2f /*nodbg*/
  2554. /* signature OK */
  2555. lea %pc@(L(q40_do_debug)),%a1
  2556. tas %a1@
  2557. /*nodbg: q40_do_debug is 0 by default*/
  2558. 2:
  2559. #endif
  2560. #ifdef CONFIG_APOLLO
  2561. /* We count on the PROM initializing SIO1 */
  2562. #endif
  2563. #ifdef CONFIG_HP300
  2564. /* We count on the boot loader initialising the UART */
  2565. #endif
  2566. L(serial_init_done):
  2567. func_return serial_init
  2568. /*
  2569. * Output character on serial port.
  2570. */
  2571. func_start serial_putc,%d0/%d1/%a0/%a1
  2572. movel ARG1,%d0
  2573. cmpib #'\n',%d0
  2574. jbne 1f
  2575. /* A little safe recursion is good for the soul */
  2576. serial_putc #'\r'
  2577. 1:
  2578. #ifdef CONFIG_AMIGA
  2579. is_not_amiga(2f)
  2580. andw #0x00ff,%d0
  2581. oriw #0x0100,%d0
  2582. movel %pc@(L(custom)),%a0
  2583. movew %d0,%a0@(CUSTOMBASE+C_SERDAT)
  2584. 1: movew %a0@(CUSTOMBASE+C_SERDATR),%d0
  2585. andw #0x2000,%d0
  2586. jeq 1b
  2587. jra L(serial_putc_done)
  2588. 2:
  2589. #endif
  2590. #ifdef CONFIG_MAC
  2591. is_not_mac(5f)
  2592. #ifdef SERIAL_DEBUG
  2593. #if defined(MAC_USE_SCC_A) || defined(MAC_USE_SCC_B)
  2594. movel %pc@(L(mac_sccbase)),%a1
  2595. #endif
  2596. #ifdef MAC_USE_SCC_A
  2597. 3: btst #2,%a1@(mac_scc_cha_a_ctrl_offset)
  2598. jeq 3b
  2599. moveb %d0,%a1@(mac_scc_cha_a_data_offset)
  2600. #endif /* MAC_USE_SCC_A */
  2601. #ifdef MAC_USE_SCC_B
  2602. 4: btst #2,%a1@(mac_scc_cha_b_ctrl_offset)
  2603. jeq 4b
  2604. moveb %d0,%a1@(mac_scc_cha_b_data_offset)
  2605. #endif /* MAC_USE_SCC_B */
  2606. #endif /* SERIAL_DEBUG */
  2607. jra L(serial_putc_done)
  2608. 5:
  2609. #endif /* CONFIG_MAC */
  2610. #ifdef CONFIG_ATARI
  2611. is_not_atari(4f)
  2612. movel %pc@(L(iobase)),%a1
  2613. #if defined(USE_PRINTER)
  2614. 3: btst #0,%a1@(LSTMFP_GPIP)
  2615. jne 3b
  2616. moveb #LPSG_IO_B,%a1@(LPSG_SELECT)
  2617. moveb %d0,%a1@(LPSG_WRITE)
  2618. moveb #LPSG_IO_A,%a1@(LPSG_SELECT)
  2619. moveb %a1@(LPSG_READ),%d0
  2620. bclr #5,%d0
  2621. moveb %d0,%a1@(LPSG_WRITE)
  2622. nop
  2623. nop
  2624. bset #5,%d0
  2625. moveb %d0,%a1@(LPSG_WRITE)
  2626. #elif defined(USE_SCC)
  2627. 3: btst #2,%a1@(LSCC_CTRL)
  2628. jeq 3b
  2629. moveb %d0,%a1@(LSCC_DATA)
  2630. #elif defined(USE_MFP)
  2631. 3: btst #7,%a1@(LMFP_TSR)
  2632. jeq 3b
  2633. moveb %d0,%a1@(LMFP_UDR)
  2634. #endif
  2635. jra L(serial_putc_done)
  2636. 4:
  2637. #endif /* CONFIG_ATARI */
  2638. #ifdef CONFIG_MVME147
  2639. is_not_mvme147(2f)
  2640. 1: btst #2,M147_SCC_CTRL_A
  2641. jeq 1b
  2642. moveb %d0,M147_SCC_DATA_A
  2643. jbra L(serial_putc_done)
  2644. 2:
  2645. #endif
  2646. #ifdef CONFIG_MVME16x
  2647. is_not_mvme16x(2f)
  2648. /*
  2649. * If the loader gave us a board type then we can use that to
  2650. * select an appropriate output routine; otherwise we just use
  2651. * the Bug code. If we have to use the Bug that means the Bug
  2652. * workspace has to be valid, which means the Bug has to use
  2653. * the SRAM, which is non-standard.
  2654. */
  2655. moveml %d0-%d7/%a2-%a6,%sp@-
  2656. movel vme_brdtype,%d1
  2657. jeq 1f | No tag - use the Bug
  2658. cmpi #VME_TYPE_MVME162,%d1
  2659. jeq 6f
  2660. cmpi #VME_TYPE_MVME172,%d1
  2661. jne 5f
  2662. /* 162/172; it's an SCC */
  2663. 6: btst #2,M162_SCC_CTRL_A
  2664. nop
  2665. nop
  2666. nop
  2667. jeq 6b
  2668. moveb #8,M162_SCC_CTRL_A
  2669. nop
  2670. nop
  2671. nop
  2672. moveb %d0,M162_SCC_CTRL_A
  2673. jra 3f
  2674. 5:
  2675. /* 166/167/177; it's a CD2401 */
  2676. moveb #0,M167_CYCAR
  2677. moveb M167_CYIER,%d2
  2678. moveb #0x02,M167_CYIER
  2679. 7:
  2680. btst #5,M167_PCSCCTICR
  2681. jeq 7b
  2682. moveb M167_PCTPIACKR,%d1
  2683. moveb M167_CYLICR,%d1
  2684. jeq 8f
  2685. moveb #0x08,M167_CYTEOIR
  2686. jra 7b
  2687. 8:
  2688. moveb %d0,M167_CYTDR
  2689. moveb #0,M167_CYTEOIR
  2690. moveb %d2,M167_CYIER
  2691. jra 3f
  2692. 1:
  2693. moveb %d0,%sp@-
  2694. trap #15
  2695. .word 0x0020 /* TRAP 0x020 */
  2696. 3:
  2697. moveml %sp@+,%d0-%d7/%a2-%a6
  2698. jbra L(serial_putc_done)
  2699. 2:
  2700. #endif /* CONFIG_MVME16x */
  2701. #ifdef CONFIG_BVME6000
  2702. is_not_bvme6000(2f)
  2703. /*
  2704. * The BVME6000 machine has a serial port ...
  2705. */
  2706. 1: btst #2,BVME_SCC_CTRL_A
  2707. jeq 1b
  2708. moveb %d0,BVME_SCC_DATA_A
  2709. jbra L(serial_putc_done)
  2710. 2:
  2711. #endif
  2712. #ifdef CONFIG_SUN3X
  2713. is_not_sun3x(2f)
  2714. movel %d0,-(%sp)
  2715. movel 0xFEFE0018,%a1
  2716. jbsr (%a1)
  2717. addq #4,%sp
  2718. jbra L(serial_putc_done)
  2719. 2:
  2720. #endif
  2721. #ifdef CONFIG_Q40
  2722. is_not_q40(2f)
  2723. tst.l %pc@(L(q40_do_debug)) /* only debug if requested */
  2724. beq 2f
  2725. lea %pc@(q40_mem_cptr),%a1
  2726. move.l %a1@,%a0
  2727. move.b %d0,%a0@
  2728. addq.l #4,%a0
  2729. move.l %a0,%a1@
  2730. jbra L(serial_putc_done)
  2731. 2:
  2732. #endif
  2733. #ifdef CONFIG_APOLLO
  2734. is_not_apollo(2f)
  2735. movl %pc@(L(iobase)),%a1
  2736. moveb %d0,%a1@(LTHRB0)
  2737. 1: moveb %a1@(LSRB0),%d0
  2738. andb #0x4,%d0
  2739. beq 1b
  2740. jbra L(serial_putc_done)
  2741. 2:
  2742. #endif
  2743. #ifdef CONFIG_HP300
  2744. is_not_hp300(3f)
  2745. movl %pc@(L(iobase)),%a1
  2746. addl %pc@(L(uartbase)),%a1
  2747. movel %pc@(L(uart_scode)),%d1 /* Check the scode */
  2748. jmi 3f /* Unset? Exit */
  2749. cmpi #256,%d1 /* APCI scode? */
  2750. jeq 2f
  2751. 1: moveb %a1@(DCALSR),%d1 /* Output to DCA */
  2752. andb #0x20,%d1
  2753. beq 1b
  2754. moveb %d0,%a1@(DCADATA)
  2755. jbra L(serial_putc_done)
  2756. 2: moveb %a1@(APCILSR),%d1 /* Output to APCI */
  2757. andb #0x20,%d1
  2758. beq 2b
  2759. moveb %d0,%a1@(APCIDATA)
  2760. jbra L(serial_putc_done)
  2761. 3:
  2762. #endif
  2763. L(serial_putc_done):
  2764. func_return serial_putc
  2765. /*
  2766. * Output a string.
  2767. */
  2768. func_start puts,%d0/%a0
  2769. movel ARG1,%a0
  2770. jra 2f
  2771. 1:
  2772. #ifdef CONSOLE
  2773. console_putc %d0
  2774. #endif
  2775. #ifdef SERIAL_DEBUG
  2776. serial_putc %d0
  2777. #endif
  2778. 2: moveb %a0@+,%d0
  2779. jne 1b
  2780. func_return puts
  2781. /*
  2782. * Output number in hex notation.
  2783. */
  2784. func_start putn,%d0-%d2
  2785. putc ' '
  2786. movel ARG1,%d0
  2787. moveq #7,%d1
  2788. 1: roll #4,%d0
  2789. move %d0,%d2
  2790. andb #0x0f,%d2
  2791. addb #'0',%d2
  2792. cmpb #'9',%d2
  2793. jls 2f
  2794. addb #'A'-('9'+1),%d2
  2795. 2:
  2796. #ifdef CONSOLE
  2797. console_putc %d2
  2798. #endif
  2799. #ifdef SERIAL_DEBUG
  2800. serial_putc %d2
  2801. #endif
  2802. dbra %d1,1b
  2803. func_return putn
  2804. #ifdef CONFIG_MAC
  2805. /*
  2806. * mac_early_print
  2807. *
  2808. * This routine takes its parameters on the stack. It then
  2809. * turns around and calls the internal routines. This routine
  2810. * is used by the boot console.
  2811. *
  2812. * The calling parameters are:
  2813. * void mac_early_print(const char *str, unsigned length);
  2814. *
  2815. * This routine does NOT understand variable arguments only
  2816. * simple strings!
  2817. */
  2818. ENTRY(mac_early_print)
  2819. moveml %d0/%d1/%a0,%sp@-
  2820. movew %sr,%sp@-
  2821. ori #0x0700,%sr
  2822. movel %sp@(18),%a0 /* fetch parameter */
  2823. movel %sp@(22),%d1 /* fetch parameter */
  2824. jra 2f
  2825. 1:
  2826. #ifdef CONSOLE
  2827. console_putc %d0
  2828. #endif
  2829. #ifdef SERIAL_DEBUG
  2830. serial_putc %d0
  2831. #endif
  2832. subq #1,%d1
  2833. 2: jeq 3f
  2834. moveb %a0@+,%d0
  2835. jne 1b
  2836. 3:
  2837. movew %sp@+,%sr
  2838. moveml %sp@+,%d0/%d1/%a0
  2839. rts
  2840. #endif /* CONFIG_MAC */
  2841. #if defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
  2842. func_start set_leds,%d0/%a0
  2843. movel ARG1,%d0
  2844. #ifdef CONFIG_HP300
  2845. is_not_hp300(1f)
  2846. movel %pc@(L(iobase)),%a0
  2847. moveb %d0,%a0@(0x1ffff)
  2848. jra 2f
  2849. #endif
  2850. 1:
  2851. #ifdef CONFIG_APOLLO
  2852. movel %pc@(L(iobase)),%a0
  2853. lsll #8,%d0
  2854. eorw #0xff00,%d0
  2855. moveb %d0,%a0@(LCPUCTRL)
  2856. #endif
  2857. 2:
  2858. func_return set_leds
  2859. #endif
  2860. #ifdef CONSOLE
  2861. /*
  2862. * For continuity, see the data alignment
  2863. * to which this structure is tied.
  2864. */
  2865. #define Lconsole_struct_cur_column 0
  2866. #define Lconsole_struct_cur_row 4
  2867. #define Lconsole_struct_num_columns 8
  2868. #define Lconsole_struct_num_rows 12
  2869. #define Lconsole_struct_left_edge 16
  2870. #define Lconsole_struct_penguin_putc 20
  2871. func_start console_init,%a0-%a4/%d0-%d7
  2872. /*
  2873. * Some of the register usage that follows
  2874. * a0 = pointer to boot_info
  2875. * a1 = pointer to screen
  2876. * a2 = pointer to Lconsole_globals
  2877. * d3 = pixel width of screen
  2878. * d4 = pixel height of screen
  2879. * (d3,d4) ~= (x,y) of a point just below
  2880. * and to the right of the screen
  2881. * NOT on the screen!
  2882. * d5 = number of bytes per scan line
  2883. * d6 = number of bytes on the entire screen
  2884. */
  2885. lea %pc@(L(console_globals)),%a2
  2886. movel %pc@(L(mac_videobase)),%a1
  2887. movel %pc@(L(mac_rowbytes)),%d5
  2888. movel %pc@(L(mac_dimensions)),%d3 /* -> low byte */
  2889. movel %d3,%d4
  2890. swap %d4 /* -> high byte */
  2891. andl #0xffff,%d3 /* d3 = screen width in pixels */
  2892. andl #0xffff,%d4 /* d4 = screen height in pixels */
  2893. movel %d5,%d6
  2894. | subl #20,%d6
  2895. mulul %d4,%d6 /* scan line bytes x num scan lines */
  2896. divul #8,%d6 /* we'll clear 8 bytes at a time */
  2897. moveq #-1,%d0 /* Mac_black */
  2898. subq #1,%d6
  2899. L(console_clear_loop):
  2900. movel %d0,%a1@+
  2901. movel %d0,%a1@+
  2902. dbra %d6,L(console_clear_loop)
  2903. /* Calculate font size */
  2904. #if defined(FONT_8x8) && defined(CONFIG_FONT_8x8)
  2905. lea %pc@(font_vga_8x8),%a0
  2906. #elif defined(FONT_8x16) && defined(CONFIG_FONT_8x16)
  2907. lea %pc@(font_vga_8x16),%a0
  2908. #elif defined(FONT_6x11) && defined(CONFIG_FONT_6x11)
  2909. lea %pc@(font_vga_6x11),%a0
  2910. #elif defined(CONFIG_FONT_8x8) /* default */
  2911. lea %pc@(font_vga_8x8),%a0
  2912. #else /* no compiled-in font */
  2913. lea 0,%a0
  2914. #endif
  2915. /*
  2916. * At this point we make a shift in register usage
  2917. * a1 = address of console_font pointer
  2918. */
  2919. lea %pc@(L(console_font)),%a1
  2920. movel %a0,%a1@ /* store pointer to struct fbcon_font_desc in console_font */
  2921. tstl %a0
  2922. jeq 1f
  2923. lea %pc@(L(console_font_data)),%a4
  2924. movel %a0@(FONT_DESC_DATA),%d0
  2925. subl #L(console_font),%a1
  2926. addl %a1,%d0
  2927. movel %d0,%a4@
  2928. /*
  2929. * Calculate global maxs
  2930. * Note - we can use either an
  2931. * 8 x 16 or 8 x 8 character font
  2932. * 6 x 11 also supported
  2933. */
  2934. /* ASSERT: a0 = contents of Lconsole_font */
  2935. movel %d3,%d0 /* screen width in pixels */
  2936. divul %a0@(FONT_DESC_WIDTH),%d0 /* d0 = max num chars per row */
  2937. movel %d4,%d1 /* screen height in pixels */
  2938. divul %a0@(FONT_DESC_HEIGHT),%d1 /* d1 = max num rows */
  2939. movel %d0,%a2@(Lconsole_struct_num_columns)
  2940. movel %d1,%a2@(Lconsole_struct_num_rows)
  2941. /*
  2942. * Clear the current row and column
  2943. */
  2944. clrl %a2@(Lconsole_struct_cur_column)
  2945. clrl %a2@(Lconsole_struct_cur_row)
  2946. clrl %a2@(Lconsole_struct_left_edge)
  2947. /*
  2948. * Initialization is complete
  2949. */
  2950. 1:
  2951. func_return console_init
  2952. func_start console_put_stats,%a0/%d7
  2953. /*
  2954. * Some of the register usage that follows
  2955. * a0 = pointer to boot_info
  2956. * d7 = value of boot_info fields
  2957. */
  2958. puts "\nMacLinux\n"
  2959. #ifdef SERIAL_DEBUG
  2960. puts "\n vidaddr:"
  2961. putn %pc@(L(mac_videobase)) /* video addr. */
  2962. puts "\n _stext:"
  2963. lea %pc@(_stext),%a0
  2964. putn %a0
  2965. puts "\nbootinfo:"
  2966. lea %pc@(_end),%a0
  2967. putn %a0
  2968. puts "\n cpuid:"
  2969. putn %pc@(L(cputype))
  2970. # ifdef CONFIG_MAC
  2971. puts "\n sccbase:"
  2972. putn %pc@(L(mac_sccbase))
  2973. # endif
  2974. # ifdef MMU_PRINT
  2975. putc '\n'
  2976. jbsr mmu_print_machine_cpu_types
  2977. # endif
  2978. #endif /* SERIAL_DEBUG */
  2979. putc '\n'
  2980. func_return console_put_stats
  2981. #ifdef CONSOLE_PENGUIN
  2982. func_start console_put_penguin,%a0-%a1/%d0-%d7
  2983. /*
  2984. * Get 'that_penguin' onto the screen in the upper right corner
  2985. * penguin is 64 x 74 pixels, align against right edge of screen
  2986. */
  2987. lea %pc@(L(mac_dimensions)),%a0
  2988. movel %a0@,%d0
  2989. andil #0xffff,%d0
  2990. subil #64,%d0 /* snug up against the right edge */
  2991. clrl %d1 /* start at the top */
  2992. movel #73,%d7
  2993. lea %pc@(L(that_penguin)),%a1
  2994. L(console_penguin_row):
  2995. movel #31,%d6
  2996. L(console_penguin_pixel_pair):
  2997. moveb %a1@,%d2
  2998. lsrb #4,%d2
  2999. console_plot_pixel %d0,%d1,%d2
  3000. addq #1,%d0
  3001. moveb %a1@+,%d2
  3002. console_plot_pixel %d0,%d1,%d2
  3003. addq #1,%d0
  3004. dbra %d6,L(console_penguin_pixel_pair)
  3005. subil #64,%d0
  3006. addq #1,%d1
  3007. dbra %d7,L(console_penguin_row)
  3008. func_return console_put_penguin
  3009. /* include penguin bitmap */
  3010. L(that_penguin):
  3011. #include "../mac/mac_penguin.S"
  3012. #endif
  3013. /*
  3014. * Calculate source and destination addresses
  3015. * output a1 = dest
  3016. * a2 = source
  3017. */
  3018. func_start console_scroll,%a0-%a4/%d0-%d7
  3019. lea %pc@(L(mac_videobase)),%a0
  3020. movel %a0@,%a1
  3021. movel %a1,%a2
  3022. lea %pc@(L(mac_rowbytes)),%a0
  3023. movel %a0@,%d5
  3024. movel %pc@(L(console_font)),%a0
  3025. tstl %a0
  3026. jeq 1f
  3027. mulul %a0@(FONT_DESC_HEIGHT),%d5 /* account for # scan lines per character */
  3028. addal %d5,%a2
  3029. /*
  3030. * Get dimensions
  3031. */
  3032. lea %pc@(L(mac_dimensions)),%a0
  3033. movel %a0@,%d3
  3034. movel %d3,%d4
  3035. swap %d4
  3036. andl #0xffff,%d3 /* d3 = screen width in pixels */
  3037. andl #0xffff,%d4 /* d4 = screen height in pixels */
  3038. /*
  3039. * Calculate number of bytes to move
  3040. */
  3041. lea %pc@(L(mac_rowbytes)),%a0
  3042. movel %a0@,%d6
  3043. movel %pc@(L(console_font)),%a0
  3044. subl %a0@(FONT_DESC_HEIGHT),%d4 /* we're not scrolling the top row! */
  3045. mulul %d4,%d6 /* scan line bytes x num scan lines */
  3046. divul #32,%d6 /* we'll move 8 longs at a time */
  3047. subq #1,%d6
  3048. L(console_scroll_loop):
  3049. movel %a2@+,%a1@+
  3050. movel %a2@+,%a1@+
  3051. movel %a2@+,%a1@+
  3052. movel %a2@+,%a1@+
  3053. movel %a2@+,%a1@+
  3054. movel %a2@+,%a1@+
  3055. movel %a2@+,%a1@+
  3056. movel %a2@+,%a1@+
  3057. dbra %d6,L(console_scroll_loop)
  3058. lea %pc@(L(mac_rowbytes)),%a0
  3059. movel %a0@,%d6
  3060. movel %pc@(L(console_font)),%a0
  3061. mulul %a0@(FONT_DESC_HEIGHT),%d6 /* scan line bytes x font height */
  3062. divul #32,%d6 /* we'll move 8 words at a time */
  3063. subq #1,%d6
  3064. moveq #-1,%d0
  3065. L(console_scroll_clear_loop):
  3066. movel %d0,%a1@+
  3067. movel %d0,%a1@+
  3068. movel %d0,%a1@+
  3069. movel %d0,%a1@+
  3070. movel %d0,%a1@+
  3071. movel %d0,%a1@+
  3072. movel %d0,%a1@+
  3073. movel %d0,%a1@+
  3074. dbra %d6,L(console_scroll_clear_loop)
  3075. 1:
  3076. func_return console_scroll
  3077. func_start console_putc,%a0/%a1/%d0-%d7
  3078. is_not_mac(L(console_exit))
  3079. tstl %pc@(L(console_font))
  3080. jeq L(console_exit)
  3081. /* Output character in d7 on console.
  3082. */
  3083. movel ARG1,%d7
  3084. cmpib #'\n',%d7
  3085. jbne 1f
  3086. /* A little safe recursion is good for the soul */
  3087. console_putc #'\r'
  3088. 1:
  3089. lea %pc@(L(console_globals)),%a0
  3090. cmpib #10,%d7
  3091. jne L(console_not_lf)
  3092. movel %a0@(Lconsole_struct_cur_row),%d0
  3093. addil #1,%d0
  3094. movel %d0,%a0@(Lconsole_struct_cur_row)
  3095. movel %a0@(Lconsole_struct_num_rows),%d1
  3096. cmpl %d1,%d0
  3097. jcs 1f
  3098. subil #1,%d0
  3099. movel %d0,%a0@(Lconsole_struct_cur_row)
  3100. console_scroll
  3101. 1:
  3102. jra L(console_exit)
  3103. L(console_not_lf):
  3104. cmpib #13,%d7
  3105. jne L(console_not_cr)
  3106. clrl %a0@(Lconsole_struct_cur_column)
  3107. jra L(console_exit)
  3108. L(console_not_cr):
  3109. cmpib #1,%d7
  3110. jne L(console_not_home)
  3111. clrl %a0@(Lconsole_struct_cur_row)
  3112. clrl %a0@(Lconsole_struct_cur_column)
  3113. jra L(console_exit)
  3114. /*
  3115. * At this point we know that the %d7 character is going to be
  3116. * rendered on the screen. Register usage is -
  3117. * a0 = pointer to console globals
  3118. * a1 = font data
  3119. * d0 = cursor column
  3120. * d1 = cursor row to draw the character
  3121. * d7 = character number
  3122. */
  3123. L(console_not_home):
  3124. movel %a0@(Lconsole_struct_cur_column),%d0
  3125. addql #1,%a0@(Lconsole_struct_cur_column)
  3126. movel %a0@(Lconsole_struct_num_columns),%d1
  3127. cmpl %d1,%d0
  3128. jcs 1f
  3129. console_putc #'\n' /* recursion is OK! */
  3130. 1:
  3131. movel %a0@(Lconsole_struct_cur_row),%d1
  3132. /*
  3133. * At this point we make a shift in register usage
  3134. * a0 = address of pointer to font data (fbcon_font_desc)
  3135. */
  3136. movel %pc@(L(console_font)),%a0
  3137. movel %pc@(L(console_font_data)),%a1 /* Load fbcon_font_desc.data into a1 */
  3138. andl #0x000000ff,%d7
  3139. /* ASSERT: a0 = contents of Lconsole_font */
  3140. mulul %a0@(FONT_DESC_HEIGHT),%d7 /* d7 = index into font data */
  3141. addl %d7,%a1 /* a1 = points to char image */
  3142. /*
  3143. * At this point we make a shift in register usage
  3144. * d0 = pixel coordinate, x
  3145. * d1 = pixel coordinate, y
  3146. * d2 = (bit 0) 1/0 for white/black (!) pixel on screen
  3147. * d3 = font scan line data (8 pixels)
  3148. * d6 = count down for the font's pixel width (8)
  3149. * d7 = count down for the font's pixel count in height
  3150. */
  3151. /* ASSERT: a0 = contents of Lconsole_font */
  3152. mulul %a0@(FONT_DESC_WIDTH),%d0
  3153. mulul %a0@(FONT_DESC_HEIGHT),%d1
  3154. movel %a0@(FONT_DESC_HEIGHT),%d7 /* Load fbcon_font_desc.height into d7 */
  3155. subq #1,%d7
  3156. L(console_read_char_scanline):
  3157. moveb %a1@+,%d3
  3158. /* ASSERT: a0 = contents of Lconsole_font */
  3159. movel %a0@(FONT_DESC_WIDTH),%d6 /* Load fbcon_font_desc.width into d6 */
  3160. subql #1,%d6
  3161. L(console_do_font_scanline):
  3162. lslb #1,%d3
  3163. scsb %d2 /* convert 1 bit into a byte */
  3164. console_plot_pixel %d0,%d1,%d2
  3165. addq #1,%d0
  3166. dbra %d6,L(console_do_font_scanline)
  3167. /* ASSERT: a0 = contents of Lconsole_font */
  3168. subl %a0@(FONT_DESC_WIDTH),%d0
  3169. addq #1,%d1
  3170. dbra %d7,L(console_read_char_scanline)
  3171. L(console_exit):
  3172. func_return console_putc
  3173. /*
  3174. * Input:
  3175. * d0 = x coordinate
  3176. * d1 = y coordinate
  3177. * d2 = (bit 0) 1/0 for white/black (!)
  3178. * All registers are preserved
  3179. */
  3180. func_start console_plot_pixel,%a0-%a1/%d0-%d4
  3181. movel %pc@(L(mac_videobase)),%a1
  3182. movel %pc@(L(mac_videodepth)),%d3
  3183. movel ARG1,%d0
  3184. movel ARG2,%d1
  3185. mulul %pc@(L(mac_rowbytes)),%d1
  3186. movel ARG3,%d2
  3187. /*
  3188. * Register usage:
  3189. * d0 = x coord becomes byte offset into frame buffer
  3190. * d1 = y coord
  3191. * d2 = black or white (0/1)
  3192. * d3 = video depth
  3193. * d4 = temp of x (d0) for many bit depths
  3194. */
  3195. L(test_1bit):
  3196. cmpb #1,%d3
  3197. jbne L(test_2bit)
  3198. movel %d0,%d4 /* we need the low order 3 bits! */
  3199. divul #8,%d0
  3200. addal %d0,%a1
  3201. addal %d1,%a1
  3202. andb #7,%d4
  3203. eorb #7,%d4 /* reverse the x-coordinate w/ screen-bit # */
  3204. andb #1,%d2
  3205. jbne L(white_1)
  3206. bsetb %d4,%a1@
  3207. jbra L(console_plot_pixel_exit)
  3208. L(white_1):
  3209. bclrb %d4,%a1@
  3210. jbra L(console_plot_pixel_exit)
  3211. L(test_2bit):
  3212. cmpb #2,%d3
  3213. jbne L(test_4bit)
  3214. movel %d0,%d4 /* we need the low order 2 bits! */
  3215. divul #4,%d0
  3216. addal %d0,%a1
  3217. addal %d1,%a1
  3218. andb #3,%d4
  3219. eorb #3,%d4 /* reverse the x-coordinate w/ screen-bit # */
  3220. lsll #1,%d4 /* ! */
  3221. andb #1,%d2
  3222. jbne L(white_2)
  3223. bsetb %d4,%a1@
  3224. addq #1,%d4
  3225. bsetb %d4,%a1@
  3226. jbra L(console_plot_pixel_exit)
  3227. L(white_2):
  3228. bclrb %d4,%a1@
  3229. addq #1,%d4
  3230. bclrb %d4,%a1@
  3231. jbra L(console_plot_pixel_exit)
  3232. L(test_4bit):
  3233. cmpb #4,%d3
  3234. jbne L(test_8bit)
  3235. movel %d0,%d4 /* we need the low order bit! */
  3236. divul #2,%d0
  3237. addal %d0,%a1
  3238. addal %d1,%a1
  3239. andb #1,%d4
  3240. eorb #1,%d4
  3241. lsll #2,%d4 /* ! */
  3242. andb #1,%d2
  3243. jbne L(white_4)
  3244. bsetb %d4,%a1@
  3245. addq #1,%d4
  3246. bsetb %d4,%a1@
  3247. addq #1,%d4
  3248. bsetb %d4,%a1@
  3249. addq #1,%d4
  3250. bsetb %d4,%a1@
  3251. jbra L(console_plot_pixel_exit)
  3252. L(white_4):
  3253. bclrb %d4,%a1@
  3254. addq #1,%d4
  3255. bclrb %d4,%a1@
  3256. addq #1,%d4
  3257. bclrb %d4,%a1@
  3258. addq #1,%d4
  3259. bclrb %d4,%a1@
  3260. jbra L(console_plot_pixel_exit)
  3261. L(test_8bit):
  3262. cmpb #8,%d3
  3263. jbne L(test_16bit)
  3264. addal %d0,%a1
  3265. addal %d1,%a1
  3266. andb #1,%d2
  3267. jbne L(white_8)
  3268. moveb #0xff,%a1@
  3269. jbra L(console_plot_pixel_exit)
  3270. L(white_8):
  3271. clrb %a1@
  3272. jbra L(console_plot_pixel_exit)
  3273. L(test_16bit):
  3274. cmpb #16,%d3
  3275. jbne L(console_plot_pixel_exit)
  3276. addal %d0,%a1
  3277. addal %d0,%a1
  3278. addal %d1,%a1
  3279. andb #1,%d2
  3280. jbne L(white_16)
  3281. clrw %a1@
  3282. jbra L(console_plot_pixel_exit)
  3283. L(white_16):
  3284. movew #0x0fff,%a1@
  3285. jbra L(console_plot_pixel_exit)
  3286. L(console_plot_pixel_exit):
  3287. func_return console_plot_pixel
  3288. #endif /* CONSOLE */
  3289. #if 0
  3290. /*
  3291. * This is some old code lying around. I don't believe
  3292. * it's used or important anymore. My guess is it contributed
  3293. * to getting to this point, but it's done for now.
  3294. * It was still in the 2.1.77 head.S, so it's still here.
  3295. * (And still not used!)
  3296. */
  3297. L(showtest):
  3298. moveml %a0/%d7,%sp@-
  3299. puts "A="
  3300. putn %a1
  3301. .long 0xf0119f15 | ptestr #5,%a1@,#7,%a0
  3302. puts "DA="
  3303. putn %a0
  3304. puts "D="
  3305. putn %a0@
  3306. puts "S="
  3307. lea %pc@(L(mmu)),%a0
  3308. .long 0xf0106200 | pmove %psr,%a0@
  3309. clrl %d7
  3310. movew %a0@,%d7
  3311. putn %d7
  3312. putc '\n'
  3313. moveml %sp@+,%a0/%d7
  3314. rts
  3315. #endif /* 0 */
  3316. __INITDATA
  3317. .align 4
  3318. #if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA) || \
  3319. defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
  3320. L(custom):
  3321. L(iobase):
  3322. .long 0
  3323. #endif
  3324. #if defined(CONSOLE)
  3325. L(console_globals):
  3326. .long 0 /* cursor column */
  3327. .long 0 /* cursor row */
  3328. .long 0 /* max num columns */
  3329. .long 0 /* max num rows */
  3330. .long 0 /* left edge */
  3331. .long 0 /* mac putc */
  3332. L(console_font):
  3333. .long 0 /* pointer to console font (struct font_desc) */
  3334. L(console_font_data):
  3335. .long 0 /* pointer to console font data */
  3336. #endif /* CONSOLE */
  3337. #if defined(MMU_PRINT)
  3338. L(mmu_print_data):
  3339. .long 0 /* valid flag */
  3340. .long 0 /* start logical */
  3341. .long 0 /* next logical */
  3342. .long 0 /* start physical */
  3343. .long 0 /* next physical */
  3344. #endif /* MMU_PRINT */
  3345. L(cputype):
  3346. .long 0
  3347. L(mmu_cached_pointer_tables):
  3348. .long 0
  3349. L(mmu_num_pointer_tables):
  3350. .long 0
  3351. L(phys_kernel_start):
  3352. .long 0
  3353. L(kernel_end):
  3354. .long 0
  3355. L(memory_start):
  3356. .long 0
  3357. L(kernel_pgdir_ptr):
  3358. .long 0
  3359. L(temp_mmap_mem):
  3360. .long 0
  3361. #if defined (CONFIG_MVME147)
  3362. M147_SCC_CTRL_A = 0xfffe3002
  3363. M147_SCC_DATA_A = 0xfffe3003
  3364. #endif
  3365. #if defined (CONFIG_MVME16x)
  3366. M162_SCC_CTRL_A = 0xfff45005
  3367. M167_CYCAR = 0xfff450ee
  3368. M167_CYIER = 0xfff45011
  3369. M167_CYLICR = 0xfff45026
  3370. M167_CYTEOIR = 0xfff45085
  3371. M167_CYTDR = 0xfff450f8
  3372. M167_PCSCCTICR = 0xfff4201e
  3373. M167_PCTPIACKR = 0xfff42025
  3374. #endif
  3375. #if defined (CONFIG_BVME6000)
  3376. BVME_SCC_CTRL_A = 0xffb0000b
  3377. BVME_SCC_DATA_A = 0xffb0000f
  3378. #endif
  3379. #if defined(CONFIG_MAC)
  3380. L(mac_videobase):
  3381. .long 0
  3382. L(mac_videodepth):
  3383. .long 0
  3384. L(mac_dimensions):
  3385. .long 0
  3386. L(mac_rowbytes):
  3387. .long 0
  3388. #ifdef SERIAL_DEBUG
  3389. L(mac_sccbase):
  3390. .long 0
  3391. #endif
  3392. #endif /* CONFIG_MAC */
  3393. #if defined (CONFIG_APOLLO)
  3394. LSRB0 = 0x10412
  3395. LTHRB0 = 0x10416
  3396. LCPUCTRL = 0x10100
  3397. #endif
  3398. #if defined(CONFIG_HP300)
  3399. DCADATA = 0x11
  3400. DCALSR = 0x1b
  3401. APCIDATA = 0x00
  3402. APCILSR = 0x14
  3403. L(uartbase):
  3404. .long 0
  3405. L(uart_scode):
  3406. .long -1
  3407. #endif
  3408. __FINIT
  3409. .data
  3410. .align 4
  3411. availmem:
  3412. .long 0
  3413. m68k_pgtable_cachemode:
  3414. .long 0
  3415. m68k_supervisor_cachemode:
  3416. .long 0
  3417. #if defined(CONFIG_MVME16x)
  3418. mvme_bdid:
  3419. .long 0,0,0,0,0,0,0,0
  3420. #endif
  3421. #if defined(CONFIG_Q40)
  3422. q40_mem_cptr:
  3423. .long 0
  3424. L(q40_do_debug):
  3425. .long 0
  3426. #endif