Kubuntu 7.10 c_source example compile problem

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Kubuntu 7.10 c_source example compile problem

Post by ndudman »

Hi Im just trying to build the c_source example project posted at the begining of this ZBasic Native mode forum... and getting the following errors. I don't think its got as far as trying to compile
  • ls>"C:\Program Files\ZBasic\zbasic.exe" --target-device=ZX24n --directory="Z:\home\vdudman\Desktop\source\c_source/" --project="c_source.pjt"
    make: Entering directory `Z:/home/vdudman/Desktop/source/c_source/zxTempDir/c_source'
    avr-gcc -c -Dzx24n -mmcu=atmega644p -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct c_source.c -o c_source.o
    0 [main] sh 24 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
    2973 [main] sh 24 open_stackdumpfile: Dumping stack trace to sh.exe.stackdump
    make: *** [c_source.o] Error 101120
    "C:\Program: Interrupt/Exception caught (code = 0xc0000005, addr = 0xb7e30cb5)
    Error: one or more errors occurred in the back-end build process for "c_source.zxb"
    >Exit code: 1
Is it something with the file permisions ?

The sh.exe.stackdump file is
  • Exception: STATUS_ACCESS_VIOLATION at eip=30075575
    eax=00000000 ebx=7FB7F9A8 ecx=7FFDEA00 edx=00000039 esi=30590094 edi=7FB7F798
    ebp=7FB7FCB8 esp=7FB7F4AC program=C:\Program Files\ZBasic\WinAvr\utils\bin\sh.ex
    e
    cs=0073 ds=007B es=007B fs=1007 gs=0033 ss=007B
    Stack trace:
    Frame Function Args
    7FB7FCB8 30075575 (30590094, 00000000, 7FB7FDB8, 3000427C)
    7FB7FCD8 30075AD2 (7FB7FDE8, 00000000, 7FFDF760, 00000000)
    7FB7FDB8 30004297 (00000000, 00000000, 7FFDF760, 00320033)
    7FB7FE88 300047B1 (004011C8, 7FFDF760, 00000000, 00000000)
    7FB7FEA8 30004E2C (00000000, 00000000, 00000000, 00000000)
    7FB7FED8 0046E73F (004011C8, 7FB7FF38, 7FE48000, 7FB7FF08)
    7FB7FF08 0040103D (7FFDF760, 00000000, 00000000, 00000000)
    7FB7FFE8 7FC3B311 (00000000, 00000000, 00000000, 00000000)
    End of stack trace
Thanks
Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Kubuntu 7.10 c_source example compile problem

Post by dkinzer »

ndudman wrote:Im just trying to build the c_source example project posted at the begining of this ZBasic Native mode forum... and getting the following errors. I don't think its got as far as trying to compile
The output that you showed indicates that the make invocation succeeds and it then tries to execute the avr-gcc compiler which then fails when it attempts to execute one of its sub-processes. It may be that the PATH environment variable isn't getting set correctly to ensure that all of the executables from the ZBasic distribution are being used instead of those that exist elsewhere on your system.

Which Windows emulator are you using?
- Don Kinzer
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Re: Kubuntu 7.10 c_source example compile problem

Post by ndudman »

dkinzer wrote:Which Windows emulator are you using?
I'm using wine-0.9.46.

I'm just going to try it on VMware running nt2000, but I'd rather use wine :)

Any other info, or test I can do to help ?

Neil
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Re: Kubuntu 7.10 c_source example compile problem

Post by ndudman »

dkinzer wrote: It may be that the PATH environment variable isn't getting set correctly to ensure that all of the executables from the ZBasic distribution are being used instead of those that exist elsewhere on your system.
?
I don't have avr-gcc compiler installed other than the zbasic one.
Neil
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

Hi

Just thinking about this again as my native device comes in the post soon and I don't want to install NT if I can help it.

Looking at the thread about this also at
http://www.zbasic.net/forum/about1096.h ... light=wine
mention is made of adding --keep-files and that the make file created should be in the temp dir. I don't find a makefile, my project file is
  • --keep-files
    --verbose
    c_source.bas
    factorial.c
The c_source.o is created but no make file, I'm at a loss where to look to check if paths are correct etc. There is no avr-gcc install on the linux system I'm using xbuntu 8.10
  • >"C:\Program Files\ZBasic\zbasic.exe" --target-device=ZX24n --directory="Z:\home\ndudman\source\c_source/" --project="c_source.pjt"
    make: Entering directory `Z:/home/ndudman/source/c_source/zxTempDir/c_source'
    avr-gcc -c -Dzx24n -mmcu=atmega644p -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct c_source.c -o c_source.o
    "C:\Program: Interrupt/Exception caught (code = 0xc0000005, addr = 0xb7d4bb56)
    Error: one or more errors occurred in the back-end build process for "c_source.zxb"
    >Exit code: 1
