前言:
12年7月份用eCos实时内核来实现一个二层交换的板子(mips),所以先用虚拟机了了解eCos中断处理,内核调度,协议栈等,并写了文章《如何通过gxemul来运行eCos》简单记录当时的过程。实际上用gxemul不久,就改用qemu来运行eCos了。今年有一个朋友在博客问我关于gxemul来运行eCos的问题,所以现在更新一下用qemu运行eCos的操作过程。


用qemu的优点:
1.方便源码级调试
2.可以使用pcnet网卡驱动调试协议栈


操作过程:
需要修改eCos源码,可直接下载我修改的补丁

手动修改,大概过程如下
1.修改寄存器地址0xb800xxxx-->0xb000xxx
-#define MALTA_SER_16550_BASE_A    0xb80003f8
-#define MALTA_SER_16550_BASE_B    0xb80002f8
+#define MALTA_SER_16550_BASE_A    0xb00003f8
+#define MALTA_SER_16550_BASE_B    0xb00002f8


2.修改中断的处理(详细见补丁)
+++ packages/hal/mips/malta/v3_0/include/platform.inc    (revision 24)
@@ -61,6 +61,52 @@
 #include <cyg/hal/hal_arch.h>
 #include <cyg/hal/plf_io.h>
 
+    .macro    hal_vectors_init
+        # If we don~t play nice with a ROM monitor, copy the required
+        # vectors into the proper location.
+    la    t0,0x80000000        # dest addr
+    la    t1,utlb_vector        # source addr
+    la    t3,utlb_vector_end    # end dest addr
+1:    
+    lw    v0,0(t1)        # get word
+    addi    t1,t1,4
+    sw    v0,0(t0)        # write word
+    addi    t0,t0,4
+    bne    t1,t3,1b
+     nop
+
+    la    t0,0x80000180        # dest addr
+    la    t1,other_vector        # source addr
+    la    t3,other_vector_end    # end dest addr
+1:    
+    lw    v0,0(t1)        # get word
+    addi    t1,t1,4
+    sw    v0,0(t0)        # write word
+    addi    t0,t0,4
+    bne    t1,t3,1b
+     nop
+     #if 0
+        .set mips3                      # Set ISA to MIPS 3 to allow cache insns
+    # Now clear the region in the caches
+    la    t0,0x80000000        # dest addr
+    ori    t1,t0,0x200        # source addr
+1:    cache    0x01,0(t0)            # Flush word from data cache
+    cache    0x01,1(t0)
+    cache    0x01,2(t0)
+    cache    0x01,3(t0)
+    nop
+    cache    0x00,0(t0)        # Invalidate icache for word
+    cache    0x00,1(t0)
+    cache    0x00,2(t0)
+    cache    0x00,3(t0)
+    nop
+    addi    t0,t0,0x20
+    bne    t0,t1,1b
+     nop
+        .set mips0                      # reset ISA to default
+            #endif
+    .endm
+
3.到这一步qemu便可以起来了。如果要让pcnet网卡起来,需要修改eCos的pci配置。(详细见补丁)


4.命令
./mipsel-softmmu/qemu-system-mipsel -bios xxx -S -s -nographic -net nic -net tap,ifname=tap1,script=no


5.使用gdb下载代码到qemu

gdb path/of/eCos.elf
>target remote :1234
>load 0x800200bc
>go


6.配置本地电脑的ip,比如192.168.10.2,要与eCos的配置相对应,假设为192.168.10.1
用电脑ping 192.168.10.1 或用eCos ping工具ping 192.168.10.2


7.结束。成功否?

最后发布此文章的博客链接地址