This commit is contained in:
julianb0 2019-07-24 17:42:42 +02:00
parent f89e535fbd
commit 334053b24c
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
7 changed files with 53 additions and 410 deletions

View File

@ -13,7 +13,7 @@ from collections import OrderedDict
#print("k-as command line: '{}'".format(sys.argv))
WANT_DISASM = False
WANT_DISASM = True
if len(sys.argv) != 5:
print("Usage: {} (source file) (memory entry point) (output file) (symbols file)"
@ -306,8 +306,8 @@ def parse_preproc(line):
i = int(s, base=0)
if (i % 8) != 0:
i = i + (8 - i % 8)
# if (i % 8) != 0:
# i = i + (8 - i % 8)
written = b_data.write(bytearray(i))
assert(written == i)
@ -350,10 +350,10 @@ def parse_preproc(line):
l = real_len + 1 # s + null-term
# align
if (l % 8) != 0:
for i in range(8 - l % 8):
written = b_data.write(int(0).to_bytes(1, byteorder='little', signed=False))
pdata += 1
#if (l % 8) != 0:
# for i in range(8 - l % 8):
# written = b_data.write(int(0).to_bytes(1, byteorder='little', signed=False))
# pdata += 1
pdefs[label + "_len"] = str(real_len)
@ -629,12 +629,12 @@ def parse_instr(line):
# [reg+reg+imm]
else:
instr_args += "%%imm8 {} {} {} %%imm16 {}".format(fmts["m_rriw"]|mlen, reg1, reg2, imm2)
instr_args += "%%imm8 {} {} {} %%signed %%imm16 {}".format(fmts["m_rriw"]|mlen, reg1, reg2, imm2)
size += 5
# [reg+reg*imm+imm]
else:
instr_args += "%%imm8 {} {} {} %%imm8 {} %%imm32 {}".format(fmts["m_rriw"]|mlen, reg1, reg2, imm1, imm2)
instr_args += "%%imm8 {} {} {} %%imm8 {} %%signed %%imm32 {}".format(fmts["m_rrii"]|mlen, reg1, reg2, imm1, imm2)
size += 8
# [reg]
@ -644,7 +644,7 @@ def parse_instr(line):
# [imm], converted to [zero+imm]
else:
instr_args += "%%imm8 {} zero zero %%imm32 {}".format(fmts["m_rrid"]|mlen, word)
instr_args += "%%imm8 {} zero zero %%signed %%imm32 {}".format(fmts["m_rrid"]|mlen, word)
size += 7
continue
@ -665,15 +665,31 @@ def parse_instr(line):
word = str(pregs[word[1:]])
# fallthrough
# for now every immediate is 64-bit
# immediates
if is_number(word):
size += 9 # ModRM + imm
n = int(word, base=0)
instr_name += "_i"
instr_args += "%%imm8 {} ".format(fmts["imm64"])
instr_args += "%%imm64 {}".format(word)
fellthrough = False
if n < 0 or n > 0xFFFFFFFF:
size += 9
instr_args += "%%imm8 {} ".format(fmts["imm64"])
instr_args += "%%imm64 {}".format(word)
elif n > 0xFFFF:
size += 5
instr_args += "%%imm8 {} ".format(fmts["imm32"])
instr_args += "%%imm32 {}".format(word)
elif n > 0xFF:
size += 3
instr_args += "%%imm8 {} ".format(fmts["imm16"])
instr_args += "%%imm16 {}".format(word)
else:
size += 2
instr_args += "%%imm8 {} ".format(fmts["imm8"])
instr_args += "%%imm8 {}".format(word)
continue
# register
@ -825,5 +841,13 @@ parse()
gentext()
genout()
gensym()
#-------------------------------------------------------------------------------
print("Finished producing {}\n\ttext section size: {} bytes\n\tdata section size: {} bytes\n" \
.format(sys.argv[3], ptext, pdata))
leave(0)
#-------------------------------------------------------------------------------

View File

@ -6,10 +6,10 @@ __cmdstart:
include "crt/crt.k"
FILE_LOADP := 0x141000 ; 4KB above stack
FILE_LOADP := 0x121000 ; 4KB above stack
start:
mov rsp, 0x140000
mov rsp, 0x120000
mov rbp, zero
cls

View File

@ -2,11 +2,6 @@
; See the LICENSE file in the project root for more information.
__sysmain:
pause
add rax, rax, 1
jmp .1
.1:
jmp start
@ -16,12 +11,12 @@ include "crt/crt.k"
; Special addresses
;
DOSKRNL_CODE := 0x100000 ; 1MB (code)
DOSKRNL_STACK := 0x120000 ; + 128KB
TRAP0_STACK := 0x124000 ; + 16KB
INTR0_STACK := 0x128000 ; + 16KB
EXCT0_STACK := 0x12B000 ; + 16KB
DOSKRNL_STACK := 0x110000 ; + 64KB
TRAP0_STACK := 0x112000 ; + 8KB
INTR0_STACK := 0x114000 ; + 8KB
EXCT0_STACK := 0x118000 ; + 8KB
CMDCOM_LOADP := 0x140000 ; 1MB + 256KB
CMDCOM_LOADP := 0x120000 ; 1MB + 128KB
CMDCOM_MAXSZ := 0x80000 ; 512KB
;
@ -31,9 +26,6 @@ start:
mov rsp, DOSKRNL_STACK
mov rbp, zero
mov rcx, 1
crash.cxz
call main
crash

View File

@ -1,373 +0,0 @@
; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
arith128_test:
call .test_add
call .test_sub
ret
.print_lq:
push rax
push rdx
mov ax0, .fmt
call printf
add rsp, rsp, 16
prn 10
ret
.fmt = "0x%x:%x"
.test_add:
mov ax0, 0x99AABBCCDDEEFF00
mov ax1, 0x1122334455667788
mov ax2, 0xFF
call add_lq_q
call .print_lq
mov ax0, 0xFFFFFFFFFFFFFFFF
mov ax1, zero
mov ax2, 5
call add_lq_q
call .print_lq
mov ax0, 0x5500660077008800
mov ax1, 0x1100220033004400
mov ax2, 0x00AA00BB00CC00DD
mov ax3, 0x009900CE00DF00AB
call add_lq_lq
call .print_lq
ret
.test_sub:
mov ax0, 0x99AABBCCDDEEFFFF
mov ax1, 0x1122334455667788
mov ax2, 0xFF
call sub_lq_q
call .print_lq
mov ax0, zero
mov ax1, zero
mov ax2, 2
call sub_lq_q
call .print_lq
ret
file_test:
.bufsize := 256
mov ax0, .fn
call DISK.OpenFile
push rax
mov ax0, rax
mov ax1, .buf
mov ax2, .bufsize
call DISK.ReadFile
mov rcx, .bufsize
mov rdx, .buf
prns.rep.nz rdx
pop rax
call DISK.CloseFile
hlt
ret
.fn = "doskrnl.sym"
.buf = [.bufsize]
movsx_test:
mov rcx, 0x1188FF
movsxb rx8, rcx
movsxw rx9, rcx
movsxl r10, rcx
hlt
ret
dir_test:
mov ax0, .buf
mov ax1, 128
call DISK.FindFirst
jmp .list
.next:
mov ax0, .buf
mov ax1, 128
call DISK.FindNext
.list:
test rax, rax
j.z .nothing
mov ax0, .fnd
call print
mov ax0, .buf
call print
prn 10
jmp .next
.nothing:
mov ax0, .err
call print
ret
.buf = [128]
.fnd = "File found: "
.err = "No more files found"
strtol_test:
mov ax0, .s1
mov ax1, 10
call strtol
mov nx0, rax
mov ax0, .s2
mov ax1, 16
call strtol
mov nx1, rax
mov ax0, .s3
mov ax1, 0
call strtol
mov nx2, rax
mov ax0, .s4
mov ax1, 10
call strtol
mov nx3, rax
ret
.s1 = "+065536"
.s2 = "0xABCD"
.s3 = "0b100000"
.s4 = "-1"
speed_test:
utime rx8
mov rcx, ax0
nop.rep
utime rx9
mov rax, rx9
sub rax, rx8
ret
putc_scroll_test:
mov rdx, 25
.1:
mov rcx, 79
prn.rep '+'
prn '!'
dec rdx
test rdx, rdx
j.nz .1
mov rcx, 80
prn.rep '&'
mov rcx, 80
prn.rep '%'
call showoff
ret
cpudev_test:
call RFS.GetLeastAvail
mov rbx, rax
call RFS.GetCurIdx
mov rcx, rax
call RFS.GetMaxIdx
mov rdx, rax
mov ax0, 1
call RFS.ActivateFrame
mov ax0, 1
mov ax1, $rip
mov ax2, trap0_test
call RFS.StoreReg
mov ax0, 256
mov ax1, 1
call IDT.AddHandler
ret
trap0_test:
mov rsp, 0x300000
mov nx7, rax
;mov ax0, .msg
;call print
mov ax0, nx7
call IDT.DoneHandling
iret
.msg = "Handling TRAP #0 !\n"
showoff:
call ramdev_test
call bswap_test
call itoa_test
prn 10
call str_test
call movzx_test
prn 10
call printf_test
ret
printf_test:
mov ax0, .fmt
sub rsp, 128
mov q[rsp+40], 0x7FE
mov q[rsp+32], -2
mov q[rsp+24], 666
mov q[rsp+16], 0x112233DDAA6677BB
mov q[rsp+8], 'K'
mov q[rsp], .str
call printf
add rsp, 128
ret
.fmt = "%% Hello World %s - %c - %p - %d - %d - %b"
.str = "(cc)"
strchr_test:
mov rax, 0
mov ax0, .str
mov ax1, 33
call strchr
prn b[rax]
ret
.str = "Hello World!"
bswap_test:
mov rdx, 0x1122334455667788
bswap rax, rdx
mov rsi, 0x1111222233334444
wswap rx9, rsi
mov ax3, 0x1111111122222222
dswap ax0, ax3
ret
ramdev_test:
call MEM.GetMemOff
mov rdx, rax
call MEM.GetMemSize
ret
movzx_test:
enter 1
mov q[rsp], 0xFABC1234CCCCDDDD
mov rax, b[rsp]
mov rbx, w[rsp]
mov rcx, l[rsp]
mov rdx, q[rsp]
movzx rsi, b[rsp]
movzx rdi, w[rsp]
movzx rx8, l[rsp]
movzx rx9, q[rsp]
leave
ret
itoa_test:
mov ax0, .buf
mov ax1, LONG_MIN
mov ax2, 10
call itoa
mov ax0, rax
call print
prn 10
mov ax0, .buf
mov ax1, 0xfff85ffffffffff4
mov ax2, 16
call itoa
mov ax0, rax
call print
ret
.buf = [32]
devtest:
mov ax0, .buf
devctl 0, 1
mov ax0, .buf
call print
iocall 0, 0
ret
.buf = [32]
str_test:
mov ax0, .msg
call print
mov ax0, .buf1
mov ax1, .msg
call strcpy
prn 10
mov ax0, .buf1
call print
mov ax0, .buf2
mov ax1, .msg
mov ax2, 8
call strnzcpy
prn 10
mov ax0, .buf2
mov ax1, 12
call print_n
mov ax0, .msg
mov ax1, .buf1
call strcmp
mov rbx, rax
mov ax0, .buf2
mov ax1, .msg
call strcmp
mov r13, rax
mov ax0, .buf2
call strlen
ret
.msg = "Hello World :)"
.buf1 = [32]
.buf2 = "!!!!!!!!!!!!!"

View File

@ -185,7 +185,7 @@ static void extract_param(ctx_t *ctx, uint prm, acc_t *p)
p->reg1 = fetchb(ctx);
p->reg2 = fetchb(ctx);
p->imm1 = fetchb(ctx);
p->imm2 = (short)fetchw(ctx);
p->imm2 = (short)fetchd(ctx);
break;
case 6:

View File

@ -27,8 +27,8 @@ enum
enum
{
A_NONE = 0b00000,
A_REG = 0b00001,
A_NONE = 0,
A_REG = 3,
A_IMM8 = 1,
A_IMM16 = 2,

View File

@ -5,7 +5,7 @@
#define ABS(x) ((short)(x) < 0 ? -x : x)
char *cond_suffixes[] =
static const char *cond_suffixes[] =
{
"-",
"c", "o", "z", "s", "p",
@ -14,7 +14,7 @@ char *cond_suffixes[] =
"?"
};
void dump_acc(ctx_t *ctx, acc_t *p);
static void dump_acc(ctx_t *ctx, acc_t *p);
void dump_instr(ctx_t *ctx,
instr_t *in,
@ -70,7 +70,7 @@ void dump_instr(ctx_t *ctx,
trace("\n");
}
void dump_acc(ctx_t *ctx, acc_t *p)
static void dump_acc(ctx_t *ctx, acc_t *p)
{
uint mfmt;
sym_t *sym;