Welcome, Guest. Please login or register.

Author Topic: How can executables work when being thrown into different addresses on 68000 ?  (Read 12768 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline freqmaxTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2006
  • Posts: 2179
    • Show only replies by freqmax
The M68000 CPU has no MMU and thus can't move memory around and always present a neat linear memory such that all executables start at address zero. Instead executables must by necessity be copied into an arbitrary memory position and be made to work from that memory position. However this would require that all data manipulations using an addresses within the program, jumps, etc. Must all be changed for every loaded program. So how has this been solved in AmigaOS ?
 

Offline commodorejohn

  • Hero Member
  • *****
  • Join Date: Mar 2010
  • Posts: 3165
    • Show only replies by commodorejohn
    • http://www.commodorejohn.com
The executable file format, IIRC, provides a list of addresses that need to be adjusted for relocation. Also, the 68000 has a sizable range for relative branching (+/- 32KB) and highly orthogonal addressing modes, so it's entirely possible to construct code that doesn't use fixed addresses at all.
Computers: Amiga 1200, DEC VAXStation 4000/60, DEC MicroPDP-11/73
Synthesizers: Roland JX-10/MT-32/D-10, Oberheim Matrix-6, Yamaha DX7/FB-01, Korg MS-20 Mini, Ensoniq Mirage/SQ-80, Sequential Circuits Prophet-600, Hohner String Performer

"\'Legacy code\' often differs from its suggested alternative by actually working and scaling." - Bjarne Stroustrup
 

Offline freqmaxTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2006
  • Posts: 2179
    • Show only replies by freqmax
Alright so every executable on Amiga 0x000003F3 contains both code to be executed and address position list?

Such that when Exec is instructed to load an executable. It will copy the code to the allocated memory. Then Exec will use the table list of addresses and modify all address references..? before executing the code.
 

Offline rewlako

  • Newbie
  • *
  • Join Date: Apr 2012
  • Posts: 41
    • Show only replies by rewlako
The Amiga HUNK file format allows you to have both relative and absolute addressing on the data chunks. A file can contain a combination of many different HUNK types.

In short, when the EXEC loader hits a relocateable chunk (for example HUNK_RELOC32, $000003f7), the contents are loaded into an allocated memory space. The loader then proceeds to work on a lookup-table (also provided by the HUNK file) which contains the addresses to adjust accordingly.
 

Offline Thomas

There is no such think like an EXEC loader.

Loading modules is a function of  DOS.

Offline Fats

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 672
    • Show only replies by Fats
Quote from: freqmax;765183
Such that when Exec is instructed to load an executable. It will copy the code to the allocated memory. Then Exec will use the table list of addresses and modify all address references..? before executing the code.


BTW, also AmigaOS4, MorphOS and AROS use relocatable binaries.
Trust me...                                              I know what I\'m doing
 

Offline freqmaxTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2006
  • Posts: 2179
    • Show only replies by freqmax
By tradition or need? PowerPC has MMU asfair?
 

Offline commodorejohn

  • Hero Member
  • *****
  • Join Date: Mar 2010
  • Posts: 3165
    • Show only replies by commodorejohn
    • http://www.commodorejohn.com
Yes, PPC has an MMU - but everything in the Amiga system architecture is designed around a flat global memory map. Message-passing is as simple as handing over a pointer to the message to the receiving process. So introducing hardware relocation or other MMU concepts would either require an insane amount of bookkeeping on the part of the OS, or throw everything into chaos.
Computers: Amiga 1200, DEC VAXStation 4000/60, DEC MicroPDP-11/73
Synthesizers: Roland JX-10/MT-32/D-10, Oberheim Matrix-6, Yamaha DX7/FB-01, Korg MS-20 Mini, Ensoniq Mirage/SQ-80, Sequential Circuits Prophet-600, Hohner String Performer

"\'Legacy code\' often differs from its suggested alternative by actually working and scaling." - Bjarne Stroustrup
 

Offline freqmaxTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2006
  • Posts: 2179
    • Show only replies by freqmax
It should be possible to use the "page table" that the MMU uses to recalculate these pointers faster than the task switch takes? But I understand the benefits of pointer messaging (brilliant!).

There is one clear benefit as I can se. By avoiding the MMU one can also remove the latency between the CPU to memory and I/O.

I had  a deeper look into the Amiga executable format. And if I understand this correctly. An arbitrary memory location is allocated and the instruction sequence (code) is copied there. In the next step the operating system (DOS?) will use the relocation table if any to alter any absolute code location on the fly.

Seems softkick works in a similar manner with relocation tables. However the creation of those seems to be more magic that ordinary compiled files. Though trapping a debugger seems reasonable to find all absolute references in a ROM file.
 

Offline Fats

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 672
    • Show only replies by Fats
Quote from: freqmax;765208
By tradition or need? PowerPC has MMU asfair?


The need for MMU for multi-tasking OSes has grown when OSes evolved from single task to multi-task. Originally computers were single task with code hard linked to a certain start address. For the first multi-tasking OSes the whole process and it's state were swapped from memory and the next process image loaded. Next step was introduction of MMUs so programs could still think they were single task but actually were multi-tasking.
If you don't need this legacy there is no reason to not relocate the binaries during load. Some people think you need multiple adress spaces in order to provide memory protection. This is false, see SASOS for more information.
Trust me...                                              I know what I\'m doing
 

Offline donpalmera

  • Newbie
  • *
  • Join Date: Dec 2012
  • Posts: 44
    • Show only replies by donpalmera
Quote from: Fats;765259
The need for MMU for multi-tasking OSes has grown when OSes evolved from single task to multi-task. Originally computers were single task with code hard linked to a certain start address.


Relocation has been around forever. It's a must if you have code that is loadable at runtime.
Even if you have a machine that in most use loads a image to a fixed address and jumps there it's very unlikely that no one has never found a use for position independent code on it.

Quote from: Fats;765259
Next step was introduction of MMUs so programs could still think they were single task but actually were multi-tasking.


You don't need an MMU to do multitasking. MMUs are for memory protection and virtualising address spaces.

Quote from: Fats;765259
If you don't need this legacy there is no reason to not relocate the binaries during load.


If you want to have code that is loadable at runtime without switching out the complete task every time the active task changes you have to have relocation or some sort of address space virtualisation. It's far more sensible to have a table of addresses that have to be relocated by whatever loads the code than it is to move entire tasks around in memory.

Quote from: Fats;765259

Some people think you need multiple adress spaces in order to provide memory protection.


Who thinks that? Lots of microcontrollers provide limited memory protection without an MMU. I.e. write to address range X in user state causes an exception.
 

Offline Iggy

  • Hero Member
  • *****
  • Join Date: Aug 2009
  • Posts: 5348
    • Show only replies by Iggy
Argh!
Position independent coding has been around since the 8 bit cpu.
No MMU is needed.
Many OS' require it.
"Not making any hard and fast rules means that the moderators can use their good judgment in moderation, and we think the results speak for themselves." - Amiga.org, terms of service

"You, got to stem the evil tide, and keep it on the the inside" - Rogers Waters

"God was never on your side" - Lemmy

Amiga! "Our appeal has become more selective"
 

Offline Fats

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 672
    • Show only replies by Fats
Quote from: donpalmera;765266

Quote from: Fats;765259
Some people think you need multiple adress spaces in order to provide memory protection.

Who thinks that? Lots of microcontrollers provide limited memory protection without an MMU. I.e. write to address range X in user state causes an exception.


All those people who claim you can't introduce memory protection in amiga OS without breaking backwards compatibility. They make this claim because of taking memory protection by virtual address spaces as used in Windows and UNIX/Linux as a reference.
Trust me...                                              I know what I\'m doing
 

Offline psxphill

Quote from: freqmax;765181
However this would require that all data manipulations using an addresses within the program, jumps, etc. Must all be changed for every loaded program. So how has this been solved in AmigaOS ?

AmigaOS changes them for every loaded program. http://en.wikipedia.org/wiki/Amiga_Hunk
 
Quote from: donpalmera;765266
Who thinks that? Lots of microcontrollers provide limited memory protection without an MMU. I.e. write to address range X in user state causes an exception.

You missed his point. Most operating systems that use an MMU have separate memory spaces because it has other benefits, like avoiding memory fragmentation. Not because you need it to protect memory between tasks. If you don't have an MMU then you can't use separate address spaces or realistically protect memory between tasks.
 
Your limited memory protection sounds like the TLB in the 68EC040, which isn't really good enough for what AmigaOS uses the MMU for.
 
http://amigadev.elowar.com/read/ADCD_2.1/AmigaMail_Vol2_guide/node0161.html
« Last Edit: May 30, 2014, 04:33:16 PM by psxphill »
 

Offline itix

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 2380
    • Show only replies by itix
Quote from: Fats;765321
All those people who claim you can't introduce memory protection in amiga OS without breaking backwards compatibility. They make this claim because of taking memory protection by virtual address spaces as used in Windows and UNIX/Linux as a reference.


You must have misunderstood memory protection discussion on Amiga forums. You can't introduce memory protection in Amiga without breaking backwards compatibility and it has nothing to do with separate address spaces. AROS developers explained it quite we'll but can't find thread at the moment.
My Amigas: A500, Mac Mini and PowerBook