Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've written the main parts of my new operating system. I want to create a 4 MiB stack but I don't know if that could be done in 16 bits real mode or whether I have to load the kernel first, which will be in 32 bits protected mode.

Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 25-Nov-11 20:25pm    
If depends. Is it in system kernel or application? Is it x86? What's the role of real mode: bootstrap-only or it takes some place when OS is already loaded (I would suggest to get rid of real mode after bootstrap)? Do you use CPU protection rings? One for kernel and one for user level or something different (x86 has 4 rings)?
--SA

1 solution

Please see my questions to the question. Even though the answer depends on your architecture, my basic idea is the following: I would advise you to use the real mode only to bootstrap. Immediately after the time OS is started to run protected mode, you should get rid of all real-mode stuff (all code segments, data segments, stack segments). You can have a temporary 16-bit real-mode stack just for bootstrap purposes when you are loading your kernel. When this is done (or at the very end of bootstrap), you will need to adjust your memory and remove all the memory segments used by real mode, free all memory for protected mode. Create the protected-mode stack immediately before jumping to protected-mode code instruction pointer.

One more advice: don't repeat a mistake of some Microsoft memory models: keep stack and static memory segments or pages separate.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900