void send_character (int ch) { unsigned char status; do{ status = inportb(LSR) & 0x40; } while ( status!=0x40); /*repeat until Tx buffer empty ie bit 6 set */ outportb(TXDATA,(unsigned char) ch); }
/* _restore_irq: * Restores default masking for a hardware interrupt. */ void _restore_irq(int num) { unsigned char pic; if (!pic_virgin) { if (num>7) { pic = inportb(0xA1) & (~(1<<(num-8))); outportb(0xA1, pic | (default_pic2 & (1<<(num-8)))); altered_pic2 &= ~(1<<(num-8)); if (altered_pic2) return; num = 2; /* if no high IRQs remain, also restore Cascade (IRQ2) */ } pic = inportb(0x21) & (~(1<<num)); outportb(0x21, pic | (default_pic1 & (1<<num))); altered_pic1 &= ~(1<<num); } }
static void commandrw(void) { int i; pixmask(); for(i = 0; i < 4; i++) inportb(Pixmask); }
ATADEV_TYPE DISK::detect_device_type() { soft_reset(); if (m_master) outportb(m_bus + ATA_REG_HDDEVSEL, 0xA0); else outportb(m_bus + ATA_REG_HDDEVSEL, 0xB0); io_wait(); unsigned char cl = inportb(m_bus + ATA_REG_LBA1); /* CYL_LO */ unsigned char ch = inportb(m_bus + ATA_REG_LBA2); /* CYL_HI */ printf("ATA device type %02X%02X\n",ch,cl); /* differentiate ATA, ATAPI, SATA and SATAPI */ if (cl == 0x14 && ch == 0xEB) return ATADEV_PATAPI; if (cl == 0x69 && ch == 0x96) return ATADEV_SATAPI; if (cl == 0 && ch == 0) return ATADEV_PATA; if (cl == 0x3c && ch == 0xc3) return ATADEV_SATA; return ATADEV_UNKNOWN; }
void cmos_dump( uint16_t * values ) { uint16_t index; for (index = 0; index < 128; ++index) { outportb(0x70, index); values[index] = inportb(0x71); } }
/* _enable_irq: * Unmasks a hardware interrupt. */ void _enable_irq(int num) { unsigned char pic; init_irq(); pic = inportb(0x21); if (num > 7) { outportb(0x21, pic & 0xFB); /* unmask Cascade (IRQ2) interrupt */ pic = inportb(0xA1); outportb(0xA1, pic & (~(1<<(num-8)))); /* unmask PIC-2 interrupt */ altered_pic2 |= 1<<(num-8); } else { outportb(0x21, pic & (~(1<<num))); /* unmask PIC-1 interrupt */ altered_pic1 |= 1<<num; } }
void reboot() { int good = 0x02; while (good & 0x02) { good = inportb(0x64); outportb(0x64, 0xFE); } asm volatile ("hlt"); }
void disable_irq (byte irqn) { word picn= PIC1_A1; if ( irqn > 7) { picn = PIC2_A1; } outportb (picn, inportb(picn ) | ( 1 << irqn) ); }
void enable_irq(int irq) { unsigned short pic; if(irq<8) pic=PIC1_MASK; else pic=PIC2_MASK; unsigned char mask = inportb(pic) &(~IRQ_MASK(irq)); outportb(pic, mask); }
// 0 = failure u_char read_kbd() { u_long timeout; u_char stat, data; for(timeout = 500000; timeout != 0; timeout--) { stat = inportb(0x64); if(stat & 0x01) // loop until 8042 output buffer full { data = inportb(0x60); if((stat & 0xC0) == 0) // loop if parity error or receive timeout { return data; }; }; }; return 0; };
static void kb_ack() { int i; for(i=0;i<0xFFFFF;i++) { /*Keyboard acknowledge to keyboard commands other than resend or ECHO.*/ if (inportb(0x60) == 0xfa) break; } }
void Devices::detect_floppy_drives() { unsigned char c; outportb(0x70, 0x10); c = inportb(0x71); floppy[0] = c >> 4; /* get the high nibble */ floppy[1] = c & 0xF; /* get the low nibble by ANDing out the high nibble */ }
int disable_irq(int irq) { int pic = PIC1_MASK; if (irq > 7) pic = PIC2_MASK; int oldStatus = inportb(pic); outportb(pic, oldStatus | IRQ_MASK_BIT(irq)); return (((oldStatus & IRQ_MASK_BIT(irq)) == 0) ? 0 : 1); }
static int __wss_irq_irqdetect(int irqno) { unsigned char status = inportb(WSS_STATUS); /* Clear IRQ status */ outportb(WSS_STATUS, 0); /* Reset transfer counter */ __wss_outreg(WSSR_COUNT_LOW, 0); __wss_outreg(WSSR_COUNT_HIGH, 0); return (status & WSSM_INT); }
static UWORD SB_ReadDSP(void) /* Reads a byte from the DSP. returns 0xffff on timeout. */ { if(!SB_WaitDSPRead()) return 0xffff; return(inportb(DSP_READ_DATA)); }
static void install_isr(int portnum, struct port *p, int irq) { int x, baseaddr = p->baseaddr; p->irq = irq; /* Clear pending interrupts. */ do { inportb(baseaddr + RBR); inportb(baseaddr + LSR); inportb(baseaddr + MSR); x = inportb(baseaddr + IIR); } while (!(x & 0x01)); /* Calculate vector from IRQ. */ if (p->irq <= 7) { p->interrupt_enable_mask = ~(1 << p->irq); /* IMR is inverted */ p->vector_num = 8 + p->irq; p->pic_imr = 0x21; } else { p->interrupt_enable_mask = ~(1 << (p->irq - 8)); p->vector_num = 0x70 + (p->irq - 8); p->pic_imr = 0xa1; } /* Install ISR into vector. */ p->new_vector.pm_selector = _go32_my_cs(); p->new_vector.pm_offset = (int)isr_wrapper_table[portnum]; _go32_dpmi_allocate_iret_wrapper(&p->new_vector); disable(); _go32_dpmi_get_protected_mode_interrupt_vector(p->vector_num, &p->old_vector); _go32_dpmi_set_protected_mode_interrupt_vector(p->vector_num, &p->new_vector); /* Enable interrupts. */ outportb(baseaddr + MCR, 0x0f); outportb(baseaddr + IER, 0x0f); outportb(p->pic_imr, inportb(p->pic_imr) & p->interrupt_enable_mask); enable(); }
// Remaps the PIC, takes the interrupt numbers // for where to remap PIC1 and PIC2 at. void remap_pics(u_char pic1, u_char pic2) { u_char a1, a2; a1=inportb(PIC1_DATA); a2=inportb(PIC2_DATA); outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4); outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4); outportb(PIC1_DATA, pic1); outportb(PIC2_DATA, pic2); outportb(PIC1_DATA, 4); outportb(PIC2_DATA, 2); outportb(PIC1_DATA, ICW4_8086); outportb(PIC2_DATA, ICW4_8086); outportb(PIC1_DATA, a1); outportb(PIC2_DATA, a2); };
/*-------------------------------------------------------------------------- INT 09h - Interrupcao de Teclado --------------------------------------------------------------------------*/ void interrupt int_09h() { if ((inportb(0x60) == scan_tecla) && /* HOT KEY pressionada ? */ ((peekb (0x40,0x17) & tecla_shift) != 0)) { auxb = inportb(0x61); outportb (0x61,auxb | 0x80); /* Sim, avisa o reconhe- */ outportb (0x61,auxb); /* cimento da tecla para */ outportb (0x20,0x20); /* o controlador */ if (video_on) { /* Chaveia Video */ video_on = 0; outportb (porta_video,desl_video); } else { video_on = 1; outportb (porta_video,liga_video); } } else (*velha_int_09h)(); /* Chama int Original */ }
uint8 pci_read_conf8(uint8 bus, uint8 dev, uint8 func, uint8 reg) { uint8 ret; uint32 port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg); outportl(0xcf8, port); ret = inportb((uint16)(0xcfc + (reg&3))); return ret; }
/* wait_for_mpu: * Waits for the specified bit to clear on the specified port. Returns zero * if it cleared, -1 if it timed out. */ static INLINE int wait_for_mpu(int flag, int port) { int timeout; for (timeout=0; timeout<0x7FFF; timeout++) if (!(inportb(port) & flag)) return 0; return -1; }
void store_scancode() { //lock_mutex_block(&keyboard_mutex); if(curr_scancode_pos != 256) { raw_scancodes[curr_scancode_pos] = inportb(0x60); curr_scancode_pos++; }; //keyboard_mutex = 0; };
void btn_gpio_init(void) { unsigned char tmp; /* platform initial code */ /* Reset button initial function */ /* select GPIO function */ tmp=inportb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_USE_SEL); tmp |= GPIO20_BIT; outportb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_USE_SEL, tmp); /* set to input mode */ tmp=inportb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_IO_SEL); tmp |= GPIO20_BIT; outportb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_IO_SEL, tmp); return; }
static int nic_dump_prom(snic *nic, unsigned char *prom) { unsigned int f; int iobase=nic->iobase; char wordlength=2; unsigned char dump[32]; outportg(32, iobase + REMOTEBYTECOUNT0); outportg(0x00, iobase + REMOTEBYTECOUNT1); outportg(0x00, iobase + REMOTESTARTADDRESS0); outportg(0x00, iobase + REMOTESTARTADDRESS1); outportg(NIC_REM_READ | NIC_START, iobase); for(f=0;f<32;f+=2) { dump[f]=inportb(iobase + NE_DATA); dump[f+1]=inportb(iobase + NE_DATA); if(dump[f]!=dump[f+1]) wordlength=1; } for(f=0;f<LEN_PROM;f++) prom[f]=dump[f+((wordlength==2)?f:0)]; return wordlength; }
void PrintDriver() { int i, code; char *p; msg_t temp_msg; printing_semaphore = SemGet(0); //request semaphore printing_semaphore, limit 0. // reset printer (check printer power, cable, and paper), it will jitter outportb(LPT1_BASE+LPT_CONTROL, PC_SLCTIN); // CONTROL reg, SeLeCT INterrupt code = inportb(LPT1_BASE+LPT_STATUS); // read STATUS for(i = 0; i < 50; i++) //loop 50 times of IO_DELAY(); { IO_DELAY(); } outportb(LPT1_BASE+LPT_CONTROL, PC_INIT|PC_SLCTIN|PC_IRQEN); // IRQ ENable Sleep(1); //Sleep for a second, needs time resetting while(1)//forever loop: { temp_msg.recipient = running_pid; MsgRcv(&temp_msg);//receive a message, get if msg to print ******* p = temp_msg.data; cons_printf("PrintDriver (PID %d) now prints...\n", GetPid()); //a notification msg (match how demo runs) //set p to point to start of character string in message while (*p != '\0') //"what p points to" is not null/empty/(char)0, { outportb(LPT1_BASE+LPT_DATA, *p); // write char to DATA reg code = inportb(LPT1_BASE+LPT_CONTROL); // read CONTROL reg outportb(LPT1_BASE+LPT_CONTROL, code|PC_STROBE); // write CONTROL, STROBE added for(i = 0; i < 50; i++) //do 50 times of IO_DELAY { IO_DELAY(); } outportb(LPT1_BASE+LPT_CONTROL, code); // send back original CONTROL SemWait(printing_semaphore);//semaphore-wait on the printing semaphore p++; //move p to next character to print } } }
uint8_t getRawKeyboardOutput() { keyboardStatus status; // make sure the output buffer is full before // we read from it. do { status = getKeyboardStatus(); } while (!status.read); return inportb((uint16_t)0x60); }
void setup_floppy(void) { outportb(0x70,0x10); if (!inportb(0x71)) return; register_interrupt_handler(IRQ6,FloppyIRQ); reset(); devfs_handle *dev=devfs_register_device(NULL,"fd0",0660,FS_UID_ROOT,FS_GID_ROOT,FS_BLOCKDEVICE,&floppy_ops); dev->bcount=FLOPPY_SECTOR_COUNT; dev->bsize=FLOPPY_SECTOR_SIZE; }
int com_open(int *eflag_p, int baud_rate) { int baud_rate_div; int mask; if(eflag_p == NULL) { return INVALID_E_FLAG; } if(baud_rate <= 0) { return INVALID_BRD; } if(DCB->flag == OPEN) { return ALREADY_OPEN; } //initialize all the DCB fields DCB->flag = OPEN; DCB->event_flag = eflag_p; DCB->status = IDLE; DCB->ring_buffer_in = 0; DCB->ring_buffer_out = 0; DCB->ring_buffer_count = 0; oldfunc = getvect(COM1_INT_ID); setvect(COM1_INT_ID, &handler); baud_rate_div = 115200 / (long) baud_rate; //change BRD reg outportb(COM1_LC, 0x80); //set the baud_rate_div outportb(COM1_BRD_LSB, baud_rate_div & 0xFF); outportb(COM1_BRD_MSB, (baud_rate_div >> 8) & 0xFF); //cant change BRD outportb(COM1_LC, 0x03); //Enable PIC Mask disable(); mask = inportb(PIC_MASK); mask &= ~0x10; outportb(PIC_MASK, mask); enable(); //Enable COM1 interrupts outportb(COM1_MC, 0x08); //Set Data Available Interrupt bit in the interrupt enable register outportb(COM1_INT_EN, 0x01); return 0; }
static int detect_uart(unsigned int baseaddr) { int x, olddata, temp; /* check if a UART is present */ olddata = inportb(baseaddr + MCR); /* enable loopback mode, set RTS & DTR to 1 */ outportb(baseaddr + MCR, 0x1f); _delay(); /* Read the state of RTS and DTR. * Do this twice, so that lower 4 bits are clear. * OS/2 returns 0xB0 after this, instead of 0xff if no port is there. */ disable(); temp = inportb(baseaddr + MSR); temp = inportb(baseaddr + MSR); enable(); if ((temp & 0x3f) != 0x30) return 0; /* restore RTS & DTR */ outportb(baseaddr + MCR, olddata); _delay(); /* next thing to do is look for the scratch register */ olddata = inportb(baseaddr + SCR); outportb(baseaddr + SCR, 0x55); _delay(); if (inportb(baseaddr + SCR) != 0x55) return UART_8250; outportb(baseaddr + SCR, 0xAA); _delay(); if (inportb(baseaddr + SCR) != 0xAA) return UART_8250; /* restore it if it's there */ outportb(baseaddr + SCR, olddata); _delay(); /* check if there's a FIFO */ outportb(baseaddr + IIR, 1); _delay(); x = inportb(baseaddr + IIR); /* some old-fashioned software relies on this! */ outportb(baseaddr + IIR, 0x0); _delay(); if ((x & 0x80) == 0) return UART_16450; if ((x & 0x40) == 0) return UART_16550; return UART_16550A; }
void send_to_test_center (char* cmd) { while (*cmd != '\0') { /* * Wait for the UART to accept the next byte */ while (!(inportb (COM2_PORT + 5) & (1 << 5))) ; outportb (COM2_PORT, *cmd); cmd++; } }
static void SB_ResetDSP(void) /* Resets the DSP. */ { int t; /* reset the DSP by sending 1, (delay), then 0 */ outportb(DSP_RESET,1); for(t=0;t<8;t++) inportb(DSP_RESET); outportb(DSP_RESET,0); }