Simple Program Fails

Simple program for detecting the PCI Bus.
Here is the program: (Running QNX 4.25H)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <sys/pci.h>

int main (int argc, char ** argv)
{
unsigned num_buses, version, hardware;
int err, pci_installed;

err = _CA_PCI_BIOS_Present (&num_buses, &version, &hardware );
pci_installed = err ? 0 : 1;
if (pci_installed)
{
printf (“Number of buses = %d, Version = %d, Hardware = %d \n”,
num_buses, version, hardware);
}
else
{
printf (“PCI Bus is not present. \n”);
}

return 0;
}

Running the program produces the following
(The program produced no printed output from the printf 's.):

test terminated (SIGSEV) at 0007:0000A179.
%1 Memory fault ./test


Behind the scenes, _CA_PCI_BIOS_Present (…)
performs something like:

{
int pci_installed, last_bus;
union REGS r;

memset (&r, 0, sizeof (r));
r.w.ax = 0xB101; // function number to check for PCI BIOS
int386 (0x1A, &r, &r);
pci_installed = r.h.ah;
last_bus = r.h.cl;
}

…And in a similar fashion, the interrupt function call int386
causes a SIGSEGV.
It should not crash the program, whether a PCI BIOS is detected or not.

Any ideas why this is happening?

-GF

How are you compiling the program? Do you use the -T1 command line option
to cc to tell it that your application is using priviledged instructions?

Previously, Gordon Freeman wrote in qdn.public.qnx4:

Simple program for detecting the PCI Bus.
Here is the program: (Running QNX 4.25H)

#include <stdio.h
#include <stdlib.h
#include <string.h
#include <conio.h
#include <sys/pci.h

int main (int argc, char ** argv)
{
unsigned num_buses, version, hardware;
int err, pci_installed;

err = _CA_PCI_BIOS_Present (&num_buses, &version, &hardware );
pci_installed = err ? 0 : 1;
if (pci_installed)
{
printf (“Number of buses = %d, Version = %d, Hardware = %d \n”,
num_buses, version, hardware);
}
else
{
printf (“PCI Bus is not present. \n”);
}

return 0;
}

Running the program produces the following
(The program produced no printed output from the printf 's.):

test terminated (SIGSEV) at 0007:0000A179.
%1 Memory fault ./test


Behind the scenes, _CA_PCI_BIOS_Present (…)
performs something like:

{
int pci_installed, last_bus;
union REGS r;

memset (&r, 0, sizeof (r));
r.w.ax = 0xB101; // function number to check for PCI BIOS
int386 (0x1A, &r, &r);
pci_installed = r.h.ah;
last_bus = r.h.cl;
}

…And in a similar fashion, the interrupt function call int386
causes a SIGSEGV.
It should not crash the program, whether a PCI BIOS is detected or not.

Any ideas why this is happening?

-GF

How are you compiling the program? Do you use the -T1 command line option
to cc to tell it that your application is using priviledged instructions?

Previously did not consider using -T1, but tried it now,
rebuilt and ran the program as before, with the same result.

Also tried running program as root, with same result.

\

  • GF

You must be root AND T1.

“Gordon Freeman” <spamsucks@bigfoot.com> wrote in message
news:beug5p$eq1$1@inn.qnx.com

How are you compiling the program? Do you use the -T1 command line
option
to cc to tell it that your application is using priviledged
instructions?

Previously did not consider using -T1, but tried it now,
rebuilt and ran the program as before, with the same result.

Also tried running program as root, with same result.

\

  • GF

“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:beuihj$ls$1@inn.qnx.com

You must be root AND T1.

Yes, logged in as root, then ‘make clean’, then
‘make’ (with -T1 forming a part of compile flags), then ‘./test’

Result was the same under these conditions.

  • GF



“Gordon Freeman” <> spamsucks@bigfoot.com> > wrote in message
news:beug5p$eq1$> 1@inn.qnx.com> …
How are you compiling the program? Do you use the -T1 command line
option
to cc to tell it that your application is using priviledged
instructions?

Previously did not consider using -T1, but tried it now,
rebuilt and ran the program as before, with the same result.

Also tried running program as root, with same result.

\

  • GF
    \

Previously, Gordon Freeman wrote in qdn.public.qnx4:

“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:beuihj$ls$> 1@inn.qnx.com> …
You must be root AND T1.

Yes, logged in as root, then ‘make clean’, then
‘make’ (with -T1 forming a part of compile flags), then ‘./test’

If you are using a Makefile, then the -T1 is a linker option, not
a compiler option. Just try ‘cc -T1 -oprogname progname.c’ and
see if that works.

Result was the same under these conditions.

  • GF



    “Gordon Freeman” <> spamsucks@bigfoot.com> > wrote in message
    news:beug5p$eq1$> 1@inn.qnx.com> …
    How are you compiling the program? Do you use the -T1 command line
    option
    to cc to tell it that your application is using priviledged
    instructions?

Previously did not consider using -T1, but tried it now,
rebuilt and ran the program as before, with the same result.

Also tried running program as root, with same result.

\

  • GF



    \

“Hugh Brown” <hsbrown@qnx.com> wrote in message
news:Voyager.030714125718.23409B@node90.ott.qnx.com

If you are using a Makefile, then the -T1 is a linker option, not
a compiler option. Just try ‘cc -T1 -oprogname progname.c’ and
see if that works.

Problem solved, thanks.

Tried it, and it works with ‘cc -T1’ on the command line,
or as linker option in the make file.

\

  • GF

Gordon Freeman <spamsucks@bigfoot.com> wrote:

“Hugh Brown” <> hsbrown@qnx.com> > wrote in message
news:> Voyager.030714125718.23409B@node90.ott.qnx.com> …

If you are using a Makefile, then the -T1 is a linker option, not
a compiler option. Just try ‘cc -T1 -oprogname progname.c’ and
see if that works.

Problem solved, thanks.

Tried it, and it works with ‘cc -T1’ on the command line,
or as linker option in the make file.

Note: there is one other gotcha with the CA_PCI* under QNX4 – you
don’t have it in this example, but you might run into it if you include
this in something bigger…

Your stack must live below the 64K mark. That is, size < 64K, address
less than < 64K. By default – this is ok, but if you do something like
link against a Photon, TCP/IP or QWindow shared library, this will no
longer be the case.

Or, if you compile with the -N option and ask for a bigger stack.

Just so as you know.

(Work around: get the ca_pci_msg archive from ftp.qnx.com:/usr/free/…)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.