Witam probuje skompilowac napisany uprzednio i dzialajacy program do RAMu. Niestety nie dziala mi obsluga wyjatkow(prawdopodbnie chodzi o remap wektorow jednak nie udalo mi sie znalezc informacji jak tego dokonac dla tego konkretnego procesora) oraz funkcja atoi(po przejzeniu objdumpa wydaje sie znajdowac pod wlasciwym adresem:/).
Zastosowany plik startupu:
Skrypt Linkera:
Makefile:
Zastosowany plik startupu:
#*************************************************************************
# *** STR912 Startup Code For GNU Tools (executed after Reset) ***
#*************************************************************************
#
# *** Startup Code (executed after Reset) ***
#
# Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
.equ Mode_USR, 0x10
.equ Mode_FIQ, 0x11
.equ Mode_IRQ, 0x12
.equ Mode_SVC, 0x13
.equ Mode_ABT, 0x17
.equ Mode_UND, 0x1B
.equ Mode_SYS, 0x1F
.equ I_BIT, 0x80 /* when I bit is set, IRQ is disabled */
.equ F_BIT, 0x40 /* when F bit is set, FIQ is disabled */
# System Memory definitions
.equ RAM_Size, 0x00018000 /* 96K */
.equ RAM_Base, 0x04000000
.equ SCRO_AHB_UNB, 0x5C002034
# Stack definitions
.equ Top_Stack, 0x04018000
.equ UND_Stack_Size, 0x00000004
.equ SVC_Stack_Size, 0x00000100
.equ ABT_Stack_Size, 0x00000004
.equ FIQ_Stack_Size, 0x00000004
.equ IRQ_Stack_Size, 0x00000100
.equ USR_Stack_Size, 0x00001000
# STARTUP EXECUTABLE CODE
.text
.arm
.section .vectrom, "ax"
.extern main
.global _app_entry
.global _startup
.func _startup
_startup:
# Exception Vectors
Vectors:
LDR PC, Reset_Addr
LDR PC, Undef_Addr
LDR PC, SWI_Addr
LDR PC, PAbt_Addr
LDR PC, DAbt_Addr
NOP
LDR PC, [PC, #-0xFF0]
LDR PC, FIQ_Addr
# Interrupt Vectors
Reset_Addr: .word Hard_Reset
Undef_Addr: .word Undefined_Handler
SWI_Addr: .word SWI_Handler
PAbt_Addr: .word Prefetch_Handler
DAbt_Addr: .word Abort_Handler
.word 0 /* Reserved Address */
IRQ_Addr: .word IRQ_Handler
FIQ_Addr: .word FIQ_Handler
//Undef_Handler: B Undef_Handler
//SWI_Handler: B SWI_Handler
//PAbt_Handler: B PAbt_Handler
//DAbt_Handler: B DAbt_Handler
IRQ_Handler: B IRQ_Handler
FIQ_Handler: B FIQ_Handler
# Reset Handler Entry Point
Hard_Reset:
_app_entry:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
# Setup Flash Memory Interface (FMI)
# FMI_BBSR - 512 kB boot flash:
ldr r6, =0x54000000
ldr r7, =0x4
str r7, [r6]
# FMI_NBBSR - 32 kB non boot flash:
ldr r6, =0x54000004
ldr r7, =0x2
str r7, [r6]
# FMI_BBADR - boot flash base address:
ldr r6, =0x5400000C
ldr r7, =0x00000000
str r7, [r6]
# FMI_NBBADR - non boot flash base address:
ldr r6, =0x54000010
ldr r7, =0x00020000
str r7, [r6]
# FMI_CR - Flash Bank 0 enable, Flash Bank 1 enable, 1 cycle Write wait states
ldr r6, =0x54000018
ldr r7, =0x18
str r7, [r6]
# Setup SRAM Size Enable 96K RAM
nop
nop
nop
ldr r0, = SCRO_AHB_UNB
ldr r1, = 0x0196
str r1, [r0]
nop
nop
# Compiler Runtime Environment Setup
# Note: R13 = SP
// Setup stack pointers
LDR R0, =Top_Stack
// Enter Undefined Instruction Mode and set its Stack Pointer
MSR CPSR_c, #Mode_UND|I_BIT|F_BIT
MOV SP, R0
SUB R0, R0, #UND_Stack_Size
// Enter Abort Mode and set its Stack Pointer
MSR CPSR_c, #Mode_ABT|I_BIT|F_BIT
MOV SP, R0
SUB R0, R0, #ABT_Stack_Size
// Enter FIQ Mode and set its Stack Pointer
MSR CPSR_c, #Mode_FIQ|I_BIT|F_BIT
MOV SP, R0
SUB R0, R0, #FIQ_Stack_Size
// Enter IRQ Mode and set its Stack Pointer
MSR CPSR_c, #Mode_IRQ|I_BIT|F_BIT
MOV SP, R0
SUB R0, R0, #IRQ_Stack_Size
// Enter Supervisor Mode and set its Stack Pointer
MSR CPSR_c, #Mode_SVC|I_BIT|F_BIT
MOV SP, R0
SUB R0, R0, #SVC_Stack_Size
// Enter User/Sys Mode and set its Stack Pointer
MSR CPSR_c, #Mode_SYS|I_BIT|F_BIT
MOV SP, R0
SUB R0, R0, #USR_Stack_Size
// Enter User Mode and set its Stack Pointer
MSR CPSR_c, #Mode_SYS|I_BIT|F_BIT
MOV SP, R0
// Setup a default Stack Limit (when compiled with "-mapcs-stack-check")
SUB SL, SP, #USR_Stack_Size
# Set bits 17-18 of the Core Configuration Control Register
mov r0, #0x60000
mcr p15,0x1,r0,c15,c1,0
# Initialise RAM For Compiler Variables
# Relocate .data section (Copy from ROM to RAM)
# LDR R1, =_etext
# LDR R2, =_data
# LDR R3, =_edata
#LoopRel: CMP R2, R3
# LDRLO R0, [R1], #4
# STRLO R0, [R2], #4
# BLO LoopRel
# Clear .bss section
MOV R0, #0
LDR R1, =__bss_start__
LDR R2, =__bss_end__
LoopZI: CMP R1, R2
STRLO R0, [R1], #4
BLO LoopZI
# Enter the C code
# Jump to main()
B main
.size _startup, . - _startup
.endfunc
.end
Skrypt Linkera:
/*** Linker Script File ***/
/* Hitex/Gn/07.09.2006 */
/* Memory Definitions */
/* STR912 */
/*******************************************
Define Files
*******************************************/
/*******************************************
Memory Definitions
*******************************************/
/* RAM usage */
MEMORY
{
/*IntCodeRAM (rx) : ORIGIN = 0x40000000, LENGTH = 0x00003000*/
IntCodeRAM (rx) : ORIGIN = 0x40000000, LENGTH = 0x00010000
/*IntDataRAM (rw) : ORIGIN = 0x40003000, LENGTH = 0x00001000*/
IntDataRAM (rw) : ORIGIN = 0x40010000, LENGTH = 0x00010000
}
/*******************************************
Section Definitions
*******************************************/
SECTIONS
{
/*******************************************/
.text :
{
__code_start__ = .;
KEEP(*(.vectrom))
*(.text .text.*)
. = ALIGN(4);
__code_end__ = .;
*(.glue_7t) *(.glue_7)
} >IntCodeRAM =0
/* .rodata section which is used for read-only data (constants) */
.rodata . :
{
*(.rodata)
} >IntCodeRAM
. = ALIGN(4);
_etext = . ;
PROVIDE (etext = .);
/*******************************************/
.data : AT (_etext)
{
/* used for initialized data */
__data_start__ = . ;
PROVIDE (__data_start__ = .) ;
*(.data)
SORT(CONSTRUCTORS)
__data_end__ = . ;
PROVIDE (__data_end__ = .) ;
} >IntDataRAM
. = ALIGN(4);
_edata = . ;
PROVIDE (edata = .);
/*******************************************/
.bss :
{
/* used for uninitialized data */
__bss_start = . ;
__bss_start__ = . ;
*(.bss)
. = ALIGN(4);
__bss_end__ = . ;
} >IntDataRAM
.bss2 :
{
/* used for uninitialized data */
__bss2_start = . ;
__bss2_start__ = . ;
*(COMMON)
. = ALIGN(4);
__bss2_end__ = . ;
} >IntDataRAM
/*******************************************/
_end = .;
PROVIDE (end = .);
/*******************************************/
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
}
Makefile:
FLAGS = -Wall -Os -mcpu=arm966e-s
CFLAGS = $(FLAGS) -g -std=gnu99 -DPDEBUG -I ./ -I inc/ -I inc/91x_lib/ -DVECTORS_IN_RAM
ASFLAGS = -c -Wa,-mapcs-32 -mcpu=arm966e-s -gstabs -DVECTORS_IN_RAM
LDFLAGS = -Wall -I ./ -I inc/ -I inc/91x_lib/ -Os -mcpu=arm966e-s -g -DPDEBUG
OBJS = $(patsubst %.S,%.o,$(wildcard src/*.S)) $(patsubst %.c,%.o,$(wildcard src/*.c))
BIN = przerwania.bin
ELF = $(patsubst %.bin,%.elf,$(BIN))
all : $(OBJS)
arm-none-eabi-c++ $(LDFLAGS) $(OBJS) -o obj/$(ELF) -nostartfiles -T cfg/STR912-RAM.ld -Wl,-Map=lst/linker.map,--cref -g -DPDEBUG
arm-none-eabi-objcopy -O binary -S obj/$(ELF) bin/$(BIN)
%.o : %.S
arm-none-eabi-gcc $(ASFLAGS) $< -o $@
%.o : %.c
arm-none-eabi-gcc -c $(CFLAGS) $< -o $@
clean:
rm -rf src/*.o obj/*.elf bin/*.bin lst/*.map