int main(int argc, char **argv) { int i, cur; tgetopt(argc, argv); if ( toptset('h') ) { printf(usage, argv[0]); exit(0); } if ( toptset('c') ) config_file = toptargs('c'); syslog_open("updategroups", LOG_PID, LOG_NEWS); if ( (master = memmap(sizeof(MASTER))) == NULL ) die("Can't allocate master memory"); if ( (groups = memmap(sizeof(ACTIVE) * MAX_GROUPS)) == NULL ) die("Can't allocate groups memory"); loadconfig(); load_servers(); cur = -1; for (i=master->numservers-2; i>=0; i-- ) if ( (master->lservers[i])->Level != cur ) { cur = (master->lservers[i])->Level; update_server( master->lservers[i] ); } write_active(); write_newsgroups(); memunmap(master, sizeof(MASTER)); memunmap(groups, sizeof(ACTIVE) * MAX_GROUPS); syslog_close(); exit(0); }
HI_RET himd(int argc , char* argv[]) { U32 ulAddr = 0; VOID* pMem = NULL; LENGTH_T len; if (argc < 2) { printf("usage: %s <address>. sample: %s 0x80040000\n", argv[0], argv[0]); EXIT("", -1); } if (argc == 3) { if ( StrToNumber(argv[2], &len) != HI_SUCCESS) { len = DEFAULT_MD_LEN; } } else { len = DEFAULT_MD_LEN; } if( StrToNumber(argv[1], &ulAddr) == HI_SUCCESS) { printf("====dump memory %#010lX====\n", ulAddr); #ifdef PC_EMULATOR #define SHAREFILE "../shm" printf("**** is Emulator, use share file : %s ****\n", SHAREFILE); pMem = mmapfile(SHAREFILE , len); if (NULL == pMem) { EXIT("Memory Map error.", -1); } pMem += ulAddr; #else pMem = memmap(ulAddr, len); if (NULL == pMem) { EXIT("Memory Map error.", -1); } #endif hi_hexdump(STDOUT, pMem, len, 16); } else { printf("Please input address like 0x12345\n"); } return 0; }
int gpio1_1_set_on(serialNode *m) { VOID *pMem = NULL; U32 ulOld,ulNew; pMem = memmap((0x20160000+GPIO_DATA_N_X(0)),16); ulOld = *(U32*)pMem; ulOld = ulNew | (1<<0); *(U32*)pMem = ulNew; }
int gpio1_1_set_off(serialNode *m) { VOID *pMem = NULL; U32 ulOld,ulNew; pMem = memmap((0x20160000+0x400),16); ulOld = *(U32*)pMem; ulOld = ulNew | (1<<0); *(U32*)pMem = ulNew; }
int get_map(Map *map) { int fd; char *buf; int r; int x, y; buf = malloc(10000); if ((fd = open("map", O_RDONLY)) == -1) return (-1); r = read(fd, buf, 9999); buf[r] = 0; map->x = nb_cl(buf); map->y = nb_ln(buf); map->map = malloc((map->y+1)*sizeof(char*)); map->map[map->y] = NULL; for (r = 0; r < map->y; r++) { map->map[r] = malloc(map->x+1); map->map[r][map->x] = 0; } memmap(map); y = 0; r = 0; while (buf[r] && map->map[y] != NULL) { x = 0; while (buf[r] && (buf[r] != '\n') && map->map[y][x]) { if (buf[r] == 'A') { map->pacman.pos.x = x*IMG; map->pacman.pos.y = y*IMG; map->map[y][x] = '0'; } else if (buf[r] == 'D') { map->enemy.pos.x = (x*IMG)+5; map->enemy.pos.y = y*IMG; map->map[y][x] = '0'; } else map->map[y][x] = buf[r]; x++; r++; } if (buf[r] == '\n') r++; map->map[y][x] = 0; y++; } map->map[y] = NULL; return (0); }
void reg_init() { g_print("BMC init\n"); // BMC init done here void *bmcreg; int mem_fd = open("/dev/mem", O_RDWR | O_SYNC); if (mem_fd < 0) { printf("ERROR: Unable to open /dev/mem"); exit(1); } bmcreg = memmap(mem_fd,LPC_BASE); devmem(bmcreg+LPC_HICR6,0x00000500); //Enable LPC FWH cycles, Enable LPC to AHB bridge devmem(bmcreg+LPC_HICR7,0x30000E00); //32M PNOR devmem(bmcreg+LPC_HICR8,0xFE0001FF); //flash controller bmcreg = memmap(mem_fd,SPI_BASE); devmem(bmcreg+0x00,0x00000003); devmem(bmcreg+0x04,0x00002404); //UART bmcreg = memmap(mem_fd,UART_BASE); devmem(bmcreg+0x00,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200) devmem(bmcreg+0x04,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200) devmem(bmcreg+0x08,0x000000c1); //Disable Parity, 1 stop bit, 8 bits bmcreg = memmap(mem_fd,COM_BASE); devmem(bmcreg+0x9C,0x00000000); //Set UART routing bmcreg = memmap(mem_fd,SCU_BASE); devmem(bmcreg+0x00,0x13008CE7); devmem(bmcreg+0x04,0x0370E677); devmem(bmcreg+0x20,0xDF48F7FF); devmem(bmcreg+0x24,0xC738F202); //GPIO bmcreg = memmap(mem_fd,GPIO_BASE); devmem(bmcreg+0x84,0x00fff0c0); //Enable UART1 devmem(bmcreg+0x70,0x120CE406); devmem(bmcreg+0x80,0xCB000000); devmem(bmcreg+0x88,0x01C000FF); devmem(bmcreg+0x8c,0xC1C000FF); devmem(bmcreg+0x90,0x003FA009); bmcreg = memmap(mem_fd,COM_BASE); devmem(bmcreg+0x170,0x00000042); devmem(bmcreg+0x174,0x00004000); close(mem_fd); }
// ############################ GPIO_1_0 #################################### // 假设端口1_0 为设置端口 // 端口1_1 为扫描端口 int gpio1_0_set_init(serialNode *m) { // set mulit reg VOID *pMem = NULL; U32 ulOld,ulNew; // set multi register pMem = memmap((0x200F0000+0xB8),16); ulOld = *(U32*)pMem; ulOld = ulNew | (0<<0); // set out put *(U32*)pMem = ulNew; // set dir register pMem = memmap((0x20160000+0x400),16); ulOld = *(U32*)pMem; ulOld = ulNew | (1<<0); *(U32*)pMem = ulNew; // set data register pMem = memmap((0x20160000+GPIO_DATA_N_X(0)),16); ulOld = *(U32*)pMem; ulOld = ulNew | GPIO_DATA_N_X(0); // set data for 1 *(U32*)pMem = ulNew; return 0; }
void put_video_ram(void) { char *putbuf = (char *) malloc(TEXT_SIZE); char *graph_mem; if (SCR_STATE.mapped) { debug_vid("put_video_ram called\n"); if (config.vga) { if (memmap(graph_mem = (void*)GRAPH_BASE, GRAPH_SIZE, PG_U | PG_W | PG_P, (void *)GRAPH_BASE) != 0) { error("put_video_ram: memmap failed for 0x%08x\n", GRAPH_BASE); leaveemu(ERR_PT); } if (dosemu_regs->mem && READ_BYTE(BIOS_VIDEO_MODE) == 3 && READ_BYTE(BIOS_CURRENT_SCREEN_PAGE) < 8) { memcpy((caddr_t) PAGE_ADDR(0), dosemu_regs->mem, dosemu_regs->save_mem_size[0]); } } else { memcpy(putbuf, SCR_STATE.virt_address, TEXT_SIZE); if (memmap(graph_mem = (void*)SCR_STATE.virt_address, TEXT_SIZE, PG_U | PG_W | PG_P, (void *)SCR_STATE.virt_address) != 0) { error("put_video_ram: memmap failed for 0x%08x\n", (u_int)SCR_STATE.virt_address); leaveemu(ERR_PT); } memcpy(SCR_STATE.virt_address, putbuf, TEXT_SIZE); } giveup_permissions(); SCR_STATE.mapped = 0; } else warn("VID: put_video-ram but not mapped!\n"); if (putbuf) free(putbuf); debug_vid("put_video_ram completed\n"); }
static int do_go(int argc, char *argv[]) { void *addr; int rcode = 1; int fd = -1; int (*func)(int argc, char *argv[]); if (argc < 2) return COMMAND_ERROR_USAGE; if (!isdigit(*argv[1])) { fd = open(argv[1], O_RDONLY); if (fd < 0) { perror("open"); goto out; } addr = memmap(fd, PROT_READ); if (addr == (void *)-1) { perror("memmap"); goto out; } } else addr = (void *)simple_strtoul(argv[1], NULL, 16); printf("## Starting application at 0x%p ...\n", addr); console_flush(); func = addr; shutdown_barebox(); if (do_execute) do_execute(func, argc - 1, &argv[1]); else func(argc - 1, &argv[1]); /* * The application returned. Since we have shutdown barebox and * we know nothing about the state of the cpu/memory we can't * do anything here. */ while (1); out: if (fd > 0) close(fd); return rcode; }
int create(pthread_t *ptid, const pthread_attr_t *attr, void * (*start_routine) (void *), void *arg) { int flags; volatile pid_t* ctidloc; int tid; thread_func_t *user_thread; user_thread = (thread_func_t *)malloc(sizeof(thread_func_t)); user_thread->thread_func = start_routine; user_thread->thread_data = arg; user_thread->detachstate = attr->detachstate; user_thread->ptid = -1; void *stack = memmap(NULL,attr->stacksize, \ PROT_READ | PROT_WRITE, \ MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN, \ -1, 0); if (stack == MAP_FAILED) { free(user_thread); return ENOMEM; } *ptid = initialize_thread_db_entry(attr->detachstate,attr->stacksize,stack,user_thread); if (*ptid == -1) { memunmap(stack,attr->stacksize); return EAGAIN; } user_thread->ptid = *ptid; flags = CLONE_VM | CLONE_THREAD | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |\ CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_IO | SIGCHLD; ctidloc = get_tid_location_from_db_entry(*ptid); tid = clone(thread_wrapper,stack+attr->stacksize, flags, user_thread, ctidloc, NULL, ctidloc); if (tid == -1) { recycle_thread_db_entry(*ptid); return errno; } set_nonvolatile_tid(*ptid,tid); return 0; }
int main (int argc, char *argv[]) { syslog_open("nntpswitchd", LOG_PID, LOG_NEWS); init_options(argc, argv); init_sighandlers(); initproctitle(argc, argv); if ((master = memmap(sizeof (MASTER))) == NULL) die("Can't allocate master memory"); info("Server starting up.."); run_daemon(); syslog_close(); return 0; }
/** * Receive data from the Ethernet and give it to the lwip-stack */ void eth_receive_data() { if (ethRxFlag == 0) return; ethRxFlag = 0; uint32_t firstbytes = HWREG(ETH_BASE + MAC_O_DATA); uint32_t length = firstbytes & 0xFFFF; struct pbuf *buf = pbuf_alloc(PBUF_RAW, length, PBUF_RAM); if (buf == NULL) { #ifdef DEBUG_MALLOC_MM UARTprintf("oom when allocating %d byte at %s:%d\n", length, __FILE__, __LINE__); memmap(); #endif /* Clear the FIFO */ eth_rx_fifo_clear(); } else { #ifdef DEBUG_MALLOC UARTprintf("%x %d alloc %d, %s:%d;\r\n", buf, debug_ctr++, length, __FILE__, __LINE__); #endif *((uint32_t*) buf->payload) = firstbytes; uint32_t *bufptr = (uint32_t*) (((uint32_t*) buf->payload) + 1); if (length > 4) { /* We already read 4 bytes */ length -= 4; unsigned int i; for (i = 0; i < length; i += sizeof(uint32_t)) { *bufptr = HWREG(ETH_BASE + MAC_O_DATA); bufptr++; } buf->len = length; interface.input(buf, &interface); } else { #ifdef DEBUG_MALLOC UARTprintf("%x %d free, %s:%d;\r\n", buf, debug_ctr++, __FILE__, __LINE__); #endif pbuf_free(buf); } } ROM_EthernetIntEnable(ETH_BASE, ETH_INT_RX); }
static int do_bootu(int argc, char *argv[]) { int fd; void *kernel = NULL; void *oftree = NULL; if (argc != 2) return COMMAND_ERROR_USAGE; fd = open(argv[1], O_RDONLY); if (fd > 0) kernel = (void *)memmap(fd, PROT_READ); if (!kernel) kernel = (void *)simple_strtoul(argv[1], NULL, 0); #ifdef CONFIG_OFTREE oftree = of_get_fixed_tree(NULL); #endif start_linux(kernel, 0, 0, 0, oftree, ARM_STATE_SECURE); return 1; }
int gpio1_1_get_status(serialNode *m) { U32 ulOld,ulNew; VOID *pMem; pMem = memmap((0x200F0000+0xB8),16); ulOld = *(U32*)pMem; ulOld = ulNew | (0<<0); // set out put int reg_old = m->reg_value; int reg_default = GPIO_MSG_ORIGIN_BIT; if((reg_old & (1<<2)) ^ (ulOld & (1<<2))) { if((reg_default & (1<<2)) ^ (ulOld & (1<<2))) { if(m->cmd_type == CMD_RUN) { m->reg_value = ulOld; return 0; } return GPIO_MSG_1_1_ON; } return GPIO_MSG_1_1_OFF; } return 0; }
void uaeser_signal (void *vdev, int32_t sigmask) { struct devstruct *dev = (struct devstruct*)vdev; struct asyncreq *ar; int32_t i = 0; uae_sem_wait (&async_sem); ar = dev->ar; while (ar) { if (!ar->ready) { uaecptr request = ar->request; uint32_t io_data = get_long (request + 40); // 0x28 uint32_t io_length = get_long (request + 36); // 0x24 int32_t command = get_word (request + 28); uint32_t io_error = 0, io_actual = 0; uint8_t *addr; int32_t io_done = 0; switch (command) { case SDCMD_BREAK: if (ar == dev->ar) { uaeser_break (dev->sysdata, get_long (request + io_BrkTime)); io_done = 1; } break; case CMD_READ: if (sigmask & 1) { addr = memmap(io_data, io_length); if (addr) { if (uaeser_read (dev->sysdata, addr, io_length)) { io_error = 0; io_actual = io_length; io_done = 1; } } else { io_error = IOERR_BADADDRESS; io_done = 1; } } break; case CMD_WRITE: if (sigmask & 2) { io_error = IOERR_BADADDRESS; addr = memmap(io_data, io_length); if (addr && uaeser_write (dev->sysdata, addr, io_length)) io_error = 0; io_actual = io_length; io_done = 1; } break; default: write_log (_T("%s:%d incorrect async request %x (cmd=%d) signaled?!"), getdevname(), dev->unit, request, command); break; } if (io_done) { if (log_uaeserial) write_log (_T("%s:%d async request %x completed\n"), getdevname(), dev->unit, request); put_long (request + 32, io_actual); put_byte (request + 31, io_error); ar->ready = 1; write_comm_pipe_u32 (&dev->requests, request, 1); } } ar = ar->next; } uae_sem_post (&async_sem); }
/*memory dump bin*/ HI_RET himdb(int argc , char* argv[]) { U32 ulAddr = 0; VOID* pMem = NULL; VOID* pBase = NULL; LENGTH_T len = DEFAULT_MD_LEN; FILENAME_T fn; if (argc >= 3) { if ( StrToNumber(argv[2], &len) != HI_SUCCESS) { len = DEFAULT_MD_LEN; } if (argc == 4) { strcpy(fn, argv[3]); } else { sprintf(fn, "md_%s-%s", argv[1], argv[2]); } } else { printf("usage: %s <address> <len> [filename]. sample: %s 0x80040000 \n", argv[0], argv[0]); EXIT("", -1); } if( StrToNumber(argv[1], &ulAddr) == HI_SUCCESS) { printf("====dump memory:<%#010lX><%lu> to file:<%s>====\n", ulAddr, len, fn); #ifdef PC_EMULATOR #define SHAREFILE "../shm" printf("**** is Emulator, use share file : %s ****\n", SHAREFILE); pBase = mmapfile(SHAREFILE , len); pMem = pBase ; if (NULL == pMem) { EXIT("Memory Map error.", -1); } pMem = pBase + ulAddr; #else pBase = memmap(ulAddr, len); pMem = pBase ; if (NULL == pMem) { EXIT("Memory Map error.", -1); } #endif (void)hi_md2file(pMem, len, NULL, fn); } else { printf("Please input address like 0x12345\n"); } (void)munmap(pBase, len); return 0; }
HI_S32 vo_video_csc_config(HI_U32 u32LayerId, HI_U32 enCscMatrix, HI_U32 u32Luma, HI_U32 u32Contrast, HI_U32 u32Hue, HI_U32 u32Satuature, HI_U32 u32Gain) { HI_S32 s32Ret; CscCoef_S stCscCoef; HI_U8 *pAddr = NULL; HI_U32 *pRegAddr = NULL; HI_U32 u32CscIdc, u32CscOdc, u32CscP0, u32CscP1, u32CscP2, u32CscP3, u32CscP4; HI_U32 u32DacCtrl0_2; HI_S32 s32Matrix; usage(); if (u32LayerId < 0 || u32LayerId > 3) { printf ("layer err \n"); usage(); return -1; } if (u32Contrast < 0 || u32Contrast > 100) { printf ("u32Contrast err \n"); usage(); return -1; } if (u32Hue < 0 || u32Hue > 100) { printf ("u32Hue err \n"); usage(); return -1; } if (u32Luma < 0 || u32Luma > 100) { printf ("u32Luma err \n"); usage(); return -1; } if (u32Satuature < 0 || u32Satuature > 100) { printf ("u32Satuature err \n"); usage(); return -1; } if (u32Gain < 0x0 || u32Gain > 0x3F) { printf ("u32Gain err \n"); usage(); return -1; } if (enCscMatrix < 0 || enCscMatrix > 2) { printf ("enCscMatrix err \n"); usage(); return -1; } switch(enCscMatrix) { case 0:s32Matrix = HAL_CSC_MODE_RGB_TO_RGB;break; case 1:s32Matrix = HAL_CSC_MODE_BT601_TO_BT709;break; case 2:s32Matrix = HAL_CSC_MODE_BT709_TO_BT601;break; default: return -1; } vou_cal_csc_matrix(u32Luma, u32Contrast, u32Hue, u32Satuature,s32Matrix, &stCscCoef); u32CscIdc = ((get_xdc_buma(stCscCoef.csc_in_dc2) & 0x1ff) | ((get_xdc_buma(stCscCoef.csc_in_dc1) & 0x1ff) << 9) | ((get_xdc_buma(stCscCoef.csc_in_dc0) & 0x1ff) << 18)); u32CscOdc = ((get_xdc_buma(stCscCoef.csc_out_dc2) & 0x1ff) | ((get_xdc_buma(stCscCoef.csc_out_dc1) & 0x1ff) << 9) | ((get_xdc_buma(stCscCoef.csc_out_dc0) & 0x1ff) << 18)); u32CscP0 = ((conver_csc_coef(stCscCoef.csc_coef00) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef01) & 0x1fff) << 16)); u32CscP1 = ((conver_csc_coef(stCscCoef.csc_coef02) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef10) & 0x1fff) << 16)); u32CscP2 = ((conver_csc_coef(stCscCoef.csc_coef11) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef12) & 0x1fff) << 16)); u32CscP3 = ((conver_csc_coef(stCscCoef.csc_coef20) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef21) & 0x1fff) << 16)); u32CscP4 = (conver_csc_coef(stCscCoef.csc_coef22) & 0x1fff); memopen(); pAddr = (HI_U8 *)memmap(VO_BASE_REG, VO_VIDEO_CSC_SIZE); if(NULL == pAddr) { printf("err: memmap failure\n"); return HI_FAILURE; } //printf("sys_map 0x%x\n", pAddr); pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCIDC)); u32CscIdc |= (*pRegAddr & 0x08000000); //csc_en //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscIdc); *pRegAddr = u32CscIdc; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCODC)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscOdc); *pRegAddr = u32CscOdc; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP0)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP0); *pRegAddr = u32CscP0; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP1)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP1); *pRegAddr = u32CscP1; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP2)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP2); *pRegAddr = u32CscP2; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP3)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP3); *pRegAddr = u32CscP3; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP4)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP4); *pRegAddr = u32CscP4; pRegAddr = (HI_U32 *)(pAddr + (DACCTRL0_2 - VO_BASE_REG)); set_cvbs_gain(u32LayerId, pRegAddr, u32Gain); memunmap(VO_BASE_REG, VO_VIDEO_CSC_SIZE); memclose(); return HI_SUCCESS; }
void reg_init() { g_print("BMC init\n"); // BMC init done here void *bmcreg; int mem_fd = open("/dev/mem", O_RDWR | O_SYNC); if (mem_fd < 0) { printf("ERROR: Unable to open /dev/mem"); exit(1); } bmcreg = memmap(mem_fd,LPC_BASE); devmem(bmcreg+LPC_HICR6,0x00000500); //Enable LPC FWH cycles, Enable LPC to AHB bridge devmem(bmcreg+LPC_HICR7,0x30000C00); //32M PNOR devmem(bmcreg+LPC_HICR8,0xFC0003FF); //flash controller bmcreg = memmap(mem_fd,SPI_BASE); devmem(bmcreg+0x00,0x00000003); devmem(bmcreg+0x04,0x00002404); //UART bmcreg = memmap(mem_fd,UART_BASE); devmem(bmcreg+0x00,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200) devmem(bmcreg+0x04,0x00000000); //Set Baud rate divisor -> 13 (Baud 115200) devmem(bmcreg+0x08,0x000000c1); //Disable Parity, 1 stop bit, 8 bits bmcreg = memmap(mem_fd,COM_BASE); devmem(bmcreg+0x9C,0x00000000); //Set UART routing bmcreg = memmap(mem_fd,SCU_BASE); devmem(bmcreg+0x00,0x9e82fce7); //devmem(bmcreg+0x00,0x9f82fce7); // B2? devmem(bmcreg+0x04,0x0370e677); // do not modify state of power pin, otherwise // if this is a reboot, host will shutdown uint32_t reg_20 = devmem_read(bmcreg+0x20); reg_20 = reg_20 & 0x00000002; devmem(bmcreg+0x20,0xcfc8f7fd | reg_20); devmem(bmcreg+0x24,0xc738f20a); devmem(bmcreg+0x80,0x0031ffaf); //GPIO bmcreg = memmap(mem_fd,GPIO_BASE); devmem(bmcreg+0x84,0x00fff0c0); //Enable UART1 devmem(bmcreg+0x80,0xCB000000); devmem(bmcreg+0x88,0x01C000FF); devmem(bmcreg+0x8c,0xC1C000FF); devmem(bmcreg+0x90,0x003FA009); devmem(bmcreg+0x88,0x01C0007F); bmcreg = memmap(mem_fd,COM_BASE); devmem(bmcreg+0x170,0x00000042); devmem(bmcreg+0x174,0x00004000); close(mem_fd); }
/* allows remapping even if memory is mapped in...this is useful, as it * remembers where the video mem *was* mapped, unmaps from that, and then * remaps it to where the text page number says it should be */ void get_video_ram(int waitflag) { char *graph_mem; char *sbase; size_t ssize; char *textbuf = NULL, *vgabuf = NULL; debug_vid("get_video_ram STARTED\n"); if (config.vga) { ssize = GRAPH_SIZE; sbase = (char *) GRAPH_BASE; } else { ssize = TEXT_SIZE; sbase = PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)); } #if 0 if (waitflag == WAIT) { config.console_video = 0; debug_vid("VID: get_video_ram WAITING\n"); /* XXX - wait until our console is current (mixed signal functions) */ do { if (!wait_vc_active ()) break; debug_vid("Keeps waiting...And\n"); } while (errno == EINTR); } #endif if (config.vga) { debug("config.vga\n"); if (READ_BYTE(BIOS_VIDEO_MODE) == 3 && READ_BYTE(BIOS_CURRENT_SCREEN_PAGE) < 8) { textbuf = malloc(TEXT_SIZE * 8); if (!textbuf) leaveemu(ERR_MEM); memcpy(textbuf, PAGE_ADDR(0), TEXT_SIZE * 8); } if (SCR_STATE.mapped) { vgabuf = (char *)malloc(GRAPH_SIZE); if (!vgabuf) leaveemu(ERR_MEM); memcpy(vgabuf, (caddr_t) GRAPH_BASE, GRAPH_SIZE); if (memmap(graph_mem = (void *)GRAPH_BASE, GRAPH_SIZE, PG_U | PG_W | PG_P, (void *)GRAPH_BASE) != 0) { error("memmap failed for 0x%08x\n", GRAPH_BASE); leaveemu(ERR_PT); } memcpy((caddr_t) GRAPH_BASE, vgabuf, GRAPH_SIZE); } } else { textbuf = (char *)malloc(TEXT_SIZE); if (!textbuf) leaveemu(ERR_MEM); memcpy(textbuf, SCR_STATE.virt_address, TEXT_SIZE); if (SCR_STATE.mapped) { if (memmap(graph_mem = SCR_STATE.virt_address, TEXT_SIZE, PG_U | PG_W | PG_P, SCR_STATE.virt_address) != 0) { error("memmap failed for 0x%08x\n", (u_int)SCR_STATE.virt_address); leaveemu(ERR_PT); } memcpy(SCR_STATE.virt_address, textbuf, TEXT_SIZE); } } SCR_STATE.mapped = 0; if (config.vga) { if (READ_BYTE(BIOS_VIDEO_MODE) == 3) { if (dosemu_regs->mem && textbuf) memcpy(dosemu_regs->mem, textbuf, dosemu_regs->save_mem_size[0]); /* else error("ERROR: no dosemu_regs->mem!\n"); */ } debug("mapping GRAPH_BASE\n"); if (memmap(graph_mem = (void *) GRAPH_BASE, GRAPH_SIZE, PG_U | PG_W | PG_P, (void *) GRAPH_BASE) != 0) { error("memmap failed for 0x%08x\n", GRAPH_BASE); leaveemu(ERR_PT); } /* the code below is done by the video save/restore code */ get_permissions(); } else { /* this is used for page switching */ if (PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)) != SCR_STATE.virt_address) memcpy(textbuf, PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)), TEXT_SIZE); debug("mapping PAGE_ADDR\n"); if (memmap(graph_mem = PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)), TEXT_SIZE, PG_U | PG_W | PG_P, (void*)phys_text_base) != 0) { error("memmap failed for 0x%08x\n", GRAPH_BASE); leaveemu(ERR_PT); } #if 0 /* Map CGA, etc text memory to HGA memory. Useful for debugging systems with HGA or MDA cards. */ graph_mem = (char *) mmap((caddr_t) 0xb8000, TEXT_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, mem_fd, phys_text_base); if ((long) graph_mem < 0) { error("ERROR: mmap error in get_video_ram (text): %x, errno %d\n", (Bit32u) graph_mem, errno); return; } else #endif debug_vid("CONSOLE VIDEO address: %p %p %p\n", (void *) graph_mem, (void *) phys_text_base, (void *) PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE))); get_permissions(); /* copy contents of page onto video RAM */ memcpy((caddr_t) PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)), textbuf, TEXT_SIZE); } if (vgabuf) free(vgabuf); if (textbuf) free(textbuf); SCR_STATE.pageno = READ_BYTE(BIOS_CURRENT_SCREEN_PAGE); SCR_STATE.virt_address = PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)); SCR_STATE.phys_address = graph_mem; SCR_STATE.mapped = 1; }