English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 15 December 2019, 22:29   #1
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
System takeover crashes in some cases

I have a source for a system takeover and restore here: https://github.com/skeetor/amiga-uti...stemTakeover.s


Now, when I compile and execute this with my gcc projects it appears to work. Started it several times and had no problem.

https://github.com/skeetor/amiga-uti...evelop/VAsmGCC


Strangely, when I use this in an ASM only project, I always get a Task Held requestor and a guru meditation.

https://github.com/skeetor/amiga-uti...velop/VAsmOnly


I debugged it in metascope and there it worked, and on the shell I also ran it and I had some times where it worked, but mostly it seems to crash, though I don't know why.


Nay ideas whats wrong with this?
sparhawk is offline  
Old 15 December 2019, 22:44   #2
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 722
@sparhawk
It is really not a good idea to store hardware registers when dma and/or ints are active. Because some int and/or copperlist can change them and you will stay with invalid values.

Personally I think that is really good thing to check how others handle with system takeover, for example how StingRay takeover system in his MiniStartup.
Asman is offline  
Old 15 December 2019, 22:48   #3
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
Actually I was taking this from some sample code, expecting that it works, but I will look at this startup you mentioned.
sparhawk is offline  
Old 17 December 2019, 01:00   #4
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,651
Quote:
Originally Posted by sparhawk View Post
I have a source for a system takeover and restore here: https://github.com/skeetor/amiga-uti...stemTakeover.s
Probably doesn‘t matter, but I would call Forbid() at the start of SystemSave, and I wouldn‘t restore INTREQ. A real takeover should also disable all DMA and interrupts, while you only load a NULL view.

Quote:
Now, when I compile and execute this with my gcc projects it appears to work. Started it several times and had no problem.
The startup code makes a difference? Although, it is hard for anybody to analyze your code when you don‘t show the exact command lines for compiler, assembler, linker.

For example: did you compile with register arguments enabled? ASMstrlen expects the pointer in a0, while the standard C-ABI for 68k is to pass all arguments on the stack.

Quote:
Strangely, when I use this in an ASM only project, I always get a Task Held requestor and a guru meditation.
What kind of Guru? Always the same? Running under Kickstart 1.x?
phx is offline  
Old 17 December 2019, 12:59   #5
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
Running on KS 1.3. And it was always Guru 4. Anyway, I will look at the ministartup and work from there.
The compilation is done via the CMake project, from that repository. Using bebbos gcc compiler suite as a base with MSYS2. But the guru only happens in the ASM project only, so there is no additional startup code involved.

https://github.com/skeetor/amiga-uti...AsmOnly/main.s

Actually I was a bit surprised about this code anyway, as I would expect to use Forbid()/Disable() pretty early. But I'm not sure what system functions can still be called after that.
sparhawk is offline  
Old 18 December 2019, 17:02   #6
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,651
Quote:
Originally Posted by sparhawk View Post
and on the shell I also ran it and I had some times where it worked
Which means, you are running it from WB? I saw no WB startup code in your assembler-only version. But then I still see no reason for a crash when started from shell...

I would even try to build your VasmOnly-test myself, but as mentioned before there is too much information missing or hidden. How do you call vasm or the linker? Which options? Any libraries you are linking with?

Does it also crash if you comment the calls to SystemSave/SystemRestore out?

EDIT: Managed to assemble and link all your sources (main.s, strlen.s, SystemTakeover.s). The resulting executable is attached (516 Bytes). Tested on an emulated A500 with WB 1.3 in the shell. No problems.
Code:
vasmm68k_mot -Fhunk -o main.o main.s
vasmm68k_mot -Fhunk -o strlen.o strlen.s
vasmm68k_mot -Fhunk -o SystemTakeover.o SystemTakeover.s
vlink -bamigahunk -o VasmOnly.68k -s -x main.o strlen.o SystemTakeover.o
Attached Files
File Type: 68k VasmOnly.68k (516 Bytes, 12 views)

