Page 1 of 1
not 100% os related but...
Posted: Fri Feb 17, 2006 12:00 am
by robert macabre
is it possible to write position independant code?
what i mean is... is it possible to write code that can run no matter where it is in memory? i tried removing "phys=0x00100000" from my linker script just to see if it would work, but, obviously it didn't.
Re: not 100% os related but...
Posted: Fri Feb 17, 2006 12:00 am
by earlz
if you don't use any global vars it works fine. that is what i noticed anyway
Re: not 100% os related but...
Posted: Sat Feb 18, 2006 12:00 am
by Osbios
yes, you can.
For example you can use shorts jmps (128 Byte behind or ahead). In Realmode you can also copy CS to DS. Stuff like this...
In PMode it would be heavier but possible.
Do you plan to write a Virus? ^^
Re: not 100% os related but...
Posted: Sat Feb 18, 2006 12:00 am
by robert macabre
haha no virus :] i was just working on the planning apps in my os, but i know next to nothing about linker scripts. thank you both for the tips.
Re: not 100% os related but...
Posted: Sun Feb 19, 2006 12:00 am
by carbonBased
It's probably easier to use the paging hardware to ensure that all apps get loaded to the same virtual address. This also helps security by isolating the address space of each app from the others.
If you have any specific questions about linker scripts, feel free to pose them here. It's definitely worth while learning how to use linker scripts.
--Jeff
Re: not 100% os related but...
Posted: Mon Feb 20, 2006 12:00 am
by JAAman
i very much agree with carbonBased:
I use paging, then all applications are loaded at the same virtual address and no PIC or relocation-patching required
most
OSs do this, but they also use relocation -- that is, the program is compiled to run at a specific address, then the header provides the OS with a list of all address references within the code, and the OS changes them all to point to the correct location (this is of course a very simplified explaination -- i don't intend to use it myself -- all native apps should already be compiled to run in the appropriate location)
Re: not 100% os related but...
Posted: Mon Feb 20, 2006 12:00 am
by robert macabre
all right, paging sounds like making the code run would be a lot easier, but, what if my applications may rely on the ability to access each others spaces? is that possible with paging?
Re: not 100% os related but...
Posted: Mon Feb 20, 2006 12:00 am
by carbonBased
In my opinion, this is actually bad programming practice.
If apps wish to communicate with each other they should use a form of IPC. If they aboslutely require sharing address spaces between applications then a shared memory API can be developed.
In shared memory, the pager maps the same memory into the address space of both applications. In this way, the two applications can share information.
--Jeff
Re: not 100% os related but...
Posted: Mon Feb 20, 2006 12:00 am
by robert macabre
ugh. haha, all right. i don't care to keep doing it the way i'm doing it now. are you happy? no, seriously though, what site(s) would you recommend i learn about paging so that i can get it started?
Re: not 100% os related but...
Posted: Mon Feb 20, 2006 12:00 am
by carbonBased
My best source of info on paging was actually a book (which is a good source for any x86 pmode info):
Protected Mode Software Architecture - Tom Shanley
Mindshare, Inc.
0-201-55447-X
It's a great book, and I highly recommend it.
Once you've got a basic understanding of it, the concept is fairly simple, actually, and quite powerful. I intend on written up a quick overview/tutorial on it fairly soon once I get the latest release of my OS up (taking longer then expected to write docs and create the downloadable package! Was supposed to be available last month!)
--Jeff
Re: not 100% os related but...
Posted: Tue Feb 21, 2006 12:00 am
by blackcatcoder
It's the best way by doing it with paging!
If you want to have communication between two or more seperate progs use symbols and dynamic linking when you load the app !
Re: not 100% os related but...
Posted: Tue Feb 21, 2006 12:00 am
by JAAman
there are a lot of good tuts on
BonaFide OS Dev
ps. symbols and dynamic linking will not provide communication between apps at runtime -- not if your using paging
apps should
never have direct access to each others address space (though you could have a syscall that will dual map page(s) into multiple address spaces (for shared memory), but actual use of this technique should be minimized in apps, and direct access forbiden by paging (for security reasons -- this default sharing is a major security hole)
Re: not 100% os related but...
Posted: Thu Feb 23, 2006 12:00 am
by robert macabre
just for kicks, what would be the best way to compile global-variable-less code in a flat, binary format? i just want to explore the options, but i'm very bad with the compiler/linker/etc.
Re: not 100% os related but...
Posted: Sun Feb 26, 2006 12:00 am
by Da_Maestro
Dynamic Linking won't give you shared memory explicitly. Instead a much easier solution is to map the same physical memory to the two processes.