mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
cpudev doc
This commit is contained in:
parent
d13da7b480
commit
d4a0c925a1
3
Makefile
3
Makefile
@ -29,3 +29,6 @@ test: kas vm/a.out
|
||||
@echo "<<<<<<<<"
|
||||
@echo
|
||||
|
||||
wc:
|
||||
@cat $(shell find -name *.[kch]) $(shell find -name *.py) | wc -l
|
||||
|
||||
|
25
ka/dos.k
25
ka/dos.k
@ -15,29 +15,10 @@ _start:
|
||||
jmp .1
|
||||
|
||||
;
|
||||
; Some definitions
|
||||
; Preprocessor misc.
|
||||
;
|
||||
|
||||
CHAR_MIN := 0x80
|
||||
SHRT_MIN := 0x8000
|
||||
INT_MIN := 0x80000000
|
||||
LONG_MIN := 0x8000000000000000
|
||||
|
||||
XCHAR_MIN := 0xFFFFFFFFFFFFFF80
|
||||
XSHRT_MIN := 0xFFFFFFFFFFFF8000
|
||||
XINT_MIN := 0xFFFFFFFF80000000
|
||||
|
||||
CHAR_MAX := 0x7F
|
||||
SHRT_MAX := 0x7FFF
|
||||
INT_MAX := 0x7FFFFFFF
|
||||
LONG_MAX := 0x7FFFFFFFFFFFFFFF
|
||||
|
||||
BYTE_MAX := 0xFF
|
||||
WORD_MAX := 0xFFFF
|
||||
LWORD_MAX := 0xFFFFFFFF
|
||||
QWORD_MAX := 0xFFFFFFFFFFFFFFFF
|
||||
|
||||
STRLEN_MAX := 0xFFFFFFFF
|
||||
include "inc/limits.k"
|
||||
include "inc/regs.k"
|
||||
|
||||
;
|
||||
; Include librairies
|
||||
|
23
ka/inc/limits.k
Normal file
23
ka/inc/limits.k
Normal file
@ -0,0 +1,23 @@
|
||||
; The OS/K Team licenses this file to you under the MIT license.
|
||||
; See the LICENSE file in the project root for more information.
|
||||
|
||||
CHAR_MIN := 0x80
|
||||
SHRT_MIN := 0x8000
|
||||
INT_MIN := 0x80000000
|
||||
LONG_MIN := 0x8000000000000000
|
||||
|
||||
XCHAR_MIN := 0xFFFFFFFFFFFFFF80
|
||||
XSHRT_MIN := 0xFFFFFFFFFFFF8000
|
||||
XINT_MIN := 0xFFFFFFFF80000000
|
||||
|
||||
CHAR_MAX := 0x7F
|
||||
SHRT_MAX := 0x7FFF
|
||||
INT_MAX := 0x7FFFFFFF
|
||||
LONG_MAX := 0x7FFFFFFFFFFFFFFF
|
||||
|
||||
BYTE_MAX := 0xFF
|
||||
WORD_MAX := 0xFFFF
|
||||
LWORD_MAX := 0xFFFFFFFF
|
||||
QWORD_MAX := 0xFFFFFFFFFFFFFFFF
|
||||
|
||||
STRLEN_MAX := 0xFFFFFFFF
|
66
ka/inc/regs.k
Normal file
66
ka/inc/regs.k
Normal file
@ -0,0 +1,66 @@
|
||||
; The OS/K Team licenses this file to you under the MIT license.
|
||||
; See the LICENSE file in the project root for more information.
|
||||
|
||||
ID_INV := 0
|
||||
ID_RIP := 1
|
||||
ID_FLG := 2
|
||||
ID_RBP := 3
|
||||
ID_RSP := 4
|
||||
ID_RX0 := 5
|
||||
ID_RX1 := 6
|
||||
ID_RX2 := 7
|
||||
|
||||
ID_RAX := 8
|
||||
ID_RBX := 9
|
||||
ID_RCX := 10
|
||||
ID_RDX := 11
|
||||
ID_RSX := 12
|
||||
ID_RBI := 13
|
||||
ID_RDI := 14
|
||||
ID_RSI := 15
|
||||
|
||||
ID_NX0 := 16
|
||||
ID_NX1 := 17
|
||||
ID_NX2 := 18
|
||||
ID_NX3 := 19
|
||||
ID_NX4 := 20
|
||||
ID_NX5 := 21
|
||||
ID_NX6 := 22
|
||||
ID_NX7 := 23
|
||||
|
||||
ID_AX0 := 24
|
||||
ID_AX1 := 25
|
||||
ID_AX2 := 26
|
||||
ID_AX3 := 27
|
||||
ID_AX4 := 28
|
||||
ID_AX5 := 29
|
||||
ID_AX6 := 30
|
||||
ID_AX7 := 31
|
||||
|
||||
ID_LX0 := 32
|
||||
ID_LX1 := 33
|
||||
ID_LX2 := 34
|
||||
ID_LX3 := 35
|
||||
ID_LX4 := 36
|
||||
ID_LX5 := 37
|
||||
ID_LX6 := 38
|
||||
ID_LX7 := 39
|
||||
|
||||
ID_CR0 := 40
|
||||
ID_CR1 := 41
|
||||
ID_CR2 := 42
|
||||
ID_CR3 := 43
|
||||
ID_CR4 := 44
|
||||
ID_CR5 := 45
|
||||
ID_CR6 := 46
|
||||
ID_CR7 := 47
|
||||
|
||||
ID_SA0 := 48
|
||||
ID_SA1 := 49
|
||||
ID_SA2 := 50
|
||||
ID_SA3 := 51
|
||||
ID_SA4 := 52
|
||||
ID_SA5 := 53
|
||||
ID_SA6 := 54
|
||||
ID_SA7 := 55
|
||||
|
29
vm/dv/CPUDEV
Normal file
29
vm/dv/CPUDEV
Normal file
@ -0,0 +1,29 @@
|
||||
# The OS/K Team licenses this file to you under the MIT license.
|
||||
# See the LICENSE file in the project root for more information.
|
||||
|
||||
CPU device function slots:
|
||||
|
||||
slot ax0 ax1 ax2 thr name desc
|
||||
0-15 - - - - (reserved) (reserved)
|
||||
16 - - - - getmaxidx rax = maximal index for a register frame
|
||||
17 - - - - getrfusage rax = number of register frames active
|
||||
18 - - - - getcuridx rax = index of the current register frame
|
||||
19 i - - - isactive rax = is register frame #ax0 active?
|
||||
20 i - - y activate activates register frame #ax0
|
||||
21 i - - y deactivate deactivates register frame #ax0 (losing all its contents!)
|
||||
22 i i - y copyframe copy contents of frame #ax1 into (active) frame #ax0
|
||||
23 i i - y moveframe move frame #ax1 to (inactive) frame index #ax0
|
||||
24-31 - - - - (reserved) (reserved)
|
||||
32 i - - - loadargs load registers ax0-ax7 from frame #ax0
|
||||
33 i r - - loadreg rax = register #ax1 from frame #ax0
|
||||
34-47 - - - - (reserved) (reserved)
|
||||
48 i r i y storereg store ax2 into register #ax1 from frame #ax0
|
||||
49-63 - - - - (reserved) (reserved)
|
||||
64 i i - y idtadd mark interrupt #ax0 as handled by register frame #ax1
|
||||
65 i - - y idtdel mark interrupt #ax0 as unhandled
|
||||
66 i - - - idtquery rax = interrupt #ax0 handled? rdx = index of handling frame
|
||||
|
||||
Arguments:
|
||||
i immediate
|
||||
r register index (0=inv, 1=rip, etc...)
|
||||
|
@ -3,10 +3,16 @@
|
||||
|
||||
#include <pc/dev.h>
|
||||
|
||||
#define MAX_RFRAME_IDX 255
|
||||
|
||||
//
|
||||
// Register frales
|
||||
//
|
||||
reg_t **rfs = NULL;
|
||||
size_t rfs_used = 0;
|
||||
|
||||
long cpudev_testfn(ctx_t *ctx, dev_t *dev)
|
||||
{
|
||||
assert(dev == &cpudev);
|
||||
|
||||
rax = 4;
|
||||
rdx = 3;
|
||||
|
||||
@ -15,10 +21,22 @@ long cpudev_testfn(ctx_t *ctx, dev_t *dev)
|
||||
|
||||
long cpudev_poweron(ctx_t *ctx, dev_t *dev)
|
||||
{
|
||||
assert(dev == &cpudev);
|
||||
rfs = malloc(sizeof(reg_t *) * (MAX_RFRAME_IDX + 1));
|
||||
|
||||
if (rfs == NULL)
|
||||
return -1;
|
||||
|
||||
dev->fslots[0] = cpudev_testfn;
|
||||
dev->state = DEVGOOD;
|
||||
|
||||
dev->fslots[0] = cpudev_testfn;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long cpudev_poweroff(ctx_t *ctx, dev_t *dev)
|
||||
{
|
||||
if (rfs)
|
||||
free(rfs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
23
vm/pc/arch.h
23
vm/pc/arch.h
@ -60,37 +60,16 @@ struct ctx_t
|
||||
|
||||
#define R(X) ctx->r[X].val
|
||||
|
||||
static inline ushort bswap16(ushort u)
|
||||
{ return ((u<<8) | (u>>8)); }
|
||||
|
||||
static inline char getmempref(ushort len)
|
||||
{ return (len==1?'b':(len==2?'w':(len==4?'l':(len==8?'q':'x')))); }
|
||||
|
||||
enum
|
||||
{
|
||||
E_SHT, // Shutdown instruction
|
||||
E_IMP, // Not implemented
|
||||
E_ILL, // Ill-formed
|
||||
E_ACC, // Invalid access
|
||||
E_SYS, // Supervisor only
|
||||
E_ALI, // Alignment error
|
||||
E_STA, // Stack misalignment
|
||||
E_STU, // Stack underflow
|
||||
NEXCPTS
|
||||
};
|
||||
|
||||
void dumpregs(ctx_t *);
|
||||
void dumpinstr(ctx_t *, ulong, uint, ushort, acc_t *, acc_t *);
|
||||
void dumpmem(ctx_t *, ulong, ulong);
|
||||
|
||||
void _except(ctx_t *, int, char *, ...) __attribute__((__noreturn__));
|
||||
|
||||
void decode(ctx_t *ctx);
|
||||
|
||||
|
||||
#include <pc/mem.h>
|
||||
#include <pc/regs.h>
|
||||
#include <pc/decd.h>
|
||||
#include <pc/except.h>
|
||||
#include <in/arch_i.h>
|
||||
|
||||
extern reg_t arch_r[NREGS];
|
||||
|
18
vm/pc/except.h
Normal file
18
vm/pc/except.h
Normal file
@ -0,0 +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.
|
||||
|
||||
enum
|
||||
{
|
||||
E_SHT, // Shutdown instruction
|
||||
E_UDF, // Undefined behavior
|
||||
E_IMP, // Not implemented
|
||||
E_ILL, // Ill-formed
|
||||
E_ACC, // Invalid access
|
||||
E_SYS, // Supervisor only
|
||||
E_ALI, // Alignment error
|
||||
E_STA, // Stack misalignment
|
||||
E_STU, // Stack underflow
|
||||
NEXCPTS
|
||||
};
|
||||
|
||||
void _except(ctx_t *, int, char *, ...) __attribute__((__noreturn__));
|
@ -1,6 +1,12 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
static inline ushort bswap16(ushort u)
|
||||
{ return ((u<<8) | (u>>8)); }
|
||||
|
||||
static inline char getmempref(ushort len)
|
||||
{ return (len==1?'b':(len==2?'w':(len==4?'l':(len==8?'q':'x')))); }
|
||||
|
||||
#define MEMOFF (1 * 1024 * 1024)
|
||||
#define MEMSIZE (16 * 1024 * 1024) // 16MB
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user