1

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!

amanuel2
  • 4,508
  • 4
  • 36
  • 67
  • 1
    I'm curious if you ever attempted to use the GDB/QEMU debug setup instructions that I suggested as en edit to my previous answer (See the section _Setting up QEMU Debugging with your Kernel_) : http://stackoverflow.com/a/39560832/3857942 . Does actively debugging mean you actually stepped through the code using an actual debugger? – Michael Petch Sep 24 '16 at 03:37
  • @MichaelPetch Yeah ! There is this super cool osdev tutorial called brokenthorn.. I wish he was there at #osdev , but he explains how to use Bochs Debugger. so yeah ive done that , and also a lot of manual debugging. – amanuel2 Sep 24 '16 at 03:40
  • The advantage to QEMU/GDB is that you can see your source code in the debugger. You can break on function names, view variables by name. View data structures, classes etc. BOCHs is very limited in that regard. If you use CodeBlocks(which you don't but it is a nice IDE) it is even possible to build your kernel in that environment and remote debug it via GDB as well. – Michael Petch Sep 24 '16 at 03:46
  • @MichaelPetch im not really good at terminal debugging. I prefer a GUI Debugger. I havent heard of a GDB GUI Debugger – amanuel2 Sep 24 '16 at 03:48
  • Codeblocks is a GUI front end that integrates with GDB. _DDD_ is a graphical front end to GDB (and my previous answer actually mentions the commands to get _DDD_ running). The GUI on DDD isn't the best, but if you know what you are doing you can get it all going in Codeblocks. http://www.codeblocks.org/ . It is also possible to remote debug via [Eclipse C/C++ Development Tools](https://eclipse.org/cdt/) working but I find it a bit problematic to get going. – Michael Petch Sep 24 '16 at 03:51
  • @MichaelPetch [This](https://www.youtube.com/watch?v=Jab1qj_QR8s) is what you mean by Code Blocks Debugging ? I have to sleep soon. – amanuel2 Sep 24 '16 at 03:57
  • Well that is Codeblocks but that doesn't show you how to set up Codeblocks with a custom Makefile like the one you generated by hand) and doesn't show you how to do remote debugging to QEMU. – Michael Petch Sep 24 '16 at 04:01
  • @MichaelPetch Any tutorial that shows that? And by the way we are on a different topic from the question being asked :/ .. I have to sleep now – amanuel2 Sep 24 '16 at 04:04
  • But to be honest command line debugging is actually pretty easy, and the easiest to get going. I don't think it is a good excuse that you don't like terminal debugging as a reason to avoid it for kernels. Most of the problems I have found were done in most part because I actually load your kernel into GDB/QEMU (even at the command line) and simply step through the code and set breakpoints. It is a disservice to yourself by not taking advantage of a valuable tool and I think if you started using tools for debugging you will constantly be on SO asking us to debug for you. – Michael Petch Sep 24 '16 at 04:04
  • 1
    I am responding to the very last thing in your question "**Any Tips** or Help Would Be Greatly Appreciated!" I am giving you tips. use a debugger. i have given you links to an answer that shows how to setup DDD and/or GDB. You asked for tips and I am giving you the best ones possible. You refuse to accept to this day that using a debugger is at all useful, and it is in fact the very tool I use on your kernel to debug it for you. If you learned to do it, then you can probably solve most of these issues yourself. I am actually doing what I can to help you, but alas you ignore the advice. – Michael Petch Sep 24 '16 at 04:05
  • 1
    @MichaelPetch: A couple months ago, I had a similar experience with this guy in SO's asm chat room. He kept asking me questions and half the time would beg for more explanation without even taking the time to carefully read my answers (or the links in them), let alone use them as a springboard to search on those terms and learn more. IIRC, he's 15. I think he eventually started reading [Programming from the Ground up](http://savannah.nongnu.org/projects/pgubook/) after about the 10th time people told him to read something instead of asking bad questions all the time. – Peter Cordes Sep 24 '16 at 04:24
  • @PeterCordes : I am aware of his age, and that number is the one he has given. The OSDev community in IRC chat (`#OSDev`) has tried to help him as well. I've answered a number of his SO questions, but using SO as a debug service is not helping anyone. Now with this answer I know what his problem is (have a solution) but it is now time for him to use the proper tools - a debugger. I have been harping on it for 6-7 weeks now and now it is time to get him to debug this himself. I've just become an enabler that does no one any good. – Michael Petch Sep 24 '16 at 04:27
  • 2
    I want amanuel2 to succeed. He just needs to taking any good advice seriously. – Michael Petch Sep 24 '16 at 04:29
  • @PeterCordes . Ok in the middle of my calc work i see this comment.. Lets see your response. " I had a similar experience with this guy in SO's asm chat room. He kept asking me questions and half the time would beg for more explanation without even ... " . Seriously? This was months ago , When i barely even knew what a kernel was . right now i am much better in assembly than i was before . And i can research on my own , the only real difficulty i am having is using a debugger like Michael said. – amanuel2 Sep 24 '16 at 19:02
  • @PeterCordes "I think he eventually started reading Programming from the Ground up after about the 10th time people told him to read something instead of asking bad questions all the time" . First of all 10th time? ok . Also im not gonna finish that because first of all I hate GAS Syntax , and second of all i barely will use anything above chapter 3 which tells me about reading files , which i will have to implement my own using system calls. " beg for more explanation" ... – amanuel2 Sep 24 '16 at 19:03
  • @PeterCordes Your taking stuff that happened months ago , and trying to accuse me of what happened long time ago.. What a cheap move.. (Im trying extremely hard to be nice here) . Please if you are not gonna be constructive dont respond . Thankyou. – amanuel2 Sep 24 '16 at 19:03
  • 1
    @MichaelPetch Ok .. Yea im gonna spend couple days on how to figuring out how to work with debugger like GDB . And Hopefully figure out this problem. And thanks for giving me tips and helping me succeed. – amanuel2 Sep 24 '16 at 19:04
  • @MichaelPetch ok I'm better than before at debugging. I will exercise my debugging skills today to , to get very familiar with this , as this will be an essential skill for osdev . And then tomorrow try to find the error with this . key : symbol-file : BoneOS.bin :) – amanuel2 Sep 25 '16 at 20:56
  • @MichaelPetch if you can tell me how to view a full variable even if it is too long , that would be great .. :) – amanuel2 Sep 25 '16 at 22:20
  • @amanuel2 You'd have to give me an example of a variable in your OS. It is a bit unclear what you are asking. – Michael Petch Sep 25 '16 at 22:58
  • @MichaelPetch it's like a char*.. For example char* data argument in Write28() . That character is sometimes real big. And when I do `p data` it will give me like : Blshblahblah/CEFBlshnlshblah... Notice. The three dots, it gives me. Some characters and three dots to say and more.. How do I make it so I see the full variable? – amanuel2 Sep 25 '16 at 23:06
  • The other alternative that may be better is to issue this command `set print elements 0` and then do `p data` . The set print elements with a value zero should remove the limit on the total number of elements to print. The default I believe is around 200. 0 makes it unlimited. – Michael Petch Sep 25 '16 at 23:13
  • @MichaelPetch Any other tips you can give me? Ive been debbuging for some time now with GDB – amanuel2 Sep 27 '16 at 21:38

0 Answers0