diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | stage3/def.h | 3 | ||||
-rw-r--r-- | stage3/gfx.c | 16 | ||||
-rw-r--r-- | stage3/init.c | 6 | ||||
-rw-r--r-- | stage3/main.c | 7 |
5 files changed, 24 insertions, 12 deletions
@@ -14,6 +14,7 @@ override CFLAGS += \ -Wextra STAGE3 = \ + stage3/init.o \ stage3/main.o \ stage3/gfx.o \ stage3/halt.o \ @@ -83,6 +84,9 @@ bochs: cuddles.img qemu: cuddles.img qemu-system-x86_64 -drive format=raw,file=cuddles.img +qemu_slow: cuddles.img + qemu-system-x86_64 -icount shift=9,align=on,sleep=on -drive format=raw,file=cuddles.img + run: qemu clean: diff --git a/stage3/def.h b/stage3/def.h index 1da628e..f125a01 100644 --- a/stage3/def.h +++ b/stage3/def.h @@ -32,4 +32,7 @@ typedef struct { #define S(x) ((str) { sizeof (x) - 1, (x) }) #define NILS ((str) { 0, nil }) +#define BARRIER_VAR(var) asm volatile(""::"m"(var)) +#define BARRIER() asm volatile("":::"memory") + #endif diff --git a/stage3/gfx.c b/stage3/gfx.c index b01e89a..70a68d9 100644 --- a/stage3/gfx.c +++ b/stage3/gfx.c @@ -15,7 +15,9 @@ u32 make_color(color col) void gfx_set_pixel(u16 x, u16 y, u32 col) { - *((u32 *) (u64) (gfx_info->framebuffer + y * gfx_info->pitch + x * sizeof col)) = col; + u32 *out = (u32 *) (u64) (gfx_info->framebuffer + y * gfx_info->pitch + x * sizeof col); + *out = col; + BARRIER_VAR(out); } void gfx_set_area(u16 x, u16 y, u16 w, u16 h, u32 col) @@ -24,12 +26,14 @@ void gfx_set_area(u16 x, u16 y, u16 w, u16 h, u32 col) void *cend = cbeg + h * gfx_info->pitch; for (; cbeg < cend; cbeg += gfx_info->pitch) { - void *rbeg = cbeg; - void *rend = rbeg + w * sizeof col; + u32 *rbeg = cbeg; + u32 *rend = rbeg + w; - for (; rbeg < rend; rbeg += sizeof col) - *((u32 *) rbeg) = col; + for (; rbeg < rend; rbeg++) + *rbeg = col; } + + BARRIER_VAR(cbeg); } void gfx_draw_img(u16 x, u16 y, u16 w, u16 h, u32 *img) @@ -37,4 +41,6 @@ void gfx_draw_img(u16 x, u16 y, u16 w, u16 h, u32 *img) void *cbeg = (void *) (u64) (gfx_info->framebuffer + y * gfx_info->pitch + x * sizeof(color)); for (u16 yi = 0; yi < h; cbeg += gfx_info->pitch, yi++) memcpy(cbeg, img + yi * w, w * sizeof(color)); + + BARRIER_VAR(cbeg); } diff --git a/stage3/init.c b/stage3/init.c new file mode 100644 index 0000000..e913fee --- /dev/null +++ b/stage3/init.c @@ -0,0 +1,6 @@ +void kmain(); + +void init() +{ + kmain(); +} diff --git a/stage3/main.c b/stage3/main.c index 9a6f431..10fde84 100644 --- a/stage3/main.c +++ b/stage3/main.c @@ -1,10 +1,3 @@ -void kmain(); - -void init() -{ - kmain(); -} - #include "def.h" #include "paging.h" #include "gfx.h" |