Pmode stack help!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
beyondsociety

Pmode stack help!

Post by beyondsociety »

How would I setup a stack in protected mode. What size should it be and how does it work.

This is how I have set up the segment registers in pmode and I need your help with creating the stack:

mov eax,0x10
mov ds,eax
mov es,eax
mov fs,eax
mov gs,eax

jmp $
Tim

Re:Pmode stack help!

Post by Tim »

mov esp, stack_top
...
[section .bss]
stack: resb 4096
stack_top:
beyondsociety

Re:Pmode stack help!

Post by beyondsociety »

Do I have to set up the stack like you would in the beginning of the bootsector but without disabling and enabling the interrupts?

If I wanted to, could I?
PlayOS

Re:Pmode stack help!

Post by PlayOS »

When I create my stack I just do this

mov ax, 0x10 ; My Data Segment
mov ss, ax
mov esp, 0x2000000 ; Start at 32MB

I do this for now while I am still learning stuff. You should probably have a descriptor in the GDT just for your stack, but I dont worry about this at the moment.
Warmaster199

Re:Pmode stack help!

Post by Warmaster199 »

There is an error. You should base the stack right below the 1MByte mark(Recommendation). What if someone runs your OS on a 486 or a PC without 32MBytes of RAM(some pentiums)? The stack would fail to init... Just a suggestion...
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Pmode stack help!

Post by Pype.Clicker »

PlayOS wrote: I do this for now while I am still learning stuff. You should probably have a descriptor in the GDT just for your stack, but I dont worry about this at the moment.
Watch out: there is a trap about kernel stacks having their own (limitated) segments descriptors: okay, it will help you to avoid auwful kernel stack overflow, but in case of such an overflow, it will raise an exception (stack fault) that can't be handled by a "regular" trap handler (because there's no space on the stack to create the exception stackframe).

So you'll have to setup a "big brother" TSS that will catch at least the stack fault exception on a clean empty stack and resume the situation gracefully
Post Reply