from armasm to gnu arm assembler
salut !
fiquetma@ensieta.fr
Sun Apr 29 20:22:00 GMT 2007
Hello !
I have tried to translate a short code in armasm into a code in "gnu arm
assembler".
It compiles well with arm-elf-as.
Then, I have written a simple "HelloWorld" program in C, which also compiles
with arm-elf-gcc.
Now, I try to link them with arm-elf-ld and I have the following errors :
boot_code2.o(EXCEPTION_VECTORS+0xc4):boot_code2.s:84: undefined reference to
`$stack_pointer'
boot_code2.o(EXCEPTION_VECTORS+0xc8):boot_code2.s:84: undefined reference to
`SVC_STACK_TOP'
************************************************************************
The armasm code is the following :
; ARM processor modes.
SVC_MODE EQU 0x13
IRQ_MODE EQU 0x12
FIQ_MODE EQU 0x11
MACRO
proc_SwitchMode $mode, $stack_pointer
MRS R0, CPSR
MOV R1, R0
AND R1, R1, #0x1F ; Store the previous mode.
BIC R0, R0, #0x1F ; Clear the mode bits.
ORR R0, R0, #$mode ; Set the new mode bits.
MSR CPSR_csfx, R0 ; Set the processor mode.
LDR R13,=$stack_pointer ; Set the stack.
BIC R0, R0, #0x1F ; Clear the mode bits again.
ORR R0, R0, R1 ; Restore the mode.
MSR CPSR_csfx, R0 ; Set the processor mode back.
MEND
; Area definitions.
AREA EXCEPTION_VECTORS, CODE, READONLY
ENTRY
CODE32
IMPORT main
B ResetHandler
B UndefinedHandler
B SWIHandler
B PrefetchHandler
B AbortHandler
NOP
B IRQHandler
B FIQHandler
ResetHandler
; Switch the processor to the FIQ mode & set the stack pointer.
proc_SwitchMode FIQ_MODE, FIQ_STACK_TOP
; Switch the processor to the IRQ mode & set the stack pointer.
proc_SwitchMode IRQ_MODE, IRQ_STACK_TOP
; Switch the processor back to the SVC mode & set the stack pointer.
LDR R13, =SVC_STACK_TOP
Start
; Jump to the main program
BL main
TestEnd
B TestEnd
UndefinedHandler
B UndefinedHandler
SWIHandler
B SWIHandler
PrefetchHandler
B PrefetchHandler
AbortHandler
B AbortHandler
IRQHandler
STMDB R13!,{R0-R1}
LDR R0, =NumberOfIRQs
LDR R1, [R0]
ADD R1, R1, #0x1
STR R1, [R0]
LDMIA R13!,{R0-R1}
SUBS PC, R14, #0x4
FIQHandler
STMDB R13!,{R0-R1}
LDR R0, =NumberOfFIQs
LDR R1, [R0]
ADD R1, R1, #0x1
STR R1, [R0]
LDMIA R13!,{R0-R1}
SUBS PC, R14, #0x4
AREA |!!!!DSEG|, DATA, READWRITE
EXPORT MemoryErrors
EXPORT MemoryWordErrors
EXPORT MemoryHWordErrors
EXPORT MemoryByteErrors
EXPORT NumberOfIRQs
EXPORT NumberOfFIQs
MemoryErrors DCD 0
MemoryWordErrors DCD 0
MemoryHWordErrors DCD 0
MemoryByteErrors DCD 0
NumberOfIRQs DCD 0
NumberOfFIQs DCD 0
SPACE 232
AREA |!!!SVC_STACK|, DATA, READWRITE
SPACE 256
SVC_STACK_TOP
AREA |!!IRQ_STACK|, DATA, READWRITE
SPACE 256
IRQ_STACK_TOP
AREA |!FIQ_STACK|, DATA, READWRITE
SPACE 256
FIQ_STACK_TOP
END
*********************************************************************************
The "gnu arm assembler" code I have written is the following :
.extern main
.equ SVC_MODE, 0x13
.equ IRQ_MODE, 0x12
.equ FIQ_MODE, 0x11
.macro proc_SwitchMode $mode, $stack_pointer
MRS R0, CPSR
MOV R1, R0
AND R1, R1, #0x1F
BIC R0, R0, #0x1F
ORR R0, R0, #$mode
MSR CPSR_csfx, R0
LDR R13,=$stack_pointer
BIC R0, R0, #0x1F
ORR R0, R0, R1
MSR CPSR_csfx, R0
.endm
.section EXCEPTION_VECTORS
.code 32
main:
B ResetHandler
B UndefinedHandler
B SWIHandler
B PrefetchHandler
B AbortHandler
NOP
B IRQHandler
B FIQHandler
.global ResetHandler
ResetHandler:
proc_SwitchMode FIQ_MODE, FIQ_STACK_TOP
proc_SwitchMode IRQ_MODE, IRQ_STACK_TOP
LDR R13, =SVC_STACK_TOP
.global Start
Start:
BL main
.global TestEnd
TestEnd:
B TestEnd
.global UndefinedHandler
UndefinedHandler:
B UndefinedHandler
.global SWIHandler
SWIHandler:
B SWIHandler
.global PrefetchHandler
PrefetchHandler:
B PrefetchHandler
.global AbortHandler
AbortHandler:
B AbortHandler
.global IRQHandler
IRQHandler:
STMDB R13!,{R0-R1}
LDR R0, =NumberOfIRQs
LDR R1, [R0]
ADD R1, R1, #0x1
STR R1, [R0]
LDMIA R13!,{R0-R1}
SUBS PC, R14, #0x4
.global FIQHandler
FIQHandler:
STMDB R13!,{R0-R1}
LDR R0, =NumberOfFIQs
LDR R1, [R0]
ADD R1, R1, #0x1
STR R1, [R0]
LDMIA R13!,{R0-R1}
SUBS PC, R14, #0x4
.section DSEG, "w"
.global MemoryErrors
.global MemoryWordErrors
.global MemoryHWordErrors
.global MemoryByteErrors
.global NumberOfIRQs
.global NumberOfFIQs
MemoryErrors: .word 0
MemoryWordErrors: .word 0
MemoryHWordErrors: .word 0
MemoryByteErrors: .word 0
NumberOfIRQs: .word 0
NumberOfFIQs: .word 0
.space 232
.section SVC_STACK, "w"
.space 256
.global SVC_STACK_TOP
.section IRQ_STACK, "w"
.space 256
.global IRQ_STACK_TOP
.section FIQ_STACK, "w"
.space 256
.global FIQ_STACK_TOP
.end
I would be very grateful If someone could help me or just give me an advice.
Thank you in advance !
--
View this message in context: http://www.nabble.com/from-armasm-to-gnu-arm-assembler-tf3658251.html#a10221073
Sent from the gcc - cross compiler mailing list archive at Nabble.com.
--
For unsubscribe information see http://sourceware.org/lists.html#faq
More information about the crossgcc
mailing list