This is a continuation of a project I'm working on for some time (I also opened a question for anotehr isse related to the project: http://www.experts-exchange.com/Programming/Programming_Languages/Assembly/Q_21833126.html
) and that is why I am now here.
- I use nasm and gcc to create the application and bootloader (see my last comment in the above question).
- I decided to use real mode instead of protected mode as I do not need multi tasking, and over 1 MB memory and stuff like that, plus that I need direct hw access and other low level stuff, so I though there is no reason to get complicated with (mainly) memory management (will use the same addressing for code/data and hw access)
- I just hit an issue with memory management. it's probably just a confusion from my side, but I read on pmode and real mode and just can't seem to figure my way out of this.
I already have about 50% of needed asm code written (UI, the rest of 50% is the applicaiton main objective: hardware interfacing) Also I have about 30% of C code written (also UI)
now I came to the issue of writing a very simple and basic memory manager, that will provide access to the 640KB conventional memory (way too much for my needs). BUT. Until now, I was absolutly sure that I will not need more than 64KB of memory for all operations of my application. Now, after starting with the UI, I am not so sure (UI is in text mode) As I only wrote about 30% of UI, I now have about 10KB of memory (at least) used only by the existing code (for caching, and other stuff) and there are still a few things to be done, so that is why I am starting to think that I might exceeed my inital estimate of one segment for data (the code will fit in one segment for sure)
So now I am considering that I will have one segment for code, maybe one for stack (just to be on the safe side) and at least 2 segments for data. and this complicates everything (or at least is generating a lot of confusion for me).
so I know that a C pointer (gcc) is only the offset (I hope I'm not wrong with this...). until now that, wasn't a problem with having one data segment. but now that I will have possibly 2 or more, I just don't have a clue on how to work with these pointers.
so I have a C function that takes as an argument a C pointer. say:
extern void func1(char* c);
extern char* func2();
and the function is implemented in asm (nasm):
- how will I correctly access the data in func1 ? (C pointer is 4 bytes, but is still only an offset - if I understood it correctly)
- how will I pass to the C part of the program the address of the data initialized in func2? so that:
char* c = func2();
c = '3';
will use the correct data from memory (segm:offs)
ever since I started to think on this issue and read a few stuff on both protected and real mode, everything is fuzzy in my head and I am not even sure on the single data segment implementation anymore.
As I said above, all my asm code is written having real mode in mind and thus is all 16 bit and all that. So if switching to protected mode is the only way out, is there anything I have to worry about besides memory access/handling which obviously needs to be changed?
I would really prefer a solution so that I will not have to change anything on the current implementation (because then I will most likely have to change design as well and changes might become ugly and drastical)
I would like to underline that char* is a simple example. I will have pointers to structures/unions and various blocks of data, which needs to be accessed from both asm and C (I already have a few such structees: that's why I know about the aprox 10 KB need).
I don't mind if I receive some GOOD links to read on this memory issues/C pointers/addresses and how to interface between asm and C (with pointers), but I want those info to be as clear as possible as I am already filled with various information that made me get into this confused state.
I would appreciate some examples with explanations on this interfacing stuff (working with multiple segments in asm only is not an issue for me: it's the way I take that "pointer" (address = segm:offs) from asm and use it in C)
(note: I'll put a pointer in the ASM TA to this just in case)