OSDev Wiki ATA read/write sectors code not working right

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
iProgramInCpp
Member
Member
Posts: 81
Joined: Sun Apr 21, 2019 7:39 am

OSDev Wiki ATA read/write sectors code not working right

Post by iProgramInCpp »

https://wiki.osdev.org/ATA_read/write_sectors
Some of the time, it does work, some of the time it does not.
I can only read and write in one function, then the code quits working.

https://gist.github.com/iProgramMC/8328 ... 9bdfd6909f
https://gist.github.com/iProgramMC/8d92 ... 52e7b76b31

The basic code required to test the functions is here.
The code returns zeros from the FileOpen function, even though the InitFilesystem function worked beforehand and made a full tree of the filesystem.

File system is very simple, you've got the classical BPB boot-sector, then 16 sectors' worth of root directory files, and data area.
All other FAT features were stripped down as this is planned to be a read-only file system.
Its main purpose is to load other programs into memory.

I'm not sure what causes the random halt of the functioning of AtaLbaRead and AtaLbaWrite, but I have a suspicion it may be in regards to the drive not being initialized and such, even though the file system was loaded successfully.

Please help?
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.
iProgramInCpp
Member
Member
Posts: 81
Joined: Sun Apr 21, 2019 7:39 am

Re: OSDev Wiki ATA read/write sectors code not working right

Post by iProgramInCpp »

Please help!
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: OSDev Wiki ATA read/write sectors code not working right

Post by alberinfo »

i think that you're messing up some code.
in the wiki says:

Code: Select all

mov edx, 0x1f4
mov eax, ebx
shr eax, 8
out dx, al
and then

Code: Select all

mov edx, 0x1f4
mov eax, ebx
shr eax, 16
out dx, al
but instead in your code you're doing:

Code: Select all

mov edx, 0x1f4
mov eax, ebx
shr eax, 16
out dx, al
correct me if i'm wrong
iProgramInCpp
Member
Member
Posts: 81
Joined: Sun Apr 21, 2019 7:39 am

Re: OSDev Wiki ATA read/write sectors code not working right

Post by iProgramInCpp »

I've fixed it.
The resulting array is still inconsistent even if I read the same sector over and over.
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.
Post Reply