English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 02 February 2019, 15:11   #1061
Auscoder
Registered User
 
Join Date: Jan 2019
Location: Brisbane
Posts: 99
Quote:
Originally Posted by alkis View Post
On how to inline you might want to take a look at https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
The syntax is not intuitive. It would be better to have a separate assembly file where your assembler code would be.
Assembly dump with compiler flags -S
Oh! yes that is pretty horrible syntax. I'll go with the separate assembly. Though no idea how to do this even. Any chance you could point me to an example of how to create and call the separate assembly?

Quote:
Originally Posted by alkis View Post
You can use '-pg' on compiling/linking with gcc. Run the program normally. It will produce a file gmon.out. Then run m68k-amigaos-gprof executable_name gmon.out
Thanks Alkis! Seems I don't have m68k-amigaos-gprof or the required libs in my pre-packaged toolchain. So am checking out bebbo's and building from scratch.. It's taking forever and a day in Cygwin/Windows. If these are not in the toolchain could you tell me where they are?
Auscoder is offline  
Old 02 February 2019, 16:08   #1062
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 721
Quote:
Originally Posted by Auscoder View Post
Oh! yes that is pretty horrible syntax. I'll go with the separate assembly. Though no idea how to do this even. Any chance you could point me to an example of how to create and call the separate assembly?
Quick example attached.

Quote:
Originally Posted by Auscoder View Post
Thanks Alkis! Seems I don't have m68k-amigaos-gprof or the required libs in my pre-packaged toolchain. So am checking out bebbo's and building from scratch.. It's taking forever and a day in Cygwin/Windows. If these are not in the toolchain could you tell me where they are?
You are welcome
gprof is in the toolchain.
Attached Files
File Type: zip exasm.zip (939 Bytes, 129 views)
alkis is offline  
Old 03 February 2019, 10:57   #1063
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by Auscoder View Post
...
So am checking out bebbo's and building from scratch.. It's taking forever and a day in Cygwin/Windows.
You may also use http://franke.ms/download/setup-amiga-gcc.exe.
bebbo is offline  
Old 03 February 2019, 14:51   #1064
Auscoder
Registered User
 
Join Date: Jan 2019
Location: Brisbane
Posts: 99
Hi Alkis, that's awesome, all working now. Now if I could figure out how to build the assembly with - not - C linkage I would be set to go. Your help was awesome.
Auscoder is offline  
Old 03 February 2019, 14:57   #1065
Auscoder
Registered User
 
Join Date: Jan 2019
Location: Brisbane
Posts: 99
Quote:
Originally Posted by bebbo View Post
Thanks bebbo, I did compile the toolchain - It finished while I slept - This makes it much easier though. Much appreciated, and also great work on this, thanks for it all
Auscoder is offline  
Old 03 February 2019, 16:03   #1066
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 721
Quote:
Originally Posted by Auscoder View Post
Hi Alkis, that's awesome, all working now. Now if I could figure out how to build the assembly with - not - C linkage I would be set to go. Your help was awesome.
Can you please explain what you are trying to do?
alkis is offline  
Old 03 February 2019, 16:24   #1067
Auscoder
Registered User
 
Join Date: Jan 2019
Location: Brisbane
Posts: 99
Quote:
Originally Posted by bebbo View Post
Hi bebbo, so I went ahead and grabbed this version you linked earlier, tested compiled and build all went well for build, then when launching the application in WinUAE 4.1.0 (2018.12.05) 64bit the title crashes on launch with #80000008 - So I went back to the setup-amiga-gcc-6.4.1b.exe toolchain I was using earlier, recompiled + tested and the application launches fine with no crashes.

Snoopdos shows the system loads mathieeedoubletrans and then opens my application. First line of application is cout << and its at least not getting to the point where it can flush that first to shell. visually launch and crash. I am not set up with a debugger at this point so I cant step..

More testing before post....

I was using -O3 and -m68040 tried removing these but still no joy.

I went ahead and tested same executable on real hardware (060) and get a terminate like this

"terminate called after throwing an instance of 'std::_iosfailure' what(): basic_ios::clear
Program aborted

Looks like iostream errors, so I narrowed main() down to the below and still have same terminate on real hardware

Code:
int main (int argc, char *argv[])
{
//  cout << "1 :" << myfunction(1) << endl;
//  cout << "2 :" << myfunction(2) << endl;

  cout << "Launching..." << endl;

// gameMain();

  cout << "Exited. Press ENTER to continue..." << endl;
  cin.get();

  return 0;
}
Removing the iostream call, application launches and exits without a crash. WinUAE handles this quite badly with a guru like noted above. It's not causing a guru on my A1200.