Thanks for the help of suggestions, if anyone has gotten further etc.

Regards
Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

ndudman wrote:The c_source.o is created but no make file, I'm at a loss where to look to check if paths are correct etc.
My earlier post was incorrect with respect to the makefile. In order to retain the generated makefile you need to add the following (undocumented) option to the project file:

Code: Select all

--diag=x100
- Don Kinzer
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

Thanks Don

I added it and now get the make file
  • MCU = atmega644p
    TARGET = c_source.bin
    DEVICE = zx24n
    ZXLIBDIR = C:/Program Files/ZBasic/zxlib
    ZXLIB = $(DEVICE)
    LDSCRIPT=$(ZXLIBDIR)/zx_avr5.lds
    CSRC = c_source.c \
    Z:/home/ndudman/source/c_source/factorial.c

    CFLAGS = -D$(DEVICE) -mmcu=$(MCU) -std=gnu99 -fgnu89-inline -gdwarf-2 -Os
    CFLAGS += -I"$(ZXLIBDIR)" -I.
    CFLAGS += -Wall -Wstrict-prototypes -funsigned-char -fpack-struct
    LDFLAGS = -mmcu=$(MCU) -L"$(ZXLIBDIR)" -Wl,-T,"$(LDSCRIPT)"
    LDFLAGS += -u rtc_ISR
    LDFLAGS += -u default_ISR
    LDLIBS = -l$(ZXLIB) -lm
    CC = avr-gcc
    AR = avr-ar
    OBJCOPY = avr-objcopy
    NM = avr-nm
    OBJDUMP = avr-objdump
    ECHO = echo
    REMOVE = rm -f
    EXT = .i1
    OBJ = $(CSRC:.c=.o)
    EXTOBJ =
    EEPROM = $(basename $(TARGET)).eeb
    all : $(TARGET) $(EEPROM) $(basename $(TARGET)).sym
    $(REMOVE) $(basename $(TARGET))$(EXT) $(OBJ) $(CSRC:.c=.s)
    $(basename $(TARGET))$(EXT) : $(OBJ)
    $(CC) -o $(basename $(TARGET))$(EXT) $(LDFLAGS) $(OBJ) $(EXTOBJ) $(LDLIBS)
    %.o : %.c
    $(CC) -c $(CFLAGS) $< -o $@
    %.bin : %$(EXT)
    $(OBJCOPY) -R .eeprom -R .zx_eeprom -O binary $< $@
    %.eeb : %$(EXT)
    $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O binary $< $@
    %.sym : %$(EXT)
    $(NM) -n $< > $@
    %.lss : %$(EXT)
    $(OBJDUMP) -h -S $< > $@
I can run the make.exe command from cmd line and am told its uptodate, ok I had to escape the spaces in paths C:/Program\ Files/ZBasic/zxlib with a \

Then I tried running the
  • avr-gcc -c -Dzx24n -mmcu=atmega644p -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program\ Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct c_source.c -o c_source.o
and again had to escape the path with \ and change the paths
  • /home/ndudman/.wine/drive_c/Program\ Files/ZBasic/WinAvr/bin/avr-gcc.exe -c -Dzx24n -mmcu=atmega644p -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I/home/ndudman/.wine/drive_c/Program\ Files/ZBasic/zxlib -I/home/ndudman/.wine/drive_c/Program\ Files/ZBasic/zxlib -Wall -Wstrict-prototypes -funsigned-char -fpack-struct c_source.c -o c_source.o
and it compiled with no errors

Does this help us at all ?

Regards
Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

ndudman wrote:Does this help us at all ?
Perhaps. We'll need to do some experimentation here to discover what is necessary to run under Wine.

You could write a shell script (or Perl script, etc.) to modify the makefile so that you don't have to do so manually.
- Don Kinzer
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

I'm confused, or have been mistaken... when I ran the make it told me it had nothing to do, I think because the tmp files where still left over from when I built it on NT, I've gotten a bit confused. Sorry for possible confusion...

The make works now i've installed avr-gcc for Ubuntu 8.10 (simple instructions prebuilt at http://www.avride.com/pop/?p=12) And i use the linux

Code: Select all

make -f c_source.mak
command which picks up the linux avr-... programs. and the make file i've modified. It seems to work... I understand the the IDE creates the c_source.zxb file... how could I do this from the modified make file ?

