Amiga.org
The "Not Quite Amiga but still computer related category" => Alternative Operating Systems => Topic started by: trekiej on March 09, 2008, 06:37:46 PM
-
Outside of header files and libraries, when does OS specific information get added?
When I run a programm, how does the OS allocate memory and give control to the application and the application give it back.
The OS gives the application access to resources, how does it know what to give?
Source > Object > linking > Binary
-
@trekiej
Outside of header files and libraries, when does OS specific information get added?
Could you clarify that question a bit? What OS specific information?
When I run a programm, how does the OS allocate memory and give control to the application and the application give it back.
OS allocates memory in whatever way it does. You don't need to worry about that. Or what exactly are you asking here?
Entering the application typically happens by entering the very beginning of the first (code) segment. Application gives the control back by executing 'return from subroutine' with the original stack pointer (some platforms have different way to terminate, however).
The OS gives the application access to resources, how does it know what to give?
Again, I'm not quite sure what you're asking here. Access control for privileged resources?
-
In Amigaland, you transfer control to the operating system by calling library functions. Piru knows a lot more about this than I do, but generally, your header files include function table offsets (indexes). You store the library base address in your application via LoadLibrary, and a call to a function loads the table and jumps to the address referenced by the index.
In other systems, control is usually passed to the operating system using a system call instructon or interrupt or an invalid instruction exception trapped by an operating system dispatch routine. Windows uses INT 2E, for example, and Linux uses INT 80 (on x86--different architectures provide different means for making system calls).
For resources, the system functions store and keep track of allocations. For example, AllocMem and AllocVec track memory allocation. It's the application's responsibility to notify the system when those resources are no longer needed. This is true in most operating environments, althogh some, like Java, have garbage collection routines that will clean up resources that are no longer in use.
-
Thanks alot. I want to know more about OS and Application interactivity.
I guess I need to find out how a kernel works to get the info. in need. As CSI Grissom would say, I am looking for the right question.
I know I have asked a similar question before and it led to System Calls. I want to know how my application gets to the real world and there seems to be more than one answer.
What I wish I could do is learn how to use the header files and libraries to make a window to put my app.
Right now making a console app on an Amiga will do.
I wish they would teach Amiga Dos in college.
Windoz,Windoz,Windoz :-(
-
Well, considering this is in Alternative Operating Systems section I don't think he's asking about AmigaOS ABI in particular.
-
Erm. Now I'm really confused.
If you're writing programs you don't need to know how the ABI works internally, It Just Works.
If you wish to have a GUI, look into intuition and gadtools, or if you wish to have something more fancy, MUI. All of those have plenty of programming examples (intui in RKRM, MUI in mui dev archive).
-
If you just want to use Amiga-Windows ...
[shameless plug]
http://www.steamdraw.de/intuition1.c (http://www.steamdraw.de/intuition1.c)
http://www.steamdraw.de/intuition2.c (http://www.steamdraw.de/intuition2.c)
http://www.steamdraw.de/intuition3.c (http://www.steamdraw.de/intuition3.c)
http://www.steamdraw.de/intuition4.c (http://www.steamdraw.de/intuition4.c)
[/shameless plug]
:-D
-
And while we're at it:
http://www.iki.fi/sintonen/src/misc/simplewindow.c
-
I feel like there is information added during compile time that the user does not have to provide.
-
Such as?
(There is startup code added normally, but why would you need to worry about it?)
-
@ Piru:
Maybe that is what gets me. :-D
Learning C in an intro class we used include iostream.h to get I/O.
How does iostream.h work?
-
That's C++.
Why would you need to worry about how it works? Those things are something you don't need to worry about. You can concentrate on your own code.
Anyhoo, iostream is typically compiler specific. If you really must, you could take a look at gcc implementation (http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/src/) for example. I can't see a reason to bother oneself about such messy details, however.
-
Alright, thanks.
I will put this on the back burner.
I will look into how to work with libraries, etc.
I can not seem to get my c++ finished. I guess I can still work with the Amiga without it.
-
There's nothing wrong with wanting to know how it all works, but what I think Piru is getting at is that you don't need to know how system calls work to write userland applications. All you need is a set of standard C (or C++) libraries, and you're good to go, on just about any operating system.
The source code for most C runtimes is available from the runtime's publisher. Even Microsoft ships runtime source code with their commercial compilers. Unfortunately, Amiga compilers are the exception, unless you're using gcc. Mapping most C library functions to an Amiga library function isn't too difficult, though.
MIT's OpenCourseWare program has a nice operating systems class available at http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-828Fall-2006/CourseHome/index.htm (http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-828Fall-2006/CourseHome/index.htm) You'll start out by looking at how UNIX works, and by the end of the class, you'll have written your own operating system.
-
Sure all that is very interesting indeed, but I think it might be a bit too early for trekiej to delve into all that yet.
Granted, class explaining how to build your own OS from scratch could work even for beginners (as you then are not required to read and understand thousands of lines of existing code).
-
There are some questions, though, that a beginning Amiga programmer might want to ask (I know I did):
What is amiga.lib, and when and why do I need it? What about my compiler's standard libraries?
What is auto.lib, and when and why do I need it?
Why does my console application exit before calling main?
Why does my compiler/linker come with more than one startup module? Which one do I use?
And it probably won't take long before a new programmer has to figure out why a seeminlgy innocent call to printf gurus.... For all their detail, the RKMs don't spend enough time discussing concurrency issues as they relate to the OS. Instead, they refer you to a standard work on operating systems, which, while relevant, won't take into account Amiga OS specifics. (EDIT: Of course, that's exactly what I did, too. ;-))
I think the OP will soon be back with some reasonable usage questions, too, e.g. what's the difference between printf and Printf?
-
Is making a basic console program easy to do?
-
Very:
/* hello.c */
#include
int main(int argc, char * argv[])
{
printf("Hello, world!");
return 0;
}
EDIT: That's C, of course. C++ came into its own after most compiler developers had left the Amiga behind.
What compiler are you using?
-
For Amiga, nothing. I am looking to use StormC.
GCC for linux.
AmiDevCPP for widows. (AROS)
Murks IDE
-
@trekiej
First of all, when a compiler compiles code, it goes directly to binary. What the linker does is add bits of code that are functions supplied by the makers of the library being linked.
If you want something that doesn't care what operating system it uses when you compile it, you'll need one that has an intermediate representation of the code. For the Mattathias Basic project, Sidewinder and I am working with Low-Level Virtual Machine (http://www.llvm.org/). It's bitcode will link to several different operating systems and processor code types.
-
@trekiej
AmiDevCPP has a toolchain for OS3, too.
@SamuraiCrow
Dude, way to add fuel to the fire. ;-)
-
@Samurai Crow
Looks like you are working on something interesting.
Also, when the program gets changed to binary is there anything else the compiler does?
@Trev
Sure I knew that about AmiDev. :oops:
-
Then you've got an Amiga environment ready to roll.
You're asking really basic compiler/linker questions, though. Try here: http://en.wikipedia.org/wiki/Linker (http://en.wikipedia.org/wiki/Linker).
-
Thanks
-
And by basic, I didn't mean beginning. Compilers, linkers, loaders, etc. aren't usually the topics that people start with.
-
trekiej wrote:
Outside of header files and libraries, when does OS specific information get added?
When I run a programm, how does the OS allocate memory and give control to the application and the application give it back.
The OS gives the application access to resources, how does it know what to give?
Source > Object > linking > Binary
Your compiler implementation provides the standard C library (and maybe C++ library, etc too). The interfaces to these libraries, eg stdlib.h, stdio.h etc should provide the same set of functions across different platforms. They may vary depending on compiler age/version and even on platform but for example, stdio.h should provide you with the printf() function, for example, pretty much everywhere you go.
The implementation of these libraries, however is basically up to the compiler and the platform, as long as they provide the functionality advertised in the headers.
Your platform provides basic IO, memory management etc that the C library implementation for that platform uses. Essentially therefore, you can view your compiler's C standard library implementation as an abstraction layer to OS specific features.
When your code is linked, as well as the platform specific implementation of the C standard library, platform specific startup code is added that ensures your various IO streams etc. are available and ultimately invokes main() in your application.
Having said all this, you don't need to worry about any of it. As Piru stated, "It Just Works". How it works is really only of academic interest.
-
SamuraiCrow wrote:
@trekiej
First of all, when a compiler compiles code, it goes directly to binary.
I think it's not helpful to confuse beginners as they might wonder what the assemblers job then is.
-
Compiler, linker, assembler are not a problem. It is how the OS looks at and responds to the program. I wish I had a explanation of all that happens when a program loads. This is imo different for different OS.
-
It is how the OS looks at and responds to the program. I wish I had a explanation of all that happens when a program loads. This is imo different for different OS.
Even if it is, you don't need to worry about it. As long as you use the C standard library functions (http://en.wikipedia.org/wiki/C_standard_library) you will be just fine, regardless of the underlying OS.
That's the beaty of ANSI C (http://en.wikipedia.org/wiki/ANSI_C), it's very very portable.
-
I appreciate all replies.
In the end I guess I will need to get into Kernel Dev to get the full understanding.
On a side note, do files have headers. I do not mean xxx.h in a C program. Is this not how an OS knows the difference between files?
@Karlos:
That is where I want to head with this. I may get into Kernel Dev. with Linux but may go a non-programming route with my career.
-
trekiej wrote:
I appreciate all replies.
In the end I guess I will need to get into Kernel Dev to get the full understanding.
You can do that if you want to understand *internals* of a particular kernel, otherwise I'm not sure exactly what you want to understand, but if it is what I *think* it is then you better learn to write some code in asm. calling OS functions (APIs) in asm will show you what you want to know I'm guessing.
-
@Einstein: Maybe one day I will. I have too much to do and need a job to go further. I have a part-time job but it is not enough. I like too much technology and need to pick one and go with it.