Skip to content

Instantly share code, notes, and snippets.

@yashi
Last active October 3, 2018 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashi/d200601d68cd3d9948600d99aee5ef1f to your computer and use it in GitHub Desktop.
Save yashi/d200601d68cd3d9948600d99aee5ef1f to your computer and use it in GitHub Desktop.
testing cgt
commit f6d27ac92
Author: Yasushi SHOJI <y-shoji@ispace-inc.com>
Date: Wed Sep 26 00:06:46 2018 +0900
add cgt support
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 42cbfc88f..2f72fc7eb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,7 +30,7 @@ assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMa
set(CMAKE_EXECUTABLE_SUFFIX .elf)
if(NOT PROPERTY_LINKER_SCRIPT_DEFINES)
- set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__)
+ set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__CGT_LINKER_CMD__)
endif()
define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ")
@@ -263,6 +263,9 @@ zephyr_system_include_directories(${NOSTDINC})
# Force an error when things like SYS_INIT(foo, ...) occur with a missing header.
zephyr_cc_option(-Werror=implicit-int)
+#zephyr_compile_options(--diag_suppress=383)
+#zephyr_compile_options(--diag_suppress=1)
+#zephyr_compile_options(--display_error_number)
# Prohibit date/time macros, which would make the build non-deterministic
# cc-option(-Werror=date-time)
diff --git a/include/kernel.h b/include/kernel.h
index 040c7c002..bc4f17414 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -769,7 +769,7 @@ extern FUNC_NORETURN void k_thread_user_mode_enter(k_thread_entry_t entry,
* @param ... NULL-terminated list of kernel object pointers
* @req K-THREAD-004
*/
-extern void __attribute__((sentinel))
+extern void
k_thread_access_grant(struct k_thread *thread, ...);
/**
diff --git a/include/linker/linker-tool-cgt.h b/include/linker/linker-tool-cgt.h
new file mode 100644
index 000000000..fada27240
--- /dev/null
+++ b/include/linker/linker-tool-cgt.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2018 ispace, inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/**
+ * @file
+ * @brief TI CGT toolchain linker defs
+ *
+ * This header file defines the necessary macros used by the linker script for
+ * use with the TI CGT linker.
+ */
+
+#ifndef __LINKER_TOOL_CGT_H
+#define __LINKER_TOOL_CGT_H
+
+/*
+ * The GROUP_START() and GROUP_END() macros are used to define a group
+ * of sections located in one memory area, such as RAM, ROM, etc.
+ * The <where> parameter is the name of the memory area.
+ */
+#define GROUP_START(where)
+#define GROUP_END(where)
+
+/*
+ * The GROUP_LINK_IN() macro is located at the end of the section
+ * description and tells the linker that this section is located in
+ * the memory area specified by <where> argument.
+ */
+#define GROUP_LINK_IN(where) > where
+
+/*
+ * As GROUP_LINK_IN(), but takes a second argument indicating the
+ * memory region (e.g. "ROM") for the load address. Used for
+ * initialized data sections that on XIP platforms must be copied at
+ * startup.
+ *
+ * And, because output directives in GNU ld are "sticky", this must
+ * also be used on the first section *after* such an initialized data
+ * section, specifying the same memory region (e.g. "RAM") for both
+ * vregion and lregion.
+ */
+#ifdef CONFIG_XIP
+#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion AT> lregion
+#else
+#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion
+#endif
+
+/*
+ * The GROUP_FOLLOWS_AT() macro is located at the end of the section
+ * and indicates that the section does not specify an address at which
+ * it is to be loaded, but that it follows a section which did specify
+ * such an address
+ */
+#define GROUP_FOLLOWS_AT(where) AT > where
+
+/*
+ * The SECTION_PROLOGUE() macro is used to define the beginning of a section.
+ * The <name> parameter is the name of the section, and the <option> parameter
+ * is to include any special options such as (NOLOAD). Page alignment has its
+ * own parameter since it needs abstraction across the different toolchains.
+ * If not required, the <options> and <align> parameters should be left blank.
+ */
+
+#define SECTION_PROLOGUE(name, options, align) name :
+
+/*
+ * As for SECTION_PROLOGUE(), except that this one must (!) be used
+ * for data sections which on XIP platforms will have differing
+ * virtual and load addresses (i.e. they'll be copied into RAM at
+ * program startup). Such a section must (!) also use
+ * GROUP_LINK_IN_LMA to specify the correct output load address.
+ */
+#ifdef CONFIG_XIP
+#define SECTION_DATA_PROLOGUE_NOLOAD(name, align) \
+ name : type = NOLOAD
+#define SECTION_DATA_PROLOGUE(name, option, align) \
+ name :
+#else
+#error
+#endif
+
+//#define LOADADDR(x) LOAD_START(x)
+
+#define SORT_BY_NAME(x) SORT(x)
+#define OPTIONAL
+
+#define COMMON_SYMBOLS *(COMMON)
+
+#define KEEP(x) x
+#define SORT(x) x
+
+
+#endif /* !__LINKER_TOOL_CGT_H */
diff --git a/include/linker/linker-tool.h b/include/linker/linker-tool.h
index b5b96b263..bff267d70 100644
--- a/include/linker/linker-tool.h
+++ b/include/linker/linker-tool.h
@@ -18,6 +18,8 @@
#if defined(_LINKER)
#if defined(__GCC_LINKER_CMD__)
#include <linker/linker-tool-gcc.h>
+#elif defined(__CGT_LINKER_CMD__)
+#include <linker/linker-tool-cgt.h>
#else
#error "Unknown toolchain"
#endif
diff --git a/include/toolchain.h b/include/toolchain.h
index 3bea0dbc2..8907b0000 100644
--- a/include/toolchain.h
+++ b/include/toolchain.h
@@ -19,6 +19,8 @@
#include <toolchain/xcc.h>
#elif defined(__GNUC__) || (defined(_LINKER) && defined(__GCC_LINKER_CMD__))
#include <toolchain/gcc.h>
+#elif defined(__TI_ARM__)
+#include <toolchain/cgt.h>
#else
#include <toolchain/other.h>
#endif
diff --git a/include/toolchain/cgt.h b/include/toolchain/cgt.h
new file mode 100644
index 000000000..947a6f1fa
--- /dev/null
+++ b/include/toolchain/cgt.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018 ispace, inc
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef TOOLCHAIN_CGT_H
+#define TOOLCHAIN_CGT_H
+
+#include <toolchain/common.h>
+
+#define ALIAS_OF(of) __attribute__((alias(#of)))
+
+#define FUNC_ALIAS(real_func, new_alias, return_type) \
+ return_type new_alias() ALIAS_OF(real_func)
+
+#define ___in_section(a, b, c) \
+ __attribute__((section("." _STRINGIFY(a) \
+ "." _STRINGIFY(b) \
+ "." _STRINGIFY(c))))
+#define __in_section(a, b, c) ___in_section(a, b, c)
+
+#define __in_section_unique(seg) ___in_section(seg, FIXME, __COUNTER__)
+
+#define __kernel_noinit __noinit
+#define __aligned(x) __attribute__((aligned(x)))
+#define __packed __attribute__((packed))
+#define __deprecated __attribute__((deprecated))
+#define __used __attribute__((used))
+#define FUNC_NORETURN __attribute__((noreturn))
+#define __printf_like(f, a)
+#define ARG_UNUSED(x) (void)(x)
+
+#define __weak __attribute__((weak))
+
+#define CODE_UNREACHABLE
+
+#define _ASM_FILE_PROLOGUE
+
+#define GTEXT(sym) .##global sym
+#define GDATA(sym) .##global sym
+
+#define SECTION_SUBSEC_FUNC(sec, subsec, sym) \
+ .##sect ".sec:subsec.sym"
+
+/*
+ * These macros generate absolute symbols for CGT
+ */
+
+/* create an extern reference to the absolute symbol */
+
+#define GEN_OFFSET_EXTERN(name) extern const char name[]
+
+#define GEN_ABS_SYM_BEGIN(name) \
+ EXTERN_C void name(void); \
+ void name(void) \
+ {
+
+#define GEN_ABS_SYM_END }
+
+/*
+ * GNU/ARM backend does not have a proper operand modifier which does not
+ * produces prefix # followed by value, such as %0 for PowerPC, Intel, and
+ * MIPS. The workaround performed here is using %B0 which converts
+ * the value to ~(value). Thus "n"(~(value)) is set in operand constraint
+ * to output (value) in the ARM specific GEN_OFFSET macro.
+ */
+
+#define GEN_ABSOLUTE_SYM(name, value) \
+ __asm__("")
+
+
+
+#endif /* TOOLCHAIN_CGT_H */
diff --git a/kernel/init.c b/kernel/init.c
index 92cd6a48e..bfd153762 100644
--- a/kernel/init.c
+++ b/kernel/init.c
@@ -182,6 +182,7 @@ void _bss_zero(void)
*/
void _data_copy(void)
{
+ *(uint32_t *)0x08000000 = (uint32_t)&__data_rom_start;
(void)memcpy(&__data_ram_start, &__data_rom_start,
((u32_t) &__data_ram_end - (u32_t) &__data_ram_start));
#ifdef CONFIG_CCM_BASE_ADDRESS
diff --git a/kernel/sched.c b/kernel/sched.c
index 108f5102a..ac17bf3f7 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -579,13 +579,33 @@ void _priq_mq_remove(struct _priq_mq *pq, struct k_thread *thread)
}
}
+#ifdef __GCC__
+#define CTZ __builtin_ctz
+#else
+#define CTZ __ctz
+static int __ctz(unsigned int v)
+{
+ int i;
+
+ if (!v) return 32;
+
+ for (i=0; i<32; i++) {
+ if (v & 1)
+ break;
+ v = v >> 1;
+ }
+
+ return i;
+}
+#endif
+
struct k_thread *_priq_mq_best(struct _priq_mq *pq)
{
if (!pq->bitmask) {
return NULL;
}
- sys_dlist_t *l = &pq->queues[__builtin_ctz(pq->bitmask)];
+ sys_dlist_t *l = &pq->queues[CTZ(pq->bitmask)];
return CONTAINER_OF(sys_dlist_peek_head(l),
struct k_thread, base.qnode_dlist);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment