Pushing to stack when SP is 0
Posted: Fri Apr 27, 2012 5:21 am
What happens if you do it in real mode? Is interrupt generated? I couldn't find any info with google.
The Place to Start for Operating System Developers
http://f.osdev.org/
A shudder runs down my spine. Verily, evil words should not be spoken in jest...bluemoon wrote:You could do an experiment on it.
In the context of a wrapping stack pointer, this probably translates as "One ring buffer to rule them all..."Solar wrote:Ash nazg durbatulûk, ash nazg gimbatul, ash nazg thrakatulûk agh burzum-ishi krimpatul...
No, it just wraps to 0xFFFF. There is zero alignment checking in real mode.gerryg400 wrote:It does wrap around from $0 to $fffe on a 16 bit push, but the same does not apply for $1. If %sp is $1 then a push will cause a shutdown.
Code: Select all
mov esp, 1
push 0xDEAD
If the ESP or SP register is 1 when the PUSH instruction is executed in real-address mode, a stack-fault exception (#SS) is generated (because the limit of the stack segment is violated). Its delivery encounters a second stack-fault exception (for the same reason), causing generation of a double-fault exception (#DF). Delivery of the double-fault exception encounters a third stack-fault exception, and the logical processor enters shutdown mode. See the discussion of the double-fault exception in Chapter 6 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
Send a bug-report to them. This is clearly wrong. One might wonder if they do proper limit-checking in other cases as well.Rudster816 wrote:Executing that snippet in Qemu moves the word 0xDEAD to 0xFFFF, and sets SP to 0xFFFF. Memory looks like this:
0x0FFFF: 0xAD
0x10000: 0xDE
That's true. However my recollection is that if for example you set ESP to $2 and push 32 bits then ESP will end up being $fffffffe but half of the pushed value will be lost. I should warn that my recollections are not always 100%.rdos wrote:The fault in protected mode is probably also related to limit violations, and not to "wrap around". IOW, if you have a flat stack selector, and wrap it around, there will be no faults.