Author Topic: A Replacement Method for Data Statements  (Read 2437 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: A Replacement Method for Data Statements
« Reply #15 on: March 09, 2022, 06:17:01 pm »
did you edit the file common.h and add #define QB64_NOT_X86 ?  It's usually the one big change required for ARM processors to work properly.

Add the define.
Purge all libraries with the batch file for your OS.
Rebuild QB64 with the change at the top of common.h.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • Resume
Re: A Replacement Method for Data Statements
« Reply #16 on: March 21, 2022, 04:11:07 pm »
@MrGW454 @bplus

I haven't been around in a while as I have been researching a possible project in crypto.

Anyway, I have solved the issue on ARM involving DATA statements - I am going to assume I am looking at posts before MrGW454 contacted me, as from our discussion on Discord, it works.

@bplus - if you want the fix for this, I will be happy to give it to you. I actually ran into a number of issues that I guess others gave up on, until I ran into an issue involving misaligned addresses on the PI's ARM that was fixed in the x86 chip (hardware fix) that may have been done in the Apple M1 ARM processor, which until July I will not have one to test my changes with.

Also an issue is that QB64 does not work on a PI running a 64bit OS. I am looking into that, but I suspect from all the technical documents I've read (and contacts with some in the IEEE) that the PI ARM may not be a fully compliant chip, where I was told the M1 should be,
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: A Replacement Method for Data Statements
« Reply #17 on: March 21, 2022, 04:57:35 pm »
Quote
@bplus - if you want the fix for this,

Nah, just trying to help with a work around, thanks.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • Resume
Re: A Replacement Method for Data Statements
« Reply #18 on: March 21, 2022, 05:25:02 pm »
That is part of the changes, but does not fix everything, including the DATA statement issue.

Here are the changes needed to run QB64 on a Raspberry PI. Sig Bus errors are the product of a hardware fix that was made on the x86 chips, and not carried over on the ARM chip on the PI:

For common.h:
Code: [Select]
//Modification for Raspbian OS: doppler/George McGinn.
#ifdef __arm__
#define QB64_NOT_X86
#define POST_PACKED_STRUCTURE
#else
#define POST_PACKED_STRUCTURE __attribute__((__packed__))
#endif /* ARM */

For the makedat_ln32.txt file:
Code: [Select]
objcopy -Ibinary -Oelf32-littlearm -Barm
1. Add the code for common.h at the top of that source file.
2. Replace the makedat_ln32.txt file in its entirety with the above line.
3. Rerun the setup_lnx.sh script to recompile the qb64 binary.

In common.h, the statement `   #define POST_PACKED_STRUCTURE` is needed for most of the misaligned address errors (some that the x86 hardware fix will not work with this) and the `makedat` file corrects the DATA statement issue, ASAN (AddressSanitizer) errors, malformed binary executable issues. (The POST_PACKED also is part of that issue as far as I can tell).

I also have a script that will do steps two and three (I haven't got around yet to changing it to add the code to common.h yet). I have run this script on a clean copy of Raspbian OS 32bit version, and it now installs all the prerequisites and properly creates the files. QB64 does not work on the Raspbian 64bit version of the OS.

Before you run this script, you will need to add the lines above to common.h before running the setup_lnx.sh script.

Here is my update setup_lnx.sh script:
Code: Bash: [Select]
  1. #!/bin/bash
  2. #QB64 Installer -- Shell Script -- Matt Kilgore 2013
  3. #Version 5 -- January 2020
  4.  
  5. #This version includes the updates to sucessfully install QB64 on the PI
  6. #or any ARM processor (Current version only tested on the Raspberry PI and
  7. #sets the DISTRO to "raspbian".) -- George McGinn (2/1/2022)
  8.  
  9. #This checks the currently installed packages for the one's QB64 needs
  10. #And runs the package manager to install them if that is the case
  11. pkg_install() {
  12.   #Search
  13.   packages_to_install=
  14.   for pkg in $pkg_list; do
  15.     if [ -z "$(echo "$installed_packages" | grep $pkg)" ]; then
  16.       packages_to_install="$packages_to_install $pkg"
  17.     fi
  18.   done
  19.   if [ -n "$packages_to_install" ]; then
  20.     echo "Installing required packages. If prompted to, please enter your password."
  21.     $installer_command $packages_to_install
  22.   fi
  23.  
  24. }
  25.  
  26. #Make sure we're not running as root
  27. if [ $EUID == "0" ]; then
  28.   echo "You are trying to run this script as root. This is highly unrecommended."
  29.   echo "This script will prompt you for your sudo password if needed to install packages."
  30.   exit 1
  31. fi
  32.  
  33. GET_WGET=
  34. #Path to Icon
  35. #Relative Path to icon -- Don't include beginning or trailing '/'
  36. QB64_ICON_PATH="internal/source"
  37.  
  38. #Name of the Icon picture
  39. QB64_ICON_NAME="qb64icon32.png"
  40.  
  41. DISTRO=
  42.  
  43. lsb_command=`which lsb_release 2> /dev/null`
  44. if [ -z "$lsb_command" ]; then
  45.   lsb_command=`which lsb_release 2> /dev/null`
  46. fi
  47.  
  48. #Outputs from lsb_command:
  49.  
  50. #Arch Linux  = arch
  51. #Debian      = debian
  52. #Fedora      = Fedora
  53. #KUbuntu     = ubuntu
  54. #LUbuntu     = ubuntu
  55. #Linux Mint  = linuxmint
  56. #Ubuntu      = ubuntu
  57. #Raspbian    = raspbian
  58. #Slackware   = slackware
  59. #VoidLinux   = voidlinux
  60. #XUbuntu     = ubuntu
  61. #Zorin       = Zorin
  62. if [ -n "$lsb_command" ]; then
  63.   DISTRO=`$lsb_command -si | tr '[:upper:]' '[:lower:]'`
  64. elif [ -e /etc/arch-release ]; then
  65.   DISTRO=arch
  66. elif [ -e /etc/debian_version ] || [ -e /etc/debian_release ]; then
  67.   DISTRO=debian
  68. elif [ -e /etc/fedora-release ]; then
  69.   DISTRO=fedora
  70. elif [ -e /etc/redhat-release ]; then
  71.   DISTRO=redhat
  72. elif [ -e /etc/centos-release ]; then
  73.   DISTRO=centos
  74. elif $(arch | grep arm > /dev/null); then
  75.   DISTRO=raspbian
  76. fi
  77.  
  78. echo "DISTRO detected = $DISTRO"
  79.  
  80. #Find and install packages
  81. if [ "$DISTRO" == "arch" ]; then
  82.   echo "ArchLinux detected."
  83.   pkg_list="gcc zlib xorg-xmessage $GET_WGET"
  84.   installed_packages=`pacman -Q`
  85.   installer_command="sudo pacman -S "
  86.   pkg_install
  87. elif [ "$DISTRO" == "linuxmint" ] || [ "$DISTRO" == "ubuntu" ] || [ "$DISTRO" == "debian" ] || [ "$DISTRO" == "zorin" ] || [ "$DISTRO" == "raspbian" ]; then
  88.   echo "Debian/Raspian based distro detected."
  89.   pkg_list="g++ x11-utils mesa-common-dev libglu1-mesa-dev libasound2-dev zlib1g-dev $GET_WGET"
  90.   installed_packages=`dpkg -l`
  91.   installer_command="sudo apt-get -y install "
  92.   pkg_install
  93. elif [ "$DISTRO" == "fedora" ] || [ "$DISTRO" == "redhat" ] || [ "$DISTRO" == "centos" ]; then
  94.   echo "Fedora/Redhat based distro detected."
  95.   pkg_list="gcc-c++ xmessage mesa-libGLU-devel alsa-lib-devel zlib-devel $GET_WGET"
  96.   installed_packages=`yum list installed`
  97.   installer_command="sudo yum install "
  98.   pkg_install
  99. elif [ "$DISTRO" == "voidlinux" ]; then
  100.    echo "VoidLinux detected."
  101.    pkg_list="gcc xmessage glu-devel zlib-devel alsa-lib-devel $GET_WGET"
  102.    installed_packages=`xbps-query -l |grep -v libgcc`
  103.    installer_command="sudo xbps-install -Sy "
  104.    pkg_install
  105. elif [ -z "$DISTRO" ]; then
  106.   echo "Unable to detect distro, skipping package installation"
  107.   echo "Please be aware that for QB64 to compile, you will need the following installed:"
  108.   echo "  OpenGL developement libraries"
  109.   echo "  ALSA development libraries"
  110.   echo "  GNU C++ Compiler (g++)"
  111.   echo "  xmessage (x11-utils)"
  112.   echo "  zlib"
  113. fi
  114.  
  115. echo "Compiling and installing QB64..."
  116.  
  117. ### Build process
  118. find . -name "*.sh" -exec chmod +x {} \;
  119. find internal/c/parts -type f -iname "*.a" -exec rm -f {} \;
  120. find internal/c/parts -type f -iname "*.o" -exec rm -f {} \;
  121. find internal/c/libqb -type f -iname "*.o" -exec rm -f {} \;
  122. rm ./internal/temp/*
  123.  
  124. #if [ "$DISTRO" == "raspbian" ]; then
  125. if $(arch | grep arm > /dev/null); then
  126.   echo "Updating files for the ARM processor..."
  127.   echo "updating makedat_lnx32.txt file..."
  128.   pushd internal/c >/dev/null
  129.   cat > makedat_lnx32.txt <<EOF
  130. objcopy -Ibinary -Oelf32-littlearm -Barm
  131. EOF
  132.   echo "updating makedat_lnx64.txt file..."
  133.   cat > makedat_lnx64.txt <<EOF
  134. objcopy -Ibinary -Oelf64-littlearm -Barm
  135. EOF
  136.   popd >/dev/null
  137. fi
  138.  
  139. echo "Building library 'LibQB'"
  140. pushd internal/c/libqb/os/lnx >/dev/null
  141. rm -f libqb_setup.o
  142. ./setup_build.sh
  143. popd >/dev/null
  144.  
  145. echo "Building library 'FreeType'"
  146. pushd internal/c/parts/video/font/ttf/os/lnx >/dev/null
  147. rm -f src.o
  148. ./setup_build.sh
  149. popd >/dev/null
  150.  
  151. echo "Building library 'Core:FreeGLUT'"
  152. pushd internal/c/parts/core/os/lnx >/dev/null
  153. rm -f src.a
  154. ./setup_build.sh
  155. popd >/dev/null
  156.  
  157. echo "Building 'QB64'"
  158. cp -r ./internal/source/* ./internal/temp/
  159. pushd internal/c >/dev/null
  160. g++ -no-pie -w qbx.cpp libqb/os/lnx/libqb_setup.o parts/video/font/ttf/os/lnx/src.o parts/core/os/lnx/src.a -lGL -lGLU -lX11 -lpthread -ldl -lrt -D FREEGLUT_STATIC -o ../../qb64
  161. popd
  162.  
  163. if [ -e "./qb64" ]; then
  164.   echo "Done compiling!!"
  165.  
  166.   echo "Creating ./run_qb64.sh script..."
  167.   _pwd=`pwd`
  168.   echo "#!/bin/sh" > ./run_qb64.sh
  169.   echo "cd $_pwd" >> ./run_qb64.sh
  170.   echo "./qb64 &" >> ./run_qb64.sh
  171.  
  172.   chmod +x ./run_qb64.sh
  173.   #chmod -R 777 ./
  174.   echo "Adding QB64 menu entry..."
  175.   cat > ~/.local/share/applications/qb64.desktop <<EOF
  176. [Desktop Entry]
  177. Name=QB64 Programming IDE
  178. GenericName=QB64 Programming IDE
  179. Exec=$_pwd/run_qb64.sh
  180. Icon=$_pwd/$QB64_ICON_PATH/$QB64_ICON_NAME
  181. Terminal=false
  182. Type=Application
  183. Categories=Development;IDE;
  184. Path=$_pwd
  185. StartupNotify=false
  186. EOF
  187.  
  188.   echo "Running QB64..."
  189.   ./qb64 &
  190.   echo "QB64 is located in this folder:"
  191.   echo "`pwd`"
  192.   echo "There is a ./run_qb64.sh script in this folder that should let you run qb64 if using the executable directly isn't working."
  193.   echo
  194.   echo "You should also find a QB64 option in the Programming/Development section of your menu you can use."
  195. else
  196.   ### QB64 didn't compile
  197.   echo "It appears that the qb64 executable file was not created, this is usually an indication of a compile failure (You probably saw lots of error messages pop up on the screen)"
  198.   echo "Usually these are due to missing packages needed for compilation. If you're not running a distro supported by this compiler, please note you will need to install the packages listed above."
  199.   echo "If you need help, please feel free to post on the QB64 Forums detailing what happened and what distro you are using."
  200.   echo "Also, please tell them the exact contents of this next line:"
  201.   echo "DISTRO: $DISTRO"
  202. fi
  203. echo
  204. echo "Thank you for using the QB64 installer."
  205.  

did you edit the file common.h and add #define QB64_NOT_X86 ?  It's usually the one big change required for ARM processors to work properly.

Add the define.
Purge all libraries with the batch file for your OS.
Rebuild QB64 with the change at the top of common.h.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline MrGW454

  • Newbie
  • Posts: 6
Re: A Replacement Method for Data Statements
« Reply #19 on: March 23, 2022, 09:24:33 am »
Code: [Select]
[quote author=George McGinn link=topic=4617.msg141500#msg141500 date=1647897902]
That is part of the changes, but does not fix everything, including the DATA statement issue.

Here are the changes needed to run QB64 on a Raspberry PI. Sig Bus errors are the product of a hardware fix that was made on the x86 chips, and not carried over on the ARM chip on the PI:

ank you for using the QB64 installer."
[/quote]

Hi George - your fix has been working well for me.  I've performed about a dozen compilations of various BASIC programs with DATA statements and so far there have been no issues.  I'm looking to test some more complex code soon, but wanted to give you this feedback and thank you again for all your help.