diff options
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | drivers/include/vga.h | 3 | ||||
| -rw-r--r-- | drivers/tty.c | 3 | ||||
| -rw-r--r-- | kernel/include/log.h | 4 | ||||
| -rw-r--r-- | kernel/log.c | 26 | ||||
| -rw-r--r-- | kernel/main.c | 15 | ||||
| -rw-r--r-- | libc/include/stdio.h | 4 | ||||
| -rw-r--r-- | libc/stdio.c | 19 |
8 files changed, 56 insertions, 27 deletions
@@ -3,7 +3,8 @@ CC = gcc LD = ld INCLUDES = -Idrivers/include -Ikernel/include -Ilibc/include CFLAGS = -std=gnu99 -ffreestanding -fno-stack-protector -nostdlib -Wall -Wextra -m32 $(INCLUDES) -g -EMULATOR = qemu-system-i386 +QEMU = qemu-system-i386 +BOCHS = bochs AS = as ASFLAGS=-march=i686 --32 @@ -14,7 +15,11 @@ all: kappa.bin test: iso @echo "EMULATOR kappa.iso" - @$(EMULATOR) kappa.iso + @$(QEMU) kappa.iso + +test-bochs: iso + @echo "BOCHS bochs.cfg" + @$(BOCHS) -f bochs.cfg -q iso: kappa.bin @echo "Building ISO under $(ISODIR)/..." diff --git a/drivers/include/vga.h b/drivers/include/vga.h index 278601c..b83ec95 100644 --- a/drivers/include/vga.h +++ b/drivers/include/vga.h @@ -31,5 +31,8 @@ enum vga_color_t { #define VGA_MAKE_COLOR(fg, bg) (fg | bg << 4) #define VGA_MAKE_ENTRY(ch, col) (((uint16_t)ch)|((uint16_t)col<<8)) +#define VGA_RGBPACK(r, g, b) ((r << 16)|(g << 8)|(b << 0)) void vga_init(); + +void vga_drawpixel(int x, int y, uint32_t pix); diff --git a/drivers/tty.c b/drivers/tty.c index 6b83232..7bce7e7 100644 --- a/drivers/tty.c +++ b/drivers/tty.c @@ -1,4 +1,5 @@ #include <stdint.h> +#include <stdio.h> #include "io.h" #include "panic.h" #include "tty.h" @@ -34,6 +35,8 @@ void tty_init(void) } tty_set_color(VGA_MAKE_COLOR(VGA_LIGHT_GRAY, VGA_BLACK)); tty_clear(); + set_putchar(tty_putchar); + set_puts(tty_puts); } static void move_cursor(uint16_t cursor_idx) diff --git a/kernel/include/log.h b/kernel/include/log.h index 73a5545..fb29dd3 100644 --- a/kernel/include/log.h +++ b/kernel/include/log.h @@ -1 +1,3 @@ -void klog(const char*, ...); +int log_putchar(char); +int log_puts(const char*); +void log(const char*, ...); diff --git a/kernel/log.c b/kernel/log.c index cfe2922..3f509c5 100644 --- a/kernel/log.c +++ b/kernel/log.c @@ -5,35 +5,35 @@ #define BOCHS_PUTCHAR(ch) (outb(0xe9, ch)) -static int eputchar(int ch) +int log_putchar(int ch) { BOCHS_PUTCHAR(ch); return 0; } -static int eputs(const char* str) +int log_puts(const char* str) { while(*str) - putchar(*str++); + log_putchar(*str++); return 0; } -static char ehex_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7', +static char hex_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; -static void eprint_hex(unsigned int n) +static void log_print_hex(unsigned int n) { unsigned mask = 0xF0000000; unsigned shift = 28; while(mask) { - eputchar(ehex_table[(n & mask) >> shift]); + log_putchar(hex_table[(n & mask) >> shift]); mask >>= 4; shift -= 4; } } -int klog(const char *fmt, ...) +int log(const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -47,25 +47,25 @@ int klog(const char *fmt, ...) switch(*fmt++) { case 'c': - eputchar(va_arg(ap, int)); + log_putchar(va_arg(ap, int)); break; case 's': - eputs(va_arg(ap, const char*)); + log_puts(va_arg(ap, const char*)); break; case 'x': - eprint_hex(va_arg(ap, unsigned)); + log_print_hex(va_arg(ap, unsigned)); break; case 'd': - eputs(itoa(va_arg(ap, unsigned), 10)); + log_puts(itoa(va_arg(ap, unsigned), 10)); break; default: - eputs("klog: unknown format\n"); + log_puts("klog: unknown format\n"); break; } break; } default: - eputchar(ch); + log_putchar(ch); break; } } diff --git a/kernel/main.c b/kernel/main.c index 748fc7f..9082859 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -14,12 +14,12 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) { - klog("main() called\n"); + /* this should go to port e9, which is the Bochs debug port */ + printf("Testing early I/O\n"); /* initialize the TTY first, no real harm can be done */ tty_init(); - klog("tty done, magic %x\n", magic); if(magic != 0x2BADB002) { panic("Multiboot magic invalid"); @@ -27,10 +27,6 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) vga_init((struct vbe_info_t*)hdr->vbe_mode_info); - klog("multiboot header address: %x\n", hdr); - klog("multiboot vbe info struct address: %x\n", hdr->vbe_mode_info); - klog("multiboot framebuffer: %x\n", ((struct vbe_info_t*)hdr->vbe_mode_info)->physbase); - /* then the descriptor tables so we can do more useful stuff */ gdt_init(); idt_init(); @@ -46,9 +42,12 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) asm("sti"); printf("Boot finished.\n"); - printf("Testing keyboard LED's...\n"); + for(int i=0;i<50;++i) - vga_drawpixel(i, i, 0x80808080); + vga_drawpixel(i, i, VGA_RGBPACK(255, 0, 0)); + + printf("Testing keyboard LED's...\n"); + while(1) { ps2_set_leds(PS2_NUM_LOCK); diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 32391b8..ac547c7 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -1,3 +1,7 @@ int printf(const char* fmt, ...); int puts(const char*); int putchar(int); + +/* sets the I/O functions, allows easy switching between text mode and VBE */ +void set_putchar(void (*func)(char)); +void set_puts(void (*func)(const char*)); diff --git a/libc/stdio.c b/libc/stdio.c index 92fba27..0ef8b0c 100644 --- a/libc/stdio.c +++ b/libc/stdio.c @@ -1,20 +1,33 @@ -#include "tty.h" +#include "log.h" #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +static void (*putchar_ptr)(char) = log_putchar; +static void (*puts_ptr)(const char*) = log_puts; + int putchar(int ch) { - tty_putchar((char)ch); + putchar_ptr((char)ch); return 0; } int puts(const char* str) { - tty_puts(str); + puts_ptr(str); return 0; } +void set_putchar(void (*func)(char)) +{ + putchar_ptr = func; +} + +void set_puts(void (*func)(const char*)) +{ + puts_ptr = func; +} + static char hex_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |