예제 #1
0
int main(void)
{
	initRobotBase(); 	// Always call this first! The Processor will not work
						// correctly otherwise.		 
	mSleep(1000);        // delay 1s

	speed = 0; //Speed for servo from '0'(fast) - '10'(slow)

	writeString_P("\n Key Board Control \n\n");

	Start_position(); //Use this function to set the servomotor in the centre. 
					  //This function must be called before using Power_Servos();
	
	Power_Servos();  //Use this function to power the servo motors on
					 //When you want to power off the servos, you need to call function Power_Off_Servos();
	
	
	// ---------------------------------------
	// Main loop:
	while(true)
	{
		
		Event(scan_keyboard());
		
	// End of main loop!
	// ---------------------------------------
	}
	return 0;
}
예제 #2
0
파일: tsh.c 프로젝트: salamoun/reindeeros
/**
 * Start Tiny Shell process.
 */
void tiny_shell_init() {

	uint32_t 	buff_position = 0;
	uint8_t 	prompt_line = 0;

	parse_prompt();
	print_prompt();

	// start scan keyboard...
	while(1) {
		enum KEYCODE key = scan_keyboard();
		switch (key) {
			case KEY_RETURN:
				// terminate command_buffer string
				command_buffer[buff_position] = 0;
				vga_text_mode_putc('\n');
				if (!tsh_exec()) {
					kprintf("tshell: %s: command not found", command_buffer);
				}
				// reset buffer position
				buff_position = 0;
				print_prompt();
				prompt_line = 0;
				break;
			case KEY_BACKSPACE:
				// delete previous character on line
				if (vga_text_mode_cursor_getX() >= _prompt_info.prompt_len && prompt_line==0) {
					vga_text_mode_putc(kbrd_key_to_ascii(key));
					if (buff_position>0)
						buff_position--;
				}
				// roll-back cursor to previous line and delete character
				if (prompt_line>0) {
					if (prompt_line>0 && ((buff_position+_prompt_info.prompt_len-1) == (prompt_line)*COLS))
						prompt_line--;
					vga_text_mode_putc(kbrd_key_to_ascii(key));
					if (buff_position>0)
						buff_position--;
				}
				break;
			default :
				if (isascii(key)) {
					if (buff_position <= max_len_com_buffer-1) {
						command_buffer[buff_position++] = kbrd_key_to_ascii(key);
						if (prompt_line>0 && ((buff_position+_prompt_info.prompt_len-2) == (prompt_line+1)*COLS))
							prompt_line++;
						if (prompt_line==0 && (buff_position+_prompt_info.prompt_len-1 > COLS))
							prompt_line++;
						vga_text_mode_putc(kbrd_key_to_ascii(key));
					}
				}
		}
	}
}
예제 #3
0
파일: x_demo.c 프로젝트: joncampbell123/16
int get_key(void)
{

int	c = 0;

	while (c == 0)
	{
		c = scan_keyboard ();
	}

	return (c);

}
예제 #4
0
void handle_updown(void) {
  int key = scan_keyboard();
  if (updown_state == DOWN_CHECK_START) {
    if (key >= 0) {
      pressed_key = key;
      updown_state = DOWN_CHECK_END;
      updown_ocr = TICKS_TILL_SURE;
    } else {
      updown_state = IDLE;
      return ;
    }
  } else if (updown_state == DOWN_CHECK_END) {
    if (key >= 0 && key == pressed_key) {
      key_handler(pressed_key);
      if (repeat_key & 1 << pressed_key) {
        repeater_state = REPEAT_CHECK_START;
        repeater_counter = 0;
        repeater_ocr = TICKS_TILL_REPEAT;
      }
      updown_state = UP_CHECK_START;
      updown_ocr = TICKS_PER_UP_CHECK;
    } else {
      updown_state = IDLE;
    }
  } else if (updown_state == UP_CHECK_START) {
    if (key == -1) {
      updown_state = UP_CHECK_END;
      updown_ocr = TICKS_TILL_SURE;
    } else {
      updown_state = UP_CHECK_START;
      updown_ocr = TICKS_PER_UP_CHECK;
    }
  } else if(updown_state == UP_CHECK_END) {
    if (key == -1) {
      key_handler(KEYBOARD_KEYUP);
      pressed_key = -1;
      repeater_state = IDLE;
      updown_state = LONG_PAUSE_CHECK;
      updown_ocr = TICKS_TILL_LONG_PAUSE;
    } else {
      updown_state = UP_CHECK_START;
      updown_ocr = TICKS_PER_UP_CHECK;
    }
  } else if(updown_state == LONG_PAUSE_CHECK) {
    key_handler(KEYBOARD_KEYLONGPAUSE);
    updown_state = IDLE;
    set_sleep_mode(SLEEP_MODE_STANDBY);
  }
};
예제 #5
0
void handle_repeater(void) {
  int key = scan_keyboard();
  if (key == pressed_key) {
    // key pressed
    if (repeater_state == REPEAT_CHECK_START) {
      // wait till sure
      repeater_state = REPEAT_CHECK_END;
      repeater_ocr = TICKS_TILL_SURE;
    } else {
      key_handler(pressed_key);
      //PORTA ^= 1 << PA2;
      repeater_state = REPEAT_CHECK_START;
      repeater_ocr = TICKS_TILL_REPEAT;
    }
  } else {
    // bad key pressed, abort repeating
    repeater_state = IDLE;
  }
};
예제 #6
0
파일: aalinuxkbd.c 프로젝트: Ortuna/aalib
/* this is the routine you should call whenever you would normally
 * read a keypress. However, to actually tell if a key is pressed,
 * call is_key_pressed() with a scancode as arg.
 */
