[6/8] arc: libgloss: Accommodate MetaWare's standard symbol names

Message ID 20240820121043.1605628-7-ykolerov@synopsys.com
State New
Headers
Series A series of patches for Synopsys ARC port |

Commit Message

Yuriy Kolerov Aug. 20, 2024, 12:10 p.m. UTC
  From: Alexey Brodkin <abrodkin@synopsys.com>

It makes it usable with standard symbol names defined in default
linker scripts of the MetaWare toolchain.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
---
 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
  

Patch

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 <sys/types.h>
 #include <sys/errno.h>
+#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 <stdint.h>
 #include <stdio.h>
 #include <errno.h>
+#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);
 }