无法在程序集中加载内核

unable to load kernel in assembly

提问人:Johndev 提问时间:11/13/2023 最后编辑:Johndev 更新时间:11/13/2023 访问量:81

问:

#include "../drivers/time.h"
#include "../drivers/keyboard.h"
#include "../drivers/display.h"
void _GLOBAL_OFFSET_TABLE_() {}

void main() {
    char* video_memory = (char*) 0xb8000;
    *video_memory = 'X';
}

我用 C 编写一个简单的内核,我使用可以在代码中使用本教程构建的引导加载程序对其进行测试,我尝试将“X”写入 VGA 内存,映像编译完美,但引导加载程序无法“控制”kernel.c,我做错了什么?(引导加载程序代码与我提供的链接完全相同)

这是我根据要求 compiler.sh:

clear

# Compile MBR
nasm ./boot/mbr.asm -f bin -o mbr.bin

# Compile the kernel_entry.asm code
nasm ./boot/kernel_entry.asm -f elf -o kernel_entry.o

# Compile the C kernel code
gcc -m32 -ffreestanding -c ./kernel/kernel.c -o kernel.o

# Link the object files to create the kernel binary
ld -m elf_i386 -e main -Ttext 0x1000 -o kernel.bin kernel_entry.o kernel.o --oformat binary

# Create directory structure for ISO
mkdir -p iso_root/boot
cp mbr.bin iso_root/boot/
cp kernel.bin iso_root/boot/

# Create ISO image
mkisofs -b boot/mbr.bin -no-emul-boot -boot-load-size 4 -o os.iso iso_root/
C 操作系统 VirtualBox 引导加载程序

评论

1赞 Eugene Sh. 11/13/2023
但是引导加载程序不能“控制”kernel.c - 你怎么知道?
0赞 Johndev 11/13/2023
只出现引导加载程序输出,X 没有写入 VGA(我更深入地挖掘并意识到即使引导加载程序应该运行“main”功能,kernel.c 中也没有执行任何内容)
0赞 stark 11/13/2023
你是如何编译和链接的?
2赞 Eugene Sh. 11/13/2023
编辑问题并在其中添加信息。
2赞 Peter Cordes 11/13/2023
这不是一个最小的可重现示例。包含一个站外链接作为背景/参考是可以的,但如果链接死了,这个问题仍然需要有意义。

答: 暂无答案