I have a problem with this Write28() function i have , which writes to ATA Driver(HDD Driver) , in 28 Bit PIO Mode. Well , first you can see in my kernel.c++ here i call it:
ret_chr_arr file_contents=filealgo.File_to_char(sampleFile);
ret_chr_arr math_wkst_file= filealgo.File_to_char(anotherSampleFile);
ret_chr_arr file_1_contents = filealgo.File_to_char(file1);
ret_chr_arr file_2_contents = filealgo.File_to_char(file2);
ret_chr_arr file_3_contents = filealgo.File_to_char(file3);
char* res_default = Lib::str::strcat(file_contents.str,math_wkst_file.str);
res_default = Lib::str::strcat(res_default,file_1_contents.str);
res_default = Lib::str::strcat(res_default,file_2_contents.str);
res_default = Lib::str::strcat(res_default,file_3_contents.str);
//printf("\nres_default %s",res_default);
vata.return_ata().Write28(0, res_default,0, Lib::str::strlen(res_default));
vata.return_ata().Flush();
This totally works, and writes to Hard Drive... But then .. here is where the issue comes... I am making a command mkfile (for which now just default to generatedFile for the filename) , which writes to the ATA Driver also.
File tempFile;
tempFile.header.name = "FileGenerated";
ret_chr_arr file_contents_temp=filealgo.File_to_char(tempFile);
result_sector_one = Lib::str::strcat(result_sector_one,file_contents_temp.str);
vata.return_ata().Write28(0, result_sector_one,0, Lib::str::strlen(result_sector_one));
vata.return_ata().Flush();
printf("\n%s\n",vata.return_ata().Read28(0));
Interesting enough this happened to me in Read28 where I couldn't call Read28 more than once ... and that was because of the warning I previously by @millenburg about returning a pointer to a local variable.. basically return (char*) str .. when str is an array. I erased that it seemed to work... But write28() doesn't use that either.. I have spent several times trying to debug this and work it out , but it won't work. Here is a video if anyone is interested in more Information . Here is my Write28 Function:
void AdvancedTechnologyAttachment::Write28(uint8_t sectorNum, char* data, uint32_t start, uint32_t count)
{
if(!(accesible))
{
printf("Failed : Not Accessible");
return;
}
//Larger Addressing Than 28
//check first 4 bits are 0
if(sectorNum > 0x0FFFFFFF)
{
printf("ERR");
return;
}
if(count>512)
{
printf("ERR");
return;
}
//Identify What
//Drive You want to comunicate with
//MASTER || SLAVE
if(this->type == MASTER)
p8b.out(0xE0 | ((sectorNum & 0x0F000000) >> 24),port_def + 0x6);
else
p8b.out(0xF0 | ((sectorNum & 0x0F000000) >> 24),port_def + 0x6);
p8b.out(0,port_def + 0x1);
p8b.out(1,port_def + 0x2);
p8b.out( sectorNum & 0x000000FF,port_def + 0x3);
p8b.out((sectorNum & 0x0000FF00) >> 8,port_def + 0x4);
p8b.out((sectorNum & 0x00FF0000) >> 16,port_def + 0x5);
p8b.out(0x30,port_def + 0x7); //WRITE COMMAND
for(uint32_t i = start; i < count; i += 2)
{
uint16_t wdata = data[i];
if(i+1 < count)
wdata |= ((uint16_t)data[i+1]) << 8;
p16b.out(wdata,port_def);
char *text = " \0";
text[0] = (wdata >> 8) & 0xFF;
text[1] = wdata & 0xFF;
// printf(text);
}
for(int i = count + (count%2); i < 512; i += 2)
p16b.out(0x0000,port_def);
}
.. I have shown Minimal Code Possible so if you want even more info , Take a look at my source code (ata.c++ for ata code) : https://github.com/amanuel2/OS_Mirror . I'm trying to find this bug actively , but I am not succeeding :( . Any Tips or Help Would Be Greatly Appreciated!