Skip to content

Commit

Permalink
arc64: Add initial support of Synopsys ARCv3 targets
Browse files Browse the repository at this point in the history
Synopsys ARCv3 architecture includes 32-bit ARC HS5x cores and
64-bit ARC HS6x cores.

Note that libgloss for ARCv3 shares the same code base as
for ARCv1/2 targets. Thus, Makefile.inc for libgloss uses
sources from libgloss/arc directory except crtX.S files.

Co-authored-by: Shahab Vahedi <shahab@synopsys.com>
Co-authored-by: Claudiu Zissulescu <claziss@gmail.com>
Co-authored-by: Bruno Mauricio <brunoasmauricio@gmail.com>
Co-authored-by: Luis Silva <luis.m.silva99@hotmail.com>
Signed-off-by: Yuriy Kolerov <kolerov93@gmail.com>
  • Loading branch information
5 people committed May 29, 2024
1 parent 313ea5f commit 37c8623
Show file tree
Hide file tree
Showing 29 changed files with 3,359 additions and 9 deletions.
4 changes: 2 additions & 2 deletions config.guess
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Attempt to guess a canonical system name.
# Copyright 1992-2021 Free Software Foundation, Inc.

timestamp='2021-01-25'
timestamp='2024-05-24'

# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -949,7 +949,7 @@ EOF
if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
exit ;;
arc:Linux:*:* | arceb:Linux:*:*)
arc:Linux:*:* | arceb:Linux:*:* | arc64:Linux:*:*)
echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
exit ;;
arm*:Linux:*:*)
Expand Down
4 changes: 2 additions & 2 deletions config.sub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Configuration validation subroutine script.
# Copyright 1992-2021 Free Software Foundation, Inc.

timestamp='2021-01-08'
timestamp='2024-05-24'

# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1165,7 +1165,7 @@ case $cpu-$vendor in
| alphapca5[67] | alpha64pca5[67] \
| am33_2.0 \
| amdgcn \
| arc | arceb \
| arc | arceb | arc64 | arc32 \
| arm | arm[lb]e | arme[lb] | armv* \
| avr | avr32 \
| asmjs \
Expand Down
3 changes: 3 additions & 0 deletions libgloss/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ endif
if CONFIG_ARC
include arc/Makefile.inc
endif
if CONFIG_ARC64
include arc64/Makefile.inc
endif
if CONFIG_ARM
include arm/Makefile.inc
endif
Expand Down
44 changes: 44 additions & 0 deletions libgloss/arc64/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
multilibtool_LIBRARIES += %D%/libnsim.a
%C%_libnsim_a_CPPFLAGS = -I$(srcdir)/arc
%C%_libnsim_a_SOURCES = \
arc/libcfunc.c \
arc/nsim-syscalls.c \
arc/sbrk.c

multilibtool_LIBRARIES += %D%/libhl.a
%C%_libhl_a_CFLAGS = -mvolatile-di
%C%_libhl_a_CPPFLAGS = -I$(srcdir)/arc
%C%_libhl_a_SOURCES = \
arc/arc-timer.c \
arc/hl-stub.c \
arc/hl-setup.c \
arc/libcfunc.c \
arc/sbrk.c \
arc/hl/hl_gw.c \
arc/hl/hl_api.c \
arc/hl/hl_open.c \
arc/hl/hl_close.c \
arc/hl/hl_read.c \
arc/hl/hl_write.c \
arc/hl/hl_lseek.c \
arc/hl/hl_unlink.c \
arc/hl/hl_isatty.c \
arc/hl/hl_clock.c \
arc/hl/hl_gettimeofday.c \
arc/hl/hl_argc.c \
arc/hl/hl_argv.c \
arc/hl/hl_exit.c

multilibtool_DATA += \
%D%/crt0.o \
%D%/crtn.o \
%D%/crti.o \
arc/arc-main-helper.o \
arc/nsim.specs \
arc/hl.specs

libobjs_a_SOURCES += \
%D%/crt0.S \
%D%/crtn.S \
%D%/crti.S \
arc/arc-main-helper.c
123 changes: 123 additions & 0 deletions libgloss/arc64/asm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
Copyright (c) 2024, Synopsys, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) 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.
3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/

#ifndef _ARC64_ASM_H
#define _ARC64_ASM_H

#if defined (__ARC64_ARCH32__)

/* Define 32-bit word. */
.macro WORD w
.word \w
.endm

/* Move register immediate (short): r:reg, i:immediate */
.macro MOVRI_S r, i
mov_s \r, \i
.endm

/* Move register immediate (short): r:reg, ri:reg/immediate */
.macro MOVR_S r, ri
mov_s \r, \ri
.endm

/* Move register immediate: r:reg, ri:reg/immediate */
.macro MOVR r, ri
mov \r, \ri
.endm

/* Push register: r:reg */
.macro PUSHR r
push \r
.endm

/* Pop register: r:reg */
.macro POPR r
pop \r
.endm

/* Subtract register: r1(reg), r2(reg), r3(reg) */
.macro SUBR r1, r2, r3
sub \r1, \r2, \r3
.endm

