diff options
| -rw-r--r-- | OBJ | 1 | ||||
| -rw-r--r-- | drivers/gfx.c | 78 | ||||
| -rw-r--r-- | drivers/include/gfx.h | 3 | ||||
| -rw-r--r-- | drivers/include/ps2.h | 2 | ||||
| -rw-r--r-- | drivers/ps2.c | 32 | ||||
| -rw-r--r-- | kernel/irq.c | 1 | ||||
| -rw-r--r-- | kernel/isr.c | 3 | ||||
| -rw-r--r-- | kernel/main.c | 38 | ||||
| -rw-r--r-- | libc/include/stdio.h | 2 | ||||
| -rw-r--r-- | libc/include/string.h | 1 | ||||
| -rw-r--r-- | libc/string.c | 7 |
11 files changed, 149 insertions, 19 deletions
@@ -1,5 +1,6 @@ boot/head.o drivers/gfx.o +drivers/gfx_font.o drivers/pcspkr.o drivers/ps2.o drivers/tty.o diff --git a/drivers/gfx.c b/drivers/gfx.c index 538dadb..38a6591 100644 --- a/drivers/gfx.c +++ b/drivers/gfx.c @@ -1,5 +1,9 @@ +#include <stdbool.h> #include <stddef.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> +#include "gfx_font.h" #include "log.h" #include "multiboot.h" #include "panic.h" @@ -8,6 +12,7 @@ static uint8_t *framebuffer = NULL; static uint16_t fb_width; static uint16_t fb_height; + /* this is BYTES per pixel */ static uint8_t fb_bpp; @@ -30,13 +35,82 @@ void gfx_clear(uint32_t col) } } -void gfx_init(struct vbe_info_t *vbe_mode_info) +void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg) +{ + int stride = fb_bpp * fb_width; + uint8_t *line_addr = framebuffer + (x * fb_bpp) + (y * fb_width * fb_bpp); + for(int i = y; i < y + FONT_HEIGHT; ++i) + { + uint32_t line_buf[8] = {bg}; + uint8_t mask = 0x80; + for(int j = 0; j < 8; ++j, mask >>= 1) + { + if(gfx_font[(int)c][i] & mask) + line_buf[j] = fg; + } + memcpy(line_addr, line_buf, sizeof(line_buf)); + line_addr += stride; + } +} + +static int cursor_x, cursor_y; +static uint32_t fgcol, bgcol; + +void gfx_putchar(char ch) +{ + if(ch != '\n') + { + gfx_drawchar(cursor_x, cursor_y, ch, fgcol, bgcol); + cursor_x += FONT_WIDTH; + if(cursor_x >= fb_width) + { + cursor_x = 0; + cursor_y += FONT_HEIGHT; + if(cursor_y >= fb_height) + { + gfx_clear(bgcol); + cursor_y = 0; + } + } + } + else + { + cursor_x = 0; + cursor_y += FONT_HEIGHT; + if(cursor_y >= fb_height) + { + gfx_clear(bgcol); + cursor_y = 0; + } + } +} + +void gfx_puts(const char* str) +{ + while(*str) + { + gfx_putchar(*str++); + } +} + +bool gfx_init(struct vbe_info_t *vbe_mode_info) { framebuffer = (uint8_t*)vbe_mode_info->physbase; fb_width = vbe_mode_info->Xres; fb_height = vbe_mode_info->Yres; fb_bpp = vbe_mode_info->bpp / 8; if(fb_bpp != 4) - panic("BPP *MUST* be 32!!!\n"); + { + printf("WARNING: BPP != 32, falling back to text mode...\n"); + return false; + } gfx_clear(VGA_RGBPACK(0, 0, 0)); + cursor_y = 0; + cursor_x = 0; + fgcol = VGA_RGBPACK(0xff, 0xff, 0xff); + bgcol = VGA_RGBPACK(0, 0, 0); + set_putchar(gfx_putchar); + set_puts(gfx_puts); + + return true; } diff --git a/drivers/include/gfx.h b/drivers/include/gfx.h index bafd7a3..19019a9 100644 --- a/drivers/include/gfx.h +++ b/drivers/include/gfx.h @@ -1,3 +1,4 @@ +#include <stdbool.h> #include <stdint.h> enum vga_color_t { @@ -31,7 +32,7 @@ enum vga_color_t { struct vbe_info_t; -void gfx_init(struct vbe_info_t *vbe_mode_info); +bool gfx_init(struct vbe_info_t *vbe_mode_info); void gfx_drawpixel(int x, int y, uint32_t color); diff --git a/drivers/include/ps2.h b/drivers/include/ps2.h index 924ef24..6f2c572 100644 --- a/drivers/include/ps2.h +++ b/drivers/include/ps2.h @@ -1,3 +1,5 @@ +/* this is both a PS/2 keyboard AND a PS/2 MOUSE driver */ + #include <stdint.h> #define PS2_SCROLL_LOCK (1 << 0) diff --git a/drivers/ps2.c b/drivers/ps2.c index b9a9b20..742b7ad 100644 --- a/drivers/ps2.c +++ b/drivers/ps2.c @@ -1,3 +1,4 @@ +/* this is both a PS/2 keyboard AND a PS/2 MOUSE driver */ #include <stdint.h> #include <stdio.h> #include "io.h" @@ -18,7 +19,7 @@ void ps2_set_leds(uint8_t status) outb(0x60, status); } -static void ps2_handler(struct regs_t regs) +static void key_handler(struct regs_t regs) { (void) regs; uint8_t scancode = inb(0x60); @@ -33,8 +34,33 @@ static void ps2_set_scancode_set(uint8_t set) outb(0x60, set); } -void ps2_init(void) +static void keyboard_init(void) { - set_interrupt_handler(IRQ(1), ps2_handler); + set_interrupt_handler(IRQ(1), key_handler); ps2_set_scancode_set(1); } + +static void mouse_handler(struct regs_t regs) +{ + printf("mouse action!\n"); +} + +static void mouse_init(void) +{ + /* enable IRQ12 */ + set_interrupt_handler(IRQ(12), mouse_handler); + /* make the ps/2 controller generate IRQ12 */ + outb(0x64, 0x20); + uint8_t status = inb(0x64); + /* set bit 1 and unset bit 5 */ + status |= (1 << 1); + status &= ~(1 << 5); + outb(0x64, 0x60); + outb(0x60, status); +} + +void ps2_init(void) +{ + keyboard_init(); + mouse_init(); +} diff --git a/kernel/irq.c b/kernel/irq.c index d98ecda..aa726d9 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -26,7 +26,6 @@ void irq_remap(void) void irq_init(void) { irq_remap(); - printf("IRQ handlers installed.\n"); idt_set_gate(32, (uint32_t)_irq0, 0x08, 0x8E); idt_set_gate(33, (uint32_t)_irq1, 0x08, 0x8E); idt_set_gate(34, (uint32_t)_irq2, 0x08, 0x8E); diff --git a/kernel/isr.c b/kernel/isr.c index cb59603..569ecd0 100644 --- a/kernel/isr.c +++ b/kernel/isr.c @@ -19,13 +19,12 @@ void isr_handler(struct regs_t regs) } else { - printf("WARNING: unhandled ISR!\n"); + printf("WARNING: unhandled ISR 0x%x!\n", regs.int_no); } } void isr_init(void) { - printf("ISR handlers installed.\n"); idt_set_gate(0, (uint32_t)_isr0, 0x08, 0x8E); idt_set_gate(1, (uint32_t)_isr1, 0x08, 0x8E); idt_set_gate(2, (uint32_t)_isr2, 0x08, 0x8E); diff --git a/kernel/main.c b/kernel/main.c index 6cad670..e4cf47d 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -20,11 +20,22 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) printf("Testing early I/O\n"); printf("GFX init\n"); - int gfx_status = gfx_init((struct vbe_info_t*)hdr->vbe_mode_info); + bool gfx_status = gfx_init((struct vbe_info_t*)hdr->vbe_mode_info); + + puts("test123\n"); + putchar('1'); + putchar('2'); + putchar('\n'); + putchar('1'); + putchar('2'); + gfx_drawchar(0, 12, 'a', 0xffffff, 0); /* if graphical initialization fails, fall back to text mode */ if(!gfx_status) + { tty_init(); + printf("Graphics init failed, fell back to text mode.\n"); + } if(magic != 0x2BADB002) { @@ -45,21 +56,30 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) asm("sti"); - printf("Boot finished.\n"); + //printf("Boot finished.\n"); - printf("Testing RNG...\n"); + //printf("Testing RNG...\n"); srand(*current_tick); - for(int i=0;i>=0;++i) + if(gfx_status) { - int rx = rand() % *gfx_width; - int ry = rand() % *gfx_height; + /* + for(int i=0;i<100000;++i) + { + int rx = rand() % *gfx_width; + int ry = rand() % *gfx_height; - gfx_drawpixel(rx, ry, rand() % 0xFFFFFF); + gfx_drawpixel(rx, ry, rand() % 0xFFFFFF); + } + int start = *current_tick; + for(int i=0;i<1000;++i) + gfx_clear(0xff00ff); + int end = *current_tick; + printf("ticks for 1000 fills: %x\n", end-start); + */ } - gfx_clear(0xffffff); - printf("Testing keyboard LED's...\n"); + // printf("Testing keyboard LED's...\n"); while(1) { diff --git a/libc/include/stdio.h b/libc/include/stdio.h index ac547c7..92442ac 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -1,4 +1,4 @@ -int printf(const char* fmt, ...); +int printf(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));; int puts(const char*); int putchar(int); diff --git a/libc/include/string.h b/libc/include/string.h index 650a7ac..05050a0 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -1,3 +1,4 @@ #include <stddef.h> int strlen(const char*); void* memset(void*, int, size_t); +void* memcpy(void*, void*, size_t); diff --git a/libc/string.c b/libc/string.c index 8a9e422..11d398f 100644 --- a/libc/string.c +++ b/libc/string.c @@ -18,3 +18,10 @@ void* memset(void *buf, int val, size_t sz) } return buf; } + +void* memcpy(void *dest, void *src, size_t sz) +{ + while(sz--) + *(char*)dest++ = *(char*)src++; + return dest; +} |