mailing list of musl libc
 help / color / mirror / code / Atom feed
* sys/io.h lacks inb_p and outb_p on x86
@ 2015-11-08  4:26 Рысь
  2015-11-08  4:50 ` Rich Felker
  0 siblings, 1 reply; 8+ messages in thread
From: Рысь @ 2015-11-08  4:26 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 392 bytes --]

x86 arch lacks inb_p and outb_p inline functions. This is required for
memtest86+.

I don't know how properly make an assembly here, so when making memtest
I copied sys/io.h into local directory, and copied these functions from
uClibc.

I attach modified header for reference (they should go into bits/io.h).

-- 
http://lynxlynx.tk/
Power electronics made simple
Unix and simple KISS C code

[-- Attachment #2: io.h --]
[-- Type: application/octet-stream, Size: 591 bytes --]

#ifndef	_SYS_IO_H
#define	_SYS_IO_H
#ifdef __cplusplus
extern "C" {
#endif

#include <features.h>

#include <bits/io.h>

int iopl(int);
int ioperm(unsigned long, unsigned long, int);

/* Copied from uClibc */
static __inline unsigned char
inb_p (unsigned short int port)
{
  unsigned char _v;

  __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  return _v;
}

static __inline void
outb_p (unsigned char value, unsigned short int port)
{
  __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
			"Nd" (port));
}

#ifdef __cplusplus
}
#endif
#endif

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sys/io.h lacks inb_p and outb_p on x86
  2015-11-08  4:26 sys/io.h lacks inb_p and outb_p on x86 Рысь
@ 2015-11-08  4:50 ` Rich Felker
  2015-11-08  5:13   ` Рысь
  0 siblings, 1 reply; 8+ messages in thread
From: Rich Felker @ 2015-11-08  4:50 UTC (permalink / raw)
  To: musl

On Sun, Nov 08, 2015 at 11:26:55AM +0700, Рысь wrote:
> x86 arch lacks inb_p and outb_p inline functions. This is required for
> memtest86+.
> 
> I don't know how properly make an assembly here, so when making memtest
> I copied sys/io.h into local directory, and copied these functions from
> uClibc.
> 
> I attach modified header for reference (they should go into bits/io.h).

Any idea what these are intended to do? Are they documented anywhere?

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sys/io.h lacks inb_p and outb_p on x86
  2015-11-08  4:50 ` Rich Felker
@ 2015-11-08  5:13   ` Рысь
  2015-11-08  5:23     ` Rich Felker
  0 siblings, 1 reply; 8+ messages in thread
From: Рысь @ 2015-11-08  5:13 UTC (permalink / raw)
  To: musl

On Sat, 7 Nov 2015 23:50:45 -0500
Rich Felker <dalias@libc.org> wrote:

> On Sun, Nov 08, 2015 at 11:26:55AM +0700, Рысь wrote:
> > x86 arch lacks inb_p and outb_p inline functions. This is required
> > for memtest86+.
> > 
> > I don't know how properly make an assembly here, so when making
> > memtest I copied sys/io.h into local directory, and copied these
> > functions from uClibc.
> > 
> > I attach modified header for reference (they should go into
> > bits/io.h).
> 
> Any idea what these are intended to do? Are they documented anywhere?
> 
> Rich

I can't say much, but looking into memtest code I see they're used only
for beeping a PC speaker.

Comment in io.h include file of memtest says:

 * This file contains the definitions for the x86 IO instructions
 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
 * versions of the single-IO instructions (inb_p/inw_p/..).

However memtest builds with assumption they're present in sys/io.h from
host and io.h included with memtest does not define inb_p/outb_p in any
way.

I probably will go with uClibc defines, or just nop memtest beeper.

