diff --git a/sys/init/main.c b/sys/init/main.c index 3bdce03..35013b5 100644 --- a/sys/init/main.c +++ b/sys/init/main.c @@ -133,7 +133,7 @@ * * \param rootdev address of root device structure */ -int kmain(uint32_t rootdev) { +int kmain( uint32_t rootdev ) { /* Set up counter for startup routine */ int i = 0x0; @@ -142,9 +142,9 @@ clearScreen(); /* Modify src/sys/include/ubixos/init.h to add a startup routine */ - for ( i = 0x0; i < init_tasksTotal; i++ ) { + for( i = 0x0; i < init_tasksTotal; i++ ) { - if ( init_tasks[i]() != 0x0 ) { + if( init_tasks[i]() != 0x0 ) { kpanic( "Error: Initializing System Task[%i].\n", i ); diff --git a/sys/pci/hd.c b/sys/pci/hd.c index 945a57f..cae7aaa 100644 --- a/sys/pci/hd.c +++ b/sys/pci/hd.c @@ -40,162 +40,217 @@ static hdC = 0; int initHardDisk() { - _initHardDisk(0xE0); - _initHardDisk(0xF0); + + _initHardDisk( 0xE0 ); + _initHardDisk( 0xF0 ); + } -int _initHardDisk(int hdD) { - int i = 0x0; - int x = 0x0; - int minor = 0x0; - struct device_interface *devInfo = 0x0; - struct device_interface *devInfo2 = 0x0; - struct dos_partition *d = 0x0; - struct driveInfo *hdd = 0x0; - struct driveInfo *hdd2 = 0x0; - char *data = 0x0; - char *data2 = 0x0; - char name[16]; - struct bsd_disklabel *bsdd = 0x0; +int _initHardDisk( int hdD ) { - //GPT - char *secbuf = 0x0; + int i = 0x0; + int x = 0x0; + int minor = 0x0; + struct device_interface *devInfo = 0x0; + struct device_interface *devInfo2 = 0x0; + struct dos_partition *d = 0x0; + struct driveInfo *hdd = 0x0; + struct driveInfo *hdd2 = 0x0; + char *data = 0x0; + char *data2 = 0x0; + char name[16]; + struct bsd_disklabel *bsdd = 0x0; - hdd = (struct driveInfo *) kmalloc(sizeof(struct driveInfo)); - hdd->ata_identify = (struct ata_identify_data *) kmalloc(sizeof(struct ata_identify_data)); - hdd->hdPort = 0x1F0; - hdd->hdDev = hdD; //0x40; - hdd->parOffset = 0x0; - hdd->part = 0x2; + //GPT + char *secbuf = 0x0; - /* Alloc memory for device structure and set it up correctly */ - devInfo = (struct device_interface *) kmalloc(sizeof(struct device_interface)); - devInfo->read = (void *) &hdRead; - devInfo->write = (void *) &hdWrite; - devInfo->reset = (void *) &hdReset; - devInfo->init = (void *) &hdInit; - devInfo->ioctl = (void *) &hdIoctl; - devInfo->stop = (void *) &hdStop; - devInfo->start = (void *) &hdStart; - devInfo->standby = (void *) &hdStandby; - devInfo->info = hdd; - devInfo->major = hdC + 0x1; + // Allocate memory for hdd structure + hdd = ( struct driveInfo * ) kmalloc( sizeof( struct driveInfo ) ); - data = (char *) kmalloc(512); - d = (struct dos_partition *) (data + 0x1BE); + hdd->ata_identify = ( struct ata_identify_data * ) kmalloc( sizeof( struct ata_identify_data ) ); + hdd->hdPort = 0x1F0; + hdd->hdDev = hdD; //0x40; + hdd->parOffset = 0x0; + hdd->part = 0x2; - data2 = (char *) kmalloc(512); - bsdd = (struct bsd_disklabel *) data2; + /* Allocate memory for device structure and set it up correctly */ + devInfo = ( struct device_interface * ) kmalloc( sizeof( struct device_interface ) ); - if (device_add(0, 'c', devInfo) == 0x0) { - kprintf("ad%i - Start: [0x0], Size: [0x%x/0x%X]\n", hdC, hdd->hdSize, hdd->hdSize * 512); - sprintf(name, "ad%ip%i", hdC, hdd->part); - devfs_makeNode(name, 'b', 0x1, 0x0); - hdRead(devInfo->info, data, 0x0, 0x1); + devInfo->read = ( void * ) &hdRead; + devInfo->write = ( void * ) &hdWrite; + devInfo->reset = ( void * ) &hdReset; + devInfo->init = ( void * ) &hdInit; + devInfo->ioctl = ( void * ) &hdIoctl; + devInfo->stop = ( void * ) &hdStop; + devInfo->start = ( void * ) &hdStart; + devInfo->standby = ( void * ) &hdStandby; + devInfo->info = hdd; - if (d[0].dp_type == 0xEE) { - // MrOlsen (2016-01-14) DEBUG: This was just to help debug - //kprintf( "%s - Type: [0x%X - %s], Start: [0x%X], Size: [0x%X]\n", name, d[0].dp_type, (d[0].dp_type >= 0 && d[0].dp_type <= 255) ? part_types[d[0].dp_type] : "Unknown", d[0].dp_start, d[0].dp_size ); + devInfo->major = hdC + 0x1; - secbuf = (char *) kmalloc(65536); + data = ( char * ) kmalloc( 512 ); + d = ( struct dos_partition * ) ( data + 0x1BE ); - if (gptread(&freebsd_ufs_uuid, devInfo, secbuf) == -1) { - kprintf("%s: unable to load GPT\n", "KERNEL"); - //return (-1); - } - else { - devInfo2 = (struct device_interface *) kmalloc(sizeof(struct device_interface)); - hdd2 = (struct driveInfo *) kmalloc(sizeof(struct driveInfo)); - memcpy(devInfo2, devInfo, sizeof(struct device_interface)); - memcpy(hdd2, hdd, sizeof(struct driveInfo)); - //hdd2->parOffset = d[i].dp_start; - devInfo2->info = hdd2; - minor++; + data2 = ( char * ) kmalloc( 512 ); + bsdd = ( struct bsd_disklabel * ) data2; - if (gptfind(&freebsd_ufs_uuid, devInfo2, hdd->part) == -1) { - //MrOlsen (2016-01-11) FIX: I am using "1" as partition 1 - kprintf("%s: no UFS partition was found\n", "KERNEL"); - //return (-1); - } + if( device_add( 0, 'c', devInfo ) == 0x0 ) { -//MrOlsen (2016-01-14) DEBUG: This was just debugging code -//kprintf("[%i - %i]\n", hdd->parOffset, hdd2->parOffset); + kprintf( "ad%i - Start: [0x0], Size: [0x%x/0x%X]\n", hdC, hdd->hdSize, hdd->hdSize * 512 ); + sprintf( name, "ad%ip%i", hdC, hdd->part ); + devfs_makeNode( name, 'b', 0x1, 0x0 ); + hdRead( devInfo->info, data, 0x0, 0x1 ); - if (device_add(minor, 'c', devInfo2) == 0x0) { - sprintf(name, "ad%ip%i", hdC, hdd->part); - kprintf("%s - Type: [0x%X - %s], Start: [%i], Offset: [%i], Size: [%i], MM: [%i:%i]\n", name, d[0].dp_type, (d[0].dp_type >= 0 && d[0].dp_type <= 255) ? part_types[d[0].dp_type] : "Unknown", hdd2->lba_start, hdd2->parOffset, hdd2->lba_end - hdd2->lba_start, devInfo->major, minor); - devfs_makeNode(name, 'c', 0x1, minor); - } - } + if( d[0].dp_type == 0xEE ) { - } - else { + // MrOlsen (2016-01-14) DEBUG: This was just to help debug + //kprintf( "%s - Type: [0x%X - %s], Start: [0x%X], Size: [0x%X]\n", name, d[0].dp_type, (d[0].dp_type >= 0 && d[0].dp_type <= 255) ? part_types[d[0].dp_type] : "Unknown", d[0].dp_start, d[0].dp_size ); - for (i = 0x0; i < 0x4; i++) { + secbuf = ( char * ) kmalloc( 65536 ); - //MrOlsen (2016-01-14) DEBUG: This was just debugging code - //kprintf( "Type: 0x%X\n", d[i].dp_type ); + if( gptread( &freebsd_ufs_uuid, devInfo, secbuf ) == -1 ) { - if (d[i].dp_type == 0xEE) - kprintf("Motherfucker Jones! We're GPT.... Lick My Nuts Now Bitch!\n"); + kprintf("%s: unable to load GPT\n", "KERNEL"); - if (d[i].dp_type != 0x0) { - devInfo2 = (struct device_interface *) kmalloc(sizeof(struct device_interface)); - hdd2 = (struct driveInfo *) kmalloc(sizeof(struct driveInfo)); - memcpy(devInfo2, devInfo, sizeof(struct device_interface)); - memcpy(hdd2, hdd, sizeof(struct driveInfo)); - hdd2->parOffset = d[i].dp_start; - devInfo2->info = hdd2; - minor++; + //return (-1); - if (device_add(minor, 'c', devInfo2) == 0x0) { - sprintf(name, "ad%is%i", hdC, i + 1); - kprintf("%s - Type: [0x%X - %s], Start: [0x%X], Size: [0x%X], MM: [%i:%i]\n", name, d[i].dp_type, (d[i].dp_type >= 0 && d[i].dp_type <= 255) ? part_types[d[i].dp_type] : "Unknown", d[i].dp_start, d[i].dp_size, devInfo->major, minor); + } else { - devfs_makeNode(name, 'c', 0x1, minor); + devInfo2 = (struct device_interface *) kmalloc(sizeof(struct device_interface)); - if (d[i].dp_type == 0xA5) { - //Why do i need to add 1? - hdRead(devInfo->info, data2, d[i].dp_start + 1, 0x1); + hdd2 = (struct driveInfo *) kmalloc(sizeof(struct driveInfo)); - for (x = 0; x < bsdd->d_npartitions; x++) { - if (bsdd->d_partitions[x].p_size > 0) { - sprintf(name, "ad%is%i%c", hdC, i + 1, 'a' + x); - //New Nodes - devInfo2 = (struct device_interface *) kmalloc(sizeof(struct device_interface)); - hdd2 = (struct driveInfo *) kmalloc(sizeof(struct driveInfo)); - memcpy(devInfo2, devInfo, sizeof(struct device_interface)); - memcpy(hdd2, hdd, sizeof(struct driveInfo)); - //hdd2->parOffset = d[i].dp_start + bsdd->d_partitions[x].p_offset; - hdd2->lba_start = d[i].dp_start; - hdd2->parOffset = bsdd->d_partitions[x].p_offset; - devInfo2->info = hdd2; - minor++; - device_add(minor, 'c', devInfo2); - devfs_makeNode(name, 'c', 0x1, minor); - kprintf("%s - Type: [%s], Start: [0x%X], Size: [0x%X], MM: [%i:%i]\n", name, fstypenames[bsdd->d_partitions[x].p_fstype], bsdd->d_partitions[x].p_offset, bsdd->d_partitions[x].p_size, devInfo->major, minor); - } + memcpy(devInfo2, devInfo, sizeof(struct device_interface)); - } + memcpy(hdd2, hdd, sizeof(struct driveInfo)); - } + //hdd2->parOffset = d[i].dp_start; - } + devInfo2->info = hdd2; - } + minor++; - } - } - } - kfree(data); - hdC++; - return (0x0); + + if( gptfind( &freebsd_ufs_uuid, devInfo2, hdd->part ) == -1 ) { + + //MrOlsen (2016-01-11) FIX: I am using "1" as partition 1 + kprintf("%s: no UFS partition was found\n", "KERNEL"); + //return (-1); + + } + + //MrOlsen (2016-01-14) DEBUG: This was just debugging code + //kprintf("[%i - %i]\n", hdd->parOffset, hdd2->parOffset); + + if( device_add( minor, 'c', devInfo2 ) == 0x0 ) { + + sprintf(name, "ad%ip%i", hdC, hdd->part); + kprintf("[%s] - Type: [0x%X - %s], Start: [%i], Offset: [%i], Size: [%i], MM: [%i:%i]\n", name, d[0].dp_type, (d[0].dp_type >= 0 && d[0].dp_type <= 255) ? part_types[d[0].dp_type] : "Unknown", hdd2->lba_start, hdd2->parOffset, hdd2->lba_end - hdd2->lba_start, devInfo->major, minor); + devfs_makeNode(name, 'c', 0x1, minor); + + } + + } + + } else { + + for( i = 0x0; i < 0x4; i++ ) { + + //MrOlsen (2016-01-14) DEBUG: This was just debugging code + //kprintf( "Type: 0x%X\n", d[i].dp_type ); + + if( d[i].dp_type == 0xEE ) + kprintf("Motherfucker Jones! We're GPT.... Lick My Nuts Now Bitch!\n"); + + if( d[i].dp_type != 0x0 ) { + + devInfo2 = (struct device_interface *) kmalloc(sizeof(struct device_interface)); + hdd2 = (struct driveInfo *) kmalloc(sizeof(struct driveInfo)); + memcpy(devInfo2, devInfo, sizeof(struct device_interface)); + memcpy(hdd2, hdd, sizeof(struct driveInfo)); + hdd2->parOffset = d[i].dp_start; + devInfo2->info = hdd2; + minor++; + + if( device_add( minor, 'c', devInfo2 ) == 0x0 ) { + + sprintf(name, "ad%is%i", hdC, i + 1); + + kprintf("<%s> - Type: [0x%X - %s], Start: [0x%X], Size: [0x%X], MM: [%i:%i]\n", name, d[i].dp_type, (d[i].dp_type >= 0 && d[i].dp_type <= 255) ? part_types[d[i].dp_type] : "Unknown", d[i].dp_start, d[i].dp_size, devInfo->major, minor); + + + devfs_makeNode(name, 'c', 0x1, minor); + + + if( d[i].dp_type == 0xA5 ) { + + //Why do i need to add 1? + hdRead(devInfo->info, data2, d[i].dp_start + 1, 0x1); + + for( x = 0; x < bsdd->d_npartitions; x++ ) { + + if( bsdd->d_partitions[x].p_size > 0 ) { + + sprintf( name, "ad%is%i%c", hdC, i + 1, 'a' + x ); + + //New Nodes + devInfo2 = (struct device_interface *) kmalloc(sizeof(struct device_interface)); + hdd2 = (struct driveInfo *) kmalloc(sizeof(struct driveInfo)); + + memcpy(devInfo2, devInfo, sizeof(struct device_interface)); + + memcpy(hdd2, hdd, sizeof(struct driveInfo)); + + //hdd2->parOffset = d[i].dp_start + bsdd->d_partitions[x].p_offset; + + hdd2->lba_start = d[i].dp_start; + + hdd2->parOffset = bsdd->d_partitions[x].p_offset; + + devInfo2->info = hdd2; + + minor++; + + device_add(minor, 'c', devInfo2); + + devfs_makeNode(name, 'c', 0x1, minor); + + kprintf("{%s} - Type: [%s], Start: [0x%X], Size: [0x%X], MM: [%i:%i]\n", name, fstypenames[bsdd->d_partitions[x].p_fstype], bsdd->d_partitions[x].p_offset, bsdd->d_partitions[x].p_size, devInfo->major, minor); + + } + + + } + + + } + + + } + + + } + + + } + + } + + } + + kfree(data); + + hdC++; + + return (0x0); + } int hdStandby() { /* Not Implemented */ return (0x0); + } int hdStart() {