This commit is contained in:
julianb0 2019-05-30 18:31:50 +02:00
parent 474de0309d
commit fa4457c567
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
15 changed files with 196 additions and 47 deletions

View File

@ -11,12 +11,21 @@ kas: kpc as/k-as.py as/regs.lst
@cp pc/instrs/instrs.lst as
@rm -f pc/instrs/instrs.lst
asm: dos/dos.k dos/print.k
@as/k-as.py dos/dos.k 0x100000 out/a.out
DOSK = $(shell find dos -name '*.k')
test: kas asm
out/a.out: $(DOSK)
@cd dos && ../as/k-as.py dos.k 0x100000 ../out/a.out
test: kas out/a.out
@out/k.exe out/a.out > out/stdout.txt
@echo "output:"
@echo ">>>>>>>>"
@cat out/stdout.txt
@echo
@echo "<<<<<<<<"
@echo
@rm -f out/a.out
disasm: kas asm
disasm: kas out/a.out
@out/k.exe os/a.out -d
@mv fwprog.dis out

View File

@ -263,7 +263,7 @@ def parse_preproc(line):
assert(written == 1)
pdata += 1
pdefs[tok[0] + "_len"] = str(real_len)
pdefs[label + "_len"] = str(real_len)
else:
print("Invalid format: {}".format(line))
@ -516,4 +516,4 @@ parse()
gentext()
genout()
leave()
sys.exit(0)

View File

@ -15,6 +15,15 @@ _start:
stop
jmp .1
include "dos/print.k"
include "dos/main.k"
;
; Include librairies
;
include "fmt/fmt.k"
include "prn/print.k"
include "str/string.k"
;
; Disk Operating System
;
include "main.k"

5
dos/fmt/fmt.k Normal file
View File

@ -0,0 +1,5 @@
; 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 "fmt/itoa.k"

6
dos/fmt/itoa.k Normal file
View File

@ -0,0 +1,6 @@
; 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 *itoa(char *buf, int num, int base)
;

View File

@ -9,20 +9,27 @@ main:
mov ax0, .msg
call print
break
call exit
mov ax0, .buf
mov ax1, .msg
call strrev
break
mov ax0, .buf
call print
leave
ret
.msg = "Hello World :)\n"
.buf = " "
;
; Exit function
;
exit:
enter
break
mov ax0, .msg
call print

6
dos/str/string.k Normal file
View File

@ -0,0 +1,6 @@
; 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 "str/strlen.k"
include "str/strrev.k"

39
dos/str/strlen.k Normal file
View File

@ -0,0 +1,39 @@
; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
;
; int strlen(char *)
;
strlen:
xor rax, rax
.1:
test b[ax0], b[ax0]
jz .2
inc rax
inc ax0
jmp .1
.2:
ret
;
; int strnlen(char *, int)
;
strnlen:
xor rax, rax
mov rcx, ax1
jcxz .2
dec rcx
.1:
test b[ax0], b[ax0]
jz .2
inc rax
inc ax0
loop .1
.2:
ret

33
dos/str/strrev.k Normal file
View File

@ -0,0 +1,33 @@
; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
;
; void strrev(char *buf, const char *str)
;
strrev:
test b[ax1], b[ax1]
cmovz b[ax0], 0
jz .4
.1:
test b[ax1+1], b[ax1+1]
jz .2
inc ax1
jmp .1
.2:
mov b[ax0], b[ax1]
test b[ax1], b[ax1]
jz .3
inc ax0
dec ax1
jmp .2
.3:
mov b[ax0+1], 0
.4:
ret

View File

@ -6,7 +6,7 @@ all: k.exe
src = instrs/instrs.c decd.c main.c regs.c dump.c \
instrs/jumps.c except.c disd.c mem.c instrs/logic.c \
instrs/stack.c instrs/super.c instrs/arith.c log.c \
instrs/debug.c
instrs/debug.c instrs/mov.c
obj = $(patsubst %.c,%.o,$(src))

View File

@ -137,7 +137,8 @@ jb i
jbe r
jbe i
jcxz
jcxz r
jcxz i
#
# Movement instructions
@ -160,6 +161,20 @@ xchg m m
lea r m
lea m m
cmovz r r
cmovz r i
cmovz r m
cmovz m r
cmovz m i
cmovz m m
cmovnz r r
cmovnz r i
cmovnz r m
cmovnz m r
cmovnz m i
cmovnz m m
#
# Stack manipulation instructions
#

View File

@ -12,40 +12,6 @@ IMPL_START_0(nop)
}
IMPL_END;
//
// Movement instructions
//
IMPL_START_2(mov)
{
v1 = v2;
}
IMPL_OUT;
IMPL_START_2(xchg)
{
ulong t = v1;
v1 = v2;
v2 = t;
}
IMPL_OUT;
IMPL_START_1(lea)
{
if (!p2->mem) {
_except(ctx, E_ILL, "Bad LEA format");
}
v1 = (p2->type == A_REG ? ctx->r[p2->val].val : p2->val) + p2->off;
}
IMPL_OUT;
IMPL_START_1(gcs)
{
v1 = ctx->r[CR1].val;
}
IMPL_OUT;
//
// Misc. instructions
//

54
pc/instrs/mov.c Normal file
View File

@ -0,0 +1,54 @@
// 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 "instrs.h"
#include "arch_i.h"
//
// Movement instructions
//
IMPL_START_2(mov)
{
v1 = v2;
}
IMPL_OUT;
IMPL_START_2(xchg)
{
ulong t = v1;
v1 = v2;
v2 = t;
}
IMPL_OUT;
IMPL_START_1(lea)
{
if (!p2->mem) {
_except(ctx, E_ILL, "Bad LEA format");
}
v1 = (p2->type == A_REG ? ctx->r[p2->val].val : p2->val) + p2->off;
}
IMPL_OUT;
IMPL_START_1(gcs)
{
v1 = ctx->r[CR1].val;
}
IMPL_OUT;
IMPL_START_2(cmovz)
{
if (ctx->r[FLG].val & ZF)
v1 = v2;
}
IMPL_OUT;
IMPL_START_2(cmovnz)
{
if (!(ctx->r[FLG].val & ZF))
v1 = v2;
}
IMPL_OUT;

View File

@ -71,7 +71,7 @@ int main(int argc, char **argv)
//log("Loaded %lu bytes
if (fwsize < 2) {
log("Error while reading program file\n");
log("Program file too small or empty\n");
exit(-3);
}