1 /*
2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3 */
4
5 #include <string.h>
6 #include <stdio.h>
7 #include <sys/time.h>
8 #include "k_config.h"
9 #include "aos/kernel.h"
10
11 #include "aos/hal/uart.h"
12
13 volatile int errno = 0;
14 extern uart_dev_t uart_0;
15
16 #if defined (__CC_ARM) && defined(__MICROLIB)
__aeabi_assert(const char * expr,const char * file,int line)17 void __aeabi_assert(const char *expr, const char *file, int line)
18 {
19 while (1);
20 }
21 extern uint64_t krhino_sys_time_get(void);
gettimeofday(struct timeval * tv,void * tzp)22 int gettimeofday(struct timeval *tv, void *tzp)
23 {
24 uint64_t t = krhino_sys_time_get();
25 tv->tv_sec = t / 1000;
26 tv->tv_usec = (t % 1000) * 1000;
27 return 0;
28 }
29
__aeabi_errno_addr()30 volatile int *__aeabi_errno_addr()
31 {
32 return &errno;
33 }
34
35 #if (RHINO_CONFIG_MM_TLF > 0)
36 #define AOS_UNSIGNED_INT_MSB (1u << (sizeof(unsigned int) * 8 - 1))
37 extern void *aos_malloc(unsigned int size);
38 extern void aos_alloc_trace(void *addr, size_t allocator);
39 extern void aos_free(void *mem);
40 extern void *aos_realloc(void *mem, unsigned int size);
41
malloc(size_t size)42 void *malloc(size_t size)
43 {
44 void *mem;
45
46 #if (RHINO_CONFIG_MM_DEBUG > 0u)
47 mem = aos_malloc(size | AOS_UNSIGNED_INT_MSB);
48 #else
49 mem = aos_malloc(size);
50 #endif
51
52 return mem;
53 }
54
free(void * mem)55 void free(void *mem)
56 {
57 aos_free(mem);
58 }
59
realloc(void * old,size_t newlen)60 void *realloc(void *old, size_t newlen)
61 {
62 void *mem;
63
64 #if (RHINO_CONFIG_MM_DEBUG > 0u)
65 mem = aos_realloc(old, newlen | AOS_UNSIGNED_INT_MSB);
66 #else
67 mem = aos_realloc(old, newlen);
68 #endif
69
70 return mem;
71 }
72
calloc(size_t len,size_t elsize)73 void *calloc(size_t len, size_t elsize)
74 {
75 void *mem;
76
77 #if (RHINO_CONFIG_MM_DEBUG > 0u)
78 mem = aos_malloc((elsize * len) | AOS_UNSIGNED_INT_MSB);
79 #else
80 mem = aos_malloc(elsize * len);
81 #endif
82
83 if (mem) {
84 memset(mem, 0, elsize * len);
85 }
86
87 return mem;
88 }
89
strdup(const char * s)90 char * strdup(const char *s)
91 {
92 size_t len = strlen(s) +1;
93 void *dup_str = aos_malloc(len);
94 if (dup_str == NULL)
95 return NULL;
96 return (char *)memcpy(dup_str, s, len);
97 }
98
99 #endif
100
101 #pragma weak fputc
fputc(int ch,FILE * f)102 int fputc(int ch, FILE *f)
103 {
104 /* Send data. */
105 if (ch == '\n') {
106 hal_uart_send(&uart_0, (void *)"\r", 1, AOS_WAIT_FOREVER);
107 }
108 hal_uart_send(&uart_0, &ch, 1, AOS_WAIT_FOREVER);
109 return ch;
110 }
111
112 //referred from ota_socket.o
bzero()113 void bzero()
114 {
115
116 }
117
118 //referred from ssl_cli.o
time(time_t * t)119 time_t time(time_t *t)
120 {
121 return 0;
122 }
123
124 //referred from aos_network.o
accept(int sock,long * addr,long * addrlen)125 int accept(int sock, long *addr, long *addrlen)
126 {
127 return 0;
128 }
129
listen(int sock,int backlog)130 int listen(int sock, int backlog)
131 {
132 return 0;
133 }
134
135 //referred from timing.o
alarm(unsigned int seconds)136 unsigned int alarm(unsigned int seconds)
137 {
138 return 0;
139 }
140
141 #endif
142
143