xref: /netbsd/sys/arch/x68k/stand/common/chkfmt.s (revision 78d2e328)
1|
2|	check FD format
3|
4|	Written by ITOH Yasufumi
5|	This code is in the public domain
6|
7| $NetBSD: chkfmt.s,v 1.2 2011/02/21 02:31:58 itohy Exp $
8
9/* FDC address */
10#define FDC_STATUS		0xE94001	/* status register */
11#define FDC_DATA		0xE94003	/* data register */
12
13#define INT_STAT		0xE9C001	/* interrupt control */
14#define INT_FDC_BIT		2
15
16/* Status Register */
17#define NE7ST_CB_BIT		4		/* FDC busy */
18#define NE7ST_DIO_BIT		6		/* data input/output */
19#define NE7ST_RQM_BIT		7		/* request for master */
20
21/* FDC command */
22#define NE7CMD_READID		0x4A		/* READ ID */
23
24|
25|	Read ID of all sectors in current track.
26|	This routine expects that motor on, drive selection
27|	and seek is already done.
28|
29|	input:	d0.b: 0 0 0 0 0 HD US1 US0 (binary)
30|	output:	d0.l: min # sector (N C H R (2hex))
31|		d1.l: max # sector (N C H R (2hex))
32|	destroy:
33|		d0, d1
34|
35	.text
36	.even
37	.globl	check_fd_format
38check_fd_format:
39	moveml	%d2-%d7/%a1-%a3,%sp@-
40
41	moveb	%d0,%d6			| head, drive
42
43	lea	FDC_STATUS:l,%a1
44	lea	%a1@(FDC_DATA-FDC_STATUS),%a2	| FDC_DATA
45	lea	%a2@(INT_STAT-FDC_DATA),%a3	| INT_STAT
46
47	movew	%sr,%sp@-
48	oriw	#0x0700,%sr		| keep out interrupts
49	moveq	#INT_FDC_BIT,%d5
50	bclr	%d5,%a3@		| disable FDC interrupt
51
52	jbsr	read_id_sub
53	jne	exit_check_format
54	movel	%d3,%d2			| first sector
55	movel	%d3,%d0			| sector min
56sector_is_max:
57	movel	%d3,%d1			| sector max
58
59loop_read_id:
60	jbsr	read_id_sub
61	jne	exit_check_format
62	cmpl	%d0,%d3
63	jcc	sector_not_min
64	movel	%d3,%d0
65sector_not_min:
66	cmpl	%d3,%d1
67	jcs	sector_is_max
68	cmpl	%d2,%d3
69	jne	loop_read_id
70
71exit_check_format:
72	bset	%d5,%a3@		| enable FDC interrupt
73	movew	%a7@+,%sr
74
75	tstl	%d7
76	moveml	%a7@+,%d2-%d7/%a1-%a3
77	jne	_err_read_id
78
79	rts
80
81|
82|	input:	d6.b: 0 0 0 0 0 HD US1 US0 (binary)
83|		a1: FDC status addr
84|		a2: FDC data addr
85|		interrupt must be disabled
86|	output:	d3.l: sector information: N C H R (2hex)
87|		d7.l: status (nonzero if error)
88|		Z flag: true if no error, false if error
89|	destroy:
90|		d3-d4, d7
91|
92read_id_sub:
93	| wait for FDC ready
94fdc_wait_ready:
95	btst	#NE7ST_CB_BIT,%a1@
96	jne	fdc_wait_ready
97
98	| send READ ID command
99fdc_send_command1:
100	jbsr	fdc_wait_rqm
101	jmi	fdc_send_command1
102	moveb	#NE7CMD_READID,%a2@
103
104fdc_send_command2:
105	jbsr	fdc_wait_rqm
106	jmi	fdc_send_command2
107	moveb	%d6,%a2@		| X X X X X HD US1 US0 (binary)
108
109	| receive data
110	moveq	#2,%d4
111	jbsr	fdc_read_bytes
112	movel	%d3,%d7			| d7: FDC status: X ST0 ST1 ST2 (2hex)
113	moveq	#3,%d4
114	jbsr	fdc_read_bytes		| d3: sector info: C H R N (2hex)
115	rorl	#8,%d3			| d3: sector info: N C H R (2hex)
116
117	andil	#0x00f8ffff,%d7		| check status (must be zero)
118	rts
119
120|
121|	receive d4:w + 1 bytes from FDC
122|
123fdc_read_bytes:
124	asll	#8,%d3
125fdc_read_loop:
126	jbsr	fdc_wait_rqm
127	jpl	fdc_read_loop
128	moveb	%a2@,%d3
129	dbra	%d4,fdc_read_bytes
130	rts
131
132fdc_wait_rqm:
133	moveb	%a1@,%d3
134	jpl	fdc_wait_rqm		| NE7ST_RQM_BIT = 7: sign bit
135	lslb	#1,%d3			| NE7ST_DIO_BIT = 6 ... move to bit #7
136	rts
137
138|
139|	error
140|
141_err_read_id:
142	BOOT_ERROR("READ ID failed")
143