Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
John P. Willis
ilxi
Commits
29cee8f5
Commit
29cee8f5
authored
May 26, 2015
by
John P. Willis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial instructions added
parent
ba5388b4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
269 additions
and
94 deletions
+269
-94
Makefile
Makefile
+4
-1
asm.bas
asm.bas
+1
-6
cpu.bas
cpu.bas
+109
-87
inst.bas
inst.bas
+121
-0
inst.bi
inst.bi
+34
-0
No files found.
Makefile
View file @
29cee8f5
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
#-d LEXDEBUG
...
...
@@ -26,6 +26,9 @@ storage.o: storage.bas
lexer.o
:
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
fbc
-m
ilxi
$(FBCFLAGS)
-o
ilxi.o
-c
ilxi.bas
...
...
asm.bas
View file @
29cee8f5
...
...
@@ -493,7 +493,7 @@ function asm_operand_count(opcode as ubyte) as ubyte
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
return 2
case OP_CMP
case OP_CMP
, OP_LCALL
return 2
case OP_BRANCH, OP_SCALL, OP_ICALL, OP_PUSH, OP_POP
return 1
...
...
@@ -512,7 +512,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string
dim operands() as t_operand
dim operand_count as ubyte
dim i as ushort
dim displacement as ushort
dim ops_following as ubyte
dim actual_amod as ubyte
...
...
@@ -529,8 +528,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string
redim operands(operand_count) as t_operand
for i = 1 to operand_count
offset = offset + 1
...
...
@@ -541,8 +538,6 @@ function asm_disassemble(page as ushort, offset as ushort) as string
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))
select case actual_amod
...
...
cpu.bas
View file @
29cee8f5
...
...
@@ -6,6 +6,7 @@
#include "storage.bi"
#include "asm.bi"
#include "ilxi.bi"
#include "inst.bi"
sub init_cpu()
...
...
@@ -78,122 +79,138 @@ sub cpu()
select case address_mode
case AM_IMM
operands(i).low_byte = cpu_fetch()
operands(i).high_byte = cpu_fetch()
operands(i).byte_count = 2
operands(i).immediate = 1
with operands(i)
.low_byte = cpu_fetch()
.high_byte = cpu_fetch()
.byte_count = 2
.immediate = 1
end with
case AM_REGD
operands(i)
.low_byte = cpu_fetch()
operands(i).byte_count = 1
operands(i).displacement = displacement
operands(i)
.register = 1
operands(i).has_displacement = 1
with
operands(i)
.low_byte = cpu_fetch()
.byte_count = 1
.register = 1
end with
case AM_MEMD
operands(i)
.low_byte = cpu_fetch()
operands(i).high
_byte = cpu_fetch()
operands(i).byte_count = 2
operands(i).displacement = displacement
operands(i)
.memory = 1
operands(i).has_displacement = 1
with
operands(i)
.low
_byte = cpu_fetch()
.high_byte = cpu_fetch()
.byte_count = 2
.memory = 1
end with
case AM_REGDD
operands(i).low_byte = cpu_fetch()
operands(i).byte_count = 1
operands(i).displacement = displacement
operands(i).register = 1
operands(i).has_displacement = 1
with operands(i)
.low_byte = cpu_fetch()
.byte_count = 1
.displacement = displacement
.register = 1
.has_displacement = 1
end with
case AM_MEMDD
operands(i).low_byte = cpu_fetch()
operands(i).high_byte = cpu_fetch()
operands(i).byte_count = 2
operands(i).displacement = displacement
operands(i).has_displacement = 1
operands(i).memory = 1
with operands(i)
.low_byte = cpu_fetch()
.high_byte = cpu_fetch()
.byte_count = 2
.displacement = displacement
.has_displacement = 1
.memory = 1
end with
case AM_REGI
operands(i).low_byte = cpu_fetch()
operands(i).byte_count = 1
operands(i).register = 1
operands(i).indirect = 1
with operands(i)
.low_byte = cpu_fetch()
.byte_count = 1
.register = 1
.indirect = 1
end with
case AM_MEMI
operands(i).low_byte = cpu_fetch()
operands(i).high_byte = cpu_fetch()
operands(i).byte_count = 2
operands(i).memory = 1
operands(i).indirect = 1
with operands(i)
.low_byte = cpu_fetch()
.high_byte = cpu_fetch()
.byte_count = 2
.memory = 1
.indirect = 1
end with
case AM_REGID
operands(i).low_byte = cpu_fetch()
operands(i).byte_count = 1
operands(i).displacement = displacement
operands(i).register = 1
operands(i).indirect = 1
operands(i).has_displacement = 1
with operands(i)
.low_byte = cpu_fetch()
.byte_count = 1
.displacement = displacement
.register = 1
.indirect = 1
.has_displacement = 1
end with
case AM_MEMID
operands(i).low_byte = cpu_fetch()
operands(i).high_byte = cpu_fetch()
operands(i).byte_count = 2
operands(i).displacement = displacement
operands(i).memory = 1
operands(i).has_displacement = 1
operands(i).indirect = 1
with operands(i)
.low_byte = cpu_fetch()
.high_byte = cpu_fetch()
.byte_count = 2
.displacement = displacement
.memory = 1
.has_displacement = 1
.indirect = 1
end with
end select
next i
select case opcode
case OP_COPY
inst_copy operands(1), operands(2)
case OP_ADD
inst_add operands(1), operands(2)
case OP_SUB
inst_sub operands(1), operands(2)
case OP_MUL
inst_mul operands(1), operands(2)
case OP_DIV
inst_div operands(1), operands(2)
case OP_SHL
inst_shl operands(1), operands(2)
case OP_SHR
case OP_OR
inst_shr operands(1), operands(2)
case OP_OR
inst_or operands(1), operands(2)
case OP_NOT
inst_not operands(1), operands(2)
case OP_AND
inst_and operands(1), operands(2)
case OP_XOR
inst_xor operands(1), operands(2)
case OP_EQV
inst_eqv operands(1), operands(2)
case OP_CMP
inst_cmp operands(1), operands(2)
case OP_BRANCH
inst_branch operands(1)
case OP_BEQ
inst_beq operands(1)
case OP_BNE
inst_bne operands(1)
case OP_BLT
inst_blt operands(1)
case OP_BGT
inst_bgt operands(1)
case OP_BZ
inst_bz operands(1)
case OP_SCALL
inst_scall operands(1)
case OP_LCALL
inst_lcall operands(1), operands(2)
case OP_ICALL
inst_icall operands(1)
case OP_SRET
inst_sret
case OP_LRET
inst_lret
case OP_IRET
inst_iret
case OP_PUSH
inst_push operands(1)
case OP_POP
inst_pop operands(1)
case OP_NOP
' do nothing
case OP_HLT
cpu_set_flag FL_HALT
inst_hlt
case else
end select
...
...
@@ -221,7 +238,7 @@ sub cpu()
loop
end sub
end sub
' cpu()
function cpu_fetch() as ubyte
dim t_byte as ubyte = 0
...
...
@@ -230,7 +247,11 @@ function cpu_fetch() as ubyte
cpu_state.pc += 1
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()
dim x as t_cpu_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 " PL=0 PF="; cpu_get_flag(FL_PARITY); " SF="; cpu_get_flag(FL_SIGN); " DF="; cpu_get_flag(FL_DEBUG);
print ""
end sub
end sub ' cpu_dump_state()
sub cpu_set_flag(flag as ushort)
cpu_state.fl = cpu_state.fl or flag
end sub
end sub
' cpu_set_flag()
sub cpu_clear_flag(flag as ushort)
if cpu_get_flag(flag) = 1 then
cpu_state.fl = (not cpu_state.fl) and flag
end if
end sub
end sub
' cpu_clear_flag()
function cpu_get_flag(flag as ushort) as ubyte
if (cpu_state.fl and flag) = flag then
...
...
@@ -273,15 +295,15 @@ function cpu_get_flag(flag as ushort) as ubyte
else
return 0
end if
end function
end function
' cpu_get_flag()
function cpu_get_pl() as ubyte
return (cpu_state.fl and PL_MASK) shr 9
end function
end function
' cpu_get_pl()
sub cpu_set_pl(privilege_level as ubyte)
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)
...
...
@@ -337,7 +359,7 @@ sub cpu_set_reg_alpha(register as string, value as ushort)
case REG_GP
cpu_state.gp = value
end select
end sub
end sub
' cpu_set_reg_alpha()
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
end select
end function
\ No newline at end of file
end function ' cpu_get_reg_alpha()
\ No newline at end of file
inst.bas
0 → 100644
View file @
29cee8f5
'
' 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
0 → 100644
View file @
29cee8f5
'
' 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment