int bench_main(int argc, char *argv[]) { double tmin = 0.0; double tol; int repeat = 0; int rounds = 10; int iarounds = 0; int arounds = 1; /* this is too low for precise results */ int c; report = report_verbose; /* default */ verbose = 0; tol = SINGLE_PRECISION ? 1.0e-3 : (QUAD_PRECISION ? 1e-29 : 1.0e-10); main_init(&argc, &argv); bench_srand(1); while ((c = my_getopt (argc, argv, options)) != -1) { switch (c) { case 't' : tmin = strtod(my_optarg, 0); break; case 'r': repeat = atoi(my_optarg); break; case 's': timer_init(tmin, repeat); speed(my_optarg, 0); break; case 'S': timer_init(tmin, repeat); speed(my_optarg, 1); break; case 'd': report_can_do(my_optarg); break; case 'o': useropt(my_optarg); break; case 'v': if (verbose >= 0) { /* verbose < 0 disables output */ if (my_optarg) verbose = atoi(my_optarg); else ++verbose; } break; case 'y': verify(my_optarg, rounds, tol); break; case 'a': accuracy(my_optarg, arounds, iarounds); break; case 'i': report_info(my_optarg); break; case 'I': report_info_all(); break; case 'h': if (verbose >= 0) my_usage(argv[0], options); break; case 300: /* --report-mflops */ report = report_mflops; break; case 310: /* --report-time */ report = report_time; break; case 320: /* --report-benchmark */ report = report_benchmark; break; case 330: /* --report-verbose */ report = report_verbose; break; case 400: /* --print-time-min */ timer_init(tmin, repeat); ovtpvt("%g\n", time_min); break; case 401: /* --verify-rounds */ rounds = atoi(my_optarg); break; case 402: /* --print-precision */ if (SINGLE_PRECISION) ovtpvt("single\n"); else if (QUAD_PRECISION) ovtpvt("quad\n"); else if (LDOUBLE_PRECISION) ovtpvt("long-double\n"); else if (DOUBLE_PRECISION) ovtpvt("double\n"); else ovtpvt("unknown %d\n", sizeof(bench_real)); break; case 403: /* --verify-tolerance */ tol = strtod(my_optarg, 0); break; case 404: /* --random-seed */ bench_srand(atoi(my_optarg)); break; case 405: /* --accuracy-rounds */ arounds = atoi(my_optarg); break; case 406: /* --impulse-accuracy-rounds */ iarounds = atoi(my_optarg); break; case '?': /* my_getopt() already printed an error message. */ cleanup(); return 1; default: abort (); } } /* assume that any remaining arguments are problems to be benchmarked */ while (my_optind < argc) { timer_init(tmin, repeat); speed(argv[my_optind++], 0); } cleanup(); return 0; }
void main(void) { u32 rootfs; char *rfs_txt; u32 image = 0; struct jffs2_raw_inode *node, *mfg_node; char *cmdline = 0, *altcmdline = 0; u32 kernel_nand_addr = 0, alt_kernel_nand_addr = 0; int board_id; int done = 0; u32 ret = 0; #ifdef CPU_LF1000 /* disable the USB controller */ BIT_SET(REG16(LF1000_UDC_BASE+UDC_PCR), PCE); #endif adc_init(); board_id = load_board_id(); display_backlight(board_id); clock_init(); db_init(); display_init(); fbcon_init(); db_displaytee(1); db_puts("************************************************\n"); db_puts("* *\n"); db_puts("* OpenDidj lightning-boot 1.1 / 12 Mar 2010 *\n"); db_puts("* *\n"); db_puts("************************************************\n"); db_puts("\n\n"); #ifdef CONFIG_MACH_LF_LF1000 /* now that backlight is on, see if we have enough battery to boot */ if(gpio_get_val(LOW_BATT_PORT, LOW_BATT_PIN) == 0 && ADC_TO_MV(adc_get_reading(LF1000_ADC_VBATSENSE)) < BOOT_MIN_MV){ db_puts("PANIC: battery voltage too low!\n"); die(); } #endif /* CONFIG_MACH_LF_LF1000 */ #ifdef UBOOT_SUPPORT if(((REG32(LF1000_GPIO_BASE+GPIOCPAD) & BUTTON_MSK) == BUTTON_MSK)) { do { db_puts("xmodem download mode\n"); timer_init(); offset = 0; xmodemInit(db_putchar,db_getc_async); tmr_poll_start(2000); db_puts("Switch to 115200 baud and press any button\n"); db_puts("to start XModem download...\n"); /* set the baud rate */ #define UART16(r) REG16(LF1000_SYS_UART_BASE+r) UART16(BRD) = 1; /* FIXME (for now "1" sets 115200 baud , "11" sets 19200 baud) */ UART16(UARTCLKGEN) = ((UARTDIV-1)<<UARTCLKDIV)|(UART_PLL<<UARTCLKSRCSEL); if(tfs_load_summary(sum_buffer, BOOT0_ADDR) != 0) { db_puts("trying BOOT1\n"); if(tfs_load_summary(sum_buffer, BOOT1_ADDR)) { db_puts("u-boot not found\n"); break; } } while (!done) { if (tmr_poll_has_expired()){ if(((REG32(LF1000_GPIO_BASE+GPIOCPAD) & BUTTON_MSK) != BUTTON_MSK)) { db_displaytee(0); ret = xmodemReceive(ubcopy); db_displaytee(1); if ( ret >= 0 ) break; } if (ret == -1) db_puts("XMODEM_ERROR : REMOTECANCEL\n"); if (ret == -2) db_puts("XMODEM_ERROR : OUTOFSYNC\n"); if (ret == -3) db_puts("XMODEM_ERROR : RETRYEXCEED\n"); if ( ret < 0 ) continue; /* db_puts("Loaded : "); db_int(ret); db_puts("bytes\n"); */ } } db_puts("\n\nXModem download complete.\n"); db_puts("Transferring control to U-Boot.\n"); /* jump to u-boot */ ((void (*)( int r0, int r1, int r2))UBOOT_ADDR) (0, MACH_TYPE_LF1000, 0); /* never get here! */ die(); } while(0); } #endif /* UBOOT_SUPPORT */ /* Set up the kernel command line */ /* read entire /flags partition */ nand_read(fs_buffer, BOOT_FLAGS_ADDR, BOOT_FLAGS_SIZE); /* find rootfs file */ node = jffs2_cat((char *)fs_buffer, BOOT_FLAGS_SIZE, "rootfs"); rootfs = RFS0; if(node == 0) { db_puts("warning: failed to find rootfs flags!\n"); } else { rfs_txt = (char*)node+sizeof(struct jffs2_raw_inode)-4; if(!strncmp(rfs_txt, "RFS1", 4)) { db_puts("booting RFS1\n"); rootfs = RFS1; } #ifdef NFS_SUPPORT else if(!strncmp(rfs_txt, "NFS0", 4)) { db_puts("booting NFS0\n"); rootfs = NFS0; } else if(!strncmp(rfs_txt, "NFS1", 4)) { db_puts("booting NFS1\n"); rootfs = NFS1; } #endif /* NFS_SUPPORT */ else { db_puts("booting RFS0\n"); } } /* Find the mfcart file */ mfg_node = jffs2_cat((char *)fs_buffer, BOOT_FLAGS_SIZE, "mfcart"); if(mfg_node != 0) { db_puts("Booting with mfg cartridge layout.\n"); } /* construct the command line */ if(mfg_node == 0) { if(rootfs == RFS0) { cmdline = CMDLINE_BASE CMDLINE_RFS0 CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS1 CMDLINE_UBI; kernel_nand_addr = BOOT0_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } else if(rootfs == RFS1) { cmdline = CMDLINE_BASE CMDLINE_RFS1 CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS0 CMDLINE_UBI; kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT0_ADDR; } #ifdef NFS_SUPPORT else if(rootfs == NFS0) { cmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; kernel_nand_addr = BOOT0_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } else if(rootfs == NFS1) { cmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_UBI; kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT0_ADDR; } #endif /* NFS_SUPPORT */ } else { if(rootfs == RFS0) { cmdline = CMDLINE_BASE CMDLINE_RFS0 CMDLINE_MFG CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS1 CMDLINE_MFG CMDLINE_UBI; kernel_nand_addr = BOOT0_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } else if(rootfs == RFS1) { cmdline = CMDLINE_BASE CMDLINE_RFS1 CMDLINE_MFG CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_RFS0 CMDLINE_MFG CMDLINE_UBI; kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT0_ADDR; } #ifdef NFS_SUPPORT else if(rootfs == NFS0) { cmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_MFG CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_MFG CMDLINE_UBI; kernel_nand_addr = BOOT0_ADDR; alt_kernel_nand_addr = BOOT1_ADDR; } else if(rootfs == NFS1) { cmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_MFG CMDLINE_UBI; altcmdline = CMDLINE_BASE CMDLINE_NFS CMDLINE_MFG CMDLINE_UBI; kernel_nand_addr = BOOT1_ADDR; alt_kernel_nand_addr = BOOT0_ADDR; } #endif /* NFS_SUPPORT */ } if(tfs_load_summary(sum_buffer, kernel_nand_addr)) { db_puts("warning: booting alternative kernel!\n"); if(tfs_load_summary(sum_buffer, alt_kernel_nand_addr)) { db_puts("PANIC: unable to load alt summary\n"); die(); } } db_stopwatch_start("LOAD KERNEL"); image = load_kernel(cmdline); db_stopwatch_stop(); if(image == 0) { db_puts("Warning: booting alternative kernel!\n"); if(tfs_load_summary(sum_buffer, alt_kernel_nand_addr) != 0) { die(); } image = load_kernel(altcmdline); if(image == 0) { db_puts("PANIC: nothing to boot\n"); die(); } } #ifdef DISPLAY_SUPPORT db_stopwatch_start("SPLASH"); db_puts("Loading bootsplash\n"); tfs_load_file("bootsplash.rgb", (u32 *)FRAME_BUFFER_ADDR); display_init(); db_stopwatch_stop(); #endif load_cart_id(); db_puts("Starting the kernel...\n"); cleanup_for_linux(); /* jump to image (void, architecture ID, atags pointer) */ ((void(*)(int r0, int r1, unsigned int r2))image) (0, MACH_TYPE_LF1000, (unsigned int)params_buffer); /* never get here! */ die(); }
void HariMain(void) { int i; struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; int xsize = (*binfo).scrnx; int ysize = (*binfo).scrny; char *vram = (*binfo).vram; char msg[40], mcursor[256]; int mx = xsize/2; int my = ysize/2; int fifobuf[128]; struct MOUSE_DEC mdec; unsigned char s[32]; unsigned int memtotal, count = 0; struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR; int cursor_x, cursor_c; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; struct TIMER *timer1, *timer2, *timer3; struct FIFO32 fifo; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; init_gdtidt (); init_pic (); io_sti (); fifo32_init(&fifo, 32, fifobuf); init_pit(); io_out8(PIC0_IMR, 0xf8); /* Allow PIT and Keyboard (11111000) */ io_out8(PIC1_IMR, 0xef); /* Allow Mouse (11101111) */ init_keyboard (&fifo, 256); enable_mouse (&fifo, 512, &mdec); timer1 = timer_alloc(); timer_init(timer1, &fifo, 10); timer_settime(timer1, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init (memman); memman_free (memman, 0x00001000, 0x009e000); /* 0x00001000 - 0x0009efff */ memman_free (memman, 0x00400000, memtotal - 0x00400000); init_pallete(); shtctl = shtctl_init (memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *)memman_alloc_4k (memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *)memman_alloc_4k (memman, 160 * 52); sheet_setbuf (sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf (sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf (sht_win, buf_win, 160, 52, -1); init_screen (buf_back, xsize, ysize); init_mouse_cursor8 (buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); sprintf (s, "(%d, %d)", mx, my); putfonts8_asc (buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf (s, "Memory %dMB, free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); make_textbox8 (sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; sheet_slide (sht_back, 0, 0); sheet_slide (sht_mouse, mx, my); sheet_slide (sht_win, 80, 72); sheet_updown (sht_back, 0); sheet_updown (sht_win, 1); sheet_updown (sht_mouse, 2); sheet_refresh (sht_back, 0, 0, binfo->scrnx, 48); //===================== // Task Settings //===================== struct TSS32 tas_a, tas_b; tas_a.ldtr = 0; tas_a.iomap = 0x40000000; tas_b.ldtr = 0; tas_b.iomap = 0x40000000; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *)ADR_GDT; set_segmdesc (gdt + 3, 103, (int)&tas_a, AR_TSS32); set_segmdesc (gdt + 4, 103, (int)&tas_b, AR_TSS32); load_tr(3 * 8); int tas_b_esp; tas_b_esp = memman_alloc_4k (memman, 64 * 1024) + 64 * 1024; tas_b.eip = (int)&task_b_main; tas_b.eflags = 0x00000202; tas_b.eax = 0; tas_b.ecx = 0; tas_b.edx = 0; tas_b.ebx = 0; tas_b.esp = tas_b_esp; tas_b.ebp = 0; tas_b.esi = 0; tas_b.edi = 0; tas_b.es = 1 * 8; tas_b.cs = 2 * 8; tas_b.ss = 1 * 8; tas_b.ds = 1 * 8; tas_b.fs = 1 * 8; tas_b.gs = 1 * 8; for (;;) { count ++; io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { // Keyboard Data sprintf (s, "%x", i - 256); putfonts8_asc_sht (sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 256 + 0x54) { if (keytable[i - 256] != 0) { s[0] = keytable[i-256]; s[1] = 0; putfonts8_asc_sht (sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { // Backspace putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { // Mouse Data if (mouse_decode(&mdec, i-512) != 0) { sprintf (s, "[lcr %d %d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht (sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my < 0) { my = 0; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%d, %d)", mx, my); putfonts8_asc_sht (sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide (sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide (sht_win, mx - 80, my - 8); } } } else if (i == 10) { putfonts8_asc_sht (sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); taskswitch4(); } else if (i == 3) { putfonts8_asc_sht (sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); count = 0; } else if (i <= 1) { if (i != 0) { timer_init(timer3, &fifo, 0); cursor_c = COL8_000000; } else { timer_init(timer3, &fifo, 1); cursor_c = COL8_FFFFFF; } timer_settime(timer3, 50); boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
int main(int argc,char *argv[]) { vm_instance_t *vm; #ifdef PROFILE atexit(profiler_savestat); #endif printf("Cisco Router Simulation Platform (version %s)\n",sw_version); printf("Copyright (c) 2005-2007 Christophe Fillot.\n"); printf("Build date: %s %s\n\n",__DATE__,__TIME__); /* Register platforms */ register_default_platforms(); /* Initialize timers */ timer_init(); /* Initialize object registry */ registry_init(); /* Initialize ATM module (for HEC checksums) */ atm_init(); /* Initialize CRC functions */ crc_init(); /* Initialize NetIO code */ netio_rxl_init(); /* Initialize NetIO packet filters */ netio_filter_load_all(); /* Initialize VTTY code */ vtty_init(); /* Parse standard command line */ if (!run_hypervisor(argc,argv)) parse_std_cmd_line(argc,argv); /* Create general log file */ create_log_file(); /* Periodic tasks initialization */ if (ptask_init(0) == -1) exit(EXIT_FAILURE); /* Create instruction lookup tables */ mips64_jit_create_ilt(); mips64_exec_create_ilt(); ppc32_jit_create_ilt(); ppc32_exec_create_ilt(); setup_signals(); if (!hypervisor_mode) { /* Initialize the default instance */ vm = vm_acquire("default"); assert(vm != NULL); if (vm->platform->init_instance(vm) == -1) { fprintf(stderr,"Unable to initialize router instance.\n"); exit(EXIT_FAILURE); } /* Start GDB server before the image to allow debugging from the begining of it's execution */ if (vm->gdb_server_running) { /* Stop main CPU */ vm_suspend(vm); // cpu_stop(vm->boot_cpu); if (gdb_server_start_listener(vm) < 0) { fprintf(stderr,"GDB server unable to create TCP sockets.\n"); exit(EXIT_FAILURE); } } #if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0) { m_uint32_t counter,prev = 0,delta; while(vm->status == VM_STATUS_RUNNING) { counter = cpu_get_perf_counter(vm->boot_cpu); delta = counter - prev; prev = counter; printf("delta = %u\n",delta); sleep(1); } } #else /* Start instance monitoring */ vm_monitor(vm); #endif // FIXME: remove this kludge if (vm->gdb_server_running) { //while (vm->gdb_conn->active) // usleep(1000000); gdb_server_close_control_sockets(); } /* Free resources used by instance */ vm_release(vm); } else { hypervisor_tcp_server(hypervisor_ip_address,hypervisor_tcp_port); } dynamips_reset(); close_log_file(); return(0); }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; struct TASK *task_a, *task_cons; struct TIMER *timer; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); /* 透明色なし */ make_window8(buf_cons, 256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; *((int *) (task_cons->tss.esp + 8)) = memtotal; task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 透明色なし */ make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_win, 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); /* 最初にキーボード状態との食い違いがないように、設定しておくことにする */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* キーボードコントローラに送るデータがあれば、送る */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ if (i < 0x80 + 256) { /* キーコードを文字コードに変換 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 入力文字がアルファベット */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 大文字を小文字に変換 */ } } if (s[0] != 0) { /* 通常文字 */ if (key_to == 0) { /* タスクAへ */ if (cursor_x < 128) { /* 一文字表示してから、カーソルを1つ進める */ s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { /* コンソールへ */ fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { /* バックスペース */ if (key_to == 0) { /* タスクAへ */ if (cursor_x > 8) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { /* コンソールへ */ fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x1c) { /* Enter */ if (key_to != 0) { /* コンソールへ */ fifo32_put(&task_cons->fifo, 10 + 256); } } if (i == 256 + 0x0f) { /* Tab */ if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; /* カーソルを消す */ boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put(&task_cons->fifo, 2); /* コンソールのカーソルON */ } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; /* カーソルを出す */ fifo32_put(&task_cons->fifo, 3); /* コンソールのカーソルOFF */ } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x2a) { /* 左シフト ON */ key_shift |= 1; } if (i == 256 + 0x36) { /* 右シフト ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左シフト OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右シフト OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { /* キーボードがデータを無事に受け取った */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* キーボードがデータを無事に受け取れなかった */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } /* カーソルの再表示 */ if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押していたら、sht_winを動かす */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &fifo, 0); /* 次は0を */ if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); /* 次は1を */ if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
int main (void) { uint8_t i; #ifndef HOST uint8_t read_old = 0; uint8_t old_ind = 0; const int total = 5000; #endif timer_init (); for (i = 0; i < AC_ENCODER_EXT_NB; i++) encoder_init (i, &encoder[i]); encoder_corrector_init (&encoder_corrector_right); uart0_init (); proto_send0 ('z'); sei (); while (1) { timer_wait (); if (count) { encoder_update (); encoder_corrector_update (&encoder_corrector_right, &encoder[1]); } #ifndef HOST if (read && !--read_cpt) { uint8_t r0, r1, r2, r3; r0 = encoder_ext_read (0); r1 = encoder_ext_read (1); r2 = encoder_ext_read (2); r3 = encoder_ext_read (3); if (read_mode == 0 || (read_mode == 1 && r3 != read_old) || (read_mode == 2 && (r0 == 0 || r1 == 0 || r2 == 0 || r3 == 0))) { proto_send4b ('r', r0, r1, r2, r3); read_old = r3; } read_cpt = read; } if (ind && !--ind_cpt) { i = encoder_ext_read (3); if (!ind_init && i != old_ind) { uint8_t eip = old_ind + total; uint8_t eim = old_ind - total; proto_send7b ('i', old_ind, i, eip, eim, i - eip, i - eim, i == eip || i == eim); } old_ind = i; ind_init = 0; ind_cpt = ind; } #endif if (count && !--count_cpt) { proto_send4w ('C', encoder[0].cur, encoder[1].cur, encoder[2].cur, encoder[3].cur); count_cpt = count; } while (uart0_poll ()) proto_accept (uart0_getc ()); } }
void board_init_f(ulong dummy) { unsigned int ramchip; struct mx6_ddr_sysinfo sysinfo = { /* width of data bus:0=16,1=32,2=64 */ .dsize = 2, /* config for full 4GB range so that get_mem_size() works */ .cs_density = 32, /* 512 MB */ /* single chip select */ #if IS_ENABLED(CONFIG_SPL_DRAM_1_BANK) .ncs = 1, #else .ncs = 2, #endif .cs1_mirror = 1, .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */ .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */ .walat = 1, /* Write additional latency */ .ralat = 5, /* Read additional latency */ .mif3_mode = 3, /* Command prediction working mode */ .bi_on = 1, /* Bank interleaving enabled */ .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */ .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */ .ddr_type = DDR_TYPE_DDR3, .refsel = 1, /* Refresh cycles at 32KHz */ .refr = 7, /* 8 refresh commands per refresh cycle */ }; #ifdef CONFIG_CMD_NAND /* Enable NAND */ setup_gpmi_nand(); #endif /* setup clock gating */ ccgr_init(); /* setup AIPS and disable watchdog */ arch_cpu_init(); /* setup AXI */ gpr_init(); board_early_init_f(); /* setup GP timer */ timer_init(); /* UART clocks enabled and gd valid - init serial console */ preloader_console_init(); setup_spi(); setup_gpios(); /* DDR initialization */ spl_dram_init(&sysinfo, &mt41k_xx[RAM_MT256K]); ramchip = pfla02_detect_chiptype(); debug("Detected chip %d\n", ramchip); #if !IS_ENABLED(CONFIG_SPL_DRAM_1_BANK) switch (ramchip) { case RAM_MT64K: sysinfo.cs_density = 6; break; case RAM_MT128K: sysinfo.cs_density = 10; break; case RAM_MT256K: sysinfo.cs_density = 18; break; } #endif spl_dram_init(&sysinfo, &mt41k_xx[ramchip]); /* Clear the BSS. */ memset(__bss_start, 0, __bss_end - __bss_start); phyflex_err006282_workaround(); /* load/boot image from boot device */ board_init_r(NULL, 0); }
/** Run engine event loop. * @param[in] gen Lists of generators of various types. */ static void engine_loop(struct Generators* gen) { int events_count; struct kevent *evt; struct Socket* sock; struct timespec wait; int i; int errcode; socklen_t codesize; if ((events_count = feature_int(FEAT_POLLS_PER_LOOP)) < 20) events_count = 20; events = (struct kevent *)MyMalloc(sizeof(struct kevent) * events_count); while (running) { if ((i = feature_int(FEAT_POLLS_PER_LOOP)) >= 20 && i != events_count) { events = (struct kevent *)MyRealloc(events, sizeof(struct kevent) * i); events_count = i; } /* set up the sleep time */ wait.tv_sec = timer_next(gen) ? (timer_next(gen) - CurrentTime) : -1; wait.tv_nsec = 0; Debug((DEBUG_ENGINE, "kqueue: delay: %Tu (%Tu) %Tu", timer_next(gen), CurrentTime, wait.tv_sec)); /* check for active events */ events_used = kevent(kqueue_id, 0, 0, events, events_count, wait.tv_sec < 0 ? 0 : &wait); CurrentTime = time(0); /* set current time... */ if (events_used < 0) { if (errno != EINTR) { /* ignore kevent interrupts */ /* Log the kqueue error */ log_write(LS_SOCKET, L_ERROR, 0, "kevent() error: %m"); if (!errors++) timer_add(timer_init(&clear_error), error_clear, 0, TT_PERIODIC, ERROR_EXPIRE_TIME); else if (errors > KQUEUE_ERROR_THRESHOLD) /* too many errors... */ server_restart("too many kevent errors"); } /* old code did a sleep(1) here; with usage these days, * that may be too expensive */ continue; } while (events_used > 0) { evt = &events[--events_used]; if (evt->filter == EVFILT_SIGNAL) { /* it's a signal; deal appropriately */ event_generate(ET_SIGNAL, evt->udata, evt->ident); continue; /* skip socket processing loop */ } assert(evt->filter == EVFILT_READ || evt->filter == EVFILT_WRITE); sock = sockList[evt->ident]; if (!sock) /* slots may become empty while processing events */ continue; assert(s_fd(sock) == evt->ident); gen_ref_inc(sock); /* can't have it going away on us */ Debug((DEBUG_ENGINE, "kqueue: Checking socket %p (fd %d) state %s, " "events %s", sock, s_fd(sock), state_to_name(s_state(sock)), sock_flags(s_events(sock)))); if (s_state(sock) != SS_NOTSOCK) { errcode = 0; /* check for errors on socket */ codesize = sizeof(errcode); if (getsockopt(s_fd(sock), SOL_SOCKET, SO_ERROR, &errcode, &codesize) < 0) errcode = errno; /* work around Solaris implementation */ if (errcode) { /* an error occurred; generate an event */ Debug((DEBUG_ENGINE, "kqueue: Error %d on fd %d, socket %p", errcode, s_fd(sock), sock)); event_generate(ET_ERROR, sock, errcode); gen_ref_dec(sock); /* careful not to leak reference counts */ continue; } } switch (s_state(sock)) { case SS_CONNECTING: if (evt->filter == EVFILT_WRITE) { /* connection completed */ Debug((DEBUG_ENGINE, "kqueue: Connection completed")); event_generate(ET_CONNECT, sock, 0); } break; case SS_LISTENING: if (evt->filter == EVFILT_READ) { /* connect. to be accept. */ Debug((DEBUG_ENGINE, "kqueue: Ready for accept")); event_generate(ET_ACCEPT, sock, 0); } break; case SS_NOTSOCK: /* doing nothing socket-specific */ case SS_CONNECTED: if (evt->filter == EVFILT_READ) { /* data on socket */ Debug((DEBUG_ENGINE, "kqueue: EOF or data to be read")); event_generate(evt->flags & EV_EOF ? ET_EOF : ET_READ, sock, 0); } if (evt->filter == EVFILT_WRITE) { /* socket writable */ Debug((DEBUG_ENGINE, "kqueue: Data can be written")); event_generate(ET_WRITE, sock, 0); } break; case SS_DATAGRAM: case SS_CONNECTDG: if (evt->filter == EVFILT_READ) { /* socket readable */ Debug((DEBUG_ENGINE, "kqueue: Datagram to be read")); event_generate(ET_READ, sock, 0); } if (evt->filter == EVFILT_WRITE) { /* socket writable */ Debug((DEBUG_ENGINE, "kqueue: Datagram can be written")); event_generate(ET_WRITE, sock, 0); } break; } gen_ref_dec(sock); /* we're done with it */ } timer_run(); /* execute any pending timers */ } }
int main(void) { SystemCoreClockUpdate(); uint32_t i; callback = data_recv_callback; iox_led_init(); timer_init(); uart_init(31250, callback); for (i = 0; i < TBUF_SIZE; i++) { timer[i] = 0; } head = 0; tail = 0; headt = 0; tailt = 0; n = 0; light = true; iox_led_on(false, light, false, false); while (1) { #ifdef TESTING timer_delay(10); // wait 1s midi_on(1, n, 90); light = !light; n > 127 ? n = 0 : n; iox_led_on(true, light, false, false); timer_delay(5); // wait 0.5s midi_off(1, n++, 90); #endif #ifdef GHDRUMS /* * If full command received, send ON data and * store timer. */ if (n >= 3) { if (!buffer_empty()) { midi_on(0, data[(tail + 1)], data[(tail + 2)]); timer[headt++] = timer_get() + 5; headt %= TBUF_SIZE; light = !light; iox_led_on(false, false, false, light); n -= 3; } } /* * If time has passed, send OFF command. */ if (!tbuffer_empty()) { if (timer[tailt] > timer_get()) { if (!buffer_empty()) { midi_off(0, data[(tail + 1)], data[(tail + 2)]); tail = (tail + MIDI_CMD_LEN) % BUF_SIZE; tailt = (tailt + 1) % TBUF_SIZE; } } } #endif } return 0; }
extern "C" int _start(kernel_args *bootKernelArgs, int currentCPU) { if (bootKernelArgs->kernel_args_size != sizeof(kernel_args) || bootKernelArgs->version != CURRENT_KERNEL_ARGS_VERSION) { // This is something we cannot handle right now - release kernels // should always be able to handle the kernel_args of earlier // released kernels. debug_early_boot_message("Version mismatch between boot loader and " "kernel!\n"); return -1; } smp_set_num_cpus(bootKernelArgs->num_cpus); // wait for all the cpus to get here smp_cpu_rendezvous(&sCpuRendezvous); // the passed in kernel args are in a non-allocated range of memory if (currentCPU == 0) memcpy(&sKernelArgs, bootKernelArgs, sizeof(kernel_args)); smp_cpu_rendezvous(&sCpuRendezvous2); // do any pre-booting cpu config cpu_preboot_init_percpu(&sKernelArgs, currentCPU); thread_preboot_init_percpu(&sKernelArgs, currentCPU); // if we're not a boot cpu, spin here until someone wakes us up if (smp_trap_non_boot_cpus(currentCPU, &sCpuRendezvous3)) { // init platform arch_platform_init(&sKernelArgs); // setup debug output debug_init(&sKernelArgs); set_dprintf_enabled(true); dprintf("Welcome to kernel debugger output!\n"); dprintf("Haiku revision: %s\n", get_haiku_revision()); // init modules TRACE("init CPU\n"); cpu_init(&sKernelArgs); cpu_init_percpu(&sKernelArgs, currentCPU); TRACE("init interrupts\n"); int_init(&sKernelArgs); TRACE("init VM\n"); vm_init(&sKernelArgs); // Before vm_init_post_sem() is called, we have to make sure that // the boot loader allocated region is not used anymore boot_item_init(); debug_init_post_vm(&sKernelArgs); low_resource_manager_init(); // now we can use the heap and create areas arch_platform_init_post_vm(&sKernelArgs); lock_debug_init(); TRACE("init driver_settings\n"); driver_settings_init(&sKernelArgs); debug_init_post_settings(&sKernelArgs); TRACE("init notification services\n"); notifications_init(); TRACE("init teams\n"); team_init(&sKernelArgs); TRACE("init ELF loader\n"); elf_init(&sKernelArgs); TRACE("init modules\n"); module_init(&sKernelArgs); TRACE("init semaphores\n"); haiku_sem_init(&sKernelArgs); TRACE("init interrupts post vm\n"); int_init_post_vm(&sKernelArgs); cpu_init_post_vm(&sKernelArgs); commpage_init(); call_all_cpus_sync(non_boot_cpu_init, &sKernelArgs); TRACE("init system info\n"); system_info_init(&sKernelArgs); TRACE("init SMP\n"); smp_init(&sKernelArgs); cpu_build_topology_tree(); TRACE("init timer\n"); timer_init(&sKernelArgs); TRACE("init real time clock\n"); rtc_init(&sKernelArgs); timer_init_post_rtc(); TRACE("init condition variables\n"); condition_variable_init(); // now we can create and use semaphores TRACE("init VM semaphores\n"); vm_init_post_sem(&sKernelArgs); TRACE("init generic syscall\n"); generic_syscall_init(); smp_init_post_generic_syscalls(); TRACE("init scheduler\n"); scheduler_init(); TRACE("init threads\n"); thread_init(&sKernelArgs); TRACE("init kernel daemons\n"); kernel_daemon_init(); arch_platform_init_post_thread(&sKernelArgs); TRACE("init I/O interrupts\n"); int_init_io(&sKernelArgs); TRACE("init VM threads\n"); vm_init_post_thread(&sKernelArgs); low_resource_manager_init_post_thread(); TRACE("init DPC\n"); dpc_init(); TRACE("init VFS\n"); vfs_init(&sKernelArgs); #if ENABLE_SWAP_SUPPORT TRACE("init swap support\n"); swap_init(); #endif TRACE("init POSIX semaphores\n"); realtime_sem_init(); xsi_sem_init(); xsi_msg_init(); // Start a thread to finish initializing the rest of the system. Note, // it won't be scheduled before calling scheduler_start() (on any CPU). TRACE("spawning main2 thread\n"); thread_id thread = spawn_kernel_thread(&main2, "main2", B_NORMAL_PRIORITY, NULL); resume_thread(thread); // We're ready to start the scheduler and enable interrupts on all CPUs. scheduler_enable_scheduling(); // bring up the AP cpus in a lock step fashion TRACE("waking up AP cpus\n"); sCpuRendezvous = sCpuRendezvous2 = 0; smp_wake_up_non_boot_cpus(); smp_cpu_rendezvous(&sCpuRendezvous); // wait until they're booted // exit the kernel startup phase (mutexes, etc work from now on out) TRACE("exiting kernel startup\n"); gKernelStartup = false; smp_cpu_rendezvous(&sCpuRendezvous2); // release the AP cpus to go enter the scheduler TRACE("starting scheduler on cpu 0 and enabling interrupts\n"); scheduler_start(); enable_interrupts(); } else { // lets make sure we're in sync with the main cpu // the boot processor has probably been sending us // tlb sync messages all along the way, but we've // been ignoring them arch_cpu_global_TLB_invalidate(); // this is run for each non boot processor after they've been set loose smp_per_cpu_init(&sKernelArgs, currentCPU); // wait for all other AP cpus to get to this point smp_cpu_rendezvous(&sCpuRendezvous); smp_cpu_rendezvous(&sCpuRendezvous2); // welcome to the machine scheduler_start(); enable_interrupts(); } #ifdef TRACE_BOOT // We disable interrupts for this dprintf(), since otherwise dprintf() // would acquires a mutex, which is something we must not do in an idle // thread, or otherwise the scheduler would be seriously unhappy. disable_interrupts(); TRACE("main: done... begin idle loop on cpu %d\n", currentCPU); enable_interrupts(); #endif for (;;) cpu_idle(); return 0; }
void HariMain(void) { struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; struct MOUSE_DEC mdec; unsigned int memtotal; struct SHTCTL *shtctl; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct TASK *task_a, *task_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; int cursor_x, cursor_c, mx, my, i; // cursor_x: 记录光标显示位置 struct TIMER *timer; char s[40]; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`', 0, '\\', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; // key_to为1时,console窗口有效 init_gdtidt(); init_pic(); io_sti(); /* IDT/PIC的初始化结束,开启CPU中断 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* 许可PIC1和键盘(11111000) */ io_out8(PIC1_IMR, 0xef); /* 许可鼠标(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); // 使用的内存空间,包含了0x00400000前已用的内存 memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); // 为什么没给tss.eip、tss.esp赋值?task_a什么都不干。 fifo.task = task_a; task_run(task_a, 1, 2); /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 没有透明色 */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); /* 无透明色 */ make_window8(buf_cons, 256, 165, "console", 0); // act为1时,颜色不变;act为0时,标题栏变灰色。 make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; // 与bootpack.c相同的地址段,asmkfunc.nas中bootpack启动部分 task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; // 传参 task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 没有透明色 */ make_window8(buf_win, 144, 52, "task_a", 1); // act为1时,颜色不变;act为0时,标题栏变灰色。 make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // 透明色号99 init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back , 0, 0); sheet_slide(sht_cons , 32, 4); sheet_slide(sht_win , 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win , 2); sheet_updown(sht_mouse, 3); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); /* 为了避免和键盘当前状态冲突,在一开始先进行设置 */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* 如果存在想键盘控制器发送的数据,则发送 */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { /* J char ss[10]; sprintf(ss, "%c", "J"); putfonts8_asc(binfo->vram, binfo->scrnx, 100, 100, COL8_FFFFFF, ss); */ task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* 键盘数据 */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x80 + 256) { /* 将按键编码转换为字符编码 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 当输入字符为应为字符时 */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 将大写字母转换为小写字母 */ } } if (s[0] != 0) { /* 通常文字 */ if (key_to == 0) { /* 发送给任务A */ if (cursor_x < 128) { /* 显示1个字符就前移1次光标 */ s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { /* 发送给命令行窗口 */ fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { /* 退格键 */ if (key_to == 0) { /* 发送给任务A */ if (cursor_x > 8) { /* 用空格键把光标消去后,后移1次光标 */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { /* 发送给命令行窗口 */ fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x0f) { /* Tab */ if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x2a) { /* 左Shift ON */ key_shift |= 1; // 直接赋值呢? } if (i == 256 + 0x36) { /* 右Shift ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左Shift OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右Shift OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { /* 键盘成功接收到数据 */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* 键盘没有成功接收到数据 */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } /* カーソルの再表示 */ boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* 鼠标的3个字节都齐了,显示出来 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* 移动鼠标 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 按下左键、移动sht_win */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* 光标用定时器 */ if (i != 0) { timer_init(timer, &fifo, 0); /* 下面设定0 */ cursor_c = COL8_000000; } else { timer_init(timer, &fifo, 1); /* 下面设定1 */ cursor_c = COL8_FFFFFF; } timer_settime(timer, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { int i; struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; int xsize = (*binfo).scrnx; int ysize = (*binfo).scrny; char *vram = (*binfo).vram; char msg[40], mcursor[256]; int mx = xsize/2; int my = ysize/2; int fifobuf[128], keycmd_buf[32]; struct MOUSE_DEC mdec; unsigned char s[32]; unsigned int memtotal; struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR; int cursor_x, cursor_c; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct TIMER *timer; struct FIFO32 fifo, keycmd; struct TASK *task_a, *task_cons; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; init_gdtidt (); init_pic (); io_sti (); fifo32_init(&fifo, 32, fifobuf, 0); fifo32_init(&keycmd, 32, keycmd_buf, 0); init_pit(); io_out8(PIC0_IMR, 0xf8); /* Allow PIT and Keyboard (11111000) */ io_out8(PIC1_IMR, 0xef); /* Allow Mouse (11101111) */ init_keyboard (&fifo, 256); enable_mouse (&fifo, 512, &mdec); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init (memman); memman_free (memman, 0x00001000, 0x009e000); /* 0x00001000 - 0x0009efff */ memman_free (memman, 0x00400000, memtotal - 0x00400000); init_pallete(); shtctl = shtctl_init (memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *)memman_alloc_4k (memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *)memman_alloc_4k (memman, 160 * 52); sheet_setbuf (sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf (sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf (sht_win, buf_win, 160, 52, -1); init_screen (buf_back, xsize, ysize); init_mouse_cursor8 (buf_mouse, 99); make_window8(buf_win, 160, 52, "task_a", 1); // sprintf (s, "(%d, %d)", mx, my); // putfonts8_asc (buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); // sprintf (s, "Memory %dMB, free : %dKB", // memtotal / (1024 * 1024), memman_total(memman) / 1024); // putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); make_textbox8 (sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; //===================== // Task Settings //===================== task_a = task_init(memman); fifo.task = task_a; task_run (task_a, 1, 0); /* console sheet */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *)memman_alloc_4k(memman, 256 * 165); sheet_setbuf (sht_cons, buf_cons, 256, 165, -1); make_window8 (buf_cons, 256, 165, "console", 0); make_textbox8 (sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc (); task_cons->tss.esp = memman_alloc_4k (memman, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int)&console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; *((int *) (task_cons->tss.esp + 8)) = (int) memtotal; task_run (task_cons, 1, 0); /* level = 2, priority = 2 */ //======================= // Sheet Setting //======================= sheet_slide (sht_back, 0, 0); sheet_slide (sht_mouse, mx, my); sheet_slide (sht_cons, 32, 4); sheet_slide (sht_win, 64, 56); sheet_updown (sht_back, 0); sheet_updown (sht_cons, 1); sheet_updown (sht_win, 2); sheet_updown (sht_mouse, 3); sheet_refresh (sht_back, 0, 0, binfo->scrnx, 48); fifo32_put (&keycmd, KEYCMD_LED); fifo32_put (&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready (); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { // Keyboard Data // sprintf (s, "%x", i - 256); // putfonts8_asc_sht (sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x80 + 256) { if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0) { if (key_to == 0) { if (cursor_x < 128) { s[1] = 0; putfonts8_asc_sht (sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { // To Console fifo32_put (&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { // Backspace if (key_to == 0) { // To Task-A if (cursor_x > 8) { putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x0f) { // Tab if (key_to == 0) { key_to = 1; make_wtitle8 (buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8 (buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; // Delete cursor boxfill8 (sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put (&task_cons->fifo, 2); // cursor ON console } else { key_to = 0; make_wtitle8 (buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8 (buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; // Delete cursor fifo32_put (&task_cons->fifo, 3); // cursor OFF console } sheet_refresh (sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh (sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x1c) { if (key_to != 0) { fifo32_put (&task_cons->fifo, 10 + 256); } } if (i == 256 + 0x2a) { // Left Shift ON key_shift |= 1; } if (i == 256 + 0x36) { // Right Shift ON key_shift |= 2; } if (i == 256 + 0xaa) { // Left Shift OFF key_shift &= ~1; } if (i == 256 + 0xb6) { // Right Shift ON key_shift &= ~2; } if (i == 256 + 0x3a) { // CapsLock key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { // NumLock key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { // ScrollLock key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { // KeyBoard receive Data keycmd_wait = -1; } if (i == 256 + 0xfe) { // KeyBoard failed to receive Data wait_KBC_sendready (); io_out8(PORT_KEYDAT, keycmd_wait); } // Redraw cursor if (cursor_c >= 0) { boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { // Mouse Data if (mouse_decode(&mdec, i-512) != 0) { // sprintf (s, "[lcr %d %d]", mdec.x, mdec.y); // if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } // if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } // if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } // putfonts8_asc_sht (sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my < 0) { my = 0; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } // sprintf(s, "(%d, %d)", mx, my); // putfonts8_asc_sht (sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide (sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide (sht_win, mx - 80, my - 8); } } } else if (i <= 1) { if (i != 0) { timer_init(timer, &fifo, 0); if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
int main(void) { wl_err_t wl_status; int status; struct ctx_server *hs; enum wl_host_attention_mode mode; startup_init(); board_init(); led_init(); tc_init(); delay_init(FOSC0); #ifdef _TEST_SPI_ for (;;) { /* handle console input */ console_poll(); spi_poll(NULL); } #else printk("Arduino Wifi Startup... [%s]\n", timestamp); size_t size_ctx_server = sizeof(struct ctx_server); hs = calloc(1, size_ctx_server); ASSERT(hs, "out of memory"); size_t size_netif = sizeof(struct netif); hs->net_cfg.netif = calloc(1, size_netif); ASSERT(hs->net_cfg.netif, "out of memory"); hs->net_cfg.dhcp_enabled = INIT_IP_CONFIG; INFO_INIT("hs:%p size:0x%x netif:%p size:0x%x\n", hs, size_ctx_server, hs->net_cfg.netif, size_netif); initShell(hs); timer_init(NULL, NULL); lwip_init(); status = fw_download_init(); ASSERT(status == 0, "failed to prepare for firmware download\n"); wl_status = wl_transport_init(fw_read_cb, hs, &mode); if (wl_status != WL_SUCCESS) goto err; INFO_INIT("Mode: 0x%x\n", mode); wl_status = wl_init(hs, wl_init_complete_cb, mode); if (wl_status != WL_SUCCESS) goto err; /* start main loop */ for (;;) poll(hs); err: /* show error message on console and display if wlan initialization fails */ #define WL_CARD_FAILURE_STR "Could not detect wl device, aborting\n" #define WL_FIRMWARE_INVALID_STR "Invalid firmware data, aborting\n" #define WL_OTHER_FAILURE_STR "Failed to start wl initialization\n" switch (wl_status) { case WL_CARD_FAILURE: printk(WL_CARD_FAILURE_STR); break; case WL_FIRMWARE_INVALID: printk(WL_FIRMWARE_INVALID_STR); break; default: printk(WL_OTHER_FAILURE_STR); break; } for (;;) { timer_poll(); } #endif }
int main(int argc,char *argv[]) { vm_instance_t *vm; #ifdef PROFILE atexit(profiler_savestat); #endif #ifdef USE_UNSTABLE printf("Cisco Router Simulation Platform (version %s/%s unstable)\n", sw_version,os_name); #else printf("Cisco Router Simulation Platform (version %s/%s stable)\n", sw_version,os_name); #endif printf("Copyright (c) 2005-2011 Christophe Fillot.\n"); printf("Build date: %s %s\n\n",__DATE__,__TIME__); gen_uuid_init(); /* Register platforms */ register_default_platforms(); /* Initialize timers */ timer_init(); /* Initialize object registry */ registry_init(); /* Initialize ATM module (for HEC checksums) */ atm_init(); /* Initialize CRC functions */ crc_init(); /* Initialize NetIO code */ netio_rxl_init(); /* Initialize NetIO packet filters */ netio_filter_load_all(); /* Initialize VTTY code */ vtty_init(); /* Parse standard command line */ atexit(destroy_cmd_line_vars); if (!run_hypervisor(argc,argv)) parse_std_cmd_line(argc,argv); /* Create general log file */ create_log_file(); /* Periodic tasks initialization */ if (ptask_init(0) == -1) exit(EXIT_FAILURE); /* Create instruction lookup tables */ mips64_jit_create_ilt(); mips64_exec_create_ilt(); ppc32_jit_create_ilt(); ppc32_exec_create_ilt(); setup_signals(); if (!hypervisor_mode) { /* Initialize the default instance */ vm = vm_acquire("default"); assert(vm != NULL); if (vm_init_instance(vm) == -1) { fprintf(stderr,"Unable to initialize router instance.\n"); exit(EXIT_FAILURE); } #if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0) { m_uint32_t counter,prev = 0,delta; while(vm->status == VM_STATUS_RUNNING) { counter = cpu_get_perf_counter(vm->boot_cpu); delta = counter - prev; prev = counter; printf("delta = %u\n",delta); sleep(1); } } #else /* Start instance monitoring */ vm_monitor(vm); #endif /* Free resources used by instance */ vm_release(vm); } else { hypervisor_tcp_server(hypervisor_ip_address,hypervisor_tcp_port); } dynamips_reset(); close_log_file(); return(0); }
/* simple test to packetize the data and print it */ int main( int argc, char *argv[]) { volatile struct mstp_port_struct_t *mstp_port; long my_baud = 38400; uint32_t packet_count = 0; MSTP_Port.InputBuffer = &RxBuffer[0]; MSTP_Port.InputBufferSize = sizeof(RxBuffer); MSTP_Port.OutputBuffer = &TxBuffer[0]; MSTP_Port.OutputBufferSize = sizeof(TxBuffer); MSTP_Port.This_Station = 127; MSTP_Port.Nmax_info_frames = 1; MSTP_Port.Nmax_master = 127; MSTP_Port.SilenceTimer = Timer_Silence; MSTP_Port.SilenceTimerReset = Timer_Silence_Reset; /* mimic our pointer in the state machine */ mstp_port = &MSTP_Port; MSTP_Init(mstp_port); packet_statistics_clear(); /* initialize our interface */ if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { printf("mstpcap --scan <filename>\r\n" "perform statistic analysis on MS/TP capture file.\r\n"); printf("\r\n"); printf("mstpcap [interface] [baud] [named pipe]\r\n" "Captures MS/TP packets from a serial interface\r\n" "and save them to a file. Saves packets in a\r\n" "filename mstp_20090123091200.cap that has data and time.\r\n" "After receiving 65535 packets, a new file is created.\r\n" "\r\n" "Command line options:\r\n" "[interface] - serial interface.\r\n" " defaults to COM4 on Windows, and /dev/ttyUSB0 on linux.\r\n" "[baud] - baud rate. 9600, 19200, 38400, 57600, 115200\r\n" " defaults to 38400.\r\n" "[named pipe] - use \\\\.\\pipe\\wireshark as the name\r\n" " and set that name as the interface name in Wireshark\r\n"); return 0; } if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) { printf("mstpcap %s\r\n", BACNET_VERSION_TEXT); printf("Copyright (C) 2011 by Steve Karg\r\n" "This is free software; see the source for copying conditions.\r\n" "There is NO warranty; not even for MERCHANTABILITY or\r\n" "FITNESS FOR A PARTICULAR PURPOSE.\r\n"); return 0; } if ((argc > 1) && (strcmp(argv[1], "--scan") == 0)) { if (argc > 2) { printf("Scanning %s\r\n", argv[2]); /* perform statistics on the file */ if (test_global_header(argv[2])) { while (read_received_packet(mstp_port)) { packet_count++; fprintf(stderr, "\r%u packets", (unsigned) packet_count); } if (packet_count) { packet_statistics_print(); } } else { fprintf(stderr, "File header does not match.\n"); } return 1; } } if (argc > 1) { RS485_Set_Interface(argv[1]); } else { #if defined(_WIN32) print_com_ports(); return 0; #endif } if (argc > 2) { my_baud = strtol(argv[2], NULL, 0); RS485_Set_Baud_Rate(my_baud); } atexit(cleanup); RS485_Initialize(); timer_init(); fprintf(stdout, "mstpcap: Using %s for capture at %ld bps.\n", RS485_Interface(), (long) RS485_Get_Baud_Rate()); #if defined(_WIN32) SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_PROCESSED_INPUT); SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlCHandler, TRUE); #else signal_init(); #endif if (argc > 3) { named_pipe_create(argv[3]); } filename_create_new(); /* run forever */ for (;;) { RS485_Check_UART_Data(mstp_port); MSTP_Receive_Frame_FSM(mstp_port); /* process the data portion of the frame */ if (mstp_port->ReceivedValidFrame) { write_received_packet(mstp_port); mstp_port->ReceivedValidFrame = false; packet_count++; } else if (mstp_port->ReceivedValidFrameNotForUs) { write_received_packet(mstp_port); mstp_port->ReceivedValidFrameNotForUs = false; packet_count++; } else if (mstp_port->ReceivedInvalidFrame) { write_received_packet(mstp_port); Invalid_Frame_Count++; mstp_port->ReceivedInvalidFrame = false; packet_count++; } if (!(packet_count % 100)) { fprintf(stdout, "\r%hu packets, %hu invalid frames", packet_count, Invalid_Frame_Count); } if (packet_count >= 65535) { packet_statistics_print(); packet_statistics_clear(); filename_create_new(); packet_count = 0; } } }
void console_task(struct SHEET *sheet, unsigned int memtotal) { struct TIMER *timer; struct TASK *task = task_now(); int i, fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1; char s[30], cmdline[30], *p; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; int x, y; struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600); int *fat = (int *) memman_alloc_4k(memman, 4 * 2880); struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; fifo32_init(&task->fifo, 128, fifobuf, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settime(timer, 50); file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); /* プロンプト表示 */ putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1); for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&task->fifo); io_sti(); if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &task->fifo, 0); /* 次は0を */ if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } else { timer_init(timer, &task->fifo, 1); /* 次は1を */ if (cursor_c >= 0) { cursor_c = COL8_000000; } } timer_settime(timer, 50); } if (i == 2) { /* カーソルON */ cursor_c = COL8_FFFFFF; } if (i == 3) { /* カーソルOFF */ boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); cursor_c = -1; } if (256 <= i && i <= 511) { /* キーボードデータ(タスクA経由) */ if (i == 8 + 256) { /* バックスペース */ if (cursor_x > 16) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); cursor_x -= 8; } } else if (i == 10 + 256) { /* Enter */ /* カーソルをスペースで消してから改行する */ putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); cmdline[cursor_x / 8 - 2] = 0; cursor_y = cons_newline(cursor_y, sheet); /* コマンド実行 */ if (strcmp(cmdline, "mem") == 0) { /* memコマンド */ sprintf(s, "total %dMB", memtotal / (1024 * 1024)); putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); cursor_y = cons_newline(cursor_y, sheet); sprintf(s, "free %dKB", memman_total(memman) / 1024); putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); cursor_y = cons_newline(cursor_y, sheet); cursor_y = cons_newline(cursor_y, sheet); } else if (strcmp(cmdline, "cls") == 0) { /* clsコマンド */ for (y = 28; y < 28 + 128; y++) { for (x = 8; x < 8 + 240; x++) { sheet->buf[x + y * sheet->bxsize] = COL8_000000; } } sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128); cursor_y = 28; } else if (strcmp(cmdline, "dir") == 0) { /* dirコマンド */ for (x = 0; x < 224; x++) { if (finfo[x].name[0] == 0x00) { break; } if (finfo[x].name[0] != 0xe5) { if ((finfo[x].type & 0x18) == 0) { sprintf(s, "filename.ext %7d", finfo[x].size); for (y = 0; y < 8; y++) { s[y] = finfo[x].name[y]; } s[ 9] = finfo[x].ext[0]; s[10] = finfo[x].ext[1]; s[11] = finfo[x].ext[2]; putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); cursor_y = cons_newline(cursor_y, sheet); } } } cursor_y = cons_newline(cursor_y, sheet); } else if (strncmp(cmdline, "type ", 5) == 0) { /* typeコマンド */ /* ファイル名を準備する */ for (y = 0; y < 11; y++) { s[y] = ' '; } y = 0; for (x = 5; y < 11 && cmdline[x] != 0; x++) { if (cmdline[x] == '.' && y <= 8) { y = 8; } else { s[y] = cmdline[x]; if ('a' <= s[y] && s[y] <= 'z') { /* 小文字は大文字に直す */ s[y] -= 0x20; } y++; } } /* ファイルを探す */ for (x = 0; x < 224; ) { if (finfo[x].name[0] == 0x00) { break; } if ((finfo[x].type & 0x18) == 0) { for (y = 0; y < 11; y++) { if (finfo[x].name[y] != s[y]) { goto type_next_file; } } break; /* ファイルが見つかった */ } type_next_file: x++; } if (x < 224 && finfo[x].name[0] != 0x00) { /* ファイルが見つかった場合 */ p = (char *) memman_alloc_4k(memman, finfo[x].size); file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); cursor_x = 8; for (y = 0; y < finfo[x].size; y++) { /* 1文字ずつ出力 */ s[0] = p[y]; s[1] = 0; if (s[0] == 0x09) { /* タブ */ for (;;) { putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); cursor_x += 8; if (cursor_x == 8 + 240) { cursor_x = 8; cursor_y = cons_newline(cursor_y, sheet); } if (((cursor_x - 8) & 0x1f) == 0) { break; /* 4で割り切れたらbreak */ } } } else if (s[0] == 0x0a) { /* 改行 */ cursor_x = 8; cursor_y = cons_newline(cursor_y, sheet); } else if (s[0] == 0x0d) { /* 復帰 */ /* とりあえずなにもしない */ } else { /* 普通の文字 */ putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1); cursor_x += 8; if (cursor_x == 8 + 240) { cursor_x = 8; cursor_y = cons_newline(cursor_y, sheet); } } } memman_free_4k(memman, (int) p, finfo[x].size); } else { /* ファイルが見つからなかった場合 */ putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15); cursor_y = cons_newline(cursor_y, sheet); } cursor_y = cons_newline(cursor_y, sheet); } else if (strcmp(cmdline, "hlt") == 0) { /* hlt.hrbアプリケーションを起動 */ for (y = 0; y < 11; y++) { s[y] = ' '; } s[0] = 'H'; s[1] = 'L'; s[2] = 'T'; s[8] = 'H'; s[9] = 'R'; s[10] = 'B'; for (x = 0; x < 224; ) { if (finfo[x].name[0] == 0x00) { break; } if ((finfo[x].type & 0x18) == 0) { for (y = 0; y < 11; y++) { if (finfo[x].name[y] != s[y]) { goto hlt_next_file; } } break; /* ファイルが見つかった */ } hlt_next_file: x++; } if (x < 224 && finfo[x].name[0] != 0x00) { /* ファイルが見つかった場合 */ p = (char *) memman_alloc_4k(memman, finfo[x].size); file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); set_segmdesc(gdt + 1003, finfo[x].size - 1, (int) p, AR_CODE32_ER); farjmp(0, 1003 * 8); memman_free_4k(memman, (int) p, finfo[x].size); } else { /* ファイルが見つからなかった場合 */ putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15); cursor_y = cons_newline(cursor_y, sheet); } cursor_y = cons_newline(cursor_y, sheet); } else if (cmdline[0] != 0) { /* コマンドではなく、さらに空行でもない */ putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); cursor_y = cons_newline(cursor_y, sheet); cursor_y = cons_newline(cursor_y, sheet); } /* プロンプト表示 */ putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">", 1); cursor_x = 16; } else { /* 一般文字 */ if (cursor_x < 240) { /* 一文字表示してから、カーソルを1つ進める */ s[0] = i - 256; s[1] = 0; cmdline[cursor_x / 8 - 2] = i - 256; putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1); cursor_x += 8; } } } /* カーソル再表示 */ if (cursor_c >= 0) { boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); } sheet_refresh(sheet, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16); } } }
void irq_test(void) { int timer_th; int event_th; struct set max; struct set avg; struct set ticks; struct set ticks0; struct set dt; int i; int ms; /* make sure IRQs are disabled */ cm3_irq_disable(STM32F_IRQ_TIM6); cm3_irq_disable(STM32F_IRQ_TIM7); cm3_irq_disable(STM32F_IRQ_TIM9); /* allocate semaphore */ printf("1.\n"); sem_timer = thinkos_sem_alloc(0); /* allocate event */ printf("2.\n"); ev_timer = thinkos_ev_alloc(); /* initialize timer 6 */ timer_init(STM32F_TIM6); /* initialize timer 7 */ timer_init(STM32F_TIM7); /* set timer 7 to very high priority */ cm3_irq_pri_set(STM32F_IRQ_TIM7, 0x20); cm3_irq_enable(STM32F_IRQ_TIM7); /* initialize timer 9 */ timer_init(STM32F_TIM9); /* set timer 9 to very low priority */ cm3_irq_pri_set(STM32F_IRQ_TIM9, 0xff); cm3_irq_enable(STM32F_IRQ_TIM9); printf("4.\n"); event_th = thinkos_thread_create(event_wait_task, NULL, stack[1], STACK_SIZE, THINKOS_OPT_PRIORITY(0) | THINKOS_OPT_ID(0)); printf("5.\n"); timer_th = thinkos_thread_create(timer_isr_task, NULL, stack[2], STACK_SIZE, THINKOS_OPT_PRIORITY(0) | THINKOS_OPT_ID(0)); thinkos_sleep(100); // printf("- All times in microseconds\n"); printf("| TIM6 IRQ Wait | TIM7 High Pri " "| TIM9 Low Pri | TIM7 > Ev Wait |\n"); printf("| dt avg max | dt avg max " "| dt avg max | dt avg max |\n"); memset(&meter, 0, sizeof(meter)); timer_start(STM32F_TIM6); timer_start(STM32F_TIM7); timer_start(STM32F_TIM9); ticks0.tim6 = 0; ticks0.tim7 = 0; ticks0.tim9 = 0; ticks0.event = 0; // for (i = 0; i < 10; i++) { for (i = 0; i < 5; i++) { for (ms = 0; ms < 1000; ms++) thinkos_sem_wait(sem_timer); /* get data */ max = meter.max; avg = meter.avg; ticks = meter.ticks; avg.tim6 = (avg.tim6 * 33) / 64; max.tim6 *= 33; avg.tim7 = (avg.tim7 * 33) / 64; max.tim7 *= 33; avg.tim9 = (avg.tim9 * 33) / 64; max.tim9 *= 33; avg.event = (avg.event * 33) / 64; max.event *= 33; dt.tim6 = ticks.tim6 - ticks0.tim6; ticks0.tim6 = ticks.tim6; dt.tim7 = ticks.tim7 - ticks0.tim7; ticks0.tim7 = ticks.tim7; dt.tim9 = ticks.tim9 - ticks0.tim9; ticks0.tim9 = ticks.tim9; dt.event = ticks.event - ticks0.event; ticks0.event = ticks.event; printf("| %4d %4d %4d | %4d %4d %4d | %4d %4d %4d | %4d %4d %4d |\n", dt.tim6, avg.tim6, max.tim6, dt.tim7, avg.tim7, max.tim7, dt.tim9, avg.tim9, max.tim9, dt.event, avg.event, max.event); } printf("\n"); cm3_irq_disable(STM32F_IRQ_TIM7); cm3_irq_disable(STM32F_IRQ_TIM9); thinkos_cancel(event_th, 0); thinkos_cancel(timer_th, 0); thinkos_ev_free(ev_timer); thinkos_sem_free(sem_timer); }
int main (int argc, char *argv[]) { errval_t err; char *cardName = NULL; const char *imagefile = IMAGEFILE; vfs_init(); err = timer_init(); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error initialising timer client library\n"); } if (argc < 3) { printf("Usage: %s <Network card Name> <vfs mount URI> [disk image path]\n", argv[0]); printf("<Network card Name> value is ignored in this version\n"); return 1; } if(argc > 3) { imagefile = argv[3]; } cardName = argv[1]; printf("vmkitmon: start\n"); printf("Ignoring the cardname [%s], and using the default one from vfs_mount\n", cardName); vfs_mkdir(VFS_MOUNTPOINT); err = vfs_mount(VFS_MOUNTPOINT, argv[2]); if (err_is_fail(err)) { printf("vmkitmon: error mounting %s: %s\n", argv[2], err_getstring(err)); return 1; } /* Initialization */ err = realmode_init(); assert_err(err, "realmode_init"); // fetch all relevant multiboot data //load_multiboot_files(); // aquire the standard input #if 1 err = terminal_want_stdin(TERMINAL_SOURCE_SERIAL); assert_err(err, "terminal_want_stdin"); #endif // load files // FIXME: use a dynamic way to specify those arguments printf("Loading file [%s]\n", GRUB_IMG_PATH); vfs_load_file_to_memory(GRUB_IMG_PATH, &grub_image, &grub_image_size); printf("Loading file [%s]\n", imagefile); vfs_load_file_to_memory(imagefile, &hdd0_image, &hdd0_image_size); printf("Done with file loading\n"); /* Guest execution */ // perform some sanity checks if (grub_image == NULL) { printf("vmkitmon: no grub image available, abort\n"); return 1; } guest = guest_create (); assert(guest != NULL); err = guest_make_runnable(guest, true); assert_err(err, "guest_make_runnable"); printf("vmkitmon: end\n"); messages_handler_loop(); }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO8 timerfifo, timerfifo2, timerfifo3; char s[40], keybuf[32], mousebuf[128], timerbuf[8], timerbuf2[8], timerbuf3[8]; struct TIMER *timer, *timer2, *timer3; int mx, my, i; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); init_pic(); io_sti(); fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); init_pit(); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); fifo8_init(&timerfifo, 8, timerbuf); timer = timer_alloc(); timer_init(timer, &timerfifo, 1); timer_settime(timer, 1000); fifo8_init(&timerfifo2, 8, timerbuf2); timer2 = timer_alloc(); timer_init(timer2, &timerfifo2, 1); timer_settime(timer2, 300); fifo8_init(&timerfifo3, 8, timerbuf3); timer3 = timer_alloc(); timer_init(timer3, &timerfifo3, 1); timer_settime(timer3, 50); init_keyboard(); enable_mouse(&mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { sprintf(s, "%010d", timerctl.count); putfonts8_asc_sht(sht_win, 40, 28, COL8_000000, COL8_C6C6C6, s, 10); io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) + fifo8_status(&timerfifo2) + fifo8_status(&timerfifo3) == 0) { io_sti(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); } } else if (fifo8_status(&timerfifo) != 0) { i = fifo8_get(&timerfifo); io_sti(); putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (fifo8_status(&timerfifo2) != 0) { i = fifo8_get(&timerfifo2); io_sti(); putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (fifo8_status(&timerfifo3) != 0) { i = fifo8_get(&timerfifo3); io_sti(); if (i != 0) { timer_init(timer3, &timerfifo3, 0); boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); } else { timer_init(timer3, &timerfifo3, 1); boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); } timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } } }
int main(void) { uint8_t i, j; struct cRGB leds[NUM_MODULES] = {{ 0 }}; /* struct cRGB my_color = { */ /* .r = 0x68, */ /* .g = 0x28, */ /* .b = 0x00 */ /* }; */ wdt_reset(); cli(); PRR = _BV(PRADC); DDRB = _BV(DO_ONEWIRE) | _BV(PB0); DDRC = _BV(DO_MCOM) | IRSEL_MASK; DDRD = MSEL_MASK | _BV(PD5) | _BV(PD7); PORTB = _BV(PB2); PORTB = 0; PORTC = 0; PORTD = _BV(PD5); // CTC, /256 divider for 640 µs tick // The transmission starts with 24 alternating edges about 630 µs apart. // Since the pulse period is closely matched to the tick period, we are // basically guaranteed at least one edge to lock onto in every tick // period, most likely two. // Since we are sending more edges than we need (12 pulses but only 8 // sensor modules total) we are also guaranteed that we can lock onto the // signal within one full cycle when not already busy for more than half of // a message time. // After that the state machine can suck in the data, ignoring any leading pulses. TCCR0A = _BV(WGM01); TCCR0B = _BV(CS02); TIMSK0 = _BV(OCIE0A); OCR0A = 0x13; // same 38 KHz timer as transmitter for timing pulses TCCR1A = _BV(WGM11); TCCR1B = _BV(WGM13) | _BV(CS10); TIMSK1 = _BV(TOIE1); ICR1 = 0x0068; OCR1A = 0x0046; // pin change interrupt on PCINT22 (PD6) to detect incoming IR data edges PCICR = _BV(PCIE2); PCMSK2 = _BV(PCINT22); timer_init(timers, 1); PORTD &= ~_BV(PD5); sei(); for (i = 0; i < NUM_MODULES; i++) { for (j = 0; j < NUM_MODULES; j++) { if (j <= i) { leds[j].r = 0xFF; } else { leds[j].r = 0x00; } } ws2812_setleds(leds, NUM_MODULES); _delay_ms(50); } _delay_ms(300); for (i = 0xFF; i > 0; i--) { for (j = 0; j < NUM_MODULES; j++) { leds[j].r = i - 1; } ws2812_setleds(leds, NUM_MODULES); _delay_ms(1); } //timer_arm(&timers[1], 1000); for (;;) { if (bit_is_set(TFLAG, TRECVTIMEOUT)) { cli(); TFLAG &= ~_BV(TRECVTIMEOUT); //aaaaaa = 0; PRR &= ~_BV(PRTIM0); set_state(STATE_WAIT); sei(); } if (do_pulse) { //uint8_t sreg = SREG; //cli(); do_pulse = 0; //msel = motor_map[trigger_sel]; //SREG = sreg; if (data_byte == 0x1B) { pulse_led(leds, NUM_MODULES, led_map[trigger_sel], 20, 255, 160); }/* else { pulse_led(leds, NUM_MODULES, ledsel, (struct cRGB*)&cc); }*/ // select corresponding motor //PORTD = (PORTD & ~MSEL_MASK) | ((msel << 2) & MSEL_MASK); //PORTC |= _BV(DO_MCOM); //_delay_ms(800); //PORTC &= ~_BV(DO_MCOM); } /* if (do_test) { do_test = 0; for (i = 0; i < 3; i++) { leds[i].r = 0; leds[i].g = 0; leds[i].b = 0xFF; } ws2812_setleds(leds, 3); _delay_ms(20); for (i = 0; i < 3; i++) { leds[i].r = 0; leds[i].g = 0; leds[i].b = 0; } ws2812_setleds(leds, 3); timer_arm(&timers[1], 1000); } */ } return 0; }
void console_task(layer_t* layer, unsigned int memtotal) { #define INPUT_BEG_POS_X (16) #define INPUT_BEG_POS_Y (28) timer_t* timer; task_t* task = task_now(); mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR; int data, fifobuf[128]; int* fat = (int*)mem_mgr_alloc_4k(memmgr, 4 * 2880); char cmdline[32]; console_t console; console.layer = layer; console.cur_x = 8; console.cur_y = INPUT_BEG_POS_Y; console.cur_c = -1; *((int*)0x0fec) = (int)&console; fifo_init(&task->fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settimer(timer, 50); file_readfat(fat, (unsigned char*)(ADR_DISKIMG + 0x000200)); /* display the prompt of console window */ console_putchar(&console, '>', 1); 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 (console.cur_c >= 0) console.cur_c = COLOR8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); if (console.cur_c >= 0) console.cur_c = COLOR8_000000; } timer_settimer(timer, 50); } if (2 == data) /* cursor ON */ console.cur_c = COLOR8_FFFFFF; if (3 == data) { /* cursor OFF */ fill_box8(layer->buf, layer->w_size, COLOR8_000000, console.cur_x, console.cur_y, console.cur_x + 7, console.cur_y + 15); console.cur_c = -1; } if (256 <= data && data <= 511) { /* keyboard data */ if ((8 + 256) == data) { /* backspace */ if (console.cur_x > INPUT_BEG_POS_X) { /* erase the cursor and move forward one character */ console_putchar(&console, ' ', 0); console.cur_x -= 8; } } else if ((10 + 256) == data) { /* Enter Key */ /* erase cursor by space */ console_putchar(&console, ' ', 0); cmdline[console.cur_x / 8 - 2] = 0; console_newline(&console); console_runcmd(&console, cmdline, fat, memtotal); /* show the prompt */ console_putchar(&console, '>', 1); } else { /* general character */ if (console.cur_x < 240) { /* display one character and move backward one character */ cmdline[console.cur_x / 8 - 2] = data - 256; console_putchar(&console, data - 256, 1); } } } /* show the cursor again */ if (console.cur_c >= 0) { fill_box8(layer->buf, layer->w_size, console.cur_c, console.cur_x, console.cur_y, console.cur_x + 7, console.cur_y + 15); } layers_refresh(layer, console.cur_x, console.cur_y, console.cur_x + 8, console.cur_y + 16); } } }
/** * Initialize the playstate * * @return GFraMe error code */ static GFraMe_ret ps_init(int isLoading) { GFraMe_ret rv; GFraMe_save sv, *pSv; int map, plX, plY, time; // Open the configurations rv = GFraMe_save_bind(&sv, CONFFILE); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error reading config file", __ret); pSv = &sv; // Read the desired fps (for update and drawing) rv = GFraMe_save_read_int(&sv, "ufps", &_maxUfps); if (rv != GFraMe_ret_ok) _maxUfps = GAME_UFPS; rv = GFraMe_save_read_int(&sv, "dfps", &_maxDfps); if (rv != GFraMe_ret_ok) _maxDfps = GAME_DFPS; rv = GFraMe_save_read_int(&sv, "speedrun", &_ps_isSpeedrun); if (rv != GFraMe_ret_ok) _ps_isSpeedrun = 0; GFraMe_save_close(&sv); pSv = 0; if (!isLoading) { gv_init(); plX = 16; plY = 184; map = 0; } else { rv = gv_load(SAVEFILE); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to load state", __ret); plX = gv_getValue(DOOR_X) * 8; plY = gv_getValue(DOOR_Y) * 8; map = gv_getValue(MAP); } time = gv_getValue(GAME_TIME); timer_init(time); if (map >= 20) { audio_playBoss(); } else if (map >= 15) { audio_playTensionGoesUp(); } else if (map >= 4) { audio_playMovingOn(); } else { audio_playIntro(); } rv = ui_init(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to init ui", __ret); rv = rg_init(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to registry ui", __ret); rv = map_init(&m); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to init map", __ret); rv = player_init(&p1, ID_PL1, 224, plX, plY); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to init player", __ret); rv = player_init(&p2, ID_PL2, 240, plX, plY); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to init player", __ret); rv = map_loadi(m, map); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to init map", __ret); signal_init(); _timerTilCredits = 0; _ps_onOptions = 0; _ps_text = 0; switchState = 0; transition_initFadeOut(); #ifdef DEBUG _updCalls = 0; _drwCalls = 0; _time = 0; _ltime = 0; #endif rv = GFraMe_ret_ok; __ret: if (pSv) GFraMe_save_close(pSv); return rv; }
int main() { lua_State *lua = luaL_newstate(); luaL_openlibs(lua); motor_Config config; l_motor_register(lua); l_audio_register(lua); l_graphics_register(lua); l_image_register(lua); l_keyboard_register(lua); l_mouse_register(lua); l_filesystem_register(lua); l_timer_register(lua); l_math_register(lua); l_event_register(lua); l_joystick_register(lua); chdir("/love"); l_boot(lua, &config); if(config.identity) { filesystem_setIdentity(config.identity, false); } image_init(); joystick_init(); keyboard_init(); graphics_init(config.window.width, config.window.height); audio_init(); math_init(); if(luaL_dofile(lua, "main.lua")) { printf("Error: %s\n", lua_tostring(lua, -1)); } lua_pushcfunction(lua, errorhandler); lua_getglobal(lua, "love"); lua_pushstring(lua, "load"); lua_rawget(lua, -2); /*if(lua_pcall(lua, 0, 0, 1)) { printf("Error in love.load: %s\n", lua_tostring(lua, -1)); } */ pcall(lua, 0); lua_pop(lua, 1); lua_pushcfunction(lua, errorhandler); mainLoopData.luaState = lua; mainLoopData.errhand = luaL_ref(lua, LUA_REGISTRYINDEX); timer_init(); #ifdef EMSCRIPTEN emscripten_set_main_loop_arg(main_loop, &mainLoopData, 0, 1); #else for(;;) { main_loop(&mainLoopData); } #endif }
int main(int argc, int *argv[]) { bool quit = false; /* quit flag */ int i, j; int play_stat = 0; Timer fps; /* cap frame rate */ SDL_Event event; SDL_Surface *mouseother; SDL_Surface *wintitle[3]; SDL_Surface *screen; /* main screen */ SDL_Surface *chessboard; /* chess board */ Button pieces[CHESSBOARD_ROW][CHESSBOARD_COLUMN] = {{0}}; SDL_Surface *piece_stat_img[PIECE_STAT + 1] = {NULL}; /* pieces image */ int mouse_map[CHESSBOARD_ROW][CHESSBOARD_COLUMN] = {{0}}; /* click or not */ int pieces_map[CHESSBOARD_ROW][CHESSBOARD_COLUMN] = {{0}}; /* pieces state */ /* Init SDL lib*/ if(SDL_Init(SDL_INIT_EVERYTHING) == -1){ return 1; } /* Init screen */ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); if(screen == NULL){ return 1; } SDL_WM_SetCaption("XO_OX", NULL); /* Load resource */ piece_stat_img[1] = load_image("xooxres/chess1.png"); piece_stat_img[2] = load_image("xooxres/chess2.png"); piece_stat_img[3] = piece_stat_img[1]; /* for special show, but no time to do */ piece_stat_img[4] = piece_stat_img[2]; /* for special show, but no time to do */ chessboard = load_image("xooxres/chessboard.png"); mouseother = load_image("xooxres/mouseother.png"); wintitle[0] = load_image("xooxres/wintitle1.png"); wintitle[1] = load_image("xooxres/wintitle2.png"); wintitle[2] = load_image("xooxres/wintitle3.png"); /* Init timer */ timer_init(&fps); /* Init button */ for(i = 0; i < CHESSBOARD_ROW; i++){ for(j = 0; j < CHESSBOARD_COLUMN; j++){ button_init(&pieces[i][j], SUBBOARD_WIDTH * i, SUBBOARD_HEIGHT * j, SUBBOARD_WIDTH , SUBBOARD_HEIGHT ); button_set_stat_img(&pieces[i][j], BUTTON_MOUSEOVER, NULL); button_set_stat_img(&pieces[i][j], BUTTON_MOUSEOUT, mouseother); button_set_stat_img(&pieces[i][j], BUTTON_MOUSEUP, mouseother); button_set_stat_img(&pieces[i][j], BUTTON_MOUSEDOWN, mouseother); } } /* Main loop */ while(quit == false){ /* timer start */ timer_start(&fps); while(SDL_PollEvent(&event)){ /* Pieces input handle */ pieces_handle_event(pieces, mouse_map, &event); /* User quit */ if(event.type == SDL_QUIT){ quit = true; } } /* logic function */ play_stat = mouse_to_piece_map(mouse_map, pieces_map); /* show chessboard */ subchessboard_show(piece_stat_img[get_leader()], mouseother, mouse_map, screen); /* show pieces */ pieces_show(piece_stat_img, pieces_map, screen); /* */ if(play_stat != 0){ printf("play_stat = %d\n", play_stat); apply_surface((SCREEN_WIDTH - wintitle[play_stat - 1]->w) / 2, (SCREEN_HEIGHT - wintitle[play_stat - 1]->h) / 2, wintitle[play_stat - 1], screen); } /* Update screen */ if(SDL_Flip(screen) == -1){ return 1; } if(play_stat != 0){ SDL_Delay(3000); quit = true; } /* cap frame rate */ if(timer_get_ticks(&fps) < 1000 / FRAME_PER_SECOND){ SDL_Delay((1000 / FRAME_PER_SECOND) - timer_get_ticks(&fps)); } } /* Free resource */ SDL_FreeSurface(chessboard); SDL_FreeSurface(mouseother); for(i = 0; i < 2; i++){ SDL_FreeSurface(piece_stat_img[i]); } for(i = 0; i < 3; i++){ SDL_FreeSurface(wintitle[i]); } SDL_Quit(); return 0; }
void console_task(struct SHEET *sheet, unsigned int memtotal) { struct TIMER *timer; struct TASK *task = task_now(); int i, fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1; char s[30], cmdline[30]; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; int x, y; fifo32_init(&task->fifo, 128, fifobuf, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settime(timer, 50); /* プロンプト表示 */ putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1); for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&task->fifo); io_sti(); if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &task->fifo, 0); /* 次は0を */ if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } else { timer_init(timer, &task->fifo, 1); /* 次は1を */ if (cursor_c >= 0) { cursor_c = COL8_000000; } } timer_settime(timer, 50); } if (i == 2) { /* カーソルON */ cursor_c = COL8_FFFFFF; } if (i == 3) { /* カーソルOFF */ boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); cursor_c = -1; } if (256 <= i && i <= 511) { /* キーボードデータ(タスクA経由) */ if (i == 8 + 256) { /* バックスペース */ if (cursor_x > 16) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); cursor_x -= 8; } } else if (i == 10 + 256) { /* Enter */ /* カーソルをスペースで消してから改行する */ putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1); cmdline[cursor_x / 8 - 2] = 0; cursor_y = cons_newline(cursor_y, sheet); /* コマンド実行 */ if (strcmp(cmdline, "mem") == 0) { /* memコマンド */ sprintf(s, "total %dMB", memtotal / (1024 * 1024)); putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); cursor_y = cons_newline(cursor_y, sheet); sprintf(s, "free %dKB", memman_total(memman) / 1024); putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30); cursor_y = cons_newline(cursor_y, sheet); cursor_y = cons_newline(cursor_y, sheet); } else if (strcmp(cmdline, "cls") == 0) { /* clsコマンド */ for (y = 28; y < 28 + 128; y++) { for (x = 8; x < 8 + 240; x++) { sheet->buf[x + y * sheet->bxsize] = COL8_000000; } } sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128); cursor_y = 28; } else if (cmdline[0] != 0) { /* コマンドではなく、さらに空行でもない */ putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); cursor_y = cons_newline(cursor_y, sheet); cursor_y = cons_newline(cursor_y, sheet); } /* プロンプト表示 */ putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">", 1); cursor_x = 16; } else { /* 一般文字 */ if (cursor_x < 240) { /* 一文字表示してから、カーソルを1つ進める */ s[0] = i - 256; s[1] = 0; cmdline[cursor_x / 8 - 2] = i - 256; putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1); cursor_x += 8; } } } /* カーソル再表示 */ if (cursor_c >= 0) { boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); } sheet_refresh(sheet, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16); } } }
void uos_init (void) { debug_puts ("\nTesting timer.\n"); timer_init (&timer, KHZ, 10); task_create (hello, "Timer", "hello", 1, task, sizeof (task)); }
void console_task(struct SHEET *sheet, unsigned int memtotal) { struct TIMER *timer; struct TASK *task = task_now(); struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; int i, fifobuf[128], *fat = (int *) memman_alloc_4k(memman, 4 * 2880); struct CONSOLE cons; char cmdline[30]; cons.sht = sheet; cons.cur_x = 8; cons.cur_y = 28; cons.cur_c = -1; *((int *) 0x0fec) = (int) &cons; fifo32_init(&task->fifo, 128, fifobuf, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settime(timer, 50); file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); /* プロンプト表示 */ cons_putchar(&cons, '>', 1); for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&task->fifo); io_sti(); if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &task->fifo, 0); /* 次は0を */ if (cons.cur_c >= 0) { cons.cur_c = COL8_FFFFFF; } } else { timer_init(timer, &task->fifo, 1); /* 次は1を */ if (cons.cur_c >= 0) { cons.cur_c = COL8_000000; } } timer_settime(timer, 50); } if (i == 2) { /* カーソルON */ cons.cur_c = COL8_FFFFFF; } if (i == 3) { /* カーソルOFF */ boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15); cons.cur_c = -1; } if (256 <= i && i <= 511) { /* キーボードデータ(タスクA経由) */ if (i == 8 + 256) { /* バックスペース */ if (cons.cur_x > 16) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ cons_putchar(&cons, ' ', 0); cons.cur_x -= 8; } } else if (i == 10 + 256) { /* Enter */ /* カーソルをスペースで消してから改行する */ cons_putchar(&cons, ' ', 0); cmdline[cons.cur_x / 8 - 2] = 0; cons_newline(&cons); cons_runcmd(cmdline, &cons, fat, memtotal); /* コマンド実行 */ /* プロンプト表示 */ cons_putchar(&cons, '>', 1); } else { /* 一般文字 */ if (cons.cur_x < 240) { /* 一文字表示してから、カーソルを1つ進める */ cmdline[cons.cur_x / 8 - 2] = i - 256; cons_putchar(&cons, i - 256, 1); } } } /* カーソル再表示 */ if (cons.cur_c >= 0) { boxfill8(sheet->buf, sheet->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15); } sheet_refresh(sheet, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16); } } }
int main(void) { unsigned cmd; char c; p_arc_pwr_op = &arc_pwr_op; timer_init(); arc_pwr_register((struct arc_pwr_op *)p_arc_pwr_op);//init arc_pwr_op arc_param->serial_disable=0; serial_put_hex(readl(P_AO_RTI_STATUS_REG1),32); writel(0,P_AO_RTI_STATUS_REG1); f_serial_puts("sleep .......\n"); arc_param->serial_disable=0; while(1){ cmd = readl(P_AO_RTI_STATUS_REG0); if(cmd == 0) { delay_ms(10); continue; } c = (char)cmd; if(c == 't') { init_I2C(); // copy_reboot_code(); #ifdef CONFIG_MESON_TRUSTZONE copy_reboot_code_temp(temp_arm_base, sizeof(temp_arm_base)); #endif enter_power_down(); //test_arc_core(); break; } else if(c == 'q') { f_serial_puts(" - quit command loop\n"); writel(0,P_AO_RTI_STATUS_REG0); break; } else { f_serial_puts(" - cmd no support (ARC)\n"); } //command executed writel(0,P_AO_RTI_STATUS_REG0); } // asm("SLEEP"); while(1){ // udelay__(600); cmd = readl(P_AO_RTI_STATUS_REG1); c = (char)cmd; // f_serial_puts("REG2="); // serial_put_hex(readl(P_AO_RTI_STATUS_REG2),32); if(c == 0) { udelay__(6000); cmd = readl(P_AO_RTI_STATUS_REG1); c = (char)cmd; if((c == 0)||(c!='r')) { #ifdef _UART_DEBUG_COMMUNICATION_ serial_put_hex(cmd,32); f_serial_puts(" arm boot fail\n\n"); wait_uart_empty(); #endif #if 0 //power down cmd = readl(P_AO_GPIO_O_EN_N); cmd &= ~(1<<6); cmd &= ~(1<<22); writel(cmd,P_AO_GPIO_O_EN_N); #endif } } else if ( cmd == 1 ) { serial_put_hex(cmd,32); f_serial_puts(" ARM has started running\n"); wait_uart_empty(); } else if ( cmd == 2 ) { serial_put_hex(cmd,32); f_serial_puts(" Reenable SEC\n"); wait_uart_empty(); } else if(c=='r') { f_serial_puts("arm boot succ\n"); wait_uart_empty(); asm(".long 0x003f236f"); //add sync instruction. asm("flag 1"); asm("nop"); asm("nop"); asm("nop"); } else { #ifdef _UART_DEBUG_COMMUNICATION_ serial_put_hex(cmd,32); f_serial_puts(" arm unkonw state\n"); wait_uart_empty(); #endif } //cmd='f'; //writel(cmd,P_AO_RTI_STATUS_REG1); } return 0; }
void hw_init(void) { /* Disable watchdog */ at91_disable_wdt(); /* At this stage the main oscillator is supposed * to be enabled PCK = MCK = MOSC */ /* Configure PLLA = MOSC * (PLL_MULA + 1) / PLL_DIVA */ pmc_cfg_plla(PLLA_SETTINGS, PLL_LOCK_TIMEOUT); /* Initialize PLLA charge pump */ /* not needed for SAMA5D4 */ pmc_init_pll(0); /* Switch MCK on PLLA output */ pmc_cfg_mck(BOARD_PRESCALER_PLLA, PLL_LOCK_TIMEOUT); /* Setup AHB 32-bit Matrix Divisor */ pmc_cfg_h32mxdiv(BOARD_H32MX, PLL_LOCK_TIMEOUT); /* Enable External Reset */ writel(AT91C_RSTC_KEY_UNLOCK | AT91C_RSTC_URSTEN, AT91C_BASE_RSTC + RSTC_RMR); #if defined(CONFIG_ENTER_NWD) cpacr_init(); /* Program the DACR to allow client access to *all* domains */ dacr_swd_init(); #endif #if defined(CONFIG_MATRIX) /* Initialize the matrix */ matrix_init(); #endif /* initialize the dbgu */ initialize_dbgu(); /* Redirect all interrupts to non-secure AIC */ redirect_interrupts_to_aic(); #if defined(CONFIG_MATRIX) matrix_read_slave_security(); matrix_read_periperal_security(); #endif /* Init timer */ timer_init(); #ifdef CONFIG_DDR2 /* Initialize MPDDR Controller */ ddramc_init(); #endif /* load one wire information */ one_wire_hw_init(); /* Reset HDMI SiI9022 */ SiI9022_hw_reset(); /* Disable software modem device's clock */ at91_disable_smd_clock(); #ifdef CONFIG_TWI twi_init(); #endif #ifdef CONFIG_ACT8865 /* Set ACT8865 REG power saving mode */ act8865_set_power_saving_mode(); /* Set ACT8865 output voltage */ sama5d4ek_act8865_set_reg_voltage(); /* Dsiable ACT8865 I2C interface */ if (act8865_workaround_disable_i2c()) while (1) ; #endif #ifdef CONFIG_PM_EXTERNAL_DEVICES #ifdef CONFIG_HDMI SiI9022_enter_power_state_D3_Cold(); #endif #ifdef CONFIG_WM8904 wm8904_enter_low_power(); #endif #ifdef CONFIG_MACB /* Make PHYs to power down mode */ phys_enter_power_down(); #endif #endif /* #ifdef CONFIG_PM_EXTERNAL_DEVICES */ #ifdef CONFIG_USER_HW_INIT hw_init_hook(); #endif }
int main(int argc, char **argv) { static char *ifname = NULL; /* Name of interface to attach to */ fd_set rfds, readers; int n, nfds = 0, i; int daemonize = 0; struct timeval *timeout; struct timespec timeout_spec; struct sigaction sigact; sigset_t mask, origmask; /* Remember the name of the executable... */ progname = strrchr(argv[0], '/'); if (progname) progname++; else progname = argv[0]; /* Use debug output as default */ debug = 1; memset (&sigact, 0, sizeof(struct sigaction)); sigact.sa_handler = signal_handler; /* This server should shut down on these signals. */ sigaction(SIGTERM, &sigact, 0); sigaction(SIGHUP, &sigact, 0); sigaction(SIGINT, &sigact, 0); sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGHUP); sigaddset(&mask, SIGINT); /* Only capture segmentation faults when we are not debugging... */ #ifndef DEBUG sigaddset(&mask, SIGSEGV); #endif /* Block the signals we are watching here so that we can * handle them in pselect instead. */ sigprocmask(SIG_BLOCK, &mask, &origmask); /* Parse command line: */ while (1) { int opt; opt = getopt_long(argc, argv, "i:fjln:dghoq:r:s:c:uwxDLRV", longopts, 0); if (opt == EOF) break; switch (opt) { case 0: break; case 'd': debug = 0; daemonize = 1; break; case 'f': llfeedback = 1; active_route_timeout = ACTIVE_ROUTE_TIMEOUT_LLF; break; case 'g': rreq_gratuitous = !rreq_gratuitous; break; case 'i': ifname = optarg; break; case 'j': hello_jittering = !hello_jittering; break; case 'l': log_to_file = !log_to_file; break; case 'n': if (optarg && isdigit(*optarg)) { receive_n_hellos = atoi(optarg); if (receive_n_hellos < 2) { fprintf(stderr, "-n should be at least 2!\n"); exit(-1); } } break; case 'o': optimized_hellos = !optimized_hellos; break; case 'q': if (optarg && isdigit(*optarg)) qual_threshold = atoi(optarg); break; case 'r': if (optarg && isdigit(*optarg)) rt_log_interval = atof(optarg) * 1000; break; case 's': if (optarg && isdigit(*optarg)) inet_aton(optarg, &server_addr); break; case 'c': if (optarg && isdigit(*optarg)) { node_discovery_mode = !node_discovery_mode; discovery_internal = atof(optarg) * 1000 * 60; } break; case 'u': unidir_hack = !unidir_hack; break; case 'w': internet_gw_mode = !internet_gw_mode; break; case 'x': expanding_ring_search = !expanding_ring_search; break; case 'L': local_repair = !local_repair; break; case 'D': wait_on_reboot = !wait_on_reboot; break; case 'R': ratelimit = !ratelimit; break; case 'V': printf ("\nAODV-UU v%s, %s © Uppsala University & Ericsson AB.\nAuthor: Erik Nordström, <*****@*****.**>\n\n", AODV_UU_VERSION, DRAFT_VERSION); exit(0); break; case '?': case ':': exit(0); default: usage(0); } } /* Check that we are running as root */ if (geteuid() != 0) { fprintf(stderr, "must be root\n"); exit(1); } /* Detach from terminal */ if (daemonize) { if (fork() != 0) exit(0); /* Close stdin, stdout and stderr... */ /* close(0); */ close(1); close(2); setsid(); } /* Make sure we cleanup at exit... */ atexit((void *) &cleanup); /* Initialize data structures and services... */ rt_table_init(); log_init(); /* packet_queue_init(); */ host_init(ifname); /* packet_input_init(); */ nl_init(); nl_send_conf_msg(); aodv_socket_init(); #ifdef LLFEEDBACK if (llfeedback) { llf_init(); } #endif /* Set sockets to watch... */ FD_ZERO(&readers); for (i = 0; i < nr_callbacks; i++) { FD_SET(callbacks[i].fd, &readers); if (callbacks[i].fd >= nfds) nfds = callbacks[i].fd + 1; } /* Set the wait on reboot timer... */ if (wait_on_reboot) { timer_init(&worb_timer, wait_on_reboot_timeout, &wait_on_reboot); timer_set_timeout(&worb_timer, DELETE_PERIOD); alog(LOG_NOTICE, 0, __FUNCTION__, "In wait on reboot for %d milliseconds. Disable with \"-D\".", DELETE_PERIOD); } if(node_discovery_mode && internet_gw_mode) { timer_init(&discovery_timer, node_discovery_timeout, NULL); timer_set_timeout(&discovery_timer, discovery_internal); DEBUG(LOG_DEBUG, 0, "This is gateway and set with node discovery\n"); } /* Schedule the first Hello */ if (!optimized_hellos && !llfeedback) hello_start(); if (rt_log_interval) log_rt_table_init(); while (1) { memcpy((char *) &rfds, (char *) &readers, sizeof(rfds)); timeout = timer_age_queue(); timeout_spec.tv_sec = timeout->tv_sec; timeout_spec.tv_nsec = timeout->tv_usec * 1000; if ((n = pselect(nfds, &rfds, NULL, NULL, &timeout_spec, &origmask)) < 0) { if (errno != EINTR) alog(LOG_WARNING, errno, __FUNCTION__, "Failed select (main loop)"); continue; } if (n > 0) { for (i = 0; i < nr_callbacks; i++) { if (FD_ISSET(callbacks[i].fd, &rfds)) { /* We don't want any timer SIGALRM's while executing the callback functions, therefore we block the timer... */ (*callbacks[i].func) (callbacks[i].fd); } } } } /* Main loop */ return 0; }