Esempio n. 1
0
void run_debugger(void) {
	int i;
    show_mainui();
    ui_refresh();

    ice.regs->flags &= ~TF_MASK;
    
    if(ice.regs->int_no != 1)
		output_print("Break due to INT 0x%lX", ice.regs->int_no);
	
	fn_show_stack = fn_kallsyms_lookup_name("show_stack");
	
	if(fn_show_stack){
		//fn_show_stack(current, ice.regs->sp);
	}else{
		printk(KERN_ALERT "not found show stack\n");
	}
	
    while(1) {
        if(exec_command(get_command())) {
            clear_command();
            break;
        }

        clear_command();
        //for (i = 0; i < 100000000; i++);
        //break;
    }

    unhook_idt(0xef);
    ice.running_state = NOT_RUNNING;
}
Esempio n. 2
0
int main(){ //主函数
	char command[100];
	char *args[1000];
	int size, i;
	char value[1050];
	char shellname[1050];

	//初始化,增加环境变量
	getcwd(first, 999); //获取当前目录
	strcpy(value, "shell=");
	strcpy(shellname, first);
	strcat(shellname, "/myshell");
	strcat(value, shellname);
	putenv(value);

	while(true){
		type_prompt();	//输出命令提示符
		//读取指令
		size = read_command(command, args, stdin);
		//分词并调用指令
		backstage(command, args, size);
		//释放内存
		clear_command(args, size);
	}
}
Esempio n. 3
0
int myshell(char *args[], int size){
	FILE *fp;
	char command[100];
	char *argv[1000];
	char s[1000];

	if(size == 0){//必须有一个参数
		printf("myshell:没有参数\n");
		return false;
	}

	fp = fopen(args[0], "r");
	if(fp == NULL){
		printf("打开文件失败\n");
		return false;
	}
	while(!feof(fp)){
		//逐行读取指令
		size = read_command(command, argv, fp);
		//判断是否已经读取到文件末尾
		if(size == -1) break;
		//调用指令
		backstage(command, argv, size);
		//释放内存
		clear_command(argv, size);
	}
	fclose(fp);
	return 1;

}
Esempio n. 4
0
/// cleans up game memory and SDL at exit
void cleanup()
{
    extern void clear_command();
    extern void clear_console();
    extern void clear_mdls();
    extern void clear_sound();

    recorder::stop();
    cleanupserver();
    
    /// "Use this function to set a window's input grab mode."
    /// https://wiki.libsdl.org/SDL_SetWindowGrab
    if(screen) SDL_SetWindowGrab(screen, SDL_FALSE);

    /// "Use this function to set relative mouse mode."
    /// https://wiki.libsdl.org/SDL_SetRelativeMouseMode
    SDL_SetRelativeMouseMode(SDL_FALSE);

    /// "Use this function to toggle whether or not the cursor is shown."
    /// https://wiki.libsdl.org/SDL_ShowCursor
    SDL_ShowCursor(SDL_TRUE);
    cleargamma();

    /// free octree memory
    freeocta(worldroot);
    clear_command();
    clear_console();
    clear_mdls();
    clear_sound();
    closelogfile();
    
    /// "Use this function to clean up all initialized subsystems. You should call it upon all exit conditions."
    /// https://wiki.libsdl.org/SDL_Quit
    SDL_Quit();
}
Esempio n. 5
0
void set_up_terminal() {
	char c = attr;
	text_color(RED, BLACK);
	puts("terminal:>");
	term_ind = index;
	clear_command();
	attr = c;
}
Esempio n. 6
0
void cleanup()
{
    recorder::stop();
    cleanupserver();
    SDL_ShowCursor(1);
    SDL_WM_GrabInput(SDL_GRAB_OFF);
    SDL_SetGamma(1, 1, 1);
    freeocta(worldroot);
    extern void clear_command(); clear_command();
    extern void clear_console(); clear_console();
    extern void clear_mdls();    clear_mdls();
    extern void clear_sound();   clear_sound();
    SDL_Quit();
}
Esempio n. 7
0
void cleanup()
{
    holdscreenlock;
    recorder::stop();
    cleanupserver();
    if(screen) SDL_SetWindowGrab(screen, SDL_FALSE);
    SDL_SetRelativeMouseMode(SDL_FALSE);
    SDL_ShowCursor(SDL_TRUE);
    cleargamma();
    freeocta(worldroot);
    extern void clear_command(); clear_command();
    extern void clear_console(); clear_console();
    extern void clear_mdls();    clear_mdls();
    extern void clear_sound();   clear_sound();
    closelogfile();
    SDL_Quit();
}
Esempio n. 8
0
void cleanup()
{
    recorder::stop();
    cleanupserver();
    showcursor(true);
//#ifdef FAKESHOWCURSOR
//    if(scursor) SDL_FreeCursor(scursor);
//    scursor = ncursor = NULL;
//#endif
    SDL_WM_GrabInput(SDL_GRAB_OFF);
    cleargamma();
    freeocta(worldroot);
    extern void clear_command();    clear_command();
    extern void clear_console();    clear_console();
    extern void clear_mdls();       clear_mdls();
    stopsound();
    closelogfile();
    SDL_Quit();
}
Esempio n. 9
0
static void 
console_task(layer_t* layer, unsigned int mem_total)
{
#define INPUT_BEG_POS_X   (24)
#define INPUT_BEG_POS_Y   (28)
#define PROMPT_CHAR       ("> ")
#define PROMPT_LEN        (2)
  timer_t* timer;
  task_t*  task = task_now();
  int data, fifobuf[128];
  int cursor_x = INPUT_BEG_POS_X, cursor_y = INPUT_BEG_POS_Y; 
  int cursor_c = -1;
  char buf[32], cmdline[32];
  mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR;
  
  fifo_init(&task->fifo, fifobuf, 128, task);
  timer = timer_alloc();
  timer_init(timer, &task->fifo, 1);
  timer_settimer(timer, 50);

  /* display the prompt of console window */
  drawstring_and_refresh(layer, 8, 28, 
      COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN);

  for ( ; ; ) {
    io_cli();

    if (0 == fifo_size(&task->fifo)) {
      task_sleep(task);
      io_sti();
    }
    else {
      data = fifo_get(&task->fifo);
      io_sti();

      if (data <= 1) {
        /* timer for cursor */
        if (0 != data) {
          timer_init(timer, &task->fifo, 0);
          if (cursor_c >= 0)
            cursor_c = COLOR8_FFFFFF;
        }
        else {
          timer_init(timer, &task->fifo, 1);
          if (cursor_c >= 0)
            cursor_c = COLOR8_000000;
        }

        timer_settimer(timer, 50);
      }
      if (2 == data)  /* cursor ON */
        cursor_c = COLOR8_FFFFFF;
      if (3 == data) {  /* cursor OFF */
        fill_box8(layer->buf, layer->w_size,
            COLOR8_000000, cursor_x, 28, cursor_x + 7, cursor_y + 15);
        cursor_c = -1;
      }
      if (256 <= data && data <= 511) {
        /* keyboard data */
        if ((8 + 256) == data) {
          /* backspace */
          if (cursor_x > INPUT_BEG_POS_X) {
            /* erase the cursor and move forward one character */
            drawstring_and_refresh(layer, cursor_x, cursor_y, 
                COLOR8_FFFFFF, COLOR8_000000, " ", 1);
            cursor_x -= 8;
          }
        }
        else if ((10 + 256) == data) {
          /* Enter Key */
          /* erase cursor by space */
          drawstring_and_refresh(layer, cursor_x, cursor_y, 
              COLOR8_FFFFFF, COLOR8_000000, " ", 1);
          
          cmdline[cursor_x / 8 - 3] = 0;
          cursor_y = console_newline(cursor_y, layer);

          /* execute command */
          if (0 == strcmp("mem", cmdline)) {
            /* check memory command */
            cursor_y = memory_command(layer, memmgr, mem_total, cursor_y);
          }
          else if (0 == strcmp("clear", cmdline)) {
            /* clear command */
            cursor_y = clear_command(layer);
          }
          else if (0 == strcmp("ls", cmdline)) {
            /* ls(dir) command */
            cursor_y = list_command(layer, cursor_y);
          }
          else if (0 == strncmp("cat ", cmdline, 4)) {
            /* cat command */
            cursor_y = cat_command(layer, cursor_x, cursor_y, cmdline);
          }
          else if (0 != cmdline[0]) {
            /* neither command nor null string */
            drawstring_and_refresh(layer, 8, cursor_y, 
                COLOR8_FFFFFF, COLOR8_000000, "Bad Command.", 12);
            cursor_y = console_newline(cursor_y, layer);
            cursor_y = console_newline(cursor_y, layer);
          }

          /* show prompt */
          drawstring_and_refresh(layer, 8, cursor_y, 
              COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN);
          cursor_x = INPUT_BEG_POS_X;
        }
        else {
          /* general character */
          if (cursor_x < 240) {
            /* display one character and move backward one character */
            buf[0] = data - 256;
            buf[1] = 0;
            cmdline[cursor_x / 8 - 3] = data - 256;
            drawstring_and_refresh(layer, cursor_x, cursor_y, 
                COLOR8_FFFFFF, COLOR8_000000, buf, 1);
            cursor_x += 8;
          }
        }
      }
      /* show the cursor again */
      if (cursor_c >= 0) {
        fill_box8(layer->buf, layer->w_size, 
            cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15);
      }
      layers_refresh(layer, cursor_x, cursor_y, 
          cursor_x + 8, cursor_y + 16);
    }
  }
}
Esempio n. 10
0
void run_command() {
	is_cmd = 1;
	int size = str_len(command);
	if(str_startswith(command, "hlt") == 1) {
		text_color(BLACK, BLACK);
		clear_screen();
		halt();
	} else if(str_startswith(command, "println")) {
		putslns(command, 8, size);
	} else if(str_startswith(command, "printvln")) {
		if(letti(command[9]) != -1)
			putnumln(reg[letti(command[9])]);
	} else if(str_startswith(command, "printv")) {
		if(letti(command[7]) != -1)
			putnum(reg[letti(command[7])]);
	} else if(str_startswith(command, "print")) {
		putss(command, 6, size);
	} else if (str_startswith(command, "clear")) {
		clear_screen();
		index = 0;
    } else if(str_startswith(command, "setv")) {
		if(letti(command[5]) != -1) {
			int r = letti(command[5]);
			
			int i = 0;
			while(i < 7) {
				command[i] = ' ';
				i++;
			}
			
			reg[r] = atoi(command);
		}
	} else if(str_startswith(command, "add")) {
		if(letti(command[4])!=-1 && letti(command[6])!=-1)
			reg[letti(command[4])] += reg[letti(command[6])];
	} else if(str_startswith(command, "sub")) {
		if(letti(command[4])!=-1 && letti(command[6])!=-1)
			reg[letti(command[4])] -= reg[letti(command[6])];
	} else if(str_startswith(command, "mul")) {
		if(letti(command[4])!=-1 && letti(command[6])!=-1)
			reg[letti(command[4])] *= reg[letti(command[6])];
	} else if(str_startswith(command, "div")) {
		if(letti(command[4])!=-1 && letti(command[6])!=-1)
			reg[letti(command[4])] /= reg[letti(command[6])];
	} else if(str_startswith(command, "mod")) {
		if(letti(command[4])!=-1 && letti(command[6])!=-1)
			reg[letti(command[4])] %= reg[letti(command[6])];
	} else if(str_startswith(command, "cc") == 1) {
		if(str_startswith(command, "cc help")) {
			putsln("Colors:");
			putsln(">>> BLACK       :: 0");
			putsln(">>> BLUE        :: 1");
			putsln(">>> GREEN       :: 2");
			putsln(">>> CYAN        :: 3");
			putsln(">>> RED         :: 4");
			putsln(">>> MAGENTA     :: 5");
			putsln(">>> BROWN       :: 6");
			putsln(">>> LT GRAY     :: 7");
			putsln(">>> DK GRAY     :: 8");
			putsln(">>> LT BLUE     :: 9");
			putsln(">>> LT GREEN    :: A");
			putsln(">>> LT CYAN     :: B");
			putsln(">>> LT RED      :: C");
			putsln(">>> LT MAGENTA  :: D");
			putsln(">>> LT BROWN    :: E");
			putsln(">>> WHITE       :: F");
		} else {
			char b = command[4];
			char f = command[3];
			if(f > '@' && b > '@')
				text_color(f - '0', b - 55);
			else if(f > '@')
				text_color(f - 55, b - '0');
			else if(b > '@')
				text_color(f - '0', b - 55);
			else
				text_color(f - '0', b - '0');
		}
	} else if(str_startswith(command, "help") == 1) {
		putsln("Commands:");
		putsln(">>> hlt          :: halts cpu");
		putsln(">>> cc fb|help   :: change text color - (fore, back)");
		putsln(">>> print text   :: print out a piece of text");
		putsln(">>> printv let   :: print out the value of variable let");
		putsln(">>> printvln let :: print out the value of variable let with a line after");
		putsln(">>> println text :: print out a piece of text with a line");
		putsln(">>> clear        :: Clears the screen");
		putsln(">>> setv let val :: set variable let to val");
		putsln(">>> add base set :: adds base to set and stores in base");
		putsln(">>> sub base set :: subtracts base from set and stores in base");
		putsln(">>> mul base set :: multiplies base by set and stores in base");
		putsln(">>> div base set :: divides base by set and stores in set");
		putsln(">>> mod base set :: divides base by set and stores remainder in set");
		putsln(">>> println text :: print out a piece of text with a line");
		putsln(">>> help         :: show help command");
	} else {
		puts(">>> Unknown command: ");
		putsln(command);
		putsln(">>> Try help.");
	}
	clear_command();
	
	is_cmd = 0;
}
Esempio n. 11
0
/*
 * void execute_commands()
 *
 * Processes commands until the QUIT command is entered
 *
 */
