Page 1 of 1

Segmentation

Posted: Wed Dec 22, 2010 1:37 pm
by bergen110
Hello,

When i place a value in a segment:offset, /*do i have the beginning of an memory manager?
Sorry for this question but i want to learn the basics of a memory manager right now*/

edit 2: is this value on an location memory?

Thanks

edit: Sorry for my poor English, i am Dutch

Re: Segmentation

Posted: Wed Dec 22, 2010 2:04 pm
by Combuster
From your question, I get the idea you don't know how segmentation works. Start with the basics, then work from there.
Sorry for my poor English, i am Dutch
Of all languages, Dutch is the worst excuse, imo.

Re: Segmentation

Posted: Wed Dec 22, 2010 2:05 pm
by Casm
In real mode, multiplying the value in a segment register by sixteen and adding an offset address gives you a real physical address in memory, so:

mov ax, 67h
mov es,ax
mov bx, 1234h
mov es:[bx], dl

would move the value in the dl register into memory location 18A4h

In protected mode the segment register contains an index into a look up table, which in its turn contains the segment's base address (amongst other things).

A memory manager is a piece of software which keeps track of which areas of memory are in use, and which are not, which allocates memory to other processes in the system, and frees it again when they are finished with it, and will most likely also maintain page tables. Typically those responsibilities are divided up between the physical memory manager and the virtual memory manager.

It sounds to me that you have got some serious reading to do if you have got any ideas about writing an operating system.

Re: Segmentation

Posted: Wed Dec 22, 2010 2:52 pm
by bergen110
Hello,

Thanks for the answers.
I have done plenty of hours of reading theory but memory is for me the hardest thing.
I have readed several books about Operating Systems.
And now i want to write my own, but i am stuck with the memory.
So i asked it here.
May be i am to young for this (14) but i want to do this for the fun i can have with it.
And because i am 14 i can't speak/write english very well.

edit:

this is the segmentation example i have made:

mov ax, 67h
mov es, ax
mov di, 1234h
mov ax, 10
mov [es:di], ax

Is this the right way? it works...


Thanks

Re: Segmentation

Posted: Wed Dec 22, 2010 5:23 pm
by Casm
bergen110 wrote: this is the segmentation example i have made:

mov ax, 67h
mov es, ax
mov di, 1234h
mov ax, 10
mov [es:di], ax

Is this the right way? it works...


Thanks
It may be right, depending upon the syntax of your assembler, but it has nothing to do with memory management. As for necessary reading, you could start off with this:

http://www.amazon.co.uk/gp/product/0135 ... d_i=468294

and then this:

http://www.intel.com/design/pentiumii/m ... 243192.htm

Re: Segmentation

Posted: Wed Dec 22, 2010 10:46 pm
by Brendan
Hi,
bergen110 wrote:Sorry for this question but i want to learn the basics of a memory manager right now*/
Ok, a quick crash course..

First, there's 3 different types of "memory manager" for different purposes.

The first type is the "Physical memory manager". It manages the actual RAM (and possibly things like deciding which areas of the physical address space to use for memory mapped devices).

The second type is the "Virtual memory manager". It creates (and destroys) virtual address spaces, and manages whatever is mapped into those virtual address spaces. This includes things like swap space, memory mapped files, shared areas, etc. It relies on the physical memory manager to allocate/free actual physical pages of RAM.

The third type is heap management. An OS should be flexible enough to support a wide range of different "heap managers", including different implementations of "malloc/free", different types of garbage collectors and "none" (where the application does it's own custom-designed memory management instead). Because different languages use different types of "heap managers", they are usually implemented in libraries. For example, for applications written in C you might have a "standard library" for C which includes a default implementation of malloc/free. Any heap management that processes use rely on the kernel's "virtual memory manager"; and therefore the kernel itself shouldn't have any heap management that processes use. However (for at least some people's kernels) it is possible/desirable to have some heap management built into the kernel that the kernel itself (and not processes) use. The kernel's heap manager should/would be specifically designed for the kernel's expected usage (and not designed as a general purpose heap manager).

Segmentation and paging are part of the kernel's "virtual memory manager". For most OSs segmentation is effectively disabled (all segments set to "base = 0, limit = MAX") and paging is used for everything. There's good reasons for this, but this is only a quick crash course...


Cheers,

Brendan