static int pci_cfg_modify (pci_dev_t bdf, ulong addr, ulong size, ulong value, int incrflag) { ulong i; int nbytes; uint val4; ushort val2; u_char val1; /* Print the address, followed by value. Then accept input for * the next value. A non-converted value exits. */ do { printf("%08lx:", addr); if (size == 4) { pci_read_config_dword(bdf, addr, &val4); printf(" %08x", val4); } else if (size == 2) { pci_read_config_word(bdf, addr, &val2); printf(" %04x", val2); } else { pci_read_config_byte(bdf, addr, &val1); printf(" %02x", val1); } nbytes = cli_readline(" ? "); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { /* <CR> pressed as only input, don't modify current * location and move to next. "-" pressed will go back. */ if (incrflag) addr += nbytes ? -size : size; nbytes = 1; /* good enough to not time out */ bootretry_reset_cmd_timeout(); } #ifdef CONFIG_BOOT_RETRY_TIME else if (nbytes == -2) { break; /* timed out, exit the command */ } #endif else { char *endp; i = simple_strtoul(console_buffer, &endp, 16); nbytes = endp - console_buffer; if (nbytes) { /* good enough to not time out */ bootretry_reset_cmd_timeout(); pci_cfg_write (bdf, addr, size, i); if (incrflag) addr += size; } } } while (nbytes); return 0; }
static void run_repl(sl_vm_t* vm) { printf("Interactive Slash\n"); cli_setup_readline(); while(true) { char* line = cli_readline(">> "); if(!line) { printf("\n"); shutdown_vm(vm, 0); } sl_vm_frame_t frame; SLVAL exception; SL_TRY(frame, SL_UNWIND_EXCEPTION, { SLVAL result = sl_do_string(vm, (uint8_t*)line, strlen(line), "(repl)", 1); result = sl_inspect(vm, result); printf("=> "); sl_string_t* str = (sl_string_t*)sl_get_ptr(result); fwrite(str->buff, str->buff_len, 1, stdout); printf("\n"); }, exception, { SLVAL exception_str = sl_to_s_no_throw(vm, exception); sl_string_t* str = (sl_string_t*)sl_get_ptr(exception_str); fwrite(str->buff, str->buff_len, 1, stdout); printf("\n"); });
static int pci_cfg_modify(pci_dev_t bdf, ulong addr, ulong size, ulong value, int incrflag) #endif { ulong i; int nbytes; ulong val; /* Print the address, followed by value. Then accept input for * the next value. A non-converted value exits. */ do { printf("%08lx:", addr); #ifdef CONFIG_DM_PCI dm_pci_read_config(dev, addr, &val, size); #else val = pci_read_config(bdf, addr, size); #endif printf(" %0*lx", pci_field_width(size), val); nbytes = cli_readline(" ? "); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { /* <CR> pressed as only input, don't modify current * location and move to next. "-" pressed will go back. */ if (incrflag) addr += nbytes ? -size : size; nbytes = 1; /* good enough to not time out */ bootretry_reset_cmd_timeout(); } #ifdef CONFIG_BOOT_RETRY_TIME else if (nbytes == -2) { break; /* timed out, exit the command */ } #endif else { char *endp; i = simple_strtoul(console_buffer, &endp, 16); nbytes = endp - console_buffer; if (nbytes) { /* good enough to not time out */ bootretry_reset_cmd_timeout(); #ifdef CONFIG_DM_PCI dm_pci_write_config(dev, addr, i, size); #else pci_cfg_write(bdf, addr, size, i); #endif if (incrflag) addr += size; } } } while (nbytes); return 0; }
void cli_simple_loop(void) { static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, }; int len; int flag; int rc = 1; for (;;) { if (rc >= 0) { /* Saw enough of a valid command to * restart the timeout. */ bootretry_reset_cmd_timeout(); } len = cli_readline(CONFIG_SYS_PROMPT); flag = 0; /* assume no special flags for now */ if (len > 0) strcpy(lastcommand, console_buffer); else if (len == 0) flag |= CMD_FLAG_REPEAT; #ifdef CONFIG_BOOT_RETRY_TIME else if (len == -2) { /* -2 means timed out, retry autoboot */ puts("\nTimed out waiting for command\n"); # ifdef CONFIG_RESET_TO_RETRY /* Reinit board to run initialization code again */ do_reset(NULL, 0, 0, NULL); # else return; /* retry autoboot */ # endif } #endif if (len == -1) puts("<INTERRUPT>\n"); else rc = run_command_repeatable(lastcommand, flag); if (rc <= 0) { /* invalid command or not repeatable, forget it */ lastcommand[0] = 0; } } }
int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char message[CONFIG_SYS_CBSIZE]; int i, len, pos, size; char *local_args[4]; char *endptr; local_args[0] = argv[0]; local_args[1] = argv[1]; local_args[2] = NULL; local_args[3] = NULL; /* * Check the syntax: * * env_ask envname [message1 ...] [size] */ if (argc == 1) return CMD_RET_USAGE; /* * We test the last argument if it can be converted * into a decimal number. If yes, we assume it's * the size. Otherwise we echo it as part of the * message. */ i = simple_strtoul(argv[argc - 1], &endptr, 10); if (*endptr != '\0') { /* no size */ size = CONFIG_SYS_CBSIZE - 1; } else { /* size given */ size = i; --argc; } if (argc <= 2) { sprintf(message, "Please enter '%s': ", argv[1]); } else { /* env_ask envname message1 ... messagen [size] */ for (i = 2, pos = 0; i < argc; i++) { if (pos) message[pos++] = ' '; strcpy(message + pos, argv[i]); pos += strlen(argv[i]); } message[pos++] = ' '; message[pos] = '\0'; } if (size >= CONFIG_SYS_CBSIZE) size = CONFIG_SYS_CBSIZE - 1; if (size <= 0) return 1; /* prompt for input */ len = cli_readline(message); if (size < len) console_buffer[size] = '\0'; len = 2; if (console_buffer[0] != '\0') { local_args[2] = console_buffer; len = 3; } /* Continue calling setenv code */ return _do_env_set(flag, len, local_args, H_INTERACTIVE); }
/* Modify memory. * * Syntax: * mm{.b, .w, .l, .q} {addr} * nm{.b, .w, .l, .q} {addr} */ static int mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) { ulong addr; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA u64 i; #else ulong i; #endif int nbytes, size; void *ptr = NULL; if (argc != 2) return CMD_RET_USAGE; bootretry_reset_cmd_timeout(); /* got a good command to get here */ /* We use the last specified parameters, unless new ones are * entered. */ addr = mm_last_addr; size = mm_last_size; if ((flag & CMD_FLAG_REPEAT) == 0) { /* New command specified. Check for a size specification. * Defaults to long if no or incorrect specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) return 1; /* Address is specified since argc > 1 */ addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; } #ifdef CONFIG_HAS_DATAFLASH if (addr_dataflash(addr)){ puts ("Can't modify DataFlash in place. Use cp instead.\n\r"); return 0; } #endif #ifdef CONFIG_BLACKFIN if (addr_bfin_on_chip_mem(addr)) { puts ("Can't modify L1 instruction in place. Use cp instead.\n\r"); return 0; } #endif /* Print the address, followed by value. Then accept input for * the next value. A non-converted value exits. */ do { ptr = map_sysmem(addr, size); printf("%08lx:", addr); if (size == 4) printf(" %08x", *((u32 *)ptr)); #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA else if (size == 8) printf(" %016" PRIx64, *((u64 *)ptr)); #endif else if (size == 2) printf(" %04x", *((u16 *)ptr)); else printf(" %02x", *((u8 *)ptr)); nbytes = cli_readline(" ? "); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { /* <CR> pressed as only input, don't modify current * location and move to next. "-" pressed will go back. */ if (incrflag) addr += nbytes ? -size : size; nbytes = 1; /* good enough to not time out */ bootretry_reset_cmd_timeout(); } #ifdef CONFIG_BOOT_RETRY_TIME else if (nbytes == -2) { break; /* timed out, exit the command */ } #endif else { char *endp; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA i = simple_strtoull(console_buffer, &endp, 16); #else i = simple_strtoul(console_buffer, &endp, 16); #endif nbytes = endp - console_buffer; if (nbytes) { /* good enough to not time out */ bootretry_reset_cmd_timeout(); if (size == 4) *((u32 *)ptr) = i; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA else if (size == 8) *((u64 *)ptr) = i; #endif else if (size == 2) *((u16 *)ptr) = i; else *((u8 *)ptr) = i; if (incrflag) addr += size; } } } while (nbytes); if (ptr) unmap_sysmem(ptr); mm_last_addr = addr; mm_last_size = size; return 0; }