mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
lots of stuff!
This commit is contained in:
parent
27cb6a1b26
commit
4bccea4a9d
3
Makefile
3
Makefile
@ -5,7 +5,7 @@ KODIR=ka/obj
|
||||
|
||||
all: kas
|
||||
|
||||
kpc:
|
||||
kpc: vm/Makefile
|
||||
@cd vm && make --no-print-directory -s verbose=yes
|
||||
|
||||
kas: kpc as/regs.lst as/k-as.py
|
||||
@ -24,6 +24,7 @@ clean:
|
||||
test: $(KODIR)/a.out
|
||||
@vm/k.exe $(KODIR)/a.out $(KODIR)/a.sym
|
||||
@rm -f $(KODIR)/a.out $(KODIR)/a.sym
|
||||
|
||||
wc: clean
|
||||
@cat $(shell find -name *.[kch]) $(shell find -name *.py) | wc -l
|
||||
|
||||
|
8
ka/ABI
8
ka/ABI
@ -105,14 +105,14 @@ To call a variadic function, do this:
|
||||
add rsp, nargs * 8
|
||||
|
||||
To the variadic function, argN can be accessed the following way:
|
||||
mov reg, [rbp + N*8 + 16]
|
||||
mov reg, [rbp+N*8+16]
|
||||
|
||||
For instance:
|
||||
mov rax, [rbp + 16] ; arg0
|
||||
mov rdx, [rbp + 24] ; arg1
|
||||
mov rax, [rbp+16] ; arg0
|
||||
mov rdx, [rbp+24] ; arg1
|
||||
|
||||
It is recommended to use the reg+reg*imm16+imm16 memory format:
|
||||
mov rax, [rbp + rcx * 8 + 16] ; accesses arg#rcx
|
||||
mov rax, [rbp+rcx*8+16] ; accesses arg#rcx
|
||||
|
||||
The 'va_list' type can be regarded as a pointer to the
|
||||
variadic function's rbp+16
|
||||
|
13
ka/dos.k
13
ka/dos.k
@ -4,16 +4,25 @@
|
||||
;
|
||||
; Entry point
|
||||
;
|
||||
_start:
|
||||
start:
|
||||
mov rsp, 0x200000
|
||||
xor rbp, rbp
|
||||
|
||||
call main
|
||||
|
||||
; Wait for and print input indefinitely
|
||||
.1:
|
||||
hlt
|
||||
scan rax
|
||||
xpause
|
||||
|
||||
test rax, rax
|
||||
j.z .1
|
||||
|
||||
prn rax
|
||||
jmp .1
|
||||
|
||||
|
||||
|
||||
include "inc/limits.k"
|
||||
include "crt/crt.k"
|
||||
|
||||
|
@ -1,10 +1,18 @@
|
||||
; The OS/K Team licenses this file to you under the MIT license.
|
||||
; See the LICENSE file in the project root for more information.
|
||||
|
||||
PrintBootMsg:
|
||||
mov ax0, .bootmsg
|
||||
call print
|
||||
ret
|
||||
|
||||
.bootmsg = "Starting DOS...\n\n"
|
||||
|
||||
;
|
||||
; Main function
|
||||
;
|
||||
main:
|
||||
call keybd_test
|
||||
call PrintBootMsg
|
||||
|
||||
ret
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
; The OS/K Team licenses this file to you under the MIT license.
|
||||
; See the LICENSE file in the project root for more information.
|
||||
|
||||
keybd_test:
|
||||
.1:
|
||||
scan rax
|
||||
xpause
|
||||
speed_test:
|
||||
utime lx0
|
||||
|
||||
test rax, rax
|
||||
j.z .1
|
||||
mov rcx, ax0
|
||||
nop.rep
|
||||
|
||||
prn rax
|
||||
jmp .1
|
||||
|
||||
ret
|
||||
utime lx1
|
||||
|
||||
mov rax, lx1
|
||||
sub rax, lx0
|
||||
|
||||
stop
|
||||
|
||||
putc_scroll_test:
|
||||
mov rdx, 25
|
||||
@ -55,18 +55,14 @@ cpudev_test:
|
||||
mov ax1, 1
|
||||
call IDT.AddHandler
|
||||
|
||||
trap 0
|
||||
trap 0
|
||||
trap 1
|
||||
|
||||
ret
|
||||
|
||||
trap0_test:
|
||||
mov rsp, 0x300000
|
||||
mov nx7, rax
|
||||
|
||||
mov ax0, .msg
|
||||
call print
|
||||
;mov ax0, .msg
|
||||
;call print
|
||||
|
||||
mov ax0, nx7
|
||||
call IDT.DoneHandling
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
verbose ?= yes
|
||||
OBJDIR = ob
|
||||
|
||||
FLAGS=-O2 -g -Wall -fno-builtin-log -I.
|
||||
|
||||
dv_src = $(shell ls dv/*.c)
|
||||
@ -39,9 +40,9 @@ $(OBJDIR)/%.o: %.c
|
||||
$(OBJDIR)/%.d: %.c
|
||||
@mkdir -p $(shell dirname $@)
|
||||
@cc -I. -MM -MT $(@:%.d=%.o) -MF $@ $<
|
||||
#@if [ $(verbose) = "yes" ]; then \
|
||||
# echo ${CL2}[$@] ${CL}dependencies generated.${CL3};\
|
||||
#fi
|
||||
# @if [ $(verbose) = "yes" ]; then \
|
||||
# echo ${CL2}[$@] ${CL}dependencies generated.${CL3};\
|
||||
# fi
|
||||
|
||||
in/instrs.lst: in/INSTRS in/arch_i.py
|
||||
@cd in && python3 arch_i.py
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
|
||||
long memdev_getmemoff(ctx_t *ctx, dev_t *dev)
|
||||
{
|
||||
|
10
vm/in/INSTRS
10
vm/in/INSTRS
@ -464,6 +464,16 @@ nop
|
||||
#
|
||||
pause
|
||||
|
||||
#
|
||||
# Get timestamp in seconds
|
||||
#
|
||||
time rm
|
||||
|
||||
#
|
||||
# Get timestamp in µseconds
|
||||
#
|
||||
utime rm
|
||||
|
||||
#
|
||||
# CPU Identification Number
|
||||
#
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
#include <in/instrs.h>
|
||||
|
||||
//
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <in/instrs.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <pc/console.h>
|
||||
|
||||
@ -57,6 +58,12 @@ IMPL_OUT;
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
IMPL_START_1(time)
|
||||
{
|
||||
v1 = time(NULL);
|
||||
}
|
||||
IMPL_OUT;
|
||||
|
||||
IMPL_START_1(utime)
|
||||
{
|
||||
struct timeval time;
|
||||
gettimeofday(&time, NULL);
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <in/instrs.h>
|
||||
|
||||
static volatile long *prev_stk;
|
||||
|
||||
IMPL_START_1(trap)
|
||||
{
|
||||
if (v1 > 255)
|
||||
|
11
vm/pc/arch.h
11
vm/pc/arch.h
@ -4,12 +4,15 @@
|
||||
#ifndef _ARCH_H
|
||||
#define _ARCH_H
|
||||
|
||||
//#define NDEBUG 1
|
||||
|
||||
#define dev_t stddev_t
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
@ -32,9 +35,11 @@ typedef struct arch_t arch_t;
|
||||
typedef struct dev_t dev_t;
|
||||
|
||||
void logerr(const char *, ...);
|
||||
void trace(const char *, ...);
|
||||
void vlog(const char *, va_list);
|
||||
|
||||
// void trace(const char *, ...);
|
||||
#define trace printf
|
||||
|
||||
#define KARCH_MAJOR 0
|
||||
#define KARCH_MINOR 1
|
||||
#define KARCH_REVIS 0
|
||||
@ -83,7 +88,7 @@ void disable_stdin_echoing(void);
|
||||
#include <pc/mem.h>
|
||||
#include <pc/sym.h>
|
||||
#include <pc/regs.h>
|
||||
#include <pc/decd.h>
|
||||
#include <pc/decode.h>
|
||||
#include <pc/except.h>
|
||||
#include <in/arch_i.h>
|
||||
|
||||
@ -91,5 +96,7 @@ extern ctx_t main_ctx;
|
||||
extern reg_t arch_r[NREGS];
|
||||
extern instr_t arch_i[NINSTRS];
|
||||
|
||||
extern size_t rfs_current_idx;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -262,6 +262,8 @@ void console_putc(ctx_t *ctx, char ch)
|
||||
{
|
||||
scr_rects[y]->y -= 16; // surf->h
|
||||
}
|
||||
|
||||
console_render(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,10 +167,6 @@ void decode(ctx_t *ctx)
|
||||
if (sym)
|
||||
trace("0x%lX: %s:\n", pc, sym->name);
|
||||
*/
|
||||
|
||||
// Instruction counter
|
||||
ctx->ninstrs++;
|
||||
|
||||
//
|
||||
// Process the first word of the instruction
|
||||
//
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
#include <pc/console.h>
|
||||
|
||||
void die(int code)
|
||||
|
@ -17,7 +17,7 @@ char *cond_suffixes[] =
|
||||
#define _ATT_STYLE 0
|
||||
#endif
|
||||
|
||||
static void dump_acc(ctx_t *ctx, acc_t *p);
|
||||
void dump_acc(ctx_t *ctx, acc_t *p);
|
||||
|
||||
void dump_instr(ctx_t *ctx,
|
||||
instr_t *in,
|
||||
@ -28,7 +28,7 @@ void dump_instr(ctx_t *ctx,
|
||||
uint cond,
|
||||
ulong pc)
|
||||
{
|
||||
trace("0x%lX:\t", pc);
|
||||
trace("%03lu 0x%lX:\t", ctx->ninstrs, pc);
|
||||
|
||||
if (lock)
|
||||
trace("lock");
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
|
||||
int dying = 0;
|
||||
|
||||
@ -10,6 +10,7 @@ void _except(ctx_t *ctx, int _code, char *fmt, ...)
|
||||
va_list ap;
|
||||
ulong handler;
|
||||
uint code = _code;
|
||||
volatile char ch;
|
||||
|
||||
ulong orig_frame;
|
||||
|
||||
@ -87,7 +88,7 @@ void _except(ctx_t *ctx, int _code, char *fmt, ...)
|
||||
|
||||
idt_handling[code]++;
|
||||
|
||||
main_loop();
|
||||
longjmp(exc_jmp_buf, code);
|
||||
}
|
||||
|
||||
actually_die:
|
||||
|
@ -25,6 +25,7 @@ enum
|
||||
};
|
||||
|
||||
extern int dying;
|
||||
extern jmp_buf exc_jmp_buf;
|
||||
|
||||
void main_loop(void) __attribute__((__noreturn__));
|
||||
void _except(ctx_t *, int, char *, ...) __attribute__((__noreturn__));
|
||||
|
12
vm/pc/exec.c
12
vm/pc/exec.c
@ -3,7 +3,7 @@
|
||||
|
||||
#include <pc/arch.h>
|
||||
|
||||
static bool eval_cond(ctx_t *ctx, uint cond)
|
||||
bool eval_cond(ctx_t *ctx, uint cond)
|
||||
{
|
||||
bool neg = cond & (1 << 4);
|
||||
bool ok;
|
||||
@ -56,8 +56,12 @@ void exec_instr(ctx_t *ctx,
|
||||
bool out;
|
||||
ulong r1 = 0, r2 = 0;
|
||||
|
||||
// Debugging
|
||||
// Instruction counter
|
||||
ctx->ninstrs++;
|
||||
|
||||
#ifndef NDEBUG
|
||||
dump_instr(ctx, in, p1, p2, lock, rep, cond, pc);
|
||||
#endif
|
||||
|
||||
//
|
||||
// For REPs we evaluate the condition AFTER running the instruction,
|
||||
@ -112,8 +116,12 @@ do_rep:
|
||||
if (rcx == 0)
|
||||
return;
|
||||
|
||||
ctx->ninstrs++;
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Show that we're REP'ing
|
||||
dump_instr(ctx, in, p1, p2, lock, rep, cond, pc);
|
||||
#endif
|
||||
|
||||
goto do_rep;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <pc/arch.h>
|
||||
|
||||
/*
|
||||
void trace(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -11,6 +12,7 @@ void trace(const char *fmt, ...)
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
*/
|
||||
|
||||
void logerr(const char *fmt, ...)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
#include <pc/console.h>
|
||||
|
||||
#define FWPROGSIZE (1024 * 1024 * 1024)
|
||||
@ -48,11 +48,15 @@ void sigsegv(int _)
|
||||
sigcommon();
|
||||
}
|
||||
|
||||
jmp_buf exc_jmp_buf;
|
||||
|
||||
//
|
||||
// Main loop
|
||||
//
|
||||
void main_loop(void)
|
||||
{
|
||||
setjmp(exc_jmp_buf);
|
||||
|
||||
//
|
||||
// Start decoding
|
||||
//
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <pc/device.h>
|
||||
|
||||
reg_t arch_r[] =
|
||||
{
|
||||
@ -79,14 +79,12 @@ reg_t arch_r[] =
|
||||
trace("%s=0x%-16lX ", r->name, R(i)); \
|
||||
} \
|
||||
|
||||
extern size_t rfs_current_idx;
|
||||
|
||||
void dumpregs(ctx_t *ctx)
|
||||
{
|
||||
int i;
|
||||
reg_t *r;
|
||||
|
||||
trace("Current RFRAME index: #%u\n", rfs_current_idx);
|
||||
trace("Current RFRAME index: #%lu\n", rfs_current_idx);
|
||||
|
||||
DUMPREGS(RAX, RDI);
|
||||
DUMPREGS(AX0, AX3);
|
||||
|
Loading…
Reference in New Issue
Block a user