![]() |
![]() |
#1 |
Registered User
![]() Join Date: Jan 2008
Location: somewhere
Posts: 43
|
Reference to undefined symbol __ldivu / __lmodu
Hello
Here's the plan. I'm coding a custom kickstart with cross compiling on Ubuntu 16.04 x64 using this toolchain : https://github.com/cahirwpz/amigaos-cross-toolchain. This tool chain is ok, every test I made for amiga executables are fine.Now, I want to make a custom kickstart from scratch so I don't want to use any system library or std lib. Below is a bare bones c source code I made to isolate my problem : blink.c Code:
int main(void) { unsigned long i = 1; unsigned long base = 1; while (i != 0) { i %= base; i /= base; } } Code:
# A = vasmm68k_mot -Fhunk -spaces -nosym -quiet C = vc -c -c99 -O1 -sc -vv -S -vv L = vlink -nostdlib -s -brawbin1 -Ttext 0xfc0000 D = rm default: blink.o $(L) -o rom.bin blink.o clean: @$(D) *.o rom.bin blink.o: blink.c $(C) blink.c Code:
vc -c -c99 -O1 -sc -vv -S -vv blink.c vc frontend for vbcc (c) in 1995-2010 by Volker Barthelmann flags=389 opt=991 len=1522 Argument 8:blink.c File "blink.c"=2 add_name: "/tmp/fileyYNTuE.asm" vbccm68k "blink.c" -o= "/tmp/fileyYNTuE.asm" -c99 -sc -O=991 -I/opt/m68k-amigaos/vbcc-include -I/opt/m68k-amigaos/os-include vbcc V0.9b (c) in 1995-2011 by Volker Barthelmann vbcc code-generator for m68k/ColdFire V1.8 (c) in 1995-2010 by Volker Barthelmann add_name: "blink.o" vasmm68k_mot -Fhunk -phxass "/tmp/fileyYNTuE.asm" -o "blink.o" -I/opt/m68k-amigaos/os-include vasm 1.6b (c) in 2002-2013 Volker Barthelmann vasm M68k/CPU32/ColdFire cpu backend 1.3e (c) 2002-2013 Frank Wille vasm motorola syntax module 3.4a (c) 2002-2013 Frank Wille vasm hunk format output module 2.3 (c) 2002-2012 Frank Wille CODE(acrx4): 48 bytes rm -v "/tmp/fileyYNTuE.asm" '/tmp/fileyYNTuE.asm' supprimé free p->obj "blink.o" free p free p->obj "/tmp/fileyYNTuE.asm" free p vlink -nostdlib -s -brawbin1 -Ttext 0xfc0000 -o rom.bin blink.o blink.o: In "l5": Error 21: blink.o (CODE+0xc): Reference to undefined symbol __lmodu. Error 21: blink.o (CODE+0x1e): Reference to undefined symbol __ldivu. makefile:7 : la recette pour la cible « default » a échouée make: *** [default] Erreur 1 Code:
int main(void) { unsigned long i = 1; unsigned long base = 1; //while (i != 0) // <========= HERE ====== { i %= base; i /= base; } } itoa.o: In "l12": Error 21: itoa.o (CODE+0x32): Reference to undefined symbol __lmodu. Error 21: itoa.o (CODE+0x58): Reference to undefined symbol __ldivu. And the full project is 68kos.zip Can someone can help me on this ? |
![]() |
![]() |
#2 |
Natteravn
![]() Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
|
Your C source does 32 bit modulo and division with a 32 bit result and it is compiled for a 68000 target CPU. But there is no native 68000 instruction for this task (only 68020+ has it), so the compiler calls _lmodu() and _ldivu() from vclib for these operations.
Solution: Either write _lmodu and _ldivu yourself or link with vc.lib. |
![]() |
![]() |
#3 |
Registered User
![]() Join Date: Jan 2008
Location: somewhere
Posts: 43
|
Hello,
You are right, using 68020 target (vc [...] -cpu=68020) and everything is now fine... Thank you ! But some questions remain unanswered : - Why if the 'while' loop is present, the error rises, and not when there is no loop ? Does the compiler detects this case and adjust accordingly ? - If I want to stick to 68000 target, you said I have to write my own version of those functions. Where can I get the source from ? Thank you ! |
![]() |
![]() |
#4 | ||
Natteravn
![]() Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
|
Quote:
Quote:
Code:
; 32bit Division/Modulo for 68000/68010 * Functions: * long __divu(register long d0, register long d1) * long __divs(register long d0, register long d1) * long __modu(register long d0, register long d1) * long __mods(register long d0, register long d1) * __ldivs etc. expect parameters on the stack mc68000 code xdef __divu xdef __divs xdef __modu xdef __mods xdef __ldivs xdef __ldivu xdef __lmods xdef __lmodu __lmods movem.l 4(sp),d0/d1 __mods: tst.l d1 bmi 1$ tst.l d0 bmi 2$ bsr __divu move.l d1,d0 rts 1$: neg.l d1 tst.l d0 bmi 3$ bsr __divu move.l d1,d0 rts 2$: neg.l d0 bsr __divu neg.l d1 move.l d1,d0 rts 3$: neg.l d0 bsr __divu neg.l d1 move.l d1,d0 rts __lmodu movem.l 4(sp),d0/d1 __modu: bsr __divu move.l d1,d0 rts __ldivs movem.l 4(sp),d0/d1 __divs: tst.l d0 bpl 2$ neg.l d0 tst.l d1 bpl 1$ neg.l d1 bsr __divu neg.l d1 rts 1$: bsr __divu neg.l d0 neg.l d1 rts 2$: tst.l d1 bpl __divu neg.l d1 bsr __divu neg.l d0 rts __ldivu movem.l 4(sp),d0/d1 __divu: move.l d2,-(sp) swap d1 move.w d1,d2 bne 2$ swap d0 swap d1 swap d2 move.w d0,d2 beq 1$ divu d1,d2 move.w d2,d0 1$: swap d0 move.w d0,d2 divu d1,d2 move.w d2,d0 swap d2 move.w d2,d1 move.l (sp)+,d2 rts 2$: move.l d3,-(sp) moveq #16,d3 cmp.w #$80,d1 bhs 3$ rol.l #8,d1 subq.w #8,d3 3$: cmp.w #$800,d1 bhs 4$ rol.l #4,d1 subq.w #4,d3 4$: cmp.w #$2000,d1 bhs 5$ rol.l #2,d1 subq.w #2,d3 5$: tst.w d1 bmi 6$ rol.l #1,d1 subq.w #1,d3 6$: move.w d0,d2 lsr.l d3,d0 swap d2 clr.w d2 lsr.l d3,d2 swap d3 divu d1,d0 move.w d0,d3 move.w d2,d0 move.w d3,d2 swap d1 mulu d1,d2 sub.l d2,d0 bhs 8$ subq.w #1,d3 add.l d1,d0 7$: bhs.s 7$ 8$: moveq #0,d1 move.w d3,d1 swap d3 rol.l d3,d0 swap d0 exg d0,d1 move.l (sp)+,d3 move.l (sp)+,d2 rts end |
||
![]() |
![]() |
#5 | ||
Registered User
![]() Join Date: Jan 2008
Location: somewhere
Posts: 43
|
Quote:
Quote:
I want to make a custom kickstart from scratch, so I can't use any external library. I have to build "mine" (http://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler) |
||
![]() |
![]() |
#6 | |
Natteravn
![]() Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
|
Quote:
Many functions from the C-library can be used without problems (e.g. all string operations, ctype, 64-bit arithmetics). You only have to make sure to avoid functions which do OS-calls, like stdio, stdlib, time. When building a ROM you have to be careful with static variables. And it may be useful to write a proper linker script. |
|
![]() |
![]() |
#7 |
Registered User
![]() Join Date: Jan 2008
Location: somewhere
Posts: 43
|
Ok, understood.
Where can I download the source code of vclib ? |
![]() |
![]() |
#8 |
Natteravn
![]() Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,318
|
|
![]() |
![]() |
#9 |
Registered User
![]() Join Date: Jan 2008
Location: somewhere
Posts: 43
|
Ok
![]() Any way, thank you ! |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
AmiDevCpp asm - undefined reference | Sephnroth | Coders. C/C++ | 14 | 27 December 2022 16:51 |
SAS/C: Undefined symbols | Yesideez | Coders. C/C++ | 14 | 13 February 2014 16:36 |
AsmOne: Undefined symbol | copse | Coders. Asm / Hardware | 2 | 02 April 2012 01:41 |
Undefined symbol bsr.b init_bitmaps | VoltureX | Coders. General | 12 | 13 November 2011 16:11 |
using the '*'-symbol in assembler - what do you expect? | phx | Coders. General | 11 | 02 December 2009 12:56 |
|
|