您需要首先加载内核错误

时间:2016-07-19 14:06:56

标签: c++ x86 gas osdev grub

现在当我选择自定义操作系统时,当我从GRUB的菜单执行我的操作系统时,我得到一个紫色背景:

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 . . .

..我不一定理解为什么会这样。让我告诉你我的文件:

loader.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)

kernel.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);
}

linker.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 . . .

同样,我不明白为什么内核没有先加载......请帮助。

1 个答案:

答案 0 :(得分:2)

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

请参阅Managing EFI Boot Loaders for Linux: Dealing with Secure Boot