#include #include #include #include #include "Hardware.h" #include "Hardware_Tools.h" /** * défult implementation for the interruptions handler... (return !) */ void emptyIT() { return ; } /** * void dumpsector(int cyl, int sec) * sec: the sector * cyl: the cylender */ void dumpsector(int cyl, int sec) { unsigned char *ptr; int sectorSize; int i; /* Get disk geometry */ _out(0x3F6,0x16); sectorSize = (_in(0x114)<<8) + _in(0x115); /* */ ptr = malloc(sectorSize); /* head shift */ printf("seek...\n"); _out(0x110,(cyl>>8)&0xFF); /* cylinder high */ _out(0x111,cyl&0xFF); /* cylinder low */ _out(0x112,(sec>>8)&0xFF); /* sector high */ _out(0x113,sec&0xFF); /* sector low */ _out(0x3F6,0x02); /* DISK_SEEK */ _sleep(14); /* HDA_IRQ */ /* data read */ printf("read...\n"); _out(0x110,0); _out(0x111,1); _out(0x3F6,0x04); /* DISK_READ */ _sleep(14); /* HDA_IRQ */ /* Extract masterbuffer */ memcpy(ptr,MASTERBUFFER, sectorSize); /* Dump the disk buffer */ printf("%04d - ",0); for(i=0;i>8)&0xFF); /* cylinder high */ _out(0x111,cyl&0xFF); /* cylinder low */ _out(0x112,(sec>>8)&0xFF); /* sector high */ _out(0x113,sec&0xFF); /* sector low */ _out(0x3F6,0x02); /* DISK_SEEK */ _sleep(14); /* HDA_IRQ */ /* format */ _out(0x110,0); _out(0x111,1); _out(0x112,(value>>24)&255); _out(0x113,(value>>16)&255); _out(0x114,(value>>8)&255); _out(0x115,(value)&255); _out(0x3F6,0x08); /* DISK_FORMAT */ _sleep(14); } } printf(" delay : %d \n",_in(0xF0)-base); } void format(int cyl,int sec, int n, int v) { /* head shift */ printf("seek...\n"); _out(0x110,(cyl>>8)&0xFF); /* cylinder high */ _out(0x111,cyl&0xFF); /* cylinder low */ _out(0x112,(sec>>8)&0xFF); /* sector high */ _out(0x113,sec&0xFF); /* sector low */ _out(0x3F6,0x02); /* DISK_SEEK */ _sleep(14); /* HDA_IRQ */ /* format */ _out(0x110,0); _out(0x111,n&255); _out(0x112,(v>>24)&255); _out(0x113,(v>>16)&255); _out(0x114,(v>>8)&255); _out(0x115,(v)&255); _out(0x3F6,0x08); /* DISK_FORMAT */ for(;n>0;n--) _sleep(14); } void printIT() { printf("hello from IT\n"); _out(0xF8,0xFFFFFFFE); } int main(int argc, char * argv[]) { int i; if(argc < 2) { printf("%s usage : \n",argv[0]); printf(" \"%s dumpsec 1 2\" dump value of the sector 2, cylinder 1\n",argv[0]); printf(" \"%s format 1 2 3 4\" format 4 from sector 2, cylinder 1 with the value 4\n",argv[0]); printf(" \"%s format 0 1\" format the disk with value 1 from the end until the begining\n",argv[0]); return 1; } /* initialisation du matériel */ if( initHardware("Hardware.ini") == 0 ) return 0; IRQVECTOR[14] = emptyIT; _mask(1); /* autoriser toutes les interruptions > 1 */ if(strcmp(argv[1],"dumpsec")==0) { dumpsector(atoi(argv[2]),atoi(argv[3])); } else if(strcmp(argv[1],"format")==0) { if(argc==4) formatAll(atoi(argv[2]),atoi(argv[3])); else format(atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5])); } else if(strcmp(argv[1],"timer")==0) { IRQVECTOR[2] = printIT; _out(0xF4,128+64+32); _out(0xF8,0xFFFFFFFE); for(i=0;i<100000000;i++) ; } return 0; }