The little book about OS development

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Avidanborisov
Posts: 10
Joined: Sat May 10, 2014 8:10 am

Re: The little book about OS development

Post by Avidanborisov »

sortie wrote:Avidanborisov: Stack in the .bss is technically allowed.
Wouldn't you overwrite stuff in the .bss that way?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: The little book about OS development

Post by Combuster »

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 ]
Avidanborisov
Posts: 10
Joined: Sat May 10, 2014 8:10 am

Re: The little book about OS development

Post by Avidanborisov »

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: Select all

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?
User avatar
iansjack
Member
Member
Posts: 4689
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: The little book about OS development

Post by iansjack »

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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: The little book about OS development

Post by Combuster »

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 ]
Avidanborisov
Posts: 10
Joined: Sat May 10, 2014 8:10 am

Re: The little book about OS development

Post by Avidanborisov »

iansjack wrote:
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.
User avatar
iansjack
Member
Member
Posts: 4689
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: The little book about OS development

Post by iansjack »

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.
helino
Posts: 9
Joined: Mon Jan 16, 2012 8:11 am

Re: The little book about OS development

Post by helino »

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
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: The little book about OS development

Post by bubach »

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.
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
willedwards
Member
Member
Posts: 96
Joined: Sat Mar 15, 2014 3:49 pm

Re: The little book about OS development

Post by willedwards »

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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: The little book about OS development

Post by Combuster »

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 ]
Post Reply