封装龙芯1c上常见外设接口,便于在裸机程序或实时操作系统中使用,类似于STM32库,正在不断添加中。Git地址是https://gitee.com/caogos/OpenLoongsonLib1c
封装龙芯1c库难免会涉及到汇编程序,本文以c语言main()函数中调用一个用汇编实现的禁止中断的函数。源码如下
test_entry.S
#define v0 $2 /* return value */
#define v1 $3
#define ra $31 /* return address */
#define CP0_STATUS $12
.section ".text", "ax"
.set noreorder
.globl irq_disable
irq_disable:
mfc0 v0, CP0_STATUS
and v1, v0, 0xfffffffe
mtc0 v1, CP0_STATUS
jr ra
nop
.set reorder
main.c
#include <stdio.h>
extern void irq_disable();
int main(void)
{
irq_disable();
}
使用命令“mipsel-linux-gcc test_entry.S main.c -o test”编译