]>
git.saurik.com Git - apple/boot.git/blob - i386/boot1u/disk.c
cd8b4cd35e74b0f4810358fdfdb2e51ad2232e4d
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 2002 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.2 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
28 #include <saio_types.h>
29 #include <saio_internal.h>
35 * trackbuf points to the start of the track cache. Biosread()
36 * will store the sectors read from disk to this memory area.
38 * biosbuf points to a sector within the track cache, and is
39 * updated by Biosread().
42 static const char * const trackbuf
= (char *) ptov(BIOS_ADDR
);
44 static const char * biosbuf
= (char *) ptov(BIOS_ADDR
);
49 #define SPT(di) ((di) & 0xff)
50 #define HEADS(di) ((((di)>>8) & 0xff) + 1)
51 #define SPC(di) (SPT(di) * HEADS(di))
53 #define BPS 512 /* sector size of the device */
54 #define N_CACHE_SECS (BIOS_LEN / BPS)
55 #define UFS_FRONT_PORCH 0
57 #define ECC_CORRECTED_ERR 0x11
60 //#define DEBUG_DISK(x) printf x
62 extern void bios(biosBuf_t
*bb
);
65 int ebiosread(int dev
, long sec
, int count
)
70 unsigned char reserved
;
71 unsigned char numblocks
;
72 unsigned char reserved2
;
73 unsigned short bufferOffset
;
74 unsigned short bufferSegment
;
75 unsigned long long startblock
;
77 addrpacket
.size
= sizeof(addrpacket
);
83 bb
.esi
.rr
= OFFSET((unsigned)&addrpacket
);
84 bb
.ds
= SEGMENT((unsigned)&addrpacket
);
85 addrpacket
.reserved
= addrpacket
.reserved2
= 0;
86 addrpacket
.numblocks
= count
;
87 addrpacket
.bufferOffset
= OFFSET(ptov(BIOS_ADDR
));
88 addrpacket
.bufferSegment
= SEGMENT(ptov(BIOS_ADDR
));
89 addrpacket
.startblock
= sec
;
91 if ((bb
.eax
.r
.h
== 0x00) || (i
++ >= 5))
94 /* reset disk subsystem and try again */
101 //==========================================================================
102 // Use BIOS INT13 calls to read the sector specified. This function will
103 // also perform read-ahead to cache a few subsequent sector to the sector
107 // 0 on success, or an error code from INT13/F2 or INT13/F42 BIOS call.
109 static int Biosread( int biosdev
, unsigned int secno
)
113 DEBUG_DISK(("Biosread dev %x sec %d \n", biosdev
, secno
));
115 rc
= ebiosread(biosdev
, secno
, 1);
116 if (rc
== ECC_CORRECTED_ERR
) {
122 //==========================================================================
124 static int readBytes( int biosdev
, unsigned int blkno
,
125 unsigned int byteCount
, void * buffer
)
128 char * cbuf
= (char *) buffer
;
132 DEBUG_DISK(("%s: dev %x block %x [%d] -> 0x%x...", __FUNCTION__
,
133 biosdev
, blkno
, byteCount
, (unsigned)cbuf
));
135 for ( ; byteCount
; cbuf
+= BPS
, blkno
++ )
137 error
= Biosread( biosdev
, blkno
);
140 DEBUG_DISK(("error\n"));
144 copy_len
= (byteCount
> BPS
) ? BPS
: byteCount
;
145 bcopy( biosbuf
, cbuf
, copy_len
);
146 byteCount
-= copy_len
;
149 DEBUG_DISK(("done\n"));
154 //==========================================================================
156 //==========================================================================
157 // Handle seek request from filesystem modules.
159 void diskSeek( BVRef bvr
, long long position
)
161 bvr
->fs_boff
= position
/ BPS
;
164 //==========================================================================
165 // Handle read request from filesystem modules.
167 int diskRead( BVRef bvr
, long addr
, long length
)
169 return readBytes( bvr
->biosdev
,
170 bvr
->fs_boff
+ bvr
->part_boff
,
176 findUFSPartition(int dev
, struct fdisk_part
*_fp
)
178 struct disk_blk0
*db
;
179 struct fdisk_part
*fp
;
181 unsigned long offset
= 0;
183 db
= (struct disk_blk0
*)biosbuf
;
184 for (i
=0; i
<FDISK_NPART
; i
++) {
185 DEBUG_DISK(("i=%d, %ld\n", i
, offset
));
187 DEBUG_DISK(("reading\n"));
188 cc
= Biosread(dev
, offset
);
193 fp
= (struct fdisk_part
*)&db
->parts
[i
];
194 DEBUG_DISK(("systid %x\n", fp
->systid
));
195 if (fp
->systid
== 0xA8) {
196 bcopy(fp
, _fp
, sizeof(struct fdisk_part
));
197 _fp
->relsect
+= offset
;
198 DEBUG_DISK(("found %d\n", i
));
200 } else if (fp
->systid
== 0x05 ||
201 fp
->systid
== 0x0F ||
202 fp
->systid
== 0x85) {
203 offset
+= fp
->relsect
;
213 initUFSBVRef( BVRef bvr
, int biosdev
, const struct fdisk_part
* part
)
215 bvr
->biosdev
= biosdev
;
217 bvr
->part_boff
= part
->relsect
+ UFS_FRONT_PORCH
/BPS
,
218 bvr
->part_type
= part
->systid
;
219 bvr
->fs_loadfile
= UFSLoadFile
;
220 bvr
->fs_getdirentry
= UFSGetDirEntry
;
221 bvr
->description
= 0;
227 bb
.ebx
.r
.h
= 0x00; /* background black */
228 bb
.ebx
.r
.l
= 0x0F; /* foreground white */
246 bb
.ecx
.rr
= ms
>> 16;
247 bb
.edx
.rr
= ms
& 0xFFFF;