![]() |
![]() |
#1 |
Registered User
Join Date: Nov 2014
Location: Poland
Posts: 72
|
VASM wrong assembling?
Hi,
I have a portion of assembler code generated by gcc: Code:
MakeGadgets: lea (-304,%sp),%sp movem.l #16190,-(%sp) Code:
00001ab0 <MakeGadgets>: 1ab0: 4fef fed0 lea %sp@(-304),%sp 1ab4: 48e7 3f3e moveml %d2-%d7/%a2-%fp,%sp@- Code:
00001d9c <MakeGadgets>: 1d9c: 4fef fed0 lea %sp@(-304),%sp 1da0: 48e7 7cfc moveml %d1-%d5/%a0-%a5,%sp@- Code:
movem.l (%sp)+,#31996 lea (304,%sp),%sp rts Code:
2096: 4cdf 7cfc moveml %sp@+,%d2-%d7/%a2-%fp 209a: 4fef 0130 lea %sp@(304),%sp 209e: 4e75 rts ![]() NOTE: I'm m68k assembler newbie, let me know if I did something obviously wrong. |
![]() |
![]() |
#2 |
Registered User
Join Date: Dec 2007
Location: Dark Kingdom
Posts: 213
|
according to standard Motorola syntax, movem does not support the immediate addressing mode.
I.e., IMHO movem.l #some value,-(sp) should give error. I imagine that the interpretation of such a code should be that the immediate operand encodes which registers are involved. I think it's bad practice for gcc to generate such code |
![]() |
![]() |
#3 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,555
|
Yes, this is one of those gas "extensions", because it is probably easier for the compiler to output the register list as bit mask.
Vasm supports it, but obviously I didn't expect that you have to reverse the bitmask yourself, when a pre-decrement addressing mode is used. This can be easily fixed in cpus/m68k/opcodes.h by replacing D2R (reversed) with D16 for QI (quick immediate) addressing modes: Code:
diff -r1.33 opcodes.h 755c755 < "movem", {QI,PA}, {{D2R,SEA}, {0x4880,0},2|WL|S_WL6,m68000up}, --- > "movem", {QI,PA}, {{D16,SEA}, {0x4880,0},2|WL|S_WL6,m68000up}, 775c775 < "movm", {QI,PA}, {{D2R,SEA}, {0x4880,0},2|WL|S_WL6,m68000up}, --- > "movm", {QI,PA}, {{D16,SEA}, {0x4880,0},2|WL|S_WL6,m68000up}, |
![]() |
![]() |
#4 |
Registered User
Join Date: Nov 2014
Location: Poland
Posts: 72
|
Thanks for the fix!
More questions 1) .word is treated by VASM as 32bit, while GAS treats it as 16bit. Is this known issue? 2) Any chance of adding .balign[w\l] directives? |
![]() |
![]() |
#5 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,555
|
Quote:
I don't understand why .word should be 16 bits for M68k, as it is also a 32-bit CPU. Or does it change for >=68020? I can improve the current implementation, but I need more information. Quote:
.balignw and .balignl are missing indeed. I'm working on it. |
||
![]() |
![]() |
#6 |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,157
|
Simply that in M68K nomenclature a word is 16 bits, as in move.w, add.w, etc, whereas a longword is 32-bits - move.l, etc. Thus any context in which something called just "word" is 32-bits is going to surprise M68K veterans!
|
![]() |
![]() |
#7 | |
AMOS Extensions Developer
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
|
Quote:
For those of us aware of older computers and mainframes (pre 1980s), a 'word' can be as much as 64 (72?) bits! |
|
![]() |
![]() |
#8 | |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 373
|
Quote:
I'm surprised they haven't come back, given how often computers are used in multimedia. 48 bits is a convenient size for all sorts of things. |
|
![]() |
![]() |
#9 | |
Registered User
Join Date: May 2014
Location: inside the emulator
Posts: 377
|
Quote:
![]() |
|
![]() |
![]() |
#10 | |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 373
|
Quote:
Seriously, though, there is a penalty for using bigger values. Cache is too valuable to be filled with so many leading zeros! 48 bits is nice for audio processing -- you can process a 24-bit audio stereo pair. 48 bits is also nice for image processing when you need high dynamic range. 16 bits per channel is very convenient. And most DACs max out at 24-bit resolution, so most processing of real world data is nicely paired with a 48-bit word. Yeah, I know. I'm nutz. ![]() Check out some of the FPGAs and DSPs out there, though. You'll find a surprising amount of support for 24/48 bit processing. |
|
![]() |
![]() |
#11 |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
sorry guys but cant this thread remain preserved for its genuine purpose?
|
![]() |
![]() |
#12 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,555
|
Quote:
Now I only need a list, for all CPUs supported by vasm, which defines the "traditional" word-size. Also 16-bits for x86? ![]() I agree that I have to fix that, of course. |
|
![]() |
![]() |
#13 |
Registered User
Join Date: Nov 2014
Location: Poland
Posts: 72
|
|
![]() |
![]() |
#14 |
Registered User
Join Date: Nov 2014
Location: Poland
Posts: 72
|
Also, I sometimes get this warning:
Code:
warning 1007 in line 3 of "/tmp/ccFFZW8l.s": scratch at end of line > .section .rodata.str1.1,"aMS",@progbits,1 |
![]() |
![]() |
#15 | ||
Banned
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
|
Quote:
http://en.wikipedia.org/wiki/Word_%2...rchitecture%29 Fortunately, GAS appears to use the consistent 68k/VAX/PDP-11 definition which is always word=16 bits (2 bytes) and longword=32 bits (4 bytes). Quote:
|
||
![]() |
![]() |
#16 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,555
|
Vasm's std syntax module only reads the section name and attributes. The rest is ignored. I think @progbits is ELF specific. Don't know what the last argument means.
|
![]() |
![]() |
#17 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,555
|
|
![]() |
![]() |
#18 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,555
|
Quote:
And, for the moment, I changed .word to emit 16-bit constants, until I implement a better, backend-dependant, solution. |
|
![]() |
![]() |
#19 |
Registered User
Join Date: Nov 2014
Location: Poland
Posts: 72
|
Thank you! I'll tests those changes shortly. For now I think I found a problem with weak symbols.
Here is original code as generated by GCC: Code:
pea __LIBS_LIST__ jsr _set_open_libraries_list addq.l #8,%sp tst.l %d0 jeq .L10 move.l %a6,-(%sp) pea 1.w pea 1.w pea __INIT_LIST__ jsr _set_call_funcs Code:
88: 4879 0000 0000 pea 0 <Workbench_3_Workbench_ExpungeLib> 8a: R_68K_32 __LIBS_LIST__ 8e: 4eb9 0000 0000 jsr 0 <Workbench_3_Workbench_ExpungeLib> 90: R_68K_32 _set_open_libraries_list 94: 508f addql #8,%sp 96: 4a80 tstl %d0 98: 6700 008a beqw 124 <Workbench_InitLib+0xc4> 9c: 2f0e movel %fp,%sp@- 9e: 4878 0001 pea 1 <Workbench_3_Workbench_ExpungeLib+0x1> a2: 4878 0001 pea 1 <Workbench_3_Workbench_ExpungeLib+0x1> a6: 4879 0000 00b8 pea b8 <Workbench_InitLib+0x58> a8: R_68K_32 .rodata+0xb8 ac: 4eb9 0000 0000 jsr 0 <Workbench_3_Workbench_ExpungeLib> ae: R_68K_32 _set_call_funcs Code:
88: 4879 0000 0000 pea 0 <Workbench_3_Workbench_ExpungeLib> 8a: R_68K_32 __LIBS_LIST__ 8e: 4eb9 0000 0000 jsr 0 <Workbench_3_Workbench_ExpungeLib> 90: R_68K_32 _set_open_libraries_list 94: 508f addql #8,%sp 96: 4a80 tstl %d0 98: 6700 0082 beqw 11c <Workbench_InitLib+0xbc> 9c: 2f0e movel %fp,%sp@- 9e: 4878 0001 pea 1 <Workbench_3_Workbench_ExpungeLib+0x1> a2: 4878 0001 pea 1 <Workbench_3_Workbench_ExpungeLib+0x1> a6: 4879 0000 0000 pea 0 <Workbench_3_Workbench_ExpungeLib> a8: R_68K_32 __INIT_LIST__ ac: 4eb9 0000 0000 jsr 0 <Workbench_3_Workbench_ExpungeLib> ae: R_68K_32 _set_call_funcs Code:
.weak __INIT_LIST__ .align 2 .type __INIT_LIST__, @object .size __INIT_LIST__, 8 __INIT_LIST__: .skip 8 If I changed the __INIT_LIST__ to be external non-weak, things started to work as they should. |
![]() |
![]() |
#20 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,555
|
Yes, that's a serious problem with references to weak symbols. Thanks for reporting. It was never much tested, because usually AmigaOS and MorphOS programs don't need them.
Unlike gas, vasm always tries to convert relocations with defined symbols into section+offset, so the symbol is no longer needed. Doing that with weak symbols is fatal of course, because the linker may change the reference. Fixed for aout and ELF formats. Please try tomorrows snapshot. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
vasm question | marduk_kurios | Coders. Asm / Hardware | 7 | 14 February 2014 20:06 |
Assembling Gravity Force 2 source code | absence | Coders. General | 5 | 13 May 2012 11:44 |
[REQ:ASM] Assembling and running | jman | Coders. Tutorials | 9 | 07 May 2011 18:39 |
Devpac and assembling for absolute addresses | h0ffman | Coders. General | 10 | 21 March 2011 19:12 |
vasm 1.5 RFC | phx | Coders. General | 30 | 11 December 2010 02:08 |
|
|