initial commit

This commit is contained in:
2026-04-12 22:20:18 +08:00
commit 190c2edbb2
155 changed files with 36314 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
#ifndef common_func_H
#define common_func_H
#include <larchintrin.h>
typedef signed int S32;
typedef unsigned int U32;
typedef unsigned int uint32_t;
typedef signed short S16;
typedef unsigned short U16;
typedef signed char S8;
typedef unsigned char U8;
typedef long long S64;
typedef unsigned long long U64;
void RegWrite(unsigned int addr,unsigned int var);
unsigned int RegRead(unsigned int addr);
void SaveMemory(unsigned int *DestAddr, unsigned int *SrcAddr, unsigned int Size);
static inline U32 csr_readl(U32 reg)
{
return __csrrd_w(reg);
}
static inline U64 csr_readq(U32 reg)
{
return __csrrd_w(reg);
}
static inline void csr_writel(U32 val, U32 reg)
{
__csrwr_w(val, reg);
}
static inline void csr_writeq(U64 val, U32 reg)
{
__csrwr_w(val, reg);
}
static inline U32 csr_xchgl(U32 val, U32 mask, U32 reg)
{
return __csrxchg_w(val, mask, reg);
}
static inline U64 csr_xchgq(U64 val, U64 mask, U32 reg)
{
return __csrxchg_w(val, mask, reg);
}
#define CacheOp_Cache 0x03
#define CacheOp_Op 0x1c
#define Cache_I 0x00
#define Cache_D 0x01
#define Cache_V 0x02
#define Cache_S 0x03
#define Index_Invalidate 0x08
#define Index_Writeback_Inv 0x08
#define Hit_Invalidate 0x10
#define Hit_Writeback_Inv 0x10
#define Index_Invalidate_I (Cache_I | Index_Invalidate)
#define Index_Writeback_Inv_D (Cache_D | Index_Writeback_Inv)
#define Hit_Invalidate_I (Cache_I | Hit_Invalidate)
#define Hit_Writeback_Inv_D (Cache_D | Hit_Writeback_Inv)
#define cache_op(op, addr) \
__asm__ __volatile__( \
" cacop %0, %1 \n" \
: \
: "i" (op), "R" (*(unsigned char *)(addr)))
static inline void flush_icache_line_indexed(unsigned long addr)
{
cache_op(Index_Invalidate_I, addr);
}
static inline void flush_dcache_line_indexed(unsigned long addr)
{
cache_op(Index_Writeback_Inv_D, addr);
}
static inline void flush_icache_line(unsigned long addr)
{
cache_op(Hit_Invalidate_I, addr);
}
static inline void flush_dcache_line(unsigned long addr)
{
cache_op(Hit_Writeback_Inv_D, addr);
}
static inline void init_dcache_line(unsigned long addr)
{
cache_op(0x01, addr);
}
#endif

View File

@@ -0,0 +1,22 @@
#ifndef _CONFREG_TIME_H_H
#define _CONFREG_TIME_H_H
extern unsigned long CONFREG_TIMER_BASE;
extern unsigned long CONFREG_CLOCKS_PER_SEC;
extern unsigned long CORE_CLOCKS_PER_SEC;
#define MSEC_PER_SEC 1000L
#define USEC_PER_MSEC 1000L
#define NSEC_PER_USEC 1000L
#define NSEC_PER_MSCEC 1000000L
#define USEC_PER_SEC 1000000L
#define NSEC_PER_SEC 1000000000L
#define FSEC_PER_SEC 1000000000000000LL
unsigned long get_cpu_clock_count();//获取处理器核统计的时钟周期数
unsigned long get_confreg_clock_count();//获取CONFREG的时钟周期数
unsigned long get_clock_count();//根据是否存在宏 USE_CPU_CLOCK_COUNT 输出 处理器核/CONFREG 的计数器值
unsigned long get_ns(void);//获取统计的纳秒数
unsigned long get_us(void);//获取统计的微秒数
#endif

View File

@@ -0,0 +1,8 @@
#ifndef CORE_TIME_H
#define CORE_TIME_H
#include "common_func.h"
void delay_ms(uint32_t ms);
#endif

View File

@@ -0,0 +1,21 @@
#ifndef DVI_H
#define DVI_H
#include "common_func.h"
#define DVI_BASEADDR 0xbf100000
#define DVI_RECT_DIR (DVI_BASEADDR + 0x0)
#define DVI_RECT_L_W (DVI_BASEADDR + 0x4)
#define DVI_SQU_DIR (DVI_BASEADDR + 0x8)
#define DVI_SQU_R (DVI_BASEADDR + 0xC)
// draw rect on DVI to x y
void DVI_Draw_Rect(uint32_t x, uint32_t y, uint32_t l, uint32_t w);
// draw squ on DVI to x y r
void DVI_Draw_SQU(uint32_t x, uint32_t y, uint32_t r);
#endif // DVI

View File

