QEMU中指令添加相关(1):测试程序

QEMU中指令添加相关(1):测试程序

1、汇编.s入口汇编

#See LICENSE forlicense details.

.section
.text.init,“ax”,@progbits

.globl _start

_start:

csrr  t0, mhartid             # read

hardware thread id (hart stands for hardware thread),将线程id放到t0寄存器

bnez  t0, halt                # run only

on the first hardware thread (hartid == 0), halt all the other threads,判断t0值是否为0,为0则向下执行,否则跳转到halt

la    sp, stack_top           # setup

stack pointer //将栈顶的地址加载到sp寄存器中

j     main       #跳转到main标签,即执行主程序

halt:

    j     halt                    # enter

the infinite loop

2、主程序

static int a = 3;

static int b = 256;

static volatile int
uart = (int)0x10013000;

static int
custom48(long addr,long addr1)

{

int ret = 0;

asm volatile (

        "jobget48  %[dest],%[src1],%[src2]"

        :[dest]"=r"(ret)

        :[src1]"r"(addr),[src2]"r"(addr1)

        );

return ret;

}

static int
custom64(long addr,long addr1)

{

int ret = 0;

asm volatile (

        "jobget64

%[dest],%[src1],%[src2]"

        :[dest]"=r"(ret)

        :[src1]"r"(addr),[src2]"r"(addr1)

        );

return ret;

}

void main()

{

int ret1 = 0;

int ret2 = 0;

ret1 = custom48((long)&a,

(long)&b);

ret2 = custom64((long)&a,

(long)&b);

if(ret1)

{

    uart[0] = 'o';

    uart[0] = 'k';

    uart[0] = '4';

}

if(ret2) {

    uart[0] = 'o';

    uart[0] = 'k';

    uart[0] = '6';

}

else

{

    uart[0] = 'e';

    uart[0] = 'r';

    uart[0] = 'r';

}

while(1);

}

3、Makefile文件

PREFIX =
/home/s29363/riscv/install-64-bm/bin/riscv64-unknown-elf-

CC = $(PREFIX)gcc

LD = $(PREFIX)ld

OBJDUMP =
$(PREFIX)objdump

QEMU =
/home/s29363/qemu/qemu-system/install-s64/bin/qemu-system-riscv64

CFLAGS = -static
-mcmodel=medany -fvisibility=hidden -ffunction-sections -fdata-sections
-nostdlib -nostartfiles -nostdinc -g -c -O0

LDFLAGS = -T
/home/s29363/qemu/qemu-system/riscv-test/default.lds --nmagic --gc-sections

QEMU_FLAGS = -nographic
-machine sifive_u -bios none -kernel

TARGET = hello

$(TARGET):start.o
hello.o

    @$(LD) $(LDFLAGS) start.o hello.o -o

$(TARGET)

start.o:

    @$(CC) $(CFLAGS) start.s -o start.o

hello.o:

    @$(CC) $(CFLAGS) hello.c -o hello.o

.PHONY: qemu

qemu:

    $(QEMU) $(QEMU_FLAGS) hello

.PHONY: dis

dis:hello.o

    @$(OBJDUMP)     -d hello.o

    @rm -rf hello.o

.PHONY: clean

clean:

    @rm -rf $(TARGET) start.o hello.o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值