Kernel GRUB无效的多重启动
我正在编写一个简单的32位内核。我正在吃GRUB。代码如下:Kernel GRUB无效的多重启动,kernel,grub,Kernel,Grub,我正在编写一个简单的32位内核。我正在吃GRUB。代码如下: #include <stdio.h> #include <sys/kernel.h> #include <sys/tty.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <keys.h> #include <sys/sata.h> #inc
#include <stdio.h>
#include <sys/kernel.h>
#include <sys/tty.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <keys.h>
#include <sys/sata.h>
#include <string.h>
#include <sys/iob.h>
void *free_space;
void *kmalloc(size_t s) {
void *block = free_space;
free_space += s;
return block;
}
void meminit() {
/* Initialize the heap. It starts at 0xC0200000. */
free_space = (void *)0xC0200000;
}
char *buffer;
void read() {
buffer = malloc(512);
read_sata(0, 1, buffer);
}
void check() {
//outb(0x1F0, 0x00);
//printf("%d\n", inw(0x1F0));
}
void kernel_init(void) {
keys_init();
meminit();
}
void kernel_main(void) {
/* Initialize terminal interface */
terminal_initialize();
check();
abort();
}
当我检查multiboot头是否有效时,
grub文件--is-x86-multiboot kernel.bin
,它返回1(错误)。但是当我注释read()
函数时,它是可引导的。这里怎么了?它太大了吗?内核大约是20KB。我解决了这个问题,使读取
和检查
函数保持静态。但是我不能在函数中放入更多的代码。如果我将内核放在下半部分,它似乎也能工作。多引导头必须位于内核的前8K。尝试将其添加到linkerfile中,以便多引导头是第一个。我在更改引导中的一些代码之前解决了它。s文件我解决了它,使读取
和检查
函数保持静态。但是我无法在函数中添加更多代码。如果我将内核设置为下半部分,则多引导头似乎也可以工作。多引导头必须位于内核的前8K。尝试将其添加到linkerfile中,使multiboot头成为第一个。在更改boot.s文件中的某些代码之前,我解决了这个问题
ENTRY(_start)
OUTPUT_FORMAT(elf32-i386)
SECTIONS {
/* The kernel will live at 3GB + 1MB in the virtual
address space, which will be mapped to 1MB in the
physical address space. */
. = 0xC0100000;
.text : AT(ADDR(.text) - 0xC0000000) {
*(.text)
*(.rodata*)
}
.data ALIGN (0x1000) : AT(ADDR(.data) - 0xC0000000) {
*(.data)
}
.bss : AT(ADDR(.bss) - 0xC0000000) {
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}