Bona Fide OS Developer
View unanswered posts | View active topics It is currently Fri Nov 24, 2017 4:58 pm



Post new topic Reply to topic  [ 9 posts ] 
 Some basic questions 
Author Message

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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?


Sun Apr 25, 2010 10:17 am
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post 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.

_________________
Thank you for reading,

Kieran C G Foot


Sun Apr 25, 2010 4:30 pm
Profile WWW

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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.


Mon Apr 26, 2010 11:47 am
Profile

Joined: Tue Apr 20, 2010 1:39 pm
Posts: 17
Post Re: Some basic questions
I think that aligns the memory to multiables of four.
And dont worry about segmentation.


Mon Apr 26, 2010 5:08 pm
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post 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.

_________________
Thank you for reading,

Kieran C G Foot


Tue Apr 27, 2010 5:20 am
Profile WWW

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post 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?


Tue Apr 27, 2010 5:30 am
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: Some basic questions
Yup, thats exactly it :D

Grub loads to 1MB.

_________________
Thank you for reading,

Kieran C G Foot


Tue Apr 27, 2010 5:40 am
Profile WWW

Joined: Tue Apr 20, 2010 9:08 am
Posts: 20
Post Re: Some basic questions
So you mean the kernel is loaded at address 0x100000?


Tue Apr 27, 2010 5:49 am
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: Some basic questions
Yup

_________________
Thank you for reading,

Kieran C G Foot


Tue Apr 27, 2010 6:37 am
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.