2 | author: chapuni(webmaster@chapuni.com)
3 | Yasha(itohy@NetBSD.org)
5 | $NetBSD: boot.S,v 1.7 2005/12/11 12:19:44 christos Exp $
7 #include <machine/asm.h>
10 #define BASEOFF 0x8000
11 #define BASEPTR_A (TEXTADDR+BASEOFF)
12 #define BASEPTR_R %pc@(top+BASEOFF:W)
14 #define SRAM 0x00ED0000 /* SRAM stat addr */
15 #define SRAM_MEMSZ (SRAM + 8) /* (L) size of main memory */
16 #define MINMEM 0x00400000 /* at least 4MB required */
18 #define BOOT_ERROR(s) jbsr boot_error; .asciz s; .even
20 .globl _C_LABEL(bootufs)
22 ASENTRY_NOPROFILE(start)
23 ASENTRY_NOPROFILE(top)
24 bras _ASM_LABEL(entry0)
27 .word 0x8199,0x94e6,0x82ea,0x82bd
28 .word 0x8e9e,0x82c9,0x82cd,0x8cbb
29 .word 0x8ec0,0x93a6,0x94f0,0x8149
31 | 0x2000 (FD), 0x2400 (SASI/SCSI) (¤â¤·¤¯¤Ï 0x0f0000)
32 | d4 ¤Ë¤Ï¤¹¤Ç¤Ë SCSI ID ¤¬Æþ¤Ã¤Æ¤¤¤ë
33 | ¤³¤³¤«¤é jmp ¤Þ¤Ç¤Ï¥ê¥í¥±¡¼¥¿¥Ö¥ë¤Ë½ñ¤«¤Í¤Ð¤Ê¤é¤Ê¤¤¡£
34 ASENTRY_NOPROFILE(entry0)
35 moveml %d0-%d7/%a0-%a7,_C_LABEL(startregs)
36 lea BASEPTR_A:l,%a5 | set base ptr
37 #define _RELOC(adr) %a5@(((adr)-(BASEPTR_A&0xffff)):W)
38 #define ASRELOC(var) _RELOC(_ASM_LABEL(var))
39 #define RELOC(var) _RELOC(_C_LABEL(var))
45 | Since LABELLOFFSET in <machine/disklabel.h> is 0x40,
46 | entry must be after 0x000001d4 (0x000f01d4)
51 ASENTRY_NOPROFILE(entry)
52 movew #_end-1,%d0 | bss end (low word only)
54 | clear out bss (must be <= 64KB)
59 movel %d4,RELOC(ID) | SCSI ID (if booted from SCSI)
62 lea ASRELOC(top),%a1 | set stack pointer to 0x000F0000
63 lea %a1@,%sp | a1 will be used later for IOCS calls
65 | we use 68020 instructions, and check MPU beforehand
67 | here d1.w = -1, and the above "subw a1,d0" = 0x9049, and
68 | if MPU <= 010 loads 0x49,
69 | if MPU >= 020 loads 0x90.
70 | This is a move, not a tst instruction
71 | because pc-relative tsts are not availble on 000/010.
72 chkmpu: moveb %pc@(clrbss-chkmpu-2:B,%d0:W:2),%d0 | 103B 02xx
73 jmi mpuok | MC68020 or later
74 BOOT_ERROR("MPU 68000?")
75 mpuok: | XXX check for MMU?
78 lsll #8,%d0 | clear MSByte
80 movel %d0,RELOC(BOOT_INFO)
85 | 0xED0000...0xED3FFE SRAM
98 jne boot_dev_unsupported | boot from SASI?
103 andib #0x03,%d0 | drive # (head=0)
105 moveml %d0-%d1,RELOC(FDSECMINMAX) | min and max sec #
108 orw %d2,%d1 | PDA*256 + MODE
109 movel %d1,RELOC(FDMODE)
110 movel %d0,%d2 | read position (first sector)
111 movel #8192,%d3 | read bytes
124 boot_dev_unsupported:
125 BOOT_ERROR("unsupported boot device")
128 | volatile void BOOT_ERROR(const char *msg);
129 | print error message, wait for key press and reboot
131 booterr_msg: .ascii "\r\n\n"
134 reboot_msg: .asciz "\r\n[Hit key to reboot]"
137 ENTRY_NOPROFILE(BOOT_ERROR)
140 boot_error: lea %pc@(booterr_msg),%a1
144 lea %pc@(reboot_msg),%a1
147 | wait for a key press (or release of a modifier)
150 | issue software reset
156 | ROM boot ... probably from SCSI
159 #ifdef SCSI_ADHOC_BOOTPART
161 | Find out boot partition in an ad hoc manner.
164 | get block length of the SCSI disk
165 SCSIIOCS(__S_READCAP) | using buffer at a1
168 BOOT_ERROR("READCAP failed")
170 moveb %a1@(6),%d5 | 1: 256, 2: 512, 4: 1024
171 lsrb #1,%d5 | 0: 256, 1: 512, 2: 1024
172 movel %d5,RELOC(SCSI_BLKLEN)
174 | find out the start position of the boot partition
178 | pass read pos (in block #) in d2
179 | Human68k-style partition table does not exist
180 | d2 is 4 at the maximum
181 | SCSI IPLs (genuine and SxSI):
182 | pass read pos (in kilobytes) in d2
183 | d2 is bigger than 0x20
184 | partition table on the memory is destroyed
185 | BOOT MENU Ver.2.22:
186 | passes partition table entry address in a0
187 | d2 is cleared to zero
188 | No other IPL is supported. XXX FIXME
191 | no information in d2 -- probably from BOOT MENU
192 | a0 points the partiion table entry
193 movel %a0@(0x0008),%d2 | in KByte
196 lsll #8,%d2 | clear MSByte
198 lsrl %d5,%d2 | in sector
201 moveq #8192/256,%d3 | size is 8KB
202 lsrl %d5,%d3 | in sector
203 jbsr scsiread | read at %a1
208 sc3: movel %d2,RELOC(SCSI_PARTTOP)
210 moveq #1,%d5 | 512bytes/sec
212 moveq #8192/512,%d3 | Æɤ߹þ¤á¤ëºÇÂ祵¥¤¥º
213 moveq #0x40,%d2 | ¤¤¤ï¤æ¤ë·è¤áÂǤÁ(sd*a ¤Î¤ß)
220 read_error: BOOT_ERROR("read error")
222 #undef RELOC /* base register a5 is no longer available */
229 | input: d2.l: pos in sector
230 | d3.l: len in sector
232 | d5: sector length (0: 256, 1: 512, 2: 1024)
238 moveml %d2-%d3/%d6-%d7/%a2,%sp@-
239 | if (pos >= 0x200000 || (len > 255 && pos + len >= 0x200000))
244 swap %d0 | d0.l = 0x00200000
246 subqb #1,%d6 | d6.l = 255
248 addb %d5,%d7 | d7.b = (sector length: 0-2) + 8
254 subl %d2,%d0 | d0.0 = 0x200000 - pos
255 cmpl %d0,%d3 | <= len
256 jcs scsiread_noext | no
258 scsiread_ext: | use READEXT
259 extw %d6 | d6.l = 65535
260 moveq #__S_READEXT,%d1
262 scsiread_noext: | use READ
264 | d1: SCSI IOCS call #
265 | d6: max sector count at a time
266 movel %d3,%a2 | save original len in a2
270 1: IOCS(__SCSIDRV) | SCSIIOCS(d1)
273 movel %d3,%d0 | addr += read count << (8 + sec len)
276 exg %d3,%a2 | restore original len to d3
277 addl %a2,%d2 | pos += read count
278 subl %a2,%d3 | len -= read count
280 moveml %sp@+,%d2-%d3/%d6-%d7/%a2
284 | The former part must reside in the first 1KB.
288 |--------------------------------------------------------------------------
290 | The latter text+data part is not accessible at the first boot time.
291 | PC-relative can be used from here.
293 jmp _C_LABEL(bootufs) | 0x0Fxxxx ¤ËÈô¤ó¤Ç¤æ¤¯
297 | int badbaddr __P((void *adr));
298 | check if the given address is valid for byte read
299 | return: 0: valid, 1: not valid
301 ENTRY_NOPROFILE(badbaddr)
302 lea 0x0008:W,%a1 | MPU Bus Error vector
306 oriw #0x0700,%sr | keep out interrupts
308 movel %a0,%a1@ | set bus error vector
309 movel %sp,%d1 | save sp
311 tstb %a0@ | try read...
312 moveq #0,%d0 | this is skipped on bus error
313 badr1: moveal %d1,%sp | restore sp
318 | void RAW_READ __P((void *buf, u_int32_t blkpos, size_t bytelen));
320 | buf: input buffer address
321 | blkpos: read start position in the partition in 512byte-blocks
322 | bytelen: read length in bytes
324 Lraw_read_buf=4+(4*11)
325 Lraw_read_pos_=Lraw_read_buf+4
326 Lraw_read_len=Lraw_read_buf+8
328 #ifdef SCSI_ADHOC_BOOTPART
329 | RAW_READ of physical disk
330 ENTRY_NOPROFILE(RAW_READ0)
335 ENTRY_NOPROFILE(RAW_READ)
336 #ifdef SCSI_ADHOC_BOOTPART
337 movel _C_LABEL(SCSI_PARTTOP),%d0
340 moveml %d2-%d7/%a2-%a6,%sp@-
341 moveml %sp@(Lraw_read_buf),%d1-%d3
343 | d2.l: pos in 512byte-blocks
344 | d3.l: length in bytes
345 | a1 (=d1): buffer address
347 lea BASEPTR_R,%a5 | set base ptr
348 #define _RELOC(adr) %a5@(((adr)-(BASEPTR_A&0xffff)):W)
349 #define ASRELOC(var) _RELOC(_ASM_LABEL(var))
350 #define RELOC(var) _RELOC(_C_LABEL(var))
352 tstb _RELOC(_C_LABEL(BOOT_INFO)+1) | simple check. may be incorrect!
356 movel RELOC(ID),%d4 | SCSI ID
357 #ifdef SCSI_ADHOC_BOOTPART
358 movel RELOC(SCSI_BLKLEN),%d5 | sector size: 0-2
359 | XXX length must be sector aligned
360 lsrl #8,%d3 | size in 256byte-blocks
361 lsrl %d5,%d3 | size in sector
362 bcss read_half | minimal error check
363 lsll #1,%d2 | X flag and d2: pos in 256byte-blocks
364 roxrl %d5,%d2 | pos in sector
365 addl %d0,%d2 | physical pos in sector
367 moveq #1,%d5 | 512bytes/sec
368 moveq #9,%d0 | shift count
371 bcss read_half | minimal error check
373 addl #0x40,%d2 | 'a' partition starts here
376 | BOOT_ERROR("out of seek") | pos exceeds 32bit
383 | Floppy read routine
386 | convert to seek position
388 asll #2,%d2 | size in 128byte-blocks
390 | sec = raw_read_pos (d2)
391 | sec >>= 7 + (sector length: 0-3)
393 lea RELOC(FDSECMINMAX),%a0
395 moveb %a0@,%d1 | d1: sector length (0-3)
396 lsrl %d1,%d2 | d2: pos in sector
397 bcss read_half | error check
399 | trk = sec / (# sectors)
400 | sec = sec % (# sectors)
402 moveb %a0@(7),%d1 | d1: max sector #
403 subb %a0@(3),%d1 | - min sector #
404 addqb #1,%d1 | d1: # sectors
405 divu %d1,%d2 | d2: (sec << 16) | track
407 | position = (sec length << 24) | (track/2 << 16)
408 | | (track%2 << 8) | (min sec # + sec)
410 movel %a0@,%d0 | d0: (sec len << 24) | min sec #
411 lsrw #1,%d2 | d2: (sec << 16) | (track / 2)
413 bset #8,%d0 | |= (track % 2) << 8
414 1: swap %d2 | d2: ((track / 2) << 16) | sec
415 addl %d0,%d2 | d2: position
418 movel RELOC(FDMODE),%d1 | PDA*256 + MODE
420 | B_READ (for floppy)
421 | d1.w: PDA x 256 + MODE
422 | PDA: 0x90 (drive 0) ... 0x93 (drive 3)
427 | bit31-24: sector length (0: 128, 1: 256, 2: 512, 3: 1K)
428 | bit23-16: track # (0-79)
429 | bit15-08: side (0 or 1)
430 | bit07-00: sector # (1-)
438 | -1 on parameter error
439 | destroy: d0, d2, d3, a1
441 andil #0xf8ffff00,%d0 | check status (must be zero)
445 moveml %sp@+,%a2-%a6/%d2-%d7
447 #undef _RELOC /* base register a5 is no longer available */
451 read_half: BOOT_ERROR("read half of block")
454 ENTRY_NOPROFILE(B_KEYINP)
458 ENTRY_NOPROFILE(B_PUTC)
463 ENTRY_NOPROFILE(B_PRINT)
469 | void memcpy(void *dst, const void *src, size_t count);
470 | void memmove(void *dst, const void *src, size_t count);
472 | small and slow memcpy...
473 | THIS FUNCTION DOES NOT CONFORM THE ANSI STANDARD
475 ENTRY_NOPROFILE(memcpy)
476 ENTRY_NOPROFILE(memmove)
478 movel %a1@,%d1 | count
480 moveal %a1@-,%a0 | src
481 moveal %a1@-,%a1 | dest
491 Lmcpfw: | copy forward
496 | movel %sp@(8),%d0 | uncomment this to conform ANSI
504 BSS(BOOT_INFO, 4) | result of IOCS(__BOOTINF)
505 BSS(FDMODE, 4) | Floppy access mode: PDA x 256 + MODE
506 BSS(FDSECMINMAX, 8) | +0: (min sector) sector length
507 | +1: (min sector) track #
508 | +2: (min sector) side
509 | +3: (min sector) sector #
510 | +4: (max sector) sector length
511 | +5: (max sector) track #
512 | +6: (max sector) side
513 | +7: (max sector) sector #
514 #ifdef SCSI_ADHOC_BOOTPART
515 BSS(SCSI_PARTTOP, 4) | start sector of boot partition
516 BSS(SCSI_BLKLEN ,4) | sector len 0: 256, 1: 512, 2: 1024