I'm writing a tiny kernel for educational purposes and I was thinking of a good way to set up my stack in real-mode. I read from here: http://wiki.osdev.org/Memory_Map_%28x86%29 that addresses 0x07E00 to 0x7FFFF were guaranteed to be free for use.
So if I set the stack segment to 0x0900, that would give the stack a range from 0x0900 << 4 to 0x0900 << 4 + 0xFFFF which is 0x09000 to 0x18FFF which means I would get a safe 0x10000 bytes of stack space, right?
And I could just set my stack pointer to 0, and it would "underflow" to 0xFFFE at the next push too? Segmentation is a little confusing to me.
This is how the relevant part of the code looks:
BITS 16
ORG 0x0000
mov ax, 0x07C0
mov ds, ax ; ds = origin of code
mov ax, 0xB800
mov es, ax ; es = origin of video memory
mov ax, 0x0900
mov ss, ax
mov ax, 0
mov sp, ax