OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 3:17 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 2:13 am 
Offline

Joined: Sat May 10, 2014 8:10 am
Posts: 10
sortie wrote:
Avidanborisov: Stack in the .bss is technically allowed.


Wouldn't you overwrite stuff in the .bss that way?


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 2:34 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Basically, you're claiming that reserving space for the stack in .bss implies the stack will always write outside that reserved space?

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 3:41 am 
Offline

Joined: Sat May 10, 2014 8:10 am
Posts: 10
Combuster wrote:
Basically, you're claiming that reserving space for the stack in .bss implies the stack will always write outside that reserved space?


I'm claiming that the way it's done in the the book, the space reserved for the stack and the .bss section coincide.
Code:
KERNEL_STACK_SIZE equ 4096                  ; size of stack in bytes

section .bss
align 4                                     ; align at 4 bytes
kernel_stack:                               ; label points to beginning of memory
    resb KERNEL_STACK_SIZE                  ; reserve stack for the kernel
...
mov esp, kernel_stack + KERNEL_STACK_SIZE   ; point esp to the start of the
                                            ; stack (end of memory area)


The space reserved for the stack starts right at the beginning of the .bss section. With enough stack frames, wouldn't you overwrite stuff in the .bss?


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 3:50 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Quote:
With enough stack frames, wouldn't you overwrite stuff in the .bss?
Since the stack is the first item in the .bss section, how could it possibly overwrite other variables stored there? (It could, but only if you tried to pop more items from it than had been pushed.)

If you think this method of allocating stack space is dangerous, how would you propose to allocate an initial stack?


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 4:06 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Avidanborisov wrote:
The space reserved for the stack starts right at the beginning of the .bss section. With enough stack frames, wouldn't you overwrite stuff in the .bss?
The stack grows downwards. So:
1) It would more likely write into .data when full
2) You're assuming the stack overflow to prove the stack overflow, which is a circular argument.
3) A stack overflow would be the actual bug, not the placement of the stack in memory. You can put it anywhere and with enough pushes or pops, it will reach into areas it shouldn't.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 4:15 am 
Offline

Joined: Sat May 10, 2014 8:10 am
Posts: 10
iansjack wrote:
Quote:
With enough stack frames, wouldn't you overwrite stuff in the .bss?
Since the stack is the first item in the .bss section, how could it possibly overwrite other variables stored there? (It could, but only if you tried to pop more items from it than had been pushed.)

If you think this method of allocating stack space is dangerous, how would you propose to allocate an initial stack?


Oops, just realized now that resb reserves the space for stack. My bad for not really paying attention to the code :)
My thought was that the stack isn't really the first item in the .bss section, that we just make esp point to <.bss + 4096>. This way we could obviously overwrite stuff in the .bss section.

Either way, I believe the way it's done in Bare Bones (with a separate .stack section) is nicer.


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 7:27 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
The .stack section in Bare Bones is combined above other static data by the linker. Arguably this is more dangerous, as you pointed out, because an overflowing stack will - in this case - overwrite other static data. In the end you can use paging to totally isolate the stack so that the result of an overflowing stack is a page exception. The OS can then handle this in whatever manner it deems appropriate - at least this way you get a well-defined exception rather than mysteriously corrupted data.


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Mon Jan 12, 2015 3:47 pm 
Offline

Joined: Mon Jan 16, 2012 8:11 am
Posts: 9
Everyone, again, thanks for all the great feedback (both criticism and encouragement), it is deeply appreciated! I will try to follow this thread and file issues on github based on your comments and feedback (and then hopefully fix those issues).

Combuster, sortie: Thanks for answering my question about using a cross-compiler. I agree that the text desperately needs a paragraph about using a cross-compiler.

EDIT: spelling


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Wed Jan 14, 2015 4:49 pm 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1223
Location: Sweden
I'll start with the good stuff.

I like the idea behind this project, and hosting the stuff you learned along the way as a small book/tutorial on
GitHub pages is cool. It's well organized, has clear and informative illustrations.

Unfortunately, I get the feeling that you rushed writing the text before fully understanding the concepts yourself.

Stuff like the quote below clearly shows just how much of the the terms and concepts that you have mixed up.

Quote:
4.2 The Framebuffer

The framebuffer is a hardware device that is capable of displaying a buffer of memory on the screen [26]. The framebuffer has 80 columns and 25 rows, and the row and column indices start at 0 (so rows are labelled 0 - 24).

4.2.1 Writing Text

Writing text to the console via the framebuffer is done with memory-mapped I/O. The starting address of the memory-mapped I/O for the framebuffer is 0x000B8000 [27]


You basically just said that a memory mapped I/O area is a piece of hardware, that the same memory area
has columns and rows. Yes that's right. RAM has rows and columns, apparently.

You further explain how the console (how you define a console is anyones guess) is written to via the
memory mapped I/O area with the help of memory mapped I/O. :?:

The VGA-chip or whatever do-all-legacy-stuff-chip that simulate the VGA's capabilities these days, is the
actual hardware responsible for providing the text based output mode that the computer boots into.

The framebuffer in this case is just another name for the memory mapped I/O area, not a piece of hardware.
The specific textmode of the VGA that provides space for 80 columns and 25 rows is called mode 0x03.

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Thu Jan 15, 2015 2:22 am 
Offline
Member
Member

Joined: Sat Mar 15, 2014 3:49 pm
Posts: 96
As a native English speaker and programmer, I don't find that particular section on the framebuffer ambiguous nor wrong at all.

Sure it could be phrased in a myriad of different ways, each way lending weight to some aspect that some other programmer feels most important. But for text for beginners I don't see the harm or inaccuracies at all.


Top
 Profile  
 
 Post subject: Re: The little book about OS development
PostPosted: Thu Jan 15, 2015 2:44 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Text mode doesn't qualify for being/having a framebuffer at all. It's rendered as tiles and lacks a memory location for each individual pixel on the screen.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 45 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