You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

64位内核中VGA文本模式光标无法移动或隐藏的问题求助

VGA文本模式光标控制失效问题排查

开发64位操作系统内核时,遇到VGA文本模式光标无法移动、无法隐藏的问题。使用outb指令尝试设置光标位置,光标完全无反应;执行隐藏光标的操作也无效,提前启用光标也无济于事。

光标控制代码

void Terminal::SetCursor(WORD x, WORD y)
{
    WORD pos = y * VGA_WIDTH + x;

    outb(0x3D4, 0x0F);
    outb(0x3D5, (WORD)(pos & 0xFF));
    outb(0x3D4, 0x0E);
    outb(0x3D5, (WORD)((pos >> 8) & 0xFF));
}

void Terminal::HideCursor()
{
    outb(0x03D4, 0x0A);
    outb(0x3D5, 0x20);
}

inb/outb实现

static inline void outb(BYTE value, WORD port)
{
    __asm volatile ("outb %0, %1" : : "a" (value), "Nd" (port));
}

static inline BYTE inb(WORD port)
{
    BYTE value;
    __asm volatile ("inb %1, %0" : "=a" (value) : "Nd" (port));
    return value;
}

内核主函数

extern "C" void kmain(void* memmap)
{
    Terminal::HideCursor(); //TODO: Look into why this is not working!
    Terminal::Clear();
}

编译脚本

bin/kernel.bin: tmp/kernel_entry.o tmp/kernel.o tmp/Terminal.o
    i686-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary

tmp/kernel.o: src/kernel/main.cpp
    i686-elf-gcc -ffreestanding -g -c $^ -o $@

tmp/Terminal.o: src/kernel/Terminal.cpp
    i686-elf-gcc -ffreestanding -g -c $^ -o $@

补充提供boot.asm代码及完整Makefile,恳请各位提供技术帮助。

内容的提问来源于stack exchange,提问作者Florian Schumacher

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 22:09:15