/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos720 src/bos/usr/bin/sysdumpdev/dumpfmt/kext/ketestext.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[] = "@(#)73	1.1  src/bos/usr/bin/sysdumpdev/dumpfmt/kext/ketestext.c.S, cmdcrash, bos720 1/11/96 14:53:06";

/*
 * COMPONENT_NAME: (CMDCRASH)
 *
 * FUNCTIONS: 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/malloc.h>
#include <sys/uio.h>
#include <sys/dump.h>
#include <sys/seg.h>
#include "../ketest.h"

/* config parameters. */
struct extparms ep;			
char *buf;

/* dump routine prototype */
struct cdt *dmp_tbl(int which);

/*
 * Kernel extension entry point, called at config. time.
 * Registers the dump routine called during the dump.
 *
 * input:
 *	cmd - unused (typically 1=config, 2=unconfig)
 *	uiop - points to the uio structure.
 */
int
ketestext(int cmd, struct uio *uiop)
{
	int rc;
	char *bufp;

	/* get the passed data */
	if ((rc=uiomove((char *)&ep,sizeof(ep),UIO_WRITE,uiop)) != 0) return(rc);

	/* Allocate a buffer for the data */
	buf = (char *)xmalloc(ep.len,0,kernel_heap);
	if (buf)
		copyin(ep.buf,buf,ep.len);

	/* The dump routine must be pinned.
	 * In this case, pincode will pin this entire module.
	 */
	if ((rc=pincode(dmp_tbl))==0) {
		/* Register the dump formatter */
		rc = dmp_add(dmp_tbl);
	}

	return(rc);
}

/*
 * Both the dump table and the dmp_tbl() function must be pinned.
 * The data dumped need not be pinned, however the function must not
 * reference data that may be paged out.
 */
struct {
	struct cdt_head _cdt_head;	/* Header */
	struct cdt_entry cde[2];	/* 3 entries */
} tbl;

/*
 * Setup and return the tbl structure at dump time.
 *
 * Environment:  Must be pinned and cannot page fault.
 *
 * Input:  which=1 means setup the table.
 *	   which=2 means dumping is finished.
 *
 * Output: The table's address is returned.
 */
struct cdt *
dmp_tbl(int which)
{
	/* If initial call */
	if (which==1) {
		/* Setup the header */
		tbl.cdt_magic = DMP_MAGIC;
		strcpy(tbl.cdt_name,"sample_table");
		/* We'll have 2 entries. */
		tbl.cdt_len = sizeof(tbl._cdt_head)+2*sizeof(struct cdt_entry);

		/* Setup the entries now. */
		/* All in the kernel segment */
		tbl.cde[0].d_segval = tbl.cde[1].d_segval = tbl.cde[2].d_segval = KERNELSEGVAL;
		/* dump the extparms structure */
		strcpy(tbl.cde[0].d_name,"extparms");
		tbl.cde[0].d_ptr = (char *)&ep;
		tbl.cde[0].d_len = sizeof(ep);
		/* dump the buffer */
		strcpy(tbl.cde[1].d_name,"buffer");
		tbl.cde[1].d_ptr = buf;
		tbl.cde[1].d_len = ep.len;
	}

	return((struct cdt *)&tbl);
}
