fdc.c
isa/fdc.h
isa/8259.h
sys/video.h
sys/gdt.h
sys/idt.h
ubixos/types.h
ubixos/spinlock.h
sys/io.h
sys/dma.h
sys/device.h
lib/kprintf.h
lib/kmalloc.h
devfs/devfs.h
ubixos/spinlock.h
sys/dma.h
devfs/devfs.h
ubixos/types.h
sys/_types.h
sys/video.h
vfs/file.h
lib/kmalloc.h
sys/idt.h
vfs/mount.h
lib/kprintf.h
sys/gdt.h
ubixfs/dirCache.h
isa/fdc.h
sys/io.h
isa/8259.h
src/sys/isa/fdc.c
sys/device.h
asm
(".globl floppyIsr \n""floppyIsr: \n"" pusha \n"" push %ss \n"" push %ds \n"" push %es \n"" push %fs \n"" push %gs \n"" call floppyIsrhndlr \n"" pop %gs \n"" pop %fs \n"" pop %es \n"" pop %ds \n"" pop %ss \n"" popa \n"" iret \n")
asm
".globl floppyIsr \n""floppyIsr: \n"" pusha \n"" push %ss \n"" push %ds \n"" push %es \n"" push %fs \n"" push %gs \n"" call floppyIsrhndlr \n"" pop %gs \n"" pop %fs \n"" pop %es \n"" pop %ds \n"" pop %ss \n"" popa \n"" iret \n"
void void block2Hts (int block, int *head, int *track, int *sector) block2Hts int block int * head int * track int * sector geometry DrvGeom::heads DrvGeom::spt fdcRw
int int fdc_init () fdc_init devfs_makeNode device_add dInt dPresent fdcInit2 fdcRead fdcWrite floppyIsr device_interface::init irqEnable kmalloc device_interface::major mVec device_interface::read device_interface::reset reset setVector device_interface::write
int int fdcInit2 (struct device_node *dev) fdcInit2 struct device_node * dev device_node::devInfo device_interface::size fdc_init
void void fdcRead (void *info, void *baseAddr, uInt32 startSector, uInt32 sectorCount) fdcRead void * info void * baseAddr uInt32 startSector uInt32 sectorCount fdcSpinLock readBlock spinLock spinUnlock fdc_init
bool bool fdcRw (int block, Int8 *blockBuffer, bool read, unsigned long numSectors) fdcRw int block Int8 * blockBuffer bool read unsigned long numSectors block2Hts cmdRead cmdWrite dg144Gap3rw dg144Spt dg168Gap3rw diskChange dmaXfer FALSE fdcCcr fdcDir fdcRw geometry inportByte kprint kprintf motorOff motorOn outportByte recalibrate reset seek sendByte DrvGeom::spt status tbaddr TRUE waitFdc fdcRw readBlock writeBlock
void void fdcWrite (void *info, void *baseAddr, uInt32 startSector, uInt32 sectorCount) fdcWrite void * info void * baseAddr uInt32 startSector uInt32 sectorCount writeBlock fdc_init
void void floppyIsrhndlr () floppyIsrhndlr done outportByte TRUE x20
int int getByte () getByte fdcData fdcMsr inportByte waitFdc
void void motorOff (void) motorOff void FALSE motor TRUE fdcRw recalibrate
void void motorOn (void) motorOn void FALSE fdcDor motor outportByte TRUE fdcRw recalibrate
bool bool readBlock (int block, Int8 *blockBuffer, unsigned long numSectors) readBlock int block Int8 * blockBuffer unsigned long numSectors fdcRw TRUE fdcRead
void void recalibrate (void) recalibrate void cmdRecal motorOff motorOn sendByte TRUE waitFdc fdcRw reset
void void reset (void) reset void cmdSpecify diskChange done FALSE fdcDor motor outportByte recalibrate seek sendByte TRUE waitFdc fdc_init fdcRw
bool bool seek (int track) seek int track cmdSeek FALSE fdcTrack kprintf sendByte sr0 TRUE waitFdc x20 fdcRw reset
void void sendByte (int Int8) sendByte int Int8 fdcData fdcMsr inportByte outportByte fdcRw recalibrate reset seek waitFdc
bool bool waitFdc (bool sensei) waitFdc bool sensei cmdSensei diskChange done FALSE fdcDir fdcMsr fdcTrack getByte inportByte sendByte sr0 statSize status timeOut TRUE fdcRw recalibrate reset seek
bool bool writeBlock (int block, Int8 *blockBuffer, unsigned long numSectors) writeBlock int block Int8 * blockBuffer unsigned long numSectors FALSE fdcRw fdcWrite
bool bool diskChange diskChange FALSE fdcRw reset waitFdc
bool volatile bool done done FALSE bcopy floppyIsrhndlr reset waitFdc
spinLock_t spinLock_t fdcSpinLock fdcSpinLock SPIN_LOCK_INITIALIZER fdcRead
Int8 volatile Int8 fdcTrack fdcTrack 0xff seek waitFdc
drvGeom drvGeom geometry geometry { dg144Heads,dg144Tracks,dg144Spt } block2Hts fdcRw
bool bool motor motor FALSE motorOff motorOn reset
Int8 Int8 sr0 sr0 0 seek waitFdc
Int8 Int8 statSize statSize 0 waitFdc
Int8 Int8 status[7] [7] status { 0 } fdcRw ne2kHandler vmmFindFreePage vmmFreeProcessPages vmmMemMapInit waitFdc
unsigned long unsigned long tbaddr tbaddr 0x80000L fdcRw
int volatile int timeOut timeOut 0 waitFdc

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: fdc_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<isa/fdc.h>
    #include<isa/8259.h>
    #include<sys/video.h>
    #include<sys/gdt.h>
    #include<sys/idt.h>
    #include<ubixos/types.h>
    #include<ubixos/spinlock.h>
    #include<sys/io.h>
    #include<sys/dma.h>
    #include<sys/device.h>
    #include<lib/kprintf.h>
    #include<lib/kmalloc.h>
    #include<devfs/devfs.h>

    staticspinLock_tfdcSpinLock=SPIN_LOCK_INITIALIZER;

    staticvolatilebooldone=FALSE;
    staticdrvGeomgeometry={dg144Heads,dg144Tracks,dg144Spt};
    staticbooldiskChange=FALSE;
    staticboolmotor=FALSE;
    staticvolatileInt8fdcTrack=0xff;
    staticInt8sr0=0;
    staticvolatileinttimeOut=0;
    staticInt8statSize=0;
    staticInt8status[7]={0};

    unsignedlongtbaddr=0x80000L;

    intfdcInit2(structdevice_node*dev){
    dev->devInfo->size=(1024*1450);
    return(0x0);
    }

    intfdc_init(){
    structdevice_interface*devInfo=(structdevice_interface*)kmalloc(sizeof(structdevice_interface));
    setVector(floppyIsr,mVec+6,(dInt+dPresent));
    irqEnable(6);
    reset();
    devInfo->major=0x0;
    devInfo->init=(void*)&fdcInit2;
    devInfo->read=fdcRead;
    devInfo->write=fdcWrite;
    devInfo->reset=(void*)reset;

    device_add(0,'c',devInfo);
    devfs_makeNode("fd0",'b',0x0,0x0);
    return(0x0);
    }

    asm(
    ".globlfloppyIsr\n"
    "floppyIsr:\n"
    "pusha\n"
    "push%ss\n"
    "push%ds\n"
    "push%es\n"
    "push%fs\n"
    "push%gs\n"
    "callfloppyIsrhndlr\n"
    "pop%gs\n"
    "pop%fs\n"
    "pop%es\n"
    "pop%ds\n"
    "pop%ss\n"
    "popa\n"
    "iret\n"
    );

    voidfloppyIsrhndlr(){
    done=TRUE;
    outportByte(0x20,0x20);
    }

    voidsendByte(intInt8){
    volatileintmsr;
    inttmo;
    for(tmo=0;tmo<128;tmo++){
    msr=inportByte(fdcMsr);
    if((msr&0xc0)==0x80){
    outportByte(fdcData,Int8);
    return;
    }
    inportByte(0x80);
    }
    }

    intgetByte(){
    volatileintmsr;
    inttmo;
    for(tmo=0;tmo<128;tmo++){
    msr=inportByte(fdcMsr);
    if((msr&0xd0)==0xd0){
    returninportByte(fdcData);
    }
    inportByte(0x80);
    }
    return(-1);
    }

    boolfdcRw(intblock,Int8*blockBuffer,boolread,unsignedlongnumSectors){
    inthead=0x0,track=0x0,sector=0x0,tries=0x0,copyCount=0x0;
    unsignedchar*p_tbaddr=(char*)0x80000;
    unsignedchar*p_blockbuff=blockBuffer;
    //kprintf("Block:[%i]\n",block);
    block2Hts(block,&head,&track,&sector);
    motorOn();
    if(!read&&blockBuffer){
    /*copydatafromdatabufferintotrackbuffer*/
    for(copyCount=0;copyCount<(numSectors*512);copyCount++){
    *p_tbaddr=*p_blockbuff;
    p_blockbuff++;
    p_tbaddr++;
    }
    }
    for(tries=0;tries<3;tries++){
    if(inportByte(fdcDir)&0x80){
    diskChange=TRUE;
    seek(1);/*clear"diskchange"status*/
    recalibrate();
    motorOff();
    kprint("FDC:Diskchangedetected.Tryingagain.\n");
    returnfdcRw(block,blockBuffer,read,numSectors);
    }
    if(!seek(track)){
    motorOff();
    kprintf("FDC:Errorseekingtotrack[%i]\n",block);
    returnFALSE;
    }
    outportByte(fdcCcr,0);
    if(read){
    dmaXfer(2,tbaddr,numSectors*512,FALSE);
    sendByte(cmdRead);
    }
    else{
    dmaXfer(2,tbaddr,numSectors*512,TRUE);
    sendByte(cmdWrite);
    }
    sendByte(head<<2);
    sendByte(track);
    sendByte(head);
    sendByte(sector);
    sendByte(2);/*512Int8s/sector*/
    sendByte(geometry.spt);
    if(geometry.spt==dg144Spt){
    sendByte(dg144Gap3rw);/*gap3sizefor1.44Mread/write*/
    }
    else{
    sendByte(dg168Gap3rw);/*gap3sizefor1.68Mread/write*/
    }
    sendByte(0xff);/*DTL=unused*/
    if(!waitFdc(TRUE)){
    kprint("Timedout,tryingoperationagainafterreset()\n");
    reset();
    returnfdcRw(block,blockBuffer,read,numSectors);
    }
    if((status[0]&0xc0)==0)break;/*worked!outtahere!*/
    recalibrate();/*oops,tryagain...*/
    }
    motorOff();
    if(read&&blockBuffer){
    p_blockbuff=blockBuffer;
    p_tbaddr=(char*)0x80000;
    for(copyCount=0x0;copyCount<(numSectors*512);copyCount++){
    *p_blockbuff=*p_tbaddr;
    p_blockbuff++;
    p_tbaddr++;
    }
    }
    return(tries!=3);
    }

    voidblock2Hts(intblock,int*head,int*track,int*sector){
    *head=(block%(geometry.spt*geometry.heads))/(geometry.spt);
    *track=block/(geometry.spt*geometry.heads);
    *sector=block%geometry.spt+1;
    }

    voidmotorOn(void){
    if(motor==FALSE){
    outportByte(fdcDor,0x1c);
    motor=TRUE;
    }
    }

    voidmotorOff(void){
    if(motor==TRUE){
    //outportByte(fdcDor,0x0);
    //outportByte(fdcDor,0x0C);
    motor=FALSE;
    }
    }

    boolseek(inttrack){
    if(fdcTrack==track){
    return(TRUE);
    }
    sendByte(cmdSeek);
    sendByte(0);
    sendByte(track);
    if(!waitFdc(TRUE)){
    kprintf("waitfdcfailed\n");
    return(FALSE);
    }
    if((sr0!=0x20)||(fdcTrack!=track)){
    return(FALSE);
    }
    else{
    return(TRUE);
    }
    }

    boolreadBlock(intblock,Int8*blockBuffer,unsignedlongnumSectors){
    intresult=0x0,loop=0x0;
    if(numSectors>1){
    for(loop=0;loop<numSectors;loop++){
    result=fdcRw(block+loop,blockBuffer+(loop*512),TRUE,1);
    }
    returnresult;
    }
    returnfdcRw(block,blockBuffer,TRUE,numSectors);
    }

    boolwriteBlock(intblock,Int8*blockBuffer,unsignedlongnumSectors){
    returnfdcRw(block,blockBuffer,FALSE,numSectors);
    }

    boolwaitFdc(boolsensei){
    timeOut=50000;
    while(!done&&timeOut);
    statSize=0;
    while((statSize<7)&&(inportByte(fdcMsr)&(1<<4))){
    status[(int)statSize++]=getByte();
    }
    if(sensei){
    sendByte(cmdSensei);
    sr0=getByte();
    fdcTrack=getByte();
    }
    done=FALSE;
    if(!timeOut){
    if(inportByte(fdcDir)&0x80){
    diskChange=TRUE;
    }
    return(FALSE);
    }
    else{
    return(TRUE);
    }
    }

    voidrecalibrate(void){
    motorOn();
    sendByte(cmdRecal);
    sendByte(0);
    waitFdc(TRUE);
    motorOff();
    }

    voidreset(void){
    outportByte(fdcDor,0);
    motor=FALSE;
    outportByte(fdcDor,0x0c);
    done=TRUE;
    waitFdc(TRUE);
    sendByte(cmdSpecify);
    sendByte(0xdf);
    sendByte(0x02);
    seek(1);
    recalibrate();
    diskChange=FALSE;
    return;
    }

    voidfdcRead(void*info,void*baseAddr,uInt32startSector,uInt32sectorCount){
    spinLock(&fdcSpinLock);
    readBlock(startSector,baseAddr,sectorCount);
    spinUnlock(&fdcSpinLock);
    return;
    }
    voidfdcWrite(void*info,void*baseAddr,uInt32startSector,uInt32sectorCount){
    writeBlock(startSector,baseAddr,sectorCount);
    return;
    }

    /***

    $Log: fdc_8c.xml,v $
    Revision 1.6  2006/12/19 14:12:51  reddawg
    rtld-elf almost workign

    Revision1.1.1.12006/06/0112:46:12reddawg
    ubix2

    Revision1.22005/10/1200:13:37reddawg
    Removed

    Revision1.1.1.12005/09/2617:24:01reddawg
    nomessage

    Revision1.242004/09/0721:54:38reddawg
    okrevertedbacktooldschedulingfornow....

    Revision1.232004/09/0615:13:25reddawg
    LastcommitbeforeFreeBSD6.0

    Revision1.222004/08/2120:06:28reddawg
    okcheckoutexec.c

    Revision1.212004/08/1516:47:49reddawg
    Fixed

    Revision1.202004/08/1500:33:02reddawg
    Wowtheidedriverworksagain

    Revision1.192004/08/0120:40:45reddawg
    Netrelatedfixes

    Revision1.182004/07/2921:32:16reddawg
    Myquicklunchsbreaksworthofupdates....

    Revision1.172004/07/2708:03:36reddawg
    chg:stoppedpushalltheseextraregistersIcan'tfindagoodreasonastowhyIwasdoingit

    Revision1.162004/07/2217:32:25reddawg
    Ibrokeithopefully

    Revision1.152004/07/2110:02:09reddawg
    devfs:renamedfunctions
    devicesystem:renamedfunctions
    fdc:fixedafewpotentialbugsandcleanedupsomeunusedvariables
    strol:fixeddefinition
    endtask:madeitprintoutfreepagedebuginfo
    kmalloc:fixedahugememoryleakwehadsomeunhandleddescriptorinsertionsosomedescriptorswerelost
    ld:fixedapointerconversion
    file:cleanedupafewunusedvariables
    sched:broketaskdeletion
    kprintf:fixedogPrintfdefinition

    Revision1.142004/07/1702:38:31reddawg
    Fixedafewproblems

    Revision1.132004/07/1412:42:46reddawg
    fdc:fdcInittofdc_init
    ChangedStartupRoutines

    Revision1.122004/06/0410:19:42reddawg
    notes:wecompileagain,thankg-danywaysiwasabouttocry

    Revision1.112004/05/2022:51:09reddawg
    CleanedUpWarnings

    Revision1.102004/05/1923:36:52reddawg
    BugFixes

    Revision1.92004/05/1915:31:27reddawg
    Fixeduptherestofthereferences

    Revision1.82004/05/1915:26:33reddawg
    Fixedreferenceissuesduetochangesindriversubsystem

    Revision1.72004/05/1002:23:24reddawg
    MinorChangesToSourceCodeToPrepareItForOpenSourceRelease

    Revision1.62004/04/3014:16:04reddawg
    FixedallthedatatypestobeconsistantuInt8,uInt16,uInt32,Int8,Int16,Int32

    Revision1.52004/04/2915:29:20reddawg
    FixedAllRunningIssues

    Revision1.42004/04/2802:22:54reddawg
    Thisisafiarlylargecommitbutwearestartingtousenewdrivermodel
    allaround

    Revision1.32004/04/2622:22:33reddawg
    DevFSnowusescorrectsizeofdevice

    Revision1.22004/04/2221:20:05reddawg
    FDCnowaddsdrivestothedevfs

    Revision1.1.1.12004/04/1512:07:09reddawg
    UbixOSv1.0

    Revision1.62004/04/1316:36:33reddawg
    Changedourcopyright,itisallnowunderaBSD-Stylelicense

    END
    ***/