not 100% os related but...
-
- Member
- Posts: 26
- Joined: Fri Nov 18, 2005 12:00 am
- Location: a perfect view out of the novotel
not 100% os related but...
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.
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.
Re: not 100% os related but...
if you don't use any global vars it works fine. that is what i noticed anyway
Re: not 100% os related but...
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? ^^
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
-
- 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...
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.
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: not 100% os related but...
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
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...
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)
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)
-
- 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...
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.
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: not 100% os related but...
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
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
-
- 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...
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.
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: not 100% os related but...
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
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
-
- Member
- Posts: 132
- Joined: Wed Nov 03, 2004 12:00 am
- Location: Austria
- Contact:
Re: not 100% os related but...
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 !
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...
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)
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)
-
- 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...
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.
-
- Member
- Posts: 144
- Joined: Tue Oct 26, 2004 11:00 pm
- Location: Australia
Re: not 100% os related but...
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
--- Albert Einstein