2019-05-15 20:06:45 +02:00
|
|
|
// The OS/K Team licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
2019-05-15 19:26:40 +02:00
|
|
|
|
2019-06-05 19:31:48 +02:00
|
|
|
#ifndef _ARCH_H
|
|
|
|
#define _ARCH_H
|
|
|
|
|
2019-06-21 22:19:55 +02:00
|
|
|
//#define NDEBUG 1
|
|
|
|
|
2019-06-05 19:31:48 +02:00
|
|
|
#define dev_t stddev_t
|
|
|
|
|
2019-05-29 16:57:22 +02:00
|
|
|
#include <ctype.h>
|
2019-05-15 19:26:40 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-05-16 10:03:01 +02:00
|
|
|
#include <string.h>
|
2019-06-21 22:19:55 +02:00
|
|
|
#include <setjmp.h>
|
2019-05-16 10:03:01 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
2019-06-06 22:07:34 +02:00
|
|
|
#include <limits.h>
|
2019-05-15 19:26:40 +02:00
|
|
|
|
2019-06-05 19:31:48 +02:00
|
|
|
#undef dev_t
|
2019-05-15 19:26:40 +02:00
|
|
|
#define static_assert _Static_assert
|
2019-05-16 10:03:01 +02:00
|
|
|
#define alignof _Alignof
|
2019-05-15 19:26:40 +02:00
|
|
|
|
|
|
|
typedef unsigned int bool;
|
|
|
|
typedef unsigned char uchar;
|
|
|
|
typedef unsigned short ushort;
|
|
|
|
typedef unsigned int uint;
|
|
|
|
typedef unsigned long ulong;
|
|
|
|
|
|
|
|
typedef struct reg_t reg_t;
|
|
|
|
typedef struct ctx_t ctx_t;
|
|
|
|
typedef struct instr_t instr_t;
|
|
|
|
typedef struct acc_t acc_t;
|
|
|
|
typedef struct arch_t arch_t;
|
2019-06-05 19:31:48 +02:00
|
|
|
typedef struct dev_t dev_t;
|
2019-05-15 19:26:40 +02:00
|
|
|
|
2019-06-19 21:41:22 +02:00
|
|
|
void logerr(const char *, ...);
|
2019-05-30 11:32:00 +02:00
|
|
|
void vlog(const char *, va_list);
|
|
|
|
|
2019-06-21 22:19:55 +02:00
|
|
|
// void trace(const char *, ...);
|
|
|
|
#define trace printf
|
|
|
|
|
2019-06-13 23:12:11 +02:00
|
|
|
#define KARCH_MAJOR 0
|
|
|
|
#define KARCH_MINOR 1
|
|
|
|
#define KARCH_REVIS 0
|
|
|
|
|
2019-05-15 19:26:40 +02:00
|
|
|
struct ctx_t
|
|
|
|
{
|
2019-06-18 12:58:26 +02:00
|
|
|
// Array of NREGS ulong's
|
|
|
|
ulong *rf;
|
|
|
|
|
|
|
|
// Register (names & types) table
|
2019-05-15 19:26:40 +02:00
|
|
|
reg_t *r;
|
2019-06-18 12:58:26 +02:00
|
|
|
|
|
|
|
// Instruction table
|
2019-05-15 19:26:40 +02:00
|
|
|
instr_t *i;
|
|
|
|
|
2019-07-04 20:33:49 +02:00
|
|
|
// Instruction currently executing
|
|
|
|
instr_t *cur_in;
|
|
|
|
|
2019-07-11 18:34:21 +02:00
|
|
|
// Starting address of instruction currently executing
|
|
|
|
ulong cur_pc;
|
|
|
|
|
2019-05-15 19:26:40 +02:00
|
|
|
// Memory and memory size
|
2019-05-16 10:03:01 +02:00
|
|
|
ushort *mp;
|
2019-05-15 19:26:40 +02:00
|
|
|
ulong mz;
|
|
|
|
|
|
|
|
// Read next instruction
|
|
|
|
ushort (*get)(ctx_t *ctx);
|
2019-05-30 12:19:38 +02:00
|
|
|
|
2019-06-05 19:31:48 +02:00
|
|
|
// Devices list head
|
|
|
|
dev_t *dh;
|
2019-06-18 23:01:41 +02:00
|
|
|
|
2019-07-11 18:34:21 +02:00
|
|
|
// Instructions executed
|
|
|
|
ulong ninstrs; // totally
|
|
|
|
ulong ni_thisfr; // this frame
|
2019-07-02 20:13:05 +02:00
|
|
|
|
|
|
|
// Last COND field
|
|
|
|
uint cond;
|
2019-07-04 20:33:49 +02:00
|
|
|
|
|
|
|
// Dumpinstr switch
|
|
|
|
bool dumpsw;
|
2019-05-15 19:26:40 +02:00
|
|
|
};
|
|
|
|
|
2019-06-18 12:58:26 +02:00
|
|
|
#define R(X) ctx->rf[X]
|
2019-06-02 16:33:28 +02:00
|
|
|
|
2019-06-19 21:41:22 +02:00
|
|
|
void die(int code) __attribute__((__noreturn__));
|
|
|
|
|
2019-05-16 16:48:45 +02:00
|
|
|
void dumpregs(ctx_t *);
|
2019-05-29 16:57:22 +02:00
|
|
|
void dumpinstr(ctx_t *, ulong, uint, ushort, acc_t *, acc_t *);
|
2019-05-16 16:48:45 +02:00
|
|
|
void dumpmem(ctx_t *, ulong, ulong);
|
2019-05-15 19:26:40 +02:00
|
|
|
|
|
|
|
void decode(ctx_t *ctx);
|
|
|
|
|
2019-06-16 12:48:30 +02:00
|
|
|
void enable_stdin_echoing(void);
|
|
|
|
void disable_stdin_echoing(void);
|
|
|
|
|
2019-06-14 16:47:01 +02:00
|
|
|
#include <pc/mem.h>
|
2019-06-19 13:47:10 +02:00
|
|
|
#include <pc/sym.h>
|
2019-06-05 12:53:09 +02:00
|
|
|
#include <pc/regs.h>
|
2019-06-21 22:19:55 +02:00
|
|
|
#include <pc/decode.h>
|
2019-06-15 13:42:30 +02:00
|
|
|
#include <pc/except.h>
|
2019-06-05 12:53:09 +02:00
|
|
|
#include <in/arch_i.h>
|
2019-05-29 16:57:22 +02:00
|
|
|
|
2019-06-19 21:41:22 +02:00
|
|
|
extern ctx_t main_ctx;
|
2019-05-29 16:57:22 +02:00
|
|
|
extern reg_t arch_r[NREGS];
|
|
|
|
extern instr_t arch_i[NINSTRS];
|
2019-05-15 21:47:08 +02:00
|
|
|
|
2019-06-21 22:19:55 +02:00
|
|
|
extern size_t rfs_current_idx;
|
|
|
|
|
2019-06-05 19:31:48 +02:00
|
|
|
#endif
|
|
|
|
|