@@ -0,0 +1,31 @@
#ifndef _HANDLER_H
#define _HANDLER_H
#define ex_tlb_load_present_type 0x1
#define ex_tlb_store_present_type 0x2
#define ex_tlb_fetch_present_type 0x3
#define ex_tlb_modify_type 0x4
#define ex_tlb_read_inhibit_type 0x5
#define ex_tlb_execute_inhibit_type 0x6
#define ex_tlb_privilege_error_type 0x7
#define ex_ade_type 0x8
#define ex_align_check_type 0x9
#define ex_bound_check_error_type 0xa
#define ex_syscall_type 0xb
#define ex_break_type 0xc
#define ex_ri_type 0xd
#define ex_previlege_inst_type 0xe
#define ex_fpe_disable_type 0xf
#define ex_lsx_disable_type 0x10
#define ex_lasx_disable_type 0x11
#define ex_fpe_type 0x12
#define ex_watch_type 0x13
#define ex_bt_disable_type 0x14
#define ex_bt_help_type 0x15
#define ex_psi_type 0x16
#define ex_hypcall_type 0x17
#define ex_field_change_type 0x18
#define ex_sate_related_type 0x19
#define ex_tlb_refill 0x3f
#endif

View File

@@ -0,0 +1,14 @@
#ifndef LED_H
#define LED_H
#include "common_func.h"
#define LEDS_BASEADDR 0xbf20f300
#define LEDS_GPIO_DATA (LEDS_BASEADDR + 0x00)
// set leds pin
void setLedPin(uint32_t data);
void toggleLedPin(uint32_t data);
#endif

View File

@@ -0,0 +1,104 @@
#ifndef _SYS_REGDEF_H
#define _SYS_REGDEF_H
# define zero $r0
# define ra $r1
# define tp $r2
# define sp $r3
# define a0 $r4
# define a1 $r5
# define a2 $r6
# define a3 $r7
# define a4 $r8
# define a5 $r9
# define a6 $r10
# define a7 $r11
# define v0 $r4
# define v1 $r5
# define t0 $r12
# define t1 $r13
# define t2 $r14
# define t3 $r15
# define t4 $r16
# define t5 $r17
# define t6 $r18
# define t7 $r19
# define t8 $r20
# define x $r21
# define fp $r22
# define s0 $r23
# define s1 $r24
# define s2 $r25
# define s3 $r26
# define s4 $r27
# define s5 $r28
# define s6 $r29
# define s7 $r30
# define s8 $r31
# define fa0 $f0
# define fa1 $f1
# define fa2 $f2
# define fa3 $f3
# define fa4 $f4
# define fa5 $f5
# define fa6 $f6
# define fa7 $f7
# define fv0 $f0
# define fv1 $f1
# define ft0 $f8
# define ft1 $f9
# define ft2 $f10
# define ft3 $f11
# define ft4 $f12
# define ft5 $f13
# define ft6 $f14
# define ft7 $f15
# define ft8 $f16
# define ft9 $f17
# define ft10 $f18
# define ft11 $f19
# define ft12 $f20
# define ft13 $f21
# define ft14 $f22
# define ft15 $f23
# define fs0 $f24
# define fs1 $f25
# define fs2 $f26
# define fs3 $f27
# define fs4 $f28
# define fs5 $f29
# define fs6 $f30
# define fs7 $f31
#define csr_crmd 0x0
#define csr_prmd 0x1
#define csr_euen 0x2
#define csr_ecfg 0x4
#define csr_estat 0x5
#define csr_era 0x6
#define csr_badv 0x7
#define csr_eentry 0xc
#define csr_tlbidx 0x10
#define csr_tlbehi 0x11
#define csr_tlbelo0 0x12
#define csr_tlbelo1 0x13
#define csr_asid 0x18
#define csr_pgdl 0x19
#define csr_pgdh 0x1a
#define csr_pgd 0x1b
#define csr_cpuid 0x20
#define csr_save0 0x30
#define csr_save1 0x31
#define csr_save2 0x32
#define csr_save3 0x33
#define csr_tid 0x40
#define csr_tcfg 0x41
#define csr_tval 0x42
#define csr_ticlr 0x44
#define csr_llbctl 0x60
#define csr_tlbrentry 0x88
#define csr_dmw0 0x180
#define csr_dmw1 0x181
#endif

View File

@@ -0,0 +1,17 @@
// seg7.h
#ifndef SEG7_H
#define SEG7_H
#include "common_func.h"
#define SEG7_BASEADDR 0xbf20f200
#define SEG7_SELECT (SEG7_BASEADDR + 0x00)
#define SEG7_NUM (SEG7_BASEADDR + 0x04)
// set seg num
void setSegNum(uint32_t seg1,uint32_t num1,uint32_t seg2,uint32_t num2);
#endif

View File

@@ -0,0 +1,12 @@
#ifndef _UART_PRINT_H
#define _UART_PRINT_H
#define UART_PRINT(str)\
la a0, 1f;\
.section .rodata ;\
1: ;\
.asciz str ;\
.section .init ;\
bl %plt(puts)
#endif