Page 1 of 1
Pmode stack help!
Posted: Fri Sep 06, 2002 4:03 pm
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 $
Re:Pmode stack help!
Posted: Fri Sep 06, 2002 4:50 pm
by Tim
mov esp, stack_top
...
[section .bss]
stack: resb 4096
stack_top:
Re:Pmode stack help!
Posted: Fri Sep 06, 2002 5:47 pm
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?
Re:Pmode stack help!
Posted: Fri Sep 06, 2002 7:20 pm
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.
Re:Pmode stack help!
Posted: Sun Sep 08, 2002 9:45 am
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...
Re:Pmode stack help!
Posted: Mon Sep 09, 2002 3:14 am
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