I'm OK to stick with older version, or not even use iostream tbh... But for your info the above seems active on the package you linked.
Auscoder is offline  
Old 03 February 2019, 16:27   #1068
Auscoder
Registered User
 
Join Date: Jan 2019
Location: Brisbane
Posts: 99
Quote:
Originally Posted by alkis View Post
Can you please explain what you are trying to do?
I am using C++ so default C++ linkage everywhere, the asm is compiled with "C" linkage, so I need to forward declare with extern "C" int function(); rather than just int function(); The last as default is C++ linkage right.

Not a big deal really I can work around it with some macros in the headers.
Auscoder is offline  
Old 03 February 2019, 19:20   #1069
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,553
Attach binary, thanks. (But it sounds like different config/WB/or too small stack, the usual)
Toni Wilen is offline  
Old 04 February 2019, 01:41   #1070
Auscoder
Registered User
 
Join Date: Jan 2019
Location: Brisbane
Posts: 99
Quote:
Originally Posted by Toni Wilen View Post
Attach binary, thanks. (But it sounds like different config/WB/or too small stack, the usual)
Hi Toni, attached super simple hello world with cpp, binary and uae config that shows the problem

This ver built using the latest toolchain that bebbo linked me here http://franke.ms/download/setup-amiga-gcc.exe.

Using to compile-

Code:
m68k-amigaos-c++ hello.cpp -o hello.exe -Os -noixemul
This same build does not have crash issues with the older toolchain I used "setup-amiga-gcc-6.4.1b.exe" the link for this one expired.

I checked it booting from WB3.1 FDD as well as my HDD image. Remember this application is also terminated without executing fully on real Amiga as well. Just different termination behaviour. Guru vs terminate.
Attached Files
File Type: zip iostreamcrash.zip (352.5 KB, 122 views)
Auscoder is offline  
Old 04 February 2019, 08:02   #1071
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by Toni Wilen View Post
Attach binary, thanks. (But it sounds like different config/WB/or too small stack, the usual)

it's rather my broken toolchain, the usual...
... the merge with 6.5.0 created this issue: no code for CTORS* is created => no CTOR is invoked. => cout is uninitialized => boom

EDIT: * no code to register CTOR/DTOR for startup/exit

Last edited by bebbo; 04 February 2019 at 08:15.
bebbo is offline  
Old 04 February 2019, 08:14   #1072
pipper
Registered User
 
Join Date: Jul 2017
Location: San Jose
Posts: 676
I can confirm that the simple example is crashing. I don't think its a problem with WinUAE, most likely with the gcc toolchain and its C++ standard library.
pipper is offline  
Old 04 February 2019, 09:13   #1073
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
I just pushed the fix. new setup-amiga-gcc.exe is available...

EDIT: now :-)

Last edited by bebbo; 04 February 2019 at 11:34.
bebbo is offline  
Old 04 February 2019, 14:13   #1074
Auscoder
Registered User
 
Join Date: Jan 2019
Location: Brisbane
Posts: 99
Hey bebbo, awesome!

Do we always grab the latest from the same link - http://franke.ms/download/setup-amiga-gcc.exe ?

Grabbed from that link, confirmed working great! Cheers!

Last edited by Auscoder; 04 February 2019 at 14:34.
Auscoder is offline  
Old 04 February 2019, 14:30   #1075
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by Auscoder View Post
Hey bebbo, awesome!

Do we always grab the latest from the same link - https://franke.ms/download/setup-amiga-gcc.exe ?
yup
bebbo is offline  
Old 04 February 2019, 16:18   #1076
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,553
Quote:
Originally Posted by Auscoder View Post
Hi Toni, attached super simple hello world with cpp, binary and uae config that shows the problem
It reads from non-existing RAM which can return "random" data that can also depend on used hardware. UAE returned zero and code used returned value as destination pointer for some copy or clear operation. Result was execbase and interrupt vector overwrite..
Toni Wilen is offline  
Old 18 February 2019, 14:59   #1077
thyslo
Registered User
 
Join Date: Apr 2018
Location: Germany
Posts: 193
Hi,

I have a question regarding the scope when using this toolchain.

I have a class which is kind of a wrapper around some dos.library functions. Here is the Open() method as an example:

Code:
#include <proto/dos.h>

...

bool AmigaFile::Open(const SimpleString& p_FileName,
                     int p_amigaDosAccessMode)
{
  // Opening the file
  m_pFile = ::Open(p_FileName.C_str(), p_amigaDosAccessMode);
  if(m_pFile == NULL)
  {
    // Opening failed
    return false;
  }

  return true;
}

