Fix bug: Disk driver not working for slave drive
This commit is contained in:
parent
78bea1f8bb
commit
1705096d91
2
makefile
2
makefile
|
|
@ -19,7 +19,7 @@ all: bootloader tools kernel
|
||||||
sudo mkdir mount/sys # for system files
|
sudo mkdir mount/sys # for system files
|
||||||
# ./diskwrite -v -o image.bin
|
# ./diskwrite -v -o image.bin
|
||||||
# ./diskwrite -v -l kernel.elf idm.elf -o image.bin
|
# ./diskwrite -v -l kernel.elf idm.elf -o image.bin
|
||||||
qemu-system-i386 -hda image.bin -hdb test.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio -D intlog.txt -d int
|
qemu-system-i386 -hda image.bin -hdc test.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio -D intlog.txt -d int
|
||||||
sudo umount mount
|
sudo umount mount
|
||||||
|
|
||||||
tools:
|
tools:
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ uint32_t pm_alloc(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t pm_alloc_index(uint32_t index){
|
uint32_t pm_alloc_index(uint32_t index){
|
||||||
for(uint32_t i = index; i < 2; i++){
|
// printf("%x\n", index);
|
||||||
|
for(uint32_t i = index; i < index + 2; i++){
|
||||||
for(int j = 0; j < 8; j++){
|
for(int j = 0; j < 8; j++){
|
||||||
// if(!(pm_map[i] & (1 << j))){
|
// if(!(pm_map[i] & (1 << j))){
|
||||||
pm_map[i] |= (1 << j);
|
pm_map[i] |= (1 << j);
|
||||||
|
|
@ -36,19 +37,23 @@ uint32_t pm_alloc_index(uint32_t index){
|
||||||
}
|
}
|
||||||
uint32_t pm_alloc_64kaligned(){
|
uint32_t pm_alloc_64kaligned(){
|
||||||
uint32_t cont = 0;
|
uint32_t cont = 0;
|
||||||
|
uint32_t current = 0;
|
||||||
for(uint32_t i = 0; i < mmap_count; i++){
|
for(uint32_t i = 0; i < mmap_count; i++){
|
||||||
|
// printf("Index: %x\n", i);
|
||||||
for(int j = 0; j < 8; j++){
|
for(int j = 0; j < 8; j++){
|
||||||
if(!(pm_map[i] & (1 << j))){
|
if(!(pm_map[i] & (1 << j))){
|
||||||
continue;
|
continue;
|
||||||
}else{
|
}else{
|
||||||
j++;
|
// j++;
|
||||||
cont = -1;
|
cont = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(cont == 1){
|
if(cont == 1){
|
||||||
return pm_alloc_index(i);
|
// printf("Allocating index: %x (%x)\n", i, pm_map[i]);
|
||||||
|
return pm_alloc_index(current);
|
||||||
}
|
}
|
||||||
|
current = i;
|
||||||
cont++;
|
cont++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -282,9 +282,10 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
||||||
uint16_t io_base = drive.BARs[0] >> 2;
|
uint16_t io_base = drive.BARs[0] >> 2;
|
||||||
uint16_t ctrl_base = drive.BARs[1] >> 2;
|
uint16_t ctrl_base = drive.BARs[1] >> 2;
|
||||||
uint16_t bm_base = drive.BARs[4] & ~3;
|
uint16_t bm_base = drive.BARs[4] & ~3;
|
||||||
|
|
||||||
|
|
||||||
PRD_T *prdt = drive.PRDT;
|
PRD_T *prdt = drive.PRDT;
|
||||||
|
api(MODULE_API_PRINT, MODULE_NAME, "%x, %x, %x, %x\n", io_base, ctrl_base, bm_base, api(MODULE_API_PADDR, prdt));
|
||||||
uint32_t pages = (count + 4095) / 4096;
|
uint32_t pages = (count + 4095) / 4096;
|
||||||
|
|
||||||
uint32_t sector_count = pages*8;
|
uint32_t sector_count = pages*8;
|
||||||
|
|
@ -347,7 +348,7 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
||||||
|
|
||||||
uint8_t status = inb(ctrl_base);
|
uint8_t status = inb(ctrl_base);
|
||||||
uint8_t bm_status = inb(bm_base + 2);
|
uint8_t bm_status = inb(bm_base + 2);
|
||||||
// api(MODULE_API_PRINT, MODULE_NAME, "Status: (ATA)%x, (Busmaster)%x\n", status, bm_status);
|
api(MODULE_API_PRINT, MODULE_NAME, "Status: (ATA)%x, (Busmaster)%x\n", status, bm_status);
|
||||||
// if(ATA_ABRT(status)){
|
// if(ATA_ABRT(status)){
|
||||||
// puts(api, MODULE_NAME, "Command aborted\n");
|
// puts(api, MODULE_NAME, "Command aborted\n");
|
||||||
// return -1;
|
// return -1;
|
||||||
|
|
@ -498,28 +499,34 @@ void ide_init(uint32_t BARS[5]){
|
||||||
}
|
}
|
||||||
drives[primary_index].BARs[4] = BARS[4];
|
drives[primary_index].BARs[4] = BARS[4];
|
||||||
drives[primary_slave_index].BARs[4] = BARS[4];
|
drives[primary_slave_index].BARs[4] = BARS[4];
|
||||||
|
drives[primary_slave_index].flags.slave = 1;
|
||||||
drives[secondary_index].BARs[4] = BARS[4];
|
drives[secondary_index].BARs[4] = BARS[4];
|
||||||
drives[secondary_slave_index].BARs[4] = BARS[4];
|
drives[secondary_slave_index].BARs[4] = BARS[4];
|
||||||
|
drives[secondary_slave_index].flags.slave = 1;
|
||||||
|
|
||||||
uint32_t prdt_primary_paddr = api(MODULE_API_PMALLOC64K);
|
uint32_t prdt_primary_paddr = api(MODULE_API_PMALLOC64K);
|
||||||
|
uint32_t prdt_primary_slave_paddr = api(MODULE_API_PMALLOC64K);
|
||||||
uint32_t prdt_secondary_paddr = api(MODULE_API_PMALLOC64K);
|
uint32_t prdt_secondary_paddr = api(MODULE_API_PMALLOC64K);
|
||||||
|
uint32_t prdt_secondary_slave_paddr = api(MODULE_API_PMALLOC64K);
|
||||||
drives[primary_index].PRDT = (void *)api(MODULE_API_KMALLOC_PADDR, prdt_primary_paddr, 16);
|
drives[primary_index].PRDT = (void *)api(MODULE_API_KMALLOC_PADDR, prdt_primary_paddr, 16);
|
||||||
|
drives[primary_slave_index].PRDT = (void *)api(MODULE_API_KMALLOC_PADDR, prdt_primary_slave_paddr, 16);
|
||||||
drives[secondary_index].PRDT = (void *)api(MODULE_API_KMALLOC_PADDR, prdt_secondary_paddr, 16);
|
drives[secondary_index].PRDT = (void *)api(MODULE_API_KMALLOC_PADDR, prdt_secondary_paddr, 16);
|
||||||
|
drives[secondary_slave_index].PRDT = (void *)api(MODULE_API_KMALLOC_PADDR, prdt_secondary_slave_paddr, 16);
|
||||||
//now call ATA IDENTIFY
|
//now call ATA IDENTIFY
|
||||||
uint8_t master_status = ata_identify(primary_index, ATA_MASTER);
|
uint8_t master_status = ata_identify(primary_index, ATA_MASTER);
|
||||||
uint8_t slave_status = ata_identify(primary_slave_index, ATA_SLAVE);
|
uint8_t slave_status = ata_identify(primary_slave_index, ATA_SLAVE);
|
||||||
if(master_status){
|
if(!master_status){
|
||||||
drives[primary_index].type = TYPE_NULL;
|
drives[primary_index].type = TYPE_NULL;
|
||||||
}
|
}
|
||||||
if(slave_status){
|
if(!slave_status){
|
||||||
drives[primary_slave_index].type = TYPE_NULL;
|
drives[primary_slave_index].type = TYPE_NULL;
|
||||||
}
|
}
|
||||||
master_status = ata_identify(secondary_index, ATA_MASTER);
|
master_status = ata_identify(secondary_index, ATA_MASTER);
|
||||||
slave_status = ata_identify(secondary_slave_index, ATA_SLAVE);
|
slave_status = ata_identify(secondary_slave_index, ATA_SLAVE);
|
||||||
if(master_status){
|
if(!master_status){
|
||||||
drives[secondary_index].type = TYPE_NULL;
|
drives[secondary_index].type = TYPE_NULL;
|
||||||
}
|
}
|
||||||
if(slave_status){
|
if(!slave_status){
|
||||||
drives[secondary_slave_index].type = TYPE_NULL;
|
drives[secondary_slave_index].type = TYPE_NULL;
|
||||||
}
|
}
|
||||||
// outb(BARS[4] >> 1, 0x0);
|
// outb(BARS[4] >> 1, 0x0);
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,69 @@
|
||||||
|
|
||||||
KOS_MAPI_FP api;
|
KOS_MAPI_FP api;
|
||||||
|
|
||||||
|
void mount_fat32(vfile_t *dev_file, char *destination){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void detect_partitions(vfile_t *file){
|
void detect_partitions(vfile_t *file){
|
||||||
char *buffer = malloc(api, 1);
|
char *buffer = malloc(api, 1);
|
||||||
// buffer[0] = 5;
|
|
||||||
fread(api, file, buffer, 0, 512);
|
fread(api, file, buffer, 0, 512);
|
||||||
mbr_t *mbr = buffer;
|
mbr_t *mbr = buffer;
|
||||||
|
if(mbr->magic != MBR_MAGIC){
|
||||||
|
puts(api, MODULE_NAME, "No MBR!\n");
|
||||||
|
api(MODULE_API_PRINT, MODULE_NAME, "Magic: %x\n", mbr->magic);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//first: check for filesystem headers (if they exist, register entire drive as fs and return)
|
||||||
|
//then, check partitions.
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
partition_t part = mbr->partitions[i];
|
||||||
|
if(part.type == 0xee){
|
||||||
|
puts(api, MODULE_NAME, "Found gpt\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(part.attributes != 0 || part.attributes != 0x80){
|
||||||
|
//check disk for filesystem
|
||||||
|
api(MODULE_API_PRINT, MODULE_NAME, "No partitions!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//now, re-check for filesystems
|
||||||
|
}
|
||||||
api(MODULE_API_PRINT, MODULE_NAME, "Magic: %x\n", mbr->magic);
|
api(MODULE_API_PRINT, MODULE_NAME, "Magic: %x\n", mbr->magic);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//buffer is a pointer to a string that contains the filename, followed by a comma, followed by the mount destination. If there is no destination [i.e. no comma], command will be treated as unmount
|
||||||
|
int mount(vfile_t *file, char *buffer, uint32_t offset, uint32_t count){
|
||||||
|
char filename_buffer[256];
|
||||||
|
char destination_buffer[256];
|
||||||
|
uint32_t comma_offset = 0;
|
||||||
|
int i = 0;
|
||||||
|
for(; i < 256; i++){
|
||||||
|
if(buffer[i] == ',' || !buffer[i]){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
filename_buffer[i] = buffer[i];
|
||||||
|
}
|
||||||
|
filename_buffer[i] = 0;
|
||||||
|
comma_offset = i + 1;
|
||||||
|
i = 0;
|
||||||
|
for(; i < 256; i++){
|
||||||
|
if(buffer[i] == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
destination_buffer[i] = buffer[i];
|
||||||
|
}
|
||||||
|
destination_buffer[i] = 0;
|
||||||
|
vfile_t *src = fopen(api, filename_buffer);
|
||||||
|
if(!src){
|
||||||
|
puts(api, MODULE_NAME, "src does not exist\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int phony_read(vfile_t *file, char*buffer, uint32_t offset, uint32_t count){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void init(KOS_MAPI_FP module_api, uint32_t api_version){
|
void init(KOS_MAPI_FP module_api, uint32_t api_version){
|
||||||
api = module_api;
|
api = module_api;
|
||||||
|
|
@ -24,8 +79,10 @@ void init(KOS_MAPI_FP module_api, uint32_t api_version){
|
||||||
}
|
}
|
||||||
vfile_t **dir_data = disk_dir->access.data.ptr;
|
vfile_t **dir_data = disk_dir->access.data.ptr;
|
||||||
for(uint32_t i = 0; dir_data[i]; i++){
|
for(uint32_t i = 0; dir_data[i]; i++){
|
||||||
|
api(MODULE_API_PRINT, MODULE_NAME, "Filename: %s\n", dir_data[i]->name);
|
||||||
detect_partitions(dir_data[i]);
|
detect_partitions(dir_data[i]);
|
||||||
}
|
}
|
||||||
|
fcreate(api, "/dev/fat32mnt", VFILE_DEVICE, mount, phony_read);
|
||||||
|
// mount(0, "bleh,test", 0, 15);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue