gpt4 book ai didi

c++ - 您需要先加载内核错误

转载 作者:太空狗 更新时间:2023-10-29 21:37:06 27 4
gpt4 key购买 nike

现在,当我选择 Custom OS 时,当我从 GRUB 的菜单中执行我的 OS 时,我得到一个紫色背景:

error: secure boot forbids loading module from (hdo, gpt7)/boot/grub/x86_64-efi/multiboot.mod
error: You need to load your kernel first
Press any key to continue . . .

.. 我不一定明白为什么会这样。让我给你看我的文件:

加载器.S:

#Global MultiBoot Kernel Recongnzation
.set MAGIC, 0x1BADB002
.set FLAGS , (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS)

#Putting in object file
.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM


.section .text

.extern kernelMain
.globl loader

loader:
mov $kernel_stack , %esp
push %eax
push %ebx
call kernelMain

_eof:
cli
hlt
jmp _eof


.section .bss
.space 2*1024*1024 #2 MiB
kernel_stack:

生成文件:

GPPARAMS =  -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = kernel.o loader.o

all:
g++ -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -o kernel.o -c kernel.cc
as $(ASPARAMS) -o loader.o loader.S

mykernel.bin : linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $@ $(objects)

install: mykernel.bin
sudo cp $< /boot/mykernel.bin

clean:
rm $(objects)

内核.cc:

int strlen(char* str)
{
int l=0;
while(str[l]!='\0')l++;
return l;
}

void printf(char *str)
{
unsigned short* ViedoMemory = (unsigned short*)0xb8000;

for(int i=0; str[i]!='\0'; ++i)
ViedoMemory[i]= (ViedoMemory[i] & 0xFF00)|str[i];
}



extern "C" void kernelMain(void* multiboot_structure, unsigned int magicnumber)
{
printf("Hello World");
while(1);
}

链接器.ld:

ENTRY(loader)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)

SECTIONS
{
. = 0x0100000;

.text :
{
*(.multiboot)
*(.text*)
*(.rodata)
}

.data :
{
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;

*(.data)
}

.bss :
{
*(.bss)
}

/DISCARD/ :
{
*(.fini_array*)
*(.comment)
}
}

现在我首先通过makefile加载它:

make
make mykernel.bin
make install

然后当然在 /boot/grub/grub.cfg 我添加了这个:

### BEGIN MYKERNEL
menuentry 'Operating System Tut'{
multiboot /boot/mykernel.bin
boot
}
### END MYKERNEL ###

然后,当我执行 sudo reboot 并从下拉列表中选择 Operating System Tut 时,出现了我之前描述的错误:

error: secure boot forbids loading module from (hdo, gpt7)/boot/grub/x86_64-efi/multiboot.mod

error: You need to load your kernel first

Press any key to continue . . .

同样,我不明白为什么内核没有首先加载...将不胜感激。

最佳答案

尝试关闭 BIOS 中的 Secure Boot 选项,看看是否会产生不同的结果。启用此选项后,固件会检查您的引导加载程序是否已签名并阻止其执行,如果未签名,或者其签名与存储在 NVRAM 中的 key 不对应,或者是否在 NVRAM 中列入黑名单。

参见 Managing EFI Boot Loaders for Linux: Dealing with Secure Boot .

关于c++ - 您需要先加载内核错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38460881/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com