Problems with IDE controller.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

Problems with IDE controller.

Post 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 72 times
Last edited by ateno3 on Sun Jun 30, 2013 5:22 am, edited 2 times in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problems with IDE controller.

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

Re: Problems with IDE controller.

Post 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??
Post Reply