/* Add PCL-rel: r:reg, symb: symbol */
.macro ADDPCL r,symb
add \r, pcl, \symb
.endm

#elif defined (__ARC64_ARCH64__)

/* Define 64-bit word. */
.macro WORD w
.xword \w
.endm

/* Move immediate (short): r:reg, i:immediate */
.macro MOVRI_S r, i
movhl_s \r, \i
orl_s \r, \r, \i
.endm

/* Move register immediate (short): r:reg, ri:reg/immediate */
.macro MOVR_S r, ri
movl_s \r, \ri
.endm

/* Move register immediate: r:reg, ri:reg/immediate */
.macro MOVR r, ri
movl \r, \ri
.endm

/* Push register: r:reg */
.macro PUSHR r
pushl_s \r
.endm

/* Pop register: r:reg */
.macro POPR r
popl_s \r
.endm

/* Subtract register: r1(reg), r2(reg), r3(reg) */
.macro SUBR r1, r2, r3
subl \r1, \r2, \r3
.endm

/* Add PCL-rel: r:reg, symb: symbol */
.macro ADDPCL r, symb
addl \r, pcl, \symb@pcl
.endm

#else /* !__ARC64_ARC32__ && !__ARC64_ARC64__ */
# error Please use either 32-bit or 64-bit version of arc64 compiler
#endif

#endif /* _ARC64_ASM_H */
160 changes: 160 additions & 0 deletions libgloss/arc64/crt0.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
Copyright (c) 2024, Synopsys, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) 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.
3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/

/*
The startup code for the ARC family of processors does the following before
transferring control to user defined main label:
1. Set sp to __stack_top (link time variable)
2. Zero out the bss section (for uninitialized globals)
After returning from main, the processor is halted and the pipeline is
flushed out.
*/

#include "asm.h"
#include "../arc/arc-symbols.h"

.macro initfp from=0, to=31
fmvi2s f0+\from,r0
.if \to-\from
initfp "(\from+1)",\to
.endif
.endm

.extern main

.section .text.__startup, "ax", @progbits
.global __start
.type __start, @function
.align 4
__start:
MOVRI_S sp, STACK_TOP ; Stack address

; Allow unaligned accesses.
lr r2, [0xA]
bset r2, r2, 19
flag r2

;;; Clear the bss segment.
MOVRI_S r0, SMALL_DATA_BSS_START ; r0 = start of the bss section
MOVRI_S r2, SMALL_DATA_BSS_END
SUBR r2, r2, r0 ; r2 = size of the bss section in bytes
MOVR_S r1, 0 ; r1 = bytes to fill in
bl memset

;;; Clear the registers.
MOVR_S r0, 0
MOVR_S r1, 0
MOVR_S r2, 0
MOVR_S r3, 0
MOVR_S r4, 0
MOVR_S r5, 0
MOVR_S r6, 0
MOVR_S r7, 0
MOVR_S r8, 0
MOVR_S r9, 0
MOVR_S r10, 0
MOVR_S r11, 0
MOVR_S r12, 0
MOVR_S r13, 0
MOVR_S r14, 0
MOVR_S r15, 0
MOVR_S r16, 0
MOVR_S r17, 0
MOVR_S r18, 0
MOVR_S r19, 0
MOVR_S r20, 0
MOVR_S r21, 0
MOVR_S r22, 0
MOVR_S r23, 0
MOVR_S r24, 0
MOVR_S r25, 0
MOVR_S r26, 0
MOVR_S r27, 0
;; SP (r28) is initialized
MOVR_S ilink, 0
MOVR r30, 0

#if defined(__ARC_FPU_DP__) || defined (__ARC_FPU_SP__)
initfp 0,31
#endif

;; Call constructors.
jl _init

;;; Setup fini routines to be called from exit
MOVRI_S r0, _fini
jl atexit

jl __setup_argv_and_call_main

j exit
.size __start, .-__start

;;; arc-main-helper.o object can be used to replace this function
;;; and properly set up arguments and/or other low-level stuff.
.section .text.__setup_argv_and_call_main,"ax",@progbits
.weak __setup_argv_and_call_main
.type __setup_argv_and_call_main, @function
.align 4

__setup_argv_and_call_main:
PUSHR blink
;;; Call main() with argv[0] set to "baremetal", argv[1] to NULL and empty envp
MOVR_S r0, 1 ; Set argc to 1
ADDPCL r1,.argv_data ; Set argv to the appropriate pointer
MOVR_S r2, 0
MOVR_S r3, 0

MOVRI_S blink, main
jl [blink]

POPR blink
j_s [blink]

.align 4
;; Dummy program name
.prog_name:
.string "baremetal"
;; argv data
.argv_data:
WORD @.prog_name
WORD 0x00
.size __setup_argv_and_call_main, .-__setup_argv_and_call_main

.section .text._exit_halt,"ax",@progbits
.global _exit_halt
.type _exit_halt, @function
.align 4
_exit_halt:
; r0 contains exit code
mov r0, r0
flag 1
b _exit_halt
.size _exit_halt, .-_exit_halt
Loading

0 comments on commit 37c8623

Please sign in to comment.