VGA: could be configured from MBI

This commit is contained in:
Mathieu Maret 2021-10-25 21:29:02 +02:00
parent 8ff10c938c
commit 8a53ecfecd
4 changed files with 51 additions and 32 deletions

View File

@ -54,7 +54,7 @@ debug:kernel kernel.sym
#qemu-system-x86_64 -s -S -kernel kernel&
#qemu-system-i386 -s -S -kernel kernel&
#gdb -s kernel.sym -ex "target remote localhost:1234" -ex "dir core:driver:arch/$(ARCH))'"
gdb -x debug.gdb
gdb -q -x debug.gdb
debug_test: CFLAGS += $(DEBUG_FLAGS) -DRUN_TEST
debug_test: debug

View File

@ -47,7 +47,7 @@ void kmain(unsigned long magic, unsigned long addr)
VGASetup(BLACK, GREEN);
printf("Setting up Interruptions\n");
printf("[Setup] Interruptions\n");
gdtSetup();
idtSetup();
irqSetup();
@ -58,7 +58,7 @@ void kmain(unsigned long magic, unsigned long addr)
multiboot_info_t *mbi = (multiboot_info_t *)addr;
/* Are mem_* valid? */
if (CHECK_FLAG(mbi->flags, 0)) {
printf("mem_lower = %dKiB mem_upper %dKiB\n", mbi->mem_lower, mbi->mem_upper);
printf("mem_lower = %dKiB, mem_upper %dKiB\n", mbi->mem_lower, mbi->mem_upper);
upperMemKB = mbi->mem_upper;
}
@ -100,7 +100,8 @@ void kmain(unsigned long magic, unsigned long addr)
}
if (CHECK_FLAG(mbi->flags, 12)) {
printf("Framebuffer from 0x%llx size (%dx%d) pitch %d bpp %d\n", mbi->framebuffer_addr, mbi->framebuffer_width, mbi->framebuffer_height, mbi->framebuffer_pitch, mbi->framebuffer_bpp);
printf("Re configure Framebuffer from 0x%llx size (%dx%d) pitch %d bpp %d\n", mbi->framebuffer_addr, mbi->framebuffer_width, mbi->framebuffer_height, mbi->framebuffer_pitch, mbi->framebuffer_bpp);
VGAConfigure(mbi->framebuffer_addr, mbi->framebuffer_width, mbi->framebuffer_height);
}
}
@ -109,7 +110,7 @@ void kmain(unsigned long magic, unsigned long addr)
upperMemKB = 32 * 1024;
}
printf("Setting up Mem\n");
printf("[Setup] Mem\n");
memSetup(upperMemKB, &firstUsedByMem, &lastUsedByMem);
@ -137,34 +138,32 @@ void kmain(unsigned long magic, unsigned long addr)
printf("Cannot get memory Mapping information, using default value\n");
memAddBank(lastUsedByMem, upperMemKB * 1024, 1);
}
printf("%d pages taken by kernel(0x%x->0x%x))\n", (lastUsedByMem - firstUsedByMem)/PAGE_SIZE, firstUsedByMem, lastUsedByMem);
printf("with %d pages taken for memory management\n", (lastUsedByMem - (paddr_t)&__ld_kernel_end)/PAGE_SIZE);
printf("%d pages used by kernel(0x%x->0x%x))", (lastUsedByMem - firstUsedByMem)/PAGE_SIZE, firstUsedByMem, lastUsedByMem);
printf(" (%d pages for MM)\n", (lastUsedByMem - (paddr_t)&__ld_kernel_end)/PAGE_SIZE);
#ifdef RUN_TEST
testPhymem();
#endif
printf("Setting up Pagination\n");
printf("[Setup] Pagination\n");
pagingSetup(firstUsedByMem, lastUsedByMem);
for (paddr_t i = VGA_ADDR; i < VGA_ADDR + VGA_WIDTH * VGA_HEIGHT * sizeof(short) ; i += PAGE_SIZE) {
pageMap(i, i, PAGING_MEM_WRITE);
}
VGAMap();
printf("Setting up IRQ handlers\n");
printf("[Setup] IRQ handlers\n");
irqSetRoutineWrapped(IRQ_KEYBOARD, keyboard_do_irq);
printf("Enabling HW interrupts\n");
printf("[Setup] HW interrupts\n");
// Enabling the HW interrupts
exceptionSetup();
asm volatile("sti\n");
printf("Setting up Serial link (115200)\n");
printf("[Setup] Serial link (115200)\n");
serialSetup(115200);
printf("Setting up allocation system\n");
printf("[Setup] allocation system\n");
areaInit(firstUsedByMem, lastUsedByMem);
//allocSetup();
printf("Setting up thread system\n");
printf("[Setup] thread system\n");
kthreadSetup(_stack_bottom, (_stack_top - _stack_bottom + 1));
kthreadCreate("idle ", idleThread, NULL);

View File

