Page 2 of 3

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 11:46 am
by linuxyne
You can enable IDE tracing in qemu to gather more info.

Code: Select all

-trace enable=ide_*

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 1:07 pm
by Caffeine
linuxyne wrote:You can enable IDE tracing in qemu to gather more info.

Code: Select all

-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: Select all

[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?

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 1:42 pm
by linuxyne
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).

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 1:48 pm
by Octocontrabass
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.

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 1:57 pm
by iansjack
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.

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 4:37 pm
by Caffeine
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: Select all

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: Select all

[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.

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 4:43 pm
by Octocontrabass
According to that log, you're reading the status register and nothing else. Is there more to the log that you haven't posted?

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 5:18 pm
by Caffeine
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: Select all

[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: Select all

[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

Re: How do I find a partition while in WSL2?

Posted: Thu Apr 07, 2022 5:29 pm
by Octocontrabass
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.)

Re: How do I find a partition while in WSL2?

Posted: Fri Apr 08, 2022 8:38 am
by Caffeine
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: Select all

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: Select all

void outportb (unsigned short _port, unsigned char _data) {
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

Re: How do I find a partition while in WSL2?

Posted: Fri Apr 08, 2022 11:27 am
by Octocontrabass
Caffeine wrote:

Code: Select all

    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: Select all

        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: Select all

    outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7);
You need to wait for the drive to be ready before sending another command.

Re: How do I find a partition while in WSL2?

Posted: Tue Apr 12, 2022 12:55 pm
by Caffeine
Octocontrabass wrote:
Caffeine wrote:

Code: Select all

    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: Select all

        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: Select all

    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.

Re: How do I find a partition while in WSL2?

Posted: Tue Apr 12, 2022 1:15 pm
by Octocontrabass
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: Select all

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

Re: How do I find a partition while in WSL2?

Posted: Tue Apr 12, 2022 1:28 pm
by Caffeine
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: Select all

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: Select all

[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: Select all

[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: Select all

[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

Re: How do I find a partition while in WSL2?

Posted: Tue Apr 12, 2022 3:41 pm
by Octocontrabass
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: Select all

[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"?