static int isavga_write(struct dev_write_args *ap) { cdev_t dev = ap->a_head.a_dev; return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), ap->a_uio, ap->a_ioflag); }
/** * Run kernel. */ void kmain() { gdt_install(); idt_install(); isr_install(); irq_install(); clock_install(); vga_init(); vga_write("Bandit Kernel v0.0.1\n"); vga_write("Developer: Matheus Vieira Portela\n"); vga_write("Contact: matheusvportela at gmail dot com\n\n"); clock_set_frequency(1); /* test_division_by_zero_exception(); */ /* Kernel infinite loop */ while(1) { vga_write("tick\n"); clock_wait(18); } }
static int isavga_write(struct cdev *dev, struct uio *uio, int flag) { return (vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag)); }
void vga_write_string(char* string) { char* next_char = string; while (*next_char != 0) { vga_write(*next_char++); } }
void do_drive_cdrom_startstop_test(struct ide_controller *ide,unsigned char which) { struct menuboxbounds mbox; char backredraw=1; int select=-1; char redraw=1; int c; /* UI element vars */ menuboxbounds_set_def_list(&mbox,/*ofsx=*/4,/*ofsy=*/7,/*cols=*/1); menuboxbounds_set_item_strings_arraylen(&mbox,drive_cdrom_startstop_strings); /* most of the commands assume a ready controller. if it's stuck, * we'd rather the user have a visual indication that it's stuck that way */ c = do_ide_controller_user_wait_busy_controller(ide); if (c != 0) return; /* select the drive we want */ idelib_controller_drive_select(ide,which,/*head*/0,IDELIB_DRIVE_SELECT_MODE_CHS); /* in case the IDE controller is busy for that time */ c = do_ide_controller_user_wait_busy_controller(ide); if (c != 0) return; /* read back: did the drive select take effect? if not, it might not be there. another common sign is the head/drive select reads back 0xFF */ c = do_ide_controller_drive_check_select(ide,which); if (c < 0) return; /* it might be a CD-ROM drive, which in some cases might not raise the Drive Ready bit */ do_ide_controller_atapi_device_check_post_host_reset(ide); /* wait for the drive to indicate readiness */ /* NTS: If the drive never becomes ready even despite our reset hacks, there's a strong * possibility that the device doesn't exist. This can happen for example if there * is a master attached but no slave. */ c = do_ide_controller_user_wait_drive_ready(ide); if (c < 0) return; /* for completeness, clear pending IRQ */ idelib_controller_ack_irq(ide); while (1) { if (backredraw) { backredraw = 0; redraw = 1; background_draw(); vga_moveto(0,0); header_write("CD-ROM eject/load",ide,which); } if (redraw) { redraw = 0; vga_moveto(mbox.ofsx,mbox.ofsy - 2); vga_write_color((select == -1) ? 0x70 : 0x0F); vga_write("Back to IDE drive main menu"); while (vga_state.vga_pos_x < (mbox.width+mbox.ofsx) && vga_state.vga_pos_x != 0) vga_writec(' '); menuboxbound_redraw(&mbox,select); } c = getch(); if (c == 0) c = getch() << 8; if (c == 27) { break; } else if (c == 13) { if (select == -1) break; switch (select) { case 0: /* show IDE register taskfile */ do_common_show_ide_taskfile(ide,which); redraw = backredraw = 1; break; case 1: /*Eject*/ case 2: /*Load*/ case 3: /*Start*/ case 4: /*Stop*/ { static const unsigned char cmd[4] = {2/*eject*/,3/*load*/,1/*start*/,0/*stop*/}; do_drive_atapi_eject_load(ide,which,cmd[select-1]); } break; }; } else if (c == 0x4800) { if (--select < -1) select = mbox.item_max; redraw = 1; } else if (c == 0x4B00) { /* left */ redraw = 1; } else if (c == 0x4D00) { /* right */ redraw = 1; } else if (c == 0x5000) { if (++select > mbox.item_max) select = -1; redraw = 1; } } }
void printf(const char* format, ...) { va_list currentParam; const char* formatIter = format; char* bufferIter = writeBuffer; va_start(currentParam, format); while(*formatIter != '\0') { if (*formatIter != '%') { *bufferIter = *formatIter; ++bufferIter; } else { //escape sequence detected ++formatIter; switch (*formatIter) { case '\0': break; case '%' : *bufferIter = '%'; break; case 'c' : { char arg = va_arg(currentParam, int); // char is promoted to int when passed via va memcpy((void *)(bufferIter), &arg, 1); break; } case 's' : { char* arg = va_arg(currentParam, char*); uint32_t arglen = strlen(arg); memcpy((void *)(bufferIter), (void *)arg, arglen); bufferIter += arglen-1; break; } case 'd' : { bool isNegative = false; const char numberBufferSize = 12; char buffer[numberBufferSize]; int32_t arg = va_arg(currentParam, int); if (arg < 0) { isNegative = true; arg = -arg; } char* startIter = itoa(arg, buffer+numberBufferSize, 10); if (isNegative) { *--startIter = '-'; } uint32_t numberlen = strlen(startIter); memcpy((void *)(bufferIter), (void *)startIter, numberlen); bufferIter += numberlen-1; break; } case 'p' : { const char numberBufferSize = 32; char buffer[numberBufferSize]; char *pstr = itoa(va_arg(currentParam, uint64_t), buffer+numberBufferSize, 16); *--pstr = 'x'; *--pstr = '0'; memcpy((void *)(bufferIter), (void *)pstr, strlen(pstr)); bufferIter += strlen(pstr)-1; break; } case 'f' : *bufferIter = 'f'; break; case 'l' : *bufferIter = 'l'; break; } ++bufferIter; } ++formatIter; } *bufferIter = 0; va_end(currentParam); vga_write(writeBuffer); }