From f1eae1be22063b7222df1083dabed2e609427c24 Mon Sep 17 00:00:00 2001 From: julianb0 Date: Tue, 18 Jun 2019 23:04:55 +0200 Subject: [PATCH] cleaner --- ka/dos.k | 1 + ka/main.k | 192 ---------------------------------------------------- ka/tests.k | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+), 192 deletions(-) create mode 100644 ka/tests.k diff --git a/ka/dos.k b/ka/dos.k index 3e9e8d9..238d156 100644 --- a/ka/dos.k +++ b/ka/dos.k @@ -35,5 +35,6 @@ include "sys/memdev.k" ; ; Disk Operating System ; +include "tests.k" include "main.k" diff --git a/ka/main.k b/ka/main.k index fa8db15..0c0df0f 100644 --- a/ka/main.k +++ b/ka/main.k @@ -6,197 +6,5 @@ ; main: call cpudev_test - iret - -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 - - trap 0 - trap 0 - 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 rdi, 0x1111222233334444 - wswap rsx, rdi - - 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 rsx, b[rsp] - movzx rbi, w[rsp] - movzx rsi, l[rsp] - movzx rdi, 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 rsx, rax - - mov ax0, .buf2 - call strlen - - ret - -.msg = "Hello World :)" - -.buf1 = [32] -.buf2 = "!!!!!!!!!!!!!" - diff --git a/ka/tests.k b/ka/tests.k new file mode 100644 index 0000000..d188ad4 --- /dev/null +++ b/ka/tests.k @@ -0,0 +1,195 @@ +; The OS/K Team licenses this file to you under the MIT license. +; See the LICENSE file in the project root for more information. + +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 + + trap 0 + trap 0 + trap 1 + + 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 rdi, 0x1111222233334444 + wswap rsx, rdi + + 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 rsx, b[rsp] + movzx rbi, w[rsp] + movzx rsi, l[rsp] + movzx rdi, 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 rsx, rax + + mov ax0, .buf2 + call strlen + + ret + +.msg = "Hello World :)" + +.buf1 = [32] +.buf2 = "!!!!!!!!!!!!!"