Welcome, Guest. Please login or register.

Author Topic: How to Hijack the classic Amiga hardware?  (Read 5439 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline MskoDestnyTopic starter

  • Sr. Member
  • ****
  • Join Date: Oct 2004
  • Posts: 363
    • Show only replies by MskoDestny
    • http://www.retrodev.com
How to Hijack the classic Amiga hardware?
« on: November 09, 2005, 04:30:59 AM »
I'm writing an operating system and I'm thinking about doing my initial development on it targetting the Amiga (specifically my A4000). So I'm looking for information about two things:

1) How to gain complete control over the processor (get into system mode basically)
2) How to control the basic Amiga hardware without any help from the OS libraries/kickstart ROM.

Since the idea is to replace Amiga OS once the new OS is loaded, there's no need to be system friendly (beyond being able to boot after workbench has loaded). Also the Amiga won't be the primary target(well unless a bunch of weird Amigans want to run a PalmOS clone on their Amigas for some reason) in the long run (it's just a fun and accessible place to start) so making the bootloader flexible isn't a big requirement. It just has to work on my Amiga.
 

Offline Zac67

  • Hero Member
  • *****
  • Join Date: Nov 2004
  • Posts: 2890
    • Show only replies by Zac67
Re: How to Hijack the classic Amiga hardware?
« Reply #1 on: November 09, 2005, 07:22:24 AM »
No offense meant, but you asking these questions (esp. 1) kind of leaves me in doubt that you're really up to the task...
If you don't target the Amiga as primary system, but just use it as a development platform, there's no need for 2) since you leave it to normal Kickstart to setup the hardware (RAM, caches, IDE, video, ...) and then take over the machine much like most games do it or other OSes.
If you're going to ask 'Then how do I take over the machine?' you're definitely not up to it, sorry.
Furthermore, writing a modern OS is nothing one single person can do in his lifetime...
 

Offline msh5150

  • Newbie
  • *
  • Join Date: Nov 2005
  • Posts: 10
    • Show only replies by msh5150
Re: How to Hijack the classic Amiga hardware?
« Reply #2 on: November 09, 2005, 08:54:36 AM »
To get you started the following might be of interest:

movea.l 4.s,a6           ;Execbase
jsr     _LVOForbid(a6)   ;Disable multitasking

lea    $dff000,a5        ;Custom chip base
move.w #$7FFF,intena(a5) ;Disable interrupts
move.w #$7FFF,dmacon(a5) ;Disable DMA

..... You can now do what you like :)

If you are running on 68010+ your VBR will be 0 at this point.

This code can be on a bootblock. But of course if you disable everything then you'll need to make your own raw trackloader. (Isn't that hard).
 

Offline darkcoder

  • Full Member
  • ***
  • Join Date: Sep 2002
  • Posts: 164
    • Show only replies by darkcoder
Re: How to Hijack the classic Amiga hardware?
« Reply #3 on: November 09, 2005, 10:07:40 AM »
Quote

..... You can now do what you like :)

If you are running on 68010+ your VBR will be 0 at this point.


Are you sure? LVODisable does not change VBR, and I never heard that forbid does...
The Dark Coder / Trinity
 

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: How to Hijack the classic Amiga hardware?
« Reply #4 on: November 09, 2005, 10:16:23 AM »
@MskoDestny
hwstartup.asm

The code does a bit more than is really needed, and also includes cleanup code, but at least it should give you some idea what needs to be done.
 

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: How to Hijack the classic Amiga hardware?
« Reply #5 on: November 09, 2005, 10:20:11 AM »
@msh5150
Quote
movea.l 4.s,a6 ;Execbase
jsr _LVOForbid(a6) ;Disable multitasking

lea $dff000,a5 ;Custom chip base
move.w #$7FFF,intena(a5) ;Disable interrupts
move.w #$7FFF,dmacon(a5) ;Disable DMA

Forbid is not enough, you must Disable.

Quote
If you are running on 68010+ your VBR will be 0 at this point.