@ -2,12 +2,16 @@
#include "io.h"
#include "irq.h"
#include "klibc.h"
#include "paging.h"
#include "mem.h"
static uint vgaBgColor;
static uint vgaColor;
static int line, col;
static volatile short *vga = (short *)VGA_ADDR;
static uint fbWidth = VGA_WIDTH;
static uint fbHeight = VGA_HEIGHT;
static void clearScreen(uint bgColor);
static void cursorMove(int x, int y);
static void cursorEnable(uint8_t cursor_start, uint8_t cursor_end);
@ -24,13 +28,21 @@ int VGASetup(uint bgColor, uint color)
return 0;
}
int VGAConfigure(int addr, uint width, uint height){
vga = (short *)addr;
fbWidth = width;
fbHeight = height;
return 0;
}
static void clearScreen(uint bgColor)
{
uint32_t flags;
long int colorAttr = bgColor << 12;
disable_IRQs(flags);
for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) {
for (uint i = 0; i < fbWidth * fbHeight; i++) {
vga[i] = colorAttr;
}
restore_IRQs(flags);
@ -41,11 +53,11 @@ void VGAclearLine(uint bgColor, uint line)
uint32_t flags;
long int colorAttr = bgColor << 12;
if (line >= VGA_HEIGHT)
if (line >= fbHeight)
return;
disable_IRQs(flags);
for (uint i = VGA_WIDTH * line; i < VGA_WIDTH * (line + 1); i++) {
for (uint i = fbWidth * line; i < fbWidth * (line + 1); i++) {
vga[i] = colorAttr;
}
restore_IRQs(flags);
@ -54,7 +66,7 @@ void VGAclearLine(uint bgColor, uint line)
void VGAPrintf(uint color, uint bgColor, int startX, int startY, const char *format, ...)
{
int flags;
char tmp[VGA_WIDTH];
char tmp[fbWidth];
int idx = 0;
disable_IRQs(flags);
@ -73,9 +85,9 @@ void VGAPrintf(uint color, uint bgColor, int startX, int startY, const char *for
static void printCharDetails(const char str, uint color, uint bgColor, int startX, int startY)
{
int pos = VGA_WIDTH * startY + startX;
int pos = fbWidth * startY + startX;
if (pos > VGA_WIDTH * VGA_HEIGHT || pos < 0)
if (pos > (int)(fbWidth * fbHeight) || pos < 0)
return;
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
@ -88,13 +100,13 @@ void VGAScrollUp(void)
int flags;
disable_IRQs(flags);
for (int i = 1; i < VGA_HEIGHT - VGA_STATUS_LINE_HEIGHT;
for (uint i = 1; i < fbHeight - VGA_STATUS_LINE_HEIGHT;
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));
memcpy((void *)&vga[fbWidth * (i - 1)], (void *)&vga[fbWidth * i],
fbWidth * sizeof(short));
}
for (int i = 0; i < VGA_WIDTH; i++) {
vga[(VGA_HEIGHT - 1 - VGA_STATUS_LINE_HEIGHT) * VGA_WIDTH + i] = colorAttr;
for (uint i = 0; i < fbWidth; i++) {
vga[(fbHeight - 1 - VGA_STATUS_LINE_HEIGHT) * fbWidth + i] = colorAttr;
}
restore_IRQs(flags);
}
@ -107,7 +119,7 @@ void VGAPutc(const char str)
if (str == '\n') {
line++;
col = 0;
if (line >= VGA_HEIGHT - VGA_STATUS_LINE_HEIGHT) {
if (line >= (int)(fbHeight - VGA_STATUS_LINE_HEIGHT)) {
VGAScrollUp();
line--;
}
@ -116,7 +128,7 @@ void VGAPutc(const char str)
} else if (str == '\b') {
col--;
if (col < 0) {
col = VGA_WIDTH - 1;
col = fbWidth - 1;
line--;
if (line < 0)
line = 0;
@ -124,11 +136,11 @@ void VGAPutc(const char str)
printCharDetails(' ', vgaColor, vgaBgColor, col, line);
} else {
printCharDetails(str, vgaColor, vgaBgColor, col++, line);
if (col == VGA_WIDTH) {
if (col == (int)fbWidth) {
col = 0;
line++;
}
if (line >= VGA_HEIGHT - VGA_STATUS_LINE_HEIGHT) {
if (line >= (int)(fbHeight - VGA_STATUS_LINE_HEIGHT)) {
VGAScrollUp();
line--;
}
@ -156,7 +168,7 @@ void cursorDisable(void)
static void cursorMove(int x, int y)
{
long int colorAttr = (vgaBgColor << 4 | (vgaColor & 0x0f)) << 8;
uint16_t pos = y * VGA_WIDTH + x;
uint16_t pos = y * fbWidth + x;
vga[pos] = colorAttr;
outb(0x3D4, 0x0F);
@ -164,3 +176,9 @@ static void cursorMove(int x, int y)
outb(0x3D4, 0x0E);
outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
}
void VGAMap(void){
for (paddr_t i = VGA_ADDR; i < VGA_ADDR + VGA_WIDTH * VGA_HEIGHT * sizeof(short) ; i += PAGE_SIZE) {
pageMap(i, i, PAGING_MEM_WRITE);
}
}

View File

@ -21,6 +21,8 @@
int VGASetup(uint bgColor, uint color);
void VGAPutc(const char str);
int VGAConfigure(int addr, uint width, uint height);
void VGAPrintf(uint color, uint bgColor, int startX, int startY, const char *format, ...);
void VGAClearLine(uint bgColor, uint line);
void VGAScrollUp(void);
void VGAMap(void);