Exemplo n.º 1
0
/*******************************************************************************
 *
 * i8042_getc - wait till keyboard input is available
 *		option: turn on/off cursor while waiting
 */
int i8042_getc(void)
{
	int ret_chr;
	unsigned char scan_code;

	while (kbd_input == -1) {
		while ((in8(I8042_STATUS_REG) & 0x01) == 0) {
#ifdef CONFIG_CONSOLE_CURSOR
			if (--blinkCount == 0) {
				cursor_state ^= 1;
				console_cursor(cursor_state);
				blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
			}
			udelay(10);
#endif
		}
		scan_code = in8(I8042_DATA_REG);
		if (scan_code != 0xfa)
			kbd_conv_char (scan_code);
	}
	ret_chr = kbd_input;
	kbd_input = -1;
	return ret_chr;
}
Exemplo n.º 2
0
/*******************************************************************************
 *
 * i8042_kbd_init - reset keyboard and init state flags
 */
int i8042_kbd_init(void)
{
	int keymap, try;
	char *penv;

	if (!kbd_controller_present())
		return -1;

#ifdef CONFIG_USE_CPCIDVI
	penv = getenv("console");
	if (penv != NULL) {
		if (strncmp(penv, "serial", 7) == 0)
			return -1;
	}
#endif
	/* Init keyboard device (default US layout) */
	keymap = KBD_US;
	penv = getenv("keymap");
	if (penv != NULL) {
		if (strncmp(penv, "de", 3) == 0)
			keymap = KBD_GER;
	}

	for (try = 0; try < KBD_RESET_TRIES; try++) {
		if (kbd_reset() == 0) {
			kbd_mapping = keymap;
			kbd_flags   = NORMAL;
			kbd_state   = 0;
			kbd_led_set();
			return 0;
		}
	}
	return -1;
}


/*******************************************************************************
 *
 * i8042_tstc - test if keyboard input is available
 *		option: cursor blinking if called in a loop
 */
