From 0ae9ad7d929d93227c818334b135397ae25a34db Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 20 Aug 2020 23:54:01 +0200 Subject: [PATCH] protect vga access from mutlithread --- drivers/vga.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/vga.c b/drivers/vga.c index a391992..1558316 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -1,6 +1,7 @@ #include "vga.h" #include "io.h" #include "klibc.h" +#include "irq.h" static uint vgaBgColor; static uint vgaColor; @@ -18,20 +19,28 @@ int VGASetup(uint bgColor, uint color) void clearScreen(uint bgColor) { + uint32_t flags; volatile short *vga = (short *)VGA_ADDR; long int colorAttr = bgColor << 12; + + disable_IRQs(flags); for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) { vga[i] = colorAttr; } + restore_IRQs(flags); } void clearScreenLine(uint bgColor, uint line) { + uint32_t flags; volatile short *vga = (short *)VGA_ADDR; long int colorAttr = bgColor << 12; + + disable_IRQs(flags); for (uint i = VGA_WIDTH * line; i < VGA_WIDTH * (line + 1); i++) { vga[i] = colorAttr; } + restore_IRQs(flags); } void printIntDetails(int integer, uint color, uint bgColor, int startX, int startY) @@ -67,6 +76,9 @@ void vgaScrollUp(void) { long int colorAttr = vgaBgColor << 12; volatile short *vga = (short *)VGA_ADDR; + int flags; + + disable_IRQs(flags); for (int i = 1; i < VGA_HEIGHT - 1; i++) { // last line is status line. Do not scroll it memcpy((void *)&vga[VGA_WIDTH * (i - 1)], (void *)&vga[VGA_WIDTH * i], VGA_WIDTH * sizeof(short)); @@ -74,10 +86,14 @@ void vgaScrollUp(void) for (int i = 0; i < VGA_WIDTH; i++) { vga[(VGA_HEIGHT - 2) * VGA_WIDTH + i] = colorAttr; } + restore_IRQs(flags); } void VGAputc(const char str) { + int flags; + + disable_IRQs(flags); if (str == '\n') { line++; col = 0; @@ -106,18 +122,23 @@ void VGAputc(const char str) } } cursorMove(col, line); + restore_IRQs(flags); } void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY) { + uint32_t flags; volatile short *vga = (short *)VGA_ADDR; int i = 0; long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8; + + disable_IRQs(flags); while (*str) { vga[VGA_WIDTH * startY + startX + i] = colorAttr | *str; str++; i++; } + restore_IRQs(flags); } void cursorEnable(uint8_t cursor_start, uint8_t cursor_end)