OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:08 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 11:46 am 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 207
You can enable IDE tracing in qemu to gather more info.

Code:
-trace enable=ide_*


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 1:07 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
linuxyne wrote:
You can enable IDE tracing in qemu to gather more info.

Code:
-trace enable=ide_*


Thanks, that helped a lot. It is definitely reading and writing data, but I'm not exactly sure what is wrong with it. I'm pretty sure this is what the code is supposed to be doing.

Here is a snippet from the output:
Code:
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f0 (Data); val 0x00; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f0 (Data); val 0x00; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f0 (Data); val 0x00; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f0 (Data); val 0x00; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f0 (Data); val 0x00; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f0 (Data); val 0x00; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f7 (Command); val 0xe7; bus 0x55d61092fc40 IDEState 0x55d61092fcc0
[email protected]:ide_exec_cmd IDE exec cmd: bus 0x55d61092fc40; state 0x55d61092fcc0; cmd 0xe7
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x55d61092fc40 IDEState 0x55d61092fcc


Does anything look wrong here?


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 1:42 pm 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 207
Can't say what's wrong with those lines. You should check the ide_ioport_write and ide_ioport_read functions in qemu for details, along with the general knowledge about how the IDE ATA PIO is supposed to behave.

Did you resolve the warnings/comments raised/referenced in the previous replies (for e.g. there was a warning about the block#0 of an implicitly-given raw image being marked as read-only).


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 1:48 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Caffeine wrote:
I'm writing to LBA 0x0 and I'm checking that the disk gets saved by restarting the OS and reading LBA 0x0 again. Is there a better way to check if the disk saved or not?

Use a hex editor to examine the disk image. What if there's a bug in your code to read the disk?

Caffeine wrote:
Does anything look wrong here?

According to that log, DRQ has not cleared, which means the drive is still waiting for you to complete the transfer, which means you're aborting the command by starting a new command.

It looks like the transfer is not completing because you're using 8-bit writes with a port that only accepts 16-bit writes.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 1:57 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
The error message is actually saying that you can’t write to block 0, so it’s no wonder you don’t see a change. Either try specifically saying it’s a raw image or try writing to a different block.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 4:37 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
iansjack wrote:
The error message is actually saying that you can’t write to block 0, so it’s no wonder you don’t see a change. Either try specifically saying it’s a raw image or try writing to a different block.


I've changed the qemu command to:
Code:
qemu-system-i386 -drive file=disk.img,media=disk,format=raw -cdrom Binaries/caffieneOS.iso -m 16M -boot order=dc


And now the output is:
Code:
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x562a82a55dd0 IDEState 0x562a82a55e50
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x50; bus 0x562a82a55dd0 IDEState 0x562a82a55e50


But it still does not save to the virtual hard disk when I restart the machine.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 4:43 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
According to that log, you're reading the status register and nothing else. Is there more to the log that you haven't posted?


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 5:18 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
According to that log, you're reading the status register and nothing else. Is there more to the log that you haven't posted?


Yeah, sorry. I don't know how I didn't catch that. Here is part of the log when it writes:
Code:
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f6 (Device/Head); val 0x40; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f2 (Sector Count); val 0x00; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f3 (Sector Number); val 0x00; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f4 (Cylinder Low); val 0x00; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f5 (Cylinder High); val 0x00; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f2 (Sector Count); val 0x02; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f3 (Sector Number); val 0xff; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f4 (Cylinder Low); val 0x00; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f5 (Cylinder High); val 0x00; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f7 (Command); val 0x34; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_exec_cmd IDE exec cmd: bus 0x5592c4de8190; state 0x5592c4de8210; cmd 0x34
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x58; bus 0x5592c4de8190 IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x0000000f; bus 0x5592c4de8190; IDEState 0x5592c4de8210


(The end of the log where is writes):
Code:
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_data_writel IDE PIO wr @ 0x1f0 (Data: Long); val 0x00000000; bus 0x5592c4de8190; IDEState 0x5592c4de8210
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f7 (Command); val 0xe7; bus 0x5592c4de8190 IDEState 0x5592c4de8210


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Thu Apr 07, 2022 5:29 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
According to that log, you're not checking the status register before you send the next command. The drive will abort the write if it's not ready before you send the next command.

You're also using 32-bit writes on the 16-bit data register, which is not supported by all IDE controllers. (I'm not even sure if QEMU supports it.)


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Fri Apr 08, 2022 8:38 am 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
According to that log, you're not checking the status register before you send the next command. The drive will abort the write if it's not ready before you send the next command.

You're also using 32-bit writes on the 16-bit data register, which is not supported by all IDE controllers. (I'm not even sure if QEMU supports it.)


