Пример #1
0
Файл: sh.c Проект: amazonsx/nos
int main(int argc, char *argv[])
{
	char buf[MAX] = {0};
	int count = 0;
	while ((count = get_cmds(buf, MAX)) > 0) {
#if DEBUG == 1
		print_cmds(count);
#endif
		run_cmds(buf);
		init_pipes();
	}
}
Пример #2
0
void
toplevel_show(const char *buf)
{
	static const struct cmdtab show_cmds[] = {
	    {	"args",		show_args,	},
	    {	"bootinfo",	show_bootinfo,	},
#if 0 /* XXX notyet */
	    {	"pt",		show_pt,	},
	    {	"rpb",		show_rpb,	},
#endif
	    {	NULL,				},
	};

	if (dispatch_cmd(buf, show_cmds) == DISPATCH_CMD_NOCMD) {
		printf("no subcommand given.  allowed subcommands:\n");
		print_cmds(show_cmds, NULL, 0);
	}
}
Пример #3
0
const char *
cvt_number(const char *buf, u_int64_t *nump)
{
	int base;
	unsigned char c;

	base = 10;
	*nump = 0;

	c = *buf;
	if (c == '0') {
		c = *(++buf);

		if (c == 'x' || c == 'X') {
			base = 16;
			buf++;
		} else {
			base = 8;
		}
	}

	for (c = *buf; c != '\0' && !isspace(c); c = *(++buf)) {
		switch (base) {
		case 10:
			if (c < '0' || c > '9')
				goto done;
		}
	}
done:

}

int
dispatch_cmd(const char *buf, const struct cmdtab *cmds)
{
	const struct cmdtab *try, *winner;
	size_t nonwhitespace, i;
	unsigned int nmatches;
	const char *pre, *post;
	int rv;

	/* advance past white space. */
	buf = advance_past_space(buf);
	if (buf == NULL)
		return (DISPATCH_CMD_NOCMD);

	/* find how much non-white space there is. */
	nonwhitespace = 0;
	while ((buf[nonwhitespace] != '\0') && !isspace(buf[nonwhitespace]))
		nonwhitespace++;

	/* at this point, nonwhitespace should always be non-zero */
	if (nonwhitespace == 0) {
		printf("assertion failed: dispatch_cmd: nonwhitespace == 0\n");
		halt();
	}

	/* see how many matches there were. */
	for (nmatches = 0, try = cmds;
	    try != NULL && try->cmd != NULL;
	    try++) {
		if (strncmp(buf, try->cmd, nonwhitespace) == 0) {
			winner = try;
			nmatches++;
		}
	}

	if (nmatches == 1) {
		(*winner->fn)(buf + nonwhitespace);
		return (DISPATCH_CMD_MATCHED);
	} else if (nmatches == 0) {
		pre = "invalid command word";
		post = "allowed words";
		rv = DISPATCH_CMD_NOMATCH;
	} else {
		pre = "ambiguous command word";
		post = "matches";
		rv = DISPATCH_CMD_AMBIGUOUS;
	}

	printf("%s \"", pre);
	print_stringarray(buf, nonwhitespace);
	printf("\", %s:\n", post);

	/* print commands.  if no match, print all commands. */
	print_cmds(cmds, buf, rv == DISPATCH_CMD_NOMATCH ? 0 : nonwhitespace);
	return (rv);
}

void
print_cmds(const struct cmdtab *cmds, const char *match, size_t matchlen)
{
	const struct cmdtab *try;

	printf("    ");
	for (try = cmds; try != NULL && try->cmd != NULL; try++) {
		if (strncmp(match, try->cmd, matchlen) == 0)
			printf("%s%s", try != cmds ? ", " : "", try->cmd);
	}
	printf("\n");
}

void
print_stringarray(const char *s, size_t maxlen)
{
	size_t i;

	for (i = 0; (i < maxlen) && (*s != '\0'); i++, s++)
		putchar(*s);
}

void
warn_ignored_args(const char *buf, const char *cmd)
{

	if (advance_past_space(buf) != NULL)
		printf("WARNING: extra arguments to \"%s\" command ignored\n",
		    cmd);
}


/*
 * Top-level Commands
 */

void
toplevel_dpb(const char *buf)
{
	u_int64_t startaddr, count = 1;

	buf = advance_past_space(buf);
	if (buf == NULL) {
		printf("\"dpb\" must be given starting address\n");
		return;
	}
	buf = cvt_number(buf, &startaddr);
	if (*buf != '\0' && !isspace(*buf)) {
		printf("bad character '%c' in starting address\n");
		return;
	}

	buf = advance_past_space(buf);
	if (buf != NULL) {
		buf = cvt_number(buf, &count);
		if (*buf != '\0' && !isspace(*buf)) {
			printf("bad character '%c' in count\n");
			return;
		}
		buf = advance_past_space(buf);
		if (buf != NULL) {
			printf("extra args at end of \"dpb\" command\n");
			return;
		}
	}

	printf("startaddr = 0x%lx, count = 0x%lx\n", startaddr, count);
	printf("\"dpb\" not yet implemented\n");
}

