📄 parser.c
字号:
itc_printf("Server IP address: %s\r\n", iptoa(status.siaddr)); return retval;}////////////////////////////////////////////////////////////////////////////////// set_speed_parse// PURPOSE: Parses a set speed command and changes the CPU speed accordingly.// PARAMS: (IN) char *arg - argument(s) to the set speed command.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intset_speed_parse(char const *arg){ u32 speed; if(!(arg = get_number_parse(arg, &speed))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else { const int newspeed = set_cpu_speed(speed); if (newspeed < 0) { error_print(PARSE_INVALID_ARG_ERROR); } else { const u16 storedspeed = newspeed; // Store as u16 to save space itc_printf("CPU speed set to %d MHz\r\n", newspeed); (void) eeprom_write_item("CPUCLK", sizeof("CPUCLK")-1, &storedspeed, sizeof(storedspeed)); } } return 1;}////////////////////////////////////////////////////////////////////////////////// set_gw_parse// PURPOSE: Parses a set gw (gateway) command and changes the gateway IP address// accordingly.// PARAMS: (IN) char *arg - argument(s) to the set gw command.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intset_gw_parse(char const *arg){ u32 ip; int retval = 0; if(*arg != 0) { if(!(ip = atoip(arg))) { error_print(PARSE_INVALID_ARG_ERROR); retval = 0; } else { const u32 flags = FLAG_USE_STATICIP; status.giaddr = ip; (void) eeprom_write_item("FLAGS", sizeof("FLAGS")-1, &flags, sizeof(flags)); (void) eeprom_write_item("SGATE", sizeof("SGATE")-1, &status.giaddr, sizeof(status.giaddr)); retval = 1; } } itc_printf("Gateway IP address: %s\r\n", iptoa(status.giaddr)); return retval;}////////////////////////////////////////////////////////////////////////////////// set_mask_parse// PURPOSE: Parses a set mask command and changes the subnet mask accordingly.// PARAMS: (IN) char *arg - argument(s) to the set mask command.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intset_mask_parse(char const *arg){ u32 ip; int retval = 0; if(*arg != 0) { if(!(ip = atoip(arg))) { error_print(PARSE_INVALID_ARG_ERROR); retval = 0; } else { const u32 flags = FLAG_USE_STATICIP; status.smask = ip; (void) eeprom_write_item("FLAGS", sizeof("FLAGS")-1, &flags, sizeof(flags)); (void) eeprom_write_item("SMASK", sizeof("SMASK")-1, &status.smask, sizeof(status.smask)); retval = 0; } } itc_printf("Subnet Mask: %s\r\n", iptoa(status.smask)); return retval;}////////////////////////////////////////////////////////////////////////////////// getbyte_parse// PURPOSE: Parses a getbyte command and prints memory locations accordingly.// PARAMS: (IN) char *arg - argument string to parse.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intgetbyte_parse(char const *arg){ u8 *address; u32 length; if(!(arg = get_number_parse(arg, (u32 *)&address))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else if(!get_number_parse(arg, &length)) { length = 1; } print_bytes(address, length); return 1;}////////////////////////////////////////////////////////////////////////////////// getbyte_parse// PURPOSE: Parses a getword command and prints memory locations accordingly.// PARAMS: (IN) char *arg - argument string to parse.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intgetword_parse(char const *arg){ u16 *address; u32 length; if(!(arg = get_number_parse(arg, (u32 *)&address))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else if(!get_number_parse(arg, &length)) { length = 1; } print_words(address, length); return 1;}////////////////////////////////////////////////////////////////////////////////// getdword_parse// PURPOSE: Parses a getdword command and prints memory locations accordingly.// PARAMS: (IN) char *arg - argument string to parse.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intgetdword_parse(char const *arg){ u32 *address; u32 length; if(!(arg = get_number_parse(arg, (u32 *)&address))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else if(!get_number_parse(arg, &length)) { length = 1; } print_dwords(address, length); return 1;}////////////////////////////////////////////////////////////////////////////////// setbyte_parse// PURPOSE: Sets 8 bit aligned memory to an 8 bit pattern.// PARAMS: (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intsetbyte_parse(char const *arg){ u8 *address; u32 value; int length; if(!get_number_parse(arg, (u32 *)&address)) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); if(!(get_number_parse(arg, &value))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); if(!get_number_parse(arg, (u32 *)&length)) { length = 1; } memset8(address, (u8)value, length); return 1;}////////////////////////////////////////////////////////////////////////////////// setword_parse// PURPOSE: Sets 16 bit aligned memory to a 16 bit pattern.// PARAMS: (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intsetword_parse(char const *arg){ u16 *address; u32 value; int length; if(!(get_number_parse(arg, (u32 *)&address))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); if(!(get_number_parse(arg, &value))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); if(!get_number_parse(arg, (u32 *)&length)) { length = 1; } if((u32)address % sizeof(u16)) { error_print(PARSE_ALIGN_ERROR); return 0; } memset16(address, (u16)value, length); return 1;}////////////////////////////////////////////////////////////////////////////////// setdword_parse// PURPOSE: Sets 32 bit aligned memory to an 32 bit pattern.// PARAMS: (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intsetdword_parse(char const *arg){ u32 *address; u32 value; int length; if(!(get_number_parse(arg, (u32 *)&address))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); if(!(get_number_parse(arg, &value))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); if(!get_number_parse(arg, (u32 *)&length)) { length = 1; } if((u32)address % sizeof(u32)) { error_print(PARSE_ALIGN_ERROR); return 0; } memset32(address, value, length); return 1;}////////////////////////////////////////////////////////////////////////////////// exec_parse// PURPOSE: Executes, and if necessary downloads, a script containing IBoot// commands// PARAMS: (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intexec_parse(char const *arg){ int size = 0; char *curline; char buf[MAX_SCRIPT_SIZE], filename[MAX_FILENAME_SIZE]; u32 addr; /* see if address of script was specified */ if(!get_number_parse(arg, (u32 *)&curline)) { /* see if IP address was given */ arg = next_token(arg); curline = (char *)buf; if (*arg == ':') { if(!(addr = atoip(arg))) { error_print(PARSE_INVALID_IP_ERROR); return 0; } status.siaddr = addr; arg = next_token(arg); } if (status.siaddr == 0) { error_print(PARSE_INVALID_IP_ERROR); return 0; } if(!(get_filename_parse(arg, filename, sizeof(filename)))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if(status.ciaddr == 0) { u32 temp; message_print(PARSE_DHCP_MESSAGE); if(!init_dhcp(&status.ciaddr, &temp, &status.giaddr, &status.smask)) { error_print(DHCP_TIMEOUT_ERROR); return 0; } } size = tftpget(arg, (u8 *)buf); if(size < 0) { itc_printf("\r\n"); error_print(TFTP_TIMEOUT_ERROR); return 0; } if(size >= sizeof(buf)) { /* The stack has been overwritten so it is unsafe to continue */ itc_printf("\r\n"); error_print(PARSE_INVALID_ARG_ERROR); itc_printf("Halting.\r\n"); /* endless loop */ for (;;); } buf[size] = 0; } return parse_script (curline) != mode_error;}////////////////////////////////////////////////////////////////////////////////// copy_parse// PURPOSE: Copies a region of memory to another region of memory.// PARAMS: (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intcopy_parse(char const *arg){ int length; u8 *dest, *src; char const *temp; temp = get_number_parse(arg, (u32 *)&dest); if (temp) { temp = get_number_parse(temp, (u32 *)&src); if (temp) { temp = get_number_parse(temp, (u32 *)&length); } } if(temp == NULL) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if((u32)dest < PLATFORM_MEMORY_BASE || (u32)dest > PLATFORM_MEMORY_MAX) { error_print(PARSE_RANGE_ERROR); return 0; } itc_memcpy (dest, src, length); return 1;}////////////////////////////////////////////////////////////////////////////////// memtest_parse// PURPOSE: Runs various memory tests on a memory range.// PARAMS: (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intmemtest_parse(char const *arg){ char const *temp; u32 start, end; if(!(temp = get_number_parse(arg, &start))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else if(!get_number_parse(temp, &end)) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else { itc_printf("Testing from 0x%x to 0x%x\r\n", (u32)start, (u32)end); itc_printf("Walking ones: %s.\r\n", (do_walking_ones((unsigned int)start, (unsigned int)end) ? "Failed" : "Passed")); itc_printf("Walking zeros: %s.\r\n", (do_walking_zeros((unsigned int)start, (unsigned int)end) ? "Failed" : "Passed")); itc_printf("Streaming ones: %s.\r\n", (do_streaming_ones((unsigned int)start, (unsigned int)end) ? "Failed" : "Passed")); itc_printf("Streaming zeros: %s.\r\n", (do_streaming_zeros((unsigned int)start, (unsigned int)end) ? "Failed" : "Passed")); } return 1;}////////////////////////////////////////////////////////////////////////////////// crc_parse// PURPOSE: Calculates CRC on a memory range.// PARAMS: (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intcrc_parse(char const *arg){ char const *temp; u32 start, len; if(!(temp = get_number_parse(arg, &start))) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else if(!get_number_parse(temp, &len)) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -