MorphOS 1.4 software power off story...
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 408 from 2004/7/15
    From: Russia, Moscow
    Yesterday i've spent a wonderful exciting evening devoted to this little long-standing problem. And here are results: the operation is quite simple, however it can't be accomplished inside MorphOS environment. Here is a short description of what and why (for all curious guys here):
    1) Besides sending a shutdown command to the VIA8235 controller it's necessary to perform some "magic" PCI configuration space access cycle. The necessary registers on Peg2 are: 0xF1000c78 - address, 0xF1000c7c - data. They are part of Marvell chip (base address is 0xF1000000).
    2) Such a cycle can't be caused by pci_write_config_long() because the address written doesn't represent a valid PCI device.
    3) Marvell's MMIO space exists under MorphOS however it's protected fron the applications by the MMU. pcix.library doesn't access them directly, it uses Quark calls.
    4) To call Quark you load function code into r0 register and produce an "sc" (system call) interrupt. The rest of processing is performed inside Quark on CPU supervisor level. Interrupt vectors table is placed at 0xFFF00000 and it's impossible to even read it. It is protected with MMU.
    That's all folks. Your hands are tied here.
    One more interesting fact: A window at 0xF1002000 is open for r/w access, a Gigabit ethernet controller is located there. Drivers writers are welcome. 8-)

    Related links:
    Linux kernel source code - gives a great overview of all Marvell northbridge registers. See MIPS-specific kernel part for the HW accessing code.
    U-Boot firmware source code - This opensource firmware is used on AmigaOne, however it supports Marvell reference boards too. This link leads to Marvell-specific code. Note that Articia code is also present in this tree, it can be interesting for Peg1 owners.

    [ Edited by Sonic on 2006/8/29 11:35 ]
    iPod, iBook, iMac,... iRobot?
  • »29.08.06 - 07:08
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    Robin
    Posts: 741 from 2003/2/24
    Hmmm ... this was told me years ago. (That it does not work with current MorphOS-Bootimage)

    Now imagine how much time you wasted :-P
  • »29.08.06 - 07:40
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 408 from 2004/7/15
    From: Russia, Moscow
    Quote:


    Now imagine how much time you wasted :-P


    2 evenings total.
    You know, i can't say they are totally wasted. That was great experience and my first steps in PPC asm :-)
    Probably one day i'll write some kind of article about Pegasos HW and MorphOS internals, for curious guys like me. 8-)
    iPod, iBook, iMac,... iRobot?
  • »29.08.06 - 07:46
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    MarK
    Posts: 641 from 2004/1/25
    From: Prague, The Cz...
    i also don't think the time was wasted... i like this investigation, and would be cool to get even more information of the pegasos2 itself... reminds me good old amiga hw, and it's special addresses... :-)

    bye and thanks, MarK.
  • »29.08.06 - 09:07
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    jcmarcos
    Posts: 1178 from 2003/3/13
    From: Pinto, Madrid ...
    Quote:

    Quote:

    Now imagine how much time you wasted :-P


    Not at all!

    Quote:

    Probably one day i'll write some kind of article about Pegasos HW and MorphOS internals, for curious guys like me. 8-)

    And I'm for sure one that will be very interested in that reading. MorphOS is about investigation. Hell, home computers used to be for learning, remember those old times hacking away our lottle Commodores?
    This use for computers as learning tools got lost when PC's came into scene, and computers became commodity items. This has lead to an ever growing percentage of computer users which don't really know how they work (leading to immense amounts of frustration, rejectness, and... wads of money coming in from support services).
    Computers are not for ignorants, no matter how much money big companies put in to convince the world otherwise.
  • »29.08.06 - 09:14
    Profile
  • Just looking around
    Stingray454
    Posts: 18 from 2006/8/23
    So, if anyone could explain to a n00b.. The protected MMU address space is defined where? If we now know the range of memory that need to be readable/writable from within MOS, can this be changed in MOS v1.5 or later versions? It would certainly be a nice feature to have :)
  • »29.08.06 - 12:30
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    Crumb
    Posts: 732 from 2003/2/24
    From: aGaS & CUAZ Al...
    The possibility of making Quark calls is also very interesting. It would allow you to protect/un-protect the areas you need, or maybe to remap memory areas... that would be very useful to port SheepShaver.
  • »29.08.06 - 12:38
    Profile Visit Website
  • MorphOS Developer
    CISC
    Posts: 619 from 2005/8/27
    From: the land with ...
    Quote:

    If we now know the range of memory that need to be readable/writable from within MOS, can this be changed in MOS v1.5 or later versions? It would certainly be a nice feature to have :)


    Uhhh, 1.5 had this feature from day 1...

    Besides, it was a complete waste of time by Sonic because someone else already hacked a software shutdown for 1.4 (which will probably corrupt your harddrive, destroy your pegasos (and your precious floppy drive too!) and eat your children (atleast the first example is quite likely), but who cares, you got shutdown! ;) ).


    - CISC
  • »29.08.06 - 12:39
    Profile
  • MorphOS Developer
    CISC
    Posts: 619 from 2005/8/27
    From: the land with ...
    Quote:

    The possibility of making Quark calls is also very interesting. It would allow you to protect/un-protect the areas you need, or maybe to remap memory areas... that would be very useful to port SheepShaver.


    The first one might be useful (but that won't happen until the API is ready for public consumption), the second is nonsense, unprotecting areas we set as protected will always be a no-go for obvious reasons, however some limited MMU access was always planned...


    - CISC
  • »29.08.06 - 12:44
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    Jupp3
    Posts: 1193 from 2003/2/24
    From: Helsinki, Finland
    Quote:

    Uhhh, 1.5 had this feature from day 1...

    So why doesn't MorphOS 1.4.5 has that feature? Afaik, it's newer than "day 1 MorphOS 1.5" :-D
  • »29.08.06 - 12:48
    Profile Visit Website
  • MorphOS Developer
    CISC
    Posts: 619 from 2005/8/27
    From: the land with ...
    Quote:

    So why doesn't MorphOS 1.4.5 has that feature? Afaik, it's newer than "day 1 MorphOS 1.5"


    Because Quark underwent a series of rather big changes during this period, which meant we could not easily transplant a newer Quark into the 1.4.x releases without potentially seriously breaking something, so we didn't...


    - CISC
  • »29.08.06 - 12:52
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 408 from 2004/7/15
    From: Russia, Moscow
    Quote:


    Crumb wrote:
    The possibility of making Quark calls is also very interesting. It would allow you to protect/un-protect the areas you need, or maybe to remap memory areas... that would be very useful to port SheepShaver.


    At least not current Quark version i guess (however, just guess, may be i'm wrong).
    You can see many interesting information on your serial port if you specify some qdebugflags on the kernel's command line. Unfortunately i don't remember their names but you can find them out yourself. To do this ungzip your kernel, load it into hex editor and search for "QDEBUGFLAGS" string. You'll fing a ReadArgs() template used to parse kernel command line then (yes, ReadArgs() is also part of Quark now :-)). It will be followed by 3 more templates. First of them is embedded template for qdebugflags (Quark), second - for edebugflags (exec.library) and third - for ddebugflags (dos.library). These arguments (except Quark) correspond to switches in "Debug" section of your MorphOS system prefs, however setting these flags at boottime allows you to get some init-time information which is hidden otherwise.
    The flag names are pretty self-explanatory.
    In short, amongst other things, this will tell you about how memory mapping is set up. You'll see that it's setup during startup and exec.library doesn't change it after that. It's really an "A-Box", an operating system inside another operaring system (Quark), this is the same situation as Linux-hosted AROS, you can't get into Linux's side from within AROS, it runs in a completely virtualized isolated environment.
    So i guess current Quark doesn't provide calls to do it just because noone needs it. Even if it does, we would have to disassemble Quark in order to understand them, but this is impossible (A-Box just doesn't see it, for it Quark's memory space doesn't exist, we just get hits when we try to get there).
    Modules inside the kernel are compressed (debug log tells about this), so disassembling a raw kernel binary doesn't discover the kernel implementation itself.
    PCI interrupts are not true interrupts, they are emulated. This means you're not a true supervisor inside them and you can't do more than you can usually do. I guess they are implemented as bottom halves.
    Also the kernel really doesn't use even OpenFirmware's RTAS, despite you can find its methods names in the kernel, i've checked it by replacing "system-reboot" string with "shutdown"; after this rebooting function inside MorphOS gave reboot as before, this means this RTAS method is not used, obviously other methods aren't used also. This means my previous suggestions were wrong and it's impossible to introduce "virtual firmware" layer which would intercept some calls from within the kernel.
    All we can learn about Quark are syscalls numbers which implement AmigaOS libraries functionality (like rebooting, PCI access, etc). However this won't have any practical application since these functions can be accomplished in a system-friendly manner using libraries. Moreover, noone guarantees that Quark API will not change in future MorphOS versions/revisions.
    Further reverse engineering would require a giant effort of modifying MOL to make it running MorphOS. After this we could have a complete virtual machine to look what's inside. :-) However, personally i have neither time nor enough motivation to do it. In addition i'm enough busy with other projects.
    iPod, iBook, iMac,... iRobot?
  • »29.08.06 - 13:13
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    Crumb
    Posts: 732 from 2003/2/24
    From: aGaS & CUAZ Al...
    Quote:


    CISC wrote:
    Quote:

    The possibility of making Quark calls is also very interesting. It would allow you to protect/un-protect the areas you need, or maybe to remap memory areas... that would be very useful to port SheepShaver.


    The first one might be useful (but that won't happen until the API is ready for public consumption), the second is nonsense, unprotecting areas we set as protected will always be a no-go for obvious reasons, however some limited MMU access was always planned...


    - CISC


    That would be great! :-) I guess that Itix could do a SheepShaver port in a week :-D
  • »29.08.06 - 13:30
    Profile Visit Website
  • MorphOS Developer
    zukow
    Posts: 645 from 2005/2/9
    From: Poland
    @Sonic

    wow :)
  • »29.08.06 - 14:37
    Profile Visit Website
  • Leo
  • Order of the Butterfly
    Order of the Butterfly
    Leo
    Posts: 419 from 2003/8/18
    @Sonic: that was an interesting post :) Keep sharing your experimentations :)

    @CISC:
    Quote:


    Because Quark underwent a series of rather big changes during this period, which meant we could not easily transplant a newer Quark into the 1.4.x releases without potentially seriously breaking something, so we didn't...


    And what would you be breaking if you released newer Quark+MOS 1.5 ? 8-)

    Leo.

    [ Edited by Leo on 2006/8/29 13:40 ]
    Nothing hurts a project more than developers not taking the time to let their community know what is going on.
  • »29.08.06 - 15:39
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    marcik
    Posts: 268 from 2003/4/12
    From: Kielce/Krakow,...
    Quote:

    And what would you be breaking if you released newer Quark+MOS 1.5 ?


    A secret deal with satan? :-P
  • »29.08.06 - 15:43
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    SoundSquare
    Posts: 1213 from 2004/12/1
    From: Paris, France
    Quote:

    Linux kernel source code - gives a great overview of all Marvell northbridge registers. See MIPS-specific kernel part for the HW accessing code.- This opensource firmware is used on AmigaOne, however it supports Marvell reference boards too. This link leads to Marvell-specific code. Note that Articia code is also present in this tree, it can be interesting for Peg1 owners.


    very interesting, does that mean that Peg1 boards could be turned to AOnes very easily ? and Pegasso2 as well ?
    That would definately break the market if u could get a cheap Peg1 board flashed with uboot and sold on ebay as AOnes for 1000$ :-p

    I still believe that Sonic would give a significant boost for MorphOs development if he could join the VIP MOS coders secret society. *sigh*
  • »29.08.06 - 15:50
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    jcmarcos
    Posts: 1178 from 2003/3/13
    From: Pinto, Madrid ...
    Quote:

    zukow wrote:
    @Sonic
    wow :)


    Really. Wow. That was some damn serious hacking. I guess it could win Sonic an award as core member of MorphOS... or completely otherwise, as his tactics are quite... erm... unorthodox?
    That's brave man! You seem to be a developer with a great degree of deep concentration!
  • »29.08.06 - 16:33
    Profile
  • MorphOS Developer
    Henes
    Posts: 507 from 2003/6/14
    Quote:


    And what would you be breaking if you released newer Quark+MOS 1.5 ? 8-)


    More or less everything :-)
  • »30.08.06 - 00:16
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Posts: 408 from 2004/7/15
    From: Russia, Moscow
    Quote:


    SoundSquare wrote:

    very interesting, does that mean that Peg1 boards could be turned to AOnes very easily ? and Pegasso2 as well ?


    Pegasos-1 - yes, exactly.
    There was some post in some AmigaOne-oriented forum (i've found it once but lost the link) about the experiment conducted by Genesi. They've flashed a slightly modified Pegasos-1 firmware into AmigaOne and it booted MorphOS.
    Technically it is possible. It is also technically possible to write a loadable u-boot implementation for Pegasos-1 which would boot up AmigaOS4. It's also possible to do a reverse thing - write an OpenFirmware implementation on top of u-boot and make AmigaOne booting up MorphOS.
    This is the same kind of task as my BootX port. Difficult but doable.
    AmigaOS4 people, however, say that they ship some hardware protection key with every copy of AmigaOS4. Well, probably loyal OS4 owners could tell more...
    All this is not true, however, for Pegasos-2. It has quite another northbridge that AmigaOS4 is unable to drive.

    [ Edited by Sonic on 2006/8/30 8:44 ]
    iPod, iBook, iMac,... iRobot?
  • »30.08.06 - 06:41
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2057 from 2003/6/4
    Quote:


    Sonic wrote:
    Quote:


    SoundSquare wrote:

    AmigaOS4 people, however, say that they ship some hardware protection key with every copy of AmigaOS4.




    And pigs can fly...
    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »30.08.06 - 11:01
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2057 from 2003/6/4
    Quote:


    marcik wrote:
    Quote:

    And what would you be breaking if you released newer Quark+MOS 1.5 ?


    A secret deal with satan? :-P


    I thought that was V1.666.
    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »30.08.06 - 11:02
    Profile Visit Website
  • Caterpillar
    Caterpillar
    Posts: 37 from 2006/8/23
    Actually, there is some extra stuff on the flash of the AmigaOne. I wanted to fix the CW keyboard support in UBoot, and if you flash an AmigaOne with just UBoot, OS4 doesn't boot any more (only linux). You have to flash it with UBoot, and the extra stuff that OS4 uses.
    Pegasos 1 April 2, MorphOS 1.4.5
    AmigaOne XE/G4, OS4 Beta
    Various classic machines
  • »30.08.06 - 11:06
    Profile Visit Website
  • MorphOS Developer
    CISC
    Posts: 619 from 2005/8/27
    From: the land with ...
    Quote:

    Actually, there is some extra stuff on the flash of the AmigaOne. I wanted to fix the CW keyboard support in UBoot, and if you flash an AmigaOne with just UBoot, OS4 doesn't boot any more (only linux). You have to flash it with UBoot, and the extra stuff that OS4 uses.


    Well, isn't UBoot GPL? In which case you (as an owner of an A1 and the UBoot that comes with it), must be able to receive the full sources of UBoot on request, including the bit that makes OS4 run...


    - CISC
  • »30.08.06 - 12:06
    Profile
  • Caterpillar
    Caterpillar
    Posts: 37 from 2006/8/23
    I don't think the OS4 stuff is part of UBoot, referenced by UBoot or required by UBoot. Its just stored on the same chip. Just like its possible to distribute GPL and non-GPL programs on the same CD.

    Even if a different license would be required (which I don't actually know, see above), how do we know Hyperion haven't got such a license? They have a good working relationship with the U-Boot team, AFAIK.

    If you _REALLY_ care, take it up with them.
    Pegasos 1 April 2, MorphOS 1.4.5
    AmigaOne XE/G4, OS4 Beta
    Various classic machines
  • »31.08.06 - 10:49
    Profile Visit Website