Mercurial > lcfOS
comparison python/ppci/linker.py @ 365:98ff43cfdd36
Nasty bug in adr instruction
author | Windel Bouwman |
---|---|
date | Wed, 19 Mar 2014 22:32:04 +0100 |
parents | c49459768aaa |
children | 9667d78ba79e |
comparison
equal
deleted
inserted
replaced
364:c49459768aaa | 365:98ff43cfdd36 |
---|---|
1 import logging | 1 import logging |
2 import struct | 2 import struct |
3 from .objectfile import ObjectFile | 3 from .objectfile import ObjectFile |
4 from . import CompilerError | 4 from . import CompilerError |
5 from .bitfun import encode_imm32 | |
5 | 6 |
6 def align(x, m): | 7 def align(x, m): |
7 while ((x % m) != 0): | 8 while ((x % m) != 0): |
8 x = x + 1 | 9 x = x + 1 |
9 return x | 10 return x |
97 U = 1 | 98 U = 1 |
98 if offset < 0: | 99 if offset < 0: |
99 offset = -offset | 100 offset = -offset |
100 U = 0 | 101 U = 0 |
101 assert offset < 4096 | 102 assert offset < 4096 |
102 section.data[reloc.offset+2] |= (U << 7) #(rel24 >> 16) & 0xFF | 103 section.data[reloc.offset+2] |= (U << 7) |
103 section.data[reloc.offset+1] |= (offset >> 8) & 0xF | 104 section.data[reloc.offset+1] |= (offset >> 8) & 0xF |
104 section.data[reloc.offset+0] = offset & 0xFF | 105 section.data[reloc.offset+0] = offset & 0xFF |
105 | 106 |
106 @reloc('adr_imm12') | 107 @reloc('adr_imm12') |
107 def apply_adr_imm12(reloc, sym, section, reloc_value): | 108 def apply_adr_imm12(reloc, sym, section, reloc_value): |
111 U = 2 | 112 U = 2 |
112 if offset < 0: | 113 if offset < 0: |
113 offset = -offset | 114 offset = -offset |
114 U = 1 | 115 U = 1 |
115 assert offset < 4096 | 116 assert offset < 4096 |
117 offset = encode_imm32(offset) | |
116 section.data[reloc.offset+2] |= (U << 6) | 118 section.data[reloc.offset+2] |= (U << 6) |
117 section.data[reloc.offset+1] |= (offset >> 8) & 0xF | 119 section.data[reloc.offset+1] |= (offset >> 8) & 0xF |
118 section.data[reloc.offset+0] = offset & 0xFF | 120 section.data[reloc.offset+0] = offset & 0xFF |
119 | 121 |
120 @reloc('absaddr32') | 122 @reloc('absaddr32') |