From 0d7cde7c4d735ebebd39b988440f50f5889bd29f Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sun, 8 Feb 2015 12:15:06 -0500 Subject: lots of stuff --- Makefile | 13 +- OBJ | 2 + bochs.cfg | 2 +- boot/head.S | 4 +- drivers/gfx-as.S | 27 + drivers/gfx.c | 55 +- drivers/gfx_font.c | 1728 ++++++++++++++++++++++++++++++++++++++++++++ drivers/include/gfx.h | 14 +- drivers/include/gfx_font.h | 4 + kernel/fpu.c | 25 + kernel/include/fpu.h | 2 + kernel/main.c | 42 +- kernel/timer.c | 3 +- 13 files changed, 1883 insertions(+), 38 deletions(-) create mode 100644 drivers/gfx-as.S create mode 100644 drivers/gfx_font.c create mode 100644 drivers/include/gfx_font.h create mode 100644 kernel/fpu.c create mode 100644 kernel/include/fpu.h diff --git a/Makefile b/Makefile index 582f7c5..476b8f7 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,16 @@ OBJ := $(shell cat OBJ) CC = gcc LD = ld -INCLUDES = -Idrivers/include -Ikernel/include -Ilibc/include -CFLAGS = -std=gnu99 -ffreestanding -fno-stack-protector -nostdlib -Wall -Wextra -m32 $(INCLUDES) -g +INCLUDES = -Idrivers/include -Ikernel/include -Ilibc/include -Iapps/ + +CFLAGS := -std=gnu99 -ffreestanding -fno-stack-protector -nostdlib -Wall -Wextra -m32 $(INCLUDES) -g -O1 -mtune=generic -msse +CFLAGS += -fexpensive-optimizations -ftree-loop-vectorize -finline-functions -fomit-frame-pointer -ftree-vectorize + QEMU = qemu-system-i386 BOCHS = bochs AS = as -ASFLAGS=-march=i686 --32 +ASFLAGS = -march=i686 --32 ISODIR = isodir @@ -34,11 +37,11 @@ iso: kappa.bin kappa.bin: $(OBJ) $(SOURCES) Makefile @$(LD) -T kernel/linker.ld -o kappa.bin -melf_i386 $(OBJ) @echo "LD $@" -%.o: %.c +%.o: %.c Makefile @$(CC) $(CFLAGS) -c $< -o $@ @echo "CC $<" -%.o: %.S +%.o: %.S Makefile @$(AS) $(ASFLAGS) -c $< -o $@ @echo "AS $<" clean: diff --git a/OBJ b/OBJ index 6eadd24..81fe9b1 100644 --- a/OBJ +++ b/OBJ @@ -1,9 +1,11 @@ boot/head.o drivers/gfx.o +drivers/gfx-as.o drivers/gfx_font.o drivers/pcspkr.o drivers/ps2.o drivers/tty.o +kernel/fpu.o kernel/gdt-as.o kernel/gdt.o kernel/idt-as.o diff --git a/bochs.cfg b/bochs.cfg index 3b61bfd..e22e703 100644 --- a/bochs.cfg +++ b/bochs.cfg @@ -19,7 +19,7 @@ ata2: enabled=0 ata3: enabled=0 pci: enabled=1, chipset=i440fx vga: extension=vbe, update_freq=5 -cpu: count=1:1:1, ips=4000000, quantum=16, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 +cpu: count=1:1:1, ips=4000000, quantum=16, model=bx_generic, reset_on_triple_fault=0, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 cpuid: level=6, stepping=3, model=3, family=6, vendor_string="AuthenticAMD", brand_string="AMD Athlon(tm) processor" cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0 cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, avx_f16c=0, avx_fma=0, bmi=0, xop=0, fma4=0 diff --git a/boot/head.S b/boot/head.S index 34edafc..8bd42f1 100644 --- a/boot/head.S +++ b/boot/head.S @@ -17,8 +17,8 @@ multiboot_header: .long 0 .long 0 .long 0 # 1=text mode - .long 640 # screen height (don't care) - .long 480 # screen width (don't care) + .long 0 # screen height (don't care) + .long 0 # screen width (don't care) .long 32 # screen BPP: MUST be 32 .section .stack diff --git a/drivers/gfx-as.S b/drivers/gfx-as.S new file mode 100644 index 0000000..70009c1 --- /dev/null +++ b/drivers/gfx-as.S @@ -0,0 +1,27 @@ + .global gfx_clear + .extern fb_width + .extern fb_height + .extern fb_bpp + .extern _gfx_bgcol + .extern framebuffer + # void gfx_clear(uint32_t color) +gfx_clear: + movzwl fb_width, %ecx + movzwl fb_height, %edx + movl framebuffer, %eax + pushl %ebx + movl _gfx_bgcol, %ebx + imull %ecx, %edx + movzbl fb_bpp, %ecx + imull %ecx, %edx + addl %eax, %edx + cmpl %edx, %eax + jnb .L2 +.L6: + movl %ebx, (%eax) + addl %ecx, %eax + cmpl %eax, %edx + ja .L6 +.L2: + popl %ebx + ret diff --git a/drivers/gfx.c b/drivers/gfx.c index 53d6686..8dc9d74 100644 --- a/drivers/gfx.c +++ b/drivers/gfx.c @@ -9,25 +9,47 @@ #include "panic.h" #include "gfx.h" -static uint8_t *framebuffer = NULL; -static uint16_t fb_width; -static uint16_t fb_height; +uint8_t *framebuffer = NULL; +uint16_t fb_width; +uint16_t fb_height; /* this is BYTES per pixel */ -static uint8_t fb_bpp; +uint8_t fb_bpp; const uint8_t *gfx_bpp = &fb_bpp; const uint16_t *gfx_width = &fb_width; const uint16_t *gfx_height = &fb_height; static int cursor_x, cursor_y; -static uint32_t fgcol, bgcol; +uint32_t _gfx_fgcol, _gfx_bgcol; -void gfx_drawpixel(int x, int y, uint32_t col) +void gfx_set_background(uint32_t col) { - ((uint32_t*)framebuffer)[y * fb_width + x] = col; + _gfx_bgcol = col; } +uint32_t gfx_get_background(void) +{ + return _gfx_bgcol; +} + +void gfx_set_foreground(uint32_t col) +{ + _gfx_fgcol = col; +} + +uint32_t gfx_get_foreground(void) +{ + return _gfx_fgcol; +} + +void gfx_drawpixel(int x, int y) +{ + ((uint32_t*)framebuffer)[y * fb_width + x] = _gfx_fgcol; +} + +/* implemented in assembly now */ +/* void gfx_clear(uint32_t col) { uint8_t *p = framebuffer; @@ -38,28 +60,29 @@ void gfx_clear(uint32_t col) p += fb_bpp; } } +*/ void gfx_reset(void) { - gfx_clear(VGA_RGBPACK(0, 0, 0)); + _gfx_fgcol = VGA_RGBPACK(0xff, 0xff, 0xff); + _gfx_bgcol = VGA_RGBPACK(0, 0, 0); + gfx_clear(); cursor_y = 0; cursor_x = 0; - fgcol = VGA_RGBPACK(0xff, 0xff, 0xff); - bgcol = VGA_RGBPACK(0, 0, 0); } -void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg) +void gfx_drawchar(int x, int y, char c) { int stride = fb_bpp * fb_width; uint8_t *line_addr = framebuffer + (x * fb_bpp) + (y * stride); for(int i = 0; i < FONT_HEIGHT; ++i) { - uint32_t line_buf[8] = {bg}; + uint32_t line_buf[8] = {_gfx_bgcol}; uint8_t mask = 0x80; for(int j = 0; j < 8; ++j, mask >>= 1) { if(gfx_font[(int)c][i] & mask) - line_buf[j] = fg; + line_buf[j] = _gfx_fgcol; } memcpy(line_addr, line_buf, sizeof(line_buf)); line_addr += stride; @@ -70,7 +93,7 @@ void gfx_putchar(char ch) { if(ch != '\n') { - gfx_drawchar(cursor_x, cursor_y, ch, fgcol, bgcol); + gfx_drawchar(cursor_x, cursor_y, ch); cursor_x += FONT_WIDTH; if(cursor_x >= fb_width) { @@ -78,7 +101,7 @@ void gfx_putchar(char ch) cursor_y += FONT_HEIGHT; if(cursor_y >= fb_height) { - gfx_clear(bgcol); + gfx_clear(); cursor_y = 0; } } @@ -89,7 +112,7 @@ void gfx_putchar(char ch) cursor_y += FONT_HEIGHT; if(cursor_y >= fb_height) { - gfx_clear(bgcol); + gfx_clear(); cursor_y = 0; } } diff --git a/drivers/gfx_font.c b/drivers/gfx_font.c new file mode 100644 index 0000000..311e86d --- /dev/null +++ b/drivers/gfx_font.c @@ -0,0 +1,1728 @@ +#include + +/* + * terminal bitmap fallback font + */ + +/* Binary Literals */ +#define b(x) ((uint8_t)b_(0 ## x ## uL)) +#define b_(x) ((x & 1) | (x >> 2 & 2) | (x >> 4 & 4) | (x >> 6 & 8) | (x >> 8 & 16) | (x >> 10 & 32) | (x >> 12 & 64) | (x >> 14 & 128)) + +const uint8_t gfx_font[][12] = { + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111110), + b(11000011), + b(10000001), /* 4 */ + b(10100101), + b(10000001), + b(10111101), + b(10011001), /* 8 */ + b(11000011), + b(01111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111110), + b(11111111), + b(11111111), /* 4 */ + b(11011011), + b(11111111), + b(11000011), + b(11100111), /* 8 */ + b(11111111), + b(01111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(01000100), + b(11101110), /* 4 */ + b(11111110), + b(11111110), + b(11111110), + b(01111100), /* 8 */ + b(00111000), + b(00010000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00010000), + b(00111000), + b(01111100), /* 4 */ + b(11111110), + b(11111110), + b(01111100), + b(00111000), /* 8 */ + b(00010000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00111100), + b(00111100), /* 4 */ + b(11111111), + b(11100111), + b(11100111), + b(00011000), /* 8 */ + b(00011000), + b(01111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00111100), + b(01111110), /* 4 */ + b(11111111), + b(11111111), + b(01111110), + b(00011000), /* 8 */ + b(00011000), + b(01111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00111100), + b(01111110), + b(01111110), + b(00111100), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(11111111), + b(11111111), + b(11111111), + b(11111111), /* 4 */ + b(11000011), + b(10000001), + b(10000001), + b(11000011), /* 8 */ + b(11111111), + b(11111111), + b(11111111), + b(11111111) /* 01 */ + }, + { b(00000000), + b(00000000), + b(00111100), + b(01111110), /* 4 */ + b(01100110), + b(01000010), + b(01000010), + b(01100110), /* 8 */ + b(01111110), + b(00111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(11111111), + b(11111111), + b(11000011), + b(10000001), /* 4 */ + b(10011001), + b(10111101), + b(10111101), + b(10011001), /* 8 */ + b(10000001), + b(11000011), + b(11111111), + b(11111111) /* 01 */ + }, + { b(00000000), + b(00111110), + b(00001110), + b(00111010), /* 4 */ + b(01110010), + b(11111000), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111100), + b(01100110), + b(01100110), /* 4 */ + b(01100110), + b(00111100), + b(00011000), + b(01111110), /* 8 */ + b(00011000), + b(00011000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011111), + b(00011001), + b(00011001), /* 4 */ + b(00011111), + b(00011000), + b(00011000), + b(01111000), /* 8 */ + b(11111000), + b(01110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111111), + b(01100011), + b(01111111), /* 4 */ + b(01100011), + b(01100011), + b(01100011), + b(01100111), /* 8 */ + b(11100111), + b(11100110), + b(11000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00011000), + b(11011011), /* 4 */ + b(01111110), + b(11100111), + b(11100111), + b(01111110), /* 8 */ + b(11011011), + b(00011000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(10000000), + b(11000000), + b(11100000), /* 4 */ + b(11111000), + b(11111110), + b(11111000), + b(11100000), /* 8 */ + b(11000000), + b(10000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000010), + b(00000110), + b(00001110), /* 4 */ + b(00111110), + b(11111110), + b(00111110), + b(00001110), /* 8 */ + b(00000110), + b(00000010), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00111100), + b(01111110), /* 4 */ + b(00011000), + b(00011000), + b(00011000), + b(01111110), /* 8 */ + b(00111100), + b(00011000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01100110), + b(01100110), + b(01100110), /* 4 */ + b(01100110), + b(01100110), + b(00000000), + b(00000000), /* 8 */ + b(01100110), + b(01100110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111111), + b(11011011), + b(11011011), /* 4 */ + b(11011011), + b(01111011), + b(00011011), + b(00011011), /* 8 */ + b(00011011), + b(00011011), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111110), + b(01100011), + b(00110000), /* 4 */ + b(00111100), + b(01100110), + b(01100110), + b(00111100), /* 8 */ + b(00001100), + b(11000110), + b(01111110), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(11111110), /* 8 */ + b(11111110), + b(11111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00111100), + b(01111110), /* 4 */ + b(00011000), + b(00011000), + b(00011000), + b(01111110), /* 8 */ + b(00111100), + b(00011000), + b(01111110), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00111100), + b(01111110), /* 4 */ + b(00011000), + b(00011000), + b(00011000), + b(00011000), /* 8 */ + b(00011000), + b(00011000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00011000), + b(00011000), /* 4 */ + b(00011000), + b(00011000), + b(00011000), + b(01111110), /* 8 */ + b(00111100), + b(00011000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00011000), /* 4 */ + b(00001100), + b(11111110), + b(00001100), + b(00011000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00110000), /* 4 */ + b(01100000), + b(11111110), + b(01100000), + b(00110000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11000000), + b(11000000), + b(11111110), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00100100), /* 4 */ + b(01100110), + b(11111111), + b(01100110), + b(00100100), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00010000), + b(00010000), /* 4 */ + b(00111000), + b(00111000), + b(01111100), + b(01111100), /* 8 */ + b(11111110), + b(11111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(11111110), + b(11111110), /* 4 */ + b(01111100), + b(01111100), + b(00111000), + b(00111000), /* 8 */ + b(00010000), + b(00010000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00110000), + b(01111000), + b(01111000), /* 4 */ + b(00110000), + b(00110000), + b(00000000), + b(00110000), /* 8 */ + b(00110000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01100110), + b(01100110), + b(00100100), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01101100), + b(01101100), + b(11111110), /* 4 */ + b(01101100), + b(01101100), + b(01101100), + b(11111110), /* 8 */ + b(01101100), + b(01101100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00110000), + b(00110000), + b(01111100), + b(11000000), /* 4 */ + b(11000000), + b(01111000), + b(00001100), + b(00001100), /* 8 */ + b(11111000), + b(00110000), + b(00110000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(11000100), + b(11001100), /* 4 */ + b(00011000), + b(00110000), + b(01100000), + b(11001100), /* 8 */ + b(10001100), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01110000), + b(11011000), + b(11011000), /* 4 */ + b(01110000), + b(11111010), + b(11011110), + b(11001100), /* 8 */ + b(11011100), + b(01110110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00110000), + b(00110000), + b(00110000), /* 4 */ + b(01100000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00001100), + b(00011000), + b(00110000), /* 4 */ + b(01100000), + b(01100000), + b(01100000), + b(00110000), /* 8 */ + b(00011000), + b(00001100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01100000), + b(00110000), + b(00011000), /* 4 */ + b(00001100), + b(00001100), + b(00001100), + b(00011000), /* 8 */ + b(00110000), + b(01100000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(01100110), /* 4 */ + b(00111100), + b(11111111), + b(00111100), + b(01100110), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /** 4 */ + b(00011000), + b(00011000), + b(01111110), + b(00011000), /* 8 */ + b(00011000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00111000), + b(00111000), + b(01100000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(11111110), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00111000), + b(00111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000010), + b(00000110), /* 4 */ + b(00001100), + b(00011000), + b(00110000), + b(01100000), /* 8 */ + b(11000000), + b(10000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111100), + b(11000110), + b(11001110), /* 4 */ + b(11011110), + b(11010110), + b(11110110), + b(11100110), /* 8 */ + b(11000110), + b(01111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00010000), + b(00110000), + b(11110000), /* 4 */ + b(00110000), + b(00110000), + b(00110000), + b(00110000), /* 8 */ + b(00110000), + b(11111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(11001100), + b(11001100), /* 4 */ + b(00001100), + b(00011000), + b(00110000), + b(01100000), /* 8 */ + b(11001100), + b(11111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(11001100), + b(00001100), /* 4 */ + b(00001100), + b(00111000), + b(00001100), + b(00001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00001100), + b(00011100), + b(00111100), /* 4 */ + b(01101100), + b(11001100), + b(11111110), + b(00001100), /* 8 */ + b(00001100), + b(00011110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111100), + b(11000000), + b(11000000), /* 4 */ + b(11000000), + b(11111000), + b(00001100), + b(00001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111000), + b(01100000), + b(11000000), /* 4 */ + b(11000000), + b(11111000), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111110), + b(11000110), + b(11000110), /* 4 */ + b(00000110), + b(00001100), + b(00011000), + b(00110000), /* 8 */ + b(00110000), + b(00110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(11001100), + b(11001100), /* 4 */ + b(11001100), + b(01111000), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(11001100), + b(11001100), /* 4 */ + b(11001100), + b(01111100), + b(00011000), + b(00011000), /* 8 */ + b(00110000), + b(01110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00111000), /* 4 */ + b(00111000), + b(00000000), + b(00000000), + b(00111000), /* 8 */ + b(00111000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00111000), /* 4 */ + b(00111000), + b(00000000), + b(00000000), + b(00111000), /* 8 */ + b(00111000), + b(00011000), + b(00110000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00001100), + b(00011000), + b(00110000), /* 4 */ + b(01100000), + b(11000000), + b(01100000), + b(00110000), /* 8 */ + b(00011000), + b(00001100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01111110), + b(00000000), + b(01111110), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01100000), + b(00110000), + b(00011000), /* 4 */ + b(00001100), + b(00000110), + b(00001100), + b(00011000), /* 8 */ + b(00110000), + b(01100000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(11001100), + b(00001100), /* 4 */ + b(00011000), + b(00110000), + b(00110000), + b(00000000), /* 8 */ + b(00110000), + b(00110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111100), + b(11000110), + b(11000110), /* 4 */ + b(11011110), + b(11010110), + b(11011110), + b(11000000), /* 8 */ + b(11000000), + b(01111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00110000), + b(01111000), + b(11001100), /* 4 */ + b(11001100), + b(11001100), + b(11111100), + b(11001100), /* 8 */ + b(11001100), + b(11001100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111100), + b(01100110), + b(01100110), /* 4 */ + b(01100110), + b(01111100), + b(01100110), + b(01100110), /* 8 */ + b(01100110), + b(11111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111100), + b(01100110), + b(11000110), /* 4 */ + b(11000000), + b(11000000), + b(11000000), + b(11000110), /* 8 */ + b(01100110), + b(00111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111000), + b(01101100), + b(01100110), /* 4 */ + b(01100110), + b(01100110), + b(01100110), + b(01100110), /* 8 */ + b(01101100), + b(11111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111110), + b(01100010), + b(01100000), /* 4 */ + b(01100100), + b(01111100), + b(01100100), + b(01100000), /* 8 */ + b(01100010), + b(11111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111110), + b(01100110), + b(01100010), /* 4 */ + b(01100100), + b(01111100), + b(01100100), + b(01100000), /* 8 */ + b(01100000), + b(11110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111100), + b(01100110), + b(11000110), /* 4 */ + b(11000000), + b(11000000), + b(11001110), + b(11000110), /* 8 */ + b(01100110), + b(00111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11001100), + b(11001100), + b(11001100), /* 4 */ + b(11001100), + b(11111100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(11001100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(00110000), + b(00110000), /* 4 */ + b(00110000), + b(00110000), + b(00110000), + b(00110000), /* 8 */ + b(00110000), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011110), + b(00001100), + b(00001100), /* 4 */ + b(00001100), + b(00001100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11100110), + b(01100110), + b(01101100), /* 4 */ + b(01101100), + b(01111000), + b(01101100), + b(01101100), /* 8 */ + b(01100110), + b(11100110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11110000), + b(01100000), + b(01100000), /* 4 */ + b(01100000), + b(01100000), + b(01100010), + b(01100110), /* 8 */ + b(01100110), + b(11111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11000110), + b(11101110), + b(11111110), /* 4 */ + b(11111110), + b(11010110), + b(11000110), + b(11000110), /* 8 */ + b(11000110), + b(11000110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11000110), + b(11000110), + b(11100110), /* 4 */ + b(11110110), + b(11111110), + b(11011110), + b(11001110), /* 8 */ + b(11000110), + b(11000110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111000), + b(01101100), + b(11000110), /* 4 */ + b(11000110), + b(11000110), + b(11000110), + b(11000110), /* 8 */ + b(01101100), + b(00111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111100), + b(01100110), + b(01100110), /* 4 */ + b(01100110), + b(01111100), + b(01100000), + b(01100000), /* 8 */ + b(01100000), + b(11110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111000), + b(01101100), + b(11000110), /* 4 */ + b(11000110), + b(11000110), + b(11001110), + b(11011110), /* 8 */ + b(01111100), + b(00001100), + b(00011110), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111100), + b(01100110), + b(01100110), /* 4 */ + b(01100110), + b(01111100), + b(01101100), + b(01100110), /* 8 */ + b(01100110), + b(11100110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(11001100), + b(11001100), /* 4 */ + b(11000000), + b(01110000), + b(00011000), + b(11001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111100), + b(10110100), + b(00110000), /* 4 */ + b(00110000), + b(00110000), + b(00110000), + b(00110000), /* 8 */ + b(00110000), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11001100), + b(11001100), + b(11001100), /* 4 */ + b(11001100), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11001100), + b(11001100), + b(11001100), /* 4 */ + b(11001100), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(01111000), + b(00110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11000110), + b(11000110), + b(11000110), /* 4 */ + b(11000110), + b(11010110), + b(11010110), + b(01101100), /* 8 */ + b(01101100), + b(01101100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11001100), + b(11001100), + b(11001100), /* 4 */ + b(01111000), + b(00110000), + b(01111000), + b(11001100), /* 8 */ + b(11001100), + b(11001100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11001100), + b(11001100), + b(11001100), /* 4 */ + b(11001100), + b(01111000), + b(00110000), + b(00110000), /* 8 */ + b(00110000), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111110), + b(11001110), + b(10011000), /* 4 */ + b(00011000), + b(00110000), + b(01100000), + b(01100010), /* 8 */ + b(11000110), + b(11111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111100), + b(00110000), + b(00110000), /* 4 */ + b(00110000), + b(00110000), + b(00110000), + b(00110000), /* 8 */ + b(00110000), + b(00111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(10000000), + b(11000000), + b(01100000), /* 4 */ + b(00110000), + b(00011000), + b(00001100), + b(00000110), /* 8 */ + b(00000010), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111100), + b(00001100), + b(00001100), /* 4 */ + b(00001100), + b(00001100), + b(00001100), + b(00001100), /* 8 */ + b(00001100), + b(00111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00010000), + b(00111000), + b(01101100), + b(11000110), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(11111111), + b(00000000) /* 12 */ + }, + { b(00110000), + b(00110000), + b(00011000), + b(00000000), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01111000), + b(00001100), + b(01111100), + b(11001100), /* 8 */ + b(11001100), + b(01110110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11100000), + b(01100000), + b(01100000), /* 4 */ + b(01111100), + b(01100110), + b(01100110), + b(01100110), /* 8 */ + b(01100110), + b(11011100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01111000), + b(11001100), + b(11000000), + b(11000000), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011100), + b(00001100), + b(00001100), /* 4 */ + b(01111100), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01110110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01111000), + b(11001100), + b(11111100), + b(11000000), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00111000), + b(01101100), + b(01100000), /* 4 */ + b(01100000), + b(11111000), + b(01100000), + b(01100000), /* 8 */ + b(01100000), + b(11110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01110110), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(01111100), + b(00001100), + b(11001100), + b(01111000) /* 12 */ + }, + { b(00000000), + b(11100000), + b(01100000), + b(01100000), /* 4 */ + b(01101100), + b(01110110), + b(01100110), + b(01100110), /* 8 */ + b(01100110), + b(11100110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00011000), + b(00000000), /* 4 */ + b(01111000), + b(00011000), + b(00011000), + b(00011000), /* 8 */ + b(00011000), + b(01111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00001100), + b(00001100), + b(00000000), /* 4 */ + b(00011100), + b(00001100), + b(00001100), + b(00001100), /* 8 */ + b(00001100), + b(11001100), + b(11001100), + b(01111000) /* 12 */ + }, + { b(00000000), + b(11100000), + b(01100000), + b(01100000), /* 4 */ + b(01100110), + b(01101100), + b(01111000), + b(01101100), /* 8 */ + b(01100110), + b(11100110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01111000), + b(00011000), + b(00011000), /* 4 */ + b(00011000), + b(00011000), + b(00011000), + b(00011000), /* 8 */ + b(00011000), + b(01111110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11111100), + b(11010110), + b(11010110), + b(11010110), /* 8 */ + b(11010110), + b(11000110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11111000), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(11001100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01111000), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11011100), + b(01100110), + b(01100110), + b(01100110), /* 8 */ + b(01100110), + b(01111100), + b(01100000), + b(11110000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01110110), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01111100), + b(00001100), + b(00011110) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11101100), + b(01101110), + b(01110110), + b(01100000), /* 8 */ + b(01100000), + b(11110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01111000), + b(11001100), + b(01100000), + b(00011000), /* 8 */ + b(11001100), + b(01111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00100000), + b(01100000), /* 4 */ + b(11111100), + b(01100000), + b(01100000), + b(01100000), /* 8 */ + b(01101100), + b(00111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11001100), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(11001100), + b(01110110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11001100), + b(11001100), + b(11001100), + b(11001100), /* 8 */ + b(01111000), + b(00110000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11000110), + b(11000110), + b(11010110), + b(11010110), /* 8 */ + b(01101100), + b(01101100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11000110), + b(01101100), + b(00111000), + b(00111000), /* 8 */ + b(01101100), + b(11000110), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(01100110), + b(01100110), + b(01100110), + b(01100110), /* 8 */ + b(00111100), + b(00001100), + b(00011000), + b(11110000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 4 */ + b(11111100), + b(10001100), + b(00011000), + b(01100000), /* 8 */ + b(11000100), + b(11111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011100), + b(00110000), + b(00110000), /* 4 */ + b(01100000), + b(11000000), + b(01100000), + b(00110000), /* 8 */ + b(00110000), + b(00011100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00011000), + b(00011000), + b(00011000), /* 4 */ + b(00011000), + b(00000000), + b(00011000), + b(00011000), /* 8 */ + b(00011000), + b(00011000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11100000), + b(00110000), + b(00110000), /* 4 */ + b(00011000), + b(00001100), + b(00011000), + b(00110000), /* 8 */ + b(00110000), + b(11100000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01110011), + b(11011010), + b(11001110), /* 4 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000), /* 8 */ + b(00000000), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00000000), + b(00000000), + b(00010000), /* 4 */ + b(00111000), + b(01101100), + b(11000110), + b(11000110), /* 8 */ + b(11111110), + b(00000000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01000100), + b(01101100), + b(00111000), /* 4 */ + b(00110000), + b(01100000), + b(11000000), + b(11000000), /* 8 */ + b(01100000), + b(00111000), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(00110000), + b(00110000), + b(11111110), /* 4 */ + b(00110000), + b(00110000), + b(01111010), + b(10110110), /* 8 */ + b(01111100), + b(00110010), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(11111110), + b(00001100), + b(00011000), /* 4 */ + b(00110000), + b(00011000), + b(00001100), + b(01110110), /* 8 */ + b(11000110), + b(01111100), + b(00000000), + b(00000000) /* 12 */ + }, + { b(00000000), + b(01100110), + b(01100110), + b(01100110), /* 4 */ + b(01100110), + b(00000000), + b(00000000), + b(00111100), /* 8 */ + b(01100110), + b(11000011), + b(00000000), + b(00000000) /* 12 */ + }, +}; diff --git a/drivers/include/gfx.h b/drivers/include/gfx.h index 182428e..42ada32 100644 --- a/drivers/include/gfx.h +++ b/drivers/include/gfx.h @@ -34,18 +34,26 @@ struct vbe_info_t; bool gfx_init(struct vbe_info_t *vbe_mode_info); -void gfx_drawpixel(int x, int y, uint32_t color); +void gfx_drawpixel(int x, int y); -void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg); +void gfx_drawchar(int x, int y, char ch); void gfx_putchar(char ch); void gfx_puts(const char* str); -void gfx_clear(uint32_t color); +void gfx_clear(void); void gfx_reset(void); +void gfx_set_foreground(uint32_t); + +uint32_t gfx_get_foreground(void); + +void gfx_set_background(uint32_t); + +uint32_t gfx_get_background(void); + extern const uint16_t *gfx_width, *gfx_height; /* this is _BYTES_ per pixel, NOT BITS per pixel! */ diff --git a/drivers/include/gfx_font.h b/drivers/include/gfx_font.h new file mode 100644 index 0000000..f7db9d7 --- /dev/null +++ b/drivers/include/gfx_font.h @@ -0,0 +1,4 @@ +#include +#define FONT_WIDTH 8 +#define FONT_HEIGHT 12 +extern const uint8_t gfx_font[][FONT_HEIGHT]; diff --git a/kernel/fpu.c b/kernel/fpu.c new file mode 100644 index 0000000..f5512d6 --- /dev/null +++ b/kernel/fpu.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2011-2013 Kevin Lange */ +/* this code from toaruos */ +#include +#include "fpu.h" + +/** + * Enable the FPU and SSE + */ +void fpu_enable(void) { + asm volatile ("clts"); + size_t t; + asm volatile ("mov %%cr4, %0" : "=r"(t)); + t |= 3 << 9; + asm volatile ("mov %0, %%cr4" :: "r"(t)); +} + +/** + * Disable FPU and SSE so it traps to the kernel + */ +void fpu_disable(void) { + size_t t; + asm volatile ("mov %%cr0, %0" : "=r"(t)); + t |= 1 << 3; + asm volatile ("mov %0, %%cr0" :: "r"(t)); +} diff --git a/kernel/include/fpu.h b/kernel/include/fpu.h new file mode 100644 index 0000000..da2b48a --- /dev/null +++ b/kernel/include/fpu.h @@ -0,0 +1,2 @@ +void enable_fpu(void); +void disable_fpu(void); diff --git a/kernel/main.c b/kernel/main.c index 336b31c..927a497 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -11,11 +11,22 @@ #include "panic.h" #include "pcspkr.h" #include "ps2.h" +#include "fpu.h" #include "timer.h" #include "tty.h" +void gpf(struct regs_t regs) +{ + printf("General protection fault!\n"); + printf("EIP before fault: 0x%x\n", regs.eip); + printf("Error code: %d\n", regs.err_code); + panic("GPF"); +} + void main(struct multiboot_info_t *hdr, uint32_t magic) { + fpu_enable(); + asm("movq %xmm0, %xmm0"); /* this should go to port e9, which is the Bochs debug port */ printf("Testing early I/O\n"); @@ -46,6 +57,8 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) timer_init(HZ); ps2_init(); + set_interrupt_handler(0xd, gpf); + asm("sti"); printf("Boot finished.\n"); @@ -61,27 +74,35 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) int rx = rand() % *gfx_width; int ry = rand() % *gfx_height; - gfx_drawpixel(rx, ry, rand() % 0xFFFFFF); + gfx_set_foreground(rand() % 0x1000000); + gfx_drawpixel(rx, ry); } int endpix = *current_tick; int startfill = *current_tick; - for(int i=0;i<100;++i) - gfx_clear(rand() % 0xFFFFFF); + for(int i=0;i<1000;++i) + { + gfx_set_background(rand() % 0x1000000); + gfx_clear(); + } int endfill = *current_tick; + gfx_set_background(0); + gfx_set_foreground(0xFFFFFF); + gfx_clear(); int starttext = *current_tick; for(int i=0;i<1000000;++i) { int rx = rand() % *gfx_width; int ry = rand() % *gfx_height; - gfx_drawchar(rx, ry, 'A', VGA_RGBPACK(0xff, 0xff, 0xff), 0); + gfx_drawchar(rx, ry, rand()%127+1); } int endtext = *current_tick; gfx_reset(); printf("--- Graphics benchmark results ---\n"); printf("Ticks for 1,000,000 random pixels: %d\n", endpix-startpix); - printf("Ticks for 100 random fills: %d\n", endfill-startfill); - printf("Ticks for 1,000,000 chars: %d\n", endtext-starttext); + printf("Ticks for 1,000 random fills: %d\n", endfill-startfill); + printf("Ticks for 1,000,000 random chars: %d\n", endtext-starttext); + printf("Ticks per second: %d\n", HZ); printf("Resolution: %dx%dx%d\n", *gfx_width, *gfx_height, *gfx_bpp * 8); } @@ -90,12 +111,13 @@ void main(struct multiboot_info_t *hdr, uint32_t magic) while(1) { ps2_set_leds(PS2_NUM_LOCK); - for(int i=0;i<50000000;++i); + timer_delay(HZ/4); ps2_set_leds(PS2_CAPS_LOCK); - for(int i=0;i<50000000;++i); + timer_delay(HZ/4); ps2_set_leds(PS2_SCROLL_LOCK); - for(int i=0;i<50000000;++i); + timer_delay(HZ/4); ps2_set_leds(PS2_CAPS_LOCK); - for(int i=0;i<50000000;++i); + timer_delay(HZ/4); } + while(1); } diff --git a/kernel/timer.c b/kernel/timer.c index 2fbd8eb..7bdc1f9 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -32,5 +32,6 @@ void timer_init(uint32_t freq) void timer_delay(uint64_t ticks) { uint64_t end = *current_tick + ticks; - while(*current_tick <= end); + while(*current_tick <= end) + asm("hlt"); } -- cgit v1.1