[363] | 1 | /*
|
---|
| 2 | * TOPPERS/JSP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Just Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | * Copyright (C) 2003-2004 by Takagi Nobuhisa
|
---|
| 9 | *
|
---|
| 10 | * ä¸è¨èä½æ¨©è
|
---|
| 11 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 12 | * ã«ãã£ã¦å
|
---|
| 13 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 14 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 15 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 16 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 17 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 18 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 19 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 20 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 21 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 22 | * ç¨ã§ããå½¢ã§åé
|
---|
| 23 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 24 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 25 | * è
|
---|
| 26 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 27 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 28 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 29 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 30 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 31 | * ã¨ï¼
|
---|
| 32 | * (a) åé
|
---|
| 33 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 34 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 35 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 36 | * (b) åé
|
---|
| 37 | å¸ã®å½¢æ
|
---|
| 38 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 39 | * å ±åãããã¨ï¼
|
---|
| 40 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 41 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 42 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 43 | 責ãããã¨ï¼
|
---|
| 44 | *
|
---|
| 45 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 46 | ã
|
---|
| 47 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 48 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 49 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 50 | *
|
---|
| 51 | * @(#) $Id: newlibrt.c,v 1.2 2004/09/17 09:11:44 honda Exp $
|
---|
| 52 | */
|
---|
| 53 | #include <stddef.h>
|
---|
| 54 | #include <reent.h>
|
---|
| 55 | #include <errno.h>
|
---|
| 56 | #include "../kernel/jsp_kernel.h"
|
---|
| 57 |
|
---|
| 58 | #ifndef HEAP_TOP
|
---|
| 59 | #define HEAP_TOP ~0UL
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
| 62 | /*
|
---|
| 63 | * For malloc (Newlib)
|
---|
| 64 | */
|
---|
| 65 | static int cxxrt_dis_dsp;
|
---|
| 66 |
|
---|
| 67 | void __malloc_lock(struct _reent *ptr)
|
---|
| 68 | {
|
---|
| 69 | if (!iniflg || sns_dsp())
|
---|
| 70 | return;
|
---|
| 71 | dis_dsp();
|
---|
| 72 | cxxrt_dis_dsp = 1;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void __malloc_unlock(struct _reent *ptr)
|
---|
| 76 | {
|
---|
| 77 | if (!cxxrt_dis_dsp)
|
---|
| 78 | return;
|
---|
| 79 | cxxrt_dis_dsp = 0;
|
---|
| 80 | ena_dsp();
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void *_sbrk_r(struct _reent *ptr, ptrdiff_t nbyte)
|
---|
| 84 | {
|
---|
| 85 | extern char end;
|
---|
| 86 | static char *heap_ptr = &end;
|
---|
| 87 | static char *heap_end = (char*)HEAP_TOP;
|
---|
| 88 | char *base;
|
---|
| 89 |
|
---|
| 90 | if (!iniflg)
|
---|
| 91 | {
|
---|
| 92 | volatile char _auto;
|
---|
| 93 | if (&end < &_auto && &_auto < heap_end)
|
---|
| 94 | heap_end = (char*)&_auto;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | if (heap_ptr + nbyte + 32 > heap_end)
|
---|
| 98 | {
|
---|
| 99 | ptr->_errno = errno = ENOMEM;
|
---|
| 100 | return (void*)-1;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | base = heap_ptr;
|
---|
| 104 | heap_ptr += nbyte;
|
---|
| 105 | return base;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /*
|
---|
| 109 | * For program termination
|
---|
| 110 | */
|
---|
| 111 | #define ATEXIT_MAX (32 + 1)
|
---|
| 112 |
|
---|
| 113 | static void (*atexit_table[ATEXIT_MAX])(void);
|
---|
| 114 | static int atexit_num;
|
---|
| 115 |
|
---|
| 116 | /*
|
---|
| 117 | * abortæã«æåã«å¼åºãããããã¯
|
---|
| 118 | * raise(SIGABRT)ãå¼åºãããã«ããã°ããã¹ãç°å¢ã¨ã®äºæãã¨ããã¨ãå¯è½ã«ãªãã
|
---|
| 119 | */
|
---|
| 120 | void (*_atabort)(void) = 0;
|
---|
| 121 |
|
---|
| 122 | int atexit(void (*func)(void))
|
---|
| 123 | {
|
---|
| 124 | int result = -1;
|
---|
| 125 | int sync = iniflg;
|
---|
| 126 |
|
---|
| 127 | if (sync)
|
---|
| 128 | loc_cpu();
|
---|
| 129 |
|
---|
| 130 | if (atexit_num < ATEXIT_MAX)
|
---|
| 131 | {
|
---|
| 132 | atexit_table[atexit_num++] = func;
|
---|
| 133 | result = 0;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | if (sync)
|
---|
| 137 | unl_cpu();
|
---|
| 138 |
|
---|
| 139 | return result;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | void exit(int status)
|
---|
| 143 | {
|
---|
| 144 | if (iniflg)
|
---|
| 145 | kernel_exit();
|
---|
| 146 | _exit(status);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | void abort(void)
|
---|
| 150 | {
|
---|
| 151 | if (_atabort != 0)
|
---|
| 152 | (*_atabort)();
|
---|
| 153 | if (iniflg)
|
---|
| 154 | kernel_abort();
|
---|
| 155 | _exit(3);
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | /*
|
---|
| 159 | * For software hooks
|
---|
| 160 | */
|
---|
| 161 | void software_init_hook(void)
|
---|
| 162 | {
|
---|
| 163 | extern void _toppers_cxxrt_init(void);
|
---|
| 164 | _toppers_cxxrt_init();
|
---|
| 165 | {
|
---|
| 166 | #ifdef __ELF__
|
---|
| 167 | extern void _init(void);
|
---|
| 168 | extern void _fini(void);
|
---|
| 169 | atexit(_fini);
|
---|
| 170 | _init();
|
---|
| 171 | #else
|
---|
| 172 | extern void __main(void);
|
---|
| 173 | __main();
|
---|
| 174 | #endif
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | void software_term_hook(void)
|
---|
| 179 | {
|
---|
| 180 | int i;
|
---|
| 181 |
|
---|
| 182 | for (i = atexit_num - 1; i >= 0; i--)
|
---|
| 183 | (*atexit_table[i])();
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | /* ãªã³ã¯è§£æ±ºç¨ã®ããã¼ */
|
---|
| 187 | int main() { return 0; }
|
---|
| 188 |
|
---|