Commit 29cee8f5 authored by John P. Willis's avatar John P. Willis

Initial instructions added

parent ba5388b4
OBJS = ilxi.o alu.o asm.o cpu.o error.o host.o storage.o lexer.o OBJS = ilxi.o alu.o asm.o cpu.o error.o host.o storage.o lexer.o inst.o
FBCFLAGS = -g FBCFLAGS = -g
#-d LEXDEBUG #-d LEXDEBUG
...@@ -26,6 +26,9 @@ storage.o: storage.bas ...@@ -26,6 +26,9 @@ storage.o: storage.bas
lexer.o: lexer.bas lexer.o: lexer.bas
fbc $(FBCFLAGS) -o lexer.o -c lexer.bas fbc $(FBCFLAGS) -o lexer.o -c lexer.bas
inst.o: inst.bas
fbc $(FBCFLAGS) -o inst.o -c inst.bas
ilxi.o: ilxi.bas ilxi.o: ilxi.bas
fbc -m ilxi $(FBCFLAGS) -o ilxi.o -c ilxi.bas fbc -m ilxi $(FBCFLAGS) -o ilxi.o -c ilxi.bas
......
...@@ -493,7 +493,7 @@ function asm_operand_count(opcode as ubyte) as ubyte ...@@ -493,7 +493,7 @@ function asm_operand_count(opcode as ubyte) as ubyte
select case opcode select case opcode
case OP_COPY, OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_SHL, OP_SHR, OP_OR, OP_NOT, OP_AND, OP_XOR, OP_EQV case OP_COPY, OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_SHL, OP_SHR, OP_OR, OP_NOT, OP_AND, OP_XOR, OP_EQV
return 2 return 2
case OP_CMP case OP_CMP, OP_LCALL
return 2 return 2
case OP_BRANCH, OP_SCALL, OP_ICALL, OP_PUSH, OP_POP case OP_BRANCH, OP_SCALL, OP_ICALL, OP_PUSH, OP_POP
return 1 return 1
...@@ -512,7 +512,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string ...@@ -512,7 +512,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string
dim operands() as t_operand dim operands() as t_operand
dim operand_count as ubyte dim operand_count as ubyte
dim i as ushort dim i as ushort
dim displacement as ushort dim displacement as ushort
dim ops_following as ubyte dim ops_following as ubyte
dim actual_amod as ubyte dim actual_amod as ubyte
...@@ -529,8 +528,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string ...@@ -529,8 +528,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string
redim operands(operand_count) as t_operand redim operands(operand_count) as t_operand
for i = 1 to operand_count for i = 1 to operand_count
offset = offset + 1 offset = offset + 1
...@@ -541,8 +538,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string ...@@ -541,8 +538,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string
actual_amod = asm_amod_amod(operands(i).amod) actual_amod = asm_amod_amod(operands(i).amod)
'print "for operand "; i; ", got amod byte of "; actual_amod; " (binary "; bin(actual_amod); ")"
displacement = asm_decode_disp(asm_amod_disp(operands(i).amod)) displacement = asm_decode_disp(asm_amod_disp(operands(i).amod))
select case actual_amod select case actual_amod
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "storage.bi" #include "storage.bi"
#include "asm.bi" #include "asm.bi"
#include "ilxi.bi" #include "ilxi.bi"
#include "inst.bi"
sub init_cpu() sub init_cpu()
...@@ -78,122 +79,138 @@ sub cpu() ...@@ -78,122 +79,138 @@ sub cpu()
select case address_mode select case address_mode
case AM_IMM case AM_IMM
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).high_byte = cpu_fetch() .low_byte = cpu_fetch()
operands(i).byte_count = 2 .high_byte = cpu_fetch()
operands(i).immediate = 1 .byte_count = 2
.immediate = 1
end with
case AM_REGD case AM_REGD
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).byte_count = 1 .low_byte = cpu_fetch()
operands(i).displacement = displacement .byte_count = 1
operands(i).register = 1 .register = 1
operands(i).has_displacement = 1 end with
case AM_MEMD case AM_MEMD
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).high_byte = cpu_fetch() .low_byte = cpu_fetch()
operands(i).byte_count = 2 .high_byte = cpu_fetch()
operands(i).displacement = displacement .byte_count = 2
operands(i).memory = 1 .memory = 1
operands(i).has_displacement = 1 end with
case AM_REGDD case AM_REGDD
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).byte_count = 1 .low_byte = cpu_fetch()
operands(i).displacement = displacement .byte_count = 1
operands(i).register = 1 .displacement = displacement
operands(i).has_displacement = 1 .register = 1
.has_displacement = 1
end with
case AM_MEMDD case AM_MEMDD
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).high_byte = cpu_fetch() .low_byte = cpu_fetch()
operands(i).byte_count = 2 .high_byte = cpu_fetch()
operands(i).displacement = displacement .byte_count = 2
operands(i).has_displacement = 1 .displacement = displacement
operands(i).memory = 1 .has_displacement = 1
.memory = 1
end with
case AM_REGI case AM_REGI
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).byte_count = 1 .low_byte = cpu_fetch()
operands(i).register = 1 .byte_count = 1
operands(i).indirect = 1 .register = 1
.indirect = 1
end with
case AM_MEMI case AM_MEMI
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).high_byte = cpu_fetch() .low_byte = cpu_fetch()
operands(i).byte_count = 2 .high_byte = cpu_fetch()
operands(i).memory = 1 .byte_count = 2
operands(i).indirect = 1 .memory = 1
.indirect = 1
end with
case AM_REGID case AM_REGID
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).byte_count = 1 .low_byte = cpu_fetch()
operands(i).displacement = displacement .byte_count = 1
operands(i).register = 1 .displacement = displacement
operands(i).indirect = 1 .register = 1
operands(i).has_displacement = 1 .indirect = 1
.has_displacement = 1
end with
case AM_MEMID case AM_MEMID
operands(i).low_byte = cpu_fetch() with operands(i)
operands(i).high_byte = cpu_fetch() .low_byte = cpu_fetch()
operands(i).byte_count = 2 .high_byte = cpu_fetch()
operands(i).displacement = displacement .byte_count = 2
operands(i).memory = 1 .displacement = displacement
operands(i).has_displacement = 1 .memory = 1
operands(i).indirect = 1 .has_displacement = 1
.indirect = 1
end with
end select end select
next i next i
select case opcode select case opcode
case OP_COPY case OP_COPY
inst_copy operands(1), operands(2)
case OP_ADD case OP_ADD
inst_add operands(1), operands(2)
case OP_SUB case OP_SUB
inst_sub operands(1), operands(2)
case OP_MUL case OP_MUL
inst_mul operands(1), operands(2)
case OP_DIV case OP_DIV
inst_div operands(1), operands(2)
case OP_SHL case OP_SHL
inst_shl operands(1), operands(2)
case OP_SHR case OP_SHR
inst_shr operands(1), operands(2)
case OP_OR case OP_OR
inst_or operands(1), operands(2)
case OP_NOT case OP_NOT
inst_not operands(1), operands(2)
case OP_AND case OP_AND
inst_and operands(1), operands(2)
case OP_XOR case OP_XOR
inst_xor operands(1), operands(2)
case OP_EQV case OP_EQV
inst_eqv operands(1), operands(2)
case OP_CMP case OP_CMP
inst_cmp operands(1), operands(2)
case OP_BRANCH case OP_BRANCH
inst_branch operands(1)
case OP_BEQ case OP_BEQ
inst_beq operands(1)
case OP_BNE case OP_BNE
inst_bne operands(1)
case OP_BLT case OP_BLT
inst_blt operands(1)
case OP_BGT case OP_BGT
inst_bgt operands(1)
case OP_BZ
inst_bz operands(1)
case OP_SCALL case OP_SCALL
inst_scall operands(1)
case OP_LCALL case OP_LCALL
inst_lcall operands(1), operands(2)
case OP_ICALL case OP_ICALL
inst_icall operands(1)
case OP_SRET case OP_SRET
inst_sret
case OP_LRET case OP_LRET
inst_lret
case OP_IRET case OP_IRET
inst_iret
case OP_PUSH case OP_PUSH
inst_push operands(1)
case OP_POP case OP_POP
inst_pop operands(1)
case OP_NOP case OP_NOP
' do nothing
case OP_HLT case OP_HLT
cpu_set_flag FL_HALT inst_hlt
case else case else
end select end select
...@@ -221,7 +238,7 @@ sub cpu() ...@@ -221,7 +238,7 @@ sub cpu()
loop loop
end sub end sub ' cpu()
function cpu_fetch() as ubyte function cpu_fetch() as ubyte
dim t_byte as ubyte = 0 dim t_byte as ubyte = 0
...@@ -230,7 +247,11 @@ function cpu_fetch() as ubyte ...@@ -230,7 +247,11 @@ function cpu_fetch() as ubyte
cpu_state.pc += 1 cpu_state.pc += 1
return t_byte return t_byte
end function end function ' cpu_fetch()
function cpu_get_effective_address(operand as t_operand) as ushort
end function ' cpu_get_effective_address()
sub cpu_dump_state() sub cpu_dump_state()
dim x as t_cpu_state dim x as t_cpu_state
...@@ -255,17 +276,18 @@ sub cpu_dump_state() ...@@ -255,17 +276,18 @@ sub cpu_dump_state()
print " LF="; cpu_get_flag(FL_LESSTHAN); " GF="; cpu_get_flag(FL_GREATERTHAN); " ZF="; cpu_get_flag(FL_ZERO); print " LF="; cpu_get_flag(FL_LESSTHAN); " GF="; cpu_get_flag(FL_GREATERTHAN); " ZF="; cpu_get_flag(FL_ZERO);
print " PL=0 PF="; cpu_get_flag(FL_PARITY); " SF="; cpu_get_flag(FL_SIGN); " DF="; cpu_get_flag(FL_DEBUG); print " PL=0 PF="; cpu_get_flag(FL_PARITY); " SF="; cpu_get_flag(FL_SIGN); " DF="; cpu_get_flag(FL_DEBUG);
print "" print ""
end sub
end sub ' cpu_dump_state()
sub cpu_set_flag(flag as ushort) sub cpu_set_flag(flag as ushort)
cpu_state.fl = cpu_state.fl or flag cpu_state.fl = cpu_state.fl or flag
end sub end sub ' cpu_set_flag()
sub cpu_clear_flag(flag as ushort) sub cpu_clear_flag(flag as ushort)
if cpu_get_flag(flag) = 1 then if cpu_get_flag(flag) = 1 then
cpu_state.fl = (not cpu_state.fl) and flag cpu_state.fl = (not cpu_state.fl) and flag
end if end if
end sub end sub ' cpu_clear_flag()
function cpu_get_flag(flag as ushort) as ubyte function cpu_get_flag(flag as ushort) as ubyte
if (cpu_state.fl and flag) = flag then if (cpu_state.fl and flag) = flag then
...@@ -273,15 +295,15 @@ function cpu_get_flag(flag as ushort) as ubyte ...@@ -273,15 +295,15 @@ function cpu_get_flag(flag as ushort) as ubyte
else else
return 0 return 0
end if end if
end function end function ' cpu_get_flag()
function cpu_get_pl() as ubyte function cpu_get_pl() as ubyte
return (cpu_state.fl and PL_MASK) shr 9 return (cpu_state.fl and PL_MASK) shr 9
end function end function ' cpu_get_pl()
sub cpu_set_pl(privilege_level as ubyte) sub cpu_set_pl(privilege_level as ubyte)
cpu_state.fl or= (privilege_level shl 9) cpu_state.fl or= (privilege_level shl 9)
end sub end sub ' cpu_set_pl()
sub cpu_set_reg_alpha(register as string, value as ushort) sub cpu_set_reg_alpha(register as string, value as ushort)
...@@ -337,7 +359,7 @@ sub cpu_set_reg_alpha(register as string, value as ushort) ...@@ -337,7 +359,7 @@ sub cpu_set_reg_alpha(register as string, value as ushort)
case REG_GP case REG_GP
cpu_state.gp = value cpu_state.gp = value
end select end select
end sub end sub ' cpu_set_reg_alpha()
function cpu_get_reg_alpha(register as string) as ushort function cpu_get_reg_alpha(register as string) as ushort
...@@ -394,4 +416,4 @@ function cpu_get_reg_alpha(register as string) as ushort ...@@ -394,4 +416,4 @@ function cpu_get_reg_alpha(register as string) as ushort
return cpu_state.gp return cpu_state.gp
end select end select
end function end function ' cpu_get_reg_alpha()
\ No newline at end of file \ No newline at end of file
'
' inst.bas
'
#include "inst.bi"
#include "storage.bi"
#include once "asm.bi"
#include "cpu.bi"
#include "ilxi.bi"
sub inst_copy(dest as t_operand, source as t_operand)
end sub ' inst_copy()
sub inst_add(dest as t_operand, source as t_operand)
end sub ' inst_add()
sub inst_sub(dest as t_operand, source as t_operand)
end sub ' inst_sub()
sub inst_mul(dest as t_operand, source as t_operand)
end sub ' inst_mul()
sub inst_div(dest as t_operand, source as t_operand)
end sub ' inst_div()
sub inst_shl(dest as t_operand, count as t_operand)
end sub ' inst_shl()
sub inst_shr(dest as t_operand, count as t_operand)
end sub ' inst_shr()
sub inst_or(dest as t_operand, source as t_operand)
end sub ' inst_or()
sub inst_not(dest as t_operand, source as t_operand)
end sub ' inst_not()
sub inst_and(dest as t_operand, source as t_operand)
end sub ' inst_and()
sub inst_xor(dest as t_operand, source as t_operand)
end sub ' inst_xor()
sub inst_eqv(dest as t_operand, source as t_operand)
end sub ' inst_eqv()
sub inst_cmp(dest as t_operand, source as t_operand)
end sub ' inst_cmp()
sub inst_branch(dest as t_operand)
end sub ' inst_branch()
sub inst_beq(dest as t_operand)
end sub ' inst_beq()
sub inst_bne(dest as t_operand)
end sub ' inst_bne()
sub inst_blt(dest as t_operand)
end sub ' inst_blt()
sub inst_bgt(dest as t_operand)
end sub ' inst_bgt()
sub inst_bz(dest as t_operand)
end sub ' inst_bz()
sub inst_scall(dest as t_operand)
end sub ' inst_scall()
sub inst_lcall(dest as t_operand, page as t_operand)
end sub ' inst_lcall()
sub inst_icall(dest as t_operand)
end sub ' inst_icall()
sub inst_sret()
end sub ' inst_sret()
sub inst_lret()
end sub ' inst_lret()
sub inst_iret()
end sub ' inst_iret()
sub inst_push(dest as t_operand)
end sub ' inst_push()
sub inst_pop(dest as t_operand)
end sub ' inst_pop()
sub inst_hlt()
cpu_set_flag FL_HALT
end sub ' inst_hlt()
\ No newline at end of file
'
' inst.bi
'
#include once "asm.bi"
declare sub inst_copy(dest as t_operand, source as t_operand)
declare sub inst_add(dest as t_operand, source as t_operand)
declare sub inst_sub(dest as t_operand, source as t_operand)
declare sub inst_mul(dest as t_operand, source as t_operand)
declare sub inst_div(dest as t_operand, source as t_operand)
declare sub inst_shl(dest as t_operand, count as t_operand)
declare sub inst_shr(dest as t_operand, count as t_operand)
declare sub inst_or(dest as t_operand, source as t_operand)
declare sub inst_not(dest as t_operand, source as t_operand)
declare sub inst_and(dest as t_operand, source as t_operand)
declare sub inst_xor(dest as t_operand, source as t_operand)
declare sub inst_eqv(dest as t_operand, source as t_operand)
declare sub inst_cmp(dest as t_operand, source as t_operand)
declare sub inst_branch(dest as t_operand)
declare sub inst_beq(dest as t_operand)
declare sub inst_bne(dest as t_operand)
declare sub inst_blt(dest as t_operand)
declare sub inst_bgt(dest as t_operand)
declare sub inst_bz(dest as t_operand)
declare sub inst_scall(dest as t_operand)
declare sub inst_lcall(dest as t_operand, page as t_operand)
declare sub inst_icall(dest as t_operand)
declare sub inst_sret()
declare sub inst_lret()
declare sub inst_iret()
declare sub inst_push(dest as t_operand)
declare sub inst_pop(dest as t_operand)
declare sub inst_hlt()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment