OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Dec 06, 2019 8:26 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Booting OS with GRUB
PostPosted: Mon Nov 04, 2019 10:20 am 
Offline

Joined: Mon Nov 04, 2019 9:36 am
Posts: 1
We are developing 32-bit OS. I used to run it like this:
Code:
qemu-system-i386 -kernel os.bin
. Today I wanted to make ISO image:
Code:
grub-mkrescue -o bootable.iso iso

When I start
Code:
qemu-system-i386 -cdrom bootable.iso
it shows grub. Next, I press enter to boot OS. The OS started up, but in less than a second it returns to GRUB.

Grub config:
Code:
menuentry "OS" {
multiboot /os.bin
}


linker.ld:
Code:
ENTRY(_start)


SECTIONS
{
   . = 1M;
   kernel_phys_start = .;

   .text BLOCK(4K) : ALIGN(4K)
   {
      *(.multiboot)
      *(.text)
   }

   .rodata BLOCK(4K) : ALIGN(4K)
   {
      *(.rodata)
   }

   .data BLOCK(4K) : ALIGN(4K)
   {
      *(.rodata)
   }

   .bss BLOCK(4K) : ALIGN(4K)
   {
      *(COMMON)
      *(.bss)
   }
   kernel_phys_end = .;
}


boot.s:
Code:
.set ALIGN,    1<<0             # align loaded modules on page boundaries
.set MEMINFO,  1<<1             # provide memory map
.set FLAGS,    ALIGN | MEMINFO  # this is the Multiboot 'flag' field
.set MAGIC,    0x1BADB002       # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot

# Declare a header as in the Multiboot Standard.
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM

# Reserve a stack for the initial thread.
.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

# The kernel entry point.
.section .text
.global _start
.type _start, @function
_start:
   movl $stack_top, %esp

   # Call the global constructors.
   #call _init

   # Transfer control to the main kernel.
   call init

   # Hang if kernel_main unexpectedly returns.
   cli
1:   hlt
   jmp 1b
.size _start, . - _start


Top
 Profile  
 
 Post subject: Re: Booting OS with GRUB
PostPosted: Mon Nov 04, 2019 2:31 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 88
Location: North Dakota, United States
If your description is accurate, then your OS is probably triple faulting. Once grub has loaded your kernel it is impossible for the system to "return" to it without a processor reset being initiated. Ensure you've set up a double fault handler to catch any errors that are not caught by any other IDT entries -- that should solve your problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Kamal123 and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group