ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

prep_ide.c
Go to the documentation of this file.
00001 #include "freeldr.h"
00002 #include "machine.h"
00003 #include "ppcmmu/mmu.h"
00004 #include "prep.h"
00005 
00006 #define SWAP_W(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
00007 
00008 typedef struct _idectl_desc {
00009     int port;
00010     long long seekto;
00011     int seek_cylinder, seek_head, seek_sector;
00012     int cylinders, heads, sectors, bytespersec;
00013 } idectl_desc;
00014 
00015 idectl_desc ide1_desc = { 0x800001f0 };
00016 
00017 void ide_seek( void *extension, int low, int high ) {
00018     idectl_desc *desc = (idectl_desc *)extension;
00019     long long seekto = ((((long long)high) << 32) | (low & 0xffffffff));
00020     /* order = sector, head, cylinder */
00021     desc->seek_sector = seekto % desc->sectors;
00022     seekto /= desc->sectors;
00023     desc->seek_head = seekto % desc->heads;
00024     seekto /= desc->heads;
00025     desc->seek_cylinder = seekto;
00026     desc->seekto = seekto;
00027 }
00028 
00029 /* Thanks chuck moore.  This is based on the color forth ide code */
00030 /* Wait for ready */
00031 void ide_rdy( void *extension ) {
00032     idectl_desc *desc = (idectl_desc *)extension;
00033     while( !(GetPhysByte(desc->port+7) & 0x40) ) sync();
00034 }
00035 
00036 void ide_drq( void *extension ) {
00037     idectl_desc *desc = (idectl_desc *)extension;
00038     while( !(GetPhysByte(desc->port+7) & 0x08) ) sync();
00039 }
00040 
00041 void ide_bsy( void *extension ) {
00042     idectl_desc *desc = (idectl_desc *)extension;
00043     while( GetPhysByte(desc->port+7) & 0x80 )
00044     {
00045     printf("Waiting for not busy\n");
00046     sync();
00047     }
00048 }
00049 
00050 int ide_read( void *extension, char *buffer, int bytes ) {
00051     idectl_desc *desc = (idectl_desc *)extension;
00052     short *databuf = (short *)buffer;
00053     int inwords;
00054 
00055     ide_bsy( extension );
00056     SetPhysByte(desc->port+2, bytes / desc->bytespersec);
00057     SetPhysByte(desc->port+3, desc->seek_sector + 1);
00058     SetPhysByte(desc->port+4, desc->seek_cylinder);
00059     SetPhysByte(desc->port+5, desc->seek_cylinder >> 8);
00060     SetPhysByte(desc->port+6, desc->seek_head | 0xa0);
00061     SetPhysByte(desc->port+7, 0x20);
00062 
00063     for( inwords = 0; inwords < desc->bytespersec / sizeof(short); inwords++ ) {
00064     databuf[inwords] = GetPhysHalf(desc->port);
00065     }
00066 
00067     desc->seekto += desc->bytespersec;
00068     ide_seek( extension, desc->seekto, desc->seekto >> 32 );
00069 
00070     return bytes - (bytes % desc->bytespersec);
00071 }
00072 
00073 void ide_setup( void *extension ) {
00074     idectl_desc *desc = (idectl_desc *)extension;
00075     short identbuffer[256];
00076     char namebuf[41];
00077     short *databuf = (short *)identbuffer, in;
00078     int inwords;
00079 
00080     ide_rdy( extension );
00081     ide_bsy( extension );
00082     desc->bytespersec = 512;
00083     SetPhysByte(desc->port+2, 1);
00084     SetPhysByte(desc->port+3, 0);
00085     SetPhysByte(desc->port+4, 0);
00086     SetPhysByte(desc->port+5, 0);
00087     SetPhysByte(desc->port+6, 0);
00088     SetPhysByte(desc->port+7, 0xec);
00089     ide_drq( extension );
00090 
00091     for( inwords = 0; inwords < desc->bytespersec / sizeof(short); inwords++ ) {
00092     in = GetPhysHalf(desc->port);
00093     databuf[inwords] = SWAP_W(in);
00094     sync();
00095     }
00096 
00097     desc->cylinders = identbuffer[1];
00098     desc->heads = identbuffer[3];
00099     desc->sectors = identbuffer[6];
00100 
00101     /* Debug: Write out hard disc model */
00102 
00103     strncpy(namebuf, (char *)(identbuffer+0x1b), 41);
00104     printf("HARD DISC MODEL: %s c,h,s %d,%d,%d\n",
00105        namebuf, desc->cylinders, desc->heads, desc->sectors);
00106 }

Generated on Sat May 26 2012 04:17:54 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.