This compiles without errors in StormC4 / gcc mode.

But with the toolchain there is a naming conflict. I just come around it by renaming the method e.g. to OpenF() and by calling simply Open() instead of ::Open().

But especially the method renaming seems no good solution.

Is there a better way?
thyslo is offline  
Old 18 February 2019, 15:32   #1078
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by thyslo View Post
Hi,

I have a question regarding the scope when using this toolchain.

I have a class which is kind of a wrapper around some dos.library functions. Here is the Open() method as an example:

Code:
#include <proto/dos.h>

...

bool AmigaFile::Open(const SimpleString& p_FileName,
                     int p_amigaDosAccessMode)
{
  // Opening the file
  m_pFile = ::Open(p_FileName.C_str(), p_amigaDosAccessMode);
  if(m_pFile == NULL)
  {
    // Opening failed
    return false;
  }

  return true;
}
This compiles without errors in StormC4 / gcc mode.

But with the toolchain there is a naming conflict. I just come around it by renaming the method e.g. to OpenF() and by calling simply Open() instead of ::Open().

But especially the method renaming seems no good solution.

Is there a better way?
By default '#include <proto/dos.h>' includes macros, so 'Open' is a macro not a function. Same thing for all AmigaOs function included via 'proto/...'

If you'd use 'clib/dos_protos.h' protos instead, you get real functions - provided by libamiga - but you'll use stubs to call the libraries.

EDIT: you might use lowercase for your functions as for verbs in real world languages...
bebbo is offline  
Old 18 February 2019, 18:37   #1079
thyslo
Registered User
 
Join Date: Apr 2018
Location: Germany
Posts: 193
Thank you, bebbo!

So I'll try using #include <clib/dos_protos.h>


Quote:
Originally Posted by bebbo View Post
you might use lowercase for your functions as for verbs in real world languages...
I usually write the public methods uppercase to distinguish them from private and protected methods. But I really might rethink this for future projects as today it admittedly seems a bit archaic:-)
thyslo is offline  
Old 19 February 2019, 16:53   #1080
thyslo
Registered User
 
Join Date: Apr 2018
Location: Germany
Posts: 193
Makefile creation

If this is off topic, please ignore this post.

I've now changed my example to compile without problems using the command line

Code:
/opt/amiga/bin/m68k-amigaos-g++ AmigaFile.cpp SimpleString.cpp main.cpp
As said, it is compiling with no problems.

The I wanted to create a simple makefile:

Code:
CC=/opt/amiga/bin/m68k-amigaos-c++
CPPFLAGS=-I. -I/opt/amiga/m68k-amigaos/ndk-include/

Application: AmigaFile.o SimpleString.o main.o
	$(CC) -o Application AmigaFile.o SimpleString.o main.o -I.
Sadly if I now run 'make' there are some errors:

Code:
In file included from /usr/include/x86_64-linux-gnu/sys/select.h:47:0,
                 from /usr/include/x86_64-linux-gnu/sys/types.h:219,
                 from /usr/include/stdlib.h:275,
                 from /usr/include/c++/6/cstdlib:75,
                 from /usr/include/c++/6/stdlib.h:36,
                 from Array.h:4,
                 from AmigaFile.h:6,
                 from AmigaFile.cpp:3:
/usr/include/x86_64-linux-gnu/bits/time.h:30:8: error: redefinition of ‘struct timeval’
 struct timeval
        ^~~~~~~
In file included from /opt/amiga/m68k-amigaos/ndk-include/dos/dosextens.h:26:0,
                 from /opt/amiga/m68k-amigaos/ndk-include/clib/dos_protos.h:21,
                 from AmigaFile.cpp:1:
/opt/amiga/m68k-amigaos/ndk-include/devices/timer.h:30:8: error: previous definition of ‘struct timeval’
 struct timeval {
Is there some obvious error in the makefile?
thyslo 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
New GCC based dev toolchain for AmigaOS 3.x cla Coders. Releases 8 24 December 2017 10:18
Issue with photon/xxxx WinUAE Toolchain arpz Coders. Asm / Hardware 2 26 September 2015 22:33
New 68k gcc toolchain arti Coders. C/C++ 17 31 July 2015 03:59
Hannibal's WinUAE Demo Toolchain 5 Bobic Amiga scene 1 23 July 2015 21:04
From gcc to vbcc. Cowcat Coders. General 9 06 June 2014 14:45

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 06:41.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.16328 seconds with 14 queries