real mode

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.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

real mode

Post 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.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: real mode

Post 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
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: real mode

Post 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?
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: real mode

Post 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
Hyperdrive
Member
Member
Posts: 93
Joined: Mon Nov 24, 2008 9:13 am

Re: real mode

Post 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.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: real mode

Post 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.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
Hyperdrive
Member
Member
Posts: 93
Joined: Mon Nov 24, 2008 9:13 am

Re: real mode

Post 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
Last edited by Hyperdrive on Tue Mar 17, 2009 3:51 am, edited 1 time in total.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: real mode

Post 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?
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: real mode

Post 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?
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: real mode

Post 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.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
Hyperdrive
Member
Member
Posts: 93
Joined: Mon Nov 24, 2008 9:13 am

Re: real mode

Post 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
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: real mode

Post 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.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: real mode

Post by AJ »

Hi,

How about a heap-style dynamic memory allocator?

Cheers,
Adam
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: real mode

Post by xyjamepa »

would you please give me more information about it
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
Hyperdrive
Member
Member
Posts: 93
Joined: Mon Nov 24, 2008 9:13 am

Re: real mode

Post 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
Post Reply