I am developing a 32 bit OS and I need to be able to set up NEW data segments/stack segments for programs. However I can not find ANY good information about how to use these segment registers in protected mode. I really need to be able to set up a new stack segment so my programs are not sharing the same stack as the kernel.
Asked
Active
Viewed 1,200 times
3

Ciro Santilli OurBigBook.com
- 347,512
- 102
- 1,199
- 985

user1454902
- 750
- 9
- 24
-
And the segments are already setup by the bootloader – user1454902 Jan 11 '13 at 23:37
-
Yes I know what a stack is, I need to set it equal to a pointer of memory allocated by my OS – user1454902 Jan 11 '13 at 23:39
-
3`MOV SS, ???` won't do? I guess you just need to set the correct memory protection (read/write) + some own metadata for the purposes of deallocation (thread finished) and context switching. – John Dvorak Jan 11 '13 at 23:42
-
Read: http://download.intel.com/products/processor/manual/253665.pdf Chapter 3.4.2 And also: http://download.intel.com/products/processor/manual/253667.pdf The MOV instruction – Vlad Krasnov Jan 13 '13 at 08:06
1 Answers
1
In x86 protected mode the segment registers points to GDT selectors.
1 . So we need to setup the proper selectors for each segments expecially for cs, ds, ss before far jump to protected mode. 2 . Selectors are 8byte length, which defines the base, limit and access permissions. Please see the below link for your reference http://en.wikibooks.org/wiki/X86_Assembly/Global_Descriptor_Table, http://www.jamesmolloy.co.uk/tutorial_html/4.-The%20GDT%20and%20IDT.html, http://en.wikipedia.org/wiki/Global_Descriptor_Table. 3 . If you need more on this please reply me, i can show you my simple OS code which sets the proper the GDT and enter into protected mode.

Mohanraj
- 4,056
- 2
- 22
- 24