Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / x68k / stand / common / chkfmt.s
blobf75eae98ea0634f4c6ca494fa834d3d57f4794e2
2 | check FD format
4 | Written by Yasha (ITOH Yasufumi)
5 | This code is in the public domain
7 | $NetBSD$
9 /* FDC address */
10 #define FDC_STATUS 0xE94001 /* status register */
11 #define FDC_DATA 0xE94003 /* data register */
13 #define INT_STAT 0xE9C001 /* interrupt control */
14 #define INT_FDC_BIT 2
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 */
21 /* FDC command */
22 #define NE7CMD_READID 0x4A /* READ ID */
25 | Read ID of all sectors in current track.
26 | This routine expects that motor on, drive selection
27 | and seek is already done.
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
35 .text
36 .even
37 .globl check_fd_format
38 check_fd_format:
39 moveml %d2-%d7/%a1-%a3,%sp@-
41 moveb %d0,%d6 | head, drive
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
47 movew %sr,%sp@-
48 oriw #0x0700,%sr | keep out interrupts
49 moveq #INT_FDC_BIT,%d5
50 bclr %d5,%a3@ | disable FDC interrupt
52 jbsr read_id_sub
53 jne exit_check_format
54 movel %d3,%d2 | first sector
55 movel %d3,%d0 | sector min
56 sector_is_max:
57 movel %d3,%d1 | sector max
59 loop_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
65 sector_not_min:
66 cmpl %d3,%d1
67 jcs sector_is_max
68 cmpl %d2,%d3
69 jne loop_read_id
71 exit_check_format:
72 bset %d5,%a3@ | enable FDC interrupt
73 movew %a7@+,%sr
75 tstl %d7
76 moveml %a7@+,%d2-%d7/%a1-%a3
77 jne _err_read_id
79 rts
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
92 read_id_sub:
93 | wait for FDC ready
94 fdc_wait_ready:
95 btst #NE7ST_CB_BIT,%a1@
96 jne fdc_wait_ready
98 | send READ ID command
99 fdc_send_command1:
100 jbsr fdc_wait_rqm
101 jmi fdc_send_command1
102 moveb #NE7CMD_READID,%a2@
104 fdc_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)
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)
117 andil #0x00f8ffff,%d7 | check status (must be zero)
121 | receive d4:w + 1 bytes from FDC
123 fdc_read_bytes:
124 asll #8,%d3
125 fdc_read_loop:
126 jbsr fdc_wait_rqm
127 jpl fdc_read_loop
128 moveb %a2@,%d3
129 dbra %d4,fdc_read_bytes
132 fdc_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
139 | error
141 _err_read_id:
142 BOOT_ERROR("READ ID failed")