The error I was getting from Zbasic make.exe was (just included incase it makes any sense)
  • /home/ndudman/.wine/drive_c/Program\ Files/ZBasic/WinAvr/utils/bin/make.exe -f c_source.mak
    avr-gcc -c -Dzx24n -mmcu=atmega644p -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I/home/ndudman/.wine/drive_c/Program\ Files/ZBasic/zxlib -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct /home/ndudman/source/c_source/zxTempDir/c_source/c_source.c -o /home/ndudman/source/c_source/zxTempDir/c_source/c_source.o
    process_begin: CreateProcess(NULL, avr-gcc -c -Dzx24n -mmcu=atmega644p -std=gnu99 -fgnu89-inline -gdwarf-2 -Os "-I/home/ndudman/.wine/drive_c/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct /home/ndudman/source/c_source/zxTempDir/c_source/c_source.c -o /home/ndudman/source/c_source/zxTempDir/c_source/c_source.o, ...) failed.
    make (e=2): File not found
    make.exe: *** [/home/ndudman/source/c_source/zxTempDir/c_source/c_source.o] Error 2
The continuation of CFLAGS on a new line seems to add "" around "-I/home/ndudman/.wine/drive_c/Program Files/ZBasic/zxlib" and the \ for the space in path seems to get removed.

Not sure how the upload to device is performed for zx devices ? I guess the ZLoad.exe, just need the final zxb file ?

I've been developing on an atmega8 using AvrUsb500v2 an stk500 V2 compatible, with USB interface from http://www.tuxgraphics.org/electronics/ ... 7052.shtml. Would I be able to use the old usb programmer, and associated linux programs I had for the zx device ?

Neil

p.s Heres the make file with my changes, it runs using linux make
  • MCU = atmega644p
    TARGET = c_source.bin
    DEVICE = zx24n
    ZXLIBDIR = /home/ndudman/.wine/drive_c/Program\ Files/ZBasic/zxlib
    ZXLIB = $(DEVICE)
    LDSCRIPT=$(ZXLIBDIR)/zx_avr5.lds
    CSRC = /home/ndudman/source/c_source/zxTempDir/c_source/c_source.c \
    /home/ndudman/source/c_source/factorial.c

    CFLAGS = -D$(DEVICE) -mmcu=$(MCU) -std=gnu99 -fgnu89-inline -gdwarf-2 -Os
    CFLAGS += -I$(ZXLIBDIR) -I.
    CFLAGS += -Wall -Wstrict-prototypes -funsigned-char -fpack-struct
    LDFLAGS = -mmcu=$(MCU) -L$(ZXLIBDIR) -Wl,-T,$(LDSCRIPT)
    LDFLAGS += -u rtc_ISR
    LDFLAGS += -u default_ISR
    LDLIBS = -l$(ZXLIB) -lm
    CC = avr-gcc
    AR = avr-ar
    OBJCOPY = avr-objcopy
    NM = avr-nm
    OBJDUMP = avr-objdump
    ECHO = echo
    REMOVE = rm -f
    EXT = .i1
    OBJ = $(CSRC:.c=.o)
    EXTOBJ =
    EEPROM = $(basename $(TARGET)).eeb
    all : $(TARGET) $(EEPROM) $(basename $(TARGET)).sym
    $(REMOVE) $(basename $(TARGET))$(EXT) $(OBJ) $(CSRC:.c=.s)
    $(basename $(TARGET))$(EXT) : $(OBJ)
    $(CC) -o $(basename $(TARGET))$(EXT) $(LDFLAGS) $(OBJ) $(EXTOBJ) $(LDLIBS)
    %.o : %.c
    $(CC) -c $(CFLAGS) $< -o $@
    %.bin : %$(EXT)
    $(OBJCOPY) -R .eeprom -R .zx_eeprom -O binary $< $@
    %.eeb : %$(EXT)
    $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O binary $< $@
    %.sym : %$(EXT)
    $(NM) -n $< > $@
    %.lss : %$(EXT)
    $(OBJDUMP) -h -S $< > $@
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

ndudman wrote:how could I do this from the modified make file ?
Unfortunately, there isn't an external command for converting the .bin file to a .zxb file. I apologize for not thinking ahead to that issue.
ndudman wrote:The error I was getting from Zbasic make.exe was (just included incase it makes any sense)
It is difficult to determine which of the issues you've identified are artifacts of the displaying mechanism and which are real. We've installed Unbutu here on a test machine and will soon install Wine so we can do further testing. It is possible that we'll have to add a special option to instruct the ZBasic compiler to build a specially constructed makefile for use on Linux/Wine platforms. Some years ago, I suggested to the Wine team that there should be a way to determine if an application was executing under Wine. The response was that they would never consider doing such a thing because it is contrary to their goal of making Wine completely transparent. I haven't looked at Wine for some years so I don't know if they have relented on this position. I still think that it would be a useful mechanism for special circumstances.
ndudman wrote:Not sure how the upload to device is performed for zx devices ? I guess the ZLoad.exe, just need the final zxb file ?
Although the zload utility can be used, the IDE has its own internal mechanism; essentially an internalized form of the code used to implement zload.exe.
ndudman wrote:Would I be able to use the old usb programmer, and associated linux programs I had for the zx device ?
Although you can use any compatible AVR Flash programmer to program a ZX chip, doing so will require that the chip be erased which will cause loss of the ZX bootloader. A compiled ZX application will not function without the ZX bootloader because it provides some important functionality.
- Don Kinzer
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

dkinzer wrote:Unfortunately, there isn't an external command for converting the .bin file to a .zxb file. I apologize for not thinking ahead to that issue.
Dont apologise... I didn't understand how it all operates internally so was just wondering what was possible.

Thanks for the info about using a different programmer, I was thinking there might be something like that, although didn't understand exactly what.

Also for the info about wine and how the internals of the IDE operate. I appreciate your time and effort and sorry to be psting such things, was really hoping that i could help more. But am at least pleased to understand things a little better now.

Regards
Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

dkinzer wrote:We'll need to do some experimentation here to discover what is necessary to run under Wine.
We now have native mode compiles working successfully under Wine. We tested this on Ubuntu v8.10 with Wine v1.1.12.

The problem turned out to be an issue with the gnu make utility running on top of mingw running on Wine. It would run one command and then fail with an access violation similar to the one you described. Curiously, we are able to execute a series of avr-gcc commands from a batch file.

To work around this problem, we modified the ZBasic compiler to detect when it is running on Wine. In that case, it builds a batch file containing the back-end build commands instead of constructing a makefile to achieve the same purpose. The same effect can be achieved on "real" Windows by using the newly added compiler option --use-batch-file (whose presence is ignored for VM mode devices).

An experimental version of the ZBasic compiler containing this change can be obtained using the link below. You should be able to unzip it and copy the ZBasic.exe file to the ZBasic installation directory on your Linux box.

http://www.zbasic.net/download/ZBasic/2 ... 2-6-10.zip

We haven't yet been able to test downloading from the IDE to a ZX under Wine. We have some unknown issue with the serial port configuration under Wine. The devices /dev/ttyS0 and /dev/ttyS1 are present and they work properly in Linux. In the ZBasic IDE, we can successfully open Com1 and Com2 but we can neither send nor receive data via the ports.

I'd like to get a report from someone else about the ability to download or even to receive output from the ZX. As shipped from the factory, most ZX devices contain a program that outputs a "hello world" message in a loop.
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Post by dlh »

dkinzer wrote: I'd like to get a report from someone else about the ability to download or even to receive output from the ZX. As shipped from the factory, most ZX devices contain a program that outputs a "hello world" message in a loop.
I haven't yet completed my Linux (or OSX) downloader coding but I can receive output from my ZX-40a under Ubuntu & Debian. I have Fedora 9 installed but haven't gotten around to testing with it. I do not use Wine so I cannot help there.
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

Hi

I just installed the experimental version and its really great to see compilation of simple code, will try it with my project now, and happily stop using win95 under vmplayer ontop of linux on an old laptop.

Will happily test and provide feedback of a factory loaded new zx24n, as soon as it arrives which should be any day now.

I have two computers with near identical OS Linux Kubuntu 8.10 (desktop) and Xubuntu 8.10 (laptop). Ive been putting off finding out how to connect the new zx24n to serial port, perhaps now is the time to confirm I have everything ? Im mostly worried about the laptop as it dosnt have a serial port only usb, I think I need another cable for that ?

Thanks Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

ndudman wrote:Ive been putting off finding out how to connect the new zx24n to serial port, perhaps now is the time to confirm I have everything ? Im mostly worried about the laptop as it dosnt have a serial port only usb, I think I need another cable for that ?
All ZX devices have (mostly) standard serial interfaces. In order to a ZX to a PC you need to have a 9-pin or 25-pin serial port. If your computer doesn't have a standard serial port, you'll need to get a USB-serial port adapter.

Unfortunately, not all such adapters are fast enough to function correctly with the standard DTR signalling that is used to get the ZX into download mode. Our experience has been that the adapters which use the second generation FTDI chips (like the FT232RL) function perfectly. Adapters based on other chips may or may not work; we've tried some that did work and others that didn't. Moreover, some USB adapters seem to have a driver anomaly that causes the IDE downloader software to get hung in a loop waiting for characters to be transmitted. We've seen this with the Keyspan USA19 adapter. Oddly, it works fine using the zload utility.

For desktop systems, it is probably best to get an inexpensive serial card if your system doesn't have standard serial ports. You should be able to buy one for less than the cost of a USB adapter and it is almost certain to work without problems.
- Don Kinzer
Post Reply