home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3949 < prev    next >
Text File  |  1991-08-31  |  13KB  |  444 lines

  1. Xref: wupost comp.unix.xenix.sco:4165 alt.sources:3949
  2. Path: wupost!uunet!mcsun!ukc!stl!robobar!ronald
  3. From: ronald@robobar.co.uk (Ronald S H Khoo)
  4. Newsgroups: comp.unix.xenix.sco,alt.sources
  5. Subject: XENIX 2.3.4 syscalls (Re: What is newest Xenix Dev System Release?)
  6. Summary: source code included
  7. Keywords: xenix OS 2.3.4 / DS 2.3.1
  8. Message-ID: <1991Aug31.182326.6506@robobar.co.uk>
  9. Date: 31 Aug 91 18:23:26 GMT
  10. References: <19385@scorn.sco.COM>
  11. Followup-To: comp.unix.xenix.sco
  12. Organization: Robobar Ltd., Perivale, Middx., ENGLAND.
  13. Lines: 429
  14.  
  15. Archive-Name: Xenix/dumpsys
  16.  
  17. timr@sco.COM (Tim Ruckle) writes:
  18.  
  19. > There are no new system calls in the 2.3.4 kernel.
  20.  
  21. This is, of course, not true, as has already been observed. scoinfo()
  22. and eacess() being mentioned in the released notes.
  23. You can use a generic cxenix() system call interface to call these routines
  24. of course.  More of that below.
  25.  
  26. > You've got the latest release of the XENIX Dev Sys with Release 2.3.1
  27. > and lng244.
  28.  
  29. This is again, only true "in a sense".  Yes, it's the latest Development
  30. System from SCO that is labeled "for XENIX".  However, it is useful to note
  31. that the SCO Unix development system's XENIX cross-development package
  32. is newer, and of course it will run on a current SCO XENIX.  *Many
  33. Times* in the past Sean F has mentioned in the past that he used to do
  34. exactly that.  (So if it don't work, blame him, not me :-)
  35.  
  36. In the old version (I only have 3.2.0f, I can't speak for the current
  37. version) eaccess is in /lib/386/Slib3.2.a, but a cursory glance does not
  38. seem to reveal scoinfo.  Doesn't matter.  See below.
  39.  
  40. OK, so you want the generic cxenix() call, and the syscall numbers for
  41. eaccess() and scoinfo().  I could just tell you what they are, but it's
  42. much more useful to give you my "dumpsys" program that will extract
  43. the numbers out of your link-kit, just in case SCO upgrades XENIX again
  44. and puts more system calls in which you want to call.  You will need
  45. GCC/GAS as recently posted here (or ftp them from unix.secs.oakland.edu)
  46. because I don't use the Microsoft rubbish, and so the stuff below needs
  47. GCC/GAS.
  48.  
  49. The shar below contains the source and Makefile to generate the dumpsys
  50. program that reveals the system call numbers.  If you have access to
  51. a SCO UNIX development system, this information is also available
  52. in /usr/include/sys.s, but dumpsys will tell you what calls are
  53. actually implemented on your kernel.  I am grateful to
  54. Keith "Pax" Gabryelski <ag@cbmvax.commodore.com> for his news
  55. article <38@elgar.UUCP> (dated 24 Jan 89) for the information which
  56. led to dumpsys.
  57.  
  58. Having run dumpsys on a XENIX 2.3.4 system, you will find that eaccess()
  59. is cxenix(37) and scoinfo() is cxenix(50).  Now for the calling sequence.
  60. By guesswork, you can intuit that eaccess() is called the same way as
  61. access() and I suppose scoinfo() is probably called the same way as
  62. uname() (but I can't check because it's the weekend, and the 2.3.4
  63. machine is at the office)
  64.  
  65. To use the generic cxenix() call, just say stuff like cxenix(37, file, mode)
  66. instead of eaccess(file, mode).  Look, I'll even throw in a eaccess(1)
  67. command sample, just do
  68.  
  69.     gcc eaccess.c syscall.S -o eaccess
  70.  
  71. to compile it.  It even has a usage: line when invoked with no args,
  72. but no manual page.  Hey, this is my weekend! :-)
  73.  
  74. #! /bin/sh
  75. # This is a shell archive, meaning:
  76. # 1. Remove everything above the #! /bin/sh line.
  77. # 2. Save the resulting text in a file.
  78. # 3. Execute the file with /bin/sh (not csh) to create the files:
  79. #    Makefile
  80. #    dumpsys.c
  81. #    eaccess.c
  82. #    sizes.sh
  83. #    syscall.S
  84. # This archive created: Sat Aug 31 19:16:04 1991
  85. export PATH; PATH=/bin:$PATH
  86. echo shar: extracting "'Makefile'" '(1946 characters)'
  87. if test -f 'Makefile'
  88. then
  89.     echo shar: will not over-write existing file "'Makefile'"
  90. else
  91. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  92. X# /*
  93. X#  * @begin{boilerplate}
  94. X#  * Copyright 1991 Ronald Khoo <ronald@ibmpcug.co.uk>
  95. X#  * This is Really Free Software.
  96. X#  * Permission granted to use this software for any purpose provided that
  97. X#  * the author be held free from any blame for anything that may occur as a
  98. X#  * result of this software being used; that this notice be preserved in all
  99. X#  * copies of this software and derived works, and the documentation therof;
  100. X#  * and that any modifications be clearly marked as such.
  101. X#  * @end{boilerplate}
  102. X#  */
  103. XCC=    /usr/local/bin/gcc
  104. XMDEP=    /usr/sys/mdep
  105. XE=    sysent.o cxenix.o
  106. XO=    $(OO) $E
  107. XOO=    dumpsys.o stubs.o 
  108. X
  109. Xdumpsys:    $O
  110. X    $(CC) $(CFLAGS) $O -o $@
  111. X
  112. Xstubs.c:    $E Makefile
  113. X    nm -g $E | sed -n '/ * U _\([a-z][^ ]*\)/s//\1/p'  | sort -u > T
  114. X    sed -n -e '/^write$$/{s//extern write();/p;d;}' \
  115. X           -e '/^cxenix$$/{s//extern cxenix();/p;d;}' \
  116. X           -e '/^utssys$$/{s//extern utssys();/p;d;}' \
  117. X           -e 's/.*/&(){}/p' T > $@
  118. X    echo "struct { int (*func)(); char *name; } functab[] = {" >> $@
  119. X    sed 's/.*/    { &, "&" },/' T >> $@
  120. X    echo "0 };" >> $@
  121. X    nm -g $E | sed -n '/.* _\([a-z][^ ]*ent\) *$$/s//\1/p'  | sort -u > T
  122. X    nm -g $E | sed -n '/.* _\([a-z][^ ]*entry\) *$$/s//\1/p'  | sort -u >> T
  123. X    sed 's/.*/extern struct sysent &[];/' T >> $@
  124. X    echo '#include "stubs.h"' >> $@
  125. X    echo '#include <sys/types.h>' >> $@
  126. X    echo '#include <sys/systm.h>' >> $@
  127. X    echo "struct { struct sysent *sysent; char *name; int nent; } systab[] = {" >> $@
  128. X    sed 's/.*/    { &, "&", SIZE_& \/ sizeof (struct sysent) },/' T >> $@
  129. X    echo "};" >> $@
  130. X    echo "int nsysent = sizeof systab / sizeof *systab;" >> $@
  131. X    rm -f T
  132. X
  133. Xstubs.o:    stubs.h
  134. X
  135. Xstubs.h:    $E Makefile
  136. X    echo int fred = 5\; > x.c
  137. X    -$(CC) $E x.c -o x
  138. X    : yes, i did expect all those link errors
  139. X    nm -n x | \
  140. X    sed -n '/^....:\([0-9a-zA-Z]*\)  *D _\(.*\)$$/s//\1 \2/p' | \
  141. X    sh sizes.sh > stubs.h
  142. X    rm -f x x.c
  143. X
  144. Xclean:
  145. X    rm -f x a.out core $(OO) stubs.* x.c
  146. X
  147. Xrealclean:    clean
  148. X    rm -f $E dumpsys
  149. X
  150. X$E:    $(MDEP)/libmdep.a
  151. X    ar x $? $@
  152. SHAR_EOF
  153. if test 1946 -ne "`wc -c < 'Makefile'`"
  154. then
  155.     echo shar: error transmitting "'Makefile'" '(should have been 1946 characters)'
  156. fi
  157. fi # end of overwriting check
  158. echo shar: extracting "'dumpsys.c'" '(2588 characters)'
  159. if test -f 'dumpsys.c'
  160. then
  161.     echo shar: will not over-write existing file "'dumpsys.c'"
  162. else
  163. sed 's/^X//' << \SHAR_EOF > 'dumpsys.c'
  164. X/*
  165. X * @begin{boilerplate}
  166. X * Copyright 1991 Ronald Khoo <ronald@ibmpcug.co.uk>
  167. X * This is Really Free Software.
  168. X * Permission granted to use this software for any purpose provided that
  169. X * the author be held free from any blame for anything that may occur as a
  170. X * result of this software being used; that this notice be preserved in all
  171. X * copies of this software and derived works, and the documentation therof;
  172. X * and that any modifications be clearly marked as such.
  173. X * @end{boilerplate}
  174. X */
  175. X#include <sys/types.h>
  176. X#include <sys/systm.h>
  177. X
  178. Xextern struct { int (*func)(); char *name; } functab[];
  179. Xextern struct { struct sysent *sysent; char *name; int nent; } systab[];
  180. Xextern int nsysent;
  181. Xextern nosys();
  182. X
  183. X#if 0
  184. Xmain()
  185. X{
  186. X    int i, j, k;
  187. X    register struct sysent *s;
  188. X
  189. X    printf("dumpsys: %d sysent tables found\n", nsysent);
  190. X
  191. X    for (i = 0; i < nsysent; i++) {
  192. X        printf("\n%s:\n", systab[i].name);
  193. X        for (s = systab[i].sysent; s < systab[i].sysent + systab[i].nent; s++) {
  194. X            printf ("% 4d  |  ", s - systab[i].sysent);
  195. X            printf("% 3d  |  % 3d  | % 2d  |  % 2d  | %#08o | ",
  196. Xs->sy_ret, s->sy_arg386, s->sy_nlarg286, s->sy_nmarg286, s->sy_argmask);
  197. X            k = 1;
  198. X            for (j = 0; functab[j].func; j++)
  199. X                if (functab[j].func == s->sy_call) {
  200. X                    printf("%s\n", functab[j].name);
  201. X                    k = 0;
  202. X                    break;
  203. X                }
  204. X            if (k) printf("%#04x\n", s->sy_call);
  205. X        }
  206. X    }
  207. X}
  208. X#endif
  209. X
  210. Xextern struct sysent sysent[], cxentry[], svidsysent[];
  211. Xint sysent_count, cxentry_count, svidsysent_count;
  212. X
  213. Xstruct { char *name; int *count; } tab2[] = {
  214. X    { "sysent", &sysent_count },
  215. X    { "cxentry", &cxentry_count },
  216. X    { "svidsysent", &svidsysent_count },
  217. X    0
  218. X};
  219. X
  220. X#include <stdio.h>
  221. Xmain()
  222. X{
  223. X    int i, j;
  224. X
  225. X    for (i = 0; i < nsysent; i++)
  226. X        for (j=0; tab2[j].name; j++)
  227. X            if (strcmp(tab2[j].name, systab[i].name) == 0)
  228. X                tab2[j].count[0] = systab[i].nent;
  229. X
  230. X    /* don't ask me how or why this redirection works */
  231. X    /* it just seems to (on xenix 386 2.3.3 anyway) */
  232. X    for (i=0; i < sysent_count; i++)
  233. X        if (sysent[i].sy_call == 0)
  234. X            sysent[i] = svidsysent[sysent[i].sy_arg386];
  235. X    
  236. X    printf("sysent:\n\n");
  237. X    printsys(sysent, sysent_count);
  238. X    printf("\n\ncxentry:\n\n");
  239. X    printsys(cxentry, cxentry_count);
  240. X    exit(0);
  241. X}
  242. X
  243. Xprintsys(ent, count)
  244. X    struct sysent *ent;
  245. X{
  246. X    int i, j;
  247. X
  248. X    for (i = 0; i < count; i++) {
  249. X        register struct sysent *s = ent + i;
  250. X        if (s->sy_call == nosys)
  251. X            continue;
  252. X        printf ("% 4d  |  ", i);
  253. X        printf("% 3d  |  % 3d  |  %#08o | ",
  254. X            s->sy_ret, s->sy_arg386, s->sy_argmask);
  255. X        for (j = 0; functab[j].func; j++)
  256. X            if (functab[j].func == s->sy_call) {
  257. X                printf("%s", functab[j].name);
  258. X                break;
  259. X            }
  260. X        putchar('\n');
  261. X    }
  262. X}
  263. SHAR_EOF
  264. if test 2588 -ne "`wc -c < 'dumpsys.c'`"
  265. then
  266.     echo shar: error transmitting "'dumpsys.c'" '(should have been 2588 characters)'
  267. fi
  268. fi # end of overwriting check
  269. echo shar: extracting "'eaccess.c'" '(1215 characters)'
  270. if test -f 'eaccess.c'
  271. then
  272.     echo shar: will not over-write existing file "'eaccess.c'"
  273. else
  274. sed 's/^X//' << \SHAR_EOF > 'eaccess.c'
  275. X/*
  276. X * eaccess(C) command -- sample usage of cxenix() system call
  277. X */
  278. X/*
  279. X * @begin{boilerplate}
  280. X * Copyright 1991 Ronald Khoo <ronald@ibmpcug.co.uk>
  281. X * This is Really Free Software.
  282. X * Permission granted to use this software for any purpose provided that
  283. X * the author be held free from any blame for anything that may occur as a
  284. X * result of this software being used; that this notice be preserved in all
  285. X * copies of this software and derived works, and the documentation therof;
  286. X * and that any modifications be clearly marked as such.
  287. X * @end{boilerplate}
  288. X */
  289. X
  290. X#define CXENIX_eaccess    37    /* from dumpsys's output */
  291. X
  292. X#include <stdio.h>
  293. X#include <unistd.h>
  294. X#include <errno.h>
  295. X#include <string.h>
  296. X
  297. Xmain(argc, argv)
  298. X    char **argv;
  299. X{
  300. X    char *errstr;
  301. X    int mode;
  302. X
  303. X    if (argc != 3)
  304. X        usage();
  305. X
  306. X    switch(argv[2][0]) {
  307. X    case 'R': case 'r':    mode = R_OK; break;
  308. X    case 'W': case 'w':    mode = W_OK; break;
  309. X    case 'X': case 'x':    mode = X_OK; break;
  310. X    case 'F': case 'f':    mode = F_OK; break;
  311. X    default:        usage();
  312. X    }
  313. X    if (cxenix(CXENIX_eaccess, argv[1], mode) < 0)
  314. X        errstr = strerror(errno);
  315. X    else
  316. X        errstr = "OK";
  317. X
  318. X    printf("%s: %s\n", argv[1], errstr);
  319. X}
  320. X
  321. Xusage()
  322. X{
  323. X    fprintf(stderr, "usage: eaccess file R | W | X | F\n");
  324. X    exit(1);
  325. X}
  326. SHAR_EOF
  327. if test 1215 -ne "`wc -c < 'eaccess.c'`"
  328. then
  329.     echo shar: error transmitting "'eaccess.c'" '(should have been 1215 characters)'
  330. fi
  331. fi # end of overwriting check
  332. echo shar: extracting "'sizes.sh'" '(876 characters)'
  333. if test -f 'sizes.sh'
  334. then
  335.     echo shar: will not over-write existing file "'sizes.sh'"
  336. else
  337. sed 's/^X//' << \SHAR_EOF > 'sizes.sh'
  338. X# /*
  339. X#  * @begin{boilerplate}
  340. X#  * Copyright 1991 Ronald Khoo <ronald@ibmpcug.co.uk>
  341. X#  * This is Really Free Software.
  342. X#  * Permission granted to use this software for any purpose provided that
  343. X#  * the author be held free from any blame for anything that may occur as a
  344. X#  * result of this software being used; that this notice be preserved in all
  345. X#  * copies of this software and derived works, and the documentation therof;
  346. X#  * and that any modifications be clearly marked as such.
  347. X#  * @end{boilerplate}
  348. X#  */
  349. Xwhile read addr symbol
  350. Xdo
  351. X    test "$endsym" && eval "$endsym=$addr"
  352. X    case "$symbol" in
  353. X        *ent*)    endsym=end$symbol
  354. X            eval "begin$symbol=$addr"
  355. X            syms="$syms $symbol"
  356. X            ;;
  357. X        *)    endsym=
  358. X            ;;
  359. X    esac
  360. Xdone
  361. X
  362. Xfor i in $syms
  363. Xdo
  364. X    eval "end=\$end$i"
  365. X    eval "begin=\$begin$i"
  366. X    size="`echo 16i $end $begin -p | tr '[a-f]' '[A-F]' | dc`"
  367. X    echo "#define SIZE_$i\t$size"
  368. Xdone
  369. SHAR_EOF
  370. if test 876 -ne "`wc -c < 'sizes.sh'`"
  371. then
  372.     echo shar: error transmitting "'sizes.sh'" '(should have been 876 characters)'
  373. fi
  374. fi # end of overwriting check
  375. echo shar: extracting "'syscall.S'" '(1053 characters)'
  376. if test -f 'syscall.S'
  377. then
  378.     echo shar: will not over-write existing file "'syscall.S'"
  379. else
  380. sed 's/^X//' << \SHAR_EOF > 'syscall.S'
  381. X/ /*
  382. X/  * @begin{boilerplate}
  383. X/  * Copyright 1991 Ronald Khoo <ronald@ibmpcug.co.uk>
  384. X/  * This is Really Free Software.
  385. X/  * Permission granted to use this software for any purpose provided that
  386. X/  * the author be held free from any blame for anything that may occur as a
  387. X/  * result of this software being used; that this notice be preserved in all
  388. X/  * copies of this software and derived works, and the documentation therof;
  389. X/  * and that any modifications be clearly marked as such.
  390. X/  * @end{boilerplate}
  391. X/  */
  392. X    .file    "syscall.s"
  393. X    .globl    _cxenix
  394. X    .globl    _syscall
  395. X    .globl    _errno
  396. X    .align  2
  397. X_syscall:
  398. X    popl    %edx
  399. X    popl    %eax
  400. X    pushl    %edx
  401. X    / call    far 0x7:0x0
  402. X    .byte    0x9a,0,0,0,0,7,0
  403. X    jb    .L1
  404. X    popl    %edx
  405. X    pushl    %edx
  406. X    pushl    %edx
  407. X    ret
  408. X.L1:    movl    %eax,_errno
  409. X    movl    $-1,%eax
  410. X    popl    %edx
  411. X    pushl    %edx
  412. X    pushl    %edx
  413. X    ret
  414. X_cxenix:
  415. X    popl    %edx
  416. X    popl    %eax
  417. X    pushl    %edx
  418. X    sall $8,%eax
  419. X    leal 40(%eax),%eax
  420. X    / call    far 0x7:0x0
  421. X    .byte    0x9a,0,0,0,0,7,0
  422. X    jb    .L2
  423. X    popl    %edx
  424. X    pushl    %edx
  425. X    pushl    %edx
  426. X    ret
  427. X.L2:    movl    %eax,_errno
  428. X    movl    $-1,%eax
  429. X    popl    %edx
  430. X    pushl    %edx
  431. X    pushl    %edx
  432. X    ret
  433. SHAR_EOF
  434. if test 1053 -ne "`wc -c < 'syscall.S'`"
  435. then
  436.     echo shar: error transmitting "'syscall.S'" '(should have been 1053 characters)'
  437. fi
  438. fi # end of overwriting check
  439. #    End of shell archive
  440. exit 0
  441.  
  442. -- 
  443. Ronald Khoo <ronald@robobar.co.uk> +44 81 991 1142 (O) +44 71 229 7741 (H)
  444.