Page 1 of 1
Load code to low physical memory
Posted: Wed Aug 24, 2011 4:53 am
by TryHarder
Greetings,
I'm trying to add graphics to my OS. I've choose to switch graphic modes with VESA. After a lot of reading and seeking for a best way to cooperate with BIOS via VESA int 10h interface I've stayed for this solution: every time I need to switch to graphic mode from text mode (and probably back) I'll force my kernel to drop to real mode, make needed 'int 10h' calls, go back to protected mode. The problem is that the code that will do it for me should be in a low MB of physical memory because of Rmode. My bootloader switches to Pmode and loads kernel into the high physical memory. Now I'm seeking for easy solution of placing relevant code into low physical memory. One approach that I've though about is a simple copy of relevant memory area with a code to low address at the kernel initialization stage, but this sounds a bit problematic and hackish. Can you suggest me a better way of doing that?
Re: Load code to low physical memory
Posted: Wed Aug 24, 2011 5:30 am
by djmauretto
Can you suggest me a better way of doing that?
V86 mode

Re: Load code to low physical memory
Posted: Wed Aug 24, 2011 5:51 am
by Combuster
Virtual 8086 mode is meant to solve the issue of having to revert system configuration when going back to real mode, at the cost of complexity elsewhere. It does not save the OP from actually getting code running under the 1MB mark, but it can now be performed using paging rather than making a physical copy and associated memory usage constraints.
But yes, in all cases you have to copy code to under the 1M mark, and make sure it actually is capable of running there. You can hand-write position independent assembly and copy it whereever. You can also embed a fixed address in it instead. In either case, you'll want to have a start and end pointer to this code block as you'll end up moving it around.
As far as professionalism is concerned, some people believe that any use of 16-bit code is a violation of that, so you might just as well get over it.
Re: Load code to low physical memory
Posted: Wed Aug 24, 2011 5:56 am
by TryHarder
djmauretto wrote:V86 mode
Thanks for response!

I've considered this possibility and discarded it because V86 requires great kernel support for tons of 'sensitive' instructions, mainly because interrupt stuff. Also, as far as I understand, it's a way harder to get V86 mode working.
V86 mode is very convenient for running old applications written for Rmode, because it was designed for that, but less convenient for running kernel code (switching from Pmode to V86 designed to occur in interrupts stub).
Re: Load code to low physical memory
Posted: Wed Aug 24, 2011 6:00 am
by TryHarder
Combuster wrote:
But yes, in all cases you have to copy code to under the 1M mark, and make sure it actually is capable of running there. You can hand-write position independent assembly and copy it whereever. You can also embed a fixed address in it instead. In either case, you'll want to have a start and end pointer to this code block as you'll end up moving it around.
As far as professionalism is concerned, some people believe that any use of 16-bit code is a violation of that, so you might just as well get over it.
That's exactly what I'm about to do. Just thought maybe there are some common ways of doing that (bootloader tweaks or so).
Could you please explain your last sentence? You saying that I can avoid 16bit code in my case?
Re: Load code to low physical memory
Posted: Wed Aug 24, 2011 6:08 am
by Combuster
Well, yes you can, and if you read the FAQ it has some starting pointers on that. The same page also tells you that those ways are significantly more complex and the choice not to do things the "best" way is mostly a practical one.
Re: Load code to low physical memory
Posted: Wed Aug 24, 2011 6:33 am
by TryHarder
Thanks for advices. Honestly, I've been seeking for some way to avoid Rmode last 3 days. The closest thing I got is VESA3.0 protected mode interface. But my card supports only VESA2.0. Another attempt is a kind of translating software, but there's nothing ready-to-use (or I've missed some?). Of course I can write some of mine, but it will take a lot of time, and I don't have it
