mirror of
https://github.com/Plexi09/Nadir-Kernel.git
synced 2026-10-20 23:17:27 +02:00
fix: cursor position says fixed in the console (#3)
This commit is contained in:
parent
591c57c8f8
commit
75c2b200d8
2 changed files with 27 additions and 1 deletions
2
Makefile
2
Makefile
|
|
@ -36,7 +36,7 @@ $(BUILD)/isr.o: $(ARCH_DIR)/isr.asm | $(BUILD)
|
||||||
$(BUILD)/kmain.o: kernel/core/kmain.c include/console.h include/idt.h include/pic.h include/pit.h include/serial.h include/keyboard.h | $(BUILD)
|
$(BUILD)/kmain.o: kernel/core/kmain.c include/console.h include/idt.h include/pic.h include/pit.h include/serial.h include/keyboard.h | $(BUILD)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(BUILD)/console.o: $(ARCH_DIR)/console.c include/console.h | $(BUILD)
|
$(BUILD)/console.o: $(ARCH_DIR)/console.c include/console.h include/io.h | $(BUILD)
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(BUILD)/idt.o: $(ARCH_DIR)/idt.c include/idt.h include/console.h include/pic.h | $(BUILD)
|
$(BUILD)/idt.o: $(ARCH_DIR)/idt.c include/idt.h include/console.h include/pic.h | $(BUILD)
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,20 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
#define VGA_WIDTH 80
|
#define VGA_WIDTH 80
|
||||||
#define VGA_HEIGHT 25
|
#define VGA_HEIGHT 25
|
||||||
#define VGA_ADDR 0xB8000
|
#define VGA_ADDR 0xB8000
|
||||||
#define COLOR_DEFAULT 0x0FU /* white on black */
|
#define COLOR_DEFAULT 0x0FU /* white on black */
|
||||||
|
|
||||||
|
/* VGA CRT controller ports: index selects the register, data reads/writes
|
||||||
|
* it. Registers 0x0E/0x0F hold the high/low byte of the cursor offset. */
|
||||||
|
#define VGA_CRT_INDEX 0x3D4U
|
||||||
|
#define VGA_CRT_DATA 0x3D5U
|
||||||
|
#define VGA_CRT_CURSOR_HIGH 0x0EU
|
||||||
|
#define VGA_CRT_CURSOR_LOW 0x0FU
|
||||||
|
|
||||||
/* Cursor position. Lives in BSS. */
|
/* Cursor position. Lives in BSS. */
|
||||||
static uint8_t cursor_row;
|
static uint8_t cursor_row;
|
||||||
static uint8_t cursor_col;
|
static uint8_t cursor_col;
|
||||||
|
|
@ -18,6 +26,22 @@ static uint8_t cursor_col;
|
||||||
* store in order. */
|
* store in order. */
|
||||||
static volatile uint16_t *const vga = (uint16_t *)VGA_ADDR;
|
static volatile uint16_t *const vga = (uint16_t *)VGA_ADDR;
|
||||||
|
|
||||||
|
/* Sync the blinking hardware cursor to cursor_row/cursor_col.
|
||||||
|
* WHY it exists: writing VGA cells alone never moves the CRT cursor, so
|
||||||
|
* without this the hardware cursor stays where SeaBIOS left it (issue #3).
|
||||||
|
* Runs at Ring 0 (CPL 0): `out` traps with #GP(0) if CPL > IOPL, so this
|
||||||
|
* must never run in userspace. A wrong port value cannot fault (open bus
|
||||||
|
* ignores it); it would only misplace the visible cursor. */
|
||||||
|
static void update_hw_cursor(void)
|
||||||
|
{
|
||||||
|
uint16_t pos = (uint16_t)(cursor_row * VGA_WIDTH + cursor_col);
|
||||||
|
|
||||||
|
outb(VGA_CRT_INDEX, VGA_CRT_CURSOR_LOW);
|
||||||
|
outb(VGA_CRT_DATA, (uint8_t)(pos & 0xFFU));
|
||||||
|
outb(VGA_CRT_INDEX, VGA_CRT_CURSOR_HIGH);
|
||||||
|
outb(VGA_CRT_DATA, (uint8_t)((pos >> 8) & 0xFFU));
|
||||||
|
}
|
||||||
|
|
||||||
/* Move every line one row up and blank the last line */
|
/* Move every line one row up and blank the last line */
|
||||||
static void scroll(void)
|
static void scroll(void)
|
||||||
{
|
{
|
||||||
|
|
@ -39,6 +63,7 @@ void console_clear(void)
|
||||||
}
|
}
|
||||||
cursor_row = 0;
|
cursor_row = 0;
|
||||||
cursor_col = 0;
|
cursor_col = 0;
|
||||||
|
update_hw_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void console_putchar(char c)
|
void console_putchar(char c)
|
||||||
|
|
@ -76,6 +101,7 @@ void console_putchar(char c)
|
||||||
scroll();
|
scroll();
|
||||||
cursor_row = VGA_HEIGHT - 1;
|
cursor_row = VGA_HEIGHT - 1;
|
||||||
}
|
}
|
||||||
|
update_hw_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void console_puts(const char *s)
|
void console_puts(const char *s)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue