Page 6 of 6

Re: FUSE filesystem?

Posted: Mon Dec 13, 2021 6:27 pm
by zap8600
Hi. So, how do I use inw and outw to read and write to a port when using strings?
Octocontrabass wrote:
zap8600 wrote:So I have decided to switch from IDE drives to ATA/ATAPI drives.
What's the difference? As far as I know, those are the same thing.
If I am right, an IDE drive can be written to and read from with ports 0x1f0 through 0x1f7 and 0x3f6 (or something similar). Writing to and reading from an ATA/ATAPI disk requires an IDE cable for IDE mode and only uses 0x1f0 and 0x3f6. Sorry about the attempt to recreate a insl and a outsl command. I can't find much information on the commands, so I had to piece together what info I could find.

Re: FUSE filesystem?

Posted: Mon Dec 13, 2021 8:00 pm
by Octocontrabass
zap8600 wrote:Hi. So, how do I use inw and outw to read and write to a port when using strings?
First, read this warning from Intel:
Intel SDM volume 2B wrote:REP INS may read from the I/O port without writing to the memory location if an exception or VM exit occurs due to the write (e.g. #PF). If this would be problematic, for example because the I/O port read has side-effects, software should ensure the write to the memory location does not cause an exception or VM exit.
In other words, if your OS uses exceptions to do things like demand paging and REP INSW causes one of those exceptions, it will silently corrupt data.

Anyway, inline assembly for REP INSW and REP OUTSW should look like this:

Code: Select all

void rep_insw( uint16_t port, void * dest, size_t count )
{
    asm volatile( "rep insw" : "+D"(dest), "+c"(count), "=m"(*(char (*)[count*2])dest) : "d"(port) );
}

void rep_outsw( uint16_t port, void * src, size_t count )
{
    asm volatile( "rep outsw" : "+S"(src), "+c"(count) : "d"(port), "m"(*(char (*)[count*2])src) );
}
zap8600 wrote:If I am right, an IDE drive can be written to and read from with ports 0x1f0 through 0x1f7 and 0x3f6 (or something similar). Writing to and reading from an ATA/ATAPI disk requires an IDE cable for IDE mode and only uses 0x1f0 and 0x3f6.
They are the same thing. Whether you call them IDE or ATA, the legacy ISA ports are 0x1F0-0x1F7 and 0x3F6 for the primary HBA, and 0x170-0x177 and 0x376 for the secondary. PCI IDE controllers may not use the legacy ISA ports; when you enumerate PCI you'll be able to check which ports each PCI IDE controller is using.
zap8600 wrote:I can't find much information on the commands, so I had to piece together what info I could find.
Writing inline assembly is difficult, but the GCC manual explains almost everything you need to know except the instructions. (The instructions are explained in the Intel and AMD manuals, AT&T syntax is explained all over the place, and the odd details most people never need to think about are explained in the binutils manual.)