Need help with real mode segmentation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Need help with real mode segmentation

Post by joke »

First of all, I'm new to the forum so hi all! :D


I'm currently trying to develop a very simple, real mode os (monotasking, like dos). My problem is that I only find tutors for pmode and nothing for real mode. Here's my question: I've found a very simple bootloader that loads my kernel in 1000:0000 How can i set-up my code,data and stack segments?
(Should i load the base addresses in cs,ds,ss?)

thanks
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Post by carbonBased »

You should do a search for some information on real mode system architecture (the intel manuals are good for this)... this information does exist, and can be used to differentiate a lot of this pmode discussion from what you want.

I say this, because you seem to be implying that there is some setup involved in defining segments. While this is true in pmode, real mode segments are simply a portion of the full address space, such that:

linear_address = (segment * 16) + segment_offset

Each segment is also fixed at 64k (limited by a 16-bit offset value).

Hopefully that helps,
Jeff

PS: I think anybody that feels the urge to chime in about the realmode idt being a subset of the pmode idt should ignore this urge, as it would just muddy the water, and confuse the issue (IMO, at least...)
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

I've been examining the source code of some real mode oses (like MiniDos by Dex), and there is extensive usage of all three segment registers. Eg, every time a function is called, there's a pusha. But to use pusha there also must be a stack segment. So, if I want a 64k stack at 0300:0000 then what must i do, just
mov ss, 0x12C0 ? (seg*16+offset, if i've understood correctly the formula)
is that enough?
Thanks again
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Post by carbonBased »

Generally speaking, without a stack, you cannot call functions... this is a programming fundamental which osdevers should know and understand.

In order to setup a stack in real mode, yes, all you need to do is load the ss register.

The equation is for converting linear addresses (which you would see in a non-segmented platform) to segmented addresses (and back again). You syntax of 0300:0000 *is* segmented (this syntax generally means segment:offset). As such, you'd simply load ss with 300.

The equation is there so that one understands that 0300:0000 is actually referencing the linear address 300*16+0 = 3000 (I'm assuming 0300 is hex).

--Jeff
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

Thnaks a lot! :D ( i just found it too strange that real mode segmentation was so simple!)
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
Post Reply