/* Initializes the controller */ void controller_init( void ) { /* initialize variables */ flag_check_delay = 0; flag_new_request = 0; /* clear data structures */ memset( &javiator_data, 0, sizeof( javiator_data ) ); /* initialize hardware */ ports_init( ); wdog_init( ); //adc_init( ); parallel_init( ); bmu09a_init( ); lsm215_init( ); //minia_init( ); leds_init( ); /* register watchdog event and start timer */ wdog_register_flag( (uint8_t *) &flag_check_delay, NOTIFY_PERIOD ); wdog_start( ); #if 0 /* register ADC channels */ adc_add_channel( ADC_CH_SONAR ); adc_add_channel( ADC_CH_BATT ); #endif /* set Robostix signal LEDs */ LED_ON( RED ); LED_ON( BLUE ); LED_ON( YELLOW ); /* enable interrupts */ sei( ); }
void pc_basic_device_init(qemu_irq *isa_irq, FDCtrl **floppy_controller, ISADevice **rtc_state) { int i; DriveInfo *fd[MAX_FD]; PITState *pit; qemu_irq rtc_irq = NULL; qemu_irq *a20_line; ISADevice *i8042; qemu_irq *cpu_exit_irq; register_ioport_write(0x80, 1, 1, ioport80_write, NULL); register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL); if (!no_hpet) { DeviceState *hpet = sysbus_create_simple("hpet", HPET_BASE, NULL); for (i = 0; i < 24; i++) { sysbus_connect_irq(sysbus_from_qdev(hpet), i, isa_irq[i]); } rtc_irq = qdev_get_gpio_in(hpet, 0); } *rtc_state = rtc_init(2000, rtc_irq); qemu_register_boot_set(pc_boot_set, *rtc_state); pit = pit_init(0x40, isa_reserve_irq(0)); pcspk_init(pit); for(i = 0; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { serial_isa_init(i, serial_hds[i]); } } for(i = 0; i < MAX_PARALLEL_PORTS; i++) { if (parallel_hds[i]) { parallel_init(i, parallel_hds[i]); } } a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 1); i8042 = isa_create_simple("i8042"); i8042_setup_a20_line(i8042, a20_line); vmmouse_init(i8042); cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1); DMA_init(0, cpu_exit_irq); for(i = 0; i < MAX_FD; i++) { fd[i] = drive_get(IF_FLOPPY, 0, i); } *floppy_controller = fdctrl_init_isa(fd); }
void parallel_hds_isa_init(ISABus *bus, int n) { int i; assert(n <= MAX_PARALLEL_PORTS); for (i = 0; i < n; i++) { if (parallel_hds[i]) { parallel_init(bus, i, parallel_hds[i]); } } }
int main(void){ /* Initialize parallel interface to rocket controller */ /* This needs to be done early to avoid drawing excessive current through the internal protection zeners, due to the 100k pullups to 5V */ parallel_init(); /* Allow voltages to stabilize in addition to warm-up time */ _delay_ms(500); /* Initialize thermocouple interface library */ max31855_init(&SPI_CS_PORT,&SPI_CS_DDR,(_BV(SPI_CS1) | _BV(SPI_CS2))); /* The following will be executed indefinitely */ while(1){ /* Acquire one sample from each sensor IC */ uint32_t result_tc_1 = max31855_get(&SPI_CS_PORT,_BV(SPI_CS1)); uint32_t result_tc_2 = max31855_get(&SPI_CS_PORT,_BV(SPI_CS2)); /* 42 42 are sync words for transmitted data */ uint8_t byteArray[] = { 0x42, 0x42, result_tc_1 >> 24, result_tc_1 >> 16, result_tc_1 >> 8, result_tc_1, result_tc_2 >> 24, result_tc_2 >> 16, result_tc_2 >> 8, result_tc_2 }; /* This function writes a given number of bytes to the rocket controller */ parallel_puts(byteArray,10); } }
void test_sample_primary_rays(bool use_gpu) { // Let's have a perspective camera with 1x1 pixel, // with identity to world matrix, // fov 45 degree auto pos = Vector3f{0, 0, 0}; auto look = Vector3f{0, 0, 1}; auto up = Vector3f{0, 1, 0}; Matrix3x3f n2c = Matrix3x3f::identity(); Matrix3x3f c2n = Matrix3x3f::identity(); Camera camera{1, 1, &pos[0], &look[0], &up[0], &n2c.data[0][0], &c2n.data[0][0], 1e-2f, false}; parallel_init(); // Sample from the center of pixel Buffer<CameraSample> samples(use_gpu, 1); samples[0].xy = Vector2{0.5f, 0.5f}; Buffer<Ray> rays(use_gpu, 1); Buffer<RayDifferential> ray_differentials(use_gpu, 1); sample_primary_rays(camera, samples.view(0, 1), rays.view(0, 1), ray_differentials.view(0, 1), use_gpu); cuda_synchronize(); equal_or_error<Real>(__FILE__, __LINE__, rays[0].org, Vector3{0, 0, 0}); equal_or_error<Real>(__FILE__, __LINE__, rays[0].dir, Vector3{0, 0, 1}); // TODO: test ray differentials parallel_cleanup(); }
static void sun4uv_init(MemoryRegion *address_space_mem, ram_addr_t RAM_size, const char *boot_devices, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model, const struct hwdef *hwdef) { SPARCCPU *cpu; M48t59State *nvram; unsigned int i; uint64_t initrd_addr, initrd_size, kernel_addr, kernel_size, kernel_entry; PCIBus *pci_bus, *pci_bus2, *pci_bus3; ISABus *isa_bus; qemu_irq *ivec_irqs, *pbm_irqs; DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; DriveInfo *fd[MAX_FD]; void *fw_cfg; /* init CPUs */ cpu = cpu_devinit(cpu_model, hwdef); /* set up devices */ ram_init(0, RAM_size); prom_init(hwdef->prom_addr, bios_name); ivec_irqs = qemu_allocate_irqs(cpu_set_ivec_irq, cpu, IVEC_MAX); pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, ivec_irqs, &pci_bus2, &pci_bus3, &pbm_irqs); pci_vga_init(pci_bus); // XXX Should be pci_bus3 isa_bus = pci_ebus_init(pci_bus, -1, pbm_irqs); i = 0; if (hwdef->console_serial_base) { serial_mm_init(address_space_mem, hwdef->console_serial_base, 0, NULL, 115200, serial_hds[i], DEVICE_BIG_ENDIAN); i++; } for(; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { serial_isa_init(isa_bus, i, serial_hds[i]); } } for(i = 0; i < MAX_PARALLEL_PORTS; i++) { if (parallel_hds[i]) { parallel_init(isa_bus, i, parallel_hds[i]); } } for(i = 0; i < nb_nics; i++) pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL); ide_drive_get(hd, MAX_IDE_BUS); pci_cmd646_ide_init(pci_bus, hd, 1); isa_create_simple(isa_bus, "i8042"); for(i = 0; i < MAX_FD; i++) { fd[i] = drive_get(IF_FLOPPY, 0, i); } fdctrl_init_isa(isa_bus, fd); nvram = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59); initrd_size = 0; initrd_addr = 0; kernel_size = sun4u_load_kernel(kernel_filename, initrd_filename, ram_size, &initrd_size, &initrd_addr, &kernel_addr, &kernel_entry); sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices, kernel_addr, kernel_size, kernel_cmdline, initrd_addr, initrd_size, /* XXX: need an option to load a NVRAM image */ 0, graphic_width, graphic_height, graphic_depth, (uint8_t *)&nd_table[0].macaddr); fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0); fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry); fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); if (kernel_cmdline) { fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline) + 1); fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); } else { fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0); } fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]); fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width); fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height); fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth); qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); }
int main(int argc, char **argv) { char bootfile_buf[MAX_PATH_LEN]; char * initfile = (char *) 0; char * eclipsedir = (char *) 0; int c, new_argc; pword goal, module; int err; int init_flags = INIT_SHARED|INIT_PRIVATE|INIT_ENGINE|INIT_PROCESS; unsigned startup_delay = 0; int vm_options = 0; char * session, * nsrv_hostname; unsigned nsrv_port_number; #ifdef PROFILE moncontrol(0); /* disable profiling by default */ #endif /* * collect information from the command line * remove some internally used arguments from the command line */ for (c = new_argc = 1; c < argc; ) { if (argv[c][0] == '-' && argv[c][2] == 0) /* single char opt */ { switch (argv[c][1]) { case 'a': /* -a <worker> <session> <nsrv_hostname> <nsrv_port_no> */ if (++c + 4 > argc) usage(argv[c-1]); ec_options.parallel_worker = atoi(argv[c++]); session = argv[c++]; nsrv_hostname = argv[c++]; nsrv_port_number = atoi(argv[c++]); break; case 'c': /* -c <shared_map_file> */ if (++c + 1 > argc) usage(argv[c-1]); ec_options.mapfile = argv[c++]; ec_options.allocation = ALLOC_FIXED; init_flags &= ~INIT_SHARED; break; case 'm': /* -m <shared_map_file> */ if (++c + 1 > argc) usage(argv[c-1]); ec_options.mapfile = argv[c++]; ec_options.allocation = ALLOC_FIXED; break; case 'b': /* -b <bootfile> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c++]; /* shift */ break; case 'e': /* -e <goal> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c++]; /* shift */ break; case 'g': /* -g <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.globalsize = sizearg(argv[c++]); if (ec_options.globalsize < MIN_GLOBAL) { ec_bad_exit("ECLiPSe: Global stack size out of range."); } break; case 'd': /* -d <n> */ /* delay worker startup by <n> seconds */ if (++c + 1 > argc) usage(argv[c-1]); startup_delay = atoi(argv[c++]); if (startup_delay == 0) ec_options.io_option = OWN_IO; /* every worker has its own i/o */ else sleep(startup_delay); break; case 'D': /* -D <eclipsedir> */ if (++c + 1 > argc) usage(argv[c-1]); eclipsedir = argv[c++]; break; case 'l': /* -l <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.localsize = sizearg(argv[c++]); if (ec_options.localsize < MIN_LOCAL) { ec_bad_exit("ECLiPSe: local stack size out of range."); } break; case 'h': /* -h <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.privatesize = sizearg(argv[c++]); if (ec_options.privatesize < MIN_PRIVATE) { ec_bad_exit("ECLiPSe: Private heap size out of range."); } break; case 's': /* -s <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.sharedsize = sizearg(argv[c++]); if (ec_options.sharedsize < MIN_SHARED) { ec_bad_exit("ECLiPSe: Shared heap size out of range."); } break; case 'o': /* enable oracles */ c += 1; vm_options = ORACLES_ENABLED; break; case 'p': argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-2]); argv[new_argc++] = argv[c]; /* shift */ ec_options.option_p = atoi(argv[c++]); break; case '-': /* -- give the rest to Prolog */ for (; c < argc;) argv[new_argc++] = argv[c++]; break; default: /* unknown: error */ usage(argv[c]); break; } } else if (!strcmp(argv[c], "-debug_level")) { if (++c + 1 > argc) usage(argv[c-1]); ec_options.debug_level = atoi(argv[c++]); } else if (!strcmp(argv[c], "-layout")) { int lflags = 0; char *from = 0; char *to = 0; long increment = 0L; if (++c + 1 <= argc) lflags = (int) strtol(argv[c++], (char **) 0, 16); if (c + 1 <= argc) increment = strtol(argv[c++], (char **) 0, 16); if (c + 1 <= argc) from = (char *) strtol(argv[c++], (char **) 0, 16); if (c + 1 <= argc) to = (char *) strtol(argv[c++], (char **) 0, 16); if (ec_options.allocation == ALLOC_FIXED) mem_layout(); #ifdef HAVE_MMAP ec_layout(lflags, from, to, increment); #else ec_bad_exit("ECLiPSe: The -layout scan is not supported without\nmemory mapping."); #endif } else if (!strcmp(argv[c], "-norl")) { argv[new_argc++] = argv[c++]; /* shift */ ec_options.rl = 0; } else /* raise error unless preceeded by a -- option */ { usage(argv[c]); } } /*---------------------------------------------------------------- * Initialize private heap as early as possible * (must be before setup_mps()) *----------------------------------------------------------------*/ malloc_init(); irq_lock_init(delayed_break); /*---------------------------------------------------------------- * Init message passing system *----------------------------------------------------------------*/ if (ec_options.parallel_worker) { setup_mps(ec_options.parallel_worker, session, nsrv_hostname, nsrv_port_number, init_flags & INIT_SHARED); } /*---------------------------------------------------------------- * Make the connection to the shared heap, if any. * Because of mmap problems on some machines this should * happen AFTER initializing the message passing system. *----------------------------------------------------------------*/ mem_init(init_flags); /* depends on -c and -m options */ /*---------------------------------------------------------------- * Init parallel scheduler etc. *----------------------------------------------------------------*/ if (ec_options.parallel_worker) { parallel_init(init_flags); } /*---------------------------------------------------------------- * Init the low-level I/O stuff, ie the part which should * really not be done by eclipse itself... *----------------------------------------------------------------*/ /* char_io_init(); does not yet exist */ /*---------------------------------------------------------------- * Entry point after longjmp(reset) *----------------------------------------------------------------*/ switch (setjmp(reset)) { case 0: /* raw boot or -r from above */ break; case 3: /* restore program state */ case 2: init_flags = REINIT_SHARED|INIT_ENGINE|INIT_PRIVATE; break; case 4: /* restore execution state */ init_flags = REINIT_SHARED|INIT_PRIVATE; break; case 1: /* reset after fatal error */ default: if (!(GlobalFlags & HEAP_READY) || ec_options.parallel_worker) { (void) ec_cleanup(); exit(-1); } init_flags = INIT_ENGINE; switch (memory_corrupted++) { case 0: break; case 1: /* try to print a message */ memory_corrupted = 2; ec_bad_exit("ECLiPSe: Fatal error, memory corrupted."); /* fall to */ case 2: /* we couldn't even print the message */ exit(-1); } break; } /* * set up our own panic function which longjumps back to reset * To access command line through global variabes */ ec_options.user_panic = main_panic; ec_options.Argc = new_argc; ec_options.Argv = argv; ec_options.eclipse_home = (char *) 0; ec_options.init_flags = init_flags; if (eclipsedir) ec_options.eclipse_home = eclipsedir; /* * Init the global (shared) eclipse structures, dictionary, code... * Maybe load a saved state. * Note that we don't have an engine yet! */ eclipse_global_init(init_flags); /*---------------------------------------------------------------- * Setup the Prolog engine *----------------------------------------------------------------*/ /* * If we have a PROG_AND_DATA saved state (execution state saved) * we are finished and enter the emulator. */ if (!(init_flags & INIT_ENGINE)) { err = restart_emulc(); (void) ec_cleanup(); exit(err); } /* * Initialize the Prolog engine */ emu_init(init_flags, vm_options); /* * If we are not running an already booted eclipse, * compile $ECLIPSEDIR/lib/kernel.eco */ if (init_flags & INIT_SHARED) { char msg[1024]; initfile = strcat(strcpy(bootfile_buf, ec_eclipse_home), "/lib/kernel.eco"); if (ec_access(initfile, R_OK) < 0) { sprintf(msg, "ECLiPSe: Can't find boot file %s!\nPlease check the setting of your ECLIPSEDIR environment variable\nor use the -D <dir> command line option.", initfile); ec_bad_exit(msg); } err = eclipse_boot(initfile); if (err != PSUCCEED) { (void) ec_cleanup(); exit(err); } } if (init_flags & (INIT_SHARED|REINIT_SHARED)) GlobalFlags |= HEAP_READY; /* for the other workers */ goal = ec_term(ec_did("main",1), ec_long(init_flags & INIT_SHARED ? 0 : 1)); module.val.did = d_.kernel_sepia; module.tag.kernel = ModuleTag(d_.kernel_sepia); if (ec_options.parallel_worker <= 1) /* only or first worker */ { err = main_emulc_noexit(goal.val, goal.tag, module.val, module.tag); if (err == PYIELD) { memory_corrupted = 0; /* assume it's ok */ ec_post_goal(ec_term(ec_did(":",2), ec_atom(ec_did("sepia_kernel",0)), ec_atom(ec_did("standalone_toplevel",0)))); do { err = ec_resume(); } while (err == PYIELD); } } else { err = slave_emulc(); } ec_cleanup(); exit(err); /*NOTREACHED*/ }
static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size, const char *boot_devices, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model, const struct hwdef *hwdef) { CPUState *env; char buf[1024]; m48t59_t *nvram; int ret, linux_boot; unsigned int i; ram_addr_t ram_offset, prom_offset, vga_ram_offset; long initrd_size, kernel_size; PCIBus *pci_bus, *pci_bus2, *pci_bus3; QEMUBH *bh; qemu_irq *irq; int drive_index; BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; BlockDriverState *fd[MAX_FD]; void *fw_cfg; ResetData *reset_info; linux_boot = (kernel_filename != NULL); /* init CPUs */ if (!cpu_model) cpu_model = hwdef->default_cpu_model; env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find Sparc CPU definition\n"); exit(1); } bh = qemu_bh_new(tick_irq, env); env->tick = ptimer_init(bh); ptimer_set_period(env->tick, 1ULL); bh = qemu_bh_new(stick_irq, env); env->stick = ptimer_init(bh); ptimer_set_period(env->stick, 1ULL); bh = qemu_bh_new(hstick_irq, env); env->hstick = ptimer_init(bh); ptimer_set_period(env->hstick, 1ULL); reset_info = qemu_mallocz(sizeof(ResetData)); reset_info->env = env; reset_info->reset_addr = hwdef->prom_addr + 0x40ULL; qemu_register_reset(main_cpu_reset, reset_info); main_cpu_reset(reset_info); // Override warm reset address with cold start address env->pc = hwdef->prom_addr + 0x20ULL; env->npc = env->pc + 4; /* allocate RAM */ ram_offset = qemu_ram_alloc(RAM_size); cpu_register_physical_memory(0, RAM_size, ram_offset); prom_offset = qemu_ram_alloc(PROM_SIZE_MAX); cpu_register_physical_memory(hwdef->prom_addr, (PROM_SIZE_MAX + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK, prom_offset | IO_MEM_ROM); if (bios_name == NULL) bios_name = PROM_FILENAME; snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); ret = load_elf(buf, hwdef->prom_addr - PROM_VADDR, NULL, NULL, NULL); if (ret < 0) { ret = load_image_targphys(buf, hwdef->prom_addr, (PROM_SIZE_MAX + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK); if (ret < 0) { fprintf(stderr, "qemu: could not load prom '%s'\n", buf); exit(1); } } kernel_size = 0; initrd_size = 0; if (linux_boot) { /* XXX: put correct offset */ kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL); if (kernel_size < 0) kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR, ram_size - KERNEL_LOAD_ADDR); if (kernel_size < 0) kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR, ram_size - KERNEL_LOAD_ADDR); if (kernel_size < 0) { fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } /* load initrd */ if (initrd_filename) { initrd_size = load_image_targphys(initrd_filename, INITRD_LOAD_ADDR, ram_size - INITRD_LOAD_ADDR); if (initrd_size < 0) { fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", initrd_filename); exit(1); } } if (initrd_size > 0) { for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR); stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size); break; } } } } pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, NULL, &pci_bus2, &pci_bus3); isa_mem_base = VGA_BASE; vga_ram_offset = qemu_ram_alloc(vga_ram_size); pci_vga_init(pci_bus, phys_ram_base + vga_ram_offset, vga_ram_offset, vga_ram_size, 0, 0); // XXX Should be pci_bus3 pci_ebus_init(pci_bus, -1); i = 0; if (hwdef->console_serial_base) { serial_mm_init(hwdef->console_serial_base, 0, NULL, 115200, serial_hds[i], 1); i++; } for(; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { serial_init(serial_io[i], NULL/*serial_irq[i]*/, 115200, serial_hds[i]); } } for(i = 0; i < MAX_PARALLEL_PORTS; i++) { if (parallel_hds[i]) { parallel_init(parallel_io[i], NULL/*parallel_irq[i]*/, parallel_hds[i]); } } for(i = 0; i < nb_nics; i++) pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci"); irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS); if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { fprintf(stderr, "qemu: too many IDE bus\n"); exit(1); } for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { drive_index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS); if (drive_index != -1) hd[i] = drives_table[drive_index].bdrv; else hd[i] = NULL; } pci_cmd646_ide_init(pci_bus, hd, 1); /* FIXME: wire up interrupts. */ i8042_init(NULL/*1*/, NULL/*12*/, 0x60); for(i = 0; i < MAX_FD; i++) { drive_index = drive_get_index(IF_FLOPPY, 0, i); if (drive_index != -1) fd[i] = drives_table[drive_index].bdrv; else fd[i] = NULL; } floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd); nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59); sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices, KERNEL_LOAD_ADDR, kernel_size, kernel_cmdline, INITRD_LOAD_ADDR, initrd_size, /* XXX: need an option to load a NVRAM image */ 0, graphic_width, graphic_height, graphic_depth, (uint8_t *)&nd_table[0].macaddr); fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0); fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); }
int main(int argc,char *argv[]) { char cmd[255]; int hcount=0,scount=0; float herr=0,serr=0,dice; Example *ex; int do_cg=0; float epsilon; int seed=1,first=1; float e,e0,lr,lrPrev; int start=1,i,j; char loadFile[255],fn[255]; setbuf(stdout,NULL); parallel_init(&argc,&argv); if (myid==0) { announce_version(); system("hostname"); } printf("pid %d\n",getpid()); loadFile[0]=0; /* what are the command line arguments? */ for(i=1;i<argc;i++) { if (strcmp(argv[i],"-seed")==0) { seed=atoi(argv[i+1]); i++; } else if (strcmp(argv[i],"-start")==0) { start=atoi(argv[i+1]); i++; } else if (strncmp(argv[i],"-epsilon",5)==0) { epsilon=atof(argv[i+1]); i++; } else if (strncmp(argv[i],"-load",5)==0) { strcpy(loadFile,argv[i+1]); i++; } else { fprintf(stderr,"unknown argument: %s\n",argv[i]); exit(1); } } default_epsilon=0.05; mikenet_set_seed(seed); build_hearing_model(SAMPLES); /* load in our example set */ phono_examples=load_examples("phono.pat",TICKS); sem_examples=load_examples("sem.pat",TICKS); hearing_examples=load_examples("ps.pat",TICKS); speaking_examples=load_examples("sp.pat",TICKS); phono_examples->numExamples=500; sem_examples->numExamples=500; hearing_examples->numExamples=500; speaking_examples->numExamples=500; myid=parallel_proc_id(); #ifdef DO_ONLINE_PRE_TRAIN if (start==1) { for(i=1;i<=10000;i++) { dice = mikenet_random(); if (dice <=0.2) { ex=get_random_example(phono_examples); crbp_forward(phono,ex); crbp_compute_gradients(phono,ex); crbp_apply_deltas(phono); } else if (dice <= 0.5) { ex=get_random_example(hearing_examples); crbp_forward(ps,ex); crbp_compute_gradients(ps,ex); herr += compute_error(ps,ex); crbp_apply_deltas(ps); } else if (dice <= 0.7) { ex=get_random_example(sem_examples); crbp_forward(sem,ex); crbp_compute_gradients(sem,ex); crbp_apply_deltas(sem); } else { ex=get_random_example(speaking_examples); crbp_forward(sp,ex); crbp_compute_gradients(sp,ex); serr+=compute_error(sp,ex); crbp_apply_deltas(sp); } if (i % 100 == 0) { printf("%d hear %f speak %f\n",i, herr/hcount,serr/scount); herr=0.0; serr=0.0; hcount=0; scount=0; } } sprintf(fn,"s%d_online_weights",seed); save_weights(hearing,fn); } #endif parallel_broadcast_weights(hearing); do_cg=1; if (do_cg && myid==0) printf("USING CG\n"); /* loop for ITER number of times */ for(i=1;i<5;i++) { parallel_sync(); store_all_weights(hearing); e=parallel_g(ps,hearing_examples,0.8) + parallel_g(sp,speaking_examples,0.8) + parallel_g(sem,sem_examples,0.2) + parallel_g(phono,phono_examples,0.2); if(do_cg) { if (first) init_cg(hearing); else cg(hearing); first=0; } e0=e; if (myid==0) printf("%d e0: %f\n",i,e); lr = 0.2/hearing_examples->numExamples; lrPrev=lr/10; for(j=1;j<10;j++) { e=sample(lr); if (myid==0) printf("\t\t%d %f %f\n",j,e,lr); if (e>e0) { if (myid==0) test_step(hearing,lrPrev); parallel_broadcast_weights(hearing); break; } e0=e; lrPrev=lr; lr *= 1.7; } zero_gradients(hearing); if (i % 5==0 && myid==0) { sprintf(fn,"s%d_%d_weights",seed,i); save_weights(hearing,fn); } } parallel_finish(); return 0; }