/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos720 src/bos/usr/bin/sysdumpdev/dumpfmt/kext/ketest.c.S 1.1          */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1996                   */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
static char sccsid[] = "@(#)72	1.1  src/bos/usr/bin/sysdumpdev/dumpfmt/kext/ketest.c.S, cmdcrash, bos720 1/11/96 14:52:34";

/*
 * COMPONENT_NAME: (CMDCRASH)
 *
 * FUNCTIONS: Configure the sample kernel extension.
 *
 * ORIGINS: 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 1996
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

#include <sys/types.h>
#include <sys/sysconfig.h>
#include <stdio.h>
#include <strings.h>
#include <unistd.h>
#include "../ketest.h"

static char *help_text[] = {
"ketestdrvr [parameters]\n",
"Calls a sample kernel extension.\n",
""};

/* Extension loading data */
struct cfg_load cfg_load;
char progname[] = "./ketestext";
void loadit(), unloadit();

/*
 * Configure the sample kernel extension.
 *	The ketestext kernel extension is called at its entry point by
 *	sysconfig's SYS_CFGKMOD call.  Parameters are in the uio structure.
 *	4 parameters are passed to the extension of one word each.
 *	The first 2 are argc and argv.
 *	the 3rd is the address of the test message buffer; the 4th is 
 *	its length.
 *
 * input:  none
 *
 * Output:  none
 */

main(argc,argv)
int argc;
char *argv[];
{
	int rc;
	char buf[BUFLEN];
	struct cfg_kmod cfg_kmod;
	struct extparms extparms = {argc,argv,buf,BUFLEN};

	/* Load the extension. */
	loadit();

	/* Setup the parameters. */
	bzero(buf,BUFLEN);
	strcpy(buf,"sample string");
	cfg_kmod.kmid = cfg_load.kmid;
	cfg_kmod.cmd = 0;
	cfg_kmod.mdiptr = (char *)&extparms;
	cfg_kmod.mdilen = sizeof(extparms);

	/* Call the extension */
	sync(); sync(); sync();
	if (sysconfig(SYS_CFGKMOD,&cfg_kmod,sizeof(cfg_kmod))!=CONF_SUCC) {
		/* Error, unload extension too */
		perror(progname);
	}

	return(rc);
}

help()
{
	char **p;

	for (p=help_text; **p!='\0'; p++)
		fprintf(stderr,*p);
	exit(1);
}

/*
 * load a kernel extension.
 */
void loadit()
{
	extern int sysconfig();

	cfg_load.path = progname;
	cfg_load.libpath = NULL;

	/* Call sysconf to load it. */
	if (sysconfig(SYS_KLOAD,&cfg_load,sizeof(cfg_load))!=CONF_SUCC) {
		/* Error */
		perror("loadit");
		exit(2);
	}
}

/*
 * Unload the extension.
 */
void unloadit()
{
	if (sysconfig(SYS_KULOAD,&cfg_load,sizeof(cfg_load))!=CONF_SUCC){
		perror("loadit");
		exit(2);
	}
}