There is no guarantee of this. Better not assume anything about the initial VBR value.
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: How to Hijack the classic Amiga hardware?
« Reply #6 on: November 09, 2005, 11:13:46 AM »
Even though you don't return to the OS, you really should first call LoadView(NULL), followed by two WaitTOF()s. This is so that if the user launches your OS after AmigaOS has booted, any graphics card screens are guarranteed to be switched out.
Playstation Network ID: xeron6
 

Offline msh5150

  • Newbie
  • *
  • Join Date: Nov 2005
  • Posts: 10
    • Show only replies by msh5150
Re: How to Hijack the classic Amiga hardware?
« Reply #7 on: November 09, 2005, 12:09:36 PM »
When in a bootblock I've never had my VBR be anything other than 0. But to cover all bases then use _LVOSupervisor() to do a VBR read.

Is a need to call Disable()?  I've killed interrupts in hardware with the intena write surely?

@xeron
Yes, he probably should  :-D  (Hi BTW - was there ever another Fast Intro Comp on #amigascne? Or a sequel to DotMatrix?  8-) )
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: How to Hijack the classic Amiga hardware?
« Reply #8 on: November 09, 2005, 12:48:17 PM »
Hey Musashi, no there never was another #amigascne fast compo. I've done the following scenish things since then:

http://www.pouet.net/prod.php?which=12044
http://www.pouet.net/prod.php?which=16349
http://www.pouet.net/prod.php?which=18905
http://www.pouet.net/prod.php?which=16308
Playstation Network ID: xeron6
 

Offline hppacito

  • Jr. Member
  • **
  • Join Date: Oct 2005
  • Posts: 84
    • Show only replies by hppacito
Re: How to Hijack the classic Amiga hardware?
« Reply #9 on: November 09, 2005, 12:49:36 PM »
Could be a good idea to have a look at the NetBSD for initialization purposies and hw interface. BTW, if you do not plan to use the MMU (by far, a complicated task), could be a good idea to target the A500 or A600. A lees complicated processor. Try to use UAE to run your soft, that will save you plenty of time ;-)

As was already demostrated several times, a modern kernel can be done by one person. A modern OS is a bit more than a kernel. But a working shell should be your safe bet milestone.
2x A500 1MB ;-)
1x A600
3x PCs
1x Gf  :crazy:
 

Offline c64_d0c

  • Sr. Member
  • ****
  • Join Date: Sep 2004
  • Posts: 383
    • Show only replies by c64_d0c
Re: How to Hijack the classic Amiga hardware?
« Reply #10 on: November 09, 2005, 12:59:12 PM »
you're definitely not up to it... just give up and start on a easyer project...
________
Ford Falcon (Argentina) Specifications
« Last Edit: May 08, 2011, 05:50:52 AM by c64_d0c »
On schedule and rockin\\\'!!!1!!
 

Offline MskoDestnyTopic starter

  • Sr. Member
  • ****
  • Join Date: Oct 2004
  • Posts: 363
    • Show only replies by MskoDestny
    • http://www.retrodev.com
Re: How to Hijack the classic Amiga hardware?
« Reply #11 on: November 09, 2005, 01:16:35 PM »
Quote

Zac67 wrote:
No offense meant, but you asking these questions (esp. 1) kind of leaves me in doubt that you're really up to the task...

Well I could just poke the vector table (either the reset vector or some interrupt I know is going to happen soon), but I figured it would be wise to ask here the best approach in case there were any gotchas I should worry about. For all I know the vector table could be in ROM and you can't exactly muck about with VBR in user mode. Heck on many operating systems you can't even poke around in the vector table because it's protected with the MMU (though as I understand it that's not the case on the Amiga).

Quote
If you don't target the Amiga as primary system, but just use it as a development platform, there's no need for 2) since you leave it to normal Kickstart to setup the hardware (RAM, caches, IDE, video, ...) and then take over the machine much like most games do it or other OSes.

It's difficult to write a proper pre-emptive scheduler that runs in user mode. Besides, part of the reason I'm targetting the Amiga is to better understand how the hardware works.

Quote
If you're going to ask 'Then how do I take over the machine?' you're definitely not up to it, sorry.
Okay Mr. Bad Attitude.

