From patchwork Tue Aug 20 12:10:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuriy Kolerov X-Patchwork-Id: 96146 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC152384514B for ; Tue, 20 Aug 2024 12:12:20 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by sourceware.org (Postfix) with ESMTPS id 042A33846456 for ; Tue, 20 Aug 2024 12:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 042A33846456 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=synopsys.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=synopsys.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 042A33846456 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724155897; cv=none; b=lWCvM0xLNd/TkQbKvrSNqP1DIQWDd+KcI/lwXnF/lRhrs7qt2pDPf/XIbfK83RaiPsyqB1VrimVyURq45WxgrfwvEEN//Y0/iGKI1SKxIdCF/9+XdNKzJu+qMqXKC5PZQhIlPqwRfZnBZDyhnFsfgCmGNIG9G0jXtG22HO8QbKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724155897; c=relaxed/simple; bh=suA0kDJVWh1SQLV8vbMIrmf7QSQnRO2e5ftIT0doPFk=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=Q2/jd7jSG6ejAvPz5CEGb1XFyq1N4xrWxbFfEaS1cNt8pjrbAbWFNmzO+ZDSql50vkqgE7dSW5gs9db6fllSUhLHzKNtSaoyRnHPfrCQq43exSGUqUPFaSm/jVZLtXmNDc31+snrjm/1dHJ1fcuZyhrfWTWgH5nZB36tWdJHLCY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0098572.ppops.net [127.0.0.1]) by mx0b-00230701.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47KBaLGE007947 for ; Tue, 20 Aug 2024 05:11:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pfptdkimsnps; bh=izM9JTv5 COhUOR45K/LFGcQ3rc8NS/06eJD4HgdsCMQ=; b=LEoTk4BIcRqwRpDh0tkognIg oqisct1sK7+lV4KCzgHiqdKrcNvGCk+DomXswE4UdQUblGDqiHLl4ZNiUc5VrOh3 CPLlFH8ovdUC6XsDbms35mGj/2KiE/iIL6rZfTaxVJPc9jW2vQmcmYyZNZHlvCz+ 6MGNgOrDHkKm43PA3/klfjukEpjeqHv8htoKypluCwl95w4e624+3BwUW6eb9LP5 sFM51FvFq2AeU1NsfIuN7oWxDeNrIEmM5DI0vtMuuD09yL80dYsaFMldS+Ve3PtW TNSp7L6NzQ4Tqb1+objstcUDS3AB9ZVm0VM1Lj3yB7buQj0oQ/fxl1Z3LNIi3g== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0b-00230701.pphosted.com (PPS) with ESMTPS id 414g8k2rct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Aug 2024 05:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1724155892; bh=suA0kDJVWh1SQLV8vbMIrmf7QSQnRO2e5ftIT0doPFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RbVkoALQr98HNE1F4xGEYvagMOxyDGsHxj7powLCwnl1MsWGahZ9+0C2TeyNOH9GE Le71okErmZpXkTxmqzXNlNxmbLoXNmUFc37hIVuU/MpjQArG2sm4gVWWdudB8ktth7 faogIFAnLCpt3m1JGBe2pO1B7W+phWF1ZMsML7s+Y6+I0orNyK1d1MH13ccVOlmLRg QQM5aJBnaKqZ7l+YfFNmNEYgy3kl6YEahUlVC6JGJ432NuU8XojiufkBsKqrpHPIma arsguybfh1SOOltZXU43sXln6DqUEjLfgDOpNg9MDo4INp6D5vQXhticI7+g/Or3+e UVpN1X/JNQHKQ== Received: from mailhost.synopsys.com (eudc-mailhost2.synopsys.com [10.213.161.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 3373540175 for ; Tue, 20 Aug 2024 12:11:32 +0000 (UTC) Received: from SNPS-HRlPxd6IgG.internal.synopsys.com (snps-hrlpxd6igg.internal.synopsys.com [10.120.15.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id ABD73C048C; Tue, 20 Aug 2024 12:11:30 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Yuriy.Kolerov@synopsys.com To: newlib@sourceware.org Cc: Alexey Brodkin Subject: [PATCH 6/8] arc: libgloss: Accommodate MetaWare's standard symbol names Date: Tue, 20 Aug 2024 15:10:41 +0300 Message-Id: <20240820121043.1605628-7-ykolerov@synopsys.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820121043.1605628-1-ykolerov@synopsys.com> References: <20240820121043.1605628-1-ykolerov@synopsys.com> MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=bpgeB1ai c=1 sm=1 tr=0 ts=66c487f5 cx=c_pps a=8EbXvwLXkpGsT4ql/pYRAw==:117 a=8EbXvwLXkpGsT4ql/pYRAw==:17 a=yoJbH4e0A30A:10 a=jIQo8A4GAAAA:8 a=jE0oYVVNUc63e_m2cnQA:9 a=Lf5xNeLK5dgiOs8hzIjU:22 X-Proofpoint-GUID: eOxPoDIDba_2mtlu51doE0WUtaymlMXy X-Proofpoint-ORIG-GUID: eOxPoDIDba_2mtlu51doE0WUtaymlMXy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-20_09,2024-08-19_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 suspectscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=849 malwarescore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408200090 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org From: Alexey Brodkin It makes it usable with standard symbol names defined in default linker scripts of the MetaWare toolchain. Signed-off-by: Alexey Brodkin --- libgloss/arc/arc-specific.h | 32 ++++++++++++++++++++++++++ libgloss/arc/arc-symbols.h | 40 +++++++++++++++++++++++++++++++++ libgloss/arc/arc-timer.c | 18 ++++++++------- libgloss/arc/crt0.S | 20 +++++++++-------- libgloss/arc/emsk-uart-setup.c | 3 ++- libgloss/arc/iotdk-uart-setup.c | 3 ++- libgloss/arc/sbrk.c | 9 ++++---- libgloss/arc/uart-8250.c | 5 +++-- 8 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 libgloss/arc/arc-specific.h create mode 100644 libgloss/arc/arc-symbols.h diff --git a/libgloss/arc/arc-specific.h b/libgloss/arc/arc-specific.h new file mode 100644 index 000000000..01f215a8e --- /dev/null +++ b/libgloss/arc/arc-specific.h @@ -0,0 +1,32 @@ +/* + * arc-specific.h -- provide ARC-specific definitions + * + * Copyright (c) 2024 Synopsys Inc. + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + * + */ + +#ifndef _ARC_SPECIFIC_H +#define _ARC_SPECIFIC_H + +/* First check for MetaWare compiler as it also defines __GNUC__. */ +#if defined (__CCAC__) + #define read_aux_reg(r) _lr(r) + #define write_aux_reg(r, v) _sr((unsigned int)(v), r) +#elif defined (__GNUC__) + #define read_aux_reg(r) __builtin_arc_lr(r) + #define write_aux_reg(v, r) __builtin_arc_sr((unsigned int)(v), r) +#else + #error "Unexpected compiler" +#endif + +#endif /* _ARC_SPECIFIC_H */ diff --git a/libgloss/arc/arc-symbols.h b/libgloss/arc/arc-symbols.h new file mode 100644 index 000000000..a41ee3953 --- /dev/null +++ b/libgloss/arc/arc-symbols.h @@ -0,0 +1,40 @@ +/* + * arc-symbols.h -- provide ARC-specific symbols + * + * Copyright (c) 2024 Synopsys Inc. + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + * + */ + +#ifndef _ARC_SYMBOLS_H +#define _ARC_SYMBOLS_H + +/* First check for MetaWare compiler as it also defines __GNUC__. */ +#if defined (__CCAC__) + #define STACK_TOP _estack + #define SMALL_DATA_BASE _SDA_BASE_ + #define SMALL_DATA_BSS_START _fsbss + #define SMALL_DATA_BSS_END _esbss + #define START_HEAP _fheap + #define END_HEAP _eheap +#elif defined (__GNUC__) + #define STACK_TOP __stack_top + #define SMALL_DATA_BASE __SDATA_BEGIN__ + #define SMALL_DATA_BSS_START __sbss_start + #define SMALL_DATA_BSS_END _end + #define START_HEAP __start_heap + #define END_HEAP __end_heap +#else + #error "Unexpected compiler" +#endif + +#endif /* _ARC_SYMBOLS_H */ \ No newline at end of file diff --git a/libgloss/arc/arc-timer.c b/libgloss/arc/arc-timer.c index 2437407e7..0d3074d5a 100644 --- a/libgloss/arc/arc-timer.c +++ b/libgloss/arc/arc-timer.c @@ -15,6 +15,8 @@ * */ +#include "arc-specific.h" + #define ARC_TIM_BUILD 0x75 #define ARC_TIM_BUILD_VER_MASK 0x00FF #define ARC_TIM_BUILD_TIM0_FL 0x0100 @@ -37,7 +39,7 @@ const unsigned int arc_timer_default = 0; static int _arc_timer_present (unsigned int tim) { - unsigned int bcr = __builtin_arc_lr (ARC_TIM_BUILD); + unsigned int bcr = read_aux_reg (ARC_TIM_BUILD); unsigned int ver = bcr & ARC_TIM_BUILD_VER_MASK; if (ver == 0) @@ -59,9 +61,9 @@ _arc_timer_read (unsigned int tim) if (_arc_timer_present (tim)) { if (tim == 0) - return __builtin_arc_lr (ARC_TIM_COUNT0); + return read_aux_reg (ARC_TIM_COUNT0); else if (tim == 1) - return __builtin_arc_lr (ARC_TIM_COUNT1); + return read_aux_reg (ARC_TIM_COUNT1); } return 0; @@ -95,14 +97,14 @@ _arc_timer_reset (unsigned int tim) return; } - ctrl = __builtin_arc_lr (tim_control); + ctrl = read_aux_reg (tim_control); /* Disable timer interrupt when programming. */ - __builtin_arc_sr (0, tim_control); + write_aux_reg (0, tim_control); /* Default limit is 24-bit, increase it to 32-bit. */ - __builtin_arc_sr (0xFFFFFFFF, tim_limit); + write_aux_reg (0xFFFFFFFF, tim_limit); /* Set NH bit to count only when processor is running. */ - __builtin_arc_sr (ctrl | ARC_TIM_CONTROL_NH_FL, tim_control); - __builtin_arc_sr (0, tim_count); + write_aux_reg (ctrl | ARC_TIM_CONTROL_NH_FL, tim_control); + write_aux_reg (0, tim_count); } } diff --git a/libgloss/arc/crt0.S b/libgloss/arc/crt0.S index 04fe82d7e..a64599eaa 100644 --- a/libgloss/arc/crt0.S +++ b/libgloss/arc/crt0.S @@ -41,6 +41,8 @@ the initialization code. */ +#include "arc-symbols.h" + /* Compatibility with older ARC GCC, that doesn't provide some of the preprocessor defines used by newlib and libgloss for ARC. */ #if defined (__Xbarrel_shifter) && !defined (__ARC_BARREL_SHIFTER__) @@ -106,11 +108,11 @@ IVT_ENTRY(IRQ_20) ; 20 0x50 80 #ifdef __ARC601__ ; Startup code for the ARC601 processor __start: - mov gp, __SDATA_BEGIN__ - mov sp, __stack_top ; Point to top of stack + mov gp, SMALL_DATA_BASE + mov sp, STACK_TOP ; Point to top of stack mov r5, 0 ; Zero value - mov_s r2, __sbss_start ; r2 = start of the bss section - sub r3, _end, r2 ; r3 = size of the bss section in bytes + mov_s r2, SMALL_DATA_BSS_START ; r2 = start of the bss section + sub r3, SMALL_DATA_BSS_START, r2 ; r3 = size of the bss section in bytes asr_s r3, r3 asr_s r3, r3 ; r3 = size of bss in words @@ -146,9 +148,9 @@ __start: ;; Initialize jli_base sr __JLI_TABLE__,[jli_base] #endif - mov gp, __SDATA_BEGIN__ - mov_s r2, __sbss_start ; r2 = start of the bss section - sub r3, _end, r2 ; r3 = size of the bss section in bytes + mov gp, SMALL_DATA_BASE + mov_s r2, SMALL_DATA_BSS_START ; r2 = start of the bss section + sub r3, SMALL_DATA_BSS_END, r2 ; r3 = size of the bss section in bytes ; set up the loop counter register to the size (in words) of the bss section #if defined (__ARC_BARREL_SHIFTER__) asr.f lp_count, r3, 2 @@ -162,12 +164,12 @@ __start: add r3, pcl, 20 sr r3, [2] ; LP_END ; initialize stack pointer, and this instruction has 2 words - mov sp, __stack_top + mov sp, STACK_TOP mov_s r3, 0 st.ab r3, [r2, 4] ; zero out the word .Lend_zbss: #else - mov sp, __stack_top ; initialize stack pointer + mov sp, STACK_TOP ; initialize stack pointer mov_s r3,0 ; loop to zero out the bss. Enter loop only if lp_count != 0 lpnz .Lend_zbss diff --git a/libgloss/arc/emsk-uart-setup.c b/libgloss/arc/emsk-uart-setup.c index b8e1ea859..16b5f7b38 100644 --- a/libgloss/arc/emsk-uart-setup.c +++ b/libgloss/arc/emsk-uart-setup.c @@ -15,6 +15,7 @@ * */ +#include "arc-specific.h" #include "uart-8250.h" /* Setup UART parameters. */ @@ -22,7 +23,7 @@ int _setup_low_level (void) { const uint32_t aux_dmp_per = 0x20a; - void * const uart_base = (char *)__builtin_arc_lr(aux_dmp_per) + 0x00009000; + void * const uart_base = (char *)read_aux_reg(aux_dmp_per) + 0x00009000; const int uart_aux_mapped = 0; const uint32_t uart_clock = 50000000; const uint32_t uart_baud = 115200; diff --git a/libgloss/arc/iotdk-uart-setup.c b/libgloss/arc/iotdk-uart-setup.c index e6d2ac887..a7b1183b8 100644 --- a/libgloss/arc/iotdk-uart-setup.c +++ b/libgloss/arc/iotdk-uart-setup.c @@ -15,6 +15,7 @@ * */ +#include "arc-specific.h" #include "uart-8250.h" /* Setup UART parameters. */ @@ -28,7 +29,7 @@ _setup_low_level (void) const uint32_t uart_baud = 115200; /* For this platform we have to enable UART clock before configuring it. */ - __builtin_arc_sr (0x01, (uint32_t) uart_base + uart_clk_ena); + write_aux_reg (0x01, (uint32_t) uart_base + uart_clk_ena); _uart_8250_setup (uart_base, uart_aux_mapped, uart_clock, uart_baud); diff --git a/libgloss/arc/sbrk.c b/libgloss/arc/sbrk.c index 8cb8461dd..2a83a5ac9 100644 --- a/libgloss/arc/sbrk.c +++ b/libgloss/arc/sbrk.c @@ -30,9 +30,10 @@ #include #include +#include "arc-symbols.h" -extern char __start_heap; -extern char __end_heap; +extern char START_HEAP; +extern char END_HEAP; caddr_t _sbrk (size_t nbytes) @@ -42,7 +43,7 @@ _sbrk (size_t nbytes) if (heap_ptr == NULL) { - heap_ptr = &__start_heap; + heap_ptr = &START_HEAP; } /* Align the 'heap_ptr' so that memory will always be allocated at word @@ -50,7 +51,7 @@ _sbrk (size_t nbytes) heap_ptr = (char *) ((((unsigned long) heap_ptr) + 7) & ~7); prev_heap_ptr = heap_ptr; - if ((heap_ptr + nbytes) < &__end_heap) + if ((heap_ptr + nbytes) < &END_HEAP) { heap_ptr += nbytes; return (caddr_t) prev_heap_ptr; diff --git a/libgloss/arc/uart-8250.c b/libgloss/arc/uart-8250.c index 6f4e9f3d6..fd9c55fc4 100644 --- a/libgloss/arc/uart-8250.c +++ b/libgloss/arc/uart-8250.c @@ -20,6 +20,7 @@ #include #include #include +#include "arc-specific.h" /* * List of UART 8250 registers with offsets: @@ -144,7 +145,7 @@ _uart_8250_write_reg (const struct _uart_8250 *uart, uint32_t reg, uint32_t value) { if (uart->aux_mapped) - __builtin_arc_sr (value, (uint32_t) uart->base + reg); + write_aux_reg (value, (uint32_t) uart->base + reg); else *(volatile uint32_t *)(uart->base + reg) = value; } @@ -154,7 +155,7 @@ static inline uint32_t _uart_8250_read_reg (const struct _uart_8250 *uart, uint32_t reg) { if (uart->aux_mapped) - return __builtin_arc_lr ((uint32_t) uart->base + reg); + return read_aux_reg ((uint32_t) uart->base + reg); else return *(volatile uint32_t *)(uart->base + reg); }