head.S 88 KB

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