arch/riscv: Instead of use Kconfig items to compiler flags. [1/1]

PD#SWPL-68240

Problem:
Refactor for all.

Solution:
Instead of use Kconfig items to compiler flags.

Verify:
N/A

Change-Id: Idba46a2f2c3fc90c4419ea3190f692c1c72c9cf9
Signed-off-by: Xiaohu.Huang <xiaohu.huang@amlogic.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59d803d..be80a88 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,11 +13,9 @@
 	start.S
 	vtable.S
 	handlers.c
-	n200_func.c
 	interrupt_control.c
 )
 
-aml_library_link_libraries(soc__${ARCH})
 aml_library_link_libraries(kernel__${KERNEL})
 
 aml_link_libraries()
diff --git a/compiler_options.cmake b/compiler_options.cmake
index f3d8801..f275f41 100644
--- a/compiler_options.cmake
+++ b/compiler_options.cmake
@@ -11,13 +11,13 @@
 set(linker_flags "${linker_flags},--wrap=_malloc_r,--wrap=_free_r,--wrap=_realloc_r,--wrap=_calloc_r")
 endif()
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=rv32imc -mabi=ilp32 -DN200_REVA=1 -D__ASM -DSOC_${SOC} -imacros${AUTOCONF_H}")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=rv32imc -mabi=ilp32 -imacros${AUTOCONF_H}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --specs=nano.specs --specs=nosys.specs")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=rv32imc -mabi=ilp32 -nostdlib -DN200_REVA=1 -DSOC_${SOC} -imacros${AUTOCONF_H}")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fno-builtin -fgnu89-inline")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=rv32imc -mabi=ilp32 -nostdlib -imacros${AUTOCONF_H}")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --specs=nano.specs --specs=nosys.specs")
-set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=rv32imc -mabi=ilp32 -DN200_REVA=1 -DSOC_${SOC} -imacros${AUTOCONF_H}")
-set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fno-builtin -fgnu89-inline")
+set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=rv32imc -mabi=ilp32 -imacros${AUTOCONF_H}")
 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --specs=nano.specs --specs=nosys.specs")
+set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O2 -g -ffunction-sections -fdata-sections -fno-common -fgnu89-inline")
 
diff --git a/handlers.c b/handlers.c
index 2dc25d5..5ef9b56 100644
--- a/handlers.c
+++ b/handlers.c
@@ -42,7 +42,7 @@
 }
 
 
-#ifdef N200_REVA
+#ifdef CONFIG_N200_REVA
 /*Entry Point for PIC Interrupt Handler*/
 __attribute__((weak)) uint32_t handle_irq(uint32_t int_num);
 
