void putnbr_base(int nb, char *base) { if (nb < 0) { kputchar('-'); nb *= -1; } if (nb < strlen(base)) kputchar(base[nb]); else { putnbr_base(nb / strlen(base), base); kputchar(base[nb % strlen(base)]); } }
void isr_kb(void) { static unsigned char current_key = 0; static unsigned char left_shift = 0; static unsigned char right_shift = 0; static unsigned char left_alt = 0; unsigned char scan_code = 0; unsigned char state = PUSH; do { scan_code = inb(0x64); } while (scan_code & 0x01 == 0x0); scan_code = 0; scan_code = inb(0x60); if (scan_code > 0x80) { state = REL; scan_code -= 0x80; } if (scan_code == LSHIFT) left_shift = state == PUSH ? 1 : 0; else if (scan_code == RSHIFT) { right_shift = state == PUSH ? 1 : 0; } else if (scan_code == LALT) left_alt = state == PUSH ? 1 : 0; else if (state == PUSH) // press kputchar(kbmap[(scan_code * 2) + (left_shift | right_shift)]); }
/** Printf */ int kprintf(const char *format, ...) { int len = 0; char output[255]; char *current = &output[0]; va_list ap; va_start(ap, format); while(*format != '\0') { if(*format == '%') { format++; switch (*format) { /* print a string */ case 's': current = va_arg(ap, char *); kputs(current); break; /* print a char */ case 'c': current = va_arg(ap, char *); kputchar(current[0]); break; /* print an hex */ case 'x': kputs(itox(va_arg(ap, int))); break; /* print a decimal */ case 'd': kputs(itoa(va_arg(ap, int))); break; /* % escape */ case '%': kputchar('%'); break; } } else
void kputs(char *s) { while (*s != '\0') { kputchar(*s); s++; } }
void printbase10(int x){ unsigned int t; int i = 0; char buf[16]; if(x<0) kputchar('-'); x = (x<0)?-x:x; while(x >= 10){ t = __divu10(x); buf[i++] = ('0'+(x-__mulu10(t))); x = t; } buf[i] = ('0'+x); for(;i>=0;i--){ kputchar(buf[i]); } }
void validchk(uint16_t dev, const char *p) { if (!validdev(dev)) { kputs(p); kputchar(':'); panic(PANIC_INVD); } }
/** Print a string */ void kputs(char *str) { while(*str != '\0') { kputchar(*str); str++; } }
STARTUP(int kputs(char *s)) { register char *i; for (i = s; *i; ++i) kputchar(*i); return 0; }
//------------------------------------------------------------------------------ /// Outputs a character to a file. //------------------------------------------------------------------------------ int fputc(int ch, FILE *f) { if ((f == stdout) || (f == stderr)) { kputchar(ch); return ch; } else { return EOF; } }
/* Flags is not used yet but will be needed (eg for swap scans) */ void blkdev_scan(blkdev_t *blk, uint8_t flags) { uint8_t letter = 'a' + (blk - blkdev_table); used(flags); /* not used */ blk_op.blkdev = blk; mbr_parse(letter); kputchar('\n'); }
void print_regs(struct pushregs *regs) { int i; for (i = 0; i < 30; i++) { kprintf(" $"); printbase10(i + 1); kprintf("\t: "); printhex(regs->reg_r[i]); kputchar('\n'); } }
/* ======================================================================================================================= Send a specified number of bytes from buffer to host ; ======================================================================================================================= */ void Response(unsigned char *pbuf, unsigned char lenght) { /* * char msg[40]; */ while(lenght > 0) { /* * sprintf(msg, "[%x]", *pbuf++); * *send_cstring(msg); */ kputchar('['); Put_byte(*pbuf); kputchar(']'); pbuf++; lenght--; } put_crlf(); } /* Response */
void kprintf(const char *format, ...) { char **arg = (char **) &format; int c; char buf[20]; // TODO: appropriate buf size? ++arg; while ((c = *format++) != 0) { if (c != '%') kputchar(c); else { char *s; c = *format++; switch (c) { case 'd': case 'u': case 'x': itoa(buf, c, *((int *) arg++)); s = buf; goto string; case 's': s = *arg++; if (!s) s = "(null)"; string: while (*s) kputchar(*s++); break; default: panic("bad format specifier"); } } } }
/* * * kprintf - formats a string and writes it to stdout * * The return value is the number of characters which would be * written to stdout. * */ int kprintf(const char *str) { int cnt = 0; while(*str){ kputchar(*str); cnt++; str++; } //va_start(ap, fmt); //cnt = vkprintf(fmt, ap); //va_end(ap); return cnt; }
void print_trapframe(struct trapframe *tf) { PRINT_HEX("trapframe at ", tf); print_regs(&tf->tf_regs); PRINT_HEX(" $ra\t: ", tf->tf_ra); PRINT_HEX(" BadVA\t: ", tf->tf_vaddr); PRINT_HEX(" Status\t: ", tf->tf_status); PRINT_HEX(" Cause\t: ", tf->tf_cause); PRINT_HEX(" EPC\t: ", tf->tf_epc); if (!trap_in_kernel(tf)) { kprintf("Trap in usermode: "); } else { kprintf("Trap in kernel: "); } kprintf(trapname(GET_CAUSE_EXCODE(tf->tf_cause))); kputchar('\n'); }
/************************************************************************** * Transforms a argument list in to characters on the screen. * In the function * var=2; kprintf( "Hi %d \n -", var) * the string starting with the quotation mark, is literally (in HEX ASCII) * 42 48 69 20 25 64 20 5C 6E 20 55 42 * the compiler interprets the quotation marks and translates "\n" to '\n'. * 48 69 20 25 64 20 0A 20 2D * the function vsnprintf translates the specifier into "2" * 48 69 20 32 20 0A 20 2D * the function kputchar will put the characters in the proper place * Hi 2 <moves cursor to next line> * - **************************************************************************/ s32int kprintf(const s08int *fmt, ...) { s08int kprintf_buf[1024]; va_list args; u32int i; va_start( args, fmt ); vsnprintf( kprintf_buf, sizeof(kprintf_buf), fmt, args ); va_end( args ); // Writing to the video buffer must be mutual exclusive. For now interrupts are // simply disabled. In the future semaphores will be used. u32int flags; disable_and_save_interrupts(flags); for( i = 0; i < 1024; i++ ) { if( !kprintf_buf[i] ) break; kputchar( kprintf_buf[i] ); } restore_interrupts(flags); return( i ); }
void print_trapframe(struct trapframe *tf) { PRINT_HEX("trapframe at ", tf); print_regs(&tf->tf_regs); PRINT_HEX(" $ra\t: ", tf->tf_ra); PRINT_HEX(" BadVA\t: ", tf->tf_vaddr); PRINT_HEX(" Status\t: ", tf->tf_status); PRINT_HEX(" Cause\t: ", tf->tf_cause); PRINT_HEX(" EPC\t: ", tf->tf_epc); if (!trap_in_kernel(tf)) { kprintf("Trap in usermode: "); }else{ kprintf("Trap in kernel: "); } kprintf(trapname(GET_CAUSE_EXCODE(tf->tf_cause))); kputchar('\n'); // /* int i; for (i = 0; i < 20; ++i) { int *addr = (int*)(tf->tf_epc + i * 4); kprintf("0x%08x=0x%08x\n", addr, *addr); } // */ }
/* ======================================================================================================================= ======================================================================================================================= */ void InterruptHandlerReader(unsigned char *Register) { /*~~~~~~~~~~~~~~~~*/ /* * char phello[20]; * //for testing */ unsigned char len; /*~~~~~~~~~~~~~~~~*/ /* * Register = Register & 0xF7; * //set the parity flag to 0 ; * parity is not used in 15693 and Tag-It */ #if DBG Put_byte(*Register); #endif if(*Register == 0xA0) { /* TX active and only 3 bytes left in FIFO */ i_reg = 0x00; #if DBG kputchar('.'); /* FIFO filling is done in the transmit function */ #endif } else if(*Register == BIT7) { /* TX complete */ i_reg = 0x00; *Register = Reset; /* reset the FIFO after TX */ DirectCommand(Register); #if DBG kputchar('T'); #endif } else if((*Register & BIT1) == BIT1) { /* collision error */ i_reg = 0x02; /* RX complete */ // *Register = StopDecoders; /* reset the FIFO after TX */ // DirectCommand(Register); CollPoss = CollisionPosition; ReadSingle(&CollPoss, 1); // *Register = 0x0c; // ReadSingle(Register, 1); /* * CollPoss &= 0xF7; */ len = CollPoss - 0x20; /* number of valid bytes if FIFO */ if(!POLLING) { kputchar('{'); Put_byte(CollPoss); kputchar('}'); } if((len & 0x0f) != 0x00) len = len + 0x10; /* add 1 byte if broken byte recieved */ len = len >> 4; if(len != 0x00) { buf[RXTXstate] = FIFO; /* write the recieved bytes to the correct place of the * buffer; * */ ReadCont(&buf[RXTXstate], len); RXTXstate = RXTXstate + len; } /* if */ *Register = StopDecoders; /* reset the FIFO after TX */ DirectCommand(Register); *Register = Reset; DirectCommand(Register); *Register = IRQStatus; /* IRQ status register address */ *(Register + 1) = IRQMask; //ReadSingle(Register, 2); /* function call for single address read */ // ReadCont(Register, 2); if (SPIMODE) ReadCont(Register, 2); else ReadSingle(Register, 1); TRF_IRQ_CLEAR(); }
void _ttywrch(int ch) { kputchar((unsigned char)ch); }
static void putdigit0(unsigned char c) { kputchar("0123456789ABCDEF"[c & 15]); }
void kputs(const char *p) { while (*p) kputchar(*p++); }
void scsi_dev_init(uint8_t drive) { blkdev_t *blk; uint8_t *p; uint16_t secsize; /* FIXME: need to sort controller mapping policy here too */ si_dcb.device = drive; si_dcb.lun = 0; si_dcb.bus = 0; if (si_select()) /* Can't select it - probably not present */ return; /* FIXME: check if this would be better as a memcpy of fixed struct */ si_dcb.cb.cb0.opcode = SIINQUIRY; si_dcb.cb.cb0.hiblock = 0; si_dcb.cb.cb0.miblock = 0; si_dcb.cb.cb0.loblock = 0; si_dcb.cb.cb0.noblocks = 36; si_dcb.cb.cb0.control = 0; si_dcb.length = 36; si_dcb.direction = SIDIR_READ; si_user = 0; si_deselect(); /* As selects don't necessarily stack */ if (si_docmd(identify)) return; p = identify + 8; while (p < identify + 27) kputchar(*p++); kputchar('\n'); /* Ok the device exists, but we may not be able to drive it */ switch(identify[0] & 0x1F) { case 0x00: /* Hard Disk */ case 0x07: /* Optical */ case 0x0C: /* RAID */ case 0x0E: /* RBC */ break; default: return; } /* We should spin the device up I guess. We don't currently support removable media - that would need us to defer much of this to open and add an open hook to the blkdev layer */ /* FIXME: use Test Unit ready - but note that for SASI at least TUR is optional */ /* Read capacity tells us the disk size */ memset(&si_dcb.cb.cb0, 0, sizeof(si_dcb.cb.cb0)); si_dcb.cb.cb0.opcode = SIREAD_CAP; si_dcb.length = 8; si_dcb.direction = SIDIR_READ; si_user = 0; if (si_docmd(cap)) return; if (cap[4] || cap[5]) /* Block size over 64K */ return; secsize = (cap[6] << 8) | cap[7]; if (secsize != 512) { kprintf("scsi: unsupported sector size %d\n", secsize); return; } /* Ok we pass. Allocate a disk device */ blk = blkdev_alloc(); if (!blk) return; blk->transfer = si_cmd; blk->flush = si_flush; blk->driver_data = drive; /* Very big disks report FFFFFFFF if they overrun this. We don't care we currently only speak READ6 anyway ! */ blk->drive_lba_count = ((uint32_t)cap[0] << 24) | ((uint32_t)cap[1] << 16) | ((uint16_t)cap[2] << 8) | cap[3]; blkdev_scan(blk, SWAPSCAN); }
static int sys_putc(uint32_t arg[]) { int c = (int)arg[0]; kputchar(c); return 0; }
static void explode(struct trapdata *framedata, int type) { uint16_t *excp = framedata->exception; uint32_t *fv; unsigned int i = framedata->trap; unsigned int j; if (i > 12) i = 12; for (j = 0; j < i; j++) kputs(" '* "); kputchar('\n'); for (j = 0; j < i; j++) kputs(" | "); kputchar('\n'); for (j = 0; j < i; j++) kputs(".###. "); kputchar('\n'); for (j = 0; j < i; j++) kputs("##### "); kputchar('\n'); for (j = 0; j < i; j++) kputs("##### "); kputchar('\n'); for (j = 0; j < i; j++) kputs("`###' "); kputchar('\n'); kprintf("Trap: %d\n", framedata->trap); kprintf("Register Dump\nA: "); for (i = 0; i < 7; i++) kprintf("%p ", framedata->a[i]); kprintf("%p\nD: ", get_usp()); for (i = 0; i < 8; i++) kprintf("%p ", framedata->d[i]); kprintf("\nSR: %x\n", framedata->sr); kprintf("Exception frame:\n"); for (j = 0;j < 16; j++) kprintf("%d: %x\n", j, excp[j]); /* 68010 long frame */ if (type == FRAME_C) { kputs((excp[4] & 0x100)?"R":"W"); kprintf(" FC %x", excp[4] & 7); fv = (uint32_t *)(excp +5); kprintf(" Addr %p SSW %x ", *fv, excp[4]); } /* 68000 long frame */ if (type == FRAME_A) { kputs((excp[0] & 0x10)?"R":"W"); kprintf(" FC %x", excp[0] & 7); fv = (uint32_t *)(excp + 1); kprintf(" Addr %p IR %x ", *fv, excp[3]); excp += 4; } /* All frames */ fv = (uint32_t *)(excp + 1); kprintf("PC %p SR %x\n", *fv, *excp); }