VGA: could be configured from MBI
This commit is contained in:
parent
8ff10c938c
commit
8a53ecfecd
2
Makefile
2
Makefile
@ -54,7 +54,7 @@ debug:kernel kernel.sym
|
|||||||
#qemu-system-x86_64 -s -S -kernel kernel&
|
#qemu-system-x86_64 -s -S -kernel kernel&
|
||||||
#qemu-system-i386 -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 -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: CFLAGS += $(DEBUG_FLAGS) -DRUN_TEST
|
||||||
debug_test: debug
|
debug_test: debug
|
||||||
|
29
core/main.c
29
core/main.c
@ -47,7 +47,7 @@ void kmain(unsigned long magic, unsigned long addr)
|
|||||||
|
|
||||||
VGASetup(BLACK, GREEN);
|
VGASetup(BLACK, GREEN);
|
||||||
|
|
||||||
printf("Setting up Interruptions\n");
|
printf("[Setup] Interruptions\n");
|
||||||
gdtSetup();
|
gdtSetup();
|
||||||
idtSetup();
|
idtSetup();
|
||||||
irqSetup();
|
irqSetup();
|
||||||
@ -58,7 +58,7 @@ void kmain(unsigned long magic, unsigned long addr)
|
|||||||
multiboot_info_t *mbi = (multiboot_info_t *)addr;
|
multiboot_info_t *mbi = (multiboot_info_t *)addr;
|
||||||
/* Are mem_* valid? */
|
/* Are mem_* valid? */
|
||||||
if (CHECK_FLAG(mbi->flags, 0)) {
|
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;
|
upperMemKB = mbi->mem_upper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,8 @@ void kmain(unsigned long magic, unsigned long addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CHECK_FLAG(mbi->flags, 12)) {
|
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;
|
upperMemKB = 32 * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Setting up Mem\n");
|
printf("[Setup] Mem\n");
|
||||||
|
|
||||||
memSetup(upperMemKB, &firstUsedByMem, &lastUsedByMem);
|
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");
|
printf("Cannot get memory Mapping information, using default value\n");
|
||||||
memAddBank(lastUsedByMem, upperMemKB * 1024, 1);
|
memAddBank(lastUsedByMem, upperMemKB * 1024, 1);
|
||||||
}
|
}
|
||||||
printf("%d pages taken by kernel(0x%x->0x%x))\n", (lastUsedByMem - firstUsedByMem)/PAGE_SIZE, firstUsedByMem, lastUsedByMem);
|
printf("%d pages used by kernel(0x%x->0x%x))", (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 for MM)\n", (lastUsedByMem - (paddr_t)&__ld_kernel_end)/PAGE_SIZE);
|
||||||
|
|
||||||
#ifdef RUN_TEST
|
#ifdef RUN_TEST
|
||||||
testPhymem();
|
testPhymem();
|
||||||
#endif
|
#endif
|
||||||
printf("Setting up Pagination\n");
|
printf("[Setup] Pagination\n");
|
||||||
pagingSetup(firstUsedByMem, lastUsedByMem);
|
pagingSetup(firstUsedByMem, lastUsedByMem);
|
||||||
for (paddr_t i = VGA_ADDR; i < VGA_ADDR + VGA_WIDTH * VGA_HEIGHT * sizeof(short) ; i += PAGE_SIZE) {
|
VGAMap();
|
||||||
pageMap(i, i, PAGING_MEM_WRITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Setting up IRQ handlers\n");
|
printf("[Setup] IRQ handlers\n");
|
||||||
irqSetRoutineWrapped(IRQ_KEYBOARD, keyboard_do_irq);
|
irqSetRoutineWrapped(IRQ_KEYBOARD, keyboard_do_irq);
|
||||||
|
|
||||||
printf("Enabling HW interrupts\n");
|
printf("[Setup] HW interrupts\n");
|
||||||
// Enabling the HW interrupts
|
// Enabling the HW interrupts
|
||||||
exceptionSetup();
|
exceptionSetup();
|
||||||
asm volatile("sti\n");
|
asm volatile("sti\n");
|
||||||
|
|
||||||
printf("Setting up Serial link (115200)\n");
|
printf("[Setup] Serial link (115200)\n");
|
||||||
serialSetup(115200);
|
serialSetup(115200);
|
||||||
|
|
||||||
printf("Setting up allocation system\n");
|
printf("[Setup] allocation system\n");
|
||||||
areaInit(firstUsedByMem, lastUsedByMem);
|
areaInit(firstUsedByMem, lastUsedByMem);
|
||||||
//allocSetup();
|
//allocSetup();
|
||||||
|
|
||||||
printf("Setting up thread system\n");
|
printf("[Setup] thread system\n");
|
||||||
kthreadSetup(_stack_bottom, (_stack_top - _stack_bottom + 1));
|
kthreadSetup(_stack_bottom, (_stack_top - _stack_bottom + 1));
|
||||||
kthreadCreate("idle ", idleThread, NULL);
|
kthreadCreate("idle ", idleThread, NULL);
|
||||||
|
|
||||||
|
@ -2,12 +2,16 @@
|
|||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "klibc.h"
|
#include "klibc.h"
|
||||||
|
#include "paging.h"
|
||||||
|
#include "mem.h"
|
||||||
|
|
||||||
static uint vgaBgColor;
|
static uint vgaBgColor;
|
||||||
static uint vgaColor;
|
static uint vgaColor;
|
||||||
static int line, col;
|
static int line, col;
|
||||||
|
|
||||||
static volatile short *vga = (short *)VGA_ADDR;
|
static volatile short *vga = (short *)VGA_ADDR;
|
||||||
|
static uint fbWidth = VGA_WIDTH;
|
||||||
|
static uint fbHeight = VGA_HEIGHT;
|
||||||
static void clearScreen(uint bgColor);
|
static void clearScreen(uint bgColor);
|
||||||
static void cursorMove(int x, int y);
|
static void cursorMove(int x, int y);
|
||||||
static void cursorEnable(uint8_t cursor_start, uint8_t cursor_end);
|
static void cursorEnable(uint8_t cursor_start, uint8_t cursor_end);
|
||||||
@ -24,13 +28,21 @@ int VGASetup(uint bgColor, uint color)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int VGAConfigure(int addr, uint width, uint height){
|
||||||
|
vga = (short *)addr;
|
||||||
|
fbWidth = width;
|
||||||
|
fbHeight = height;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void clearScreen(uint bgColor)
|
static void clearScreen(uint bgColor)
|
||||||
{
|
{
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
long int colorAttr = bgColor << 12;
|
long int colorAttr = bgColor << 12;
|
||||||
|
|
||||||
disable_IRQs(flags);
|
disable_IRQs(flags);
|
||||||
for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) {
|
for (uint i = 0; i < fbWidth * fbHeight; i++) {
|
||||||
vga[i] = colorAttr;
|
vga[i] = colorAttr;
|
||||||
}
|
}
|
||||||
restore_IRQs(flags);
|
restore_IRQs(flags);
|
||||||
@ -41,11 +53,11 @@ void VGAclearLine(uint bgColor, uint line)
|
|||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
long int colorAttr = bgColor << 12;
|
long int colorAttr = bgColor << 12;
|
||||||
|
|
||||||
if (line >= VGA_HEIGHT)
|
if (line >= fbHeight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
disable_IRQs(flags);
|
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;
|
vga[i] = colorAttr;
|
||||||
}
|
}
|
||||||
restore_IRQs(flags);
|
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, ...)
|
void VGAPrintf(uint color, uint bgColor, int startX, int startY, const char *format, ...)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
char tmp[VGA_WIDTH];
|
char tmp[fbWidth];
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
disable_IRQs(flags);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
|
long int colorAttr = (bgColor << 4 | (color & 0x0f)) << 8;
|
||||||
@ -88,13 +100,13 @@ void VGAScrollUp(void)
|
|||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
disable_IRQs(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
|
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[fbWidth * (i - 1)], (void *)&vga[fbWidth * i],
|
||||||
VGA_WIDTH * sizeof(short));
|
fbWidth * sizeof(short));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < VGA_WIDTH; i++) {
|
for (uint i = 0; i < fbWidth; i++) {
|
||||||
vga[(VGA_HEIGHT - 1 - VGA_STATUS_LINE_HEIGHT) * VGA_WIDTH + i] = colorAttr;
|
vga[(fbHeight - 1 - VGA_STATUS_LINE_HEIGHT) * fbWidth + i] = colorAttr;
|
||||||
}
|
}
|
||||||
restore_IRQs(flags);
|
restore_IRQs(flags);
|
||||||
}
|
}
|
||||||
@ -107,7 +119,7 @@ void VGAPutc(const char str)
|
|||||||
if (str == '\n') {
|
if (str == '\n') {
|
||||||
line++;
|
line++;
|
||||||
col = 0;
|
col = 0;
|
||||||
if (line >= VGA_HEIGHT - VGA_STATUS_LINE_HEIGHT) {
|
if (line >= (int)(fbHeight - VGA_STATUS_LINE_HEIGHT)) {
|
||||||
VGAScrollUp();
|
VGAScrollUp();
|
||||||
line--;
|
line--;
|
||||||
}
|
}
|
||||||
@ -116,7 +128,7 @@ void VGAPutc(const char str)
|
|||||||
} else if (str == '\b') {
|
} else if (str == '\b') {
|
||||||
col--;
|
col--;
|
||||||
if (col < 0) {
|
if (col < 0) {
|
||||||
col = VGA_WIDTH - 1;
|
col = fbWidth - 1;
|
||||||
line--;
|
line--;
|
||||||
if (line < 0)
|
if (line < 0)
|
||||||
line = 0;
|
line = 0;
|
||||||
@ -124,11 +136,11 @@ void VGAPutc(const char str)
|
|||||||
printCharDetails(' ', vgaColor, vgaBgColor, col, line);
|
printCharDetails(' ', vgaColor, vgaBgColor, col, line);
|
||||||
} else {
|
} else {
|
||||||
printCharDetails(str, vgaColor, vgaBgColor, col++, line);
|
printCharDetails(str, vgaColor, vgaBgColor, col++, line);
|
||||||
if (col == VGA_WIDTH) {
|
if (col == (int)fbWidth) {
|
||||||
col = 0;
|
col = 0;
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
if (line >= VGA_HEIGHT - VGA_STATUS_LINE_HEIGHT) {
|
if (line >= (int)(fbHeight - VGA_STATUS_LINE_HEIGHT)) {
|
||||||
VGAScrollUp();
|
VGAScrollUp();
|
||||||
line--;
|
line--;
|
||||||
}
|
}
|
||||||
@ -156,7 +168,7 @@ void cursorDisable(void)
|
|||||||
static void cursorMove(int x, int y)
|
static void cursorMove(int x, int y)
|
||||||
{
|
{
|
||||||
long int colorAttr = (vgaBgColor << 4 | (vgaColor & 0x0f)) << 8;
|
long int colorAttr = (vgaBgColor << 4 | (vgaColor & 0x0f)) << 8;
|
||||||
uint16_t pos = y * VGA_WIDTH + x;
|
uint16_t pos = y * fbWidth + x;
|
||||||
vga[pos] = colorAttr;
|
vga[pos] = colorAttr;
|
||||||
|
|
||||||
outb(0x3D4, 0x0F);
|
outb(0x3D4, 0x0F);
|
||||||
@ -164,3 +176,9 @@ static void cursorMove(int x, int y)
|
|||||||
outb(0x3D4, 0x0E);
|
outb(0x3D4, 0x0E);
|
||||||
outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
int VGASetup(uint bgColor, uint color);
|
int VGASetup(uint bgColor, uint color);
|
||||||
void VGAPutc(const char str);
|
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 VGAPrintf(uint color, uint bgColor, int startX, int startY, const char *format, ...);
|
||||||
void VGAClearLine(uint bgColor, uint line);
|
void VGAClearLine(uint bgColor, uint line);
|
||||||
void VGAScrollUp(void);
|
void VGAScrollUp(void);
|
||||||
|
void VGAMap(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user