change mips32 code structure

This commit is contained in:
Yanyan Jiang 2017-04-20 02:03:48 -04:00
parent a1f2c82b27
commit 538e2b3c32
11 changed files with 141 additions and 109 deletions

View File

@ -10,7 +10,7 @@ $(shell mkdir -p build/)
# AM library # AM library
AM_PATH = ./am/arch/$(ARCH) AM_PATH = ./am/arch/$(ARCH)
AM_LIB = ./build/libam-$(ARCH).a AM_LIB = ./build/libam-$(ARCH).a
AM_SRC = $(shell find -L $(AM_PATH) -name "*.c" -o -name "*.cpp" -o -name "*.S") AM_SRC = $(shell find -L $(AM_PATH)/src -name "*.c" -o -name "*.cpp" -o -name "*.S")
AM_OBJ = $(addsuffix .o, $(basename $(AM_SRC))) AM_OBJ = $(addsuffix .o, $(basename $(AM_SRC)))
# TODO: managing flags # TODO: managing flags
@ -20,7 +20,7 @@ CXXFLAGS += -std=c++11 -I ./am/ -I./$(AM_PATH)/include -O2 -MD -Wall -Werror -gg
ASFLAGS += -I ./am/ -I./$(AM_PATH)/include ASFLAGS += -I ./am/ -I./$(AM_PATH)/include
# mips32-npc # mips32-npc
CFLAGS += -fno-pic -static -fno-strict-aliasing -fno-builtin -fno-stack-protector -fno-delayed-branch -march=mips32 -D DEPLOY CFLAGS += -fno-pic -static -fno-strict-aliasing -fno-builtin -fno-stack-protector -fno-delayed-branch -mno-abicalls -march=mips32 -D DEPLOY
# x86-qemu # x86-qemu
# CFLAGS += -m32 -fno-builtin -fno-stack-protector -fno-omit-frame-pointer # CFLAGS += -m32 -fno-builtin -fno-stack-protector -fno-omit-frame-pointer
@ -43,15 +43,5 @@ build/a:
@echo "====== execute ======" @echo "====== execute ======"
@qemu-system-i386 -serial stdio build/a.out @qemu-system-i386 -serial stdio build/a.out
# TODO: merge code
mips:
@cd src/makers/$(ARCH); make
mips-linux-gnu-objcopy -O binary src/test/umain $(ARCH)_out/umain.bin
mips-linux-gnu-objdump -d src/test/umain > $(ARCH)_out/code.txt
python python/bin2text.py $(ARCH)_out/umain.bin $(ARCH)_out/ram.txt
python python/gen_bram_coe.py $(ARCH)_out/umain.bin $(ARCH)_out/app.coe
python python/instr_is_legal.py
clean: clean:
rm -rf build/ $(shell find . -name "*.o" -o -name "*.d") rm -rf build/ $(shell find . -name "*.o" -o -name "*.d")

View File

@ -0,0 +1,2 @@
start.o: start.S
mips-linux-gnu-as -march=mips32 start.S -o start.o

View File

@ -0,0 +1,9 @@
.globl _start
_start:
li $sp, 0x0001fffc
jal main
.globl _qemu
_qemu:
nop
jal main

View File

@ -1,3 +1,20 @@
#!/bin/bash #!/bin/bash
DIR=./am/arch/mips32-npc/img
DEST=$1
shift
bash -c "cd $DIR/boot && make"
mips-linux-gnu-ld -T $DIR/loader.ld -e _start -o ./build/kernel.o $DIR/boot/start.o --start-group $@ --end-group
KERN=$(readlink -f ./build/kernel.o)
# generate COE
mips-linux-gnu-objcopy -O binary $KERN ./build/kernel.bin
python $DIR/scripts/bin2text.py ./build/kernel.bin ./build/ram.txt
python $DIR/scripts/gen_bram_coe.py ./build/kernel.bin ./build/app.coe
# check instructions
mips-linux-gnu-objdump -d $KERN | python $DIR/scripts/instr_check.py