-- 
http://lynxlynx.tk/
Power electronics made simple
Unix and simple KISS C code


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sys/io.h lacks inb_p and outb_p on x86
  2015-11-08  5:13   ` Рысь
@ 2015-11-08  5:23     ` Rich Felker
  2015-11-09 22:17       ` Rich Felker
  0 siblings, 1 reply; 8+ messages in thread
From: Rich Felker @ 2015-11-08  5:23 UTC (permalink / raw)
  To: musl

On Sun, Nov 08, 2015 at 12:13:37PM +0700, Рысь wrote:
> On Sat, 7 Nov 2015 23:50:45 -0500
> Rich Felker <dalias@libc.org> wrote:
> 
> > On Sun, Nov 08, 2015 at 11:26:55AM +0700, Рысь wrote:
> > > x86 arch lacks inb_p and outb_p inline functions. This is required
> > > for memtest86+.
> > > 
> > > I don't know how properly make an assembly here, so when making
> > > memtest I copied sys/io.h into local directory, and copied these
> > > functions from uClibc.
> > > 
> > > I attach modified header for reference (they should go into
> > > bits/io.h).
> > 
> > Any idea what these are intended to do? Are they documented anywhere?
> > 
> > Rich
> 
> I can't say much, but looking into memtest code I see they're used only
> for beeping a PC speaker.
> 
> Comment in io.h include file of memtest says:
> 
>  * This file contains the definitions for the x86 IO instructions
>  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
>  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
>  * versions of the single-IO instructions (inb_p/inw_p/..).
> 
> However memtest builds with assumption they're present in sys/io.h from
> host and io.h included with memtest does not define inb_p/outb_p in any
> way.
> 
> I probably will go with uClibc defines, or just nop memtest beeper.

See http://stackoverflow.com/questions/6793899/what-does-the-0x80-port-address-connects

So apparently these are convenience functions to show the most recent
port io that was performed on a hardware debugging device in case the
memtest crashes. I don't mind adding them is software expects them to
be there, but they should be written in terms of the existing
functions rather than duplicating asm.

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sys/io.h lacks inb_p and outb_p on x86
  2015-11-08  5:23     ` Rich Felker
@ 2015-11-09 22:17       ` Rich Felker
  2015-11-10  8:08         ` Рысь
  0 siblings, 1 reply; 8+ messages in thread
From: Rich Felker @ 2015-11-09 22:17 UTC (permalink / raw)
  To: musl

On Sun, Nov 08, 2015 at 12:23:58AM -0500, Rich Felker wrote:
> On Sun, Nov 08, 2015 at 12:13:37PM +0700, Рысь wrote:
> > On Sat, 7 Nov 2015 23:50:45 -0500
> > Rich Felker <dalias@libc.org> wrote:
> > 
> > > On Sun, Nov 08, 2015 at 11:26:55AM +0700, Рысь wrote:
> > > > x86 arch lacks inb_p and outb_p inline functions. This is required
> > > > for memtest86+.
> > > > 
> > > > I don't know how properly make an assembly here, so when making
> > > > memtest I copied sys/io.h into local directory, and copied these
> > > > functions from uClibc.
> > > > 
> > > > I attach modified header for reference (they should go into
> > > > bits/io.h).
> > > 
> > > Any idea what these are intended to do? Are they documented anywhere?
> > > 
> > > Rich
> > 
> > I can't say much, but looking into memtest code I see they're used only
> > for beeping a PC speaker.
> > 
> > Comment in io.h include file of memtest says:
> > 
> >  * This file contains the definitions for the x86 IO instructions
> >  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
> >  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
> >  * versions of the single-IO instructions (inb_p/inw_p/..).
> > 
> > However memtest builds with assumption they're present in sys/io.h from
> > host and io.h included with memtest does not define inb_p/outb_p in any
> > way.
> > 
> > I probably will go with uClibc defines, or just nop memtest beeper.
> 
> See http://stackoverflow.com/questions/6793899/what-does-the-0x80-port-address-connects
> 
> So apparently these are convenience functions to show the most recent
> port io that was performed on a hardware debugging device in case the
> memtest crashes. I don't mind adding them is software expects them to
> be there, but they should be written in terms of the existing
> functions rather than duplicating asm.

Hmm, according to the man page this is actually to "pause". See:
http://man7.org/linux/man-pages/man2/outb.2.html

Of course there's also all kinds of nonsense claiming they won't work
with -O0, so I'm not sure what to believe.

