summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimapr <kimapr@mail.ru>2023-12-15 23:12:38 +0500
committerLizzy Fleckenstein <lizzy@vlhl.dev>2023-12-19 06:40:55 +0100
commita6b460d3b1b0909e0c7b388f1a55365bf24c6b7b (patch)
tree73484f566e56393122f20ddbd75f92752f992ac7
parenteef564059f773e5d29b1f6e547b8b0a3c50dfab2 (diff)
downloadcuddles-a6b460d3b1b0909e0c7b388f1a55365bf24c6b7b.tar.xz
gfx: use barriers; fix entry symbol linking order
-rw-r--r--Makefile4
-rw-r--r--stage3/def.h3
-rw-r--r--stage3/gfx.c16
-rw-r--r--stage3/init.c6
-rw-r--r--stage3/main.c7
5 files changed, 24 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index e417084..0cb067c 100644
--- a/Makefile
+++ b/Makefile
@@ -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"