Last edited by phx; 18 December 2019 at 18:33.
phx is offline  
Old 18 December 2019, 19:34   #7
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
I'm now converting the ministartup. I was not running it from WB, only from shell, and sometimes it worked, but I don't really know why.
sparhawk is offline  
Old 18 December 2019, 22:08   #8
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 722
Quote:
Originally Posted by sparhawk View Post
I'm now converting the ministartup. I was not running it from WB, only from shell, and sometimes it worked, but I don't really know why.
Converting ??? If I were you I would first check ministartup with some basic stuff like some bars on black screen. Just to be sure how it works.

Perhaps you did some mistake(s). Its hard to guess without source. Please post the source.
Asman is offline  
Old 18 December 2019, 22:38   #9
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
I have to convert it, because it doesn't assemble with vasm. Or maybe it needs some special options?

The current version can be found here, but it's not finished yet.
https://github.com/skeetor/amiga-uti...AmigaUtils/src
sparhawk is offline  
Old 19 December 2019, 00:02   #10
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
I converted this now, and it works now! Thanks for the help!

I still want to do some minor cosmetic changes, but at least I can now start to experiment with the stuff I wanted to. So next I want to get some Copper stuff working. The bars, Asman was mentioning, wil be next.
sparhawk is offline  
Old 19 December 2019, 09:44   #11
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 722
Quote:
Originally Posted by sparhawk View Post
I converted this now, and it works now! Thanks for the help!

I still want to do some minor cosmetic changes, but at least I can now start to experiment with the stuff I wanted to. So next I want to get some Copper stuff working. The bars, Asman was mentioning, wil be next.
Great. you can also use RS directive to deal with variables. You can check for example my old source in github link
It is just black interleaved screen.
Asman is offline  
Old 19 December 2019, 21:44   #12
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
I tested the startup code and it worked in the example where I use only assembler. I have another example project, where I use gcc interfacing with assembler, and strangely it did not work there, instead it just got stuck. So I debugged it and found the reason why this was the case.

In the original code, I had this:
Code:
	move.w	#$7FFF,d0
	bsr	WaitRaster
In the assembler only example it seems that the bsr was near enough to jump to the proper address. In the gcc example, it seems that the symbols where so far apart, that the bsr pointed to some weird address. Now I'm not sure if this is a problem with gcc, or something else, but I would have expected that I get some error if a symbol is not reachable with this instruction. After changing it to:
Code:
	move.w	#$7FFF,d0
	jsr	WaitRaster
it worked, of course.

So any idea, why I didn't even get a warning or an error in that case? I'm not even sure where the problem may be.

The assembler doesn't know the address of the symbol at compile time, so it probably can not warn me. Since this is in an library, it will not know it, until it is actually linked. So I would expect that I get an error at link time at latest, right?
sparhawk is offline  
Old 19 December 2019, 23:51   #13
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,651
Quote:
Originally Posted by sparhawk View Post
The assembler doesn't know the address of the symbol at compile time, so it probably can not warn me. Since this is in an library, it will not know it, until it is actually linked. So I would expect that I get an error at link time at latest, right?
Correct. The linker should tell you something like "16-bit pc-relative reference at sectioname+offset for symbol xyz out of range!".

Which linker is it and which command line options does it get?
phx is offline  
Old 20 December 2019, 07:37   #14
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
Code:
 m68k-amigaos-g++  --save-temps -Wall -pedantic -mcrt=nix13 -O3 -mregparm -O3 -DNDEBUG CMakeFiles/VASMGcc.dir/main.cpp.o CMakeFiles/VASMGcc.dir/strlen.cpp.o CMakeFiles/VASMGcc.dir/strlen.asm.o  -o bin/VASMGcc.exe -Wl,--out-implib,bin/libVASMGcc.dll.a /opt/amiga/utils/lib/libAmigaUtils.a /opt/amiga/utils/lib/libAmigaGCCUtils.a
Maybe I should post an issue on bebbo's git repository, as this appears to be a cmopiler/linker problem.

