Re: direct I/O access

2007-05-31 Thread Mike Meyer
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] typed:
> On Wed, 30 May 2007 12:39:10 -0400, Mike Meyer <[EMAIL PROTECTED]> wrote,
> 
> > Actually, protected mode is just the beginnings of it. I've never done
> > much x86 assembly, but going from the '020 to the '030 (or maybe it
> > was the '010 to the '020).  I had to start invalidating the hardware
> > caches after certain operations. After that, I switched to RISC
> > hardware, which were designed assuming that the real people writing
> > assembler would be few and far between, and did crazy things like
> > rearrange the instruction sequence behind your back and add extra
> > instructions. Modern systems do this kind of stuff as well.
>  
> do you think that it would be better to rewrite the soft in C???
> in this case, i have more work to do!
> first of all, learning C on the finger tip, before working on my soft.
> 
> and i thought that it would be very interesting to learn 
> the heart of FreeBSD.

Well, if you want to learn "the heart" of FreeBSD, I think you'd be
better off working in C. The code that isn't part of FreeBSD on pretty
much every platform would seem to be disqualified as the heart.

> > This really is a kludge, though. You haven't said what you're trying
> > to do. If you're trying to keep an old one-of device working, this is
> > probably the best way. But if it's a real device that other people
> > might be using, then writing a real device driver, or seeing if you
> > can make the device work with something like the iic drivers might be
> > better.
> 
> in fact, they are:
> - a direct to disk recorder,
> - a sampler.
> 
> they are not usable by other people, because they were discontinued.

So nobody else has them? You can't pick one up used on eBay? I
personally tend to run all but my most critical servers on
"discontinued" hardware. It's fast enough to do the job running
FreeBSD, and reasonably reliable; it's just not fast enough to run
modern versions of Windows. And I can buy a system and a hot spare for
a fraction of the cost of a new system.

  http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-31 Thread Raoul MEGELAS
On Thu, 31 May 2007 08:44:33 +0400
Eygene Ryabinkin <[EMAIL PROTECTED]> wrote,
Wed, May 30, 2007 at 02:43:07AM -0400, Mike Meyer wrote:

>> I believe this should be $0x4, as you want to *set* the values, not
>> get them.

> Right.

>> You also need to open the file "/dev/io".  I believe that leaving this
>> file open for anything more than a handful of instructions would be a
>> bad thing, but I'm not going to verify it.

> I feel that the i386_set_ioperm directly manipulates the task's I/O
> bitmap referenced by the task state segment (TSS), so you don't
> need to mangle with /dev/io.  /dev/io itself is the higher-level
> semi machine-indenepdent abstraction.  Opening /dev/io grants the
> global access to all ports, while using i386_set_ioperm gives the
> fine-grained access.  When you closing /dev/io, the port I/O access
> is revoked.

> To summarise: either you open /dev/io and do all your port I/O as
> in the good old days of the real-mode programs, or you're using
> i386_set_ioperm to obtain the access permissions to the I/O port
> range and again, do all port I/O as usual.

i rewrote my code and this time, all works fine.
thanks to Mike and Eygene.

here is the code as a proof of the above explanation:

# test_io.S

.include"system.inc"

BUFSIZE = 0x80
  
 .data
params:  .long 0x70,2,1,0
path:.asciz "/dev/io"

 .bss
 buffer: .fill BUFSIZE, 0


 .text
 .global  _start

err:
 pushl$0x1 # return failure
 SysExit


_start:
 addl $8,%esp  # discard argc and argv[0]

lealparams,%eax
pushl   %eax
pushl   $4
movl$0xa5,%eax
callbsd_kernel
addl$12,%esp


movl$0X330,%edx
inb %dx,%al
# if i try to read or write another port than 0x70/0x71, i have a segbus fault.

lealpath,%ecx
 pushl  $0 # O_RDONLY
 pushl  %ecx
 SysOpen
 jc  err # open failed
 addl $8,%esp
movl$0X330,%edx
inb %dx,%al
# all is ok!

 pushl   $0 # return success
SysExit

Thanks again.

Raoul
[EMAIL PROTECTED]

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-31 Thread rmgls
On Wed, 30 May 2007 12:39:10 -0400, Mike Meyer <[EMAIL PROTECTED]> wrote,

> Actually, protected mode is just the beginnings of it. I've never done
> much x86 assembly, but going from the '020 to the '030 (or maybe it
> was the '010 to the '020).  I had to start invalidating the hardware
> caches after certain operations. After that, I switched to RISC
> hardware, which were designed assuming that the real people writing
> assembler would be few and far between, and did crazy things like
> rearrange the instruction sequence behind your back and add extra
> instructions. Modern systems do this kind of stuff as well.
 
do you think that it would be better to rewrite the soft in C???
in this case, i have more work to do!
first of all, learning C on the finger tip, before working on my soft.

