boot.S revision 1.3.4.2       1  1.3.4.2  nathanw | file: boot.S
      2  1.3.4.2  nathanw | author: chapuni(webmaster@chapuni.com)
      3  1.3.4.2  nathanw |         Yasha(itohy@netbsd.org)
      4  1.3.4.2  nathanw |
      5  1.3.4.2  nathanw | $NetBSD: boot.S,v 1.3.4.2 2002/01/08 00:28:45 nathanw Exp $
      6  1.3.4.2  nathanw 
      7  1.3.4.2  nathanw #include <machine/asm.h>
      8  1.3.4.2  nathanw #include "iocscall.h"
      9  1.3.4.2  nathanw 
     10  1.3.4.2  nathanw #define BASEOFF		0x8000
     11  1.3.4.2  nathanw #define BASEPTR_A	(TEXTADDR+BASEOFF)
     12  1.3.4.2  nathanw #define BASEPTR_R	%pc@(top+BASEOFF:W)
     13  1.3.4.2  nathanw 
     14  1.3.4.2  nathanw #define SRAM		0x00ED0000	/* SRAM stat addr */
     15  1.3.4.2  nathanw #define SRAM_MEMSZ	(SRAM + 8)	/* (L) size of main memory */
     16  1.3.4.2  nathanw #define MINMEM		0x00400000	/* at least 4MB required */
     17  1.3.4.2  nathanw 
     18  1.3.4.2  nathanw #define BOOT_ERROR(s)	jbsr boot_error; .asciz s; .even
     19  1.3.4.2  nathanw 
     20  1.3.4.2  nathanw 	.globl	_C_LABEL(bootufs)
     21  1.3.4.2  nathanw 	.text
     22  1.3.4.2  nathanw ASENTRY_NOPROFILE(start)
     23  1.3.4.2  nathanw ASENTRY_NOPROFILE(top)
     24  1.3.4.2  nathanw 		bras	_ASM_LABEL(entry0)
     25  1.3.4.2  nathanw 		.ascii	"SHARP/"
     26  1.3.4.2  nathanw 		.ascii	"X680x0"
     27  1.3.4.2  nathanw 		.word	0x8199,0x94e6,0x82ea,0x82bd
     28  1.3.4.2  nathanw 		.word	0x8e9e,0x82c9,0x82cd,0x8cbb
     29  1.3.4.2  nathanw 		.word	0x8ec0,0x93a6,0x94f0,0x8149
     30  1.3.4.2  nathanw 		.word	0
     31  1.3.4.2  nathanw | 0x2000 (FD), 0x2400 (SASI/SCSI) ( 0x0f0000)
     32  1.3.4.2  nathanw | d4  SCSI ID 
     33  1.3.4.2  nathanw |  jmp 
     34  1.3.4.2  nathanw ASENTRY_NOPROFILE(entry0)
     35  1.3.4.2  nathanw 		moveml	%d0-%d7/%a0-%a7,_C_LABEL(startregs)
     36  1.3.4.2  nathanw 		lea	BASEPTR_A:l,%a5		| set base ptr
     37  1.3.4.2  nathanw #define _RELOC(adr)	%a5@(((adr)-(BASEPTR_A&0xffff)):W)
     38  1.3.4.2  nathanw #define ASRELOC(var)	_RELOC(_ASM_LABEL(var))
     39  1.3.4.2  nathanw #define RELOC(var)	_RELOC(_C_LABEL(var))
     40  1.3.4.2  nathanw 
     41  1.3.4.2  nathanw 		lea	RELOC(edata),%a1
     42  1.3.4.2  nathanw 		bra	_ASM_LABEL(entry)
     43  1.3.4.2  nathanw 
     44  1.3.4.2  nathanw |	Disklabel= 404bytes
     45  1.3.4.2  nathanw |	Since LABELLOFFSET in <machine/disklabel.h> is 0x40,
     46  1.3.4.2  nathanw |	entry must be after 0x000001d4 (0x000f01d4)
     47  1.3.4.2  nathanw disklabel:
     48  1.3.4.2  nathanw 		.space	406
     49  1.3.4.2  nathanw 
     50  1.3.4.2  nathanw ASENTRY_NOPROFILE(entry)
     51  1.3.4.2  nathanw 		movew	#_end-1,%d0	| bss end (low word only)
     52  1.3.4.2  nathanw 
     53  1.3.4.2  nathanw 		| clear out bss  (must be <= 64KB)
     54  1.3.4.2  nathanw 		subw	%a1,%d0
     55  1.3.4.2  nathanw clrbss:		clrb	%a1@+
     56  1.3.4.2  nathanw 		dbra	%d0,clrbss
     57  1.3.4.2  nathanw 
     58  1.3.4.2  nathanw 		movel	%d4,RELOC(ID)	| SCSI ID (if booted from SCSI)
     59  1.3.4.2  nathanw 
     60  1.3.4.2  nathanw 		| set system stack
     61  1.3.4.2  nathanw 		lea	ASRELOC(top),%a1 | set stack pointer to 0x000F0000
     62  1.3.4.2  nathanw 		lea	%a1@,%sp	| a1 will be used later for IOCS calls
     63  1.3.4.2  nathanw 
     64  1.3.4.2  nathanw 		| we use 68020 instructions, and check MPU beforehand
     65  1.3.4.2  nathanw 		|
     66  1.3.4.2  nathanw 		| here d1.w = -1, and the above "subw a1,d0" = 0x9049, and
     67  1.3.4.2  nathanw 		|	if MPU <= 010	loads 0x49,
     68  1.3.4.2  nathanw 		|	if MPU >= 020	loads 0x90.
     69  1.3.4.2  nathanw 		| This is a move, not a tst instruction
     70  1.3.4.2  nathanw 		| because pc-relative tsts are not availble on 000/010.
     71  1.3.4.2  nathanw chkmpu:		moveb	%pc@(clrbss-chkmpu-2:B,%d0:W:2),%d0	| 103B 02xx
     72  1.3.4.2  nathanw 		jmi	mpuok		| MC68020 or later
     73  1.3.4.2  nathanw 		BOOT_ERROR("MPU 68000?")
     74  1.3.4.2  nathanw mpuok:		| XXX check for MMU?
     75  1.3.4.2  nathanw 
     76  1.3.4.2  nathanw 		IOCS(__BOOTINF)
     77  1.3.4.2  nathanw 		lsll	#8,%d0		| clear MSByte
     78  1.3.4.2  nathanw 		lsrl	#8,%d0		|
     79  1.3.4.2  nathanw 		movel	%d0,RELOC(BOOT_INFO)
     80  1.3.4.2  nathanw 
     81  1.3.4.2  nathanw 		|
     82  1.3.4.2  nathanw 		| 0x80...0x8F		SASI
     83  1.3.4.2  nathanw 		| 0x90...0x93		Floppy
     84  1.3.4.2  nathanw 		| 0xED0000...0xED3FFE	SRAM
     85  1.3.4.2  nathanw 		| others		ROM (SCSI?)
     86  1.3.4.2  nathanw 		|
     87  1.3.4.2  nathanw 		movel	%d0,%d1
     88  1.3.4.2  nathanw 		clrb	%d1
     89  1.3.4.2  nathanw 		tstl	%d1
     90  1.3.4.2  nathanw 		jne	boot_ram_rom
     91  1.3.4.2  nathanw 		|
     92  1.3.4.2  nathanw 		| SASI or Floppy
     93  1.3.4.2  nathanw 		|
     94  1.3.4.2  nathanw 		movel	%d0,%d2
     95  1.3.4.2  nathanw 		andib	#0xFC,%d0
     96  1.3.4.2  nathanw 		cmpib	#0x90,%d0
     97  1.3.4.2  nathanw 		jne	boot_dev_unsupported	| boot from SASI?
     98  1.3.4.2  nathanw 		|
     99  1.3.4.2  nathanw 		| Floppy
    100  1.3.4.2  nathanw 		|
    101  1.3.4.2  nathanw 		moveb	%d2,%d0
    102  1.3.4.2  nathanw 		andib	#0x03,%d0		| drive # (head=0)
    103  1.3.4.2  nathanw 		jbsr	check_fd_format
    104  1.3.4.2  nathanw 		moveml	%d0-%d1,RELOC(FDSECMINMAX) | min and max sec #
    105  1.3.4.2  nathanw 		lslw	#8,%d2
    106  1.3.4.2  nathanw 		moveq	#0x70,%d1
    107  1.3.4.2  nathanw 		orw	%d2,%d1		| PDA*256 + MODE
    108  1.3.4.2  nathanw 		movel	%d1,RELOC(FDMODE)
    109  1.3.4.2  nathanw 		movel	%d0,%d2		| read position (first sector)
    110  1.3.4.2  nathanw 		movel	#8192,%d3	| read bytes
    111  1.3.4.2  nathanw 		IOCS(__B_READ)
    112  1.3.4.2  nathanw 		jra	boot_read_done
    113  1.3.4.2  nathanw 
    114  1.3.4.2  nathanw #include "chkfmt.s"
    115  1.3.4.2  nathanw 
    116  1.3.4.2  nathanw boot_ram_rom:
    117  1.3.4.2  nathanw 		movel	%d0,%d1
    118  1.3.4.2  nathanw 		swap	%d1
    119  1.3.4.2  nathanw 		cmpiw	#0x00ED,%d1
    120  1.3.4.2  nathanw 		jne	boot_SCSI
    121  1.3.4.2  nathanw 		| boot from SRAM?
    122  1.3.4.2  nathanw 
    123  1.3.4.2  nathanw boot_dev_unsupported:
    124  1.3.4.2  nathanw 		BOOT_ERROR("unsupported boot device")
    125  1.3.4.2  nathanw 
    126  1.3.4.2  nathanw |
    127  1.3.4.2  nathanw | volatile void BOOT_ERROR(const char *msg);
    128  1.3.4.2  nathanw |	print error message, wait for key press and reboot
    129  1.3.4.2  nathanw |
    130  1.3.4.2  nathanw booterr_msg:	.ascii	"\r\n\n"
    131  1.3.4.2  nathanw 		.ascii	BOOT
    132  1.3.4.2  nathanw 		.asciz	": "
    133  1.3.4.2  nathanw reboot_msg:	.asciz	"\r\n[Hit key to reboot]"
    134  1.3.4.2  nathanw 		.even
    135  1.3.4.2  nathanw 
    136  1.3.4.2  nathanw ENTRY_NOPROFILE(BOOT_ERROR)
    137  1.3.4.2  nathanw 		addql	#4,%sp
    138  1.3.4.2  nathanw 
    139  1.3.4.2  nathanw boot_error:	lea	%pc@(booterr_msg),%a1
    140  1.3.4.2  nathanw 		IOCS(__B_PRINT)
    141  1.3.4.2  nathanw 		moveal	%sp@+,%a1
    142  1.3.4.2  nathanw 		IOCS(__B_PRINT)
    143  1.3.4.2  nathanw 		lea	%pc@(reboot_msg),%a1
    144  1.3.4.2  nathanw 		IOCS(__B_PRINT)
    145  1.3.4.2  nathanw 
    146  1.3.4.2  nathanw 		| wait for a key press (or release of a modifier)
    147  1.3.4.2  nathanw 		IOCS(__B_KEYINP)
    148  1.3.4.2  nathanw 
    149  1.3.4.2  nathanw 		| issue software reset
    150  1.3.4.2  nathanw 		trap	#10
    151  1.3.4.2  nathanw 		| NOTREACHED
    152  1.3.4.2  nathanw 
    153  1.3.4.2  nathanw 
    154  1.3.4.2  nathanw 		|
    155  1.3.4.2  nathanw 		| ROM boot ... probably from SCSI
    156  1.3.4.2  nathanw 		|
    157  1.3.4.2  nathanw boot_SCSI:
    158  1.3.4.2  nathanw #ifdef SCSI_ADHOC_BOOTPART
    159  1.3.4.2  nathanw 		|
    160  1.3.4.2  nathanw 		| Find out boot partition in an ad hoc manner.
    161  1.3.4.2  nathanw 		|
    162  1.3.4.2  nathanw 
    163  1.3.4.2  nathanw 		| get block length of the SCSI disk
    164  1.3.4.2  nathanw 		SCSIIOCS(__S_READCAP)	| using buffer at a1
    165  1.3.4.2  nathanw 		tstl	%d0
    166  1.3.4.2  nathanw 		jeq	1f
    167  1.3.4.2  nathanw 		BOOT_ERROR("READCAP failed")
    168  1.3.4.2  nathanw 1:		moveq	#0,%d5
    169  1.3.4.2  nathanw 		moveb	%a1@(6),%d5	| 1: 256, 2: 512, 4: 1024
    170  1.3.4.2  nathanw 		lsrb	#1,%d5		| 0: 256, 1: 512, 2: 1024
    171  1.3.4.2  nathanw 		movel	%d5,RELOC(SCSI_BLKLEN)
    172  1.3.4.2  nathanw 
    173  1.3.4.2  nathanw 		| find out the start position of the boot partition
    174  1.3.4.2  nathanw 		| XXX VERY AD HOC
    175  1.3.4.2  nathanw 		|
    176  1.3.4.2  nathanw 		| ROM firmware:
    177  1.3.4.2  nathanw 		|	pass read pos (in block #) in d2
    178  1.3.4.2  nathanw 		|	Human68k-style partition table does not exist
    179  1.3.4.2  nathanw 		|	d2 is 4 at the maximum
    180  1.3.4.2  nathanw 		| SCSI IPLs (genuine and SxSI):
    181  1.3.4.2  nathanw 		|	pass read pos (in kilobytes) in d2
    182  1.3.4.2  nathanw 		|	d2 is bigger than 0x20
    183  1.3.4.2  nathanw 		|	partition table on the memory is destroyed
    184  1.3.4.2  nathanw 		| BOOT MENU Ver.2.22:
    185  1.3.4.2  nathanw 		|	passes partition table entry address in a0
    186  1.3.4.2  nathanw 		|	d2 is cleared to zero
    187  1.3.4.2  nathanw 		| No other IPL is supported.  XXX FIXME
    188  1.3.4.2  nathanw 		tstl	%d2
    189  1.3.4.2  nathanw 		jne	sc1
    190  1.3.4.2  nathanw 		| no information in d2 -- probably from BOOT MENU
    191  1.3.4.2  nathanw 		| a0 points the partiion table entry
    192  1.3.4.2  nathanw 		movel	%a0@(0x0008),%d2 | in KByte
    193  1.3.4.2  nathanw sc1:		cmpl	#0x20,%d2
    194  1.3.4.2  nathanw 		jcs	sc2
    195  1.3.4.2  nathanw 		lsll	#8,%d2		| clear MSByte
    196  1.3.4.2  nathanw 		lsrl	#6,%d2		|
    197  1.3.4.2  nathanw 		lsrl	%d5,%d2		| in sector
    198  1.3.4.2  nathanw sc2:
    199  1.3.4.2  nathanw 		| read entire boot
    200  1.3.4.2  nathanw 		moveq	#8192/256,%d3	| size is 8KB
    201  1.3.4.2  nathanw 		lsrl	%d5,%d3		| in sector
    202  1.3.4.2  nathanw 		jbsr	scsiread	| read at  %a1
    203  1.3.4.2  nathanw 
    204  1.3.4.2  nathanw 		cmpil	#5,%d2
    205  1.3.4.2  nathanw 		bcc	sc3
    206  1.3.4.2  nathanw 		movql	#0,%d2
    207  1.3.4.2  nathanw sc3:		movel	%d2,RELOC(SCSI_PARTTOP)
    208  1.3.4.2  nathanw #else
    209  1.3.4.2  nathanw 		moveq	#1,%d5		| 512bytes/sec
    210  1.3.4.2  nathanw 		movel	%d5,%sp@-
    211  1.3.4.2  nathanw 		moveq	#8192/512,%d3	| 
    212  1.3.4.2  nathanw 		moveq	#0x40,%d2	| (sd*a )
    213  1.3.4.2  nathanw 		SCSIIOCS(__S_READ)
    214  1.3.4.2  nathanw #endif
    215  1.3.4.2  nathanw 
    216  1.3.4.2  nathanw boot_read_done:
    217  1.3.4.2  nathanw 		jmp	first_kbyte
    218  1.3.4.2  nathanw 
    219  1.3.4.2  nathanw read_error:	BOOT_ERROR("read error")
    220  1.3.4.2  nathanw 
    221  1.3.4.2  nathanw #undef RELOC	/* base register  a5  is no longer available */
    222  1.3.4.2  nathanw #undef ASRELOC
    223  1.3.4.2  nathanw #undef _RELOC
    224  1.3.4.2  nathanw 
    225  1.3.4.2  nathanw |
    226  1.3.4.2  nathanw |	read SCSI
    227  1.3.4.2  nathanw |
    228  1.3.4.2  nathanw |	input:	d2.l: pos in sector
    229  1.3.4.2  nathanw |		d3.l: len in sector
    230  1.3.4.2  nathanw |		d4: target SCSI ID
    231  1.3.4.2  nathanw |		d5: sector length (0: 256, 1: 512, 2: 1024)
    232  1.3.4.2  nathanw |		a1: buffer address
    233  1.3.4.2  nathanw |	destroy:
    234  1.3.4.2  nathanw |		d0, d1, a1
    235  1.3.4.2  nathanw |
    236  1.3.4.2  nathanw scsiread:
    237  1.3.4.2  nathanw 		moveml	%d2-%d3/%d6-%d7/%a2,%sp@-
    238  1.3.4.2  nathanw 		| if (pos >= 0x200000 || (len > 255 && pos + len >= 0x200000))
    239  1.3.4.2  nathanw 		|	use READEXT
    240  1.3.4.2  nathanw 		| else
    241  1.3.4.2  nathanw 		|	use READ
    242  1.3.4.2  nathanw 		moveq	#0x20,%d0
    243  1.3.4.2  nathanw 		swap	%d0		| d0.l = 0x00200000
    244  1.3.4.2  nathanw 		moveq	#0,%d6
    245  1.3.4.2  nathanw 		subqb	#1,%d6		| d6.l = 255
    246  1.3.4.2  nathanw 		moveq	#8,%d7
    247  1.3.4.2  nathanw 		addb	%d5,%d7		| d7.b = (sector length: 0-2) + 8
    248  1.3.4.2  nathanw 		cmpl	%d0,%d2
    249  1.3.4.2  nathanw 		jcc	scsiread_ext
    250  1.3.4.2  nathanw 		moveq	#__S_READ,%d1
    251  1.3.4.2  nathanw 		cmpl	%d3,%d6
    252  1.3.4.2  nathanw 		jcc	scsiread_noext
    253  1.3.4.2  nathanw 		subl	%d2,%d0		| d0.0 = 0x200000 - pos
    254  1.3.4.2  nathanw 		cmpl	%d0,%d3		|	<= len
    255  1.3.4.2  nathanw 		jcs	scsiread_noext	| no
    256  1.3.4.2  nathanw 
    257  1.3.4.2  nathanw scsiread_ext:	| use READEXT
    258  1.3.4.2  nathanw 		extw	%d6		| d6.l = 65535
    259  1.3.4.2  nathanw 		moveq	#__S_READEXT,%d1
    260  1.3.4.2  nathanw 
    261  1.3.4.2  nathanw scsiread_noext:	| use READ
    262  1.3.4.2  nathanw loop_scsiread:
    263  1.3.4.2  nathanw 		| d1: SCSI IOCS call #
    264  1.3.4.2  nathanw 		| d6: max sector count at a time
    265  1.3.4.2  nathanw 		movel	%d3,%a2		| save original len in a2
    266  1.3.4.2  nathanw 		cmpl	%d3,%d6
    267  1.3.4.2  nathanw 		jcc	1f
    268  1.3.4.2  nathanw 		movel	%d6,%d3
    269  1.3.4.2  nathanw 1:		IOCS(__SCSIDRV)		| SCSIIOCS(d1)
    270  1.3.4.2  nathanw 		tstl	%d0
    271  1.3.4.2  nathanw 		jne	read_error
    272  1.3.4.2  nathanw 		movel	%d3,%d0		| addr += read count << (8 + sec len)
    273  1.3.4.2  nathanw 		asll	%d7,%d0
    274  1.3.4.2  nathanw 		addl	%d0,%a1
    275  1.3.4.2  nathanw 		exg	%d3,%a2		| restore original len to d3
    276  1.3.4.2  nathanw 		addl	%a2,%d2		| pos += read count
    277  1.3.4.2  nathanw 		subl	%a2,%d3		| len -= read count
    278  1.3.4.2  nathanw 		jne	loop_scsiread
    279  1.3.4.2  nathanw 		moveml	%sp@+,%d2-%d3/%d6-%d7/%a2
    280  1.3.4.2  nathanw 		rts
    281  1.3.4.2  nathanw 
    282  1.3.4.2  nathanw |
    283  1.3.4.2  nathanw |	The former part must reside in the first 1KB.
    284  1.3.4.2  nathanw |
    285  1.3.4.2  nathanw 		.globl	first_kbyte
    286  1.3.4.2  nathanw first_kbyte:
    287  1.3.4.2  nathanw |--------------------------------------------------------------------------
    288  1.3.4.2  nathanw |
    289  1.3.4.2  nathanw |	The latter text+data part is not accessible at the first boot time.
    290  1.3.4.2  nathanw |	PC-relative can be used from here.
    291  1.3.4.2  nathanw |
    292  1.3.4.2  nathanw 		jmp	_C_LABEL(bootufs)	| 0x0Fxxxx 
    293  1.3.4.2  nathanw 
    294  1.3.4.2  nathanw 		.word	0
    295  1.3.4.2  nathanw 
    296  1.3.4.2  nathanw | int badbaddr __P((caddr_t adr));
    297  1.3.4.2  nathanw |	check if the given address is valid for byte read
    298  1.3.4.2  nathanw |	return: 0: valid, 1: not valid
    299  1.3.4.2  nathanw 
    300  1.3.4.2  nathanw ENTRY_NOPROFILE(badbaddr)
    301  1.3.4.2  nathanw 		lea	0x0008:W,%a1		| MPU Bus Error vector
    302  1.3.4.2  nathanw 		moveq	#1,%d0
    303  1.3.4.2  nathanw 		lea	%pc@(badr1),%a0
    304  1.3.4.2  nathanw 		movew	%sr,%sp@-
    305  1.3.4.2  nathanw 		oriw	#0x0700,%sr		| keep out interrupts
    306  1.3.4.2  nathanw 		movel	%a1@,%sp@-
    307  1.3.4.2  nathanw 		movel	%a0,%a1@		| set bus error vector
    308  1.3.4.2  nathanw 		movel	%sp,%d1			| save sp
    309  1.3.4.2  nathanw 		moveal	%sp@(10),%a0
    310  1.3.4.2  nathanw 		tstb	%a0@			| try read...
    311  1.3.4.2  nathanw 		moveq	#0,%d0			| this is skipped on bus error
    312  1.3.4.2  nathanw badr1:		moveal	%d1,%sp			| restore sp
    313  1.3.4.2  nathanw 		movel	%sp@+,%a1@
    314  1.3.4.2  nathanw 		movew	%sp@+,%sr
    315  1.3.4.2  nathanw 		rts
    316  1.3.4.2  nathanw 
    317  1.3.4.2  nathanw | void RAW_READ __P((void *buf, u_int32_t blkpos, size_t bytelen));
    318  1.3.4.2  nathanw | inputs:
    319  1.3.4.2  nathanw |	buf:	 input buffer address
    320  1.3.4.2  nathanw |	blkpos:	 read start position in the partition in 512byte-blocks
    321  1.3.4.2  nathanw |	bytelen: read length in bytes
    322  1.3.4.2  nathanw 
    323  1.3.4.2  nathanw Lraw_read_buf=4+(4*11)
    324  1.3.4.2  nathanw Lraw_read_pos_=Lraw_read_buf+4
    325  1.3.4.2  nathanw Lraw_read_len=Lraw_read_buf+8
    326  1.3.4.2  nathanw 
    327  1.3.4.2  nathanw #ifdef SCSI_ADHOC_BOOTPART
    328  1.3.4.2  nathanw |	RAW_READ of physical disk
    329  1.3.4.2  nathanw ENTRY_NOPROFILE(RAW_READ0)
    330  1.3.4.2  nathanw 		moveq	#0,%d0
    331  1.3.4.2  nathanw 		jra	raw_read1
    332  1.3.4.2  nathanw #endif
    333  1.3.4.2  nathanw 
    334  1.3.4.2  nathanw ENTRY_NOPROFILE(RAW_READ)
    335  1.3.4.2  nathanw #ifdef SCSI_ADHOC_BOOTPART
    336  1.3.4.2  nathanw 		movel	_C_LABEL(SCSI_PARTTOP),%d0
    337  1.3.4.2  nathanw raw_read1:
    338  1.3.4.2  nathanw #endif
    339  1.3.4.2  nathanw 		moveml	%d2-%d7/%a2-%a6,%sp@-
    340  1.3.4.2  nathanw 		moveml	%sp@(Lraw_read_buf),%d1-%d3
    341  1.3.4.2  nathanw 		movel	%d1,%a1
    342  1.3.4.2  nathanw 		| d2.l:		pos in 512byte-blocks
    343  1.3.4.2  nathanw 		| d3.l:		length in bytes
    344  1.3.4.2  nathanw 		| a1 (=d1):	buffer address
    345  1.3.4.2  nathanw 
    346  1.3.4.2  nathanw 		lea	BASEPTR_R,%a5	| set base ptr
    347  1.3.4.2  nathanw #define _RELOC(adr)	%a5@(((adr)-(BASEPTR_A&0xffff)):W)
    348  1.3.4.2  nathanw #define ASRELOC(var)	_RELOC(_ASM_LABEL(var))
    349  1.3.4.2  nathanw #define RELOC(var)	_RELOC(_C_LABEL(var))
    350  1.3.4.2  nathanw 
    351  1.3.4.2  nathanw 		tstb	_RELOC(_C_LABEL(BOOT_INFO)+1) | simple check.  may be incorrect!
    352  1.3.4.2  nathanw 		beqs	raw_read_floppy
    353  1.3.4.2  nathanw 
    354  1.3.4.2  nathanw raw_read_scsi:
    355  1.3.4.2  nathanw 		movel	RELOC(ID),%d4	| SCSI ID
    356  1.3.4.2  nathanw #ifdef SCSI_ADHOC_BOOTPART
    357  1.3.4.2  nathanw 		movel	RELOC(SCSI_BLKLEN),%d5 | sector size: 0-2
    358  1.3.4.2  nathanw 		| XXX length must be sector aligned
    359  1.3.4.2  nathanw 		lsrl	#8,%d3		| size in 256byte-blocks
    360  1.3.4.2  nathanw 		lsrl	%d5,%d3		| size in sector
    361  1.3.4.2  nathanw 		bcss	read_half	| minimal error check
    362  1.3.4.2  nathanw 		lsll	#1,%d2		| X flag and d2: pos in 256byte-blocks
    363  1.3.4.2  nathanw 		roxrl	%d5,%d2		| pos in sector
    364  1.3.4.2  nathanw 		addl	%d0,%d2		| physical pos in sector
    365  1.3.4.2  nathanw #else
    366  1.3.4.2  nathanw 		moveq	#1,%d5		| 512bytes/sec
    367  1.3.4.2  nathanw 		moveq	#9,%d0		| shift count
    368  1.3.4.2  nathanw 		addl	#511,%d3
    369  1.3.4.2  nathanw 		lsrl	%d0,%d3
    370  1.3.4.2  nathanw 		bcss	read_half	| minimal error check
    371  1.3.4.2  nathanw 
    372  1.3.4.2  nathanw 		addl	#0x40,%d2	| 'a' partition starts here
    373  1.3.4.2  nathanw #endif
    374  1.3.4.2  nathanw |		jcc	1f
    375  1.3.4.2  nathanw |		BOOT_ERROR("out of seek")	| pos exceeds 32bit
    376  1.3.4.2  nathanw |1:
    377  1.3.4.2  nathanw 		jbsr	scsiread
    378  1.3.4.2  nathanw 		bras	raw_read_end
    379  1.3.4.2  nathanw 
    380  1.3.4.2  nathanw raw_read_floppy:
    381  1.3.4.2  nathanw 		|
    382  1.3.4.2  nathanw 		| Floppy read routine
    383  1.3.4.2  nathanw 		|
    384  1.3.4.2  nathanw 
    385  1.3.4.2  nathanw 		| convert to seek position
    386  1.3.4.2  nathanw 
    387  1.3.4.2  nathanw 		asll	#2,%d2		| size in 128byte-blocks
    388  1.3.4.2  nathanw 
    389  1.3.4.2  nathanw 		| sec = raw_read_pos	(d2)
    390  1.3.4.2  nathanw 		| sec >>= 7 + (sector length: 0-3)
    391  1.3.4.2  nathanw 
    392  1.3.4.2  nathanw 		lea	RELOC(FDSECMINMAX),%a0
    393  1.3.4.2  nathanw 		moveq	#0,%d1
    394  1.3.4.2  nathanw 		moveb	%a0@,%d1	| d1: sector length (0-3)
    395  1.3.4.2  nathanw 		lsrl	%d1,%d2		| d2: pos in sector
    396  1.3.4.2  nathanw 		bcss	read_half	| error check
    397  1.3.4.2  nathanw 
    398  1.3.4.2  nathanw 		| trk = sec / (# sectors)
    399  1.3.4.2  nathanw 		| sec = sec % (# sectors)
    400  1.3.4.2  nathanw 
    401  1.3.4.2  nathanw 		moveb	%a0@(7),%d1	| d1: max sector #
    402  1.3.4.2  nathanw 		subb	%a0@(3),%d1	|   - min sector #
    403  1.3.4.2  nathanw 		addqb	#1,%d1		| d1: # sectors
    404  1.3.4.2  nathanw 		divu	%d1,%d2		| d2: (sec << 16) | track
    405  1.3.4.2  nathanw 
    406  1.3.4.2  nathanw 		| position = (sec length << 24) | (track/2 << 16)
    407  1.3.4.2  nathanw 		|		| (track%2 << 8) | (min sec # + sec)
    408  1.3.4.2  nathanw 
    409  1.3.4.2  nathanw 		movel	%a0@,%d0	| d0: (sec len << 24) | min sec #
    410  1.3.4.2  nathanw 		lsrw	#1,%d2		| d2: (sec << 16) | (track / 2)
    411  1.3.4.2  nathanw 		jcc	1f
    412  1.3.4.2  nathanw 		bset	#8,%d0		| |= (track % 2) << 8
    413  1.3.4.2  nathanw 1:		swap	%d2		| d2: ((track / 2) << 16) | sec
    414  1.3.4.2  nathanw 		addl	%d0,%d2		| d2: position
    415  1.3.4.2  nathanw 
    416  1.3.4.2  nathanw 		| read
    417  1.3.4.2  nathanw 		movel	RELOC(FDMODE),%d1	| PDA*256 + MODE
    418  1.3.4.2  nathanw 
    419  1.3.4.2  nathanw 		| B_READ (for floppy)
    420  1.3.4.2  nathanw 		|  d1.w: PDA x 256 + MODE
    421  1.3.4.2  nathanw 		|	PDA: 0x90 (drive 0) ... 0x93 (drive 3)
    422  1.3.4.2  nathanw 		|	MODE:	bit6: MFM
    423  1.3.4.2  nathanw 		|		bit5: retry
    424  1.3.4.2  nathanw 		|		bit4: seek
    425  1.3.4.2  nathanw 		|  d2.l: position
    426  1.3.4.2  nathanw 		|	bit31-24: sector length (0: 128, 1: 256, 2: 512, 3: 1K)
    427  1.3.4.2  nathanw 		|	bit23-16: track # (0-79)
    428  1.3.4.2  nathanw 		|	bit15-08: side (0 or 1)
    429  1.3.4.2  nathanw 		|	bit07-00: sector # (1-)
    430  1.3.4.2  nathanw 		|  d3.l: read bytes
    431  1.3.4.2  nathanw 		|  a1:   read address
    432  1.3.4.2  nathanw 		| return:
    433  1.3.4.2  nathanw 		|  d0:	bit 31-24	ST0
    434  1.3.4.2  nathanw 		|	bit 23-16	ST1
    435  1.3.4.2  nathanw 		|	bit 15- 8	ST2
    436  1.3.4.2  nathanw 		|	bit  7- 0	C
    437  1.3.4.2  nathanw 		|	-1 on parameter error
    438  1.3.4.2  nathanw 		| destroy: d0, d2, d3, a1
    439  1.3.4.2  nathanw 		IOCS(__B_READ)
    440  1.3.4.2  nathanw 		andil	#0xf8ffff00,%d0		| check status (must be zero)
    441  1.3.4.2  nathanw 		jne	read_error
    442  1.3.4.2  nathanw 
    443  1.3.4.2  nathanw raw_read_end:
    444  1.3.4.2  nathanw 		moveml	%sp@+,%a2-%a6/%d2-%d7
    445  1.3.4.2  nathanw 		rts
    446  1.3.4.2  nathanw #undef _RELOC	/* base register  a5  is no longer available */
    447  1.3.4.2  nathanw #undef ASRELOC
    448  1.3.4.2  nathanw #undef RELOC
    449  1.3.4.2  nathanw 
    450  1.3.4.2  nathanw read_half:	BOOT_ERROR("read half of block")
    451  1.3.4.2  nathanw 
    452  1.3.4.2  nathanw 
    453  1.3.4.2  nathanw ENTRY_NOPROFILE(B_KEYINP)
    454  1.3.4.2  nathanw 		IOCS(__B_KEYINP)
    455  1.3.4.2  nathanw 		rts
    456  1.3.4.2  nathanw 
    457  1.3.4.2  nathanw ENTRY_NOPROFILE(B_PUTC)
    458  1.3.4.2  nathanw 		movel	%sp@(4),%d1
    459  1.3.4.2  nathanw 		IOCS(__B_PUTC)
    460  1.3.4.2  nathanw 		rts
    461  1.3.4.2  nathanw 
    462  1.3.4.2  nathanw ENTRY_NOPROFILE(B_PRINT)
    463  1.3.4.2  nathanw 		movel	%sp@(4),%a1
    464  1.3.4.2  nathanw 		IOCS(__B_PRINT)
    465  1.3.4.2  nathanw 		rts
    466  1.3.4.2  nathanw 
    467  1.3.4.2  nathanw |
    468  1.3.4.2  nathanw | void memcpy(void *dst, const void *src, size_t count);
    469  1.3.4.2  nathanw | void memmove(void *dst, const void *src, size_t count);
    470  1.3.4.2  nathanw |
    471  1.3.4.2  nathanw |	small and slow memcpy...
    472  1.3.4.2  nathanw |	THIS FUNCTION DOES NOT CONFORM THE ANSI STANDARD
    473  1.3.4.2  nathanw |
    474  1.3.4.2  nathanw ENTRY_NOPROFILE(memcpy)
    475  1.3.4.2  nathanw ENTRY_NOPROFILE(memmove)
    476  1.3.4.2  nathanw 	lea	%sp@(12),%a1
    477  1.3.4.2  nathanw 	movel	%a1@,%d1	| count
    478  1.3.4.2  nathanw 	jeq	Lmcpret
    479  1.3.4.2  nathanw 	moveal	%a1@-,%a0	| src
    480  1.3.4.2  nathanw 	moveal	%a1@-,%a1	| dest
    481  1.3.4.2  nathanw 	cmpl	%a1,%a0
    482  1.3.4.2  nathanw 	jcc	Lmcpfw
    483  1.3.4.2  nathanw 	| copy backward
    484  1.3.4.2  nathanw 	addal	%d1,%a0
    485  1.3.4.2  nathanw 	addal	%d1,%a1
    486  1.3.4.2  nathanw 1:	moveb	%a0@-,%a1@-
    487  1.3.4.2  nathanw 	subql	#1,%d1
    488  1.3.4.2  nathanw 	jne	1b
    489  1.3.4.2  nathanw 	jra	Lmcpret
    490  1.3.4.2  nathanw Lmcpfw:	| copy forward
    491  1.3.4.2  nathanw 1:	moveb	%a0@+,%a1@+
    492  1.3.4.2  nathanw 	subql	#1,%d1
    493  1.3.4.2  nathanw 	jne	1b
    494  1.3.4.2  nathanw Lmcpret:
    495  1.3.4.2  nathanw |	movel	%sp@(8),%d0	| uncomment this to conform ANSI
    496  1.3.4.2  nathanw 	rts
    497  1.3.4.2  nathanw 
    498  1.3.4.2  nathanw 
    499  1.3.4.2  nathanw |
    500  1.3.4.2  nathanw |	global variables
    501  1.3.4.2  nathanw |
    502  1.3.4.2  nathanw 	BSS(ID, 4)			| SCSI ID
    503  1.3.4.2  nathanw 	BSS(BOOT_INFO, 4)		| result of IOCS(__BOOTINF)
    504  1.3.4.2  nathanw 	BSS(FDMODE, 4)			| Floppy access mode: PDA x 256 + MODE
    505  1.3.4.2  nathanw 	BSS(FDSECMINMAX, 8)		| +0: (min sector) sector length
    506  1.3.4.2  nathanw 					| +1: (min sector) track #
    507  1.3.4.2  nathanw 					| +2: (min sector) side
    508  1.3.4.2  nathanw 					| +3: (min sector) sector #
    509  1.3.4.2  nathanw 					| +4: (max sector) sector length
    510  1.3.4.2  nathanw 					| +5: (max sector) track #
    511  1.3.4.2  nathanw 					| +6: (max sector) side
    512  1.3.4.2  nathanw 					| +7: (max sector) sector #
    513  1.3.4.2  nathanw #ifdef SCSI_ADHOC_BOOTPART
    514  1.3.4.2  nathanw 	BSS(SCSI_PARTTOP, 4)		| start sector of boot partition
    515  1.3.4.2  nathanw 	BSS(SCSI_BLKLEN ,4)		| sector len 0: 256, 1: 512, 2: 1024
    516  1.3.4.2  nathanw #endif
    517