So everybody can see what we're talking about, here is the gas/symbolic
test program from the tests/next branch of the mspgcc repository.

.global extern
 mov &0x1000, r15
 mov 0x1000, r15
 mov &local, r15
 mov local, r15
 mov &extern, r15
 mov extern, r15

 mov r14, &0x1000
 mov r14, 0x1000
 mov r14, &local
 mov r14, local
 mov r14, &extern
 mov r14, extern

; mov $, &extern
; mov $+2, &extern

local:
 jmp 0
 jmp 2
 jmp local
.global external_code ; a constant value within range
 jmp external_code

; jmp $
 jmp $+0
 jmp $+2
 jmp $+0x100

A couple lines are commented out because the current assembler won't
process them, something I consider to be a bug.  I would be interested in
knowing if other tools accept $ as denoting the program location counter in
contexts other than jump instructions, and if so whether it means the
beginning of the instruction or the address of the offset encoded internal
to the instruction.

Using this input with LTS-20110716:

 msp430-as    -o test.o test.s
 msp430-objdump -dr test.o > test.dis

one gets the following:

test.o:     file format elf32-msp430

Disassembly of section .text:

00000000 <local-0x30>:
   0: 1f 42 00 10 mov &0x1000,r15
   4: 1f 40 fa 0f mov 0x0ffa, r15 ;PC rel. 0x01002
   8: 1f 42 00 00 mov &0x0000,r15
 a: R_MSP430_16 .text+0x30
   c: 1f 40 22 00 mov 0x0022, r15 ;PC rel. 0x00032
  10: 1f 42 00 00 mov &0x0000,r15
 12: R_MSP430_16 extern
  14: 1f 40 00 00 mov 0x0000, r15 ;PC rel. 0x00018
 16: R_MSP430_16_PCREL_BYTE extern
  18: 82 4e 00 10 mov r14, &0x1000
  1c: 80 4e e2 0f mov r14, 0x0fe2 ;PC rel. 0x01002
  20: 82 4e 00 00 mov r14, &0x0000
 22: R_MSP430_16 .text+0x30
  24: 80 4e 0a 00 mov r14, 0x000a ;PC rel. 0x00032
  28: 82 4e 00 00 mov r14, &0x0000
 2a: R_MSP430_16 extern
  2c: 80 4e 00 00 mov r14, 0x0000 ;PC rel. 0x00030
 2e: R_MSP430_16_PCREL extern

00000030 <local>:
  30: 00 3c       jmp $+2      ;abs 0x32
  32: 01 3c       jmp $+4      ;abs 0x36
  34: fd 3f       jmp $-4      ;abs 0x30
  36: 00 3c       jmp $+2      ;abs 0x38
 36: R_MSP430_13_PCREL external_code
  38: 00 3c       jmp $+2      ;abs 0x3a
  3a: 00 3c       jmp $+2      ;abs 0x3c
  3c: 7f 3c       jmp $+256    ;abs 0x13c

With a final link:

msp430-ld -o testr.o test.o
 msp430-objdump -dr testr.o > testr.dis

where the text section starts at 0x6000, the external_code symbol has the
value 0x6000, and the extern symbol has the value 0x1000, one gets:

testr.o:     file format elf32-msp430

Disassembly of section .text:

00006000 <__ctors_end>:
    6000: 1f 42 00 10 mov &0x1000,r15
    6004: 1f 40 fa 0f mov 0x0ffa, r15 ;PC rel. 0x07002
    6008: 1f 42 30 60 mov &0x6030,r15
    600c: 1f 40 22 00 mov 0x0022, r15 ;PC rel. 0x06032
    6010: 1f 42 00 10 mov &0x1000,r15
    6014: 1f 40 ea af mov 0xafea, r15 ;PC rel. 0x01002
    6018: 82 4e 00 10 mov r14, &0x1000
    601c: 80 4e e2 0f mov r14, 0x0fe2 ;PC rel. 0x07002
    6020: 82 4e 30 60 mov r14, &0x6030
    6024: 80 4e 0a 00 mov r14, 0x000a ;PC rel. 0x06032
    6028: 82 4e 00 10 mov r14, &0x1000
    602c: 80 4e d2 af mov r14, 0xafd2 ;PC rel. 0x01002

00006030 <local>:
    6030: 00 3c       jmp $+2      ;abs 0x6032
    6032: 01 3c       jmp $+4      ;abs 0x6036
    6034: fd 3f       jmp $-4      ;abs 0x6030
    6036: e4 3f       jmp $-54     ;abs 0x6000
    6038: 00 3c       jmp $+2      ;abs 0x603a
    603a: 00 3c       jmp $+2      ;abs 0x603c
    603c: 7f 3c       jmp $+256    ;abs 0x613c

Be aware that all PC rel. comments are two bytes too high, due to bugs in
the 
disassembly<https://sourceforge.net/tracker/?func=detail&aid=3487360&group_id=42303&atid=432701>
.

Feel free to review, consider, and try the source on other tools to see
what they do.  I'm still forming a position on what I think should happen,
but my intent is to:

1) preserve existing behavior where it makes sense and/or is in common use;

2) make symbolics behave as consistently as possible in jumps compared with
normal instructions;

3) break existing behavior where I don't think it's common and it would be
indefensible if it wasn't existing.

I consider the assembly of the instruction at 0x6038 (originally jmp $+0)
to be indefensibly wrong.

I consider the fact that you can't pass the output of the disassembler into
the assembler and get back what you put in to be indefensibly wrong.

When I have confirmed my own understanding of the issues by producing a
working solution, I'll follow up to show what will happen if the world
becomes how I think it should be, and will outline how that might impact
existing code.  I expect to make the changes available in the git
repositories, but it won't be incorporated into a bundled release until
people have a chance to look at it, because it's gonna break somebody.

(As somebody suggested before, this has no relevance to C/C++ programmers
unless you use asm statements, and what we're discussing is exactly how
msp430-as/msp430-objdump/msp430-link/etc should behave.)
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to