>BBBB 7 $Id: BBBB,fd1,v 1.3 2000/02/18 22:10:19 ben Exp $  / Copyright (c) 1998, 1999, 2000 Ben Harris  All rights reserved.  H Redistribution and use in source and binary forms, with or without H modification, are permitted provided that the following conditions  are met: G 1. Redistributions of source code must retain the above copyright F notice, this list of conditions and the following disclaimer. J 2. Redistributions in binary form must reproduce the above copyright L notice, this list of conditions and the following disclaimer in the M documentation and/or other materials provided with the distribution. N 3. The name of the author may not be used to endorse or promote products N derived from this software without specific prior written permission.  J THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR O IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES M OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. F IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, N INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT O NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, K DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY I THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT N (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF G THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  O This file is part of NetBSD/arm26 -- a port of NetBSD to ARM2/3 machines.  ( Ben's BASIC BSD Booter (allegedly) debug% = 0 ! ">> BBBB, Revision 0.21" "+ș "OS_ReadMemMapInfo" nbpp%, npages% # debug% $E "Machine has ";npages%;" pages of ";nbpp% 1024;"K each. "; %8 "Total RAM: ";npages% * nbpp% 1024 1024;"Mb" & "Lowering HIMEM: &";~; ' ( = &10000 ) debug% " -> &";~ * +twirl% = 0 , -= vaddr%(npages%-1), access%(npages%-1), pgok%(npages%-1) .pgok%() = / 0get_mem_map 1ș "OS_GetEnv" A$ 2 debug% A$ 32ȕ A$, 1) <> " " (A$) > 0 A$ = A$, 2) : 4%ȕ A$, 1) = " " A$ = A$, 2) : 5!ȕ A$,1) = " " A$ = A$) : 6# tolower(A$, 5)) = "-quit" 7 A$ = A$, 7) 84 ȕ A$, 1) <> " " (A$) > 0 A$ = A$, 2) : 9' ȕ A$, 1) = " " A$ = A$, 2) : : ;file$ = "" <howto% = 0 =ȕ (A$) > 0 > Ȏ A$, 1) ? "-" @ done% = A B A$ = A$, 2) C" Ȏ tolower(A$, 1)) D: "a" : howto% = howto% &01 : RB_ASKNAME E9 "s" : howto% = howto% &02 : RB_SINGLE F6 "d" : howto% = howto% &40 : RB_KDB G# " ", "" : done% = H1  : 0, "Bad option: " + A$, 1) I J done% K " " L A$ = A$, 2) M  N2 file$ <> "" 0, "Too many files!" O' ȕ A$, 1) <> " " (A$) > 0 P file$ += A$,1) Q A$ = A$, 2) R S T U# file$ = "" (howto% &01) V "boot: "file$ W X% file$ = "" file$ = "netbsd" Y Z5 "Booting "; file$; " (howto = 0x"; ~howto%; ")" [load_kernel(file$) \ config% 1023 ]2 struct bootconfig { ^config%!0 = &942B7DFE _config%!4 = 0 `5config%!8 = howto% : u_int32_t boothowto a3config%!12 = 0 : u_int32_t bootdev b0config%!16 = 0 : u_int32_t ssym c/config%!20 = 0 : u_int32_t esym d/config%!24 = nbpp% : u_int32_t nbpp e1config%!28 = npages% : u_int32_t npages f%config%!32 = txtbasepage% * nbpp% gconfig%!36 = txtsize% h&config%!40 = databasepage% * nbpp% iconfig%!44 = datasize% j%config%!48 = bssbasepage% * nbpp% kconfig%!52 = bsssize% l0config%!56 = bssbasepage% * nbpp% + bsssize% m!config%!60 = vdu_var(11) + 1 n!config%!64 = vdu_var(12) + 1 o!config%!68 = 1 << vdu_var(9) pCconfig%!72 = vdu_var(149) + vdu_var(150) - &02000000 : XXX? qconfig%!76 = vdu_var(150) rș "OS_Byte", 165 ,,crow% s&config%!80 = crow% * vdu_var(170) t u! }; v+start_kernel(config%, 0, 0, 0, entry%) w x y get_mem_map z block% { block% (npages%+1)*12 | page%=0 npages%-1 }! block%!(page%*12) = page% ~  block%!(npages%*12) = -1 ' ș "OS_ReadMemMapEntries", block%  page% = 0 npages%-1 + vaddr%(page%) = block%!(page%*12+4) , access%(page%) = block%!(page%*12+8)  5 debug% "--------/-------/-------/-------"  page%=0 npages%-1  access%(page%) = 3  debug% ".";  Ȏ 9 vaddr%(page%) < &0008000: debug% "0"; 9 vaddr%(page%) < &0010000: debug% "+"; ' vaddr%(page%) < &1000000: $ access%(page%) = 0 ! debug% "*"; pgok%(page%) =  " debug% "a";  9 vaddr%(page%) < &1400000: debug% "d"; 9 vaddr%(page%) < &1800000: debug% "s"; 9 vaddr%(page%) < &1C00000: debug% "m"; 9 vaddr%(page%) < &1E00000: debug% "h"; 9 vaddr%(page%) < &1F00000: debug% "f"; 9 vaddr%(page%) < &2000000: debug% "S"; & page% 32 = 31 debug%     load_kernel(file$) hdr%  hdr% 32  file% = (file$) ) ș "OS_GBPB", 3, file%, hdr%, 32, 0 F magic% = (hdr%?0 << 24) (hdr%?1 <<16) (hdr%?2 << 8) hdr%?3  debug%  Ȏ magic% &0000FFFF  &0107  "(OMAGIC)";  &0108  "(NMAGIC)";  &010B  "(ZMAGIC)";  &00CC  "(QMAGIC)";   XXX: Assume ZMAGIC  J foooff% is byte offset in file. foobasepage% is base page in RAM.  txtoff% = nbpp% % txtbasepage% = (&98000) nbpp%  txtsize% = hdr%!4  txtsize% nbpp% <> 0 6 1, "Text size not a multiple of page size"  " txtpages% = txtsize% nbpp% # dataoff% = txtoff% + txtsize% . databasepage% = txtbasepage% + txtpages%  datasize% = hdr%!8 datasize% nbpp% <> 0 6 1, "Data size not a multiple of page size"  $ datapages% = datasize% nbpp% / bssbasepage% = databasepage% + datapages%  bsssize% = hdr%!12  entry% = hdr%!20   ;txtsize%;  pg% = 0 txtpages%-1 < pgok%(txtbasepage% + pg%) 0,"Page not mine!" T ș "OS_GBPB", 3, file%, vaddr%(txtbasepage%+pg%), nbpp%, txtoff% + pg%*nbpp%  twirl    "+";datasize%;  pg% = 0 datapages%-1 = pgok%(databasepage% + pg%) 0,"Page not mine!" V ș "OS_GBPB", 3, file%, vaddr%(databasepage%+pg%), nbpp%, dataoff% + pg%*nbpp%  twirl    "+";bsssize%; 8 pg% = 0 bsssize% nbpp% : overshoot is safe < pgok%(bssbasepage% + pg%) 0,"Page not mine!" / bzero(vaddr%(bssbasepage%+pg%), nbpp%)  twirl   " "    twirl # "|/-\", twirl%+1, 1)+(8);  twirl% += 1  twirl% = twirl% 4    tolower(string$)  ptr%, c%, out$  out$ = ""  string$ = "" =string$  ptr% = 1 (string$) " c% = (string$, ptr%, 1)) 0 c% >= ("A") c% <= ("Z") c% += 32  out$ += (c%)  =out$   bzero(addr%, len%) a%  a% = 0 len%-4 4  addr%!a% = 0    ' start_kernel(A%, B%, C%, D%, E%)  parameters: # R0: -> bootconfig structure  R1: unused  R2: unused  R3: unused  R4: kernel entry point  asm%, P%  asm% 256  pass% = 0 2 2  P%=asm%  [ OPT pass%  STMFD R13!,{R14}  STMFD R13!,{R0-R4}  ] ' swi_valid("Cache_Control")  [ OPT pass%   MOV R0, 1  ' MVN R1, 1 ; Disable cache  ! SWI "Cache_Control"   SWI "Cache_Flush"  ]   [ OPT pass%  MOV R0, #1  SWI "Sound_Enable"  SWI "OS_IntOff"  LDMFD R13!, {R0-R4}  SWI "OS_EnterOS" G ; We now attempt to be APCS compliant on entry to the kernel. @ ; Kernel APCS is 26bit/explicit/nofpregs/non-reentrant M ; Kernel stack is &02090000--&02088000 and coincides with RISC OS's 0 ; system stack page on >=4Mb machines.  ADR R5, regs%  LDMIA R5, {R10-R14}  MOV PC, R4  .regs% / EQUD &02088000; R10 -- Stack limit E EQUD &00000000; R11 -- Frame pointer (NULL in this case) B EQUD &00000000; R12 -- Scratch in non-re-entrant APCS  1 EQUD &02090000; R13 -- Stack pointer !; EQUD &03800003; R14 -- Return address and mode " ] # $ asm% % & ' swi_valid(swi$) ( flags% )2 ș "XOS_SWINumberFromString",,swi$ ;flags% * flags% 1 = += , - vdu_var(var%) . b% / b% 7 0 b%!0 = var% 1 b%!4 = -1 2& ș "OS_ReadVduVariables", b%, b% 3 = b%!0