So I changed the ataPioWrite() function:
Code:
void ataPioWrite(unsigned int LBA, unsigned short sectorcount, unsigned char *target) {
    outportb(ATA_PRIMARY_DRIVE_HEAD, 0x40); // Select master
    outportb(ATA_PRIMARY_SECCOUNT, (sectorcount >> 8) & 0xFF);  // Sector Count hi
    outportb(ATA_PRIMARY_LBA_LO, (LBA >> 24) & 0xFF); // LBA4
    outportb(ATA_PRIMARY_LBA_MID, (LBA >> 32) & 0xFF);  //LBA5
    outportb(ATA_PRIMARY_LBA_HI, (LBA >> 40) & 0xFF);  // LBA6

    outportb(ATA_PRIMARY_SECCOUNT, sectorcount & 0xFF); // Sector Count low
    outportb(ATA_PRIMARY_LBA_LO, LBA & 0xFF); // LBA1
    outportb(ATA_PRIMARY_LBA_MID, (LBA >> 8) & 0xFF);  //LBA2
    outportb(ATA_PRIMARY_LBA_HI, (LBA >> 16) & 0xFF);  // LBA3
    outportb(ATA_PRIMARY_COMM_REGSTAT, 0x34);  // WRITE SECTORS EXT command

    for (unsigned char i = 0; i < sectorcount; i++) {
        pollATA();  // Wait for it to be able to transfer data

        // Transfer the data
        for (int j = 0; j < 256; j++) { pollATA(); outportb(ATA_PRIMARY_DATA, target[i]); }
        target += 256;
    }

    // Flush the cache.
    outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7);
    // Poll for BSY.
    while (inportb(ATA_PRIMARY_COMM_REGSTAT) & STAT_BSY) {}
}


I added the pollAta(); command in the for loop and changed outportl to outportb, which is defined here:
Code:
void outportb (unsigned short _port, unsigned char _data) {
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Fri Apr 08, 2022 11:27 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Caffeine wrote:
Code:
    outportb(ATA_PRIMARY_LBA_MID, (LBA >> 32) & 0xFF);  //LBA5
    outportb(ATA_PRIMARY_LBA_HI, (LBA >> 40) & 0xFF);  // LBA6

Do you see compiler warnings for these two lines? If not, turn on more compiler warnings and then fix the problems.

Caffeine wrote:
Code:
        for (int j = 0; j < 256; j++) { pollATA(); outportb(ATA_PRIMARY_DATA, target[i]); }

The data port only accepts 16-bit writes. You are using 8-bit writes.

Caffeine wrote:
Code:
    outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7);

You need to wait for the drive to be ready before sending another command.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Tue Apr 12, 2022 12:55 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Caffeine wrote:
Code:
    outportb(ATA_PRIMARY_LBA_MID, (LBA >> 32) & 0xFF);  //LBA5
    outportb(ATA_PRIMARY_LBA_HI, (LBA >> 40) & 0xFF);  // LBA6

Do you see compiler warnings for these two lines? If not, turn on more compiler warnings and then fix the problems.

Caffeine wrote:
Code:
        for (int j = 0; j < 256; j++) { pollATA(); outportb(ATA_PRIMARY_DATA, target[i]); }

The data port only accepts 16-bit writes. You are using 8-bit writes.

Caffeine wrote:
Code:
    outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7);

You need to wait for the drive to be ready before sending another command.


I fixed the compiler warning. For the writes, I am a little lost on how to write 16 bits to the register. And I have put a pollATA() before the last line.

I am sorry for all of the confusion.


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Tue Apr 12, 2022 1:15 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Caffeine wrote:
For the writes, I am a little lost on how to write 16 bits to the register.

You already have a function to write an 8-bit value to a port, right? Create a copy of that function, but adapted for 16 bits. Like this:

Code:
void outportw (unsigned short _port, unsigned short _data) {
    __asm__ __volatile__ ("outw %1, %0" : : "dN" (_port), "a" (_data));
}


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Tue Apr 12, 2022 1:28 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Caffeine wrote:
For the writes, I am a little lost on how to write 16 bits to the register.

You already have a function to write an 8-bit value to a port, right? Create a copy of that function, but adapted for 16 bits. Like this:

Code:
void outportw (unsigned short _port, unsigned short _data) {
    __asm__ __volatile__ ("outw %1, %0" : : "dN" (_port), "a" (_data));
}


So I have fixed that, but it still is not saving. I'm starting to think it might have something to do with qemu not saving. I've removed all of the warnings its giving me and such, but it still isn't saving when I restart the OS. When I write to an LBA and read it back before restarting it, it works, but when closing qemu and rerunning the code, it does not work. I did not use snapshot mode or anything when I created the disk, so I have no clue what is wrong.

Also, adding pollATA() before outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7); causes the OS to stall. Anyways, removing that, the output is:
Code:
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000; bus 0x561b275cf190; IDEState 0x561b275cf210


...

Code:
[email protected]:ide_sector_write sector=3 nsectors=1
[email protected]:ide_ioport_write IDE PIO wr @ 0x1f7 (Command); val 0xe7; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_exec_cmd IDE exec cmd: bus 0x561b275cf190; state 0x561b275cf210; cmd 0xe7
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210


...

Code:
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0xc0; bus 0x561b275cf190 IDEState 0x561b275cf210
[email protected]:ide_ioport_read IDE PIO rd @ 0x1f7 (Status); val 0x50; bus 0x561b275cf190 IDEState 0x561b275cf210


Top
 Profile  
 
 Post subject: Re: How do I find a partition while in WSL2?
PostPosted: Tue Apr 12, 2022 3:41 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Caffeine wrote:
Also, adding pollATA() before outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7); causes the OS to stall.

Doesn't your pollATA() function wait for the drive to be ready to transfer data? The drive will never be ready to transfer data if the write is complete. You need to wait until the drive is ready to accept a new command instead.

Caffeine wrote:
Code:
[email protected]:ide_data_writew IDE PIO wr @ 0x1f0 (Data: Word); val 0x0000;

You didn't provide a complete log. Does every line like this say "val 0x0000"?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: 8infy, Bing [Bot] and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group