Welcome, Guest. Please login or register.

Author Topic: Odd programming question  (Read 6584 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline trekiejTopic starter

Odd programming question
« 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
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Odd programming question
« Reply #1 on: March 09, 2008, 06:55:03 PM »
@trekiej
Quote
Outside of header files and libraries, when does OS specific information get added?

Could you clarify that question a bit? What OS specific information?
Quote
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).

Quote
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?
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: Odd programming question
« Reply #2 on: March 09, 2008, 07:22:30 PM »
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.
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #3 on: March 09, 2008, 07:42:40 PM »
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  :-(
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Odd programming question
« Reply #4 on: March 09, 2008, 07:42:48 PM »
Well, considering this is in Alternative Operating Systems section I don't think he's asking about AmigaOS ABI in particular.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Odd programming question
« Reply #5 on: March 09, 2008, 07:44:42 PM »
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).
 

Offline Kronos

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: Odd programming question
« Reply #6 on: March 09, 2008, 07:50:28 PM »
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Odd programming question
« Reply #7 on: March 09, 2008, 07:57:26 PM »
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #8 on: March 09, 2008, 08:05:47 PM »
I feel like there is information added during compile time that the user does not have to provide.

Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Odd programming question
« Reply #9 on: March 09, 2008, 08:11:05 PM »
Such as?

(There is startup code added normally, but why would you need to worry about it?)
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #10 on: March 09, 2008, 08:15:03 PM »
@ 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?
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Odd programming question
« Reply #11 on: March 09, 2008, 08:16:18 PM »
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 for example. I can't see a reason to bother oneself about such messy details, however.
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #12 on: March 09, 2008, 08:31:05 PM »
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.
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: Odd programming question
« Reply #13 on: March 09, 2008, 09:21:01 PM »
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 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.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Odd programming question
« Reply #14 on: March 09, 2008, 10:10:32 PM »
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).