int i8042_tstc(void)
{
	unsigned char scan_code = 0;

#ifdef CONFIG_CONSOLE_CURSOR
	if (--blinkCount == 0) {
		cursor_state ^= 1;
		console_cursor(cursor_state);
		blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
		udelay(10);
	}
#endif

	if ((in8(I8042_STATUS_REG) & 0x01) == 0) {
		return 0;
	} else {
		scan_code = in8(I8042_DATA_REG);
		if (scan_code == 0xfa)
			return 0;

		kbd_conv_char(scan_code);

		if (kbd_input != -1)
			return 1;
	}
	return 0;
}
Exemplo n.º 3
0
static void run_tool(uint8_t devices) {
    uint8_t highlighted;

    for (uint8_t i = 0; i < 4; i++) {
        if (ide_device_is_present(i) && ide_device_get_type(i) == 0) {
            highlighted = i;
            break;
        }
    }

    bool selected[4] = {0,0,0,0};
    bool selecting = true;
    uint8_t selectedNum = 0;

    while (selecting) {
        console_clear();
        print_header();

        console_puts("Please select the drives which you would like to erase.\n");

        for (uint8_t i = 0; i < 4; i++) {
            if (ide_device_is_present(i) && ide_device_get_type(i) == 0) {
                uint8_t foreground = 0x7, background = 0x0;
                if (selected[i]) foreground = 0xC;
                if (highlighted == i) {
                    background = 0xF;
                    if (foreground == 0x7) foreground = 0x0;
                }

                console_color((background << 4) + foreground);
                console_putsf("    - ATA Device %u (%s) %7uMB - %s\n", i, ide_device_is_dma_capable(i) ? "DMA" : "PIO", ide_device_get_size(i) / 1024 / 2, ide_device_get_string(i, IDE_STRING_MODEL));
                console_color(0x07);
            }
        }

        for (int i = 0; i < 10 - devices; i++) console_puts("\n");

        console_puts("Use the \"ARROW KEYS\" to highlight a drive.\n");
        console_puts("Press \"SPACE\"  to select/deselect the currently highlighted drive.\n\n");

        console_puts("NOTE: You must select at least one drive to continue.\n\n");

        console_puts("Press \"ENTER\"  to continue.\n");
        console_puts("Press \"ESCAPE\" to go back.");

        switch (get_key()) {
            case '\n':
                if (selectedNum > 0) {
                    selecting = false;
                }
                break;
            case '\1':
                return;
            case '\3':
                do {
                    highlighted--;
                    if (highlighted > 3) highlighted = 3;
                } while (!(ide_device_is_present(highlighted) && ide_device_get_type(highlighted) == 0));
                break;
            case '\5':
                do {
                    highlighted++;
                    if (highlighted == 4) highlighted = 0;
                } while (!(ide_device_is_present(highlighted) && ide_device_get_type(highlighted) == 0));
                break;
            case ' ':
                selected[highlighted] = !selected[highlighted];
                selectedNum += selected[highlighted] ? 1 : -1;
                break;
        }
    }

    console_clear();
    print_header();

    console_puts("Please select the drives which you would like to erase.\n");

    for (uint8_t i = 0; i < 4; i++) {
        if (ide_device_is_present(i) && ide_device_get_type(i) == 0) {
            uint8_t foreground = 0x7, background = 0x0;
            if (selected[i]) foreground = 0xC;

            console_color((background << 4) + foreground);
            console_putsf("    - ATA Device %u (%s) %7uMB - %s\n", i, ide_device_is_dma_capable(i) ? "DMA" : "PIO", ide_device_get_size(i) / 1024 / 2, ide_device_get_string(i, IDE_STRING_MODEL));
            console_color(0x07);
        }
    }

    console_puts("\n\nPlease enter the number of passes to be performed (max 99, 0 to cancel): ");

    uint8_t idx = 0;
    char raw_passes[3];

    char c;
    do {
        c = get_key();

        if (c == '\x7f' && idx > 0) {
            idx--;
            console_cursor(console_row(), console_col() - 1);
            console_puts(" ");
            console_cursor(console_row(), console_col() - 1);
        } else if (c >= '0' && c <= '9' && idx < 2) {
            console_putsf("%c", c);
            raw_passes[idx] = c;
            idx++;
        }
    } while (!(c == '\n' && idx != 0));

    raw_passes[idx] = '\0';
    uint32_t passes = atoi(raw_passes);

    if (passes == 0) return;

    console_puts("\n\nPress \"ENTER\"  to ");
    console_color(0x0C);
    console_puts("WIPE THE ATA DISKS SELECTED ABOVE");
    console_color(0x07);
    console_putsf(" in %u pass", passes);

    if (passes != 1) console_puts("es");

    console_puts(".\nPress \"ESCAPE\" to cancel and go back.\n\n");

    bool wait = true;
    while (wait) {
        switch (get_key()) {
            case '\1':
                return;
                break;
            case '\n':
                wait = false;
        }
    }

    console_clear();

    console_puts("Starting Data Erasure Tool...\n\n");

    uint8_t *space = (uint8_t *) page_to_virt(alloc_page(0));
    for (uint32_t i = 1; i < 64; i++) {
        alloc_page(0);
        console_putsf("Initializing... %3u%%\r", ((i + 1) * 100) / 64);
    }
    console_puts("Initializing... 100%%\n");

    uint8_t bit = 0x00;
    for (uint32_t pass = 0; pass < passes; pass++) {
        console_clear();

        console_puts("Starting Data Erasure Tool...\n\n");

        console_putsf("Initializing... 100%%\n", space);

        console_putsf("\nWriting Pass %02u of %02u...\n", pass + 1, passes);
        for (uint32_t i = 0; i < (64 * 4 * 1024); i++) {
            space[i] = bit;
        }

        int device = 0;
        for (uint32_t i = 0; i < 4; i++) {
            if (selected[i]) {
                device++;
                uint32_t count = 0;
                uint32_t written = 0;
                while(written < ide_device_get_size(i)) {
                    count++;
                    console_putsf("    - Writing to device %u... %3u%%                                             %c\r", device, (written * 100) / ide_device_get_size(i), twirls[(count / 10) % 4]);
                    written += ide_write_sectors_same(i, ide_device_get_size(i) - written, written, space) / 512;
                }
                console_putsf("    - Writing to device %u... 100%%                                              \n", device);
            }
        }

        bit = ~bit;
    }

    console_color(0x0A);
    console_puts("\nOperation completed successfully! ");
    console_color(0x07);
    console_puts("You may now turn the computer off.");

    beep();
    die();
}