source: trunk/libs/newlib/src/libgloss/or1k/util.c @ 684

Last change on this file since 684 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.8 KB
Line 
1/* util.c -- Utility functions for OpenRISC 1000.
2 *
3 * Copyright (c) 2014 Authors
4 *
5 * Contributor Julius Baxter <julius.baxter@orsoc.se>
6 * Contributor Stefan Wallentowitz <stefan.wallentowitz@tum.de>
7 *
8 * The authors hereby grant permission to use, copy, modify, distribute,
9 * and license this software and its documentation for any purpose, provided
10 * that existing copyright notices are retained in all copies and that this
11 * notice is included verbatim in any distributions. No written agreement,
12 * license, or royalty fee is required for any of the authorized uses.
13 * Modifications to this software may be copyrighted by their authors
14 * and need not follow the licensing terms described here, provided that
15 * the new terms are clearly indicated on the first page of each file where
16 * they apply.
17 */
18
19#include <stdint.h>
20#include <stddef.h>
21#include <reent.h>
22
23#include "or1k-internals.h"
24
25#ifdef __OR1K_MULTICORE__
26// Define pointers to arrays
27uint8_t* *_or1k_stack_core;
28uint8_t* *_or1k_exception_stack_core;
29uint32_t* *_or1k_exception_level;
30#else
31// Define scalar
32uint32_t _or1k_exception_level;
33#endif
34
35uint8_t* _or1k_stack_top;
36uint8_t* _or1k_stack_bottom;
37
38uint8_t* _or1k_exception_stack_top;
39uint8_t* _or1k_exception_stack_bottom;
40
41void _or1k_init() {
42#ifdef __OR1K_MULTICORE__
43        uint32_t c;
44
45        // Initialize stacks
46        _or1k_stack_core = _sbrk_r(0, sizeof(uint8_t*) * or1k_numcores());
47        _or1k_exception_stack_core = _sbrk_r(0, sizeof(uint8_t*) * or1k_numcores());
48
49        _or1k_stack_core[0] = _or1k_stack_top;
50        _or1k_exception_stack_core[0] = _or1k_exception_stack_top;
51
52        for (c = 1; c < or1k_numcores(); c++) {
53                _or1k_stack_core[c] = _or1k_stack_core[c-1] - _or1k_stack_size;
54                _or1k_exception_stack_core[c] = _or1k_exception_stack_core[c-1] -
55                                _or1k_exception_stack_size;
56        }
57
58        size_t exc_size = sizeof(void*) * or1k_numcores() * OR1K_NUM_EXCEPTIONS;
59        _or1k_exception_handler_table = _sbrk_r(0, exc_size);
60
61        size_t int_size = sizeof(void*) * or1k_numcores() * 32;
62        size_t intdata_size = sizeof(void*) * or1k_numcores() * 32;
63        _or1k_interrupt_handler_table = _sbrk_r(0, int_size);
64        _or1k_interrupt_handler_data_ptr_table = _sbrk_r(0, intdata_size);
65#endif
66
67        _or1k_reent_init();
68
69#ifdef __OR1K_MULTICORE__
70        for (c = 0; c < or1k_numcores(); c++) {
71                _or1k_exception_handler_table[c][6] = _or1k_interrupt_handler;
72        }
73#else
74        _or1k_exception_handler_table[6] = _or1k_interrupt_handler;
75#endif
76
77#ifdef __OR1K_MULTICORE__
78        _or1k_exception_level = _sbrk_r(0, 4 * or1k_numcores());
79        for (c = 0; c < or1k_numcores(); c++) {
80                _or1k_exception_level[c] = 0;
81        }
82#else
83        _or1k_exception_level = 0;
84#endif
85}
86
87uint32_t or1k_critical_begin() {
88        uint32_t iee = or1k_interrupts_disable();
89        uint32_t tee = or1k_timer_disable();
90        return (iee << 1) | tee;
91}
92
93void or1k_critical_end(uint32_t restore) {
94        or1k_timer_restore(restore & 0x1);
95        or1k_interrupts_restore((restore >> 1) & 0x1);
96}
97
Note: See TracBrowser for help on using the repository browser.