Some refactoring and FSYS

Some refactoring of debug/tracing code and additions to FSYS and system information routines.
This commit is contained in:
Peter Weingartner 2021-09-22 16:08:09 -04:00
parent cb75f46b2e
commit 1a3e3d79f5
13 changed files with 5942 additions and 5269 deletions

View file

@ -1,7 +1,27 @@
# CPU_WDC65816 0x16 /* CPU code for the Western Design Center 65816 */
# CPU_M68000 0x20 /* CPU code for the Motorola 68000 */
# CPU_M68010 0x21 /* CPU code for the Motorola 68010 */
# CPU_M68020 0x22 /* CPU code for the Motorola 68020 */
# CPU_M68030 0x23 /* CPU code for the Motorola 68030 */
# CPU_M68040 0x24 /* CPU code for the Motorola 68040 */
# CPU_I486DX 0x34 /* CPU code for the Intel 486DX */
export CPU=32
# MODEL_FOENIX_FMX 0
# MODEL_FOENIX_C256U 1
# MODEL_FOENIX_GENX 4
# MODEL_FOENIX_C256U_PLUS 5
# MODEL_FOENIX_A2560U_PLUS 6
# MODEL_FOENIX_A2560X 8
# MODEL_FOENIX_A2560U 9
# MODEL_FOENIX_A2560K 13
export MODEL=4
export AS = vasmm68k_mot
export ASFLAGS = -quiet -Fvobj -nowarn=62
export CC = vc
export CFLAGS = +../vbcc/config/m68k-foenix -I. -Iinclude -DCPU=32 -DSYSTEM=4
export CFLAGS = +../vbcc/config/m68k-foenix -I. -Iinclude -DCPU=$(CPU) -DMODEL=$(MODEL)
export RM = cmd /C del /Q /F
cpu = m68k
@ -17,6 +37,8 @@ fat_c_src := $(wildcard fatfs/*.c)
fat_c_obj := $(subst .c,.o,$(fat_c_src))
cli_c_src := $(wildcard cli/*.c)
cli_c_obj := $(subst .c,.o,$(cli_c_src))
c_src := $(wildcard *.c)
c_obj := $(subst .c,.o,$(c_src))
.PHONY: all $(cpu) dev fatfs snd cli
@ -37,8 +59,8 @@ snd:
cli:
$(MAKE) --directory=cli
foenixmcp.s68: foenixmcp.o log.o ring_buffer.o interrupt.o syscalls.o $(cpu) dev fatfs snd cli
$(CC) $(CFLAGS) -o foenixmcp.s68 foenixmcp.o log.o ring_buffer.o interrupt.o syscalls.o $(cpu_c_obj) $(dev_c_obj) $(fat_c_obj) $(snd_c_obj) $(cli_c_obj)
foenixmcp.s68: $(c_obj) $(cpu) dev fatfs snd cli
$(CC) $(CFLAGS) -o foenixmcp.s68 $(c_obj) $(cpu_c_obj) $(dev_c_obj) $(fat_c_obj) $(snd_c_obj) $(cli_c_obj)
%.o: %.c $(DEPS)
$(CC) -S -c -o $@ $< $(CFLAGS)

View file

@ -2,6 +2,7 @@
#include <string.h>
#include "syscalls.h"
#include "log.h"
#include "cli/dos_cmds.h"
#include "dev/block.h"
#include "fatfs/ff.h"

View file

@ -139,7 +139,32 @@ short fsys_close(short c) {
* the handle to the directory if >= 0. An error if < 0
*/
short fsys_opendir(const char * path) {
return -1;
short i;
short dir = -1;
FRESULT fres;
/* Allocate a directory handle */
for (i = 0; i < MAX_DIRECTORIES; i++) {
if (g_dir_state[i] == 0) {
dir = i;
break;
}
}
if (dir < 0) {
return ERR_OUT_OF_HANDLES;
} else {
/* Try to open the directory */
fres = f_opendir(&g_directory[dir], path);
if (fres != FR_OK) {
/* If there was a problem, return an error number */
return fatfs_to_foenix(fres);
} else {
/* Otherwise, allocate and return the handle */
g_dir_state[dir] = 1;
return dir;
}
}
}
/**
@ -152,7 +177,13 @@ short fsys_opendir(const char * path) {
* 0 on success, negative number on error
*/
short fsys_closedir(short dir) {
return -1;
if (g_dir_state[dir]) {
/* Close and deallocate the handle */
f_closedir(&g_directory[dir]);
g_dir_state[dir] = 0;
}
return 0;
}
/**
@ -166,7 +197,33 @@ short fsys_closedir(short dir) {
* 0 on success, negative number on failure
*/
short fsys_readdir(short dir, p_file_info file) {
return -1;
FILINFO finfo;
if (g_dir_state[dir]) {
FRESULT fres = f_readdir(&g_directory[dir], &finfo);
if (fres != FR_OK) {
return fatfs_to_foenix(fres);
} else {
int i;
/* Copy file information into the kernel table */
file->size = finfo.fsize;
file->date = finfo.fdate;
file->time = finfo.ftime;
file->attributes = finfo.fattrib;
for (i = 0; i < MAX_PATH_LEN; i++) {
file->name[i] = finfo.fname[i];
if (file->name[i] == 0) {
break;
}
}
return 0;
}
} else {
return ERR_BAD_HANDLE;
}
}
/**

View file

@ -4,6 +4,8 @@
#include <string.h>
#include "sys_general.h"
#include "simpleio.h"
#include "log.h"
#include "interrupt.h"
#include "gabe_reg.h"
#include "superio.h"
@ -22,7 +24,6 @@
#include "snd/sid.h"
#include "fatfs/ff.h"
#include "cli/cli.h"
#include "log.h"
const char* VolumeStr[FF_VOLUMES] = { "@S", "@F", "@H" };
@ -79,46 +80,8 @@ const char* VolumeStr[FF_VOLUMES] = { "@S", "@F", "@H" };
*LED2_REG = 0x02;
}
void print(short channel, char * message) {
sys_chan_write(channel, message, strlen(message));
}
unsigned char number[5];
unsigned char hex_digits[] = "0123456789ABCDEF";
void print_hex(short channel, unsigned short x) {
short digit;
digit = (x & 0xf0) >> 4;
number[0] = hex_digits[digit];
digit = (x & 0x0f);
number[1] = hex_digits[digit];
number[2] = 0;
print(channel, number);
}
void print_hex_16(short channel, unsigned short x) {
short digit;
digit = (x >> 12) & 0x000f;
number[0] = hex_digits[digit];
digit = (x >> 8) & 0x000f;
number[1] = hex_digits[digit];
digit = (x >> 4) & 0x000f;
number[2] = hex_digits[digit];
digit = x & 0x000f;
number[3] = hex_digits[digit];
number[4] = 0;
print(channel, number);
}
void print_error(short channel, char * message, short code) {
print(channel, message);

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@
#ifndef __ERRORS_H
#define __ERRORS_H
#define MAX_ERROR_NUMBER 10 // Largest (absolute value) of the error number
#define MAX_ERROR_NUMBER 12 // Largest (absolute value) of the error number
#define ERR_OUT_OF_MEMORY -1
#define DEV_ERR_BADDEV -2 // Device number is bad (too big or no device assigned)
@ -18,5 +18,6 @@
#define DEV_WRITEPROT -9 // The media is write protected
#define ERR_BADCHANNEL -10 // The channel number was bad
#define ERR_OUT_OF_HANDLES -11 // There are no available handles for channels, files, etc.
#define ERR_BAD_HANDLE -12 // The handle passed was not valid
#endif
#endif

View file

@ -4,22 +4,97 @@
#include <string.h>
#include "log.h"
#include "simpleio.h"
#include "dev/text_screen_iii.h"
static short log_channel = 0;
static short log_level = 999;
void log_init() {
log_channel = 0;
log_level = 999;
}
/*
* Send a message to the debugging channel
* Set the maximum level of verbosity in logging.
* To be printed, a message must have a level lower or equal to this level.
*
* Input:
* level = the maximum level of verbosity to log
*/
void DEBUG(char * message) {
int i;
for (i = 0; i < strlen(message); i++) {
text_put_raw(0, message[i]);
void log_setlevel(short level) {
log_level = level;
}
/*
* Log a message to the console
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message = the message to log
*/
void log(short level, char * message) {
if (level <= log_level) {
print(log_channel, message);
print_c(log_channel, '\n');
}
}
/*
* Log a message to the console
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message1 = the first part of the message to log
* message2 = the second part of the message to log
*/
void log2(short level, char * message1, char * message2) {
if (level <= log_level) {
print(log_channel, message1);
print(log_channel, message2);
print_c(log_channel, '\n');
}
}
/*
* Log a message to the console
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message1 = the first part of the message to log
* message2 = the second part of the message to log
* message3 = the third part of the message to log
*/
void log3(short level, char * message1, char * message2, char * message3) {
if (level <= log_level) {
print(log_channel, message1);
print(log_channel, message2);
print(log_channel, message3);
print_c(log_channel, '\n');
}
}
/*
* Log a message with a number
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message1 = the first part of the message to log
* n = the number to log
*/
void log_num(short level, char * message, int n) {
if (level <= log_level) {
print(log_channel, message);
print_hex_16(log_channel, n);
print_c(log_channel, '\n');
}
text_put_raw(0, '\n');
}
/*
* Send a single character to the debugging channel
*/
void logc(c) {
text_put_raw(0, c);
void log_c(short level, char c) {
if (log_level <= level) {
print_c(log_channel, c);
}
}

View file

@ -5,15 +5,72 @@
#ifndef __LOG_H
#define __LOG_H
#define LOG_FATAL 0 /* Log a critical or fatal event */
#define LOG_ERROR 1 /* Log an error */
#define LOG_INFO 2 /* Log miscellaneous information */
#define LOG_DEBUG 3 /* Log a debugging message */
#define LOG_TRACE 4 /* Log tracing information (like entry into a subroutine) */
#define LOG_VERBOSE 5 /* Log a truly verbose message... the sort you almost never want to bother with */
/*
* Set the maximum level of verbosity in logging.
* To be printed, a message must have a level lower or equal to this level.
*
* Input:
* level = the maximum level of verbosity to log
*/
extern void log_setlevel(short level);
/*
* Log a message to the console
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message = the message to log
*/
extern void log(short level, char * message);
/*
* Log a message to the console
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message1 = the first part of the message to log
* message2 = the second part of the message to log
*/
extern void log2(short level, char * message1, char * message2);
/*
* Log a message to the console
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message1 = the first part of the message to log
* message2 = the second part of the message to log
* message3 = the third part of the message to log
*/
extern void log3(short level, char * message1, char * message2, char * message3);
/*
* Log a message with a number
*
* Inputs:
* level = the severity of the message... the logging level will filter messages displayed
* message1 = the first part of the message to log
* n = the number to log
*/
extern void log_num(short level, char * message, int n);
/*
* Log a single character
*/
extern void log_c(short log_level, char c);
/*
* Send a message to the debugging channel
*/
extern void DEBUG(char * message);
extern void logc(char c);
#define TRACE(msg) /*DEBUG(msg);*/
#define TRACEC(c) logc(c);
#define DEBUG(m) log(LOG_DEBUG, m);
#define TRACE(m) log(LOG_TRACE, m);
#define TRACEC(c) log_c(LOG_TRACE, c);
#endif

File diff suppressed because it is too large Load diff

85
src/simpleio.c Normal file
View file

@ -0,0 +1,85 @@
/*
* A simple collection of I/O functions the kernel will need often
*/
#include <string.h>
#include "syscalls.h"
#include "simpleio.h"
/*
* Print a character to a channel
*
* Inputs:
* channel = the number of the channel
* c = the character to print
*/
void print_c(short channel, char c) {
//sys_chan_write_b(channel, c);
text_put_raw(channel, c);
}
/*
* Print a string to a channel
*
* Inputs:
* channel = the number of the channel
* message = the ASCII-Z string to print
*/
void print(short channel, char * message) {
int i;
for (i = 0; i < strlen(message); i++) {
print_c(channel, message[i]);
}
// sys_chan_write(channel, message, strlen(message));
}
unsigned char number[5];
unsigned char hex_digits[] = "0123456789ABCDEF";
/*
* Print an 8-bit number as hex to a channel
*
* Inputs:
* channel = the number of the channel
* n = the number to print
*/
void print_hex(short channel, unsigned short x) {
short digit;
digit = (x & 0xf0) >> 4;
number[0] = hex_digits[digit];
digit = (x & 0x0f);
number[1] = hex_digits[digit];
number[2] = 0;
print(channel, number);
}
/*
* Print an 16-bit number as hex to a channel
*
* Inputs:
* channel = the number of the channel
* n = the number to print
*/
void print_hex_16(short channel, unsigned short x) {
short digit;
digit = (x >> 12) & 0x000f;
number[0] = hex_digits[digit];
digit = (x >> 8) & 0x000f;
number[1] = hex_digits[digit];
digit = (x >> 4) & 0x000f;
number[2] = hex_digits[digit];
digit = x & 0x000f;
number[3] = hex_digits[digit];
number[4] = 0;
print(channel, number);
}

44
src/simpleio.h Normal file
View file

@ -0,0 +1,44 @@
/*
* A simple collection of I/O functions the kernel will need often
*/
#ifndef __SIMPLE_IO_H
#define __SIMPLE_IO_H
/*
* Print a string to a channel
*
* Inputs:
* channel = the number of the channel
* message = the ASCII-Z string to print
*/
extern void print(short channel, char * message);
/*
* Print a character to a channel
*
* Inputs:
* channel = the number of the channel
* c = the character to print
*/
extern void print_c(short channel, char c);
/*
* Print an 8-bit number as hex to a channel
*
* Inputs:
* channel = the number of the channel
* n = the number to print
*/
extern void print_hex_8(short channel, short n);
/*
* Print an 16-bit number as hex to a channel
*
* Inputs:
* channel = the number of the channel
* n = the number to print
*/
extern void print_hex_16(short channel, short n);
#endif

View file

@ -1,36 +1,75 @@
#include "sys_general.h"
#include "gabe_reg.h"
/*
* Fill out a s_sys_info structure with the information about the current system
* Fill out a s_MODEL_info structure with the information about the current system
*
* Inputs:
* info = pointer to a s_sys_info structure to fill out
* info = pointer to a s_MODEL_info structure to fill out
*/
void sys_get_info(p_sys_info info) {
/* Model, CPU, and the presence of the floppy are set at compile time */
info->model = MODEL;
info->cpu = CPU;
#if MODEL==SYS_FOENIX_FMX || MODEL==SYS_FOENIX_A2560K || MODEL==SYS_FOENIX_A2560X || MODEL==SYS_FOENIX_GENX
info->has_floppy = 1;
#else
info->has_floppy = 0;
#endif
unsigned short machine_id = *GABE_MACHINE_ID;
info->gabe_rev = 0x0000; /* TODO: get this from GABE */
info->has_floppy = 0;
/* Model, CPU, and the presence of the floppy are set at compile time */
switch (machine_id & 0x000f) {
case 0x00:
info->model = MODEL_FOENIX_FMX;
info->has_floppy = 1;
break;
case 0x01:
info->model = MODEL_FOENIX_C256U;
break;
case 0x05:
info->model = MODEL_FOENIX_C256U_PLUS;
break;
case 0x0B:
info->model = MODEL_FOENIX_A2560K;
info->has_floppy = 1;
break;
case 0x09:
info->model = MODEL_FOENIX_A2560U;
break;
default:
/* Model is unknown */
info->model = 0xffff;
break;
}
switch ((machine_id & 0xf000) >> 12) {
case 0x00:
info->cpu = CPU_M68000;
break;
default:
/* Unknown CPU */
info->cpu = 0xffff;
break;
}
info->gabe_number = *GABE_CHIP_NUMBER;
info->gabe_version = *GABE_CHIP_VERSION;
info->gabe_subrev = *GABE_CHIP_SUBREV;
info->vicky_rev = 0x0000; /* TODO: get this from VICKY */
info->system_ram_size = 0; /* TODO: compute this by testing RAM */
info->has_expansion_card = 0; /* TODO: figure this out by checking with GABE */
info->has_hard_drive = 0; /* TODO: figure this out by checking with GABE */
/* Set the number of screens and the presence of ethernet based on the model and expansion card */
switch (info->model) {
case SYS_FOENIX_A2560K:
case SYS_FOENIX_A2560X:
case SYS_FOENIX_GENX:
case MODEL_FOENIX_A2560K:
case MODEL_FOENIX_A2560X:
case MODEL_FOENIX_GENX:
/* These systems are built with 2 screens and ethernet */
info->screens = 2;
info->has_ethernet = 1;

View file

@ -9,24 +9,24 @@
/* IDs for the various Foenix machines supported */
#define SYS_FOENIX_FMX 1
#define SYS_FOENIX_U 2
#define SYS_FOENIX_U_PLUS 3
#define SYS_FOENIX_A2560K 4
#define SYS_FOENIX_A2560U 5
#define SYS_FOENIX_A2560U_PLUS 6
#define SYS_FOENIX_A2560X 7
#define SYS_FOENIX_GENX 8
#define MODEL_FOENIX_FMX 0
#define MODEL_FOENIX_C256U 1
#define MODEL_FOENIX_GENX 4
#define MODEL_FOENIX_C256U_PLUS 5
#define MODEL_FOENIX_A2560U_PLUS 6
#define MODEL_FOENIX_A2560X 8
#define MODEL_FOENIX_A2560U 9
#define MODEL_FOENIX_A2560K 13
/* IDs for the CPUs supported */
#define CPU_WDC65816 0x16 /* CPU code for the Western Design Center 65816 */
#define CPU_M68000 0x20 /* CPU code for the Motorola 68000 */
#define CPU_M68010 0x21 /* CPU code for the Motorola 68010 */
#define CPU_M68020 0x22 /* CPU code for the Motorola 68020 */
#define CPU_M68030 0x23 /* CPU code for the Motorola 68030 */
#define CPU_M68040 0x24 /* CPU code for the Motorola 68040 */
#define CPU_I486DX 0x34 /* CPU code for the Intel 486DX */
#define CPU_WDC65816 0x16 /* CPU code for the Western Design Center 65816 */
#define CPU_M68000 0x20 /* CPU code for the Motorola 68000 */
#define CPU_M68010 0x21 /* CPU code for the Motorola 68010 */
#define CPU_M68020 0x22 /* CPU code for the Motorola 68020 */
#define CPU_M68030 0x23 /* CPU code for the Motorola 68030 */
#define CPU_M68040 0x24 /* CPU code for the Motorola 68040 */
#define CPU_I486DX 0x34 /* CPU code for the Intel 486DX */
/*
* Structure to describe the hardware
@ -34,7 +34,9 @@
typedef struct s_sys_info {
unsigned short model; /* Code to say what model of machine this is */
unsigned short cpu; /* Code to say which CPU is running */
unsigned short gabe_rev; /* Code for the GABE revision number */
unsigned short gabe_number; /* GABE revision information */
unsigned short gabe_version;
unsigned short gabe_subrev;
unsigned short vicky_rev; /* Code for the VICKY revision number */
int system_ram_size; /* The number of bytes of system RAM on the board */
bool has_floppy; /* TRUE if the board has a floppy drive installed */
@ -52,4 +54,4 @@ typedef struct s_sys_info {
*/
extern void sys_get_info(p_sys_info info);
#endif
#endif