aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-07 20:14:30 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-07 20:14:30 -0500
commitea15c8963fa17deaba4356219e481128db66f5bc (patch)
tree0e426f2b61a269bb747c48981dd5dfc47913cef3
parentc3b4bab880c9b3426db6252240ea3ab7838fa17b (diff)
downloadkappa-ea15c8963fa17deaba4356219e481128db66f5bc.zip
kappa-ea15c8963fa17deaba4356219e481128db66f5bc.tar.gz
kappa-ea15c8963fa17deaba4356219e481128db66f5bc.tar.bz2
kappa-ea15c8963fa17deaba4356219e481128db66f5bc.tar.xz
add benchmark
-rw-r--r--boot/head.S4
-rw-r--r--drivers/gfx.c22
-rw-r--r--drivers/include/gfx.h11
-rw-r--r--kernel/main.c28
4 files changed, 49 insertions, 16 deletions
diff --git a/boot/head.S b/boot/head.S
index 8bd42f1..34edafc 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 0 # screen height (don't care)
- .long 0 # screen width (don't care)
+ .long 640 # screen height (don't care)
+ .long 480 # screen width (don't care)
.long 32 # screen BPP: MUST be 32
.section .stack
diff --git a/drivers/gfx.c b/drivers/gfx.c
index bcc103a..53d6686 100644
--- a/drivers/gfx.c
+++ b/drivers/gfx.c
@@ -15,10 +15,14 @@ static uint16_t fb_height;
/* this is BYTES per pixel */
static 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;
+
void gfx_drawpixel(int x, int y, uint32_t col)
{
((uint32_t*)framebuffer)[y * fb_width + x] = col;
@@ -35,6 +39,15 @@ void gfx_clear(uint32_t col)
}
}
+void gfx_reset(void)
+{
+ 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);
+}
+
void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg)
{
int stride = fb_bpp * fb_width;
@@ -53,9 +66,6 @@ void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg)
}
}
-static int cursor_x, cursor_y;
-static uint32_t fgcol, bgcol;
-
void gfx_putchar(char ch)
{
if(ch != '\n')
@@ -104,11 +114,7 @@ bool gfx_init(struct vbe_info_t *vbe_mode_info)
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);
+ gfx_reset();
set_putchar(gfx_putchar);
set_puts(gfx_puts);
diff --git a/drivers/include/gfx.h b/drivers/include/gfx.h
index 19019a9..182428e 100644
--- a/drivers/include/gfx.h
+++ b/drivers/include/gfx.h
@@ -36,6 +36,17 @@ bool gfx_init(struct vbe_info_t *vbe_mode_info);
void gfx_drawpixel(int x, int y, uint32_t color);
+void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg);
+
+void gfx_putchar(char ch);
+
+void gfx_puts(const char* str);
+
void gfx_clear(uint32_t color);
+void gfx_reset(void);
+
extern const uint16_t *gfx_width, *gfx_height;
+
+/* this is _BYTES_ per pixel, NOT BITS per pixel! */
+extern const uint8_t *gfx_bpp;
diff --git a/kernel/main.c b/kernel/main.c
index dd05880..336b31c 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -55,18 +55,34 @@ void main(struct multiboot_info_t *hdr, uint32_t magic)
if(gfx_status)
{
- for(int i=0;i<100000;++i)
+ int startpix = *current_tick;
+ for(int i=0;i<1000000;++i)
{
int rx = rand() % *gfx_width;
int ry = rand() % *gfx_height;
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);
+ int endpix = *current_tick;
+ int startfill = *current_tick;
+ for(int i=0;i<100;++i)
+ gfx_clear(rand() % 0xFFFFFF);
+ int endfill = *current_tick;
+
+ 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);
+ }
+ 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("Resolution: %dx%dx%d\n", *gfx_width, *gfx_height, *gfx_bpp * 8);
}
printf("Testing keyboard LED's...\n");