static int scan_keyboard(void)
{
    int c, key, flag;

/* we use BFI to fix the PrtSc/Pause problem - i.e. we don't :^) */
    while ((c = get_scancode()) == 0xE0);
    if (c == 0xE1)
	c = get_scancode();

    if (c == -1)
	return -1;		/* no key was pressed */

    key = c & 127;
    flag = (c & 128) ? 0 : 1;	/* 1 = down */

    if (flag || key_down[key] != flag)
      key_down[key] = flag;
    else
      return (scan_keyboard ());

    if (key == LEFT_ALT)
	alt_pressed = flag;

    if (alt_pressed && flag && key >= FUNC_KEY(1) && key <= FUNC_KEY(10)) {
	struct vt_stat vts;
	int newvt;

	ioctl(tty_fd, VT_GETSTATE, &vts);
	newvt = c - FUNC_KEY(1) + 1;
	if (vts.v_active != newvt && vtswitch_allowed) {
	    ioctl(tty_fd, VT_ACTIVATE, newvt);
	    restart_con = 0;
	    while (restart_con == 0)
		usleep(50000);
	}
	return -1;		/* Got VT switch */
    }
    if (flag && key == 46 && key_down[LEFT_CTRL])
	raise(SIGINT);
    return key;			/* No VT switch */
}
예제 #7
0
void irq_handler(void)
{
    UART_DATA = 'i';
    IRQ_TMR_CTRL = TMR_IRQ; // clear irq flag
    scan_keyboard();
}
예제 #8
0
파일: x_demo.c 프로젝트: joncampbell123/16
void page_demo ()
{

char	*Error1 = "Failure during SET_VGA_MODEX (0, 320, 200, 2) call";

int		Last_Objects[2], Visible_Objects;

int		Screen_X = 384;
int		Screen_Y = 224;

int		x, y, z;
int		c, dc;
int		x1, y1, x2, y2;

int		Sprite_X, Sprite_Y;
int		Current_Page;
int		New_X, New_Y;

int		View_X,	View_Y,	View_Max, View_Cnt, View_XD, View_YD;
int		Set_Color, Prev_Color, S_Dir, P_Dir;

int		Demo_Running = True;
int		redo, code;

int pee;
pee = set_vga_modex(Mode_320x200, Screen_X, Screen_Y, 3);
	if ( pee > 0)
	{
		set_video_mode (3);
		dos_print (Error1);
		fprintf(stdout, "return value is %d\n", pee);
		//error_out (Error1);
		exit (EXIT_SUCCESS);
	}

	set_active_page (0);
	clear_vga_screen (c_BLACK);

   	print_str ("This is a Test of the Following Functions:", 99, 10, 9, c_bWHITE, c_BLACK);

	draw_line (10, 18, 350, 18, c_YELLOW);
	print_str ("SET_ACTIVE_PAGE", 99, 10, 20, c_bBLUE, c_BLACK);
	print_str ("SET_DISPLAY_PAGE", 99, 10, 30, c_GREEN, c_BLACK);
	print_str ("SET_DAC_REGISTER", 99, 10, 40, c_RED, c_BLACK);
	print_str ("CLEAR_VGA_SCREEN", 99, 10, 50, c_CYAN, c_BLACK);

	print_str ("TDRAW_BITMAP", 99, 10, 60, c_PURPLE, c_BLACK);
	print_str ("COPY_PAGE", 99, 10, 70, c_GREEN, c_BLACK);
	print_str ("COPY_BITMAP", 99, 10, 80, c_CYAN, c_BLACK);

	print_str ("GPRINTC", 99, 10, 90, c_BLUE, c_BLACK);
	print_str ("TGPRINTC", 99, 10, 100, c_GREEN, c_BLACK);
	print_str ("SET_WINDOW", 99, 10, 110, c_RED, c_BLACK);

	print_str ("VIRTUAL SCREEN SIZES", 20, 190, 20, c_bBLUE, c_BLACK);
	print_str ("    SMOOTH SCROLLING", 20, 190, 30, c_GREEN, c_BLACK);
	print_str ("    SPRITE ANIMATION", 20, 190, 40, c_CYAN, c_BLACK);
	print_str ("       PAGE FLIPPING", 20, 190, 50, c_RED, c_BLACK);
	print_str ("       COLOR CYCLING", 20, 190, 60, c_PURPLE, c_BLACK);

	for (x = 0; x <=60; x++)
	{
		set_dac_register (50 + x, 3 + x, 0, 60 - x);
		set_dac_register (150 + x, 3 + x, 0, 60 - x);
	}

	c = 0;
	dc = 1;
	for (x = 0; x <= (Screen_X / 2); x++)
	{
		draw_line (Screen_X / 2 - 1, Screen_Y / 4, x, Screen_Y - 1, c + 50);
		draw_line (Screen_X / 2, Screen_Y / 4, Screen_X - x - 1, Screen_Y - 1, c + 50);
		c+= dc;
		if ((c == 0) || (c == 60) ) { dc = -dc;}
	}

	tprint_str ("Press <ANY KEY> to Continue", 99, 72, 190, c_bWHITE);
	tprint_str ("< > = Faster   < > = Slower", 99, 72, 204, c_bGREEN);
	tprint_str ("< > = Fewer Shapes  < > = More Shapes", 99, 32, 218, c_bCYAN);

	tgprintc (43, 80, 204, c_YELLOW);
	tgprintc (45, 200, 204, c_YELLOW);

	tgprintc (25, 40, 218, c_YELLOW);
	tgprintc (24, 200, 218, c_YELLOW);

	copy_page (0, 1);
	copy_page (0, 2);

	for (x = 0; x < MAX_SPRITES; x++)
	{
		do {
			Obj[x].X_Dir = random_int(7) - 3;
			Obj[x].Y_Dir = random_int(7) - 3;
		} while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );

		Obj[x].Shape = x % MAX_SHAPES;

		Sprite_X = Img[Obj[x].Shape].X_Width;
		Sprite_Y = Img[Obj[x].Shape].Y_Width;

		Obj[x].X_pos = 1 + random_int(Screen_X - Sprite_X - 2);
		Obj[x].Y_pos = 1 + random_int(Screen_Y - Sprite_Y - 2);

		Obj[x].Last_X[0] = Obj[x].X_pos;
		Obj[x].Last_X[1] = Obj[x].X_pos;
		Obj[x].Last_Y[0] = Obj[x].Y_pos;
		Obj[x].Last_Y[1] = Obj[x].Y_pos;

	}

	Current_Page = 0;

	View_X = 0;
	View_Y = 0;
	View_Max = 3;
	View_Cnt = 0;
	View_XD = 1;
	View_YD = 1;

	Set_Color = 3;
	S_Dir = 1;
	Prev_Color = 0;
	P_Dir = 1;

	Visible_Objects = MAX_SPRITES / 2;
	Last_Objects[0] = 0;
	Last_Objects[1] = 0;

	while (Demo_Running)
	{

		set_active_page (Current_Page);

			/* Erase Old Images */

		for (x = 0; x <= Last_Objects[Current_Page]; x++)
		{
			z = 2;
			y = Obj[x].Shape;
			x1 = Obj[x].Last_X[Current_Page];
			y1 = Obj[x].Last_Y[Current_Page];
			x2 = x1 + Img[y].X_Width -1;
			y2 = y1 + Img[y].Y_Width -1;

			x1 = x1 & 0xfffc;
			x2 = x2 | 0x0003;

			copy_bitmap (z, x1, y1, x2, y2, Current_Page, x1, y1);
		}

			/* Draw new images */

		for (x = 0; x <= Visible_Objects; x++)
		{
			Sprite_X = Img[Obj[x].Shape].X_Width;
			Sprite_Y = Img[Obj[x].Shape].Y_Width;

			/*  Move Sprite */

			do
			{
				redo = False;
				New_X = Obj[x].X_pos + Obj[x].X_Dir;

				if (( New_X < 0 ) || (New_X + Sprite_X > Screen_X) )
				{
					Obj[x].X_Dir = -Obj[x].X_Dir;
					if (random_int(20) == 1)
					{
						do
						{
							Obj[x].X_Dir = random_int(7) - 3;
							Obj[x].Y_Dir = random_int(7) - 3;
						} while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
						redo = True;
					}
				}
			} while (redo);
			Obj[x].X_pos = Obj[x].X_pos + Obj[x].X_Dir;


			do
			{
				redo = False;
				New_Y = Obj[x].Y_pos + Obj[x].Y_Dir;

				if ( (New_Y < 0) || (New_Y + Sprite_Y > Screen_Y) )
				{
					Obj[x].Y_Dir = -Obj[x].Y_Dir;
					if (random_int(20) == 1)
					{
						do
						{
							Obj[x].X_Dir = random_int(7) - 3;
							Obj[x].Y_Dir = random_int(7) - 3;
						} while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
						redo = True;
					}
				}
			} while (redo);

			Obj[x].Y_pos = Obj[x].Y_pos + Obj[x].Y_Dir;

			/* Draw Sprite */

			tdraw_bitmap ((char far*) &Img[Obj[x].Shape], Obj[x].X_pos, Obj[x].Y_pos, Sprite_X, Sprite_Y);

			Obj[x].Last_X[Current_Page] = Obj[x].X_pos;
			Obj[x].Last_Y[Current_Page] = Obj[x].Y_pos;

		}

		Last_Objects[Current_Page] = Visible_Objects;


		/* Pan Screen Back & Forth */

		View_Cnt++;
		if (View_Cnt >= View_Max)
		{
			View_X+= View_XD;
			if ( (View_X == 0) || (View_X == 39) ) {View_XD = -View_XD;}
			if (View_XD < 0)
			{
				View_Y+= View_YD;
				if ( (View_Y == 0) || (View_Y == 39) ) {View_YD = -View_YD;}
			}

			set_window (Current_Page, View_X, View_Y);

			View_Cnt = 0;
		}
		else
		{
			set_display_page (Current_Page);
		}

		/* Cycle Colors */

		set_dac_register (50 + Prev_Color, 3 + Prev_Color, 0, 60 - Prev_Color);
		set_dac_register (50 + Set_Color, Set_Color, 10, 63 - Set_Color);

		set_dac_register (150 + Prev_Color, 3 + Prev_Color, 0, 60 - Prev_Color);
		set_dac_register (150 + Set_Color, 63, 63, Set_Color);

		Set_Color+= S_Dir;
		if ( (Set_Color == 60) || (Set_Color == 0) ) {S_Dir = -S_Dir;}

		Prev_Color+= P_Dir;
		if ( (Prev_Color == 60) || (Prev_Color == 0) ) {P_Dir = -P_Dir;}

		/* Check for Keystroke */

		Current_Page = Current_Page ^ 0x01;

		code = scan_keyboard ();

		if (code == Ky_ESC) {Demo_Running = False;}

		if (code == Ky_Plus)
		{
			if (View_Max < 12) {View_Max++;}
		}

		if (code == Ky_Minus)
		{
			if (View_Max > 1) {View_Max--;}
			if (View_Cnt >= View_Max) {View_Cnt = 0;}
		}

		if (code == Ky_Up)
		{
			if (Visible_Objects < MAX_SPRITES-1) {Visible_Objects++;}
		}

		if (code == Ky_Down)
		{
			if (Visible_Objects > 0) {Visible_Objects--;}
		}

	}

}
예제 #9
0
void exec_image(char *image)
/* Get a Minix image into core, patch it up and execute. */
{
	int i;
	struct image_header hdr;
	char *buf;
	u32_t vsec, addr, limit, aout, n, totalmem = 0;
	struct process *procp;		/* Process under construction. */
	long a_text, a_data, a_bss, a_stack;
	int banner= 0;
	long processor= a2l(b_value("processor"));
	u16_t kmagic, mode;
	char *console;
	char params[SECTOR_SIZE];
	extern char *sbrk(int);
	char *verb;

	/* The stack is pretty deep here, so check if heap and stack collide. */
	(void) sbrk(0);

	if ((verb= b_value(VERBOSEBOOTVARNAME)) != nil)
		verboseboot = a2l(verb);

	printf("\nLoading ");
	pretty_image(image);
	printf(".\n");

	vsec= 0;			/* Load this sector from image next. */
	addr= mem[0].base;		/* Into this memory block. */
	limit= mem[0].base + mem[0].size;
	if (limit > caddr) limit= caddr;

	/* Allocate and clear the area where the headers will be placed. */
	aout = (limit -= PROCESS_MAX * A_MINHDR);

	/* Clear the area where the headers will be placed. */
	raw_clear(aout, PROCESS_MAX * A_MINHDR);

	/* Read the many different processes: */
	for (i= 0; vsec < image_size; i++) {
		u32_t startaddr;
		startaddr = addr;
		if (i == PROCESS_MAX) {
			printf("There are more then %d programs in %s\n",
				PROCESS_MAX, image);
			errno= 0;
			return;
		}
		procp= &process[i];

		/* Read header. */
		DEBUGEXTRA(("Reading header... "));
		for (;;) {
			if ((buf= get_sector(vsec++)) == nil) return;

			memcpy(&hdr, buf, sizeof(hdr));

			if (BADMAG(hdr.process)) { errno= ENOEXEC; return; }

			/* Check the optional label on the process. */
			if (selected(hdr.name)) break;

			/* Bad label, skip this process. */
			vsec+= proc_size(&hdr);
		}
		DEBUGEXTRA(("done\n"));

		/* Sanity check: an 8086 can't run a 386 kernel. */
		if (hdr.process.a_cpu == A_I80386 && processor < 386) {
			printf("You can't run a 386 kernel on this 80%ld\n",
				processor);
			errno= 0;
			return;
		}

		/* Get the click shift from the kernel text segment. */
		if (i == KERNEL_IDX) {
			if (!get_clickshift(vsec, &hdr)) return;
			addr= align(addr, click_size);

			/* big kernels must be loaded into extended memory */
			if (k_flags & K_KHIGH) {
				addr= mem[1].base;
				limit= mem[1].base + mem[1].size;
			}
		}

		/* Save a copy of the header for the kernel, with a_syms
		 * misused as the address where the process is loaded at.
		 */
		DEBUGEXTRA(("raw_copy(0x%x, 0x%lx, 0x%x)... ", 
			aout + i * A_MINHDR, mon2abs(&hdr.process), A_MINHDR));
		hdr.process.a_syms= addr;
		raw_copy(aout + i * A_MINHDR, mon2abs(&hdr.process), A_MINHDR);
		DEBUGEXTRA(("done\n"));

		if (!banner) {
			DEBUGBASIC(("     cs       ds     text     data      bss"));
			if (k_flags & K_CHMEM) DEBUGBASIC(("    stack"));
			DEBUGBASIC(("\n"));
			banner= 1;
		}

		/* Segment sizes. */
		DEBUGEXTRA(("a_text=0x%lx; a_data=0x%lx; a_bss=0x%lx; a_flags=0x%x)\n",
			hdr.process.a_text, hdr.process.a_data, 
			hdr.process.a_bss, hdr.process.a_flags));

		a_text= hdr.process.a_text;
		a_data= hdr.process.a_data;
		a_bss= hdr.process.a_bss;
		if (k_flags & K_CHMEM) {
			a_stack= hdr.process.a_total - a_data - a_bss;
			if (!(hdr.process.a_flags & A_SEP)) a_stack-= a_text;
		} else {
			a_stack= 0;
		}

		/* Collect info about the process to be. */
		procp->cs= addr;

		/* Process may be page aligned so that the text segment contains
		 * the header, or have an unmapped zero page against vaxisms.
		 */
		procp->entry= hdr.process.a_entry;
		if (hdr.process.a_flags & A_PAL) a_text+= hdr.process.a_hdrlen;
		if (hdr.process.a_flags & A_UZP) procp->cs-= click_size;

		/* Separate I&D: two segments.  Common I&D: only one. */
		if (hdr.process.a_flags & A_SEP) {
			/* Read the text segment. */
			DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
				vsec, a_text, addr, limit));
			if (!get_segment(&vsec, &a_text, &addr, limit)) return;
			DEBUGEXTRA(("get_segment done vsec=0x%lx a_text=0x%lx "
				"addr=0x%lx\n", 
				vsec, a_text, addr));

			/* The data segment follows. */
			procp->ds= addr;
			if (hdr.process.a_flags & A_UZP) procp->ds-= click_size;
			procp->data= addr;
		} else {
			/* Add text to data to form one segment. */
			procp->data= addr + a_text;
			procp->ds= procp->cs;
			a_data+= a_text;
		}

		/* Read the data segment. */
		DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", 
			vsec, a_data, addr, limit));
		if (!get_segment(&vsec, &a_data, &addr, limit)) return;
		DEBUGEXTRA(("get_segment done vsec=0x%lx a_data=0x%lx "
			"addr=0x%lx\n", 
			vsec, a_data, addr));

		/* Make space for bss and stack unless... */
		if (i != KERNEL_IDX && (k_flags & K_CLAIM)) a_bss= a_stack= 0;

		DEBUGBASIC(("%07lx  %07lx %8ld %8ld %8ld",
			procp->cs, procp->ds, hdr.process.a_text,
			hdr.process.a_data, hdr.process.a_bss));
		if (k_flags & K_CHMEM) DEBUGBASIC((" %8ld", a_stack));

		/* Note that a_data may be negative now, but we can look at it
		 * as -a_data bss bytes.
		 */

		/* Compute the number of bss clicks left. */
		a_bss+= a_data;
		n= align(a_bss, click_size);
		a_bss-= n;

		/* Zero out bss. */
		DEBUGEXTRA(("\nraw_clear(0x%lx, 0x%lx); limit=0x%lx... ", addr, n, limit));
		if (addr + n > limit) { errno= ENOMEM; return; }
		raw_clear(addr, n);
		DEBUGEXTRA(("done\n"));
		addr+= n;

		/* And the number of stack clicks. */
		a_stack+= a_bss;
		n= align(a_stack, click_size);
		a_stack-= n;

		/* Add space for the stack. */
		addr+= n;

		/* Process endpoint. */
		procp->end= addr;

		if (verboseboot >= VERBOSEBOOT_BASIC)
			printf("  %s\n", hdr.name);
		else {
			u32_t mem;
			mem = addr-startaddr;
			printf("%s ", hdr.name);
			totalmem += mem;
		}

		if (i == 0 && (k_flags & (K_HIGH | K_KHIGH)) == K_HIGH) {
			/* Load the rest in extended memory. */
			addr= mem[1].base;
			limit= mem[1].base + mem[1].size;
		}
	}

	if (verboseboot < VERBOSEBOOT_BASIC)
		printf("(%dk)\n", totalmem/1024);

	if ((n_procs= i) == 0) {
		printf("There are no programs in %s\n", image);
		errno= 0;
		return;
	}

	/* Check the kernel magic number. */
	raw_copy(mon2abs(&kmagic), 
		process[KERNEL_IDX].data + MAGIC_OFF, sizeof(kmagic));
	if (kmagic != KERNEL_D_MAGIC) {
		printf("Kernel magic number is incorrect (0x%x@0x%lx)\n", 
			kmagic, process[KERNEL_IDX].data + MAGIC_OFF);
		errno= 0;
		return;
	}

	/* Patch sizes, etc. into kernel data. */
	DEBUGEXTRA(("patch_sizes()... "));
	patch_sizes();
	DEBUGEXTRA(("done\n"));

