]>
git.saurik.com Git - apple/boot.git/blob - i386/boot1u/disk.c
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 2002-2003 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 2.0 (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
59 extern void bios(biosBuf_t
*bb
);
63 int ebiosread(int dev
, long sec
, int count
)
68 unsigned char reserved
;
69 unsigned char numblocks
;
70 unsigned char reserved2
;
71 unsigned short bufferOffset
;
72 unsigned short bufferSegment
;
73 unsigned long long startblock
;
75 addrpacket
.size
= sizeof(addrpacket
);
81 bb
.esi
.rr
= OFFSET((unsigned)&addrpacket
);
82 bb
.ds
= SEGMENT((unsigned)&addrpacket
);
83 addrpacket
.reserved
= addrpacket
.reserved2
= 0;
84 addrpacket
.numblocks
= count
;
85 addrpacket
.bufferOffset
= OFFSET(ptov(BIOS_ADDR
));
86 addrpacket
.bufferSegment
= SEGMENT(ptov(BIOS_ADDR
));
87 addrpacket
.startblock
= sec
;
89 if ((bb
.eax
.r
.h
== 0x00) || (i
++ >= 5))
92 /* reset disk subsystem and try again */
99 //==========================================================================
100 // Use BIOS INT13 calls to read the sector specified. This function will
101 // also perform read-ahead to cache a few subsequent sector to the sector
105 // 0 on success, or an error code from INT13/F2 or INT13/F42 BIOS call.
107 static int Biosread( int biosdev
, unsigned int secno
)
111 DEBUG_DISK(("Biosread dev %x sec %d \n", biosdev
, secno
));
113 rc
= ebiosread(biosdev
, secno
, 1);
114 if (rc
== ECC_CORRECTED_ERR
) {
120 //==========================================================================
122 static int readBytes( int biosdev
, unsigned int blkno
,
123 unsigned int byteCount
, void * buffer
)
126 char * cbuf
= (char *) buffer
;
130 DEBUG_DISK(("%s: dev %x block %x [%d] -> 0x%x...", __FUNCTION__
,
131 biosdev
, blkno
, byteCount
, (unsigned)cbuf
));
133 for ( ; byteCount
; cbuf
+= BPS
, blkno
++ )
135 error
= Biosread( biosdev
, blkno
);
138 DEBUG_DISK(("error\n"));
142 copy_len
= (byteCount
> BPS
) ? BPS
: byteCount
;
143 bcopy( biosbuf
, cbuf
, copy_len
);
144 byteCount
-= copy_len
;
147 DEBUG_DISK(("done\n"));
152 //==========================================================================
154 //==========================================================================
155 // Handle seek request from filesystem modules.
157 void diskSeek( BVRef bvr
, long long position
)
159 bvr
->fs_boff
= position
/ BPS
;
162 //==========================================================================
163 // Handle read request from filesystem modules.
165 int diskRead( BVRef bvr
, long addr
, long length
)
167 return readBytes( bvr
->biosdev
,
168 bvr
->fs_boff
+ bvr
->part_boff
,
175 findUFSPartition(int dev
, struct fdisk_part
*_fp
)
177 struct disk_blk0
*db
;
178 struct fdisk_part
*fp
;
180 unsigned long offset
= 0;
181 unsigned long firstoff
= 0;
184 db
= (struct disk_blk0
*)biosbuf
;
186 DEBUG_DISK(("reading at offset %d\n", offset
));
187 cc
= Biosread(dev
, offset
);
191 for (i
=0; i
<FDISK_NPART
; i
++) {
192 DEBUG_DISK(("i=%d, offset %ld\n", i
, offset
));
193 fp
= (struct fdisk_part
*)&db
->parts
[i
];
194 DEBUG_DISK(("systid %x\n", fp
->systid
));
195 if (fp
->systid
== FDISK_UFS
) {
196 bcopy(fp
, _fp
, sizeof(struct fdisk_part
));
197 _fp
->relsect
+= offset
;
198 DEBUG_DISK(("** found UFS at partition %d\n", i
));
200 } else if (fp
->systid
== FDISK_DOSEXT
||
201 fp
->systid
== 0x0F ||
202 fp
->systid
== 0x85) {
206 if (ext_index
!= -1) {
207 DEBUG_DISK(("Found ext part at %d\n", ext_index
));
208 fp
= (struct fdisk_part
*)&db
->parts
[ext_index
];
210 offset
= firstoff
+ fp
->relsect
;
212 firstoff
= fp
->relsect
;
223 initUFSBVRef( BVRef bvr
, int biosdev
, const struct fdisk_part
* part
)
225 bvr
->biosdev
= biosdev
;
227 bvr
->part_boff
= part
->relsect
+ UFS_FRONT_PORCH
/BPS
,
228 bvr
->part_type
= part
->systid
;
229 bvr
->fs_loadfile
= UFSLoadFile
;
230 //bvr->fs_getdirentry = UFSGetDirEntry;
231 bvr
->description
= 0;
237 bb
.ebx
.r
.h
= 0x00; /* background black */
238 bb
.ebx
.r
.l
= 0x0F; /* foreground white */
256 bb
.ecx
.rr
= ms
>> 16;
257 bb
.edx
.rr
= ms
& 0xFFFF;