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