* fixed corrupted executables

* changed cprt0.as and prt0.as

git-svn-id: trunk@6553 -
This commit is contained in:
Legolas 2007-02-18 22:42:45 +00:00
parent d49a0979b4
commit 6912707e7d
4 changed files with 76 additions and 97 deletions

3
.gitignore vendored
View File

@ -1791,6 +1791,9 @@ rtl/freebsd/x86_64/*.ppu
rtl/freebsd/x86_64/*.s rtl/freebsd/x86_64/*.s
rtl/freebsd/x86_64/fpcmade.* rtl/freebsd/x86_64/fpcmade.*
rtl/freebsd/x86_64/units rtl/freebsd/x86_64/units
rtl/gba/backup
rtl/gba/build_rtl.bat
rtl/gba/build_rtl_EABI.bat
rtl/go32v2/*.bak rtl/go32v2/*.bak
rtl/go32v2/*.exe rtl/go32v2/*.exe
rtl/go32v2/*.o rtl/go32v2/*.o

View File

@ -11,15 +11,15 @@ _start:
b rom_header_end b rom_header_end
.fill 156,1,0 @ Nintendo Logo Character Data (8000004h) .fill 156,1,0 @ Nintendo Logo Character Data (8000004h)
.fill 16,1,0 @ Game Title .fill 16,1,0 @ Game Title
.byte 0x30,0x31 @ Maker Code (80000B0h) .byte 0x30,0x31 @ Maker Code (80000B0h)
.byte 0x96 @ Fixed Value (80000B2h) .byte 0x96 @ Fixed Value (80000B2h)
.byte 0x00 @ Main Unit Code (80000B3h) .byte 0x00 @ Main Unit Code (80000B3h)
.byte 0x00 @ Device Type (80000B4h) .byte 0x00 @ Device Type (80000B4h)
.fill 7,1,0 @ unused .fill 7,1,0 @ unused
.byte 0x00 @ Software Version No (80000BCh) .byte 0x00 @ Software Version No (80000BCh)
.byte 0xf0 @ Complement Check (80000BDh) .byte 0xf0 @ Complement Check (80000BDh)
.byte 0x00,0x00 @ Checksum (80000BEh) .byte 0x00,0x00 @ Checksum (80000BEh)
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
rom_header_end: rom_header_end:
@ -86,7 +86,7 @@ start_vector:
ldr r3, =__end__ @ last ewram address ldr r3, =__end__ @ last ewram address
sub r3, r2 @ r3= actual binary size sub r3, r2 @ r3= actual binary size
mov r6, r2 @ r6= 0x02000000 mov r6, r2 @ r6= 0x02000000
lsl r1, r2, #2 @ r1= 0x08000000 lsl r1, r2, #2 @ r1= 0x08000000
bl CopyMem bl CopyMem
@ -157,16 +157,6 @@ CIW0Skip:
bl CopyMemChk bl CopyMemChk
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Copy external work ram overlay 0 (ewram0 section) from LMA to VMA (ROM to RAM)
@---------------------------------------------------------------------------------
ldr r2, =__load_stop_ewram0
ldr r1, =__load_start_ewram0
sub r3, r2, r1 @ Is there any data to copy?
beq CEW0Skip @ no
ldr r2, =__ewram_overlay_start
bl CopyMem
@---------------------------------------------------------------------------------
CEW0Skip: CEW0Skip:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ set heap end @ set heap end
@ -177,7 +167,7 @@ CEW0Skip:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ global constructors @ global constructors
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ldr r3, =_init ldr r3, =__libc_init_array
bl _call_via_r3 bl _call_via_r3
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Jump to user code @ Jump to user code

View File

@ -11,36 +11,36 @@ _start:
b rom_header_end b rom_header_end
.fill 156,1,0 @ Nintendo Logo Character Data (8000004h) .fill 156,1,0 @ Nintendo Logo Character Data (8000004h)
.fill 16,1,0 @ Game Title .fill 16,1,0 @ Game Title
.byte 0x30,0x31 @ Maker Code (80000B0h) .byte 0x30,0x31 @ Maker Code (80000B0h)
.byte 0x96 @ Fixed Value (80000B2h) .byte 0x96 @ Fixed Value (80000B2h)
.byte 0x00 @ Main Unit Code (80000B3h) .byte 0x00 @ Main Unit Code (80000B3h)
.byte 0x00 @ Device Type (80000B4h) .byte 0x00 @ Device Type (80000B4h)
.fill 7,1,0 @ unused .fill 7,1,0 @ unused
.byte 0x00 @ Software Version No (80000BCh) .byte 0x00 @ Software Version No (80000BCh)
.byte 0xf0 @ Complement Check (80000BDh) .byte 0xf0 @ Complement Check (80000BDh)
.byte 0x00,0x00 @ Checksum (80000BEh) .byte 0x00,0x00 @ Checksum (80000BEh)
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
rom_header_end: rom_header_end:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
b start_vector @ This branch must be here for proper b start_vector @ This branch must be here for proper
@ positioning of the following header. @ positioning of the following header.
.GLOBAL __boot_method, __slave_number .GLOBAL __boot_method, __slave_number
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
__boot_method: __boot_method:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
.byte 0 @ boot method (0=ROM boot, 3=Multiplay boot) .byte 0 @ boot method (0=ROM boot, 3=Multiplay boot)
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
__slave_number: __slave_number:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
.byte 0 @ slave # (1=slave#1, 2=slave#2, 3=slave#3) .byte 0 @ slave # (1=slave#1, 2=slave#2, 3=slave#3)
.byte 0 @ reserved .byte 0 @ reserved
.byte 0 @ reserved .byte 0 @ reserved
.word 0 @ reserved .word 0 @ reserved
.word 0 @ reserved .word 0 @ reserved
.word 0 @ reserved .word 0 @ reserved
.word 0 @ reserved .word 0 @ reserved
.word 0 @ reserved .word 0 @ reserved
@ -54,12 +54,12 @@ start_vector:
mov r0, #0x4000000 @ REG_BASE mov r0, #0x4000000 @ REG_BASE
str r0, [r0, #0x208] str r0, [r0, #0x208]
mov r0, #0x12 @ Switch to IRQ Mode mov r0, #0x12 @ Switch to IRQ Mode
msr cpsr, r0 msr cpsr, r0
ldr sp, =__sp_irq @ Set IRQ stack ldr sp, =__sp_irq @ Set IRQ stack
mov r0, #0x1f @ Switch to System Mode mov r0, #0x1f @ Switch to System Mode
msr cpsr, r0 msr cpsr, r0
ldr sp, =__sp_usr @ Set user stack ldr sp, =__sp_usr @ Set user stack
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Enter Thumb mode @ Enter Thumb mode
@ -70,127 +70,116 @@ start_vector:
.thumb .thumb
ldr r0, =__text_start ldr r0, =__text_start
lsl r0, #5 @ Was code compiled at 0x08000000 or higher? lsl r0, #5 @ Was code compiled at 0x08000000 or higher?
bcs DoEWRAMClear @ yes, you can not run it in external WRAM bcs DoEWRAMClear @ yes, you can not run it in external WRAM
mov r0, pc mov r0, pc
lsl r0, #5 @ Are we running from ROM (0x8000000 or higher) ? lsl r0, #5 @ Are we running from ROM (0x8000000 or higher) ?
bcc SkipEWRAMClear @ No, so no need to do a copy. bcc SkipEWRAMClear @ No, so no need to do a copy.
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ We were started in ROM, silly emulators. :P @ We were started in ROM, silly emulators. :P
@ So we need to copy to ExWRAM. @ So we need to copy to ExWRAM.
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
mov r2, #2 mov r2, #2
lsl r2, r2, #24 @ r2= 0x02000000 lsl r2, r2, #24 @ r2= 0x02000000
ldr r3, =__end__ @ last ewram address ldr r3, =__end__ @ last ewram address
sub r3, r2 @ r3= actual binary size sub r3, r2 @ r3= actual binary size
mov r6, r2 @ r6= 0x02000000 mov r6, r2 @ r6= 0x02000000
lsl r1, r2, #2 @ r1= 0x08000000 lsl r1, r2, #2 @ r1= 0x08000000
bl CopyMem bl CopyMem
bx r6 @ Jump to the code to execute bx r6 @ Jump to the code to execute
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
DoEWRAMClear: @ Clear External WRAM to 0x00 DoEWRAMClear: @ Clear External WRAM to 0x00
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
mov r1, #0x40 mov r1, #0x40
lsl r1, #12 @ r1 = 0x40000 lsl r1, #12 @ r1 = 0x40000
lsl r0, r1, #7 @ r0 = 0x2000000 lsl r0, r1, #7 @ r0 = 0x2000000
bl ClearMem bl ClearMem
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
SkipEWRAMClear: @ Clear Internal WRAM to 0x00 SkipEWRAMClear: @ Clear Internal WRAM to 0x00
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@---------------------------------------------------------------------------------
@ Clear BSS section to 0x00 @---------------------------------------------------------------------------------
@--------------------------------------------------------------------------------- @ Clear BSS section to 0x00
@---------------------------------------------------------------------------------
ldr r0, =__bss_start ldr r0, =__bss_start
ldr r1, =__bss_end ldr r1, =__bss_end
sub r1, r0 sub r1, r0
bl ClearMem bl ClearMem
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Clear SBSS section to 0x00 @ Clear SBSS section to 0x00
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ldr r0, =__sbss_start ldr r0, =__sbss_start
ldr r1, =__sbss_end ldr r1, =__sbss_end
sub r1, r0 sub r1, r0
bl ClearMem bl ClearMem
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Copy initialized data (data section) from LMA to VMA (ROM to RAM) @ Copy initialized data (data section) from LMA to VMA (ROM to RAM)
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ldr r1, =__data_lma ldr r1, =__data_lma
ldr r2, =__data_start ldr r2, =__data_start
ldr r4, =__data_end ldr r4, =__data_end
bl CopyMemChk bl CopyMemChk
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Copy internal work ram (iwram section) from LMA to VMA (ROM to RAM) @ Copy internal work ram (iwram section) from LMA to VMA (ROM to RAM)
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ldr r1,= __iwram_lma ldr r1,= __iwram_lma
ldr r2,= __iwram_start ldr r2,= __iwram_start
ldr r4,= __iwram_end ldr r4,= __iwram_end
bl CopyMemChk bl CopyMemChk
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Copy internal work ram overlay 0 (iwram0 section) from LMA to VMA (ROM to RAM) @ Copy internal work ram overlay 0 (iwram0 section) from LMA to VMA (ROM to RAM)
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ldr r2,= __load_stop_iwram0 ldr r2,= __load_stop_iwram0
ldr r1,= __load_start_iwram0 ldr r1,= __load_start_iwram0
sub r3, r2, r1 @ Is there any data to copy? sub r3, r2, r1 @ Is there any data to copy?
beq CIW0Skip @ no beq CIW0Skip @ no
ldr r2,= __iwram_overlay_start ldr r2,= __iwram_overlay_start
bl CopyMem bl CopyMem
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
CIW0Skip: CIW0Skip:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@--------------------------------------------------------------------------------- @ Copy external work ram (ewram section) from LMA to VMA (ROM to RAM)
@ Copy external work ram (ewram section) from LMA to VMA (ROM to RAM) @---------------------------------------------------------------------------------
@---------------------------------------------------------------------------------
ldr r1, =__ewram_lma ldr r1, =__ewram_lma
ldr r2, =__ewram_start ldr r2, =__ewram_start
ldr r4, =__ewram_end ldr r4, =__ewram_end
bl CopyMemChk bl CopyMemChk
@---------------------------------------------------------------------------------
@ Copy external work ram overlay 0 (ewram0 section) from LMA to VMA (ROM to RAM)
@---------------------------------------------------------------------------------
ldr r2, =__load_stop_ewram0
ldr r1, =__load_start_ewram0
sub r3, r2, r1 @ Is there any data to copy?
beq CEW0Skip @ no
ldr r2, =__ewram_overlay_start
bl CopyMem
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
CEW0Skip: CEW0Skip:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@--------------------------------------------------------------------------------- @ set heap end
@ Jump to user code @---------------------------------------------------------------------------------
@--------------------------------------------------------------------------------- ldr r1, =fake_heap_end
mov r0,#0 @ int argc ldr r0, =__eheap_end
mov r1,#0 @ char *argv[] str r0, [r1]
@---------------------------------------------------------------------------------
@ Jump to user code
@---------------------------------------------------------------------------------
mov r0, #0 @ int argc
mov r1, #0 @ char *argv[]
ldr r3,=main ldr r3,=main
bx r3 bx r3
nop @ This nop is here to allow unmapped memory to be used as nop @ This nop is here to allow unmapped memory to be used as
@ as a delay of almost 1 sec with a 1 cycle resolution. @ as a delay of almost 1 sec with a 1 cycle resolution.
@ Read this for technical info: @ Read this for technical info:
@ http://www.devrs.com/gba/files/gbadevfaqs.php#RepeatUses @ http://www.devrs.com/gba/files/gbadevfaqs.php#RepeatUses
@---------------------------------------------------------------------------------
@--------------------------------------------------------------------------------- @ Clear memory to 0x00 if length != 0
@ Clear memory to 0x00 if length != 0 @---------------------------------------------------------------------------------
@--------------------------------------------------------------------------------- @ r0 = Start Address
@ r0 = Start Address @ r1 = Length
@ r1 = Length
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ClearMem: ClearMem:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ -201,14 +190,12 @@ ClearMem:
beq ClearMX @ Length is zero so exit beq ClearMX @ Length is zero so exit
mov r2,#0 mov r2,#0
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ClrLoop: ClrLoop:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
stmia r0!, {r2} stmia r0!, {r2}
sub r1,#4 sub r1,#4
bne ClrLoop bne ClrLoop
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
ClearMX: ClearMX:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ -224,7 +211,6 @@ ClearMX:
CopyMemChk: CopyMemChk:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
sub r3, r4, r2 @ Is there any data to copy? sub r3, r4, r2 @ Is there any data to copy?
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ Copy memory @ Copy memory
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
@ -246,7 +232,6 @@ CIDLoop:
stmia r2!, {r0} stmia r2!, {r0}
sub r3, #4 sub r3, #4
bne CIDLoop bne CIDLoop
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------
CIDExit: CIDExit:
@--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------

View File

@ -162,6 +162,7 @@ begin
fake_heap_end := pchar(0); fake_heap_end := pchar(0);
{ Set up signals handlers } { Set up signals handlers }
fpc_cpucodeinit;
{ Setup heap } { Setup heap }
InitHeap; InitHeap;
SysInitExceptions; SysInitExceptions;