⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moncom.c

📁 umon bootloader source code, support mips cpu.
💻 C
字号:
/* moncom.c:
 *	This function is used by the application to interface to code that
 *	is part of the monitor.  A pointer to this function exists at some
 *	"well-known" address in the monitors space.  This location must be
 *	known by the application (hence... "well-known").
 */
#include "config.h"
#include "monlib.h"
#include "genlib.h"
#include "stddefs.h"
#include "bbc.h"
#include "tfs.h"
#include "tfsprivate.h"
#include "monflags.h"
#include "pci.h"
#include "i2c.h"
#include "ether.h"
#include "flash.h"

extern int addcommand(struct monCommand *cmdlist, char *cmdlvl);
extern int profiler(void *);
static int moncom_pcnt;

int monErrorStub(void);

int
moncom(int cmd, void *arg1, void *arg2, void *arg3)
{
	int	retval;
	
	/* eliminate warnings due to arg2 & arg3 not being used...
	 */
	if (arg2 == arg3)
		retval = 0;
	else
	retval = 0;

	switch(cmd) {
		case GETMONFUNC_PUTCHAR:
			*(unsigned long *)arg1 = (unsigned long)putchar;
			break;
		case GETMONFUNC_GETCHAR:
			*(unsigned long *)arg1 = (unsigned long)getchar;
			break;
		case GETMONFUNC_GOTACHAR:
			*(unsigned long *)arg1 = (unsigned long)gotachar;
			break;
		case GETMONFUNC_GETBYTES:
			*(unsigned long *)arg1 = (unsigned long)getbytes;
			break;
		case GETMONFUNC_PRINTF:
			*(unsigned long *)arg1 = (unsigned long)printf;
			break;
		case GETMONFUNC_CPRINTF:
			*(unsigned long *)arg1 = (unsigned long)cprintf;
			break;
		case GETMONFUNC_SPRINTF:
			*(unsigned long *)arg1 = (unsigned long)sprintf;
			break;
		case GETMONFUNC_RESTART:
			*(unsigned long *)arg1 = (unsigned long)monrestart;
			break;
		case GETMONFUNC_GETENV:
			*(unsigned long *)arg1 = (unsigned long)getenv;
			break;
		case GETMONFUNC_SETENV:
			*(unsigned long *)arg1 = (unsigned long)setenv;
			break;
		case GETMONFUNC_TFSINIT:
			*(unsigned long *)arg1 = (unsigned long)tfsinit;
			break;
		case GETMONFUNC_TFSADD:
			*(unsigned long *)arg1 = (unsigned long)tfsadd;
			break;
		case GETMONFUNC_TFSUNLINK:
			*(unsigned long *)arg1 = (unsigned long)tfsunlink;
			break;
		case GETMONFUNC_TFSRUN:
			*(unsigned long *)arg1 = (unsigned long)tfsrun;
			break;
		case GETMONFUNC_TFSNEXT:
			*(unsigned long *)arg1 = (unsigned long)tfsnext;
			break;
		case GETMONFUNC_TFSFSTAT:
			*(unsigned long *)arg1 = (unsigned long)tfsfstat;
			break;
		case GETMONFUNC_TFSTRUNCATE:
			*(unsigned long *)arg1 = (unsigned long)tfstruncate;
			break;
		case GETMONFUNC_TFSEOF:
			*(unsigned long *)arg1 = (unsigned long)tfseof;
			break;
		case GETMONFUNC_TFSSTAT:
			*(unsigned long *)arg1 = (unsigned long)tfsstat;
			break;
		case GETMONFUNC_TFSREAD:
			*(unsigned long *)arg1 = (unsigned long)tfsread;
			break;
		case GETMONFUNC_TFSWRITE:
			*(unsigned long *)arg1 = (unsigned long)tfswrite;
			break;
		case GETMONFUNC_TFSOPEN:
			*(unsigned long *)arg1 = (unsigned long)tfsopen;
			break;
		case GETMONFUNC_TFSCLOSE:
			*(unsigned long *)arg1 = (unsigned long)tfsclose;
			break;
		case GETMONFUNC_TFSSEEK:
			*(unsigned long *)arg1 = (unsigned long)tfsseek;
			break;
		case GETMONFUNC_TFSGETLINE:
			*(unsigned long *)arg1 = (unsigned long)tfsgetline;
			break;
		case GETMONFUNC_TFSIPMOD:
			*(unsigned long *)arg1 = (unsigned long)tfsipmod;
			break;
		case GETMONFUNC_TFSCTRL:
			*(unsigned long *)arg1 = (unsigned long)tfsctrl;
			break;
		case GETMONFUNC_ADDCOMMAND:
			*(unsigned long *)arg1 = (unsigned long)addcommand;
			break;
		case GETMONFUNC_DOCOMMAND:
			*(unsigned long *)arg1 = (unsigned long)docommand;
			break;
		case GETMONFUNC_GETARGV:
			*(unsigned long *)arg1 = (unsigned long)getargv;
			break;
		case GETMONFUNC_CRC16:
			*(unsigned long *)arg1 = (unsigned long)xcrc16;
			break;
		case GETMONFUNC_CRC32:
			*(unsigned long *)arg1 = (unsigned long)crc32;
			break;
		case GETMONFUNC_INTSOFF:
			*(unsigned long *)arg1 = (unsigned long)intsoff;
			break;
		case GETMONFUNC_INTSRESTORE:
			*(unsigned long *)arg1 = (unsigned long)intsrestore;
			break;
		case GETMONFUNC_APPEXIT:
			*(unsigned long *)arg1 = (unsigned long)appexit;
			break;
		case GETMONFUNC_MALLOC:
			*(unsigned long *)arg1 = (unsigned long)malloc;
			break;
		case GETMONFUNC_FREE:
			*(unsigned long *)arg1 = (unsigned long)free;
			break;
		case GETMONFUNC_GETLINE:
			*(unsigned long *)arg1 = (unsigned long)getline;
			break;
		case GETMONFUNC_DECOMPRESS:
			*(unsigned long *)arg1 = (unsigned long)decompress;
			break;
		case GETMONFUNC_HEAPXTEND:
			*(unsigned long *)arg1 = (unsigned long)extendHeap;
			break;
		case GETMONFUNC_PROFILER:
			*(unsigned long *)arg1 = (unsigned long)profiler;
			break;
		case GETMONFUNC_TFSLINK:
			*(unsigned long *)arg1 = (unsigned long)tfslink;
			break;
		case GETMONFUNC_BBC:
			*(unsigned long *)arg1 = (unsigned long)bbc;
			break;
		case GETMONFUNC_MEMTRACE:
			*(unsigned long *)arg1 = (unsigned long)Mtrace;
			break;
		case GETMONFUNC_TFSTELL:
			*(unsigned long *)arg1 = (unsigned long)tfstell;
			break;
		case GETMONFUNC_VERSION:
			*(unsigned long *)arg1 = (unsigned long)monVersion;
			break;
		case GETMONFUNC_WARMSTART:
			*(unsigned long *)arg1 = (unsigned long)AppWarmStart;
			break;
		case GETMONFUNC_PCICFGREAD:
			*(unsigned long *)arg1 = (unsigned long)pciCfgRead;
			break;
		case GETMONFUNC_PCICFGWRITE:
			*(unsigned long *)arg1 = (unsigned long)pciCfgWrite;
			break;
		case GETMONFUNC_PCICONTROL:
			*(unsigned long *)arg1 = (unsigned long)pciCtrl;
			break;
		case GETMONFUNC_I2CWRITE:
			*(unsigned long *)arg1 = (unsigned long)i2cWrite;
			break;
		case GETMONFUNC_I2CREAD:
			*(unsigned long *)arg1 = (unsigned long)i2cRead;
			break;
		case GETMONFUNC_I2CCONTROL:
			*(unsigned long *)arg1 = (unsigned long)i2cCtrl;
			break;
		case GETMONFUNC_MONDELAY:
			*(unsigned long *)arg1 = (unsigned long)monDelay;
			break;
		case GETMONFUNC_GETENVP:
			*(unsigned long *)arg1 = (unsigned long)getenvp;
			break;
		case GETMONFUNC_REALLOC:
			*(unsigned long *)arg1 = (unsigned long)realloc;
			break;
		case GETMONFUNC_PIOGET:		/* As of uMon 1.0, these are */
		case GETMONFUNC_PIOSET:		/* no longer supported. */
		case GETMONFUNC_PIOCLR:		
			*(unsigned long *)arg1 = (unsigned long)monErrorStub;
			break;
#if INCLUDE_ETHERNET
		case GETMONFUNC_SENDENETPKT:
			*(unsigned long *)arg1 = (unsigned long)monSendEnetPkt;
			break;
		case GETMONFUNC_RECVENETPKT:
			*(unsigned long *)arg1 = (unsigned long)monRecvEnetPkt;
			break;
		case GETMONFUNC_PRINTPKT:
			*(unsigned long *)arg1 = (unsigned long)AppPrintPkt;
			break;
#else
		case GETMONFUNC_PRINTPKT:
		case GETMONFUNC_SENDENETPKT:
		case GETMONFUNC_RECVENETPKT:
			*(unsigned long *)arg1 = (unsigned long)monErrorStub;
			break;
#endif
		case GETMONFUNC_GETSYM:
			*(unsigned long *)arg1 = (unsigned long)getsym;
			break;
#if INCLUDE_FLASH
		case GETMONFUNC_FLASHWRITE:
			*(unsigned long *)arg1 = (unsigned long)AppFlashWrite;
			break;
		case GETMONFUNC_FLASHERASE:
			*(unsigned long *)arg1 = (unsigned long)AppFlashErase;
			break;
		case GETMONFUNC_FLASHINFO:
			*(unsigned long *)arg1 = (unsigned long)sectortoaddr;
			break;
#else
		case GETMONFUNC_FLASHWRITE:
		case GETMONFUNC_FLASHERASE:
		case GETMONFUNC_FLASHINFO:
			*(unsigned long *)arg1 = (unsigned long)monErrorStub;
			break;
#endif

		case GETMONFUNC_ASSIGNHDLR:
#ifdef ALLOW_HANDLER_ASSIGNMENT
			*(unsigned long *)arg1 = (unsigned long)assign_handler;
#else
			*(unsigned long *)arg1 = (unsigned long)monErrorStub;
#endif
			break;

		case GETMONFUNC_WATCHDOG:
			*(unsigned long *)arg1 = (unsigned long)monWatchDog;
			break;
		case GETMONFUNC_PRINTMEM:
			*(unsigned long *)arg1 = (unsigned long)printMem;
			break;
		case GETMONFUNC_PORTCMD:
#if INCLUDE_PORTCMD
			*(unsigned long *)arg1 = (unsigned long)portCmd;
#else
			*(unsigned long *)arg1 = (unsigned long)monErrorStub;
#endif
			break;
		case CACHEFTYPE_DFLUSH:
			dcacheFlush = (int(*)(char *,int))arg1;
			break;
		case CACHEFTYPE_IINVALIDATE:
			icacheInvalidate = (int(*)(char *,int))arg1;
			break;
		case CHARFUNC_PUTCHAR:
			remoteputchar = (int(*)(int))arg1;
			break;
		case CHARFUNC_GETCHAR:
			remotegetchar = (int(*)(void))arg1;
			break;
		case CHARFUNC_GOTACHAR:
			remotegotachar = (int(*)(void))arg1;
			break;
		case CHARFUNC_RAWMODEON:
			remoterawon = (int(*)(void))arg1;
			break;
		case CHARFUNC_RAWMODEOFF:
			remoterawoff = (int(*)(void))arg1;
			break;
		case ASSIGNFUNC_GETUSERLEVEL:
			extgetUsrLvl = (int(*)(void))arg1;
			break;
		default:
			printf("moncom unknown command: 0x%x\n",cmd);
			retval = -1;
			break;
	}
	moncom_pcnt++;
	return(retval);
}

