Adding PMON Commands

Adding commands to PMON is very simple. In this example, we wish to add a command called mycmd. This command simply identifies itself and prints out a list of its arguments. The function is placed in a file called mycmd.c in the pmon subdirectory. Notice that it is called with an argc/argv argument list in exactly the same way as a normal C program is called. As with UNIX, the name of the command is located in argv[0].

pmon/mycmd.c

	Optdesc mycmd_opts[] = {
		{"","My Command"},
		{0}};

	mycmd(argc,argv)
	int argc;
	char *argv[];
	{
	int i;

	printf("This is my command. Arguments were: ");
	for (i=1;i<argc;i++) printf("%s ",argv[i]);
	printf("\n");
	}


Note that you can also list any options that your new command accepts, to the mycmd_opts array. The first field can contain the list of options. Additional lines would explain those options. For example,

	Optdesc mycmd_opts[] = {
		{"[-fl]","My Command"},
		{"-f","Find bug"},
		{"-l","Lose bug"},
		{0}};
The name of this function must now be installed in the table of commands. The easiest way to do this is by using addCmdRec(). You can place this call almost anywhere, but perhaps the best place is in the CPU-specific high-init init code, eg. c4101.c. There is already a list of commands in this file, you just need to all yours to the list.

	CmdRec cmds[] = {
		{"cache",mycmd_opts,mycmd},
		.....
		{0}};
Finally, the new module must be added to the list used by the Makefile.

pmon/files.mk

	CFILES = sonic.c main.c commands.c dis.c hist.c regs.c sym.c \
		 set.c stty.c more.c memtst.c go.c load.c debug.c \
		 cmdtable.c sbrk.c mycmd.c
To support arguments that can be complex expressions, convert the argument from ascii to binary using the function get_rsa(). This function has the prototype:
	int get_rsa(unsigned long *value, char *source);
Where:

source is the input ascii string.
value is the place where the binary value is to be written.
The return value is 1 if the conversion was successful, otherwise it is zero. get_rsa() prints its own messages if the conversion was unsuccessful.

Example:

	if(!get_rsa(&adr,av[i])) return;
Once the files havebeen modified, you need to rebuild PMON and make new ROMs.


Navigation: Document Home | Document Contents | Document Index