and i thought that it would be very interesting to learn 
the heart of FreeBSD.


> This really is a kludge, though. You haven't said what you're trying
> to do. If you're trying to keep an old one-of device working, this is
> probably the best way. But if it's a real device that other people
> might be using, then writing a real device driver, or seeing if you
> can make the device work with something like the iic drivers might be
> better.

in fact, they are:
- a direct to disk recorder,
- a sampler.

they are not usable by other people, because they were discontinued.

bests regards

raoul
[EMAIL PROTECTED]

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-30 Thread Eygene Ryabinkin
Mike, good day.

Wed, May 30, 2007 at 02:43:07AM -0400, Mike Meyer wrote:
> I believe this should be $0x4, as you want to *set* the values, not
> get them.

Right.

> You also need to open the file "/dev/io".  I believe that leaving this
> file open for anything more than a handful of instructions would be a
> bad thing, but I'm not going to verify it.

I feel that the i386_set_ioperm directly manipulates the task's I/O
bitmap referenced by the task state segment (TSS), so you don't
need to mangle with /dev/io.  /dev/io itself is the higher-level
semi machine-indenepdent abstraction.  Opening /dev/io grants the
global access to all ports, while using i386_set_ioperm gives the
fine-grained access.  When you closing /dev/io, the port I/O access
is revoked.

To summarise: either you open /dev/io and do all your port I/O as
in the good old days of the real-mode programs, or you're using
i386_set_ioperm to obtain the access permissions to the I/O port
range and again, do all port I/O as usual.
-- 
Eygene
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-30 Thread M. Warner Losh
Open "/dev/io" and you should be able to do what you want.

How you do this in assembler, I'll leave to others.

Warner
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-30 Thread Mike Meyer
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] typed:
> >And I have to ask. The hardware has changed a lot since the days of
> >DoS, and things that worked then may cause strange results on modern
> >hardware. Do you know modern hardware, or are you still using dos-era
> >hardware?
> >
> yes i am aware of this, and have a few understanding of protected mode too, 
> also about music softs.

Actually, protected mode is just the beginnings of it. I've never done
much x86 assembly, but going from the '020 to the '030 (or maybe it
was the '010 to the '020).  I had to start invalidating the hardware
caches after certain operations. After that, I switched to RISC
hardware, which were designed assuming that the real people writing
assembler would be few and far between, and did crazy things like
rearrange the instruction sequence behind your back and add extra
instructions. Modern systems do this kind of stuff as well.

> ---cut---
> >> 
> >>.data
> >>.align 4
> >> params:.word 0x330,2,1 # midi port => enabling IO ???
> >> 
> >>.text
> >>.align 4
> >>.global _start
> >> _start:
> >>nop
> >>pushl   params
> >>pushl   $0x4
> >
> >I believe this should be $0x4, as you want to *set* the values, not
> >get them.
> >
> is it necessary to restore the permissions on exit?
> 
> >You also need to open the file "/dev/io".  I believe that leaving this
> >file open for anything more than a handful of instructions would be a
> >bad thing, but I'm not going to verify it.
> >
> 
> i tried this, but without set_ioperm, it was not clear on the doc 
> that one have to use these two funcions:
> in io man: i find SEE ALSO: i386_get(set)_ioperm...
> 
> is my understanding correct?

Sounds like it. You have to do i386_set_ioperm to say what port range
you want access to, and open /dev/io to actually allow it to work. It
doesn't look like it's order dependent, so doing the i386_set_ioperm
and then opening/closing /dev/io should work. I no longer have root on
a machine running i386 FreeBSD, so I can't test it very easily.

This really is a kludge, though. You haven't said what you're trying
to do. If you're trying to keep an old one-of device working, this is
probably the best way. But if it's a real device that other people
might be using, then writing a real device driver, or seeing if you
can make the device work with something like the iic drivers might be
better.

  http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-30 Thread rmgls
>> i am trying to port my old assembler soft for Dos to FreeBSD.
>
>You have my sympathy.
>
Thanks, i need it, because its a big deal for me!

>> i need to write and read directly to the midi and scsi device.
>> when i try something like this i receive a sigbus error
>> 
>> SORRY, i am NOT nor a C nor a FreeBSD expert!!!
>> all i know is Assembly language!
>
>You may have to learn some. Or at least be able to read it.
>

I read C, and begin to write some short examples.
but of course my lack is great on this topic.

>And I have to ask. The hardware has changed a lot since the days of
>DoS, and things that worked then may cause strange results on modern
>hardware. Do you know modern hardware, or are you still using dos-era
>hardware?
>

yes i am aware of this, and have a few understanding of protected mode too, 
also about music softs.

---cut---
>> 
>>  .data
>>  .align 4
>> params:  .word 0x330,2,1 # midi port => enabling IO ???
>> 
>>  .text
>>  .align 4
>>  .global _start
>> _start:
>>  nop
>>  pushl   params
>>  pushl   $0x4
>
>I believe this should be $0x4, as you want to *set* the values, not
>get them.
>
is it necessary to restore the permissions on exit?

