Skip to content

Commit eef0624

Browse files
abrodkinjjohnstn
authored andcommitted
arc: libgloss: Accommodate MetaWare's standard symbol names
It makes it usable with standard symbol names defined in default linker scripts of the MetaWare toolchain. Signed-off-by: Alexey Brodkin <[email protected]>
1 parent 16accfa commit eef0624

8 files changed

+105
-25
lines changed

libgloss/arc/arc-specific.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* arc-specific.h -- provide ARC-specific definitions
3+
*
4+
* Copyright (c) 2024 Synopsys Inc.
5+
*
6+
* The authors hereby grant permission to use, copy, modify, distribute,
7+
* and license this software and its documentation for any purpose, provided
8+
* that existing copyright notices are retained in all copies and that this
9+
* notice is included verbatim in any distributions. No written agreement,
10+
* license, or royalty fee is required for any of the authorized uses.
11+
* Modifications to this software may be copyrighted by their authors
12+
* and need not follow the licensing terms described here, provided that
13+
* the new terms are clearly indicated on the first page of each file where
14+
* they apply.
15+
*
16+
*/
17+
18+
#ifndef _ARC_SPECIFIC_H
19+
#define _ARC_SPECIFIC_H
20+
21+
/* First check for MetaWare compiler as it also defines __GNUC__. */
22+
#if defined (__CCAC__)
23+
#define read_aux_reg(r) _lr(r)
24+
#define write_aux_reg(r, v) _sr((unsigned int)(v), r)
25+
#elif defined (__GNUC__)
26+
#define read_aux_reg(r) __builtin_arc_lr(r)
27+
#define write_aux_reg(v, r) __builtin_arc_sr((unsigned int)(v), r)
28+
#else
29+
#error "Unexpected compiler"
30+
#endif
31+
32+
#endif /* _ARC_SPECIFIC_H */

libgloss/arc/arc-symbols.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* arc-symbols.h -- provide ARC-specific symbols
3+
*
4+
* Copyright (c) 2024 Synopsys Inc.
5+
*
6+
* The authors hereby grant permission to use, copy, modify, distribute,
7+
* and license this software and its documentation for any purpose, provided
8+
* that existing copyright notices are retained in all copies and that this
9+
* notice is included verbatim in any distributions. No written agreement,
10+
* license, or royalty fee is required for any of the authorized uses.
11+
* Modifications to this software may be copyrighted by their authors
12+
* and need not follow the licensing terms described here, provided that
13+
* the new terms are clearly indicated on the first page of each file where
14+
* they apply.
15+
*
16+
*/
17+
18+
#ifndef _ARC_SYMBOLS_H
19+
#define _ARC_SYMBOLS_H
20+
21+
/* First check for MetaWare compiler as it also defines __GNUC__. */
22+
#if defined (__CCAC__)
23+
#define STACK_TOP _estack
24+
#define SMALL_DATA_BASE _SDA_BASE_
25+
#define SMALL_DATA_BSS_START _fsbss
26+
#define SMALL_DATA_BSS_END _esbss
27+
#define START_HEAP _fheap
28+
#define END_HEAP _eheap
29+
#elif defined (__GNUC__)
30+
#define STACK_TOP __stack_top
31+
#define SMALL_DATA_BASE __SDATA_BEGIN__
32+
#define SMALL_DATA_BSS_START __sbss_start
33+
#define SMALL_DATA_BSS_END _end
34+
#define START_HEAP __start_heap
35+
#define END_HEAP __end_heap
36+
#else
37+
#error "Unexpected compiler"
38+
#endif
39+
40+
#endif /* _ARC_SYMBOLS_H */

libgloss/arc/arc-timer.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*
1616
*/
1717

