entry.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright 2018 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _BSP_ENTRY_H
  16. #define _BSP_ENTRY_H
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef int (*core_function)(void *ctx);
  23. typedef struct _core_instance_t
  24. {
  25. core_function callback;
  26. void *ctx;
  27. } core_instance_t;
  28. int register_core1(core_function func, void *ctx);
  29. static inline void init_lma(void)
  30. {
  31. extern unsigned int _data_lma;
  32. extern unsigned int _data;
  33. extern unsigned int _edata;
  34. unsigned int *src, *dst;
  35. src = &_data_lma;
  36. dst = &_data;
  37. while(dst < &_edata)
  38. *dst++ = *src++;
  39. }
  40. static inline void init_bss(void)
  41. {
  42. extern unsigned int _bss;
  43. extern unsigned int _ebss;
  44. unsigned int *dst;
  45. dst = &_bss;
  46. while(dst < &_ebss)
  47. *dst++ = 0;
  48. }
  49. static inline void init_tls(void)
  50. {
  51. register void *thread_pointer asm("tp");
  52. extern char _tls_data;
  53. extern __thread char _tdata_begin, _tdata_end, _tbss_end;
  54. size_t tdata_size = &_tdata_end - &_tdata_begin;
  55. memcpy(thread_pointer, &_tls_data, tdata_size);
  56. size_t tbss_size = &_tbss_end - &_tdata_end;
  57. memset(thread_pointer + tdata_size, 0, tbss_size);
  58. }
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* _BSP_ENTRY_H */