View File

@ -1,8 +1,7 @@
SECTIONS SECTIONS
{ {
. = 0x00000000; . = 0x00100000;
.text : AT(0x00100000) { *(.text) } .text : { *(.text) }
.data : { *(.data) } .data : { *(.data) }
.bss : { *(.bss) } .bss : { *(.bss) }
stack_top = .;
} }

View File

@ -28,4 +28,4 @@ with open(outPath, 'w') as f:
f.write("@{0:x} {1:s} \n".format(i, contents)) f.write("@{0:x} {1:s} \n".format(i, contents))
# for i in range(len(bins)/4,fileSize): # for i in range(len(bins)/4,fileSize):
# f.write("@{0:x} {1:d} \n".format(i, 0)) # f.write("@{0:x} {1:d} \n".format(i, 0))
print "Process complete!" print "{0} -> {1} complete!".format(inPath, outPath)

View File

@ -36,4 +36,4 @@ with open(outPath, 'w') as f:
f.write(';') f.write(';')
f.write('\n') f.write('\n')
print "Process complete!" print "{0} -> {1} complete!".format(inPath, outPath)

View File

@ -1,78 +0,0 @@
ADD
ADDU
ADDI
ADDIU
SUB
SUBU
AND
ANDI
OR
ORI
XOR
XORI
NOR
SLT
SLTU
SLTI
SLTIU
SLL
SLLV
SRL
SRLV
SRA
SRAV
CLO
SEH
SEB
CLZ
BEQ
BEQL
BGEZ
BGTZ
BLEZ
BLTZ
BNE
TEQ
TEQI
TGE
TGEI
TGEU
TGEIU
TLT
TLTI
TLTU
TLTIU
TNE
TNEI
J
JAL
JR
MOVN
MOVZ
LUI
MUL
MULT
MULTU
DIV
DIVU
MFHI
MTHI
MFLO
MTLO
LB
LBU
LH
LHU
LW
SB
SH
SW
LWL
LWR
SWL
SWR
MFC0
MTC0
SYSCALL
ERET
NOP

View File

@ -0,0 +1,89 @@
import sys
INST = """ADD
ADDU
ADDI
ADDIU
SUB
SUBU
AND
ANDI
OR
ORI
XOR
XORI
NOR
SLT
SLTU
SLTI
SLTIU
SLL
SLLV
SRL
SRLV
SRA
SRAV
CLO
SEH
SEB
CLZ
BEQ
BEQL
BGEZ
BGTZ
BLEZ
BLTZ
BNE
TEQ
TEQI
TGE
TGEI
TGEU
TGEIU
TLT
TLTI
TLTU
TLTIU
TNE
TNEI
J
JAL
JR
MOVN
MOVZ
LUI
MUL
MULT
MULTU
DIV
DIVU
MFHI
MTHI
MFLO
MTLO
LB
LBU
LH
LHU
LW
SB
SH
SW
LWL
LWR
SWL
SWR
MFC0
MTC0
SYSCALL
ERET
NOP"""
INST = [i.strip() for i in INST.strip().split('\n')]
for line in sys.stdin:
content = line.strip().split('\t')
if len(content) >= 3:
inst = content[2].upper()
if inst not in INST:
print "[INSTcheck] '{0}' is invalid.".format(inst)

View File

@ -1,13 +0,0 @@
with open('mips_out/code.txt') as code_file, open ('python/instr.txt') as instr_file:
instr_list = []
for line in instr_file:
instr_list.append(line[:len(line)-1].lower())
#print instruction set
print instr_list
for line in code_file:
content = line.split('\t\n')
if len(content) >= 3:
if content[2] not in instr_list:
print content[2] + ' is an illegal instruction !'

View File

@ -0,0 +1,17 @@
#include <am.h>
#include <npc.h>
// TODO: implement these functions.
void _trm_init() {
while (1);
}
void _ioe_init() {
}
void _halt(int code) {
}
void _putc(char ch) {
}