protect vga access from mutlithread

This commit is contained in:
Mathieu Maret 2020-08-20 23:54:01 +02:00
parent 9fe6d3c7df
commit 0ae9ad7d92

View File

@ -1,6 +1,7 @@
#include "vga.h" #include "vga.h"
#include "io.h" #include "io.h"
#include "klibc.h" #include "klibc.h"
#include "irq.h"
static uint vgaBgColor; static uint vgaBgColor;
static uint vgaColor; static uint vgaColor;
@ -18,20 +19,28 @@ int VGASetup(uint bgColor, uint color)
void clearScreen(uint bgColor) void clearScreen(uint bgColor)
{ {
uint32_t flags;
volatile short *vga = (short *)VGA_ADDR; volatile short *vga = (short *)VGA_ADDR;
long int colorAttr = bgColor << 12; long int colorAttr = bgColor << 12;
disable_IRQs(flags);
for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) { for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) {
vga[i] = colorAttr; vga[i] = colorAttr;
} }
restore_IRQs(flags);
} }
void clearScreenLine(uint bgColor, uint line) void clearScreenLine(uint bgColor, uint line)
{ {
uint32_t flags;
volatile short *vga = (short *)VGA_ADDR; volatile short *vga = (short *)VGA_ADDR;
long int colorAttr = bgColor << 12; long int colorAttr = bgColor << 12;
disable_IRQs(flags);
for (uint i = VGA_WIDTH * line; i < VGA_WIDTH * (line + 1); i++) { for (uint i = VGA_WIDTH * line; i < VGA_WIDTH * (line + 1); i++) {
vga[i] = colorAttr; vga[i] = colorAttr;
} }
restore_IRQs(flags);
} }
void printIntDetails(int integer, uint color, uint bgColor, int startX, int startY) void printIntDetails(int integer, uint color, uint bgColor, int startX, int startY)
@ -67,6 +76,9 @@ void vgaScrollUp(void)
{ {
long int colorAttr = vgaBgColor << 12; long int colorAttr = vgaBgColor << 12;
volatile short *vga = (short *)VGA_ADDR; 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 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], memcpy((void *)&vga[VGA_WIDTH * (i - 1)], (void *)&vga[VGA_WIDTH * i],
VGA_WIDTH * sizeof(short)); VGA_WIDTH * sizeof(short));
@ -74,10 +86,14 @@ void vgaScrollUp(void)
for (int i = 0; i < VGA_WIDTH; i++) { for (int i = 0; i < VGA_WIDTH; i++) {
vga[(VGA_HEIGHT - 2) * VGA_WIDTH + i] = colorAttr; vga[(VGA_HEIGHT - 2) * VGA_WIDTH + i] = colorAttr;
} }
restore_IRQs(flags);
} }
void VGAputc(const char str) void VGAputc(const char str)
{ {
int flags;
disable_IRQs(flags);
if (str == '\n') { if (str == '\n') {
line++; line++;
col = 0; col = 0;
@ -106,18 +122,23 @@ void VGAputc(const char str)
} }
} }
cursorMove(col, line); cursorMove(col, line);
restore_IRQs(flags);
} }
void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY) void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY)
{ {
uint32_t flags;
volatile short *vga = (short *)VGA_ADDR; volatile short *vga = (short *)VGA_ADDR;
int i = 0; int i = 0;
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8; long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
disable_IRQs(flags);
while (*str) { while (*str) {
vga[VGA_WIDTH * startY + startX + i] = colorAttr | *str; vga[VGA_WIDTH * startY + startX + i] = colorAttr | *str;
str++; str++;
i++; i++;
} }
restore_IRQs(flags);
} }
void cursorEnable(uint8_t cursor_start, uint8_t cursor_end) void cursorEnable(uint8_t cursor_start, uint8_t cursor_end)