int kputs(const char *str) { int pos, i, len = strlen(str); if (early_print != NO_EARLY_PRINT) spinlock_irqsave_lock(&olock); for(i=0; i<len; i++) { pos = atomic_int32_inc(&kmsg_counter); kmessages[pos % KMSG_SIZE] = str[i]; #ifdef CONFIG_VGA if (early_print & VGA_EARLY_PRINT) vga_putchar(str[i]); #endif #ifdef CONFIG_UART if (early_print & UART_EARLY_PRINT) uart_putchar(str[i]); #endif } if (early_print != NO_EARLY_PRINT) spinlock_irqsave_unlock(&olock); return len; }
short console_getline(console_color_t color, char *str, unsigned short *len) { unsigned short i=0; char c; unsigned char c233 = vga_color233(vga_console_color(color)); while (i < *len-1) { if ((sysio[0] & 0x2) == 0x2) c = keyboard_getchar(); else c = serial_getchar(0); if (c >= ' ' && c <= '~') { if ((sysio[0] & 0x2) == 0x2) vga_putchar(c233,c); else serial_putchar(0, c); str[i++] = c; } if (c == '\r' || c == '\n') { str[i] = '\0'; return i; } if (c == 0x03) { str[0] = '\0'; return -1; } if ((c == 0x7f || c == 0x08) && i > 0) { if ((sysio[0] & 0x2) == 0x2) vga_putchar(c233, c); else serial_putchar(0, c); i--; } } str[i+1] = '\0'; return i; }
int kputchar(int c) { int pos; if (early_print != NO_EARLY_PRINT) spinlock_irqsave_lock(&olock); pos = atomic_int32_inc(&kmsg_counter); kmessages[pos % KMSG_SIZE] = (unsigned char) c; #ifdef CONFIG_VGA if (early_print & VGA_EARLY_PRINT) vga_putchar(c); #endif #ifdef CONFIG_UART if (early_print & UART_EARLY_PRINT) uart_putchar(c); #endif if (early_print != NO_EARLY_PRINT) spinlock_irqsave_unlock(&olock); return 1; }
void va_snprintf(char *b, int l, char *fmt, va_list pvar, int s_flag) { int n, i; unsigned u; char *t, d[10], uint_str[10]; /* bail if args == null */ if (!fmt || (!b && s_flag) || (l < 1)) return; while (l && *fmt) { if (*fmt == '\n') { vga_putchar (*fmt, 15); } else if (*fmt == '%') { fmt++; if (!(--l)) break; switch (*fmt) { case 's': /* string */ t = va_arg (pvar, char *); while (l && *t) { if (s_flag) *b++ = *t++; else vga_putchar(*t++, 15); l--; } break; case 'c': /* single character */ if (s_flag) *b++ = va_arg (pvar, char); else vga_putchar (va_arg (pvar, char), 15); l--; break; case 'x': /* 8 digit, unsigned 32bit hex integer */ if (l < 8) { l = 0; break; } u = va_arg (pvar, unsigned int); for(i = 7; i >= 0; i--) { uint_str[i] = hexmap[u & 0x0F]; u >>= 4; } for (i = 0; i <= 7; i++) { if (s_flag) *b++ = uint_str[i]; else vga_putchar(uint_str[i], 15); } l -= 8; break; case 'd': /* signed integer */ n = va_arg (pvar, int); if (n < 0) { u = -n; if (s_flag) *b++ = '-'; else vga_putchar ('-', 15); if(!(--l)) break; } else { u = n; } goto u2; case 'u': /* unsigned integer */ u = va_arg (pvar, unsigned int); u2: i = 9; do { d[i] = (u % 10) + '0'; u /= 10; i--; } while (u && i >= 0); while (++i < 10) { if (s_flag) *b++ = d[i]; else vga_putchar (d[i], 15); if(!(--l)) break; } break; case 'X': /* 2 digit, unsigned 8bit hex int */ if (l < 2) { l = 0; break; } n = va_arg (pvar, int); if (s_flag) { *b++ = hexmap[(n & 0xF0) >> 4]; *b++ = hexmap[n & 0x0F]; } else { vga_putchar (hexmap[(n & 0xF0) >> 4], 15); vga_putchar (hexmap[n & 0x0F], 15); } l -= 2; break; default: if (s_flag) *b++ = *fmt; else vga_putchar (*fmt, 15); }