3

Right now when I select Custom OS , and when i execute my OS from the menu in GRUB I get a purple background:

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

.. I don't necessarily understand why this is happening. let me show you my files:

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:

Makefile:

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) 
  }
}

Right now how I load it is first do it by makefile:

make
make mykernel.bin
make install

and then ofcourse in the /boot/grub/grub.cfg I added this:

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

Then when I do sudo reboot, and select Operating System Tut from the drop-down list it gives me the error I described before:

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

Again, I don't understand why the kernel isn't loading first... Help would be appreciated.

amanuel2
  • 4,508
  • 4
  • 36
  • 67
  • After you fix the Secure boot BIOS issue you might want to consider this: Since you are developing on Ubuntu, rather than rebooting your machine you can test your kernel in a virtual environment. QEMU is good for multiboot kernel testing. Install QEMU using `sudo apt-get install qemu` . To test your kernel use `qemu-system-i386 -kernel mykernel.bin` . QEMU has a multiboot compliant loader. So you just specify the name of your kernel image with `-kernel` and you should be good to go. I believe you purple screen has more to do with some GrUB configuration and/or video mode problem – Michael Petch Jul 19 '16 at 15:50
  • What version of Ubuntu is on your system? – Michael Petch Jul 19 '16 at 15:51
  • @MichaelPetch anwsers to your questions: First of all My Version is 16.04 (i believe thats the latest one) and i am dual bootting it , since vm sucks for actual use(too slow). Second of all are you saying the problem is with my computer? Third of all when i do qemu i get this just stuck on Booting From ROM : http://i.imgur.com/jxQfQQP.png . BUT What about a user wants to boot my OS In dual boot.. how can he boot it up? (Just like i wanted to dual boot Ubuntu) – amanuel2 Jul 19 '16 at 15:56
  • 1
    It isn't stuck on booting. Look at the upper left hand corner of the screen. It says `Hello World` .I think your problem is more related to GRUB configuration but it may also be some interaction with your hardware but it really is difficult to tell. – Michael Petch Jul 19 '16 at 15:58
  • @MichaelPetch why does this qemu "emulator" , have a very wierd display... isnt it suppose to say Hello World at bottom? Instead of actually overwriting Version 1.8.2 Ubuntu ... – amanuel2 Jul 19 '16 at 16:00
  • Text Video memory is laid out from top to bottom. Memory address 0xb8000 is the upper left of the screen. If you want to write to a different location you will have to add an offset that takes you to a particular location. – Michael Petch Jul 19 '16 at 16:02
  • @MichaelPetch Is it possible to just clear everything and write "Hello World" ? And how would i go about adding an "OFFSET" ..? – amanuel2 Jul 19 '16 at 16:04
  • First of all @MichaelPetch how do i know how much rows and cols i have.. Second off , why dosent this cls work? void cls() { char* str = "Welcome to BONEOS Everyone!!!! Press to continue . . ."; char* space = " "; for(int i=0;str[i]!='\0'; ++i) ViedoMemory[i + 20 * 101]= (ViedoMemory[i + 20 * 101] & 0xFF00)|space[1]; } – amanuel2 Jul 19 '16 at 16:28
  • 2
    These questions are beyond the question asked. You may wish to look at [OSDev Wiki](http://wiki.osdev.org/Main_Page). You can write a loop to simply place a space in all the cells of the current screen with an appropriate attriobute. On an 80x25 text display there are 2000 cells of 2 bytes each. As for writing to another location `ViedoMemory[row*80+col+i]= (ViedoMemory[row*80+col+i] & 0xFF00)|str[i];` where you specify row and col . 80 is the number of columns. You'd have to change that if you are in a text mode with a different number of columns – Michael Petch Jul 19 '16 at 16:58
  • 1
    I'm not a fan of `-Wno-write-strings` . I'd recommend against it and simply modify your function `strlen` and `printf` to use `const char *str` instead of `char *str` – Michael Petch Jul 19 '16 at 17:22
  • That uses information that was set when GRUB used the BIOS to switch video modes. The BIOS writes information into the [BIOS Data Area](http://www.piclist.com/techref/bios/dataarea.htm) (BDA) that can be used from Protected Mode to determine the number of rows, columns, size of the current video page and the base address of the current video page among a host of other information. – Michael Petch Jul 19 '16 at 17:34
  • @MichaelPetch hold up.. Im still at episode 1 of writing your own OS.. im not sure if i am suppose to be in this level.. But what is the code you posted two commments after this one? Viedo modes? im stil 1st viedo here: https://www.youtube.com/playlist?list=PLHh55M_Kq4OApWScZyPl5HhgsTJS9MZ6M – amanuel2 Jul 19 '16 at 18:04
  • 1
    You asked the question as to how you determine the number of rows and I answered that and I answered the question about having to do address computations to place things at a row/col. That video is VERY simplistic. What your looking to do now is far more complex than that video (and yes I watched it earlier). Doing work with the video mode is very easy compared to almost everything else Things aren't easy when you are in protected mode. – Michael Petch Jul 19 '16 at 18:07
  • Ok i see.. i think ima worry about this later @MichaelPetch . If you can Michael may you come here : https://kobra.io/#/e/-KN3PRrRwB4GfNd6TZ-m ? Thanks – amanuel2 Jul 19 '16 at 18:38
  • 1
    I have tried running that kernel on QEmu, but didn't succeed... Video 2 shows how to run it in VirtualBox instead :-) – Algoman Jul 19 '16 at 19:53
  • Yup @Algoman . Viedo 1-b seems quite confusing though :/ – amanuel2 Jul 19 '16 at 20:11

1 Answers1

2

Try to turn off the Secure Boot option in your BIOS and see if that gives you a different result. When this option is enabled, the firmware checks if your boot loader is signed and prevents its execution if it isn't, or if its signature doesn't correspond to a key stored in NVRAM, or is blacklisted in the NVRAM.

See Managing EFI Boot Loaders for Linux: Dealing with Secure Boot.

jweyrich
  • 31,198
  • 5
  • 66
  • 97
  • May i ask how you get to the BIOS Sir? – amanuel2 Jul 19 '16 at 14:45
  • 3
    @Dsafds When you turn your computer on you should get a splash screen of your motherboard's manufacturer, whilst on this screen press the delete key (sometimes it's different, depends on the make - you can look that up though) to get to the BIOS. – sjrowlinson Jul 19 '16 at 14:49
  • The key depends on manufacturer, but it's generally DEL or F2. – jweyrich Jul 19 '16 at 14:50
  • Ok i managed to disable security boot from BIOS . but now its giving me an empty purple screen.. Its suppose to give me a helolworld as you can see form C++ File – amanuel2 Jul 19 '16 at 15:02
  • Did the boot work then? The problem seems to be your `printf` implementation now, or something else. – jweyrich Jul 19 '16 at 15:05
  • Sorry @jweyrich i did not see you post because you didnt mention. Hmm printf implementation? How can that go wrong when the viedo i watched had similar one and worked: https://www.youtube.com/watch?v=1rnA6wpF0o4 . Im guessing the boot worked because it gave me like a purple screen... BTW Its a "Ubuntu Style(purple)" GRUB Menu – amanuel2 Jul 19 '16 at 15:37
  • @Dsafds : When the purple screen is up, what happens if you hit ALT F1 ? – Michael Petch Jul 19 '16 at 15:40
  • @MichaelPetch nothing happenes – amanuel2 Jul 19 '16 at 15:49