I am currently writing a bootloader and have begun to run out of space in my 512B, so I have begun writing more code outside the 512B and intend to use the bootloader to read it into memory. I have added to the end of my code:
stack_start:
resb 4096
stack_end:
So that I can allocate space for the stack at the end of the operating system code. Currently in my bootloader, I allocate 4KiB for the stack after the bootloader using the following which I took from here:
mov ax, 07c0h ; 4K stack space after the bootloader -- code is running at 0x07c0
add ax, 288 ; (4096 + 512)/16 bytes per paragraph (288 paragraphs)
mov ss, ax
mov sp, 4096 ; moves the stack pointer
However now I need a way to allocate the stack to be at the end of my OS code, which will be an unknown size.
I believe I understand how these need to be set up -- similar to using es, I am using ss for extending the addressing space, but I can't find anything that explains it well for my level of knowledge. I am also not sure how to set it correctly for putting my stack at the end. I have used:
mov ax, stack_start
mov ss, ax
mov sp, 4096
And have not encountered an error; however I would like to know if this is correct, or whether I've actually just allocated some space for the stack while filling memory with a higher address.
How does ss actually work? And how can I use it and sp to allocate memory for the stack at the end of my code?
This is in i386 using nasm.
EDIT: Some way to validate that the stack is in the right place would be really useful, too, if that is at all possible.