Archive / / / boot.c
2003-05-22 11:03:46 UTC
previous next
// typedef char* mem_address_t; void start(unsigned long magic, char* mb_info) __attribute__ ((section ("boot"))); /* void boot_printf(unsigned char color, char* format_string, ...) __attribute__ ((section ("boot"))); inline void boot_printf_c(unsigned char color, char character) __attribute__ ((section ("boot"))); inline void boot_printf_u(unsigned char color, unsigned int number) __attribute__ ((section ("boot"))); inline unsigned char inportb(unsigned int port) __attribute__ ((section ("boot"))); inline void outportb(unsigned int port, unsigned char value) __attribute__ ((section ("boot"))); mem_address_t video_mem; */ void start(unsigned long magic, char* mb_info) { // char* videomemtest; // videomemtest = 0xb8002 // *videomemtest = 'b'; // boot_printf(0x0C, "This is a test."); } /* void boot_printf(unsigned char color, char* format_string, ...) { mem_address_t arg; arg = (mem_address_t)&format_string + 4; // Pointer to argument after format_string outportb(0x3d4, 0x0E); // Get first byte of screen cursor offset video_mem = (mem_address_t)inportb(0x3d5); video_mem = (mem_address_t)((int)video_mem << 8); outportb(0x3d4, 0x0F); // Get second byte video_mem += inportb(0x3d5); video_mem = (mem_address_t)((int)video_mem << 1); // Multiply by two (since each character in video memory video_mem += 0xb8000; // takes 2 byes) and add 0xb8000 to get the memory address do { if (*format_string != '%') { boot_printf_c(color, *format_string); continue; } format_string++; // Advance to character after the % if (*format_string == 'c') { // If the format specifier is a char boot_printf_c(color, *arg); arg += 4; continue; } if (*format_string == 'u') { // If the format specifier is an unsigned integer boot_printf_u(color, *arg); arg += 4; continue; } if (*format_string == '%') { boot_printf_c(color, '%'); continue; } } while(++format_string); video_mem -= 0xb8000; video_mem = (mem_address_t)((int)video_mem >> 1); outportb(0x3d4, 0x0E); outportb(0x3d5, (int)video_mem >> 8); outportb(0x3d4, 0x0F); outportb(0x3d5, (int)video_mem & 0xFF); } inline void boot_printf_c(unsigned char color, char character) { if (character != '\n') { *video_mem = character; video_mem++; *video_mem = color; video_mem++; return; } video_mem = (mem_address_t)((((int)video_mem - 0xb8000) / 160) + 1); video_mem = (mem_address_t)(((int)video_mem * 160) + 0xb8000); } inline void boot_printf_u(unsigned char color, unsigned int number) { char digit_string[11]; char* current_digit = digit_string; if (number == 0) { boot_printf_c(color, '0'); return; } while (number > 0) { *current_digit = (number % 10) + '0'; // Get rightmost digit and convert to ASCII current_digit++; number /= 10; // Remove rightmost digit from the number } // Print digit_string in reverse order starting with current_digit for (;(--current_digit) >= digit_string; boot_printf_c(color, *current_digit)); } inline unsigned char inportb(unsigned int port) { unsigned char ret; asm volatile ("inb %%dx,%%al":"=a" (ret):"d" (port)); return ret; } inline void outportb(unsigned int port, unsigned char value) { asm volatile ("outb %%al,%%dx": :"d" (port), "a" (value)); } */