18+
#include "arc-specific.h"
19+
1820
#define ARC_TIM_BUILD 0x75
1921
#define ARC_TIM_BUILD_VER_MASK 0x00FF
2022
#define ARC_TIM_BUILD_TIM0_FL 0x0100
@@ -37,7 +39,7 @@ const unsigned int arc_timer_default = 0;
3739
static int
3840
_arc_timer_present (unsigned int tim)
3941
{
40-
unsigned int bcr = __builtin_arc_lr (ARC_TIM_BUILD);
42+
unsigned int bcr = read_aux_reg (ARC_TIM_BUILD);
4143
unsigned int ver = bcr & ARC_TIM_BUILD_VER_MASK;
4244

4345
if (ver == 0)
@@ -59,9 +61,9 @@ _arc_timer_read (unsigned int tim)
5961
if (_arc_timer_present (tim))
6062
{
6163
if (tim == 0)
62-
return __builtin_arc_lr (ARC_TIM_COUNT0);
64+
return read_aux_reg (ARC_TIM_COUNT0);
6365
else if (tim == 1)
64-
return __builtin_arc_lr (ARC_TIM_COUNT1);
66+
return read_aux_reg (ARC_TIM_COUNT1);
6567
}
6668

6769
return 0;
@@ -95,14 +97,14 @@ _arc_timer_reset (unsigned int tim)
9597
return;
9698
}
9799

98-
ctrl = __builtin_arc_lr (tim_control);
100+
ctrl = read_aux_reg (tim_control);
99101
/* Disable timer interrupt when programming. */
100-
__builtin_arc_sr (0, tim_control);
102+
write_aux_reg (0, tim_control);
101103
/* Default limit is 24-bit, increase it to 32-bit. */
102-
__builtin_arc_sr (0xFFFFFFFF, tim_limit);
104+
write_aux_reg (0xFFFFFFFF, tim_limit);
103105
/* Set NH bit to count only when processor is running. */
104-
__builtin_arc_sr (ctrl | ARC_TIM_CONTROL_NH_FL, tim_control);
105-
__builtin_arc_sr (0, tim_count);
106+
write_aux_reg (ctrl | ARC_TIM_CONTROL_NH_FL, tim_control);
107+
write_aux_reg (0, tim_count);
106108
}
107109
}
108110

libgloss/arc/crt0.S

+11-9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
the initialization code.
4242
*/
4343

44+
#include "arc-symbols.h"
45+
4446
/* Compatibility with older ARC GCC, that doesn't provide some of the
4547
preprocessor defines used by newlib and libgloss for ARC. */
4648
#if defined (__Xbarrel_shifter) && !defined (__ARC_BARREL_SHIFTER__)
@@ -106,11 +108,11 @@ IVT_ENTRY(IRQ_20) ; 20 0x50 80
106108
#ifdef __ARC601__
107109
; Startup code for the ARC601 processor
108110
__start:
109-
mov gp, __SDATA_BEGIN__
110-
mov sp, __stack_top ; Point to top of stack
111+
mov gp, SMALL_DATA_BASE
112+
mov sp, STACK_TOP ; Point to top of stack
111113
mov r5, 0 ; Zero value
112-
mov_s r2, __sbss_start ; r2 = start of the bss section
113-
sub r3, _end, r2 ; r3 = size of the bss section in bytes
114+
mov_s r2, SMALL_DATA_BSS_START ; r2 = start of the bss section
115+
sub r3, SMALL_DATA_BSS_START, r2 ; r3 = size of the bss section in bytes
114116

115117
asr_s r3, r3
116118
asr_s r3, r3 ; r3 = size of bss in words
@@ -146,9 +148,9 @@ __start:
146148
;; Initialize jli_base
147149
sr __JLI_TABLE__,[jli_base]
148150
#endif
149-
mov gp, __SDATA_BEGIN__
150-
mov_s r2, __sbss_start ; r2 = start of the bss section
151-
sub r3, _end, r2 ; r3 = size of the bss section in bytes
151+
mov gp, SMALL_DATA_BASE
152+
mov_s r2, SMALL_DATA_BSS_START ; r2 = start of the bss section
153+
sub r3, SMALL_DATA_BSS_END, r2 ; r3 = size of the bss section in bytes
152154
; set up the loop counter register to the size (in words) of the bss section
153155
#if defined (__ARC_BARREL_SHIFTER__)
154156
asr.f lp_count, r3, 2
@@ -162,12 +164,12 @@ __start:
162164
add r3, pcl, 20
163165
sr r3, [2] ; LP_END
164166
; initialize stack pointer, and this instruction has 2 words
165-
mov sp, __stack_top
167+
mov sp, STACK_TOP
166168
mov_s r3, 0
167169
st.ab r3, [r2, 4] ; zero out the word
168170
.Lend_zbss:
169171
#else
170-
mov sp, __stack_top ; initialize stack pointer
172+
mov sp, STACK_TOP ; initialize stack pointer
171173
mov_s r3,0
172174
; loop to zero out the bss. Enter loop only if lp_count != 0
173175
lpnz .Lend_zbss

