change mips32 code structure
This commit is contained in:
parent
a1f2c82b27
commit
538e2b3c32
14
Makefile
14
Makefile
|
@ -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")
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
start.o: start.S
|
||||||
|
mips-linux-gnu-as -march=mips32 start.S -o start.o
|
|
@ -0,0 +1,9 @@
|
||||||
|
.globl _start
|
||||||
|
_start:
|
||||||
|
li $sp, 0x0001fffc
|
||||||
|
jal main
|
||||||
|
|
||||||
|
.globl _qemu
|
||||||
|
_qemu:
|
||||||
|
nop
|
||||||
|
jal main
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x00000000;
|
. = 0x00100000;
|
||||||
.text : AT(0x00100000) { *(.text) }
|
.text : { *(.text) }
|
||||||
.data : { *(.data) }
|
.data : { *(.data) }
|
||||||
.bss : { *(.bss) }
|
.bss : { *(.bss) }
|
||||||
stack_top = .;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
|
|
@ -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)
|
|
@ -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 !'
|
|
|
@ -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) {
|
||||||
|
}
|
Loading…
Reference in New Issue