Last edited by sparhawk; 20 December 2019 at 07:43.
sparhawk is offline  
Old 20 December 2019, 13:04   #15
bebbo
botcher

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 457
Quote:
Originally Posted by phx View Post
Correct. The linker should tell you something like "16-bit pc-relative reference at sectioname+offset for symbol xyz out of range!".

Which linker is it and which command line options does it get?

Well, m68k-amigaos-ld inserts long jump tables and adjusts the word/short jumps to the next jump table (do you remember?)


Maybe there's an error...
bebbo is offline  
Old 20 December 2019, 13:30   #16
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,651
Quote:
Originally Posted by bebbo View Post
Well, m68k-amigaos-ld inserts long jump tables and adjusts the word/short jumps to the next jump table (do you remember?)
Ah, yes! Also called ALV (Automatic Link Vector) in BLink and PhxLnk. I always wanted to support that in vlink.

Quote:
Maybe there's an error...
Most likely the vector doesn't point to the right place.
Is there an option? ALVs shouldn't be enabled by default, IMHO.
phx is offline  
Old 20 December 2019, 19:01   #17
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
I have fixed the issues when building with CMake under Linux, so this should work now. I built the executables under Linux as well, and tested them, and the same problem persists.
I also created a screenshot to illustrate it better, but I hope that you can now also build it, following the instructions on the repo.

The left side shows that the "bsr" points to "somewhere" while the right side "jsr" correctly points to "_WaitRaster".
Attached Thumbnails
Click image for larger version

Name:	BSR_Bug-vs-JSR.jpg
Views:	32
Size:	211.7 KB
ID:	65609  
sparhawk is offline  
Old 20 December 2019, 22:10   #18
bebbo
botcher

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 457
Ok, I tracked it down

Consider this example code:

Code:
_X:
        nop
        nop
        bsr foo
        rts
The output of vasm with -Fhunk differs from the as output.

vasm:
Code:
   0:   4e71            nop
   2:   4e71            nop
   4:   6100 0000       bsr.w 0x6
   8:   4e75            rts
m68k-amigaos-as:
Code:
   0:   4e71            nop
   2:   4e71            nop
   4:   6100 fffa       bsr.w 0x0
   8:   4e75            rts
and the binutils linker expects the latter version to link with correct offsets.

You may call this a bug or feature - but vasm and as aren't compatible if a bsr is used to an extern symbol.
bebbo is offline  
Old 20 December 2019, 22:19   #19
sparhawk
Registered User

sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 51
Posts: 321
Can I easily convert the code to AS? As far as I understood it, AS is not really designed to be used for "human" assembly programming, as it is mostly designed to be used by gcc right? That's actually the reason why I was using vasm instead, assuming that it is a good choice for Amiga programming and compatible with gcc.

Since I'm still at the start, I could switch to AS if it is worth it, so I wonder if that should be the way to go.
Such a bug is a bit frightening, if it compiles without warning whatsoever.

Still, thanks for your analysis. And also for the feedback on my cmake build as I now have at least some feedback from some external source. "Works on my machine" never guarantees that the next guy can also use it.
sparhawk is offline  
Old 21 December 2019, 00:03   #20
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,651
Quote:
Originally Posted by bebbo View Post
You may call this a bug or feature - but vasm and as aren't compatible if a bsr is used to an extern symbol.
When as outputs a hunk-format object file, then it is a bug in as. And when ld expects pc-relative relocs in such a form (in hunk objects) then it is also a bug in ld.

To calculate the addend of pc-relative relocs relative to the section-base is only done in a.out format. This is not how hunk-format works. Probably some old a.out code is lurking somewhere...
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
System takeover and multi floppy mess ross Coders. General 8 15 September 2018 20:01
Converting a "system-takeover" game to OS friendly alpine9000 Coders. General 13 01 January 2018 01:06
System takeover/shutdown alpine9000 Coders. Asm / Hardware 5 07 June 2016 09:03
trackdisk.device after system takeover alpine9000 Coders. Asm / Hardware 20 21 March 2016 09:17
startup/system takeover sidewinder Coders. General 15 28 February 2016 16:33

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:02.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.09804 seconds with 16 queries