head.S 89 KB

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