void execute_commands() {
  char buffer[MAX_INPUT_STRING];
  int num_chars = 0;

  while ( TRUE ) {
	
	printf( PROMPT );

	scanf("%s", buffer);
	num_chars = strlen(buffer);
	if ( is_valid_number( buffer ) ) {
	  push( atoi(buffer) );
	  continue;
	}

	if ( num_chars > 1 ) {
	  printf( BAD_INPUT_MSG );
	  continue;
	}

	if ( tolower( buffer[0] ) == QUIT ) return;

	/* Remove the TODO_MSG as you implement and test commands */
	switch( tolower( buffer[0] ) ){
	case ADD:
	  add_command();
	  break;
	case SUB:
	  sub_command();
	  break;
	case MULT:
	  mult_command();
	  break;
	case DIV:
	  div_command();
	  break;
	case MOD:
	  mod_command();
	  break;
	case AND:
	  and_command();
	  break;
	case OR:
	  or_command();
	  break;
	case XOR:
	  xor_command();
	  break;
	case NOT:
	  not_command();
	  break;
	case FACTORIAL:
	  factorial_command();
	  break;
	case TOGGLE_HEX:
	  toggle_hex();
	  break;
	case TOGGLE_BUG:
	  toggle_bug();
	  break;
	case PRINT_STACK:
	  print_stack();
	  break;
	case PRINT_TOP:
	  print_top();
	  break;
	case CLEAR:
	  clear_command();
	  break;
	case EXCHANGE:
	  exchange_command();
	  break;
	case POP:
	  pop();
	  break;
	case HELP:
	  help_command();
	  break;
	default:
	  printf( BAD_INPUT_MSG );
	}
  }
}