openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

disk.c (2859B)


      1 /* $Id: //depot/blt/srv/ide/disk.c#4 $
      2 **
      3 ** Copyright 1999 Sidney Cammeresi
      4 ** All rights reserved.
      5 **
      6 ** Redistribution and use in source and binary forms, with or without
      7 ** modification, are permitted provided that the following conditions
      8 ** are met:
      9 ** 1. Redistributions of source code must retain the above copyright
     10 **    notice, this list of conditions, and the following disclaimer.
     11 ** 2. Redistributions in binary form must reproduce the above copyright
     12 **    notice, this list of conditions, and the following disclaimer in the
     13 **    documentation and/or other materials provided with the distribution.
     14 ** 3. The name of the author may not be used to endorse or promote products
     15 **    derived from this software without specific prior written permission.
     16 **
     17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28 
     29 #include "ide-int.h"
     30 #include <stdio.h>
     31 #include <i386/io.h>
     32 
     33 int ide_disk_read (int bus, int device, void *data, int block)
     34 {
     35 	unsigned short *buf;
     36 	int i, base, cyl, head, sect;
     37 
     38 	base = ide_base (bus);
     39 	buf = (unsigned short *) data;
     40 	ide_btochs (block, ide_dev[bus * 2 + device], &cyl, &head, &sect);
     41 	IDE_WAIT_0 (STATUS, 7);
     42 
     43 	IDE_SEL_DH (bus, device, head);
     44 	IDE_WAIT_0 (STATUS, 7);
     45 	//IDE_WAIT_1 (STATUS, 6);
     46 
     47 	outb (cyl / 256, IDE_REG_CYLMSB);
     48 	outb (cyl % 256, IDE_REG_CYLLSB);
     49 	outb (sect + 1, IDE_REG_SECNUM);
     50 	outb (1, IDE_REG_SECCNT);
     51 	outb (IDE_OP_READ, IDE_REG_COMMAND);
     52 	IDE_WAIT_0 (STATUS, 7);
     53 	IDE_WAIT_1 (STATUS, 3);
     54 
     55 	for (i = 0; i < 256; i++)
     56 		buf[i] = inw (IDE_REG_DATA);
     57 	return 0;
     58 }
     59 
     60 int ide_disk_write (int bus, int device, const void *data, int block)
     61 {
     62 #if 0
     63 	short *buf;
     64 	int i, base, cyl, head, sect;
     65 
     66 	base = ide_base (bus);
     67 	buf = (short *) data;
     68 	ide_btochs (block, ide_dev[bus * 2 + device], &cyl, &head, &sect);
     69 	IDE_WAIT_0 (STATUS, 7);
     70 
     71 	/* select device */
     72 	IDE_SEL_DH (bus, device, head);
     73 	IDE_WAIT_0 (STATUS, 7);
     74 	IDE_WAIT_1 (STATUS, 6);
     75 
     76 	outb (cyl / 256, IDE_REG_CYLMSB);
     77 	outb (cyl % 256, IDE_REG_CYLLSB);
     78 	outb (sect, IDE_REG_SECNUM);
     79 	outb (1, IDE_REG_SECCNT);
     80 	outb (IDE_OP_WRITE, IDE_REG_COMMAND);
     81 	IDE_WAIT_1 (STATUS, 3);
     82 
     83 	for (i = 0; i < 256; i++)
     84 		outw (buf[i], IDE_REG_DATA);
     85 #endif
     86 
     87 	return 0;
     88 }
     89