int
monErrorStub(void)
{
	printf("ERROR: Facility not included in monitor build\n"); 
	return(-1);
}

/* We use some "negative logic" here so that the majority of the targets
 * that do not have PCI and/or I2C will receive the stubs by default.
 * If your target has real PCI monlib functions, then the target-specific
 * config.h file should have NO_MONLIB_PCI_STUBS defined.
 * Same logic applies to I2c.
 */

#ifndef NO_MONLIB_PCI_STUBS
int
pciCtrl(int interface, int cmd, unsigned long arg1,unsigned long arg2)
{
	/* Use the args to silence warnings.
	 */
	interface = 0;
	cmd = 0;
	arg1 = 0;
	arg2 = 0;
	return(-1);
}

ulong
pciCfgRead(int interface,int bus,int device,int func,int regno)
{
	/* Use the args to silence warnings.
	 */
	interface = 0;
	bus = 0;
	device = 0;
	func = 0;
	regno = 0;
	return(0);
}

int
pciCfgWrite(int interface,int bus,int device,int func,int regno,ulong value)
{
	/* Use the args to silence warnings.
	 */
	interface = 0;
	bus = 0;
	device = 0;
	func = 0;
	regno = 0;
	value = 0;
	return(-1);
}
#endif

#ifndef NO_MONLIB_I2C_STUBS
int
i2cCtrl(int interface, int cmd, unsigned long arg1, unsigned long arg2)
{
	/* Use the args to silence warnings.
	 */
	interface = 0;
	cmd = 0;
	arg1 = 0;
	arg2 = 0;
	return(-1);
}

int
i2cWrite(int interface, int bigaddr, uchar *data, int len)
{
	/* Use the args to silence warnings.
	 */
	interface = 0;
	bigaddr = 0;
	if (data)
		len = 0;
	return(-1);
}

int
i2cRead(int interface, int bigaddr, uchar *data, int len)
{
	/* Use the args to silence warnings.
	 */
	interface = 0;
	bigaddr = 0;
	if (data)
		len = 0;
	return(-1);
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -