view docs/ccguide/os9.refentry @ 2437:d26e96c40194

rfm changes
author aaronwolfe
date Wed, 24 Feb 2010 00:37:08 +0000
parents 42b2c775f05f
children
line wrap: on
line source

<refentry id="os9">
<refnamediv>
<refname>_os9</refname>
<refpurpose>system call interface from C programs</refpurpose>
</refnamediv>

<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include &lt;os9.h&gt;
</funcsynopsisinfo>
<funcprototype>
  <funcdef><function>_os9</function></funcdef>
  <paramdef>char <parameter>code</parameter></paramdef>
  <paramdef>struct registers *<parameter>reg</parameter></paramdef>
</funcprototype>
</funcsynopsis>

</refsynopsisdiv>

<refsect1><title>Description</title>
<para>
_os9 enables a programmer to access virtually any OS-9 system
call directly from a C program without having to resort to
assembly language routines.
</para>
<para>
<varname>Code</varname> is one of the codes that are defines in os9.h. os9.h
contains codes for the F$ and I$ function/service requests, and
it also contains getstt, setstt, and error codes.
</para>
<para>
The input registers(reg) for the system calls are accessed by
the following structure that is defined in os9.h:
<programlisting>
struct registers {
     char rg_cc,rg_a,rg_b,rg_dp;
     unsigned rg_x,rg_y,rg_u;
};
</programlisting>
An example program that uses _os9 is presented on the following page.
</para>
</refsect1>

<refsect1><title>Diagnostics</title>
<para>
-1 is returned is the OS-9 call failed. 0 is returned on success.
</para>
</refsect1>

<refsect1><title>Program Example</title>
<programlisting>
#include &lt;os9.h&gt;
#include &lt;modes.h&gt;

/* this program does an I$GETSTT call to get file size */
main(argc,argv)
int argc;
char **argv;
{
     struct registers reg;
     int path;

/* tell linker we need longs */
     pflinit();

/* low level open(file name is first command line param */
     path=open(*++argv,S_IREAD);

/* set up regs for call to OS-9 */
     reg.rg_a=path;
     reg.rg_b=SS_SIZE;

     if(_os9(I_GETSTT,&amp;reg) == 0)
          printf("filesize = %lx\n", /* success */
          (long) (reg.rg_x &lt;&lt; 16)+reg.rg_u);
     else printf("OS9 error #%d\n",reg.rg_b &amp; 0xff); /*failed*/
     
     dumpregs(&amp;reg);  /* take a look at the registers */
}

dumpregs(r)
register struct registers *r;
{
     printf("cc=%02x\n",r->rg_cc &amp; 0xff);
     printf(" a=%02x\n",r->rg_a &amp; 0xff);
     printf(" b=%02x\n",r->rg_b &amp; 0xff);
     printf("dp=%02x\n",r->rg_dp &amp; 0xff);
     printf(" x=%02x\n",r->rg_x);
     printf(" y=%02x\n",r->rg_u);
     printf(" u=%02x\n",r->rg_y);
}
</programlisting>
</refsect1>
</refentry>