This commit is contained in:
Ian Martin 2014-01-04 17:38:26 -05:00
commit d0abf415e7
3 changed files with 639 additions and 0 deletions

224
cpu/rl78/R5F100xL.ld Normal file
View file

@ -0,0 +1,224 @@
/*
Copyright (c) 2005,2008,2009,2011 Red Hat Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
The name of Red Hat Incorporated may not be used to endorse
or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Default linker script, for normal executables */
OUTPUT_ARCH(rl78)
ENTRY(_start)
/* Do we need any of these for elf?
__DYNAMIC = 0; */
/* This is for an RL78/G13, 64k flash, 4k ram */
MEMORY {
VEC (r) : ORIGIN = 0x00000, LENGTH = 0x00002
IVEC (r) : ORIGIN = 0x00004, LENGTH = 0x0007c
OPT (r) : ORIGIN = 0x000c0, LENGTH = 0x00004
ROM (r) : ORIGIN = 0x000d8, LENGTH = 0x0ff28
RAM (w) : ORIGIN = 0xfef00, LENGTH = 0x00fe0
STACK (w) : ORIGIN = 0xffee0, LENGTH = 0x00002
}
SECTIONS
{
.vec :
{
*(.vec)
} > VEC
.ivec :
{
*(.ivec)
} > IVEC
.opt :
{
*(.opt)
} > OPT
/* CubeSuite always starts at 0xd8. */
.csstart : {
*(.csstart)
} > ROM
/* For code that must be in the first 64k, or could fill unused
space below .rodata. */
.lowtext : {
*(.plt)
*(.lowtext)
} > ROM
.data : {
. = ALIGN(2);
PROVIDE (__datastart = .);
KEEP (*(.jcr))
*(.data.rel.ro.local) *(.data.rel.ro*)
*(.dynamic)
*(.data D .data.* .gnu.linkonce.d.*)
KEEP (*(.gnu.linkonce.d.*personality*))
SORT(CONSTRUCTORS)
*(.data1)
*(.got.plt) *(.got)
/* We want the small data sections together, so single-instruction offsets
can access them all, and initialized data all before uninitialized, so
we can shorten the on-disk segment size. */
. = ALIGN(2);
*(.sdata .sdata.* .gnu.linkonce.s.* D_2 D_1)
. = ALIGN(2);
_edata = .;
PROVIDE (edata = .);
PROVIDE (__dataend = .);
} > RAM AT> ROM
/* Note that crt0 assumes this is a multiple of two; all the
start/stop symbols are also assumed word-aligned. */
PROVIDE(__romdatastart = LOADADDR(.data));
PROVIDE (__romdatacopysize = SIZEOF(.data));
.bss : {
. = ALIGN(2);
PROVIDE (__bssstart = .);
*(.dynbss)
*(.sbss .sbss.*)
*(.bss B B_2 B_1 .bss.* .gnu.linkonce.b.*)
. = ALIGN(2);
*(COMMON)
. = ALIGN(2);
PROVIDE (__bssend = .);
_end = .;
PROVIDE (end = .);
} > RAM
PROVIDE (__bsssize = SIZEOF(.bss));
.stack (ORIGIN (STACK)) :
{
PROVIDE (__stack = .);
*(.stack)
}
.rodata (MAX(__romdatastart + __romdatacopysize, 0x2000)) : {
. = ALIGN(2);
*(.plt)
*(.rodata C C_2 C_1 .rodata.* .gnu.linkonce.r.*)
*(.rodata1)
*(.eh_frame_hdr)
KEEP (*(.eh_frame))
KEEP (*(.gcc_except_table)) *(.gcc_except_table.*)
PROVIDE (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE (__preinit_array_end = .);
PROVIDE (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE (__init_array_end = .);
PROVIDE (__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE (__fini_array_end = .);
LONG(0); /* Sentinel. */
/* gcc uses crtbegin.o to find the start of the constructors, so
we make sure it is first. Because this is a wildcard, it
doesn't matter if the user does not actually link against
crtbegin.o; the linker won't look for a file to match a
wildcard. The wildcard also means that it doesn't matter which
directory crtbegin.o is in. */
KEEP (*crtbegin*.o(.ctors))
/* We don't want to include the .ctor section from from the
crtend.o file until after the sorted ctors. The .ctor section
from the crtend file contains the end of ctors marker and it
must be last */
KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
KEEP (*crtbegin*.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} > ROM
.text :
{
PROVIDE (_start = .);
*(.text P .stub .text.* .gnu.linkonce.t.*)
KEEP (*(.text.*personality*))
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
*(.interp .hash .dynsym .dynstr .gnu.version*)
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(2);
KEEP (*(.init))
KEEP (*(.fini))
} > ROM
/* The rest are all not normally part of the runtime image. */
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.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) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/DISCARD/ : { *(.note.GNU-stack) }
}

331
cpu/rl78/crt0.S Normal file
View file

@ -0,0 +1,331 @@
/* Copyright (c) 2011 Red Hat Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
The name of Red Hat Incorporated may not be used to endorse
or promote products derived from this software without specific
prior written permission.
This software is provided by the copyright holders and contributors
"AS IS" and any express or implied warranties, including, but not
limited to, the implied warranties of merchantability and fitness for
a particular purpose are disclaimed. In no event shall Red Hat
incorporated be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage. */
#include "rl78-sys.h"
.section ".vec","a"
.short _start
.section ".ivec","a"
.macro _iv x
.weak \x
.short \x
.endm
#define IV(x) _iv _##x##_handler
#define IVx() .short 0
/* To use a vector, simply define a global function named foo_handler()
for any IV(foo) listed below (i.e. tm05_handler) */
.global _interrupt_vector_table
_interrupt_vector_table:
IV(wdti)
IV(lvi)
IV(p0)
IV(p1)
IV(p2)
IV(p3)
IV(p4)
IV(p5)
IV(st2)
IV(sr2)
IV(sre2)
IV(dma0)
IV(dma1)
IV(st0)
IV(sr0)
IV(tm01h)
IV(st1)
IV(sr1)
IV(sre1)
IV(iica0)
IV(tm00)
IV(tm01)
IV(tm02)
IV(tm03)
IV(ad)
IV(rtc)
IV(it)
IV(kr)
IV(st3)
IV(sr3)
IV(tm13)
IV(tm04)
IV(tm05)
IV(tm06)
IV(tm07)
IV(p6)
IV(p7)
IV(p8)
IV(p9)
IV(p10)
IV(p11)
IV(tm10)
IV(tm12)
IV(sre3)
IV(tm13h)
IV(md)
IV(iica1)
IV(fl)
IV(dma2)
IV(dma3)
IV(tm14)
IV(tm15)
IV(tm16)
IV(tm17)
IVx()
IVx()
IVx()
IVx()
IVx()
IVx()
IVx()
IV(brk)
/* Note: 126 vectors */
.section ".csstart", "ax"
.global __csstart
__csstart:
br !!_start
.weak __rl78_option_byte_0
.weak __rl78_option_byte_1
.weak __rl78_option_byte_2
.weak __rl78_option_byte_3
__rl78_option_byte_0 = 0x6e
__rl78_option_byte_1 = 0xff
__rl78_option_byte_2 = 0xe8
__rl78_option_byte_3 = 0x85
.section ".opt", "a"
.byte __rl78_option_byte_0
.byte __rl78_option_byte_1
.byte __rl78_option_byte_2
.byte __rl78_option_byte_3
.text
.global _start
.type _start, @function
_start:
movw sp, #__stack
;; block move to initialize .data
;; we're copying from 00:[_romdatastart] to 0F:[_datastart]
;; and our data is not in the mirrored area.
mov es, #0
sel rb0 ; bank 0
movw hl, #__datastart
movw de, #__romdatastart
sel rb1 ; bank 1
movw ax, #__romdatacopysize
shrw ax,1
1:
cmpw ax, #0
bz $1f
decw ax
sel rb0 ; bank 0
movw ax, es:[de]
movw [hl], ax
incw de
incw de
incw hl
incw hl
sel rb1
br $1b
1:
sel rb0 ; bank 0
;; block fill to .bss
sel rb0 ; bank 0
movw hl, #__bssstart
movw ax, #0
sel rb1 ; bank 1
movw ax, #__bsssize
shrw ax,1
1:
cmpw ax, #0
bz $1f
decw ax
sel rb0 ; bank 0
movw [hl], ax
incw hl
incw hl
sel rb1
br $1b
1:
sel rb0 ; bank 0
call !!__rl78_init
#ifdef PROFILE_SUPPORT /* Defined in gcrt0.S. */
movw ax, # _start
push ax
movw ax, # _etext
push ax
call !!__monstartup
#endif
movw ax, #0
push ax /* envp */
push ax /* argv */
push ax /* argc */
call !!_main
.LFE2:
movw ax, r8 ; Save return code.
push ax
#ifdef PROFILE_SUPPORT
call !!__mcleanup
#endif
call !!_exit
.size _start, . - _start
.global _rl78_run_preinit_array
.type _rl78_run_preinit_array,@function
_rl78_run_preinit_array:
movw hl, #__preinit_array_start
movw de, #__preinit_array_end
movw bc, #-2
br $_rl78_run_inilist
.global _rl78_run_init_array
.type _rl78_run_init_array,@function
_rl78_run_init_array:
movw hl, #__init_array_start
movw de, #__init_array_end
movw bc, #2
br $_rl78_run_inilist
.global _rl78_run_fini_array
.type _rl78_run_fini_array,@function
_rl78_run_fini_array:
movw hl, #__fini_array_start
movw de, #__fini_array_end
movw bc, #-2
/* fall through */
;; HL = start of list
;; DE = end of list
;; BC = step direction (+2 or -2)
_rl78_run_inilist:
next_inilist:
movw ax, hl
cmpw ax, de
bz $done_inilist
movw ax, [hl]
cmpw ax, #-1
bz $skip_inilist
cmpw ax, #0
bz $skip_inilist
push ax
push bc
push de
push hl
call ax
pop hl
pop de
pop bc
pop ax
skip_inilist:
movw ax, hl
addw ax, bc
movw hl, ax
br $next_inilist
done_inilist:
ret
.section .init,"ax"
.global __rl78_init
__rl78_init:
.section .fini,"ax"
.global __rl78_fini
__rl78_fini:
call !!_rl78_run_fini_array
.section .data
.global ___dso_handle
.weak ___dso_handle
___dso_handle:
.long 0
;;; Provide Dwarf unwinding information that will help GDB stop
;;; backtraces at the right place. This is stolen from assembly
;;; code generated by GCC with -dA.
.section .debug_frame,"",@progbits
.Lframe0:
.4byte .LECIE0-.LSCIE0 ; Length of Common Information Entry
.LSCIE0:
.4byte 0xffffffff ; CIE Identifier Tag
.byte 0x1 ; CIE Version
.ascii "\0" ; CIE Augmentation
.uleb128 0x1 ; CIE Code Alignment Factor
.sleb128 -1 ; CIE Data Alignment Factor
.byte 0xd ; CIE RA Column
.byte 0xc ; DW_CFA_def_cfa
.uleb128 0xc
.uleb128 0x3
.byte 0x8d ; DW_CFA_offset, column 0xd
.uleb128 0x3
.p2align 2
.LECIE0:
.LSFDE0:
.4byte .LEFDE0-.LASFDE0 ; FDE Length
.LASFDE0:
.4byte .Lframe0 ; FDE CIE offset
.4byte _start ; FDE initial location
.4byte .LFE2 - _start ; FDE address range
.byte 0xf ; DW_CFA_def_cfa_expression
.uleb128 1 ; length of expression
.byte 0x30 ; DW_OP_lit0
.p2align 2
.LEFDE0:
.text

84
cpu/rl78/rl78-sys.h Normal file
View file

@ -0,0 +1,84 @@
/*
Copyright (c) 2011 Red Hat Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
The name of Red Hat Incorporated may not be used to endorse
or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "syscall.h"
r8 = 0xffef0
r9 = 0xffef1
r10 = 0xffef2
r11 = 0xffef3
r12 = 0xffef4
r13 = 0xffef5
r14 = 0xffef6
r15 = 0xffef7
r16 = 0xffee8
r17 = 0xffee9
r18 = 0xffeea
r19 = 0xffeeb
r20 = 0xffeec
r21 = 0xffeed
r22 = 0xffeee
r23 = 0xffeef
#define SYS__exit SYS_exit
.macro syscall_body number
/* The RL78 doesn't really have an "interrupt" upcode, just
BRK, which we emulate exactly. We use the STOP opcode,
which is a breakpoint in the simulator. */
mov A, #\number
stop
ret
.endm
.macro do_syscall name number
__\name:
.global __\name
_\name:
.weak _\name
syscall_body \number
.endm
.macro syscall_returns name number
__\name:
.global __\name
_\name:
.weak _\name
mov r8, #\number
ret
.endm
#define S(name) do_syscall name, SYS_##name
#define SYSCALL(number) syscall_body number
#define ERR(name) syscall_returns name, -1
#define OK(name) syscall_returns name, 0
#define RET(name,val) syscall_returns name, val