Fix some compilation warnings and add esp-idf platform for experiment (#454)
And fix some code indent issues.
This commit is contained in:
25
core/shared/platform/common/freertos/freertos_malloc.c
Normal file
25
core/shared/platform/common/freertos/freertos_malloc.c
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "platform_api_vmcore.h"
|
||||
|
||||
|
||||
void *
|
||||
os_malloc(unsigned size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
os_realloc(void *ptr, unsigned size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -8,9 +8,12 @@
|
||||
|
||||
#define bh_assert(v) do { \
|
||||
if (!(v)) { \
|
||||
int _count = 1; \
|
||||
os_printf("\nASSERTION FAILED: %s, at %s, line %d\n",\
|
||||
#v, __FILE__, __LINE__); \
|
||||
abort(); \
|
||||
#v, __FILE__, __LINE__); \
|
||||
/* divived by 0 to make it abort */ \
|
||||
os_printf("%d\n", _count / (_count - 1)); \
|
||||
while (1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@ -293,7 +296,8 @@ int os_thread_join(korp_tid thread, void **value_ptr)
|
||||
int os_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
SemaphoreHandle_t semaphore;
|
||||
if (!(semaphore = xSemaphoreCreateMutex()))
|
||||
|
||||
if (!(semaphore = xSemaphoreCreateMutex()))
|
||||
return BHT_ERROR;
|
||||
mutex->sem = semaphore;
|
||||
mutex->is_recursive = false;
|
||||
@ -303,6 +307,7 @@ int os_mutex_init(korp_mutex *mutex)
|
||||
int os_recursive_mutex_init(korp_mutex *mutex)
|
||||
{
|
||||
SemaphoreHandle_t semaphore;
|
||||
|
||||
if (!(semaphore = xSemaphoreCreateRecursiveMutex()))
|
||||
return BHT_ERROR;
|
||||
mutex->sem = semaphore;
|
||||
@ -418,9 +423,3 @@ int os_cond_signal(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
{
|
||||
/* TODO: implement os_thread_get_stack_boundary */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (PLATFORM_COMMON_FREERTOS_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
file (GLOB_RECURSE source_all ${PLATFORM_COMMON_FREERTOS_DIR}/*.c)
|
||||
|
||||
set (PLATFORM_COMMON_FREERTOS_SOURCE ${source_all} )
|
||||
@ -32,6 +32,10 @@
|
||||
|
||||
#define __FDLIBM_STDC__
|
||||
|
||||
#ifndef FLT_EVAL_METHOD
|
||||
#define FLT_EVAL_METHOD 0
|
||||
#endif
|
||||
|
||||
typedef uint32_t u_int32_t;
|
||||
typedef uint64_t u_int64_t;
|
||||
|
||||
|
||||
122
core/shared/platform/esp-idf/espidf_platform.c
Normal file
122
core/shared/platform/esp-idf/espidf_platform.c
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
|
||||
int errno = 0;
|
||||
|
||||
int
|
||||
os_thread_sys_init();
|
||||
|
||||
void
|
||||
os_thread_sys_destroy();
|
||||
|
||||
int
|
||||
bh_platform_init()
|
||||
{
|
||||
return os_thread_sys_init();
|
||||
}
|
||||
|
||||
void
|
||||
bh_platform_destroy()
|
||||
{
|
||||
os_thread_sys_destroy();
|
||||
}
|
||||
|
||||
int os_printf(const char *format, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
ret += vprintf(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
os_vprintf(const char *format, va_list ap)
|
||||
{
|
||||
return vprintf(format, ap);
|
||||
}
|
||||
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
{
|
||||
|
||||
return BH_MALLOC(size);
|
||||
}
|
||||
|
||||
void
|
||||
os_munmap(void *addr, size_t size)
|
||||
{
|
||||
BH_FREE(addr);
|
||||
}
|
||||
|
||||
int
|
||||
os_mprotect(void *addr, size_t size, int prot)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
os_dcache_flush()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
atoi(const char *nptr)
|
||||
{
|
||||
bool is_negative = false;
|
||||
int total = 0;
|
||||
const char *p = nptr;
|
||||
char temp = '0';
|
||||
|
||||
if (NULL == p) {
|
||||
os_printf("invlaid atoi input\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*p == '-') {
|
||||
is_negative = true;
|
||||
p++;
|
||||
}
|
||||
|
||||
while ((temp = *p++) != '\0') {
|
||||
if (temp > '9' || temp < '0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
total = total * 10 + (int)(temp - '0');
|
||||
}
|
||||
|
||||
if (is_negative)
|
||||
total = 0 - total;
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
void *
|
||||
memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
|
||||
if (d < s) {
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
}
|
||||
else {
|
||||
const char *lasts = s + (n-1);
|
||||
char *lastd = d + (n-1);
|
||||
while (n--)
|
||||
*lastd-- = *lasts--;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
14
core/shared/platform/esp-idf/espidf_thread.c
Normal file
14
core/shared/platform/esp-idf/espidf_thread.c
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
{
|
||||
/* TODO: implement os_thread_get_stack_boundary */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -20,8 +20,8 @@
|
||||
#include <task.h>
|
||||
#include <os_api.h>
|
||||
|
||||
#ifndef BH_PLATFORM_FREERTOS
|
||||
#define BH_PLATFORM_FREERTOS
|
||||
#ifndef BH_PLATFORM_ESP_IDF
|
||||
#define BH_PLATFORM_ESP_IDF
|
||||
#endif
|
||||
|
||||
#define BH_APPLET_PRESERVED_STACK_SIZE (2 * BH_KB)
|
||||
@ -3,14 +3,17 @@
|
||||
|
||||
set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
add_definitions(-DBH_PLATFORM_FREERTOS)
|
||||
add_definitions(-DBH_PLATFORM_ESP_IDF)
|
||||
|
||||
include_directories(${PLATFORM_SHARED_DIR})
|
||||
include_directories(${PLATFORM_SHARED_DIR}/../include)
|
||||
|
||||
include (${CMAKE_CURRENT_LIST_DIR}/../common/freertos/platform_api_freertos.cmake)
|
||||
include (${CMAKE_CURRENT_LIST_DIR}/../common/math/platform_api_math.cmake)
|
||||
|
||||
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
|
||||
|
||||
set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_MATH_SOURCE})
|
||||
set (PLATFORM_SHARED_SOURCE ${source_all}
|
||||
${PLATFORM_COMMON_MATH_SOURCE}
|
||||
${PLATFORM_COMMON_FREERTOS_SOURCE})
|
||||
|
||||
@ -1,315 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "platform_api_vmcore.h"
|
||||
#include "platform_api_extension.h"
|
||||
|
||||
|
||||
int errno = 0;
|
||||
|
||||
int
|
||||
os_thread_sys_init();
|
||||
|
||||
void
|
||||
os_thread_sys_destroy();
|
||||
|
||||
int
|
||||
bh_platform_init()
|
||||
{
|
||||
return os_thread_sys_init();
|
||||
}
|
||||
|
||||
void
|
||||
bh_platform_destroy()
|
||||
{
|
||||
os_thread_sys_destroy();
|
||||
}
|
||||
|
||||
void *
|
||||
os_malloc(unsigned size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
os_realloc(void *ptr, unsigned size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
}
|
||||
|
||||
int os_printf(const char *format, ...)
|
||||
{
|
||||
/* TODO: implement os_printf */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
os_vprintf(const char *format, va_list ap)
|
||||
{
|
||||
/* TODO: implement os_vprintf */
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
{
|
||||
|
||||
return BH_MALLOC(size);
|
||||
}
|
||||
|
||||
void
|
||||
os_munmap(void *addr, size_t size)
|
||||
{
|
||||
BH_FREE(addr);
|
||||
}
|
||||
|
||||
int
|
||||
os_mprotect(void *addr, size_t size, int prot)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
os_dcache_flush()
|
||||
{
|
||||
}
|
||||
|
||||
int atoi(const char *nptr)
|
||||
{
|
||||
bool is_negative = false;
|
||||
int total = 0;
|
||||
const char *p = nptr;
|
||||
char temp = '0';
|
||||
|
||||
if (NULL == p) {
|
||||
os_printf("invlaid atoi input\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*p == '-') {
|
||||
is_negative = true;
|
||||
p++;
|
||||
}
|
||||
|
||||
while ((temp = *p++) != '\0') {
|
||||
if (temp > '9' || temp < '0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
total = total * 10 + (int)(temp - '0');
|
||||
}
|
||||
|
||||
if (is_negative)
|
||||
total = 0 - total;
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: implement these APIs which are needed by libc_builtin_wrapper.c
|
||||
* and wasm_runtime_common.c
|
||||
*/
|
||||
int strncasecmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
os_printf("### unimplemented function strncasecmp called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
long int strtol(const char *str, char **endptr, int base)
|
||||
{
|
||||
os_printf("### unimplemented function strtol called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long int strtoul(const char *str, char **endptr, int base)
|
||||
{
|
||||
os_printf("### unimplemented function strtoul called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long long int strtoull(const char *nptr, char **endptr, int base)
|
||||
{
|
||||
os_printf("### unimplemented function strtoull called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
double strtod(const char *nptr, char **endptr)
|
||||
{
|
||||
os_printf("### unimplemented function strtod called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
float strtof(const char *nptr, char **endptr)
|
||||
{
|
||||
os_printf("### unimplemented function strtof called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
os_printf("### unimplemented function strstr called!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t strspn(const char *s, const char *accept)
|
||||
{
|
||||
os_printf("### unimplemented function strspn called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t strcspn(const char *s, const char *reject)
|
||||
{
|
||||
os_printf("### unimplemented function strcspn called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
os_printf("### unimplemented function memchr called!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int isalnum(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isalnum called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isxdigit(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isxdigit called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isdigit(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isdigit called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isprint(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isprint called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isgraph(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isgraph called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isspace(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isspace called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isalpha(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isalpha called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isupper(int c)
|
||||
{
|
||||
os_printf("### unimplemented function isupper called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int toupper(int c)
|
||||
{
|
||||
os_printf("### unimplemented function toupper called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tolower(int c)
|
||||
{
|
||||
os_printf("### unimplemented function tolower called!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
|
||||
if (d < s) {
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
}
|
||||
else {
|
||||
const char *lasts = s + (n-1);
|
||||
char *lastd = d + (n-1);
|
||||
while (n--)
|
||||
*lastd-- = *lasts--;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
static union {
|
||||
int a;
|
||||
char b;
|
||||
} __ue = { .a = 1 };
|
||||
|
||||
#define is_little_endian() (__ue.b == 1)
|
||||
|
||||
static void swap32(uint8_t* pData)
|
||||
{
|
||||
uint8_t value = *pData;
|
||||
*pData = *(pData + 3);
|
||||
*(pData + 3) = value;
|
||||
|
||||
value = *(pData + 1);
|
||||
*(pData + 1) = *(pData + 2);
|
||||
*(pData + 2) = value;
|
||||
}
|
||||
|
||||
static void swap16(uint8_t* pData)
|
||||
{
|
||||
uint8_t value = *pData;
|
||||
*(pData) = *(pData + 1);
|
||||
*(pData + 1) = value;
|
||||
}
|
||||
|
||||
uint32_t htonl(uint32_t value)
|
||||
{
|
||||
uint32_t ret;
|
||||
if (is_little_endian()) {
|
||||
ret = value;
|
||||
swap32((uint8*) &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t ntohl(uint32_t value)
|
||||
{
|
||||
return htonl(value);
|
||||
}
|
||||
|
||||
uint16_t htons(uint16_t value)
|
||||
{
|
||||
uint16_t ret;
|
||||
if (is_little_endian()) {
|
||||
ret = value;
|
||||
swap16((uint8_t *)&ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
uint16_t ntohs(uint16_t value)
|
||||
{
|
||||
return htons(value);
|
||||
}
|
||||
|
||||
@ -147,7 +147,6 @@ int os_thread_detach(korp_tid thread)
|
||||
|
||||
void os_thread_exit(void *retval)
|
||||
{
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
uint8 *os_thread_get_stack_boundary()
|
||||
|
||||
Reference in New Issue
Block a user