Quote
Furthermore, writing a modern OS is nothing one single person can do in his lifetime...
AtheOS was written by a single person. It's now maintained by several people as Syllable, but it was a complete modern working operating system as AtheOS. I've already written an implementation for most of the functionality in the Palm OS memory manager (though once I tackle the MMU, I need to tweak the memory allocator so that two processes can't allocate memory in the same page and to deal with fragmentation using the MMU) and that probably took about a days worth of effort, two at the most.

Quote
movea.l 4.s,a6 ;Execbase
jsr _LVOForbid(a6) ;Disable multitasking

lea $dff000,a5 ;Custom chip base
move.w #$7FFF,intena(a5) ;Disable interrupts
move.w #$7FFF,dmacon(a5) ;Disable DMA

But that will leave me in user mode won't it? Is code in the bootblock of a floppy started in system or user mode? Is there a guide on the format of the bootblock somewhere?

Quote

From hwstartup.asm:
; if full interrupt control is desired, _main must _LVODisable,
; save intenar and disable all interrupts by writing $7fff to
; intena. to restore, write $7fff to intena, or $8000 to saved
; intenar value and write it to intena, and finally _LVOEnable.

So I'm guessing intenar is the read version of intena and that intena is used to control the interrupts generated by the hardware?

Quote
Could be a good idea to have a look at the NetBSD for initialization purposies and hw interface.

Reading driver source code to figure out how the hardware works is a bit of a pain. I suppose the bootloader might be useful, but the code Piru posted seems to have set me in the right direction.

Quote
BTW, if you do not plan to use the MMU (by far, a complicated task), could be a good idea to target the A500 or A600. A lees complicated processor. Try to use UAE to run your soft, that will save you plenty of time

Well I do plan to use the MMU eventually and unfortunately neither the A500 or UAE have an MMU. One of my goals in this project is to bring memory protection to classic Palm OS and I will need to deal with memory fragmentation and I'd rather not use the hackish mechanism Palm OS 5 and below use to deal with that.
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: How to Hijack the classic Amiga hardware?
« Reply #12 on: November 09, 2005, 01:48:22 PM »
Quote
Well I do plan to use the MMU eventually and unfortunately neither the A500 or UAE have an MMU. One of my goals in this project is to bring memory protection to classic Palm OS and I will need to deal with memory fragmentation and I'd rather not use the hackish mechanism Palm OS 5 and below use to deal with that.
 


Are you sure? I'm could have sworn that the 040 emulation in UAE does support the MMU...

Offline MskoDestnyTopic starter

  • Sr. Member
  • ****
  • Join Date: Oct 2004
  • Posts: 363
    • Show only replies by MskoDestny
    • http://www.retrodev.com
Re: How to Hijack the classic Amiga hardware?
« Reply #13 on: November 09, 2005, 02:03:46 PM »
A quick google shows mention of a preliminary MMU patch, but I haven't seen any evidence this was integrated into the main source tree. It also looked like it might not be working 100%.

Frankly, I've had bad experiences in the past testing code on emulators so I'd rather not do it now.
 

Offline msh5150

  • Newbie
  • *
  • Join Date: Nov 2005
  • Posts: 10
    • Show only replies by msh5150
Re: How to Hijack the classic Amiga hardware?
« Reply #14 on: November 09, 2005, 03:23:39 PM »
"But that will leave me in user mode won't it? Is code in the bootblock of a floppy started in system or user mode? Is there a guide on the format of the bootblock somewhere?"

Yes it will. If you want to be in supervisor mode use the exec call _LVOSupervisor() and then take over the machine after that.

The bootblock is 1K long.  The first 4 bytes are 'DOS' and then a number. Usually 0, but can be others. You can also use the word 'BOOT' for the first 4 bytes (I think).

The next 4 bytes are the checksum. Amiga won't boot your code unless this is correct.

The next 4 bytes are a block pointer to the root block (this can be ignored as you are making your own system and don't need to adhere to AmigaOS specs).

You can find more info about it here:
http://amiga.emugaming.com/adfaq.html

IMHO you might be best off doing some 'oldskool' hardware bashing code first to learn about the hardware (like trackloaders or copper/blitter effects).  Then try to build on this experience later. I'm sure most people reading this topic will have gained thier experience that way.