diff --git a/n200_func.c b/n200_func.c
deleted file mode 100644
index b34a9e8..0000000
--- a/n200_func.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
- *
- * SPDX-License-Identifier: MIT
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "n200_func.h"
-#include "register.h"
-#include "common.h"
-#include "n200_timer.h"
-#include "riscv_encoding.h"
-
-// Configure PMP to make all the address space accesable and executable
-void pmp_open_all_space(void){
-    // Config entry0 addr to all 1s to make the range cover all space
-    asm volatile ("li x6, 0xffffffff":::"x6");
-    asm volatile ("csrw pmpaddr0, x6":::);
-    // Config entry0 cfg to make it NAPOT address mode, and R/W/X okay
-    asm volatile ("li x6, 0x7f":::"x6");
-    asm volatile ("csrw pmpcfg0, x6":::);
-}
-
-void switch_m2u_mode(void){
-    clear_csr (mstatus,MSTATUS_MPP);
-    //printf("\nIn the m2u function, the mstatus is 0x%x\n", read_csr(mstatus));
-    //printf("\nIn the m2u function, the mepc is 0x%x\n", read_csr(mepc));
-    asm volatile ("la x6, 1f    ":::"x6");
-    asm volatile ("csrw mepc, x6":::);
-    asm volatile ("mret":::);
-    asm volatile ("1:":::);
-}
-
-uint32_t mtime_lo(void)
-{
-  return *(volatile uint32_t *)(TIMER_CTRL_ADDR + TIMER_MTIME);
-}
-
-
-uint32_t mtime_hi(void)
-{
-  return *(volatile uint32_t *)(TIMER_CTRL_ADDR + TIMER_MTIME + 4);
-}
-
-uint64_t get_timer_value(void)
-{
-  while (1) {
-    uint32_t hi = mtime_hi();
-    uint32_t lo = mtime_lo();
-    if (hi == mtime_hi())
-      return ((uint64_t)hi << 32) | lo;
-  }
-}
-
-uint32_t get_timer_freq(void)
-{
-  return TIMER_FREQ;
-}
-
-uint64_t get_instret_value(void)
-{
-  while (1) {
-    uint32_t hi = read_csr(minstreth);
-    uint32_t lo = read_csr(minstret);
-    if (hi == read_csr(minstreth))
-      return ((uint64_t)hi << 32) | lo;
-  }
-}
-
-uint64_t get_cycle_value(void)
-{
-  while (1) {
-    uint32_t hi = read_csr(mcycleh);
-    uint32_t lo = read_csr(mcycle);
-    if (hi == read_csr(mcycleh))
-      return ((uint64_t)hi << 32) | lo;
-  }
-}
-
-unsigned long interrupt_status_get(void)
-{
-	return read_csr(mstatus) >> 0x3;
-}
-
-void interrupt_disable(void)
-{
-	clear_csr(mstatus, MSTATUS_MIE);
-}
-
-void interrupt_enable(void)
-{
-	set_csr(mstatus, MSTATUS_MIE);
-}
-
-#ifndef N200_REVA
-
-uint32_t __attribute__((noinline)) measure_cpu_freq(size_t n)
-{
-  uint32_t start_mtime, delta_mtime;
-  uint32_t mtime_freq = get_timer_freq();
-
-  // Don't start measuruing until we see an mtime tick
-  uint32_t tmp = mtime_lo();
-  do {
-    start_mtime = mtime_lo();
-  } while (start_mtime == tmp);
-
-  uint32_t start_mcycle = read_csr(mcycle);
-
-  do {
-    delta_mtime = mtime_lo() - start_mtime;
-  } while (delta_mtime < n);
-
-  uint32_t delta_mcycle = read_csr(mcycle) - start_mcycle;
-
-  return (delta_mcycle / delta_mtime) * mtime_freq
-         + ((delta_mcycle % delta_mtime) * mtime_freq) / delta_mtime;
-}
-
-uint32_t get_cpu_freq(void)
-{
-  uint32_t cpu_freq;
-
-  // warm up
-  measure_cpu_freq(1);
-  // measure for real
-  cpu_freq = measure_cpu_freq(100);
-
-  return cpu_freq;
-}
-
-unsigned int xPortIsIsrContext(void)
-{
-	return (read_csr_msubmode & 0xff);
-}
-
-#else
-
-unsigned int xPortIsIsrContext(void)
-{
-	return read_csr_msubmode;
-}
-
-#endif
diff --git a/n200_func.h b/n200_func.h
deleted file mode 100644
index d7eb33e..0000000
--- a/n200_func.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef N200_FUNC_H
-#define N200_FUNC_H
-
-__BEGIN_DECLS
-
-#include "n200_timer.h"
-#include "interrupt_control.h"
-
-void pmp_open_all_space(void);
-
-void switch_m2u_mode(void);
-
-uint32_t get_mtime_freq(void);
-
-uint32_t mtime_lo(void);
-
-uint32_t mtime_hi(void);
-
-uint64_t get_mtime_value(void);
-
-uint64_t get_instret_value(void);
-
-uint64_t get_cycle_value(void);
-
-uint32_t get_cpu_freq(void);
-
-uint32_t __attribute__((noinline)) measure_cpu_freq(size_t n);
-
-void wfe(void);
-
-uint64_t get_timer_value(void);
-
-uint32_t get_timer_freq(void);
-
-void test_handler(void);
-
-int EnableIrq(uint32_t ulIrq);
-
-int DisableIrq(uint32_t ulIrq);
-
-int SetIrqPriority(uint32_t ulIrq, uint32_t ulProi);
-
-int ClearPendingIrq(uint32_t ulIrq);
-
-int RegisterIrq(uint32_t int_num, uint32_t int_priority, function_ptr_t handler);
-
-int UnRegisterIrq(uint32_t ulIrq);
-
-unsigned long interrupt_status_get(void);
-
-void interrupt_disable(void);
-
-void interrupt_enable(void);
-
-unsigned int xPortIsIsrContext(void);
-
-__END_DECLS
-
-#endif
diff --git a/start.S b/start.S
index b44ddc7..df7bbad 100644
--- a/start.S
+++ b/start.S
@@ -9,7 +9,7 @@
 	.type _start,@function
 _start:
 	csrc CSR_MSTATUS, MSTATUS_MIE
-#ifndef N200_REVA
+#ifndef CONFIG_N200_REVA
 	/* Set the the NMI base to share with mtvec by setting CSR_MMISC_CTL */
 	li t0, (0x1 << 9);
 	csrs CSR_MMISC_CTL, t0
@@ -104,7 +104,7 @@
 .long _data_img_start
 #endif
 
-#ifndef N200_REVA
+#ifndef CONFIG_N200_REVA
 	.global disable_mcycle_minstret
 disable_mcycle_minstret:
         csrsi CSR_MCOUNTINHIBIT, 0x5