Commit 88daccb0 authored by John P. Willis's avatar John P. Willis

Catch up

parent 8e20195f
......@@ -25,31 +25,41 @@
#
BINFILES = xiasm mkdisk ilxi ilxi.xmf
all: vm xiasm util
all: vm xiasm util linker
dist: all
mkdir -p dist/
cp src/linker/link dist/
cp src/vm/ilxi dist/
cp src/util/mkdisk dist/
cp src/xiasm/xiasm dist/
cp doc/ilxi.xmf dist/
cp bin/.ilximrc dist/
cp examples/input/input.xa dist/
lib:
cd src/lib; make
vm: lib
libilxi:
cd src/libilxi; make
libobj: libilxi
cd src/libobj; make
linker: libilxi libobj
cd src/linker; make
vm: libilxi
cd src/vm; make
xiasm: lib
xiasm: libilxi libobj
cd src/xiasm; make
util: lib
util: libilxi
cd src/util; make
clean:
cd src/lib; make clean
cd src/libilxi; make clean
cd src/libobj; make clean
cd src/vm; make clean
cd src/util; make clean
cd src/xiasm; make clean
cd src/linker; make clean
rm -rf dist
'
' OBJECT FILE FORMAT
'
' object_header
' magic: must be XIO
' relocation_count: number of relocation_entry records
'
' relocation_entry: 1 per relocation entry
'
' section_header:
'
' st_page: binary image
type object_header
magic as string * 3 ' XIO
symbol_count as integer
relocation_count as integer
section_count as integer
end type
' these are references to symbols
type relocation_entry
key as string * 24
reference_offset as ushort
section_title as string * 16
section_offset as ushort
end type
type section_header
title as string * 16
origin as ushort
size as ushort
end type
'
' message.bi
'
#define MSG_INFO 0
#define MSG_WARN 1
#define MSG_WARNING 1
#define MSG_ERROR 2
#define MSG_LISTING 3
declare sub message_init()
declare sub message_print(output_string as string)
declare sub tool_message(msg_level as ubyte, tool as string, message as string, byval output_location as string = "")
declare sub list_heading(tool as string, byval input_file as string)
declare sub listing(line_number as integer, address as string, code_output as string, byval listfile as string)
declare sub list_output(msg as string, byval listfile as string)
dim shared message_row as integer
dim shared message_col as integer
\ No newline at end of file
dim shared message_col as integer
......@@ -2,8 +2,6 @@
#define PAGECOUNT 2048
type st_page
task_id as ubyte
label as string * 255
contents(0 to PAGESIZE - 1) as ubyte
end type
......@@ -13,7 +11,7 @@ declare sub st_load_page(file as string, page as integer)
declare sub st_save_page(file as string, page as integer)
declare sub st_write_word(page as integer, offset as integer, wordval as ushort)
declare function st_read_word(page as integer, offset as integer) as ushort
declare function st_read_page(page as integer) as st_page
\ No newline at end of file
'
' message.bas
'
#include "message.bi"
#include "console.bi"
#include "cpu.bi"
#include "asm.bi"
sub message_init()
console_mutex = mutexcreate()
end sub ' message_init()
sub message_print(output_string as string)
mutexlock console_mutex
print output_string
mutexunlock console_mutex
end sub ' message_print()
\ No newline at end of file
'
' message.bas
'
#include "message.bi"
#include "console.bi"
#include "cpu.bi"
#include "asm.bi"
sub message_init()
console_mutex = mutexcreate()
end sub ' message_init()
sub message_print(output_string as string)
mutexlock console_mutex
print output_string
mutexunlock console_mutex
end sub ' message_print()
sub tool_message(msg_level as ubyte, tool as string, message as string, byval output_location as string = "")
dim msg_prefix as string
msg_prefix = ucase(tool) + ": "
select case msg_level
case MSG_INFO
msg_prefix += "INFO " + message
case MSG_WARN
msg_prefix += "WARNING " + message
case MSG_ERROR
msg_prefix += "ERROR " + message
end select
if len(output_location) > 0 then
dim fnum as integer = freefile()
open output_location for append as #fnum
print #fnum, msg_prefix
close #fnum
else
print msg_prefix
end if
end sub
sub list_heading(tool as string, byval input_file as string)
dim fnum as integer = freefile()
dim listfile as string
listfile = ucase(left(input_file, instrrev(input_file, ".") - 1)) & ".LIS"
open listfile for append as #fnum
print #fnum,""
print #fnum,
print #fnum, "", tool; " LISTING FOR "; ucase(input_file), date()
print #fnum,""
print #fnum," LINE", "OFFSET" , "CODE"
print #fnum, string(72, "-")
close #fnum
end sub
sub listing(line_number as integer, address as string, code_output as string, byval listfile as string)
dim fnum as integer = freefile()
listfile = ucase(left(listfile, instrrev(listfile, ".") - 1)) & ".LIS"
open listfile for append as #fnum
print #fnum, line_number, address, code_output
close #fnum
end sub
sub list_output(msg as string, byval listfile as string)
dim fnum as integer = freefile()
listfile = ucase(left(listfile, instrrev(listfile, ".") - 1)) & ".LIS"
open listfile for append as #fnum
print #fnum, msg
close #fnum
end sub
......@@ -16,6 +16,10 @@ function st_read_byte(page as integer, offset as integer) as byte
return mem(page).contents(offset)
end function
function st_read_page(page as integer) as st_page
return mem(page)
end function
sub st_write_byte(page as integer, offset as integer, value as byte)
if (page > (PAGECOUNT - 1)) or (page < 0) then
machine_error ERR_INVALID_PAGE_ID, 10
......@@ -85,4 +89,4 @@ sub st_save_page(file as string, page as integer)
put #file_handle, , mem(page)
close #file_handle
end sub
\ No newline at end of file
end sub
#
# ILXI Virtual Machine
#
# Makefile (libobj)
#
# Copyright 2016 John P. Willis <jpw@coherent-logic.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
FBCFLAGS = -g -mt -i ../include -p ../libilxi
OBJS = libobj.o
EXE = libobj.a
all: $(EXE)
$(EXE): $(OBJS)
fbc $(FBCFLAGS) -lib -x $(EXE) $(OBJS)
libobj.o: libobj.bas
fbc $(FBCFLAGS) -o libobj.o -c libobj.bas
clean:
rm -f libobj.a $(OBJS)
/'
libobj.bas
Copyright 2016 John P. Willis <jpw@coherent-logic.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
'/
#include "libobj.bi"
#
# ILXI Virtual Machine
#
# Makefile (link)
#
# Copyright 2016 John P. Willis <jpw@coherent-logic.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
OBJS = link.o
FBCFLAGS = -g -mt -i ../include -p ../libilxi -p ../libobj
link: $(OBJS)
fbc $(FBCFLAGS) -l ilxi -x link $(OBJS)
link.o: link.bas
fbc $(FBCFLAGS) -m link -o link.o -c link.bas
clean:
rm -f link $(OBJS)
/'
ILXI Virtual Machine
link.bas (external linker)
Copyright 2016 John P. Willis <jpw@coherent-logic.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
'/
#include "asm.bi"
#include "storage.bi"
#include "lexer.bi"
#include "util.bi"
#include "link.bi"
#include "console.bi"
#include "cpu.bi"
#include "libobj.bi"
#include "message.bi"
#define LNKE001 "LNKE001 INVALID OBJECT FILE OR OBJECT FILE CORRUPT"
dim shared relocation_table(1) as relocation_record
dim shared relct as integer = 0
dim shared base_addr as ushort = 0
dim shared current_page as ushort = 0
sub main(args as string)
dim arg_count as integer = 0
dim argi as integer = 0
dim i as integer
arg_count = lex(args)
print "ILXI SEGMENTED LINKER V0.01 (C) COHERENT LOGIC DEVELOPMENT 2016"
for i = 0 to arg_count - 1
read_object get_lexer_entry(i).strval
next
end sub
sub read_object(object_file as string)
dim fnum as integer = freefile()
dim objhdr as object_header
dim relentr as relocation_entry
dim sechdr as section_header
dim i as integer
dim reloc as relocation_record
dim mcode as ubyte
open object_file for binary as #fnum
get #fnum, , objhdr
if objhdr.magic <> "XIO" then
tool_message MSG_ERROR, "LINK", LNKE001
end
end if
' read the relocation table
for i = 0 to objhdr.relocation_count - 1
get #fnum, , relentr
with reloc
.object_file = object_file
.key = trim(relentr.key)
.base_addr = base_addr
.byte_offset = relentr.reference_offset
end with
install_relocation reloc
next i
get #fnum, , sechdr
' read in all of the machine code
for i = sechdr.origin to sechdr.origin + sechdr.size
get #fnum, , mcode
st_write_byte current_page, i, mcode
next i
' process relocations
for i = 0 to relct - 1
reloc = relocation_table(i)
next i
if sechdr.origin > 0 then
for i = 0 to relct
if relocation_table(i).object_file = object_file then
end if
next i
end if
end sub
sub install_relocation(reloc as relocation_record)
redim preserve relocation_table(relct) as relocation_record
relocation_table(relct) = reloc
relct += 1
end sub
main command()
end
/'
if udidx > 0 then ' we have a need for a fix-up pass
print ">>> PASS 2 [INFO]: Attempting to resolve "; trim(str(udidx)); " symbol(s) left over from pass 1"
dim i as integer
dim e as undef_entry
dim f as symtab_entry
dim fixup_offset as ushort
for i = 1 to udidx
e = udtab(i)
fixup_offset = e.byte_offset
f = lookup_symbol(e.e_key)
if f.resolved = 0 then
print "FATAL UNRESOLVED SYMBOL "; e.e_key
end
else
print ">>> PASS 2 [INFO]: Resolved symbol "; e.e_key; " (symbol found at offset "; hex(f.offset); "h, inserted at fix-up offset "; hex(fixup_offset); "h)"
st_write_word argi, fixup_offset, f.offset
end if
next i
end if
st_save_page output_file_name, argi
'/
/'
link.bi
Copyright 2016 John P. Willis <jpw@coherent-logic.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
'/
type relocation_record
object_file as string
key as string
base_addr as integer
byte_offset as ushort
end type
declare sub main(args as string)
declare sub read_object(object_file as string)
declare sub install_relocation(reloc as relocation_record)
......@@ -24,7 +24,7 @@
MKDISK_OBJS = mkdisk.o
OBJS = $(MKDISK_OBJS)
FBCFLAGS = -g -mt -i ../include -p ../lib
FBCFLAGS = -g -mt -i ../include -p ../libilxi
EXE = mkdisk
all: $(EXE)
......
......@@ -23,7 +23,7 @@
#
OBJS = ilxi.o
FBCFLAGS = -g -mt -i ../include -p ../lib
FBCFLAGS = -g -mt -i ../include -p ../libilxi
ilxi: $(OBJS)
fbc $(FBCFLAGS) -l ilxi -x ilxi $(OBJS)
......
......@@ -23,7 +23,7 @@
#
OBJS = xiasm.o
FBCFLAGS = -g -mt -i ../include -p ../lib
FBCFLAGS = -g -mt -i ../include -p ../libilxi -p ../libobj
xiasm: $(OBJS)
fbc $(FBCFLAGS) -l ilxi -x xiasm $(OBJS)
......
#define ASMW001 "ASMW001 SYMBOL WILL BE TRUNCATED"
#define ASME001 "ASME001 UNRESOLVED EQU "
#define ASME002 "ASME002 UNRESOLVED VAR "
#define ASME003 "ASME003 INCLUDED FILE NOT FOUND "
#define ASMI001 "ASMI001 GENERATED "
#define ASMI002 "ASMI002 PROGRAM ORIGIN SET TO "
#define ASMI003 "ASMI003 DEFERRING RESOLUTION OF "
......@@ -5,7 +5,7 @@
' ILXIM external assembler
'
'
#include "libobj.bi"
#include "asm.bi"
#include "storage.bi"
#include "lexer.bi"
......@@ -13,11 +13,13 @@
#include "xiasm.bi"
#include "console.bi"
#include "cpu.bi"
#include "message.bi"
#include "asmerr.bi"
sub main(args as string)