OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 2:07 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 77 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6
Author Message
 Post subject: Re: FUSE filesystem?
PostPosted: Mon Dec 13, 2021 6:27 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
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.


Top
 Profile  
 
 Post subject: Re: FUSE filesystem?
PostPosted: Mon Dec 13, 2021 8:00 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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:
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.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 77 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 6 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