#if !DOS
	if (!(k_flags & K_MEML)) {
		/* Copy the a.out headers to the old place. */
		raw_copy(HEADERPOS, aout, PROCESS_MAX * A_MINHDR);
	}
#endif

	/* Run the trailer function just before starting Minix. */
	DEBUGEXTRA(("run_trailer()... "));
	if (!run_trailer()) { errno= 0; return; }
	DEBUGEXTRA(("done\n"));

	/* Translate the boot parameters to what Minix likes best. */
	DEBUGEXTRA(("params2params(0x%x, 0x%x)... ", params, sizeof(params)));
	if (!params2params(params, sizeof(params))) { errno= 0; return; }
	DEBUGEXTRA(("done\n"));

	/* Set the video to the required mode. */
	if ((console= b_value("console")) == nil || (mode= a2x(console)) == 0) {
		mode= strcmp(b_value("chrome"), "color") == 0 ? COLOR_MODE :
								MONO_MODE;
	}
	DEBUGEXTRA(("set_mode(%d)... ", mode));
	set_mode(mode);
	DEBUGEXTRA(("done\n"));

	/* Close the disk. */
	DEBUGEXTRA(("dev_close()... "));
	(void) dev_close();
	DEBUGEXTRA(("done\n"));

	/* Minix. */
	DEBUGEXTRA(("minix(0x%lx, 0x%lx, 0x%lx, 0x%x, 0x%x, 0x%lx)\n", 
		process[KERNEL_IDX].entry, process[KERNEL_IDX].cs,
		process[KERNEL_IDX].ds, params, sizeof(params), aout));
	minix(process[KERNEL_IDX].entry, process[KERNEL_IDX].cs,
			process[KERNEL_IDX].ds, params, sizeof(params), aout);

	if (!(k_flags & K_BRET)) {
		extern u32_t reboot_code;
		raw_copy(mon2abs(params), reboot_code, sizeof(params));
	}
	parse_code(params);

	/* Return from Minix.  Things may have changed, so assume nothing. */
	fsok= -1;
	errno= 0;

	/* Read leftover character, if any. */
	scan_keyboard();

	/* Restore screen contents. */
	restore_screen();
}
예제 #10
0
void exec_mb(char *kernel, char* modules)
/* Get a Minix image into core, patch it up and execute. */
{
	int i;
	static char hdr[SECTOR_SIZE];
	char *buf;
	u32_t vsec, addr, limit, n, totalmem = 0;
	u16_t kmagic, mode;
	char *console;
	char params[SECTOR_SIZE];
	extern char *sbrk(int);
	char *verb;
	u32_t text_vaddr, text_paddr, text_filebytes, text_membytes;
	u32_t data_vaddr, data_paddr, data_filebytes, data_membytes;
	u32_t pc;
	u32_t text_offset, data_offset;
	i32_t segsize;
	int r;
	u32_t cs, ds;
	char *modstring, *mod;
	multiboot_info_t *mbinfo;
	multiboot_module_t *mbmodinfo;
	u32_t mbinfo_size, mbmodinfo_size;
	char *memvar;
	memory *mp;
	u32_t mod_cmdline_start, kernel_cmdline_start;
	u32_t modstringlen;
	int modnr;

	/* The stack is pretty deep here, so check if heap and stack collide. */
	(void) sbrk(0);

	if ((verb= b_value(VERBOSEBOOTVARNAME)) != nil)
		verboseboot = a2l(verb);

	printf("\nLoading %s\n", kernel);

	vsec= 0;			/* Load this sector from kernel next. */
	addr= mem[0].base;		/* Into this memory block. */
	limit= mem[0].base + mem[0].size;
	if (limit > caddr) limit= caddr;

	/* set click size for get_segment */
	click_size = PAGE_SIZE;

	k_flags = K_KHIGH|K_BRET|K_MEML|K_INT86|K_RET|K_HDR
	    |K_HIGH|K_CHMEM|K_I386;

	/* big kernels must be loaded into extended memory */
	addr= mem[1].base;
	limit= mem[1].base + mem[1].size;

	/* Get first sector */
	DEBUGEXTRA(("get_sector\n"));
	if ((buf= get_sector(vsec++)) == nil) {
	    DEBUGEXTRA(("get_sector failed\n"));
	    return;
	}
	memcpy(hdr, buf, SECTOR_SIZE);

	/* Get ELF header */
	DEBUGEXTRA(("read_header_elf\n"));
	r = read_header_elf(hdr, &text_vaddr, &text_paddr,
			    &text_filebytes, &text_membytes,
			    &data_vaddr, &data_paddr,
			    &data_filebytes, &data_membytes,
			    &pc, &text_offset, &data_offset);
	if (r < 0) { errno= ENOEXEC; return; }

	/* Read the text segment. */
	addr = text_paddr;
	segsize = (i32_t) text_filebytes;
	vsec = text_offset / SECTOR_SIZE;
	DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
		    vsec, segsize, addr, limit));
	if (!get_segment(&vsec, &segsize, &addr, limit)) return;
	DEBUGEXTRA(("get_segment done vsec=0x%lx size=0x%lx "
		    "addr=0x%lx\n",
		    vsec, segsize, addr));

	/* Read the data segment. */
	addr = data_paddr;
	segsize = (i32_t) data_filebytes;
	vsec = data_offset / SECTOR_SIZE;

	DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
		    vsec, segsize, addr, limit));
	if (!get_segment(&vsec, &segsize, &addr, limit)) return;
	DEBUGEXTRA(("get_segment done vsec=0x%lx size=0x%lx "
		    "addr=0x%lx\n",
		    vsec, segsize, addr));

	n = data_membytes - align(data_filebytes, click_size);

	/* Zero out bss. */
	DEBUGEXTRA(("\nraw_clear(0x%lx, 0x%lx); limit=0x%lx... ", addr, n, limit));
	if (addr + n > limit) { errno= ENOMEM; return; }
	raw_clear(addr, n);
	DEBUGEXTRA(("done\n"));
	addr+= n;

	/* Check the kernel magic number. */
	raw_copy(mon2abs(&kmagic),
		 data_paddr + MAGIC_OFF, sizeof(kmagic));
	if (kmagic != KERNEL_D_MAGIC) {
		printf("Kernel magic number is incorrect (0x%x@0x%lx)\n",
			kmagic, data_paddr + MAGIC_OFF);
		errno= 0;
		return;
	}

	/* Translate the boot parameters to what Minix likes best. */
	DEBUGEXTRA(("params2params(0x%x, 0x%x)... ", params, sizeof(params)));
	if (!params2params(params, sizeof(params))) { errno= 0; return; }
	DEBUGEXTRA(("done\n"));

	/* Create multiboot info struct */
	mbinfo = malloc(sizeof(multiboot_info_t));
	if (mbinfo == nil) { errno= ENOMEM; return; }
	memset(mbinfo, 0, sizeof(multiboot_info_t));

	/* Module info structs start where kernel ends */
	mbinfo->mods_addr = addr;

	modstring = strdup(modules);
	if (modstring == nil) {errno = ENOMEM; return; }
	modstringlen = strlen(modules);
	mbinfo->mods_count = split_module_list(modules);

	mbmodinfo_size = sizeof(multiboot_module_t) * mbinfo->mods_count;
	mbmodinfo = malloc(mbmodinfo_size);
	if (mbmodinfo == nil) { errno= ENOMEM; return; }
	addr+= mbmodinfo_size;
	addr= align(addr, click_size);

	mod_cmdline_start = mbinfo->mods_addr + sizeof(multiboot_module_t) *
	    mbinfo->mods_count;

	raw_copy(mod_cmdline_start, mon2abs(modules),
		 modstringlen+1);

	mbmodinfo[0].cmdline = mod_cmdline_start;
	modnr = 1;
	for (i= 0; i < modstringlen; ++i) {
	    if (modules[i] == '\0') {
		mbmodinfo[modnr].cmdline = mod_cmdline_start + i + 1;
		++modnr;
	    }
	}

	kernel_cmdline_start = mod_cmdline_start + modstringlen + 1;
	mbinfo->cmdline = kernel_cmdline_start;
	raw_copy(kernel_cmdline_start, mon2abs(kernel),
		 strlen(kernel)+1);

	mbinfo->flags = MULTIBOOT_INFO_MODS|MULTIBOOT_INFO_CMDLINE|
	    MULTIBOOT_INFO_BOOTDEV|MULTIBOOT_INFO_MEMORY;

	mbinfo->boot_device = mbdev;
	mbinfo->mem_lower = mem[0].size/1024;
	mbinfo->mem_upper = mem[1].size/1024;

	for (i = 0, mod = strtok(modstring, " "); mod != nil;
	     mod = strtok(nil, " "), i++) {

		mod = select_image(mod);
		if (mod == nil) {errno = 0; return; }

		mbmodinfo[i].mod_start = addr;
		mbmodinfo[i].mod_end = addr + image_bytes;
		mbmodinfo[i].pad = 0;

		segsize= image_bytes;
		vsec= 0;
		DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
		       vsec, segsize, addr, limit));
		if (!get_segment(&vsec, &segsize, &addr, limit)) return;
		DEBUGEXTRA(("get_segment done vsec=0x%lx size=0x%lx "
		       "addr=0x%lx\n",
		       vsec, segsize, addr));
		addr+= segsize;
		addr= align(addr, click_size);
	}
	free(modstring);

	DEBUGEXTRA(("modinfo raw_copy: dst 0x%lx src 0x%lx sz 0x%lx\n",
	    mbinfo->mods_addr, mon2abs(mbmodinfo),
	    mbmodinfo_size));
	raw_copy(mbinfo->mods_addr, mon2abs(mbmodinfo),
	    mbmodinfo_size);
	free(mbmodinfo);

	raw_copy(MULTIBOOT_INFO_ADDR, mon2abs(mbinfo),
		 sizeof(multiboot_info_t));
	free(mbinfo);

	/* Run the trailer function just before starting Minix. */
	DEBUGEXTRA(("run_trailer()... "));
	if (!run_trailer()) { errno= 0; return; }
	DEBUGEXTRA(("done\n"));

	/* Set the video to the required mode. */
	if ((console= b_value("console")) == nil || (mode= a2x(console)) == 0) {
		mode= strcmp(b_value("chrome"), "color") == 0 ? COLOR_MODE :
								MONO_MODE;
	}
	DEBUGEXTRA(("set_mode(%d)... ", mode));
	set_mode(mode);
	DEBUGEXTRA(("done\n"));

	/* Close the disk. */
	DEBUGEXTRA(("dev_close()... "));
	(void) dev_close();
	DEBUGEXTRA(("done\n"));

	/* Minix. */
	cs = ds = text_paddr;
	DEBUGEXTRA(("minix(0x%lx, 0x%lx, 0x%lx, 0x%x, 0x%x, 0x%lx)\n",
		pc, cs, ds, params, sizeof(params), 0));
	minix(pc, cs, ds, params, sizeof(params), 0);

	if (!(k_flags & K_BRET)) {
		extern u32_t reboot_code;
		raw_copy(mon2abs(params), reboot_code, sizeof(params));
	}
	parse_code(params);

	/* Return from Minix.  Things may have changed, so assume nothing. */
	fsok= -1;
	errno= 0;

	/* Read leftover character, if any. */
	scan_keyboard();

	/* Restore screen contents. */
	restore_screen();
}
예제 #11
0
파일: aalinuxkbd.c 프로젝트: Ortuna/aalib
static int linux_getchar(aa_context * c1, int wait)
{
#ifdef GPM_MOUSEDRIVER
    static Gpm_Event e;
#endif
    int c;
    int key;
    struct timeval tv;
    do {
	fd_set readfds;
	tv.tv_sec = 0;
	tv.tv_usec = 0;
	FD_ZERO(&readfds);
	FD_SET(tty_fd, &readfds);
#ifdef GPM_MOUSEDRIVER
	if (gpm_visiblepointer)
	    GPM_DRAWPOINTER(&e);
	if (__curses_usegpm) {
	    FD_SET(gpm_fd, &readfds);
	}
#endif
#ifdef GPM_MOUSEDRIVER
	select((__curses_usegpm ? gpm_fd : 0) + 1, &readfds, NULL, NULL, wait ? NULL : &tv);
	if (__curses_usegpm && FD_ISSET(gpm_fd, &readfds)) {
	    if (Gpm_GetEvent(&e) == 1) {
		__gpm_user_handler(&e, NULL);
		return AA_MOUSE;
	    }
	}
#else
	select(tty_fd, &readfds, NULL, NULL, wait ? NULL : &tv);
#endif
	c = scan_keyboard();
	if (c != -1) {
	    switch (c) {
	    case ESCAPE_KEY:
		key = AA_ESC;
		break;
	    case ENTER_KEY:
		key = 13;
		break;
	    case BACKSPACE:
		key = AA_BACKSPACE;
		break;
	    case CURSOR_LEFT:
		key = AA_LEFT;
		break;
	    case CURSOR_RIGHT:
		key = AA_RIGHT;
		break;
	    case CURSOR_UP:
		key = AA_UP;
		break;
	    case CURSOR_DOWN:
		key = AA_DOWN;
		break;
	    case CURSORBLOCK_LEFT:
		key = AA_LEFT;
		break;
	    case CURSORBLOCK_RIGHT:
		key = AA_RIGHT;
		break;
	    case CURSORBLOCK_UP:
		key = AA_UP;
		break;
	    case CURSORBLOCK_DOWN:
		key = AA_DOWN;
		break;
	    default:
		key = keymap_trans(c) & 255;
	    }
	    if (!key_down[c])
		key |= AA_RELEASE;
	    return key;
	} else
	    key = AA_NONE;
    }
    while (wait);
    return AA_NONE;
}