Skip to content

Commit 4584054

Browse files
committed
[bsp] Add mipssim bsp
This bsp is used for test MIPS base code in simutator, implemented basic MIPS cpuport and serial port driver. Signed-off-by: Jiaxun Yang <[email protected]>
1 parent 9ef9869 commit 4584054

File tree

16 files changed

+1027
-0
lines changed

16 files changed

+1027
-0
lines changed

bsp/mipssim/Kconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
mainmenu "RT-Thread Configuration"
2+
3+
config BSP_DIR
4+
string
5+
option env="BSP_ROOT"
6+
default "."
7+
8+
config RTT_DIR
9+
string
10+
option env="RTT_ROOT"
11+
default "../.."
12+
13+
# you can change the RTT_ROOT default "../.." to your rtthread_root,
14+
# example : default "F:/git_repositories/rt-thread"
15+
16+
config PKGS_DIR
17+
string
18+
option env="PKGS_ROOT"
19+
default "packages"
20+
21+
source "$RTT_DIR/Kconfig"
22+
source "$RTT_DIR/libcpu/mips/common/Kconfig"
23+
source "$PKGS_DIR/Kconfig"
24+
25+
config MIPSSIM
26+
bool
27+
select ARCH_MIPS
28+
select RT_USING_COMPONENTS_INIT
29+
select RT_USING_USER_MAIN
30+
select RT_USING_DEVICE
31+
default y

bsp/mipssim/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
MIPSSIM 板级支持包
2+
3+
4+
---
5+
6+
## 1. 简介
7+
8+
本BSP用于在MIPSSIM或QEMU的MIPSSIM Machine模拟器中运行RT-Thread。
9+
使用mips-sde-elf工具链编译。
10+
在QEMU中使用如下命令运行:
11+
```
12+
qemu-system-mipsel -M mipssim -cpu P5600 -nographic -kernel ./rtthread.elf
13+
```
14+
15+
MIPSSIM拥有一个8250串口和一个MIPSNET网卡外设,本BSP目前仅实现了串口。

bsp/mipssim/SConscript

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
objs = []
5+
list = os.listdir(cwd)
6+
7+
for d in list:
8+
path = os.path.join(cwd, d)
9+
if os.path.isfile(os.path.join(path, 'SConscript')):
10+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
11+
12+
Return('objs')

bsp/mipssim/SConstruct

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import sys
3+
import rtconfig
4+
5+
from rtconfig import RTT_ROOT
6+
7+
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
8+
from building import *
9+
10+
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
11+
12+
rtconfig.AFLAGS += ' -I' + str(Dir('#'))
13+
14+
DefaultEnvironment(tools=[])
15+
env = Environment(tools = ['mingw'],
16+
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
17+
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
18+
AR = rtconfig.AR, ARFLAGS = '-rc',
19+
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
20+
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
21+
22+
Export('RTT_ROOT')
23+
Export('rtconfig')
24+
25+
26+
# prepare building environment
27+
objs = PrepareBuilding(env, RTT_ROOT)
28+
29+
env.Replace(LINKFLAGS = rtconfig.LFLAGS)
30+
31+
if GetDepend('RT_USING_FPU'):
32+
env['CCFLAGS'] = env['CCFLAGS'].replace('-msoft-float', '-mhard-float')
33+
env['ASFLAGS'] = env['ASFLAGS'].replace('-msoft-float', '-mhard-float')
34+
env['CXXFLAGS'] = env['CXXFLAGS'].replace('-msoft-float', '-mhard-float')
35+
env['LINKFLAGS'] = env['LINKFLAGS'].replace('-msoft-float', '-mhard-float')
36+
37+
# make a building
38+
DoBuilding(TARGET, objs)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = Glob('*.c')
5+
6+
group = DefineGroup('Applications', src, depend = [''])
7+
8+
Return('group')

bsp/mipssim/applications/main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2018-05-10 zhuangwei first version
9+
*/
10+
11+
#include <rtthread.h>
12+
13+
int main(int argc, char** argv)
14+
{
15+
16+
return 0;
17+
}

bsp/mipssim/drivers/SConscript

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = Glob('*.c') + Glob('*.cpp') + Glob('*_gcc.S')
5+
6+
CPPPATH = [cwd]
7+
8+
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
9+
10+
Return('group')

bsp/mipssim/drivers/board.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-12-04 Jiaxun Yang Initial version
9+
*/
10+
11+
/**
12+
* @addtogroup mipssim
13+
*/
14+
15+
/*@{*/
16+
17+
#include <rtthread.h>
18+
#include <rthw.h>
19+
20+
#include "mips_regs.h"
21+
#include "exception.h"
22+
#include "drv_uart.h"
23+
24+
#define CPU_HZ (100 * 1000 * 1000)
25+
#define RT_HW_HEAP_END (0x80000000 + 64 * 1024 * 1024)
26+
27+
extern unsigned char __bss_end;
28+
29+
/**
30+
* this function will reset CPU
31+
*
32+
*/
33+
void rt_hw_cpu_reset(void)
34+
{
35+
rt_kprintf("reboot system...\n");
36+
while (1);
37+
}
38+
39+
/**
40+
* this function will shutdown CPU
41+
*
42+
*/
43+
void rt_hw_cpu_shutdown(void)
44+
{
45+
rt_kprintf("shutdown...\n");
46+
47+
while (1);
48+
}
49+
50+
51+
/**
52+
* This is the timer interrupt service routine.
53+
*/
54+
void rt_hw_timer_handler(void)
55+
{
56+
unsigned int count;
57+
58+
count = read_c0_compare();
59+
write_c0_compare(count);
60+
write_c0_count(0);
61+
/* increase a OS tick */
62+
rt_tick_increase();
63+
}
64+
65+
/**
66+
* This function will initial OS timer
67+
*/
68+
void rt_hw_timer_init(void)
69+
{
70+
write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND);
71+
write_c0_count(0);
72+
mips_unmask_cpu_irq(7);
73+
}
74+
75+
/**
76+
* Board level initialization
77+
*/
78+
void rt_hw_board_init(void)
79+
{
80+
rt_hw_exception_init();
81+
82+
/* init hardware interrupt */
83+
rt_hw_interrupt_init();
84+
85+
#ifdef RT_USING_FPU
86+
/* init hardware fpu */
87+
rt_hw_fpu_init();
88+
#endif
89+
90+
#ifdef RT_USING_SERIAL
91+
/* init hardware UART device */
92+
rt_hw_uart_init();
93+
/* set console device */
94+
rt_console_set_device("uart");
95+
#endif
96+
97+
#ifdef RT_USING_HEAP
98+
rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END);
99+
#endif
100+
101+
/* init operating system timer */
102+
rt_hw_timer_init();
103+
104+
105+
#ifdef RT_USING_COMPONENTS_INIT
106+
rt_components_board_init();
107+
#endif
108+
109+
rt_kprintf("Current SR: 0x%08x\n", read_c0_status());
110+
111+
}
112+
113+
/*@}*/

bsp/mipssim/drivers/cpuinit_gcc.S

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-12-04 Jiaxun Yang Initial version
9+
*/
10+
11+
#ifndef __ASSEMBLY__
12+
#define __ASSEMBLY__
13+
#endif
14+
15+
#include <mips.h>
16+
17+
.section ".text", "ax"
18+
.set noreorder
19+
20+
.globl rt_cpu_early_init
21+
rt_cpu_early_init:
22+
mfc0 t0, CP0_CONFIG
23+
ori t0, 3
24+
mtc0 t0, CP0_CONFIG
25+
ehb
26+
jr ra

0 commit comments

Comments
 (0)