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 $
Pmode stack help!
Re:Pmode stack help!
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?
If I wanted to, could I?
Re:Pmode stack help!
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.
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!
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...
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Pmode stack help!
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).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.
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