libgloss/arc/emsk-uart-setup.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*
1616
*/
1717

18+
#include "arc-specific.h"
1819
#include "uart-8250.h"
1920

2021
/* Setup UART parameters. */
2122
int
2223
_setup_low_level (void)
2324
{
2425
const uint32_t aux_dmp_per = 0x20a;
25-
void * const uart_base = (char *)__builtin_arc_lr(aux_dmp_per) + 0x00009000;
26+
void * const uart_base = (char *)read_aux_reg(aux_dmp_per) + 0x00009000;
2627
const int uart_aux_mapped = 0;
2728
const uint32_t uart_clock = 50000000;
2829
const uint32_t uart_baud = 115200;

libgloss/arc/iotdk-uart-setup.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*
1616
*/
1717

18+
#include "arc-specific.h"
1819
#include "uart-8250.h"
1920

2021
/* Setup UART parameters. */
@@ -28,7 +29,7 @@ _setup_low_level (void)
2829
const uint32_t uart_baud = 115200;
2930

3031
/* For this platform we have to enable UART clock before configuring it. */
31-
__builtin_arc_sr (0x01, (uint32_t) uart_base + uart_clk_ena);
32+
write_aux_reg (0x01, (uint32_t) uart_base + uart_clk_ena);
3233

3334
_uart_8250_setup (uart_base, uart_aux_mapped, uart_clock, uart_baud);
3435

libgloss/arc/sbrk.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030

3131
#include <sys/types.h>
3232
#include <sys/errno.h>
33+
#include "arc-symbols.h"
3334

34-
extern char __start_heap;
35-
extern char __end_heap;
35+
extern char START_HEAP;
36+
extern char END_HEAP;
3637

3738
caddr_t
3839
_sbrk (size_t nbytes)
@@ -42,15 +43,15 @@ _sbrk (size_t nbytes)
4243

4344
if (heap_ptr == NULL)
4445
{
45-
heap_ptr = &__start_heap;
46+
heap_ptr = &START_HEAP;
4647
}
4748

4849
/* Align the 'heap_ptr' so that memory will always be allocated at word
4950
boundaries. */
5051
heap_ptr = (char *) ((((unsigned long) heap_ptr) + 7) & ~7);
5152
prev_heap_ptr = heap_ptr;
5253

53-
if ((heap_ptr + nbytes) < &__end_heap)
54+
if ((heap_ptr + nbytes) < &END_HEAP)
5455
{
5556
heap_ptr += nbytes;
5657
return (caddr_t) prev_heap_ptr;

libgloss/arc/uart-8250.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdint.h>
2121
#include <stdio.h>
2222
#include <errno.h>
23+
#include "arc-specific.h"
2324

2425
/*
2526
* List of UART 8250 registers with offsets:
@@ -144,7 +145,7 @@ _uart_8250_write_reg (const struct _uart_8250 *uart, uint32_t reg,
144145
uint32_t value)
145146
{
146147
if (uart->aux_mapped)
147-
__builtin_arc_sr (value, (uint32_t) uart->base + reg);
148+
write_aux_reg (value, (uint32_t) uart->base + reg);
148149
else
149150
*(volatile uint32_t *)(uart->base + reg) = value;
150151
}
@@ -154,7 +155,7 @@ static inline uint32_t
154155
_uart_8250_read_reg (const struct _uart_8250 *uart, uint32_t reg)
155156
{
156157
if (uart->aux_mapped)
157-
return __builtin_arc_lr ((uint32_t) uart->base + reg);
158+
return read_aux_reg ((uint32_t) uart->base + reg);
158159
else
159160
return *(volatile uint32_t *)(uart->base + reg);
160161
}

0 commit comments

Comments
 (0)