not 100% os related but...

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.
Post Reply
robert macabre
Member
Member
Posts: 26
Joined: Fri Nov 18, 2005 12:00 am
Location: a perfect view out of the novotel

not 100% os related but...

Post 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.
laika, come home.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: not 100% os related but...

Post by earlz »

if you don't use any global vars it works fine. that is what i noticed anyway
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

Re: not 100% os related but...

Post 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? ^^
dw 0xAA55
robert macabre
Member
Member
Posts: 26
Joined: Fri Nov 18, 2005 12:00 am
Location: a perfect view out of the novotel

Re: not 100% os related but...

Post 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.
laika, come home.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: not 100% os related but...

Post 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
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: not 100% os related but...

Post 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)
robert macabre
Member
Member
Posts: 26
Joined: Fri Nov 18, 2005 12:00 am
Location: a perfect view out of the novotel

Re: not 100% os related but...

Post 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?
laika, come home.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: not 100% os related but...

Post 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
robert macabre
Member
Member
Posts: 26
Joined: Fri Nov 18, 2005 12:00 am
Location: a perfect view out of the novotel

Re: not 100% os related but...

Post 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?
laika, come home.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: not 100% os related but...

Post 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
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: not 100% os related but...

Post 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 !
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: not 100% os related but...

Post 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)
robert macabre
Member
Member
Posts: 26
Joined: Fri Nov 18, 2005 12:00 am
Location: a perfect view out of the novotel

Re: not 100% os related but...

Post 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.
laika, come home.
Da_Maestro
Member
Member
Posts: 144
Joined: Tue Oct 26, 2004 11:00 pm
Location: Australia

Re: not 100% os related but...

Post 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.
Two things are infinite: The universe and human stupidity. But I'm not quite sure about the universe.
--- Albert Einstein
Post Reply