[Kernel] Add 64bit CPU support.
This commit is contained in:
parent
d23a65d54e
commit
484afe9d2c
|
@ -102,9 +102,9 @@ static long _list_thread(struct rt_list_node *list)
|
||||||
while (*ptr == '#')ptr ++;
|
while (*ptr == '#')ptr ++;
|
||||||
|
|
||||||
rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n",
|
rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n",
|
||||||
thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp),
|
thread->stack_size + ((rt_ubase_t)thread->stack_addr - (rt_ubase_t)thread->sp),
|
||||||
thread->stack_size,
|
thread->stack_size,
|
||||||
(thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t) thread->stack_addr)) * 100
|
(thread->stack_size - ((rt_ubase_t) ptr - (rt_ubase_t) thread->stack_addr)) * 100
|
||||||
/ thread->stack_size,
|
/ thread->stack_size,
|
||||||
thread->remaining_tick,
|
thread->remaining_tick,
|
||||||
thread->error);
|
thread->error);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* 2018-09-04 Bernard change version number to v3.1.1
|
* 2018-09-04 Bernard change version number to v3.1.1
|
||||||
* 2018-09-14 Bernard apply Apache License v2.0 to RT-Thread Kernel
|
* 2018-09-14 Bernard apply Apache License v2.0 to RT-Thread Kernel
|
||||||
* 2018-10-13 Bernard change version number to v4.0.0
|
* 2018-10-13 Bernard change version number to v4.0.0
|
||||||
|
* 2018-10-02 Bernard add 64bit arch support
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __RT_DEF_H__
|
#ifndef __RT_DEF_H__
|
||||||
|
@ -55,13 +56,20 @@ extern "C" {
|
||||||
/* RT-Thread basic data type definitions */
|
/* RT-Thread basic data type definitions */
|
||||||
typedef signed char rt_int8_t; /**< 8bit integer type */
|
typedef signed char rt_int8_t; /**< 8bit integer type */
|
||||||
typedef signed short rt_int16_t; /**< 16bit integer type */
|
typedef signed short rt_int16_t; /**< 16bit integer type */
|
||||||
typedef signed long rt_int32_t; /**< 32bit integer type */
|
typedef signed int rt_int32_t; /**< 32bit integer type */
|
||||||
typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */
|
typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */
|
||||||
typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */
|
typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */
|
||||||
typedef unsigned long rt_uint32_t; /**< 32bit unsigned integer type */
|
typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */
|
||||||
typedef int rt_bool_t; /**< boolean type */
|
|
||||||
|
|
||||||
/* 32bit CPU */
|
#ifdef ARCH_CPU_64BIT
|
||||||
|
typedef signed long rt_int64_t; /**< 64bit integer type */
|
||||||
|
typedef unsigned long rt_uint64_t; /**< 64bit unsigned integer type */
|
||||||
|
#else
|
||||||
|
typedef signed long long rt_int64_t; /**< 64bit integer type */
|
||||||
|
typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int rt_bool_t; /**< boolean type */
|
||||||
typedef long rt_base_t; /**< Nbit CPU related date type */
|
typedef long rt_base_t; /**< Nbit CPU related date type */
|
||||||
typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */
|
typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */
|
||||||
|
|
||||||
|
@ -648,7 +656,7 @@ struct rt_mailbox
|
||||||
{
|
{
|
||||||
struct rt_ipc_object parent; /**< inherit from ipc_object */
|
struct rt_ipc_object parent; /**< inherit from ipc_object */
|
||||||
|
|
||||||
rt_uint32_t *msg_pool; /**< start address of message buffer */
|
rt_ubase_t *msg_pool; /**< start address of message buffer */
|
||||||
|
|
||||||
rt_uint16_t size; /**< size of message pool */
|
rt_uint16_t size; /**< size of message pool */
|
||||||
|
|
||||||
|
|
|
@ -98,14 +98,14 @@ void rt_hw_interrupt_enable(rt_base_t level);
|
||||||
/*
|
/*
|
||||||
* Context interfaces
|
* Context interfaces
|
||||||
*/
|
*/
|
||||||
void rt_hw_context_switch(rt_uint32_t from, rt_uint32_t to);
|
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
|
||||||
void rt_hw_context_switch_to(rt_uint32_t to);
|
void rt_hw_context_switch_to(rt_ubase_t to);
|
||||||
void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_uint32_t to);
|
void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to);
|
||||||
|
|
||||||
void rt_hw_console_output(const char *str);
|
void rt_hw_console_output(const char *str);
|
||||||
|
|
||||||
void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry);
|
void rt_hw_backtrace(rt_uint32_t *fp, rt_ubase_t thread_entry);
|
||||||
void rt_hw_show_memory(rt_uint32_t addr, rt_uint32_t size);
|
void rt_hw_show_memory(rt_uint32_t addr, rt_size_t size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exception interfaces
|
* Exception interfaces
|
||||||
|
|
|
@ -256,7 +256,7 @@ void rt_page_free(void *addr, rt_size_t npages);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RT_USING_HOOK
|
#ifdef RT_USING_HOOK
|
||||||
void rt_malloc_sethook(void (*hook)(void *ptr, rt_uint32_t size));
|
void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size));
|
||||||
void rt_free_sethook(void (*hook)(void *ptr));
|
void rt_free_sethook(void (*hook)(void *ptr));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -269,9 +269,9 @@ void rt_free_sethook(void (*hook)(void *ptr));
|
||||||
rt_err_t rt_memheap_init(struct rt_memheap *memheap,
|
rt_err_t rt_memheap_init(struct rt_memheap *memheap,
|
||||||
const char *name,
|
const char *name,
|
||||||
void *start_addr,
|
void *start_addr,
|
||||||
rt_uint32_t size);
|
rt_size_t size);
|
||||||
rt_err_t rt_memheap_detach(struct rt_memheap *heap);
|
rt_err_t rt_memheap_detach(struct rt_memheap *heap);
|
||||||
void *rt_memheap_alloc(struct rt_memheap *heap, rt_uint32_t size);
|
void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size);
|
||||||
void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize);
|
void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize);
|
||||||
void rt_memheap_free(void *ptr);
|
void rt_memheap_free(void *ptr);
|
||||||
#endif
|
#endif
|
||||||
|
@ -347,11 +347,11 @@ rt_err_t rt_mb_detach(rt_mailbox_t mb);
|
||||||
rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag);
|
rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag);
|
||||||
rt_err_t rt_mb_delete(rt_mailbox_t mb);
|
rt_err_t rt_mb_delete(rt_mailbox_t mb);
|
||||||
|
|
||||||
rt_err_t rt_mb_send(rt_mailbox_t mb, rt_uint32_t value);
|
rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value);
|
||||||
rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
|
rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
|
||||||
rt_uint32_t value,
|
rt_ubase_t value,
|
||||||
rt_int32_t timeout);
|
rt_int32_t timeout);
|
||||||
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout);
|
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout);
|
||||||
rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg);
|
rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
config ARCH_CPU_64BIT
|
||||||
|
bool
|
||||||
|
|
||||||
config ARCH_ARM
|
config ARCH_ARM
|
||||||
bool
|
bool
|
||||||
|
|
||||||
|
@ -83,6 +86,18 @@ config ARCH_POWERPC
|
||||||
config ARCH_RISCV
|
config ARCH_RISCV
|
||||||
bool
|
bool
|
||||||
|
|
||||||
|
config ARCH_RISCV_FPU
|
||||||
|
bool
|
||||||
|
|
||||||
|
config ARCH_RISCV32
|
||||||
|
select ARCH_RISCV
|
||||||
|
bool
|
||||||
|
|
||||||
|
config ARCH_RISCV64
|
||||||
|
select ARCH_RISCV
|
||||||
|
select ARCH_CPU_64BIT
|
||||||
|
bool
|
||||||
|
|
||||||
config ARCH_IA32
|
config ARCH_IA32
|
||||||
bool
|
bool
|
||||||
|
|
||||||
|
|
13
src/ipc.c
13
src/ipc.c
|
@ -32,6 +32,7 @@
|
||||||
* 2010-11-10 Bernard add IPC reset command implementation.
|
* 2010-11-10 Bernard add IPC reset command implementation.
|
||||||
* 2011-12-18 Bernard add more parameter checking in message queue
|
* 2011-12-18 Bernard add more parameter checking in message queue
|
||||||
* 2013-09-14 Grissiom add an option check in rt_event_recv
|
* 2013-09-14 Grissiom add an option check in rt_event_recv
|
||||||
|
* 2018-10-02 Bernard add 64bit support for mailbox
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
@ -486,10 +487,10 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
|
||||||
|
|
||||||
if (cmd == RT_IPC_CMD_RESET)
|
if (cmd == RT_IPC_CMD_RESET)
|
||||||
{
|
{
|
||||||
rt_uint32_t value;
|
rt_ubase_t value;
|
||||||
|
|
||||||
/* get value */
|
/* get value */
|
||||||
value = (rt_uint32_t)arg;
|
value = (rt_ubase_t)arg;
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
|
@ -1373,7 +1374,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
|
||||||
|
|
||||||
/* init mailbox */
|
/* init mailbox */
|
||||||
mb->size = size;
|
mb->size = size;
|
||||||
mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_uint32_t));
|
mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t));
|
||||||
if (mb->msg_pool == RT_NULL)
|
if (mb->msg_pool == RT_NULL)
|
||||||
{
|
{
|
||||||
/* delete mailbox object */
|
/* delete mailbox object */
|
||||||
|
@ -1436,7 +1437,7 @@ RTM_EXPORT(rt_mb_delete);
|
||||||
* @return the error code
|
* @return the error code
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
|
rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
|
||||||
rt_uint32_t value,
|
rt_ubase_t value,
|
||||||
rt_int32_t timeout)
|
rt_int32_t timeout)
|
||||||
{
|
{
|
||||||
struct rt_thread *thread;
|
struct rt_thread *thread;
|
||||||
|
@ -1567,7 +1568,7 @@ RTM_EXPORT(rt_mb_send_wait);
|
||||||
*
|
*
|
||||||
* @return the error code
|
* @return the error code
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_mb_send(rt_mailbox_t mb, rt_uint32_t value)
|
rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value)
|
||||||
{
|
{
|
||||||
return rt_mb_send_wait(mb, value, 0);
|
return rt_mb_send_wait(mb, value, 0);
|
||||||
}
|
}
|
||||||
|
@ -1583,7 +1584,7 @@ RTM_EXPORT(rt_mb_send);
|
||||||
*
|
*
|
||||||
* @return the error code
|
* @return the error code
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout)
|
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
|
||||||
{
|
{
|
||||||
struct rt_thread *thread;
|
struct rt_thread *thread;
|
||||||
register rt_ubase_t temp;
|
register rt_ubase_t temp;
|
||||||
|
|
|
@ -1189,31 +1189,36 @@ RTM_EXPORT(rt_kprintf);
|
||||||
*/
|
*/
|
||||||
void *rt_malloc_align(rt_size_t size, rt_size_t align)
|
void *rt_malloc_align(rt_size_t size, rt_size_t align)
|
||||||
{
|
{
|
||||||
void *align_ptr;
|
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
void *align_ptr;
|
||||||
|
int uintptr_size;
|
||||||
rt_size_t align_size;
|
rt_size_t align_size;
|
||||||
|
|
||||||
/* align the alignment size to 4 byte */
|
/* sizeof pointer */
|
||||||
align = ((align + 0x03) & ~0x03);
|
uintptr_size = sizeof(void*);
|
||||||
|
uintptr_size -= 1;
|
||||||
|
|
||||||
|
/* align the alignment size to uintptr size byte */
|
||||||
|
align = ((align + uintptr_size) & ~uintptr_size);
|
||||||
|
|
||||||
/* get total aligned size */
|
/* get total aligned size */
|
||||||
align_size = ((size + 0x03) & ~0x03) + align;
|
align_size = ((size + uintptr_size) & ~uintptr_size) + align;
|
||||||
/* allocate memory block from heap */
|
/* allocate memory block from heap */
|
||||||
ptr = rt_malloc(align_size);
|
ptr = rt_malloc(align_size);
|
||||||
if (ptr != RT_NULL)
|
if (ptr != RT_NULL)
|
||||||
{
|
{
|
||||||
/* the allocated memory block is aligned */
|
/* the allocated memory block is aligned */
|
||||||
if (((rt_uint32_t)ptr & (align - 1)) == 0)
|
if (((rt_ubase_t)ptr & (align - 1)) == 0)
|
||||||
{
|
{
|
||||||
align_ptr = (void *)((rt_uint32_t)ptr + align);
|
align_ptr = (void *)((rt_ubase_t)ptr + align);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
align_ptr = (void *)(((rt_uint32_t)ptr + (align - 1)) & ~(align - 1));
|
align_ptr = (void *)(((rt_ubase_t)ptr + (align - 1)) & ~(align - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set the pointer before alignment pointer to the real pointer */
|
/* set the pointer before alignment pointer to the real pointer */
|
||||||
*((rt_uint32_t *)((rt_uint32_t)align_ptr - sizeof(void *))) = (rt_uint32_t)ptr;
|
*((rt_ubase_t *)((rt_ubase_t)align_ptr - sizeof(void *))) = (rt_ubase_t)ptr;
|
||||||
|
|
||||||
ptr = align_ptr;
|
ptr = align_ptr;
|
||||||
}
|
}
|
||||||
|
@ -1232,7 +1237,7 @@ void rt_free_align(void *ptr)
|
||||||
{
|
{
|
||||||
void *real_ptr;
|
void *real_ptr;
|
||||||
|
|
||||||
real_ptr = (void *) * (rt_uint32_t *)((rt_uint32_t)ptr - sizeof(void *));
|
real_ptr = (void *) * (rt_ubase_t *)((rt_ubase_t)ptr - sizeof(void *));
|
||||||
rt_free(real_ptr);
|
rt_free(real_ptr);
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_free_align);
|
RTM_EXPORT(rt_free_align);
|
||||||
|
|
43
src/mem.c
43
src/mem.c
|
@ -11,6 +11,7 @@
|
||||||
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
|
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
|
||||||
* 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer.
|
* 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer.
|
||||||
* 2017-07-14 armink fix rt_realloc issue when new size is 0
|
* 2017-07-14 armink fix rt_realloc issue when new size is 0
|
||||||
|
* 2018-10-02 Bernard Add 64bit support
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -97,12 +98,19 @@ struct heap_mem
|
||||||
/* magic and used flag */
|
/* magic and used flag */
|
||||||
rt_uint16_t magic;
|
rt_uint16_t magic;
|
||||||
rt_uint16_t used;
|
rt_uint16_t used;
|
||||||
|
#ifdef ARCH_CPU_64BIT
|
||||||
|
rt_uint32_t resv;
|
||||||
|
#endif
|
||||||
|
|
||||||
rt_size_t next, prev;
|
rt_size_t next, prev;
|
||||||
|
|
||||||
#ifdef RT_USING_MEMTRACE
|
#ifdef RT_USING_MEMTRACE
|
||||||
|
#ifdef ARCH_CPU_64BIT
|
||||||
|
rt_uint8_t thread[8];
|
||||||
|
#else
|
||||||
rt_uint8_t thread[4]; /* thread name */
|
rt_uint8_t thread[4]; /* thread name */
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */
|
/** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */
|
||||||
|
@ -111,7 +119,12 @@ static rt_uint8_t *heap_ptr;
|
||||||
/** the last entry, always unused! */
|
/** the last entry, always unused! */
|
||||||
static struct heap_mem *heap_end;
|
static struct heap_mem *heap_end;
|
||||||
|
|
||||||
|
#ifdef ARCH_CPU_64BIT
|
||||||
|
#define MIN_SIZE 24
|
||||||
|
#else
|
||||||
#define MIN_SIZE 12
|
#define MIN_SIZE 12
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE)
|
#define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE)
|
||||||
#define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE)
|
#define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE)
|
||||||
|
|
||||||
|
@ -191,8 +204,8 @@ static void plug_holes(struct heap_mem *mem)
|
||||||
void rt_system_heap_init(void *begin_addr, void *end_addr)
|
void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||||
{
|
{
|
||||||
struct heap_mem *mem;
|
struct heap_mem *mem;
|
||||||
rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
|
rt_ubase_t begin_align = RT_ALIGN((rt_ubase_t)begin_addr, RT_ALIGN_SIZE);
|
||||||
rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
|
rt_ubase_t end_align = RT_ALIGN_DOWN((rt_ubase_t)end_addr, RT_ALIGN_SIZE);
|
||||||
|
|
||||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||||
|
|
||||||
|
@ -206,7 +219,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_kprintf("mem init, error begin address 0x%x, and end address 0x%x\n",
|
rt_kprintf("mem init, error begin address 0x%x, and end address 0x%x\n",
|
||||||
(rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
|
(rt_ubase_t)begin_addr, (rt_ubase_t)end_addr);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +228,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||||
heap_ptr = (rt_uint8_t *)begin_align;
|
heap_ptr = (rt_uint8_t *)begin_align;
|
||||||
|
|
||||||
RT_DEBUG_LOG(RT_DEBUG_MEM, ("mem init, heap begin address 0x%x, size %d\n",
|
RT_DEBUG_LOG(RT_DEBUG_MEM, ("mem init, heap begin address 0x%x, size %d\n",
|
||||||
(rt_uint32_t)heap_ptr, mem_size_aligned));
|
(rt_ubase_t)heap_ptr, mem_size_aligned));
|
||||||
|
|
||||||
/* initialize the start of the heap */
|
/* initialize the start of the heap */
|
||||||
mem = (struct heap_mem *)heap_ptr;
|
mem = (struct heap_mem *)heap_ptr;
|
||||||
|
@ -374,14 +387,14 @@ void *rt_malloc(rt_size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_sem_release(&heap_sem);
|
rt_sem_release(&heap_sem);
|
||||||
RT_ASSERT((rt_uint32_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_uint32_t)heap_end);
|
RT_ASSERT((rt_ubase_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_ubase_t)heap_end);
|
||||||
RT_ASSERT((rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
|
RT_ASSERT((rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
|
||||||
RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE - 1)) == 0);
|
RT_ASSERT((((rt_ubase_t)mem) & (RT_ALIGN_SIZE - 1)) == 0);
|
||||||
|
|
||||||
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
||||||
("allocate memory at 0x%x, size: %d\n",
|
("allocate memory at 0x%x, size: %d\n",
|
||||||
(rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
|
(rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
|
||||||
(rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
(rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
||||||
|
|
||||||
RT_OBJECT_HOOK_CALL(rt_malloc_hook,
|
RT_OBJECT_HOOK_CALL(rt_malloc_hook,
|
||||||
(((void *)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size));
|
(((void *)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size));
|
||||||
|
@ -539,7 +552,7 @@ void rt_free(void *rmem)
|
||||||
|
|
||||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||||
|
|
||||||
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
|
RT_ASSERT((((rt_ubase_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
|
||||||
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
|
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
|
||||||
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
|
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
|
||||||
|
|
||||||
|
@ -558,8 +571,8 @@ void rt_free(void *rmem)
|
||||||
|
|
||||||
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
||||||
("release memory 0x%x, size: %d\n",
|
("release memory 0x%x, size: %d\n",
|
||||||
(rt_uint32_t)rmem,
|
(rt_ubase_t)rmem,
|
||||||
(rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
(rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
||||||
|
|
||||||
|
|
||||||
/* protect the heap from concurrent access */
|
/* protect the heap from concurrent access */
|
||||||
|
@ -624,12 +637,12 @@ FINSH_FUNCTION_EXPORT(list_mem, list memory usage information)
|
||||||
int memcheck(void)
|
int memcheck(void)
|
||||||
{
|
{
|
||||||
int position;
|
int position;
|
||||||
rt_uint32_t level;
|
rt_ubase_t level;
|
||||||
struct heap_mem *mem;
|
struct heap_mem *mem;
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
|
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
|
||||||
{
|
{
|
||||||
position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr;
|
||||||
if (position < 0) goto __exit;
|
if (position < 0) goto __exit;
|
||||||
if (position > mem_size_aligned) goto __exit;
|
if (position > mem_size_aligned) goto __exit;
|
||||||
if (mem->magic != HEAP_MAGIC) goto __exit;
|
if (mem->magic != HEAP_MAGIC) goto __exit;
|
||||||
|
@ -664,7 +677,7 @@ int memtrace(int argc, char **argv)
|
||||||
rt_kprintf("\n--memory item information --\n");
|
rt_kprintf("\n--memory item information --\n");
|
||||||
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
|
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
|
||||||
{
|
{
|
||||||
int position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
int position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
rt_kprintf("[0x%08x - ", mem);
|
rt_kprintf("[0x%08x - ", mem);
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
rt_err_t rt_memheap_init(struct rt_memheap *memheap,
|
rt_err_t rt_memheap_init(struct rt_memheap *memheap,
|
||||||
const char *name,
|
const char *name,
|
||||||
void *start_addr,
|
void *start_addr,
|
||||||
rt_uint32_t size)
|
rt_size_t size)
|
||||||
{
|
{
|
||||||
struct rt_memheap_item *item;
|
struct rt_memheap_item *item;
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ rt_err_t rt_memheap_detach(struct rt_memheap *heap)
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_memheap_detach);
|
RTM_EXPORT(rt_memheap_detach);
|
||||||
|
|
||||||
void *rt_memheap_alloc(struct rt_memheap *heap, rt_uint32_t size)
|
void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size)
|
||||||
{
|
{
|
||||||
rt_err_t result;
|
rt_err_t result;
|
||||||
rt_uint32_t free_size;
|
rt_uint32_t free_size;
|
||||||
|
|
|
@ -75,11 +75,11 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
|
||||||
RT_ASSERT(thread != RT_NULL);
|
RT_ASSERT(thread != RT_NULL);
|
||||||
|
|
||||||
if (*((rt_uint8_t *)thread->stack_addr) != '#' ||
|
if (*((rt_uint8_t *)thread->stack_addr) != '#' ||
|
||||||
(rt_uint32_t)thread->sp <= (rt_uint32_t)thread->stack_addr ||
|
(rt_ubase_t)thread->sp <= (rt_ubase_t)thread->stack_addr ||
|
||||||
(rt_uint32_t)thread->sp >
|
(rt_ubase_t)thread->sp >
|
||||||
(rt_uint32_t)thread->stack_addr + (rt_uint32_t)thread->stack_size)
|
(rt_ubase_t)thread->stack_addr + (rt_ubase_t)thread->stack_size)
|
||||||
{
|
{
|
||||||
rt_uint32_t level;
|
rt_ubase_t level;
|
||||||
|
|
||||||
rt_kprintf("thread:%s stack overflow\n", thread->name);
|
rt_kprintf("thread:%s stack overflow\n", thread->name);
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
|
@ -91,7 +91,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
while (level);
|
while (level);
|
||||||
}
|
}
|
||||||
else if ((rt_uint32_t)thread->sp <= ((rt_uint32_t)thread->stack_addr + 32))
|
else if ((rt_ubase_t)thread->sp <= ((rt_ubase_t)thread->stack_addr + 32))
|
||||||
{
|
{
|
||||||
rt_kprintf("warning: %s stack is close to end of stack address.\n",
|
rt_kprintf("warning: %s stack is close to end of stack address.\n",
|
||||||
thread->name);
|
thread->name);
|
||||||
|
@ -159,7 +159,7 @@ void rt_system_scheduler_start(void)
|
||||||
rt_current_thread = to_thread;
|
rt_current_thread = to_thread;
|
||||||
|
|
||||||
/* switch to new thread */
|
/* switch to new thread */
|
||||||
rt_hw_context_switch_to((rt_uint32_t)&to_thread->sp);
|
rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp);
|
||||||
|
|
||||||
/* never come back */
|
/* never come back */
|
||||||
}
|
}
|
||||||
|
@ -214,8 +214,8 @@ void rt_schedule(void)
|
||||||
/* switch to new thread */
|
/* switch to new thread */
|
||||||
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
|
||||||
("[%d]switch to priority#%d "
|
("[%d]switch to priority#%d "
|
||||||
"thread:%.*s(sp:0x%p), "
|
"thread:%.*s(sp:0x%08x), "
|
||||||
"from thread:%.*s(sp: 0x%p)\n",
|
"from thread:%.*s(sp: 0x%08x)\n",
|
||||||
rt_interrupt_nest, highest_ready_priority,
|
rt_interrupt_nest, highest_ready_priority,
|
||||||
RT_NAME_MAX, to_thread->name, to_thread->sp,
|
RT_NAME_MAX, to_thread->name, to_thread->sp,
|
||||||
RT_NAME_MAX, from_thread->name, from_thread->sp));
|
RT_NAME_MAX, from_thread->name, from_thread->sp));
|
||||||
|
@ -228,8 +228,8 @@ void rt_schedule(void)
|
||||||
{
|
{
|
||||||
extern void rt_thread_handle_sig(rt_bool_t clean_state);
|
extern void rt_thread_handle_sig(rt_bool_t clean_state);
|
||||||
|
|
||||||
rt_hw_context_switch((rt_uint32_t)&from_thread->sp,
|
rt_hw_context_switch((rt_ubase_t)&from_thread->sp,
|
||||||
(rt_uint32_t)&to_thread->sp);
|
(rt_ubase_t)&to_thread->sp);
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
@ -243,8 +243,8 @@ void rt_schedule(void)
|
||||||
{
|
{
|
||||||
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("switch in interrupt\n"));
|
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("switch in interrupt\n"));
|
||||||
|
|
||||||
rt_hw_context_switch_interrupt((rt_uint32_t)&from_thread->sp,
|
rt_hw_context_switch_interrupt((rt_ubase_t)&from_thread->sp,
|
||||||
(rt_uint32_t)&to_thread->sp);
|
(rt_ubase_t)&to_thread->sp);
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
|
||||||
/* init thread stack */
|
/* init thread stack */
|
||||||
rt_memset(thread->stack_addr, '#', thread->stack_size);
|
rt_memset(thread->stack_addr, '#', thread->stack_size);
|
||||||
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
|
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
|
||||||
(void *)((char *)thread->stack_addr + thread->stack_size - 4),
|
(void *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)),
|
||||||
(void *)rt_thread_exit);
|
(void *)rt_thread_exit);
|
||||||
|
|
||||||
/* priority init */
|
/* priority init */
|
||||||
|
|
Loading…
Reference in New Issue