Page 1 of 2

real mode

Posted: Tue Mar 17, 2009 2:56 am
by xyjamepa
Hi,

I'm writing a real mode os,my whole kernel is loaded at the same segment
and rigiht now I'm loading programs at the buttom of this segment ,after my kernel...
my kernel is loaded at 0x1000:0x0000,so my question is can I load programs
in a different segment?


Thanx.

Re: real mode

Posted: Tue Mar 17, 2009 3:14 am
by AJ
Why would you not be able to? As long as the linear address doesn't overlap your kernel (or any system structures), you'll be fine doing that.

Cheers,
Adam

Re: real mode

Posted: Tue Mar 17, 2009 3:21 am
by xyjamepa
so If my kernel is loaded at 0x1000:0x0000 and let's assume it about 64k
it will end at 0x1000:0xFFFF so the next memory segment will start at 0x2000:0x0000

is that right?

Re: real mode

Posted: Tue Mar 17, 2009 3:29 am
by AJ
Yes. But be aware that theres also 0x1001:0xFFFF, 0x1002:0xFFFF and so on, which would also overlap the segment at 0x2000:0x0000. If you are making a real mode kernel, I suggest you get yourself very familiar with real mode segment:offset addressing.

Cheers,
Adam

Re: real mode

Posted: Tue Mar 17, 2009 3:31 am
by Hyperdrive
abuashraf wrote:so If my kernel is loaded at 0x1000:0x0000 and let's assume it about 64k
it will end at 0x1000:0xFFFF so the next memory segment will start at 0x2000:0x0000

is that right?
Yes.

(The next segment after the segment 0x1000 (starting at linear address 0x10000) would be 0x1001 (starting at linear address 0x10010). The next free memory place in your scenario is at the linear address 0x20000. That could by in real mode addressing 0x2000:0x0000 or 0x1FFF:0x0010 or ... But usually one would use 0x2000:0x0000 as you proposed.)

--TS

EDIT: AJ beat me to it.

Re: real mode

Posted: Tue Mar 17, 2009 3:33 am
by xyjamepa
Yes. But be aware that theres also 0x1001:0xFFFF, 0x1002:0xFFFF and so on, which would also overlap the segment at 0x2000:0x0000
humm...
so what do you suggest,where should I load the programs?

Thanx.

Re: real mode

Posted: Tue Mar 17, 2009 3:38 am
by Hyperdrive
abuashraf wrote:
Yes. But be aware that theres also 0x1001:0xFFFF, 0x1002:0xFFFF and so on, which would also overlap the segment at 0x2000:0x0000
humm...
so what do you suggest,where should I load the programs?
If you always use segment 0x1000 and some arbitrary offset (0x0000-0xFFFF) to access your kernel code (and data?) then always using segment 0x2000 and some arbitrary offset (0x0000-0xFFFF) to access your program's code (and data?) would be okay. But then your kernel is limited to 64 KiB. If it is okay for you, go on...


[EDIT]

Maybe it would be better not to use segment 0x2000 for all programs and finding a specific one by the offset (e.g. program A is at 0x2000:0x0000 and has 2 KiB of code/data, program B is at 0x2000:0x0800 and has 16 KiB of code/data, program C is at 0x2000:0x4000 ...).

I probably would place every program in memory on a 16 byte boundary and calling it with the corresponding segment and an offset starting at 0x0000 (e.g. program A is at 0x2000:0x0000 and has 2 KiB of code/data, program B is at 0x2080:0x0000 has 16 KiB of code/data, program C is at 0x2400:0x0000 ...).

By that you're not limiting the space for all programs to 64 KiB. And I think that is how it was actually meant to be with that addressing scheme.

[/EDIT]

--TS

Re: real mode

Posted: Tue Mar 17, 2009 3:46 am
by xyjamepa
Yes,it's okay that it'll be limited to 64k
so I'll load my kernel at 0x1000:0x0000
command line interpreter will be loaded at 0x2000:0x0000
programs will be loaded at 0x3000:0x0000
and may be a simple GUI will be loaded at 0x4000:0x0000

is this right?is there any segment will overwrite another one?

Re: real mode

Posted: Tue Mar 17, 2009 3:47 am
by AJ
abuashraf wrote:so what do you suggest,where should I load the programs?
I would consider that a balance between a) Design choice and b) The system memory map.

Cheers,
Adam

Edit (due to your last post): If each of those things is OK to be limited to 64k, then fine. If not, the offsets will most likely wrap. Have you ensured that you understand real mode addressing before you start to write your kernel?

Re: real mode

Posted: Tue Mar 17, 2009 3:58 am
by xyjamepa
probably the GUI will need more than 64k,but I think it's okay because it's
located at the buttom,and nothing will be located after it.

my question would be,is it okay if somthing (e.g. program) crossed it's segment(more than 64k),
but it won't be okay if it's going to write over another program located in the next segment?

I'm right?

Thanx.

Re: real mode

Posted: Tue Mar 17, 2009 4:00 am
by Hyperdrive
abuashraf wrote:Yes,it's okay that it'll be limited to 64k
so I'll load my kernel at 0x1000:0x0000
command line interpreter will be loaded at 0x2000:0x0000
programs will be loaded at 0x3000:0x0000
and may be a simple GUI will be loaded at 0x4000:0x0000

is this right?is there any segment will overwrite another one?
As AJ said, it is okay, if your kernel, command line interpreter, all programs in sum, and the simple GUI are at maximum 64 KiB each. But consider, that your command line interpreter for example most likely won't be as big as that - you'll waste much memory here. And also consider that all programs share 64 KiB - you'll most likely will limit the amount of different programs here. I personally think that your layout is to rigid. But well, that's a design choice...

--TS

Re: real mode

Posted: Tue Mar 17, 2009 6:12 am
by xyjamepa
You are right,command line interpreter won't be as big as 64k ,probably will be much more smaller.
I personally think that your layout is to rigid
so,would you please suggest a layout considering:

kernel which is (mostly) will not pass 64k in size.
command line interpreter
programs
simple GUI.

thanx.

Re: real mode

Posted: Tue Mar 17, 2009 6:16 am
by AJ
Hi,

How about a heap-style dynamic memory allocator?

Cheers,
Adam

Re: real mode

Posted: Tue Mar 17, 2009 6:27 am
by xyjamepa
would you please give me more information about it

Re: real mode

Posted: Tue Mar 17, 2009 7:51 am
by Hyperdrive
abuashraf wrote:
I personally think that your layout is to rigid
so,would you please suggest a layout considering:

kernel which is (mostly) will not pass 64k in size.
command line interpreter
programs
simple GUI.
First of all: I personally would consider the command line interpreter and the GUI as normal programs too. So everything comes down to how to load programs and finding a suitable place in memory.

I'd like to second AJ for a heap-style pattern. But I'm not going to describe here how to do memory allocation and heap management. There are several information sources out there on the web from which you can learn. Here in the forum an often-quoted example is JamesM's tutorial that covers the heap stuff. You can get the idea behind it there and adopt it for your project. Just STFW.

--TS