If you want these, can you prepare a patch adding all 6 *_p functions
as calls to plain in[bwl]/out[bwl] followed by a call to outb to port
0x80?

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sys/io.h lacks inb_p and outb_p on x86
  2015-11-09 22:17       ` Rich Felker
@ 2015-11-10  8:08         ` Рысь
  2015-11-10  8:50           ` Felix Janda
  0 siblings, 1 reply; 8+ messages in thread
From: Рысь @ 2015-11-10  8:08 UTC (permalink / raw)
  To: musl

On Mon, 9 Nov 2015 17:17:34 -0500
Rich Felker <dalias@libc.org> wrote:

> On Sun, Nov 08, 2015 at 12:23:58AM -0500, Rich Felker wrote:
> > On Sun, Nov 08, 2015 at 12:13:37PM +0700, Рысь wrote:
> > > On Sat, 7 Nov 2015 23:50:45 -0500
> > > Rich Felker <dalias@libc.org> wrote:
> > > 
> > > > On Sun, Nov 08, 2015 at 11:26:55AM +0700, Рысь wrote:
> > > > > x86 arch lacks inb_p and outb_p inline functions. This is
> > > > > required for memtest86+.
> > > > > 
> > > > > I don't know how properly make an assembly here, so when
> > > > > making memtest I copied sys/io.h into local directory, and
> > > > > copied these functions from uClibc.
> > > > > 
> > > > > I attach modified header for reference (they should go into
> > > > > bits/io.h).
> > > > 
> > > > Any idea what these are intended to do? Are they documented
> > > > anywhere?
> > > > 
> > > > Rich
> > > 
> > > I can't say much, but looking into memtest code I see they're
> > > used only for beeping a PC speaker.
> > > 
> > > Comment in io.h include file of memtest says:
> > > 
> > >  * This file contains the definitions for the x86 IO instructions
> > >  * inb/inw/inl/outb/outw/outl and the "string versions" of the
> > > same
> > >  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
> > >  * versions of the single-IO instructions (inb_p/inw_p/..).
> > > 
> > > However memtest builds with assumption they're present in
> > > sys/io.h from host and io.h included with memtest does not define
> > > inb_p/outb_p in any way.
> > > 
> > > I probably will go with uClibc defines, or just nop memtest
> > > beeper.
> > 
> > See
> > http://stackoverflow.com/questions/6793899/what-does-the-0x80-port-address-connects
> > 
> > So apparently these are convenience functions to show the most
> > recent port io that was performed on a hardware debugging device in
> > case the memtest crashes. I don't mind adding them is software
> > expects them to be there, but they should be written in terms of
> > the existing functions rather than duplicating asm.
> 
> Hmm, according to the man page this is actually to "pause". See:
> http://man7.org/linux/man-pages/man2/outb.2.html
> 
> Of course there's also all kinds of nonsense claiming they won't work
> with -O0, so I'm not sure what to believe.
> 
> If you want these, can you prepare a patch adding all 6 *_p functions
> as calls to plain in[bwl]/out[bwl] followed by a call to outb to port
> 0x80?
> 
> Rich

Well, I am not good at assembly right now, so no.

While digging this I came to suspection that grabbed versions from
uClibc cannot be rewritten as function calls, or I misunderstand
assembly (or it's gcc variant) at all.

So, after three+ years of experience with musl I just hit this once,
and I don't think they worth adding if there is no much interest.

memtest86+ uses no libc code, and suddenly only grabs those two from
host which is easily patchable.

I used uClibc versions just to get a conformant binary.

-- 
http://lynxlynx.tk/
Power electronics made simple
Unix and simple KISS C code


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sys/io.h lacks inb_p and outb_p on x86
  2015-11-10  8:08         ` Рысь
@ 2015-11-10  8:50           ` Felix Janda
  2015-11-10  9:29             ` Рысь
  0 siblings, 1 reply; 8+ messages in thread
From: Felix Janda @ 2015-11-10  8:50 UTC (permalink / raw)
  To: musl

Рысь wrote:
[..]
> 
> So, after three+ years of experience with musl I just hit this once,
> and I don't think they worth adding if there is no much interest.
> 
> memtest86+ uses no libc code, and suddenly only grabs those two from
> host which is easily patchable.

It also has an "io.h" which should define inb_p and outb_p via some
"misuse" of macros. Can't it use that instead of <sys/io.h>?

Felix


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sys/io.h lacks inb_p and outb_p on x86
  2015-11-10  8:50           ` Felix Janda
@ 2015-11-10  9:29             ` Рысь
  0 siblings, 0 replies; 8+ messages in thread
From: Рысь @ 2015-11-10  9:29 UTC (permalink / raw)
  To: musl

On Tue, 10 Nov 2015 09:50:52 +0100
Felix Janda <felix.janda@posteo.de> wrote:

> Рысь wrote:
> [..]
> > 
> > So, after three+ years of experience with musl I just hit this once,
> > and I don't think they worth adding if there is no much interest.
> > 
> > memtest86+ uses no libc code, and suddenly only grabs those two from
> > host which is easily patchable.
> 
> It also has an "io.h" which should define inb_p and outb_p via some
> "misuse" of macros. Can't it use that instead of <sys/io.h>?
> 
> Felix

OK the build is fixable with -DSLOW_IO_BY_JUMPING. I thought it's io.h
did not used in it. Sorry for the noise then.

-- 
http://lynxlynx.tk/
Power electronics made simple
Unix and simple KISS C code


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-11-10  9:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-08  4:26 sys/io.h lacks inb_p and outb_p on x86 Рысь
2015-11-08  4:50 ` Rich Felker
2015-11-08  5:13   ` Рысь
2015-11-08  5:23     ` Rich Felker
2015-11-09 22:17       ` Rich Felker
2015-11-10  8:08         ` Рысь
2015-11-10  8:50           ` Felix Janda
2015-11-10  9:29             ` Рысь

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).