>You also need to open the file "/dev/io".  I believe that leaving this
>file open for anything more than a handful of instructions would be a
>bad thing, but I'm not going to verify it.
>

i tried this, but without set_ioperm, it was not clear on the doc 
that one have to use these two funcions:
in io man: i find SEE ALSO: i386_get(set)_ioperm...

is my understanding correct?

thanks a lot
raoul

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-29 Thread Hans Petter Selasky
On Tuesday 29 May 2007 20:10, [EMAIL PROTECTED] wrote:
> hi all,
>
> Sorry for cross posting, but perhaps hackers is a better list than
> multimedia for this topic.
>
> i am trying to port my old assembler soft for Dos to FreeBSD.
> i need to write and read directly to the midi and scsi device.
> when i try something like this i receive a sigbus error
>
> SORRY, i am NOT nor a C nor a FreeBSD expert!!!
> all i know is Assembly language!
>
> i made some search in the devel handbook and did not found the solution.
> What is wrong here?
> Can you enlight me please?

I think you need to open /dev/io before your program can execute I/O 
instructions.

--HPS
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-29 Thread Mike Meyer
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] typed:
> Sorry for cross posting, but perhaps hackers is a better list than multimedia
> for this topic.

Probably.

> i am trying to port my old assembler soft for Dos to FreeBSD.

You have my sympathy.

> i need to write and read directly to the midi and scsi device.
> when i try something like this i receive a sigbus error
> 
> SORRY, i am NOT nor a C nor a FreeBSD expert!!!
> all i know is Assembly language!

You may have to learn some. Or at least be able to read it.

And I have to ask. The hardware has changed a lot since the days of
DoS, and things that worked then may cause strange results on modern
hardware. Do you know modern hardware, or are you still using dos-era
hardware?

> i made some search in the devel handbook and did not found the solution.
> What is wrong here?
> Can you enlight me please?
> 
> 
> Many thanks in advance and bests regards
> 
> Raoul
> [EMAIL PROTECTED]
> 
> ---cut---
> 
>   .data
>   .align 4
> params:   .word 0x330,2,1 # midi port => enabling IO ???
> 
>   .text
>   .align 4
>   .global _start
> _start:
>   nop
>   pushl   params
>   pushl   $0x3

I believe this should be $0x4, as you want to *set* the values, not
get them.

You also need to open the file "/dev/io".  I believe that leaving this
file open for anything more than a handful of instructions would be a
bad thing, but I'm not going to verify it.

Best of luck,
   movl$0Xa5,%eax
>   int $0x80
>   addl$0x08,%esp
>   movw$0x331,%dx   #  status register
>   inb %dx,%al
> # ...
>   pushl   $0 # exit
>   movl$0x1,%eax
>   int $0x80
> 
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"
> 

-- 
Mike Meyer <[EMAIL PROTECTED]>  http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-29 Thread Eygene Ryabinkin
Me again.

Wed, May 30, 2007 at 08:46:14AM +0400, Eygene Ryabinkin wrote:
> Then use i386_set_ioperm
> that will be equivalent to the first parameter to the 'int 0x80' to
> 0x04 instead 0x03.

Hmm, that should read "set the first parameter for the 'int 0x80' to
0x04 instead of 0x03" -- it is much more understandable ;))
-- 
Eygene
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: direct I/O access

2007-05-29 Thread Eygene Ryabinkin
Raoul, good day.

Tue, May 29, 2007 at 08:10:26PM +0200, [EMAIL PROTECTED] wrote:
> i am trying to port my old assembler soft for Dos to FreeBSD.
> i need to write and read directly to the midi and scsi device.
> when i try something like this i receive a sigbus error

Seems like that the following fragment

>params: .word 0x330,2,1 # midi port => enabling IO ???
>[...]
>   pushl   params
>   pushl   $0x3
>   movl$0Xa5,%eax
>   int $0x80
>   addl$0x08,%esp

translates to the call i386_get_ioperm(0x330, 2, 1).  But you should
use the i386_set_ioperm(0x330, 2, 1), aren't you?  You're trying
to grant the IO permissions for your process?  Then use i386_set_ioperm
that will be equivalent to the first parameter to the 'int 0x80' to
0x04 instead 0x03.

With 0x03 you're just trying to make the system to write the _current_
IO permissions starting with port 0x330 to the _addresses_ 0x02 and
0x01.  And this is obviously wrong, but it should provoke the segfault
error instead of sigbus.

I am not sure about the 'pushl params' statement: will it push all
three arguments to the stack?  My GNU assembler knowledge is rather
rusty and incomplete, sorry.  But maybe it is the reason why you're
getting the sigbus instead of 'correct' sigsegv.
-- 
Eygene
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"