Welcome, Guest. Please login or register.

Author Topic: Odd programming question  (Read 6614 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: Odd programming question
« 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 Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: Odd programming question
« Reply #1 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 Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: Odd programming question
« Reply #2 on: March 09, 2008, 10:38:13 PM »
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?
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: Odd programming question
« Reply #3 on: March 09, 2008, 10:46:15 PM »
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?
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: Odd programming question
« Reply #4 on: March 09, 2008, 11:04:29 PM »
@trekiej

AmiDevCPP has a toolchain for OS3, too.

@SamuraiCrow

Dude, way to add fuel to the fire. ;-)
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: Odd programming question
« Reply #5 on: March 10, 2008, 01:52:29 AM »
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.
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: Odd programming question
« Reply #6 on: March 10, 2008, 03:56:48 AM »
And by basic, I didn't mean beginning. Compilers, linkers, loaders, etc. aren't usually the topics that people start with.