Bona Fide OS Development
http://forums.osdever.net/

Some basic questions
http://forums.osdever.net/viewtopic.php?f=6&t=340
Page 1 of 1

Author:  MTK358 [ Sun Apr 25, 2010 10:17 am ]
Post subject:  Some basic questions

I wanted to try making a simple OS and I came across this:

http://wiki.osdev.org/Bare_bones

I did it and it works, but there are many things that I don't understand:

How does GRUB work and what is Multiboot?

Segmentation. Where is it used? How is it used? Do I need to know about it?

Where does stuff go in memory?

Author:  Kieran [ Sun Apr 25, 2010 4:30 pm ]
Post subject:  Re: Some basic questions

Quote:
How does GRUB work and what is Multiboot?


GRUB Is a multi stage bootloader, it loads from whichever storage medium you install it too.
Then depending if you have the correct file system support (stage 1.5) file, it will then load the specified kernel and boot.

Multiboot is the specification that GRUB is built to. It specifies the data-structure passed to the kernel and the way
the bootloader should leave the processors registers/environment.

Also see: http://wiki.osdev.org/GRUB

Quote:
Segmentation. Where is it used? How is it used? Do I need to know about it?


Segmentation was used before protected (32-Bit) mode, it's not used today and unless you are planning on writing a bootloader you don't need to worry.

Quote:
Where does stuff go in memory?


Hmmm, a little ambiguous...

There is a basic memory layout for the x86 architecture (See: http://wiki.osdev.org/Memory_Map_(x86)), however there is a lot more to memory maps then this.

The BIOS implements ways of obtaining a more accurate memory map (ref. E820 See: http://wiki.osdev.org/Detecting_Memory_(x86)#E802h).

NOTE: Grub passes this E820 memory map to your kernel as specified in the MultiBoot Specification :)

This will list most memory areas, if they are free, used, unknown or reclaimable.

Hope that answers your questions.

Author:  MTK358 [ Mon Apr 26, 2010 11:47 am ]
Post subject:  Re: Some basic questions

Kieran wrote:
Segmentation was used before protected (32-Bit) mode, it's not used today and unless you are planning on writing a bootloader you don't need to worry.


So I can just pretend segmentation doesn't exist, right?


Code:
; reserve initial kernel stack space
STACKSIZE equ 0x4000                  ; that's 16k.
 
loader:
   mov esp, stack+STACKSIZE           ; set up the stack
   push eax                           ; pass Multiboot magic number
   push ebx                           ; pass Multiboot info structure
 
   call  kmain                       ; call kernel proper
 
   cli
hang:
   hlt                                ; halt machine should kernel return
   jmp   hang
 
section .bss
[b]align 4[/b]
stack:
   resb STACKSIZE                     ; reserve 16k stack on a doubleword boundary


So it allocates a 16kb tall stack by setting ESP to the end of the code + 16kb?

Could you help explain the parts in bold?

EDIT: Howcome BBCode does not work in the code? Anyway, just pretend that the stuff in the [b] tags is bold.

Author:  smeezekitty [ Mon Apr 26, 2010 5:08 pm ]
Post subject:  Re: Some basic questions

I think that aligns the memory to multiables of four.
And dont worry about segmentation.

Author:  Kieran [ Tue Apr 27, 2010 5:20 am ]
Post subject:  Re: Some basic questions

Its alligning the stack to a 4 byte (Double Word) boundry, I presume its an attempt at optimisation of some sort.

Author:  MTK358 [ Tue Apr 27, 2010 5:30 am ]
Post subject:  Re: Some basic questions

So it just makes sure that the symbol stack: is positioned at a multiple of 4, which is the size of a dword, right?

Anyway, where is the executable put into memory by GRUB?

Author:  Kieran [ Tue Apr 27, 2010 5:40 am ]
Post subject:  Re: Some basic questions

Yup, thats exactly it :D

Grub loads to 1MB.

Author:  MTK358 [ Tue Apr 27, 2010 5:49 am ]
Post subject:  Re: Some basic questions

So you mean the kernel is loaded at address 0x100000?

Author:  Kieran [ Tue Apr 27, 2010 6:37 am ]
Post subject:  Re: Some basic questions

Yup

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/