void
toplevel_dpl(const char *buf)
{

	printf("\"dpl\" not yet implemented\n");
}

void
toplevel_dpq(const char *buf)
{

	printf("\"dpq\" not yet implemented\n");
}
int hw_parse_dsi_cmds(struct dsi_panel_cmds *pcmds)
{
	int blen = 0, len = 0;
	char *buf = NULL, *bp = NULL;
	struct dsi_ctrl_hdr *dchdr;
	int i = 0, cnt = 0;

	memset(pcmds, sizeof(struct dsi_panel_cmds), 0);

	if (!lcd_debug_malloc_dtsi_para((void **)&buf, &blen)) {
		//LCD_LOG_ERR("%s: failed\n", __func__);
		return -ENOMEM;
	}

	/* scan dcs commands */
	bp = buf;
	len = blen;
	cnt = 0;
	while (len > sizeof(*dchdr)) {
		dchdr = (struct dsi_ctrl_hdr *)bp;
		dchdr->dlen = ntohs(dchdr->dlen);
		if (dchdr->dlen > len) {
			LCD_LOG_ERR("%s: dtsi cmd=%x error, len=%d",
				__func__, dchdr->dtype, dchdr->dlen);
			return -ENOMEM;
		}
		bp += sizeof(*dchdr);
		len -= sizeof(*dchdr);
		bp += dchdr->dlen;
		len -= dchdr->dlen;
		cnt++;
	}

	if (len != 0) {
		LCD_LOG_ERR("%s: dcs_cmd=%x len=%d error!",
				__func__, buf[0], blen);
		kfree(buf);
		return -ENOMEM;
	}

	pcmds->cmds = kzalloc(cnt * sizeof(struct dsi_cmd_desc),
						GFP_KERNEL);
	if (!pcmds->cmds){
		kfree(buf);
		return -ENOMEM;
	}

	pcmds->cmd_cnt = cnt;
	pcmds->buf = buf;
	pcmds->blen = blen;

	bp = buf;
	len = blen;
	for (i = 0; i < cnt; i++) {
		dchdr = (struct dsi_ctrl_hdr *)bp;
		len -= sizeof(*dchdr);
		bp += sizeof(*dchdr);
		pcmds->cmds[i].dchdr = *dchdr;
		pcmds->cmds[i].payload = bp;
		bp += dchdr->dlen;
		len -= dchdr->dlen;
	}

	print_cmds(pcmds->cmds, pcmds->cmd_cnt);

	LCD_LOG_INFO("%s: dcs_cmd=%x len=%d, cmd_cnt=%d\n", __func__,
		pcmds->buf[0], pcmds->blen, pcmds->cmd_cnt);

	return 0;
}
/*
 * This function is called by the assembly STUB function
 */
void uart_handler() {
	
	// Disable all interupts
	atomic_up();
	
	#ifdef _IO_DEBUG
		rtx_dbug_outs((CHAR *) "Enter: uart_handler\r\n");
		rtx_dbug_outs((CHAR *) "Reading data...\r\n");
	#endif

	// irene said this should be enough - would be
	// very rare if it wasn't ready to read
	while (!(SERIAL1_UCSR & 1)) { }
	
	char_in = SERIAL1_RD;

	#ifdef _IO_DEBUG
		rtx_dbug_outs((CHAR *) "Determining what to do with char...\r\n");
	#endif

	struct io_message * msg;

	switch(char_in) {
		#ifdef _HOTKEYS_DEBUG
			case '!':
				rtx_dbug_outs((CHAR *) "'!' hotkey detected...\r\n");
				print_queues();	// print processes on ready queue and priorities
				break;
			case '@':
				rtx_dbug_outs((CHAR *) "'@' hotkey detected...\r\n");
				print_mem_blocked();	// print processes on memory blocked queue and priorities
				break;
			case '#':
				rtx_dbug_outs((CHAR *) "'#' hotkey detected...\r\n");
				print_msg_blocked();	// print processes on message blocked queue and priorities
				break;
			case '$':
				rtx_dbug_outs((CHAR *) "'$' hotkey detected...\r\n");
				print_availible_mem_queue();	// print available memory queue
				break;
			case '^':
				rtx_dbug_outs((CHAR *) "'^' hotkey detected...\r\n");
				print_used_mem_queue();	// print used memory queue
				break;
			case '&':
				rtx_dbug_outs((CHAR *) "'&' hotkey detected...\r\n");		
				output_kcd_buffer();	// print kcd buffer
				break;
			case '*':
				rtx_dbug_outs((CHAR *) "'*' hotkey detected...\r\n");
				print_cmds();	// print valid commands
				break;
		#endif
		
		default:
			#ifdef _IO_DEBUG
				rtx_dbug_outs((CHAR *) "Sending message to KCD proc...\r\n");
			#endif
			
			if (!are_blocks_available()) {
				atomic_down();
				return;
			}

			msg = (io_message *)request_memory_block();
			
			// reset tx/rx and send it to kcd
			msg->tx = UART_PID;
			msg->rx = KCD_PID;
			msg->msg[0] = char_in;
			send_message(KCD_PID, msg);
			break;
	}
	
	// Enable all interupts
	atomic_down();
}