Page 1 of 1

Problems with IDE controller.

Posted: Sat Jun 29, 2013 4:34 pm
by ateno3
Hello everyone!!
I have got problems again, this with IDE controller.
When I try to read something, which was written previously by the same controller, I get nothing in the buffer memory.
The code (that is posted below) is very primitive and it does almost anything: I only can initialize the primary master device
attached, write sectors and read them.
The main code, where I call the IDE-controller funtions, is:

Code: Select all

// ...
if(!IDE_INIT0()){
			DEBUG(false, "IDE cant be initialized :( \n");
			goto halt;
		}
		DEBUG(false, "IDE-controller initialized successfuly:)\n");
		DEBUG(false, "TESTING IDE-CONTROLLER\n");
		DEBUG(false, "Writing \"Hello everyone\" on HD... \n");
		
		u8* sectmp = (u8*) kmalloc (512);
		if(!sectmp){
			DEBUG(false, "I wasnt able to reserve mem for \'sectmp\'\n");
			goto halt;
		}
		
		memset(sectmp, 0x00, 512);
		strcpy((s8*)sectmp, "Hello everyone");
		
		if(IDE_WriteSecs(0, 1, 0, sectmp) != 0x00){
			DEBUG(false, "There was an error while writing\n");
			kfree(sectmp);
			goto halt;
		}
		
		DEBUG(false, "It was written successfuly (?)\n");
		DEBUG(false, "Read sector 0 to verify the writing\n");
		
		memset(sectmp, 0x00, 512);
		
		if(IDE_ReadSecs(0, 1, 0, sectmp) != 0x00){
			DEBUG(false, "There was an error while reading\n");
			kfree(sectmp);
			goto halt;
		}		
		
		DEBUG(false, "It was read successfuly\n");
		DEBUG(false, "%s\n", sectmp);
		
		DEBUG(false, "TEST IDE-CONTROLLER ENDS\n");
//...
Finally, I want to apologize for my English, due to it's no my mother tongue.
PD: The code has got comments, which are in the DEBUG funtions, but they are in Spanish (Sorry... )
ide.h
(1.25 KiB) Downloaded 22 times
ide.c
(22.59 KiB) Downloaded 73 times

Re: Problems with IDE controller.

Posted: Sun Jun 30, 2013 5:06 am
by Combuster
You're trying more things at once than needed. You can just try to read the first sector of any harddisk and check what's in there compared to what you actually put in there and see if that part of the code is contributing to the problem or not.


Also, read the forum rules, use code tags.

Re: Problems with IDE controller.

Posted: Sun Jun 30, 2013 5:45 am
by ateno3
Combuster wrote:You're trying more things at once than needed. You can just try to read the first sector of any harddisk and check what's in there compared to what you actually put in there and see if that part of the code is contributing to the problem or not.


Also, read the forum rules, use code tags.
First of all, thank you for answering my question.
It supposed what I write in the sector must be "Hello everyone", so when I read it again, it must be the same. Moreover, I have checked the harddisk's contents and I've seen what it's written there, and it's "Hello everyone", so the problem is , probably, in the read. That is why I have uploaded the IDE-Controller code.
PD: I think what I've written it's grammatically correct, but I don't know because I've used the translater.

EDIT: Finally, the controller works. I've these changes in the code:

Code: Select all

if(!IDE_INIT0()){
         DEBUG(false, "IDE cant be initialized :( \n");
         goto halt;
      }
      DEBUG(false, "IDE-controller initialized successfuly:)\n");
      DEBUG(false, "TESTING IDE-CONTROLLER\n");
      DEBUG(false, "Writing \"Hello everyone\" on HD... \n");
      
      u8* sectmp = (u8*) kmalloc (512);
      if(!sectmp){
         DEBUG(false, "I wasnt able to reserve mem for \'sectmp\'\n");
         goto halt;
      }
      
      memset(sectmp, 0x00, 512);
      strcpy((s8*)sectmp, "Hello everyone");
      
      if(IDE_WriteSecs(0, 1, 0, sectmp) != 0x00){
         DEBUG(false, "There was an error while writing\n");
         kfree(sectmp);
         goto halt;
      }
      
      DEBUG(false, "It was written successfuly (?)\n");
      DEBUG(false, "Read sector 0 to verify the writing\n");
      
      u8* read = (u8*) kmalloc (512);
      memset(read, 0x00, 512);
      
      if(IDE_ReadSecs(0, 1, 0, read) != 0x00){
         DEBUG(false, "There was an error while reading\n");
         kfree(read);
         kfree(sectmp);
         goto halt;
      }      
      
      DEBUG(false, "It was read successfuly\n");
      DEBUG(false, "%s\n", read);
      
      DEBUG(false, "TEST IDE-CONTROLLER ENDS\n");
//...
I don't know how... I've achieved it to work by changing the variable where I put the read data. Could anyone tell me why??