WIP work on VM. Also add program icon

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-02-25 16:58:08 +01:00
parent 87a44f2d3a
commit eef80e2199
28 changed files with 401 additions and 25 deletions

18
bios/main.s Normal file
View file

@ -0,0 +1,18 @@
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .bss
STACKSIZE = 512
.comm stack, STACKSIZE
.sect .text
_start:
sei ! disable interrupt
! setup stack
ldy.l #stack + STACKSIZE
txs

View file

@ -1,8 +1,18 @@
AC_INIT([65oo2], [1.0])
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CANONICAL_HOST
AC_CONFIG_HEADERS([config.h])
case "$host_os" in
cygwin*|mingw*)
OS_TYPE=windows;;
*)
OS_TYPE=unknown;;
esac
AM_CONDITIONAL([OS_WINDOWS], test "$OS_TYPE" = "windows")
AC_LANG(C)
AC_PROG_CC
@ -12,10 +22,41 @@ AC_PROG_RANLIB
AM_PROG_AS
AM_PROG_AR
AM_PROG_CC_C_O
PKG_PROG_PKG_CONFIG
AC_CHECK_TOOLS(WINDRES, [windres], :)
AC_ARG_ENABLE([ata-vga],
[AS_HELP_STRING([--enable-ata-vga], [enable VGA (default=yes)])],
[WANT_ATA_VGA=$enableval], [WANT_ATA_VGA=yes])
AC_ARG_ENABLE([ata-ethernet],
[AS_HELP_STRING([--enable-ata-ethernet], [enable ethernet device (default=yes)])],
[WANT_ATA_ETHERNET=$enableval], [WANT_ATA_ETHERNET=yes])
AC_ARG_ENABLE(mmu,
[AS_HELP_STRING([--enable-mmu], [enable MMU (default=yes)])],
[WANT_MMU=$enableval], [WANT_MMU=yes])
AC_ARG_ENABLE(jit,
[AS_HELP_STRING([--enable-jit], [enable JIT compiler (default=no)])],
[WANT_JIT=$enableval], [WANT_JIT=no])
AC_CHECK_INCLUDES_DEFAULT
AC_C_CONST
AM_CONDITIONAL([USE_ATA_VGA], test "$WANT_ATA_VGA" = "yes")
if test "$WANT_ATA_VGA" = "yes"; then
AC_DEFINE([ATA_VGA], [1], [Enable VGA device])
PKG_CHECK_MODULES([SDL2], [sdl2])
fi
AM_CONDITIONAL([USE_ATA_ETHERNET], test "$WANT_ATA_ETHERNET" = "yes")
if test "$WANT_ATA_ETHERNET" = "yes"; then
AC_DEFINE([ATA_ETERNET], [1], [Enable Ethernet device])
fi
AM_CONDITIONAL([USE_MMU], test "$WANT_MMU" = "yes")
AM_CONDITIONAL([USE_JIT], test "$WANT_JIT" = "yes")
AC_CONFIG_FILES([
Makefile
lib/Makefile

View file

@ -1,5 +1,7 @@
include res/Makefrag.am
bin_PROGRAMS = disas
disas_SOURCES = main.c
disas_CFLAGS =-I$(top_srcdir)
disas_LDADD = ../lib/lib65oo2.a
disas_LDADD = ../lib/lib65oo2.a $(RES)

View file

@ -90,35 +90,67 @@ fatal(const char *str, ...)
exit(EXIT_FAILURE);
}
void
decode_target_suffix(uint8_t attr)
{
fprintf(output, ".");
if (IS_TARGET_ZEXT(attr))
{
fprintf(output, "U");
}
switch (GET_TARGET_SIZE(attr))
{
case SIZE_BYTE:
fprintf(output, "B");
break;
case SIZE_WORD:
fprintf(output, "W");
break;
case SIZE_LONG:
fprintf(output, "L");
break;
}
}
void
decode_address(uint8_t attr)
{
switch (GET_ADDRESS_SIZE(attr))
{
case SIZE_BYTE:
fprintf(output, " %%%X", readu8());
break;
case SIZE_WORD:
fprintf(output, " %%%hX", readu16());
break;
case SIZE_LONG:
fprintf(output, " %%%X", readu32());
break;
default:
break;
}
}
void
decode_imm(uint8_t opcode)
{
uint8_t attr;
attr = readu8();
if ((attr & 0x3) == 0x3)
{
fprintf(output, "???\n");
return;
}
fprintf(output, "%s.", opcode_str[opcode]);
if (attr & 0x4)
fprintf(output, "%s", opcode_str[opcode]);
decode_target_suffix(attr);
switch (GET_TARGET_SIZE(attr))
{
fprintf(output, "U");
}
switch (attr & 0x3)
{
case 0x0:
fprintf(output, "B #$%X\n", readu8());
case SIZE_BYTE:
fprintf(output, " #$%X\n", readu8());
break;
case 0x1:
fprintf(output, "W #$%hX\n", readu16());
case SIZE_WORD:
fprintf(output, " #$%hX\n", readu16());
break;
case 0x2:
fprintf(output, "L #$%X\n", readu32());
case SIZE_LONG:
fprintf(output, " #$%X\n", readu32());
break;
default:
break;
@ -130,8 +162,32 @@ decode_ind(uint8_t opcode)
{
uint8_t attr;
fprintf(output, "%s", opcode_str[opcode]);
attr = readu8();
(void)attr;
if (opcode != OP_JMP_ind)
{
decode_target_suffix(attr);
}
if (opcode_addr[opcode] & (OP_ADDR_X | OP_ADDR_Y))
{
fprintf(output, " (");
}
else
{
fprintf(output, " ");
}
decode_address(attr);
if (opcode_addr[opcode] & OP_ADDR_X)
{
fprintf(output, ", X)");
}
else if (opcode_addr[opcode] & OP_ADDR_Y)
{
fprintf(output, "), Y");
}
fprintf(output, "\n");
}
void
@ -139,8 +195,24 @@ decode_abs(uint8_t opcode)
{
uint8_t attr;
fprintf(output, "%s", opcode_str[opcode]);
attr = readu8();
(void)attr;
if (opcode != OP_JSR_abs
|| opcode != OP_JMP_abs)
{
decode_target_suffix(attr);
}
decode_address(attr);
if (opcode_addr[opcode] & OP_ADDR_X)
{
fprintf(output, ", X");
}
else if (opcode_addr[opcode] & OP_ADDR_Y)
{
fprintf(output, ", Y");
}
fprintf(output, "\n");
}
void

8
disas/res/Makefrag.am Normal file
View file

@ -0,0 +1,8 @@
if OS_WINDOWS
RES = windows.$(OBJEXT)
else
RES =
endif
windows.$(OBJEXT): res/windows.rc
$(WINDRES) $< $@

BIN
disas/res/disas.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
disas/res/disas.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

1
disas/res/windows.rc Normal file
View file

@ -0,0 +1 @@
1 ICON "disas.ico"

View file

@ -39,6 +39,30 @@
# define OP_BMI_rel 0x30
# define OP_AND_ind_y 0x31
# define OP_JMP_abs 0x4C
# define OP_JMP_ind 0x6C
/*
* size encoding
*/
# define SIZE_BYTE 0x0
# define SIZE_WORD 0x1
# define SIZE_LONG 0x2
# define TARGET_ZEXT (1 << 2)
# define TARGET_SIZE_BYTE SIZE_BYTE
# define TARGET_SIZE_WORD SIZE_WORD
# define TARGET_SIZE_LONG SIZE_LONG
# define ADDRESS_SIZE_BYTE (SIZE_BYTE << 3)
# define ADDRESS_SIZE_WORD (SIZE_WORD << 3)
# define ADDRESS_SIZE_LONG (SIZE_LONG << 3)
# define GET_TARGET_SIZE(x) ((x) & 0x03)
# define GET_ADDRESS_SIZE(x) (((x) >> 3) & 0x03)
# define IS_TARGET_ZEXT(x) ((x) & TARGET_ZEXT)
extern const uint8_t opcode_addr[];
extern const char *opcode_str[];

View file

@ -1,5 +1,11 @@
include jit/Makefrag.am
include ata/Makefrag.am
include res/Makefrag.am
noinst_LIBRARIES = $(LIBJIT) $(LIB_ATA)
bin_PROGRAMS = vm
vm_SOURCES = main.c jit.c x64/x64.S
vm_SOURCES = main.c
vm_CFLAGS =-I$(top_srcdir)
vm_LDADD = ../lib/lib65oo2.a
vm_LDADD = ../lib/lib65oo2.a $(LIBJIT) $(LIB_ATA) $(RES)

7
vm/ata/Makefrag.am Normal file
View file

@ -0,0 +1,7 @@
LIB_ATA = libata.a
libata_a_SOURCES = ata/ata.c ata/rtc.c
if USE_ATA_VGA
libata_a_SOURCES += ata/vga.c
endif

27
vm/ata/ata.c Normal file
View file

@ -0,0 +1,27 @@
#include "ata.h"
#include "config.h"
extern AtaDevice rtc_dev;
#ifdef ATA_ETHERNET
extern AtaDevice ethernet_dev;
#endif /* ATA_ETHERNET */
#ifdef ATA_VGA
extern AtaDevice vga_dev;
#endif /* ATA_VGA */
AtaDevice *devices[] = {
&rtc_dev,
#ifdef ATA_ETHERNET
&ethernet_dev,
#endif /* ATA_ETHERNET */
#ifdef ATA_VGA
&vga_dev,
#endif /* ATA_VGA */
NULL
};
void
ata_bus_initialize(void)
{
}

19
vm/ata/ata.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef VM_ATA_ATA_H
# define VM_ATA_ATA_H 1
# include <stdint.h>
typedef void (*IoWrite)(uint8_t offset, uint8_t data);
typedef uint8_t (*IoRead)(uint8_t offset);
typedef struct
{
char const *name;
uint16_t start;
uint16_t end;
void *state;
IoWrite io_write;
IoRead io_read;
} AtaDevice;
#endif /* VM_ATA_ATA_H */

14
vm/ata/ethernet.c Normal file
View file

@ -0,0 +1,14 @@
#include "isa.h"
static const uint8_t mac_addr[6] = {
0x53, 0x54, 0x41, 0x4C, 0x49, 0x4E
};
AtaDevice ethernet_dev = {
"TinyEthernet",
0x360,
0x36F,
NULL,
NULL,
NULL
};

45
vm/ata/rtc.c Normal file
View file

@ -0,0 +1,45 @@
#include <time.h>
#include "ata.h"
#define REG_SECS 0x00
#define REG_MINS 0x00
#define REG_HOURS 0x00
#define REG_WKDAY 0x06
#define REG_DAY 0x07
#define REG_YEAR 0x09
#define REG_CENTURY 0x032
#define REG_STATUSA 0x0A
#define REG_STATUSB 0x0B
static uint8_t current_reg = 0x00;
void
rtc_write(uint8_t addr, uint8_t value)
{
if (addr == 0)
{
current_reg = value;
}
}
uint8_t
rtc_read(uint8_t addr)
{
time_t time;
struct tm tm;
localtime(&time);
(void)time;
(void)tm;
return (0x00);
}
AtaDevice rtc_dev = {
"RTC",
0x070,
0x071,
NULL,
NULL
};

25
vm/ata/serial.c Normal file
View file

@ -0,0 +1,25 @@
#include "ata.h"
AtaDevice com3_dev = {
"COM3",
0x3E0,
0x3EF,
NULL,
NULL
};
AtaDevice com2_dev = {
"COM2",
0x2F8,
0x2FF,
NULL,
NULL,
};
AtaDevice com1_dev = {
"COM1",
0x3F8,
0x3FF,
NULL,
NULL,
};

22
vm/ata/vga.c Normal file
View file

@ -0,0 +1,22 @@
#include "ata.h"
enum VGA_REG {
REG_CRTC_ADDR,
REG_CRTC_DATA,
REG_INPUT_STATUS1,
REG_FEAT_CTRL,
REG_ATTR_ADDR,
REG_ATTR_DATA,
};
enum VGA_CRTC {
XXX
};
AtaDevice vga_dev = {
"TinyVGA",
0x3C0,
0x3CF,
NULL,
NULL,
};

19
vm/bus.c Normal file
View file

@ -0,0 +1,19 @@
void
bus_initialize(void)
{
}
void
bus_read(void)
{
}
void
bus_write(void)
{
}
void
bus_reset(void)
{
}

7
vm/jit/Makefrag.am Normal file
View file

@ -0,0 +1,7 @@
if USE_JIT
LIBJIT = libjit.a
else
LIBJIT =
endif
libjit_a_SOURCES = jit/jit.c jit/x64/x64.S

View file

@ -1,8 +1,18 @@
#include <stdlib.h>
#include <stdio.h>
static const char *prg_name;
void
usage(void)
{
printf("Usage: %s [-hV] [-b bios]\n");
}
int
main(int argc, char **argv)
{
prg_name = argv[0];
return (EXIT_SUCCESS);
}

8
vm/res/Makefrag.am Normal file
View file

@ -0,0 +1,8 @@
if OS_WINDOWS
RES = windows.$(OBJEXT)
else
RES =
endif
windows.$(OBJEXT): res/windows.rc
$(WINDRES) $< $@

BIN
vm/res/vm.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
vm/res/vm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,001 B

1
vm/res/windows.rc Normal file
View file

@ -0,0 +1 @@
1 ICON "vm.ico"