This commit is contained in:
julianb0 2019-09-07 16:45:03 +02:00
parent bd4a38592b
commit bdfd5ea9cf
No known key found for this signature in database
GPG Key ID: 9C7ACF0C053FB8A1
23 changed files with 711 additions and 691 deletions

View File

@ -74,22 +74,42 @@ pcurfile = sys.argv[1]
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
pregs = { pregs = {
'$r0': 0, '$rax': 0, '$r1': 1, '$rbx': 1, '$r0': 0, '$eax': 0, '$rax': 0,
'$r2': 2, '$rcx': 2, '$r3': 3, '$rdx': 3, '$r1': 1, '$ebx': 1, '$rbx': 1,
'$r4': 4, '$rsi': 4, '$r5': 5, '$rdi': 5, '$r2': 2, '$ecx': 2, '$rcx': 2,
'$r6': 6, '$ax0': 6, '$r7': 7, '$ax1': 7, '$r3': 3, '$edx': 3, '$rdx': 3,
'$r8': 8, '$ax2': 8, '$r9': 9, '$ax3': 9, '$r4': 4, '$esi': 4, '$rsi': 4,
'$r10': 10, '$ax4': 10, '$r11': 11, '$ax5': 11, '$r5': 5, '$edi': 5, '$rdi': 5,
'$r12': 12, '$nx0': 12, '$r13': 13, '$nx1': 13,
'$r14': 14, '$nx2': 14, '$r15': 15, '$nx3': 15, '$r6': 6, '$ax0': 6,
'$r16': 16, '$nx4': 16, '$r17': 17, '$nx5': 17, '$r7': 7, '$ax1': 7,
'$r18': 18, '$nx6': 18, '$r19': 19, '$nx7': 19, '$r8': 8, '$ax2': 8,
'$r20': 20, '$nx8': 20, '$r21': 21, '$grp': 21, '$r9': 9, '$ax3': 9,
'$r22': 22, '$trp': 22, '$r23': 23, '$srp': 23, '$r10': 10, '$ax4': 10,
'$r24': 24, '$tmp': 24, '$r25': 25, '$rad': 25, '$r11': 11, '$ax5': 11,
'$r26': 26, '$cr0': 26, '$r27': 27, '$cr1': 27,
'$r28': 28, '$rip': 28, '$r29': 29, '$rbp': 29, '$r12': 12, '$nx0': 12,
'$r30': 30, '$rsp': 30, '$r31': 31, '$zero': 31, '$r13': 13, '$nx1': 13,
'$r14': 14, '$nx2': 14,
'$r15': 15, '$nx3': 15,
'$r16': 16, '$nx4': 16,
'$r17': 17, '$nx5': 17,
'$r18': 18, '$nx6': 18,
'$r19': 19, '$nx7': 19,
'$r20': 20, '$nx8': 20,
'$r21': 21, '$grp': 21,
'$r22': 22, '$trp': 22,
'$r23': 23, '$srp': 23,
'$r24': 24, '$tmp': 24,
'$r25': 25, '$rad': 25,
'$r26': 26, '$cr0': 26,
'$r27': 27, '$cr1': 27,
'$r28': 28, '$eip': 28, '$rip': 28,
'$r29': 29, '$ebp': 29, '$rbp': 29,
'$r30': 30, '$esp': 30, '$rsp': 30,
'$r31': 31, '$nul': 31, '$zero': 31,
} }
def parse_lst_instrs(): def parse_lst_instrs():

View File

@ -12,21 +12,21 @@ cmdstart:
; COMMAND.COM guarantees that programs ; COMMAND.COM guarantees that programs
; are always loaded on a 16KB boundary ; are always loaded on a 16KB boundary
; This is guaranteed to be the case ; This is guaranteed to be the case
; in all future versions as well ; in all future veesions as well
#define FILE_LOADP 0x108000 // + 32KB #define FILE_LOADP 0x108000 // + 32KB
start: start:
mov rsp, CMDCOM_STACK mov esp, CMDCOM_STACK
mov rbp, zero mov ebp, zero
call main call main
mov rax, Sys.EnterHaltMode mov eax, Sys.EnterHaltMode
trap 0 trap 0
crash crash
cmd.versionstr = "COMMAND.COM, version 0.1 (KVISC)\nCopyright (C) 2019, The OS/K Team\nMIT license (permissive), see LICENCE file in source tree" cmd.veesionstr = "COMMAND.COM, veesion 0.1 (KVISC)\nCopyright (C) 2019, The OS/K Team\nMIT license (permissive), see LICENCE file in source tree"
argbuf.size := 256 argbuf.size := 256
argbuf = [argbuf.size] argbuf = [argbuf.size]
@ -38,12 +38,12 @@ stdin_echoing = 1
prompt = [32] prompt = [32]
main: main:
mov rsi, prompt mov esi, prompt
mov b[rsi+0], 'C' mov b[esi+0], 'C'
mov b[rsi+1], ':' mov b[esi+1], ':'
mov b[rsi+2], '\' mov b[esi+2], '\'
mov b[rsi+3], '>' mov b[esi+3], '>'
mov b[rsi+4], ' ' mov b[esi+4], ' '
.print_prompt: .print_prompt:
call print, prompt call print, prompt
@ -56,7 +56,7 @@ main:
; call nprint, argv0, argbuf.size ; call nprint, argv0, argbuf.size
; iterator through argbuf ; iterator through argbuf
nul rcx nul ecx
.input_loop: .input_loop:
pause pause
@ -64,22 +64,22 @@ main:
pause pause
; Fill .buf with user input ; Fill .buf with user input
scan rax scan eax
jraxz .input_loop jraxz .input_loop
; ESC key pressed? ; ESC key pressed?
beq rax, 0x1B, .handle_EXIT beq eax, 0x1B, .handle_EXIT
; backspace character? ; backspace character?
bne rax, 8, .handle_input bne eax, 8, .handle_input
; anything to delete? ; anything to delete?
jrcxz .input_loop ; no jrcxz .input_loop ; no
; yes, delete it ; yes, delete it
dec rcx dec ecx
add rdx, rcx, argbuf add edx, ecx, argbuf
nul b[rdx] nul b[edx]
; update screen ; update screen
bzr b[stdin_echoing], .input_loop bzr b[stdin_echoing], .input_loop
@ -89,19 +89,19 @@ main:
.handle_input: .handle_input:
bzr b[stdin_echoing], .se.z bzr b[stdin_echoing], .se.z
prn rax prn eax
.se.z: .se.z:
beq rax, 10, .extract_argv0 beq eax, 10, .extract_argv0
; when max line length is reached, ; when max line length is reached,
; force a newline ; force a newline
beq rcx, argbuf.size, .extract_argv0 beq ecx, argbuf.size, .extract_argv0
; add character to buffer and increase iterator (rcx) ; add character to buffer and increase iterator (ecx)
add rdx, rcx, argbuf add edx, ecx, argbuf
mov b[rdx], rax mov b[edx], eax
inc rcx inc ecx
; another one ; another one
jmp .input_loop jmp .input_loop
@ -112,43 +112,43 @@ main:
jrcxz .print_prompt jrcxz .print_prompt
; find first whitespace or null-terminator ; find first whitespace or null-terminator
mov rcx, argbuf.size mov ecx, argbuf.size
mov rdx, argbuf mov edx, argbuf
scasb rdx, ' ' scasb edx, ' '
; argv1 exists? if so, save its position ; argv1 exists? if so, save its position
mov rsi, rdx mov esi, edx
.next_space: .next_space:
mov rcx, b[rsi] mov ecx, b[esi]
jrcxz .do_extract jrcxz .do_extract
; skip spaces ; skip spaces
bne rcx, ' ', .not_a_space bne ecx, ' ', .not_a_space
inc rsi inc esi
jmp .next_space jmp .next_space
.not_a_space: .not_a_space:
; if we're here, we found a ; if we're here, we found a
; non-zero non-space character ; non-zero non-space character
mov q[argv1pos], rsi mov q[argv1pos], esi
; fallthrough ; fallthrough
.do_extract: .do_extract:
; how much do we copy? ; how much do we copy?
sub rcx, rdx, argbuf sub ecx, edx, argbuf
jrcxz .detect_builtin jrcxz .detect_builtin
dec rcx dec ecx
mov rdi, argbuf mov edi, argbuf
mov rsi, argv0 mov esi, argv0
.copy_loop: .copy_loop:
mov b[rsi], b[rdi] mov b[esi], b[edi]
inc rdi inc edi
inc rsi inc esi
loop .copy_loop loop .copy_loop
@ -238,12 +238,12 @@ main:
.handle_DATE: .handle_DATE:
call GetTimeUTC call GetTimeUTC
mov rcx, b[rax+4] mov ecx, b[eax+4]
inc rcx inc ecx
push b[rax+3], rcx, w[rax+6] push b[eax+3], ecx, w[eax+6]
call printf, .datefmt call printf, .datefmt
add rsp, 40 add esp, 40
jmp .print_prompt jmp .print_prompt
@ -254,22 +254,22 @@ main:
jmp .print_prompt jmp .print_prompt
.handle_ECHO: .handle_ECHO:
mov rax, q[argv1pos] mov eax, q[argv1pos]
jraxz .echo.end jraxz .echo.end
call print, rax call print, eax
.echo.end: .echo.end:
prn 10 prn 10
jmp .print_prompt jmp .print_prompt
.handle_EXIT: .handle_EXIT:
mov rax, Sys.Shutdown mov eax, Sys.Shutdown
trap 0 trap 0
jmp .print_prompt jmp .print_prompt
.handle_HALT: .handle_HALT:
mov rax, Sys.EnterHaltMode mov eax, Sys.EnterHaltMode
trap 0 trap 0
jmp .print_prompt jmp .print_prompt
@ -284,16 +284,16 @@ main:
.handle_TIME: .handle_TIME:
call GetTimeUTC call GetTimeUTC
push b[rax], b[rax+1], b[rax+2] push b[eax], b[eax+1], b[eax+2]
call printf, .timefmt call printf, .timefmt
add rsp, 24 add esp, 24
jmp .print_prompt jmp .print_prompt
.timefmt = "%d:%d:%d\n" .timefmt = "%d:%d:%d\n"
.handle_VERS: .handle_VERS:
call print, cmd.versionstr call print, cmd.veesionstr
prn 10 prn 10
jmp .print_prompt jmp .print_prompt
@ -333,12 +333,12 @@ main:
.helpmsg.prompt = " PROMPT Change the command line prompt\n" .helpmsg.prompt = " PROMPT Change the command line prompt\n"
.helpmsg.remove = " REMOVE Delete a file (permanently)\n" .helpmsg.remove = " REMOVE Delete a file (permanently)\n"
.helpmsg.time = " TIME Display current time of day\n" .helpmsg.time = " TIME Display current time of day\n"
.helpmsg.ver = " VERS Display current COMMAND.COM version\n" .helpmsg.ver = " VERS Display current COMMAND.COM veesion\n"
.exec_not_found: .exec_not_found:
push argv0 push argv0
call printf, .enf_errmsg call printf, .enf_errmsg
add rsp, 8 add esp, 8
jmp .print_prompt jmp .print_prompt
@ -347,7 +347,7 @@ main:
.file_not_found: .file_not_found:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .fnf_errmsg call printf, .fnf_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -356,7 +356,7 @@ main:
.empty_file: .empty_file:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .ef_errmsg call printf, .ef_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -365,7 +365,7 @@ main:
.couldnt_open: .couldnt_open:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .cno_errmsg call printf, .cno_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -374,7 +374,7 @@ main:
.couldnt_remove: .couldnt_remove:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .cne_errmsg call printf, .cne_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -383,7 +383,7 @@ main:
.couldnt_read: .couldnt_read:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .cnr_errmsg call printf, .cnr_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt

View File

@ -50,7 +50,7 @@
#include "crt/fmt/printf.k" #include "crt/fmt/printf.k"
exit: exit:
mov rax, Sys.Exit mov eax, Sys.Exit
trap 0 trap 0
abort: abort:

View File

@ -6,73 +6,73 @@
; int doprnt(PUTC putc, int n, const char *fmt, va_list ap) ; int doprnt(PUTC putc, int n, const char *fmt, va_list ap)
; ;
doprnt: doprnt:
push rbp push ebp
mov rbp, rsp mov ebp, esp
push r12, r13, r14 push nx0, nx1, nx2
push r15, r16, r17 push nx3, nx4, nx5
mov r12, ax2 ; fmt mov nx0, ax2 ; fmt
mov r14, ax3 ; va_list mov nx2, ax3 ; va_list
mov r15, ax1 ; n mov nx3, ax1 ; n
mov r17, ax0 ; putc mov nx5, ax0 ; putc
nul r16 ; return value nul nx4 ; return value
.main_loop: .main_loop:
; find '%' or null-terminator ; find '%' or null-terminator
mov rcx, STRLEN_MAX mov ecx, STRLEN_MAX
mov r13, r12 mov nx1, nx0
scasb r13, '%' scasb nx1, '%'
; everything below r13 is a regular character; print it ; everything below nx1 is a regular character; print it
.print_regular: .print_regular:
beq r12, r13, .check_modf beq nx0, nx1, .check_modf
call .doput, b[r12] call .doput, b[nx0]
inc r12 inc nx0
jmp .print_regular jmp .print_regular
.check_modf: .check_modf:
; did we find a '%' ? ; did we find a '%' ?
; if not, then we found fmt's null-terminator; we're done ; if not, then we found fmt's null-terminator; we're done
bne b[r12], '%', .epilogue bne b[nx0], '%', .epilogue
; we did find a modifier / '%' ; we did find a modifier / '%'
mov rax, b[r12+1] mov eax, b[nx0+1]
add r12, 2 add nx0, 2
beq rax, 's', .modf_s beq eax, 's', .modf_s
beq rax, 'c', .modf_c beq eax, 'c', .modf_c
beq rax, 'p', .modf_p beq eax, 'p', .modf_p
beq rax, 'x', .modf_x beq eax, 'x', .modf_x
beq rax, 'd', .modf_d beq eax, 'd', .modf_d
beq rax, 'o', .modf_o beq eax, 'o', .modf_o
beq rax, 'b', .modf_b beq eax, 'b', .modf_b
beq rax, '%', .modf_percent beq eax, '%', .modf_percent
; unrecognized ; unrecognized
jmp .bad_modifier jmp .bad_modifier
.modf_s: .modf_s:
; get string address ; get string address
mov r13, q[r14] mov nx1, q[nx2]
add r14, 8 add nx2, 8
bzr r13, .nullstring bzr nx1, .nullstring
.print_string: .print_string:
movzx ax0, b[r13] movzx ax0, b[nx1]
bzr ax0, .main_loop bzr ax0, .main_loop
inc r13 inc nx1
call .doput call .doput
jmp .print_string jmp .print_string
.modf_c: .modf_c:
call .doput, q[r14] call .doput, q[nx2]
add r14, 8 add nx2, 8
jmp .main_loop jmp .main_loop
@ -99,24 +99,24 @@ doprnt:
.print_number: .print_number:
; allocate itoa conversion buffer ; allocate itoa conversion buffer
sub rsp, 80 sub esp, 80
mov r13, rsp mov nx1, esp
; assume modifier already set up ax2 ; assume modifier already set up ax2
call itoa, rsp, q[r14] call itoa, esp, q[nx2]
add r14, 8 add nx2, 8
.print_itoa_buf: .print_itoa_buf:
movzx ax0, b[r13] movzx ax0, b[nx1]
bzr ax0, .pib_end_loop bzr ax0, .pib_end_loop
inc r13 inc nx1
call .doput call .doput
jmp .print_itoa_buf jmp .print_itoa_buf
.pib_end_loop: .pib_end_loop:
add rsp, 80 add esp, 80
jmp .main_loop jmp .main_loop
.modf_percent: .modf_percent:
@ -142,11 +142,11 @@ doprnt:
jmp .main_loop jmp .main_loop
.epilogue: .epilogue:
mov rax, r16 mov eax, nx4
pop r17, r16 pop nx5, nx4
pop r15, r14 pop nx3, nx2
pop r13, r12 pop nx1, nx0
leave leave
ret ret
@ -155,23 +155,23 @@ doprnt:
; ;
.doput: .doput:
; update print count ; update print count
inc r16 inc nx4
; if n==0, don't print ; if n==0, don't print
; we follow the C convention that sprintf()-like functions ; we follow the C convention that sprintf()-like functions
; should return the number of characters that would have ; should return the number of characters that would have
; been printed/written if 'n' were big enough ; been printed/written if 'n' were big enough
bzr r15, .r bzr nx3, .r
; decrement n and print ; decrement n and print
dec r15 dec nx3
call r17 call nx5
; did putc fail? ; did putc fail?
jraxz .r jraxz .r
; yes, so artificially set n=0 ; yes, so artificially set n=0
nul r15 nul nx3
.r: .r:
ret ret

View File

@ -19,8 +19,8 @@ utoa:
; void ltostr(char *buf, int num, int base, bool signed) ; void ltostr(char *buf, int num, int base, bool signed)
; ;
ltostr: ltostr:
mov rax, ax0 mov eax, ax0
nul rcx nul ecx
; make sure base is in [2, 32] ; make sure base is in [2, 32]
bltu ax2, 2, .bad bltu ax2, 2, .bad
@ -34,7 +34,7 @@ ltostr:
bzr ax3, .conv bzr ax3, .conv
bne ax2, 10, .conv ; base 10 bne ax2, 10, .conv ; base 10
shr rcx, ax1, 63 ; extract ax1 sign shr ecx, ax1, 63 ; extract ax1 sign
jrcxz .conv jrcxz .conv
neg ax1 ; NEG if negative neg ax1 ; NEG if negative
@ -43,18 +43,18 @@ ltostr:
.conv: .conv:
bzr ax1, .fini bzr ax1, .fini
rem rdx, ax1, ax2 ; ax1 % base rem edx, ax1, ax2 ; ax1 % base
blt 9, rdx, .nondec ; rdx > 9 ? blt 9, edx, .nondec ; edx > 9 ?
add rdx, '0' add edx, '0'
jmp .next jmp .next
.nondec: .nondec:
add rdx, 55 ; 'A' - 10 add edx, 55 ; 'A' - 10
.next: .next:
mov b[ax0], rdx mov b[ax0], edx
inc ax0 inc ax0
@ -70,7 +70,7 @@ ltostr:
.cxz: .cxz:
nul b[ax0] nul b[ax0]
call strrev2, rax call strrev2, eax
ret ret
; ;

View File

@ -6,7 +6,7 @@
; ;
putc: putc:
prn ax0 prn ax0
nul rax nul eax
ret ret
; ;
@ -16,7 +16,7 @@ printf:
mov ax2, ax0 mov ax2, ax0
mov ax0, putc mov ax0, putc
mov ax1, STRLEN_MAX mov ax1, STRLEN_MAX
add ax3, rsp, 8 add ax3, esp, 8
jmp doprnt jmp doprnt
; ;
@ -25,19 +25,19 @@ printf:
nprintf: nprintf:
mov ax2, ax0 mov ax2, ax0
mov ax0, putc mov ax0, putc
add ax3, rsp, 8 add ax3, esp, 8
jmp doprnt jmp doprnt
; ;
; Print a string ; Print a string
; Guaranteed to only affect rcx and ax0 ; Guaranteed to only affect ecx and ax0
; ;
print: print:
.l: .l:
movzx rax, b[ax0] movzx eax, b[ax0]
jraxz .r jraxz .r
prn rax prn eax
inc ax0 inc ax0
jmp .l jmp .l
@ -49,7 +49,7 @@ print:
; Print exactly ax1 characters ; Print exactly ax1 characters
; ;
nprint: nprint:
mov rcx, ax1 mov ecx, ax1
jrcxz .r jrcxz .r
.l: .l:

View File

@ -4,8 +4,8 @@
; ;
; int strtol(const char *str, int base) ; int strtol(const char *str, int base)
; ;
; rax = integer extracted from str ; eax = integer extracted from str
; rdx = pointer to first invalid byte ; edx = pointer to first invalid byte
; ;
strtol: strtol:
mov ax2, 1 mov ax2, 1
@ -14,8 +14,8 @@ strtol:
; ;
; int strtoul(const char *str, int base) ; int strtoul(const char *str, int base)
; ;
; rax = integer extracted from str ; eax = integer extracted from str
; rdx = pointer to first invalid byte ; edx = pointer to first invalid byte
; ;
strtoul: strtoul:
nul ax2 nul ax2
@ -27,49 +27,49 @@ strtoul:
; guesses base when 'base'=0 ; guesses base when 'base'=0
; ;
strtoq: strtoq:
nul rax, rsi nul eax, esi
mov rdx, ax0 mov edx, ax0
; make sure base is in [2, 32] ; make sure base is in [2, 32]
beq ax1, 1, .bad beq ax1, 1, .bad
bltu 36, ax1, .bad bltu 36, ax1, .bad
; empty string? ; empty string?
bzr b[rdx], .done bzr b[edx], .done
.skip_spc: .skip_spc:
bne b[rdx], ' ', .no_spc bne b[edx], ' ', .no_spc
inc rdx inc edx
jmp .skip_spc jmp .skip_spc
.no_spc: .no_spc:
; skip + ; skip +
bne b[rdx], '+', .no_plus bne b[edx], '+', .no_plus
inc rdx inc edx
.no_plus: .no_plus:
; unsigned? ; unsigned?
bzr ax2, .unsigned bzr ax2, .unsigned
; parse '-' ; parse '-'
bne b[rdx], '-', .unsigned bne b[edx], '-', .unsigned
inc rdx inc edx
mov rsi, 1 mov esi, 1
.unsigned: .unsigned:
; base 0 ; base 0
bzr ax1, .base_0 bzr ax1, .base_0
; base prefix? ; base prefix?
bne b[rdx], '0', .main_loop bne b[edx], '0', .main_loop
inc rdx inc edx
movzx rcx, b[rdx] movzx ecx, b[edx]
; "0x"/"0b" prefix ; "0x"/"0b" prefix
jrcxz .done ; "0" jrcxz .done ; "0"
beq rcx, 'x', .parsed_0x beq ecx, 'x', .parsed_0x
beq rcx, 'b', .parsed_0b beq ecx, 'b', .parsed_0b
; may be octal, but we don't care ; may be octal, but we don't care
; we accept "0110101010" (despite base=2) for instance ; we accept "0110101010" (despite base=2) for instance
@ -77,40 +77,40 @@ strtoq:
.parsed_0x: .parsed_0x:
; are we in base 16? ; are we in base 16?
; if not, leave rax = 0 and *rdx = 'x' ; if not, leave eax = 0 and *edx = 'x'
bne ax1, 16, .done bne ax1, 16, .done
; else ; else
inc rdx inc edx
jmp .main_loop jmp .main_loop
.parsed_0b: .parsed_0b:
; are we in base 2? ; are we in base 2?
; if not, leave rax = 0 and *rdx = 'b' ; if not, leave eax = 0 and *edx = 'b'
bne ax1, 2, .done bne ax1, 2, .done
; else ; else
inc rdx inc edx
jmp .main_loop jmp .main_loop
.base_0: .base_0:
; guess base ; guess base
beq b[rdx], '0', .b0_not10 beq b[edx], '0', .b0_not10
; must be base 10 ; must be base 10
mov ax1, 10 mov ax1, 10
jmp .main_loop jmp .main_loop
.b0_not10: .b0_not10:
inc rdx inc edx
bne b[rdx], 'x', .b0_not16 bne b[edx], 'x', .b0_not16
inc rdx inc edx
mov ax1, 16 mov ax1, 16
jmp .main_loop jmp .main_loop
.b0_not16: .b0_not16:
bne b[rdx], 'b', .b0_not2 bne b[edx], 'b', .b0_not2
inc rdx inc edx
mov ax1, 2 mov ax1, 2
jmp .main_loop jmp .main_loop
@ -119,45 +119,45 @@ strtoq:
mov ax1, 8 mov ax1, 8
.main_loop: .main_loop:
movzx rcx, b[rdx] movzx ecx, b[edx]
inc rdx inc edx
; between 0 and 9? ; between 0 and 9?
bltu rcx, '0', .done bltu ecx, '0', .done
bltu '9', rcx, .not_digit10 bltu '9', ecx, .not_digit10
; yes ; yes
sub rcx, '0' sub ecx, '0'
jmp .next jmp .next
.not_digit10: .not_digit10:
bltu rcx, 'A', .done bltu ecx, 'A', .done
bltu 'Z', rcx, .not_digitAZ bltu 'Z', ecx, .not_digitAZ
sub rcx, 55 ; 'A' - 10 sub ecx, 55 ; 'A' - 10
jmp .next jmp .next
.not_digitAZ: .not_digitAZ:
bltu rcx, 'a', .done bltu ecx, 'a', .done
bltu 'z', rcx, .done bltu 'z', ecx, .done
sub rcx, 87 ; 'a' - 10 sub ecx, 87 ; 'a' - 10
jmp .next jmp .next
.next: .next:
; too large for base? ; too large for base?
blteu ax1, rcx, .done blteu ax1, ecx, .done
mul rax, ax1 mul eax, ax1
add rax, rcx add eax, ecx
jmp .main_loop jmp .main_loop
.done: .done:
; negative? ; negative?
bzr rsi, .r bzr esi, .r
; yes ; yes
neg rax neg eax
.r: .r:
ret ret

View File

@ -5,12 +5,12 @@
; void memcpy(void *, const void *, int) ; void memcpy(void *, const void *, int)
; ;
memcpy: memcpy:
mov rcx, ax2 mov ecx, ax2
jrcxz .r jrcxz .r
.l: .l:
sub rdx, ax2, rcx sub edx, ax2, ecx
mov b[ax0+rdx], b[ax1+rdx] mov b[ax0+edx], b[ax1+edx]
loop .l loop .l
.r: .r:
@ -20,7 +20,7 @@ memcpy:
; void memzero(void *, int) ; void memzero(void *, int)
; ;
memzero: memzero:
mov rcx, ax1 mov ecx, ax1
jrcxz .r jrcxz .r
.l: .l:

View File

@ -5,21 +5,21 @@
; int strnlen(char *, int) ; int strnlen(char *, int)
; ;
strnlen: strnlen:
mov rcx, ax1 mov ecx, ax1
scasb ax0, zero scasb ax0, zero
sub rax, ax1, rcx sub eax, ax1, ecx
ret ret
; ;
; int strlen(char *) ; int strlen(char *)
; ;
strlen: strlen:
mov rcx, STRLEN_MAX mov ecx, STRLEN_MAX
mov rdx, rcx mov edx, ecx
scasb ax0, zero scasb ax0, zero
sub rax, rdx, rcx sub eax, edx, ecx
ret ret
; ;
@ -27,8 +27,8 @@ strlen:
; ;
strcpy: strcpy:
.l: .l:
mov rcx, b[ax1] mov ecx, b[ax1]
mov b[ax0], rcx mov b[ax0], ecx
jrcxz .r jrcxz .r
@ -44,7 +44,7 @@ strcpy:
; void strncpy(char *, const char *, int) ; void strncpy(char *, const char *, int)
; ;
strncpy: strncpy:
mov rcx, ax2 mov ecx, ax2
jrcxz .r jrcxz .r
.l: .l:
@ -62,12 +62,12 @@ strncpy:
; void strnzcpy(char *, const char *, int) ; void strnzcpy(char *, const char *, int)
; ;
strnzcpy: strnzcpy:
mov rcx, ax2 mov ecx, ax2
jrcxz .r jrcxz .r
.l: .l:
mov rax, b[ax1] mov eax, b[ax1]
mov b[ax0], rax mov b[ax0], eax
jraxz .r jraxz .r
@ -91,68 +91,68 @@ strnzcpy:
; <0 if the first character that does not match has a lower value in str1 than in str2 ; <0 if the first character that does not match has a lower value in str1 than in str2
; ;
strcmp: strcmp:
nul rsi nul esi
.l: .l:
movzx rax, b[ax0+rsi] movzx eax, b[ax0+esi]
movzx rdx, b[ax1+rsi] movzx edx, b[ax1+esi]
bne rax, rdx, .r bne eax, edx, .r
; both zero? ; both zero?
add rcx, rax, rdx add ecx, eax, edx
jrcxz .r jrcxz .r
inc rsi inc esi
jmp .l jmp .l
.r: .r:
sub rax, rdx sub eax, edx
ret ret
; ;
; int strncmp(const char *str1, const char *str2, int maxn) ; int strncmp(const char *str1, const char *str2, int maxn)
; ;
strncmp: strncmp:
mov rcx, ax2 mov ecx, ax2
jrcxz .r jrcxz .r
.l: .l:
movzx rax, b[ax0] movzx eax, b[ax0]
movzx rdx, b[ax1] movzx edx, b[ax1]
bne rax, rdx, .r bne eax, edx, .r
inc ax0 inc ax0
inc ax1 inc ax1
loop .l loop .l
.r: .r:
sub rax, rdx sub eax, edx
ret ret
; ;
; char *strchrnul(const char *str, int ch) ; char *strchrnul(const char *str, int ch)
; ;
strchrnul: strchrnul:
mov rcx, STRLEN_MAX mov ecx, STRLEN_MAX
scasb ax0, ax1 scasb ax0, ax1
mov rax, ax0 mov eax, ax0
ret ret
; ;
; char *strchr(const char *str, int ch) ; char *strchr(const char *str, int ch)
; ;
strchr: strchr:
mov rcx, STRLEN_MAX mov ecx, STRLEN_MAX
scasb ax0, ax1 scasb ax0, ax1
bnz b[ax0], .r bnz b[ax0], .r
nul rax nul eax
ret ret
.r: .r:
mov rax, ax0 mov eax, ax0
ret ret
; ;
@ -164,11 +164,11 @@ strrev:
bzr b[ax1], .z bzr b[ax1], .z
; save str's location ; save str's location
mov rsi, ax1 mov esi, ax1
; go to str's end, just before ; go to str's end, just before
; the null terminator ; the null terminator
mov rcx, STRLEN_MAX mov ecx, STRLEN_MAX
scasb ax1, zero scasb ax1, zero
dec ax1 dec ax1
@ -177,7 +177,7 @@ strrev:
; and forward through buf ; and forward through buf
mov b[ax0], b[ax1] mov b[ax0], b[ax1]
beq ax1, rsi, .r beq ax1, esi, .r
inc ax0 inc ax0
dec ax1 dec ax1
@ -203,7 +203,7 @@ strrev2:
; go to str's end, just before ; go to str's end, just before
; the null terminator ; the null terminator
mov rcx, STRLEN_MAX mov ecx, STRLEN_MAX
scasb ax1, zero scasb ax1, zero
dec ax1 dec ax1

View File

@ -21,22 +21,22 @@
; int DaysInYear(int year) ; int DaysInYear(int year)
; ;
DaysInYear: DaysInYear:
mov rax, 365 mov eax, 365
; divisible by 4? ; divisible by 4?
rem rcx, ax0, 4 rem ecx, ax0, 4
jrcxnz .end jrcxnz .end
; divisible by 100? ; divisible by 100?
rem rcx, ax0, 100 rem ecx, ax0, 100
jrcxnz .leap jrcxnz .leap
; divisible by 400? ; divisible by 400?
rem rcx, ax0, 400 rem ecx, ax0, 400
jrcxnz .end jrcxnz .end
.leap: .leap:
inc rax inc eax
.end: .end:
ret ret
@ -47,37 +47,37 @@ DaysInYear:
GetTimeUTC: GetTimeUTC:
ytime ytime
mov rdi, .buf mov edi, .buf
; seconds ; seconds
rem rsi, rax, 60 rem esi, eax, 60
mov b[rdi], rsi mov b[edi], esi
; minutes ; minutes
div rsi, rax, 60 div esi, eax, 60
rem rsi, 60 rem esi, 60
mov b[rdi+1], rsi mov b[edi+1], esi
; hours ; hours
div rsi, rax, 3600 div esi, eax, 3600
rem rsi, 24 rem esi, 24
mov b[rdi+2], rsi mov b[edi+2], esi
; month days ; month days
div rsi, rax, 3600*24 div esi, eax, 3600*24
mov b[rdi+3], rsi mov b[edi+3], esi
; month ; month
mov b[rdi+4], rbx mov b[edi+4], rbx
; years ; years
mov w[rdi+6], rcx mov w[edi+6], ecx
; ;
; ydays (TODO) ; ydays (TODO)
; ;
mov rax, .buf mov eax, .buf
ret ret
.buf = [24] .buf = [24]

View File

@ -26,8 +26,8 @@ __sysmain:
; Entry point ; Entry point
; ;
start: start:
mov rsp, DOSKRNL_STACK mov esp, DOSKRNL_STACK
mov rbp, zero mov ebp, zero
;dump ;dump

View File

@ -7,8 +7,8 @@ start:
#include "crt/crt.k" #include "crt/crt.k"
main: main:
mov rsp, 0x104000 mov esp, 0x104000
nul rbp nul ebp
call print, .hellow call print, .hellow

View File

@ -2,122 +2,122 @@
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
dumprf: dumprf:
push rbp push ebp
mov rbp, rsp mov ebp, esp
push r12, r13 push nx0, nx1
mov r12, ax0 mov nx0, ax0
mov r13, rsp mov nx1, esp
call RFS.LoadReg, r12, $cr1 call RFS.LoadReg, nx0, $cr1
push rax push eax
call RFS.LoadReg, r12, $cr0 call RFS.LoadReg, nx0, $cr0
push rax push eax
call RFS.LoadReg, r12, $rip call RFS.LoadReg, nx0, $eip
push rax push eax
push r12 push nx0
call printf, .dmp1 call printf, .dmp1
call RFS.LoadReg, r12, $srp call RFS.LoadReg, nx0, $srp
push rax push eax
call RFS.LoadReg, r12, $trp call RFS.LoadReg, nx0, $trp
push rax push eax
push zero # fixme push zero # fixme
call RFS.LoadReg, r12, $rbp call RFS.LoadReg, nx0, $ebp
push rax push eax
call RFS.LoadReg, r12, $rsp call RFS.LoadReg, nx0, $esp
push rax push eax
call printf, .dmp2 call printf, .dmp2
call RFS.LoadReg, r12, $ax5 call RFS.LoadReg, nx0, $ax5
push rax push eax
call RFS.LoadReg, r12, $ax4 call RFS.LoadReg, nx0, $ax4
push rax push eax
call RFS.LoadReg, r12, $ax3 call RFS.LoadReg, nx0, $ax3
push rax push eax
call RFS.LoadReg, r12, $ax2 call RFS.LoadReg, nx0, $ax2
push rax push eax
call RFS.LoadReg, r12, $ax1 call RFS.LoadReg, nx0, $ax1
push rax push eax
call RFS.LoadReg, r12, $ax0 call RFS.LoadReg, nx0, $ax0
push rax push eax
call printf, .dmp3 call printf, .dmp3
call RFS.LoadReg, r12, $rdi call RFS.LoadReg, nx0, $edi
push rax push eax
call RFS.LoadReg, r12, $rsi call RFS.LoadReg, nx0, $esi
push rax push eax
call RFS.LoadReg, r12, $rdx call RFS.LoadReg, nx0, $edx
push rax push eax
call RFS.LoadReg, r12, $rcx call RFS.LoadReg, nx0, $ecx
push rax push eax
call RFS.LoadReg, r12, $rbx call RFS.LoadReg, nx0, $ebx
push rax push eax
call RFS.LoadReg, r12, $rax call RFS.LoadReg, nx0, $eax
push rax push eax
call printf, .dmp4 call printf, .dmp4
call RFS.LoadReg, r12, $r17 call RFS.LoadReg, nx0, $nx5
push rax push eax
call RFS.LoadReg, r12, $r16 call RFS.LoadReg, nx0, $nx4
push rax push eax
call RFS.LoadReg, r12, $r15 call RFS.LoadReg, nx0, $nx3
push rax push eax
call RFS.LoadReg, r12, $r14 call RFS.LoadReg, nx0, $nx2
push rax push eax
call RFS.LoadReg, r12, $r13 call RFS.LoadReg, nx0, $nx1
push rax push eax
call RFS.LoadReg, r12, $r12 call RFS.LoadReg, nx0, $nx0
push rax push eax
call printf, .dmp5 call printf, .dmp5
call RFS.LoadReg, r12, $r20 call RFS.LoadReg, nx0, $nx8
push rax push eax
call RFS.LoadReg, r12, $r19 call RFS.LoadReg, nx0, $nx7
push rax push eax
call RFS.LoadReg, r12, $r18 call RFS.LoadReg, nx0, $nx6
push rax push eax
call printf, .dmp6 call printf, .dmp6
mov rsp, r13 mov esp, nx1
pop r13, r12 pop nx1, nx0
leave leave
ret ret
.dmp1 = "Environ #1:\nfrm=0d%d rip=0x%x\ncr0=0x%x cr1=0x%x\n\n" .dmp1 = "Environ #1:\nfrm=0d%d eip=0x%x\ncr0=0x%x cr1=0x%x\n\n"
.dmp2 = "Environ #2:\nrsp=0x%x rbp=0x%x ind=0d%d\ngrp=0x%x trp=0x%x srp=0x%x\n\n" .dmp2 = "Environ #2:\nesp=0x%x ebp=0x%x ind=0d%d\ngrp=0x%x trp=0x%x srp=0x%x\n\n"
.dmp3 = "Argument:\nax0=0x%x ax1=0x%x ax2=0x%x\nax3=0x%x ax4=0x%x ax5=0x%x\n\n" .dmp3 = "Argument:\nax0=0x%x ax1=0x%x ax2=0x%x\nax3=0x%x ax4=0x%x ax5=0x%x\n\n"
.dmp4 = "Volatile:\nrax=0x%x rbx=0x%x rcx=0x%x\nrdx=0x%x rsi=0x%x rdi=0x%x\n\n" .dmp4 = "Volatile:\neax=0x%x ebx=0x%x ecx=0x%x\nrdx=0x%x esi=0x%x edi=0x%x\n\n"
.dmp5 = "Persistent:\nr12=0x%x r13=0x%x r14=0x%x\nr15=0x%x r16=0x%x r17=0x%x\n" .dmp5 = "Persistent:\nnx0=0x%x nx1=0x%x nx2=0x%x\nr15=0x%x nx4=0x%x nx5=0x%x\n"
.dmp6 = "r18=0x%x r19=0x%x r20=0x%x\n" .dmp6 = "nx6=0x%x nx7=0x%x nx8=0x%x\n"

View File

@ -2,8 +2,8 @@
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
ScreenOfDeath: ScreenOfDeath:
push r12 push nx0
mov r12, ax0 mov nx0, ax0
prn 10 prn 10
prn PRN_CLEAR prn PRN_CLEAR
@ -13,13 +13,13 @@ ScreenOfDeath:
call printf, .scr1 call printf, .scr1
pop pop
bnz r14, .not_con bnz nx2, .not_con
push .scr2_con push .scr2_con
jmp .do_print jmp .do_print
.not_con: .not_con:
; rframes #2-#3-#4 belong to kernel ; rframes #2-#3-#4 belong to kernel
blt 4, r14, .not_krn blt 4, nx2, .not_krn
push .scr2_krn push .scr2_krn
jmp .do_print jmp .do_print
@ -27,11 +27,11 @@ ScreenOfDeath:
push .scr2_usr push .scr2_usr
.do_print: .do_print:
push r14, r12 push nx2, nx0
call printf, .scr2 call printf, .scr2
add rsp, 24 add esp, 24
call dumprf, r14 call dumprf, nx2
prn 10 prn 10
call print, .scr3 call print, .scr3
@ -40,11 +40,11 @@ ScreenOfDeath:
pause pause
pause pause
scan rax scan eax
jraxz .loop jraxz .loop
beq rax, 0x0A, DefaultTrapHandler.handle_Exit beq eax, 0x0A, DefaultTrapHandler.handle_Exit
beq rax, 0x1B, DefaultTrapHandler.handle_Shutdown beq eax, 0x1B, DefaultTrapHandler.handle_Shutdown
jmp .loop jmp .loop

View File

@ -2,14 +2,14 @@
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
DefaultExceptionHandler: DefaultExceptionHandler:
mov rsp, EXCT0_STACK mov esp, EXCT0_STACK
mov ax1, r12 mov ax1, nx0
bzr r12, DefaultTrapHandler.handle_Shutdown bzr nx0, DefaultTrapHandler.handle_Shutdown
bltu 11, r12, .unknown bltu 11, nx0, .unknown
mov rsi, .err_ukn mov esi, .err_ukn
lea ax0, b[rsi + r12 * 32] lea ax0, b[esi + nx0 * 32]
call ScreenOfDeath call ScreenOfDeath
.unknown: .unknown:

View File

@ -2,27 +2,27 @@
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
TrapHandlers.prolog: TrapHandlers.prolog:
nul rbp nul ebp
; rax = caller's cr1 ; eax = caller's cr1
call RFS.LoadReg, r14, $cr1 call RFS.LoadReg, nx2, $cr1
; we don't preserve the r12 we got ; we don't preserve the nx0 we got
mov r12, rax mov nx0, eax
nul rdx nul edx
jmp rcx jmp ecx
TrapHandlers.epilog: TrapHandlers.epilog:
; TRAP return values: RAX-RDX ; TRAP return values: eax-edx
mov ax2, rax mov ax2, eax
call RFS.StoreReg, r14, $rax call RFS.StoreReg, nx2, $eax
mov ax2, rdx mov ax2, edx
call RFS.StoreReg, r14, $rdx call RFS.StoreReg, nx2, $edx
call IDT.DoneHandling, r13 call IDT.DoneHandling, nx1
iret iret
@ -32,42 +32,42 @@ TrapHandlers.epilog:
DefaultTrapHandler: DefaultTrapHandler:
.init: .init:
mov rcx, .text mov ecx, .text
mov rsp, TRAP0_STACK mov esp, TRAP0_STACK
jmp TrapHandlers.prolog jmp TrapHandlers.prolog
.text: .text:
call RFS.LoadReg, r14, $rax call RFS.LoadReg, nx2, $eax
call RFS.LoadArgs, r14 call RFS.LoadArgs, nx2
; will be optimized with a table ; will be optimized with a table
; when we have a "finished" consistent API ; when we have a "finished" consistent API
jraxz .handle_Shutdown jraxz .handle_Shutdown
beq rax, Sys.Exit, .handle_Exit beq eax, Sys.Exit, .handle_Exit
beq rax, Sys.ExecuteInFrame, .handle_EIF beq eax, Sys.ExecuteInFrame, .handle_EIF
beq rax, Sys.ReadFile, .handle_ReadFile beq eax, Sys.ReadFile, .handle_ReadFile
beq rax, Sys.OpenFile, .handle_OpenFile beq eax, Sys.OpenFile, .handle_OpenFile
beq rax, Sys.CloseFile, .handle_CloseFile beq eax, Sys.CloseFile, .handle_CloseFile
beq rax, Sys.CreateFile, .handle_CreateFile beq eax, Sys.CreateFile, .handle_CreateFile
beq rax, Sys.RemoveFile, .handle_RemoveFile beq eax, Sys.RemoveFile, .handle_RemoveFile
beq rax, Sys.FindNext, .handle_FindNext beq eax, Sys.FindNext, .handle_FindNext
beq rax, Sys.FindFirst, .handle_FindFirst beq eax, Sys.FindFirst, .handle_FindFirst
beq rax, Sys.EnterHaltMode, .handle_HaltMode beq eax, Sys.EnterHaltMode, .handle_HaltMode
.sod: .sod:
call ScreenOfDeath, .badsyscall, r13 call ScreenOfDeath, .badsyscall, nx1
.wrong: .wrong:
call ScreenOfDeath, .badparams, r13 call ScreenOfDeath, .badparams, nx1
.fini.savecx: .fini.savecx:
mov ax2, rcx mov ax2, ecx
call RFS.StoreReg, r14, $rcx call RFS.StoreReg, nx2, $ecx
.fini: .fini:
jmp TrapHandlers.epilog jmp TrapHandlers.epilog
.badsyscall = "Invalid syscall number in RAX" .badsyscall = "Invalid syscall number in eax"
.badparams = "Invalid syscall parameters" .badparams = "Invalid syscall parameters"
;------------------------------------------------; ;------------------------------------------------;
@ -79,46 +79,46 @@ DefaultTrapHandler:
; ;
.handle_Exit: .handle_Exit:
; deactivate current rframe ; deactivate current rframe
bzr r14, .hE_nz ; unless it's 0... bzr nx2, .hE_nz ; unless it's 0...
call RFS.DeactivateFrame, r14 call RFS.DeactivateFrame, nx2
.hE_nz: .hE_nz:
; open COMMAND.COM ; open COMMAND.COM
call DISK.OpenFile, .cmdcom call DISK.OpenFile, .cmdcom
; crash on failure ; crash on failure
bltz rax, abort bltz eax, abort
; load at CMDCOM_LOADP ; load at CMDCOM_LOADP
mov ax1, CMDCOM_LOADP mov ax1, CMDCOM_LOADP
mov ax2, CMDCOM_MAXSZ mov ax2, CMDCOM_MAXSZ
call DISK.ReadFile, rax call DISK.ReadFile, eax
; assume that COMMAND.COM being ; assume that COMMAND.COM being
; less then 4KB means something ; less then 4KB means something
; went wrong ; went wrong
blt rax, 0x1000, abort blt eax, 0x1000, abort
; close the handle ; close the handle
call DISK.CloseFile, rax call DISK.CloseFile, eax
; code address ; code address
mov ax2, 0x100000 mov ax2, 0x100000
call RFS.StoreReg, zero, $rip call RFS.StoreReg, zero, $eip
; usermode ; usermode
mov ax2, 3 mov ax2, 3
call RFS.StoreReg, zero, $cr0 call RFS.StoreReg, zero, $cr0
mov rcx, CMDCOM_LOADP mov ecx, CMDCOM_LOADP
sub rcx, 0x100000 sub ecx, 0x100000
; code offset ; code offset
mov ax2, rcx mov ax2, ecx
call RFS.StoreReg, zero, $cr1 call RFS.StoreReg, zero, $cr1
; return frame ; return frame
nul r14 nul nx2
jmp .fini jmp .fini
@ -127,39 +127,39 @@ DefaultTrapHandler:
.handle_EIF: .handle_EIF:
blt ax1, 5, .wrong blt ax1, 5, .wrong
; RIP can't be <1MB ; eip can't be <1MB
mov rcx, 0x100000 mov ecx, 0x100000
blt ax0, rcx, .wrong blt ax0, ecx, .wrong
; add old CR1 ; add old CR1
add ax0, r12 add ax0, nx0
; real RIP can't be <1MB+32KB either ; real eip can't be <1MB+32KB either
; (kernel + cmdcom personal space) ; (kernel + cmdcom personal space)
add rdx, rcx, 0x8000 add edx, ecx, 0x8000
blt ax0, rcx, .wrong blt ax0, ecx, .wrong
; save rframe and compute new CR1 ; save rframe and compute new CR1
mov rbx, ax1 mov ebx, ax1
sub rdi, ax0, rcx sub edi, ax0, ecx
; activate rframe ; activate rframe
call RFS.ActivateFrame, rbx call RFS.ActivateFrame, ebx
; save new CR1 ; save new CR1
mov ax2, rdi mov ax2, edi
call RFS.StoreReg, rbx, $cr1 call RFS.StoreReg, ebx, $cr1
; interruptible user mode ; interruptible user mode
mov ax2, 3 mov ax2, 3
call RFS.StoreReg, rbx, $cr0 call RFS.StoreReg, ebx, $cr0
; set RIP = 1MB ; set eip = 1MB
mov ax2, rcx mov ax2, ecx
call RFS.StoreReg, rbx, $rip call RFS.StoreReg, ebx, $eip
; change return frame ; change return frame
mov r14, rbx mov nx2, ebx
jmp .fini jmp .fini
@ -167,27 +167,27 @@ DefaultTrapHandler:
; Disk API ; Disk API
; ;
.handle_FindFirst: .handle_FindFirst:
add ax0, r12 add ax0, nx0
call DISK.FindFirst call DISK.FindFirst
jmp .fini.savecx jmp .fini.savecx
.handle_FindNext: .handle_FindNext:
add ax0, r12 add ax0, nx0
call DISK.FindNext call DISK.FindNext
jmp .fini.savecx jmp .fini.savecx
.handle_OpenFile: .handle_OpenFile:
add ax0, r12 add ax0, nx0
call DISK.OpenFile call DISK.OpenFile
jmp .fini jmp .fini
.handle_CreateFile: .handle_CreateFile:
add ax0, r12 add ax0, nx0
call DISK.CreateFile call DISK.CreateFile
jmp .fini jmp .fini
.handle_RemoveFile: .handle_RemoveFile:
add ax0, r12 add ax0, nx0
call DISK.RemoveFile call DISK.RemoveFile
jmp .fini jmp .fini
@ -196,7 +196,7 @@ DefaultTrapHandler:
jmp .fini jmp .fini
.handle_ReadFile: .handle_ReadFile:
add ax1, r12 add ax1, nx0
call DISK.ReadFile call DISK.ReadFile
jmp .fini jmp .fini

View File

@ -13,7 +13,7 @@ PrintBootMsg:
InitSyscalls: InitSyscalls:
call RFS.ActivateFrame, 1 call RFS.ActivateFrame, 1
mov ax1, $rip mov ax1, $eip
mov ax2, DefaultTrapHandler mov ax2, DefaultTrapHandler
call RFS.StoreReg call RFS.StoreReg
@ -26,14 +26,14 @@ InitSyscalls:
InitExcepts: InitExcepts:
call RFS.ActivateFrame, 2 call RFS.ActivateFrame, 2
mov ax1, $rip mov ax1, $eip
mov ax2, DefaultExceptionHandler mov ax2, DefaultExceptionHandler
call RFS.StoreReg call RFS.StoreReg
call IDT.AddHandler, zero, 2 call IDT.AddHandler, zero, 2
SwitchToCMD: SwitchToCMD:
mov rax, Sys.Exit mov eax, Sys.Exit
trap 0 trap 0
; ;

View File

@ -4,20 +4,20 @@
#define N 11 #define N 11
.handle_DIR: .handle_DIR:
push rbp push ebp
mov rbp, rsp mov ebp, esp
push r12, r13 push nx0, nx1
push r14, r15 push nx2, nx3
nul r12 ; no. of files found nul nx0 ; no. of files found
nul r13 ; no. of directories found nul nx1 ; no. of directories found
nul r14 ; total amount of bytes found nul nx2 ; total amount of bytes found
call print, .dirmsg call print, .dirmsg
.dir_first: .dir_first:
mov rax, Sys.FindFirst mov eax, Sys.FindFirst
mov ax0, .dir_buf mov ax0, .dir_buf
mov ax1, FNAME_MAX mov ax1, FNAME_MAX
trap 0 trap 0
@ -25,7 +25,7 @@
jmp .dir_list jmp .dir_list
.dir_next: .dir_next:
mov rax, Sys.FindNext mov eax, Sys.FindNext
mov ax0, .dir_buf mov ax0, .dir_buf
mov ax1, FNAME_MAX mov ax1, FNAME_MAX
trap 0 trap 0
@ -33,54 +33,54 @@
.dir_list: .dir_list:
jraxz .dir_end jraxz .dir_end
mov r15, rcx ; file size mov nx3, ecx ; file size
add r14, rcx add nx2, ecx
; directory? ; directory?
bnz rdx, .dir_is_dir bnz edx, .dir_is_dir
; found a file ; found a file
inc r12 inc nx0
; separate extension from file name ; separate extension from file name
mov rcx, FNAME_MAX mov ecx, FNAME_MAX
mov rsi, .dir_buf mov esi, .dir_buf
mov rdi, rsi mov edi, esi
scasb rsi, '.' scasb esi, '.'
; print file name ; print file name
sub ax1, rsi, rdi sub ax1, esi, edi
dec ax1 dec ax1
call nprint, rdi call nprint, edi
; calculate where to put extension ; calculate where to put extension
sub rdi, rsi, .dir_buf sub edi, esi, .dir_buf
dec rdi dec edi
.dir_ext_pad: .dir_ext_pad:
; print at least N non-space characters before extension ; print at least N non-space characters before extension
blte N, rdi, .dir_print_ext blte N, edi, .dir_print_ext
prn ' ' prn ' '
inc rdi inc edi
jmp .dir_ext_pad jmp .dir_ext_pad
.dir_print_ext: .dir_print_ext:
prn ' ' prn ' '
; here we print at least 4 characters excluding '.' ; here we print at least 4 characters excluding '.'
mov rcx, 4 mov ecx, 4
bne b[rsi], '.', .dir_print_ext.1 bne b[esi], '.', .dir_print_ext.1
inc rsi inc esi
.dir_print_ext.1: .dir_print_ext.1:
bzr b[rsi], .dir_print_ext.2 bzr b[esi], .dir_print_ext.2
; print and decrease rcx, unless it's already 0 ; print and decrease ecx, unless it's already 0
prn b[rsi] prn b[esi]
inc rsi inc esi
jrcxz .dir_print_ext.1 jrcxz .dir_print_ext.1
dec rcx dec ecx
jmp .dir_print_ext.1 jmp .dir_print_ext.1
.dir_print_ext.2: .dir_print_ext.2:
@ -97,12 +97,12 @@
prn ' ' prn ' '
prn ' ' prn ' '
shr rax, r15, 10 shr eax, nx3, 10
and r15, 1023 and nx3, 1023
push r15, rax push nx3, eax
call printf, .dir_bytesstr call printf, .dir_bytesstr
add rsp, 16 add esp, 16
.dir_prepare_next: .dir_prepare_next:
; go find next entry ; go find next entry
@ -110,37 +110,37 @@
jmp .dir_next jmp .dir_next
.dir_end: .dir_end:
shr rax, r14, 10 shr eax, nx2, 10
shr rdx, rax, 10 shr edx, eax, 10
and rax, 1023 and eax, 1023
and r14, 1023 and nx2, 1023
push r14, rax, rdx push nx2, eax, edx
call printf, .dir_endstr0 call printf, .dir_endstr0
add rsp, 24 add esp, 24
push r13, r12 push nx1, nx0
call printf, .dir_endstr1 call printf, .dir_endstr1
add rsp, 16 add esp, 16
pop r15, r14 pop nx3, nx2
pop r13, r12 pop nx1, nx0
leave leave
jmp .print_prompt jmp .print_prompt
; special case: direcory ; special case: direcory
.dir_is_dir: .dir_is_dir:
inc r13 inc nx1
; use printf instead of print ; use printf instead of print
; because it returns the # of ; because it returns the # of
; printed characters ; printed characters
call printf, .dir_buf call printf, .dir_buf
blte N, rax, .dir_no_pad blte N, eax, .dir_no_pad
sub rcx, N, rax sub ecx, N, eax
dec rcx dec ecx
.dir.l: .dir.l:
prn ' ' prn ' '

View File

@ -3,15 +3,15 @@
.try_exec: .try_exec:
; try without appending ".com" ; try without appending ".com"
mov rax, Sys.OpenFile mov eax, Sys.OpenFile
mov ax0, argv0 mov ax0, argv0
trap 0 trap 0
; we good? ; we good?
blte zero, rax, .do_exec blte zero, eax, .do_exec
; nope, append ".com" and try again ; nope, append ".com" and try again
sub rcx, argbuf.size, 5 sub ecx, argbuf.size, 5
scasb ax0, zero ; find null-term scasb ax0, zero ; find null-term
mov b[ax0+0], '.' ; ".com" mov b[ax0+0], '.' ; ".com"
mov b[ax0+1], 'c' mov b[ax0+1], 'c'
@ -20,34 +20,34 @@
nul b[ax0+4] nul b[ax0+4]
; try again ; try again
mov rax, Sys.OpenFile mov eax, Sys.OpenFile
mov ax0, argv0 mov ax0, argv0
trap 0 trap 0
; still no good? ; still no good?
bltz rax, .exec_not_found bltz eax, .exec_not_found
.do_exec: .do_exec:
; load file into memory ; load file into memory
mov ax0, rax mov ax0, eax
mov ax1, FILE_LOADP mov ax1, FILE_LOADP
mov ax2, FILE_MAXSZ mov ax2, FILE_MAXSZ
mov rax, Sys.ReadFile mov eax, Sys.ReadFile
trap 0 trap 0
; save load address ; save load address
mov rcx, rax mov ecx, eax
; close file ; close file
mov rax, Sys.CloseFile mov eax, Sys.CloseFile
trap 0 trap 0
; read anything? ; read anything?
bltz rcx, .couldnt_read bltz ecx, .couldnt_read
jrcxz .empty_file jrcxz .empty_file
; all good, let's go ; all good, let's go
mov rax, Sys.ExecuteInFrame mov eax, Sys.ExecuteInFrame
mov ax0, FILE_LOADP mov ax0, FILE_LOADP
mov ax1, 5 mov ax1, 5
trap 0 trap 0

View File

@ -2,59 +2,59 @@
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
.handle_ERASE: .handle_ERASE:
mov rax, Sys.RemoveFile mov eax, Sys.RemoveFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .couldnt_remove bltz eax, .couldnt_remove
jmp .handle_MAKE ; re-create it back jmp .handle_MAKE ; re-create it back
.handle_MAKE: .handle_MAKE:
mov rax, Sys.CreateFile mov eax, Sys.CreateFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .couldnt_open bltz eax, .couldnt_open
jmp .print_prompt jmp .print_prompt
.handle_PRINT: .handle_PRINT:
mov rax, Sys.OpenFile mov eax, Sys.OpenFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .file_not_found bltz eax, .file_not_found
mov ax0, rax mov ax0, eax
mov ax1, FILE_LOADP mov ax1, FILE_LOADP
mov ax2, FILE_MAXSZ mov ax2, FILE_MAXSZ
mov rax, Sys.ReadFile mov eax, Sys.ReadFile
trap 0 trap 0
mov rcx, rax mov ecx, eax
mov rax, Sys.CloseFile mov eax, Sys.CloseFile
trap 0 trap 0
bltz rcx, .couldnt_read bltz ecx, .couldnt_read
jrcxz .empty_file jrcxz .empty_file
call nprint, FILE_LOADP, rcx call nprint, FILE_LOADP, ecx
jmp .print_prompt jmp .print_prompt
.handle_REMOVE: .handle_REMOVE:
mov rax, Sys.RemoveFile mov eax, Sys.RemoveFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .couldnt_remove bltz eax, .couldnt_remove
jmp .print_prompt jmp .print_prompt

View File

@ -991,21 +991,21 @@ abort:
; COMMAND.COM guarantees that programs ; COMMAND.COM guarantees that programs
; are always loaded on a 16KB boundary ; are always loaded on a 16KB boundary
; This is guaranteed to be the case ; This is guaranteed to be the case
; in all future versions as well ; in all future veesions as well
start: start:
mov rsp, 0x104000 mov esp, 0x104000
mov rbp, zero mov ebp, zero
call main call main
mov rax, Sys.EnterHaltMode mov eax, Sys.EnterHaltMode
trap 0 trap 0
crash crash
cmd.versionstr = "COMMAND.COM, version 0.1 (KVISC)\nCopyright (C) 2019, The OS/K Team\nMIT license (permissive), see LICENCE file in source tree" cmd.veesionstr = "COMMAND.COM, veesion 0.1 (KVISC)\nCopyright (C) 2019, The OS/K Team\nMIT license (permissive), see LICENCE file in source tree"
argbuf.size := 256 argbuf.size := 256
argbuf = [argbuf.size] argbuf = [argbuf.size]
@ -1017,12 +1017,12 @@ stdin_echoing = 1
prompt = [32] prompt = [32]
main: main:
mov rsi, prompt mov esi, prompt
mov b[rsi+0], 'C' mov b[esi+0], 'C'
mov b[rsi+1], ':' mov b[esi+1], ':'
mov b[rsi+2], '\' mov b[esi+2], '\'
mov b[rsi+3], '>' mov b[esi+3], '>'
mov b[rsi+4], ' ' mov b[esi+4], ' '
.print_prompt: .print_prompt:
call print, prompt call print, prompt
@ -1035,7 +1035,7 @@ main:
; call nprint, argv0, argbuf.size ; call nprint, argv0, argbuf.size
; iterator through argbuf ; iterator through argbuf
nul rcx nul ecx
.input_loop: .input_loop:
pause pause
@ -1043,22 +1043,22 @@ main:
pause pause
; Fill .buf with user input ; Fill .buf with user input
scan rax scan eax
jraxz .input_loop jraxz .input_loop
; ESC key pressed? ; ESC key pressed?
beq rax, 0x1B, .handle_EXIT beq eax, 0x1B, .handle_EXIT
; backspace character? ; backspace character?
bne rax, 8, .handle_input bne eax, 8, .handle_input
; anything to delete? ; anything to delete?
jrcxz .input_loop ; no jrcxz .input_loop ; no
; yes, delete it ; yes, delete it
dec rcx dec ecx
add rdx, rcx, argbuf add edx, ecx, argbuf
nul b[rdx] nul b[edx]
; update screen ; update screen
bzr b[stdin_echoing], .input_loop bzr b[stdin_echoing], .input_loop
@ -1068,19 +1068,19 @@ main:
.handle_input: .handle_input:
bzr b[stdin_echoing], .se.z bzr b[stdin_echoing], .se.z
prn rax prn eax
.se.z: .se.z:
beq rax, 10, .extract_argv0 beq eax, 10, .extract_argv0
; when max line length is reached, ; when max line length is reached,
; force a newline ; force a newline
beq rcx, argbuf.size, .extract_argv0 beq ecx, argbuf.size, .extract_argv0
; add character to buffer and increase iterator (rcx) ; add character to buffer and increase iterator (ecx)
add rdx, rcx, argbuf add edx, ecx, argbuf
mov b[rdx], rax mov b[edx], eax
inc rcx inc ecx
; another one ; another one
jmp .input_loop jmp .input_loop
@ -1091,43 +1091,43 @@ main:
jrcxz .print_prompt jrcxz .print_prompt
; find first whitespace or null-terminator ; find first whitespace or null-terminator
mov rcx, argbuf.size mov ecx, argbuf.size
mov rdx, argbuf mov edx, argbuf
scasb rdx, ' ' scasb edx, ' '
; argv1 exists? if so, save its position ; argv1 exists? if so, save its position
mov rsi, rdx mov esi, edx
.next_space: .next_space:
mov rcx, b[rsi] mov ecx, b[esi]
jrcxz .do_extract jrcxz .do_extract
; skip spaces ; skip spaces
bne rcx, ' ', .not_a_space bne ecx, ' ', .not_a_space
inc rsi inc esi
jmp .next_space jmp .next_space
.not_a_space: .not_a_space:
; if we're here, we found a ; if we're here, we found a
; non-zero non-space character ; non-zero non-space character
mov q[argv1pos], rsi mov q[argv1pos], esi
; fallthrough ; fallthrough
.do_extract: .do_extract:
; how much do we copy? ; how much do we copy?
sub rcx, rdx, argbuf sub ecx, edx, argbuf
jrcxz .detect_builtin jrcxz .detect_builtin
dec rcx dec ecx
mov rdi, argbuf mov edi, argbuf
mov rsi, argv0 mov esi, argv0
.copy_loop: .copy_loop:
mov b[rsi], b[rdi] mov b[esi], b[edi]
inc rdi inc edi
inc rsi inc esi
loop .copy_loop loop .copy_loop
@ -1210,20 +1210,20 @@ main:
.handle_DIR: .handle_DIR:
push rbp push ebp
mov rbp, rsp mov ebp, esp
push r12, r13 push nx0, nx1
push r14, r15 push nx2, nx3
nul r12 ; no. of files found nul nx0 ; no. of files found
nul r13 ; no. of directories found nul nx1 ; no. of directories found
nul r14 ; total amount of bytes found nul nx2 ; total amount of bytes found
call print, .dirmsg call print, .dirmsg
.dir_first: .dir_first:
mov rax, Sys.FindFirst mov eax, Sys.FindFirst
mov ax0, .dir_buf mov ax0, .dir_buf
mov ax1, 0x80 mov ax1, 0x80
trap 0 trap 0
@ -1231,7 +1231,7 @@ main:
jmp .dir_list jmp .dir_list
.dir_next: .dir_next:
mov rax, Sys.FindNext mov eax, Sys.FindNext
mov ax0, .dir_buf mov ax0, .dir_buf
mov ax1, 0x80 mov ax1, 0x80
trap 0 trap 0
@ -1239,54 +1239,54 @@ main:
.dir_list: .dir_list:
jraxz .dir_end jraxz .dir_end
mov r15, rcx ; file size mov nx3, ecx ; file size
add r14, rcx add nx2, ecx
; directory? ; directory?
bnz rdx, .dir_is_dir bnz edx, .dir_is_dir
; found a file ; found a file
inc r12 inc nx0
; separate extension from file name ; separate extension from file name
mov rcx, 0x80 mov ecx, 0x80
mov rsi, .dir_buf mov esi, .dir_buf
mov rdi, rsi mov edi, esi
scasb rsi, '.' scasb esi, '.'
; print file name ; print file name
sub ax1, rsi, rdi sub ax1, esi, edi
dec ax1 dec ax1
call nprint, rdi call nprint, edi
; calculate where to put extension ; calculate where to put extension
sub rdi, rsi, .dir_buf sub edi, esi, .dir_buf
dec rdi dec edi
.dir_ext_pad: .dir_ext_pad:
; print at least 11 non-space characters before extension ; print at least 11 non-space characters before extension
blte 11, rdi, .dir_print_ext blte 11, edi, .dir_print_ext
prn ' ' prn ' '
inc rdi inc edi
jmp .dir_ext_pad jmp .dir_ext_pad
.dir_print_ext: .dir_print_ext:
prn ' ' prn ' '
; here we print at least 4 characters excluding '.' ; here we print at least 4 characters excluding '.'
mov rcx, 4 mov ecx, 4
bne b[rsi], '.', .dir_print_ext.1 bne b[esi], '.', .dir_print_ext.1
inc rsi inc esi
.dir_print_ext.1: .dir_print_ext.1:
bzr b[rsi], .dir_print_ext.2 bzr b[esi], .dir_print_ext.2
; print and decrease rcx, unless it's already 0 ; print and decrease ecx, unless it's already 0
prn b[rsi] prn b[esi]
inc rsi inc esi
jrcxz .dir_print_ext.1 jrcxz .dir_print_ext.1
dec rcx dec ecx
jmp .dir_print_ext.1 jmp .dir_print_ext.1
.dir_print_ext.2: .dir_print_ext.2:
@ -1303,12 +1303,12 @@ main:
prn ' ' prn ' '
prn ' ' prn ' '
shr rax, r15, 10 shr eax, nx3, 10
and r15, 1023 and nx3, 1023
push r15, rax push nx3, eax
call printf, .dir_bytesstr call printf, .dir_bytesstr
add rsp, 16 add esp, 16
.dir_prepare_next: .dir_prepare_next:
; go find next entry ; go find next entry
@ -1316,37 +1316,37 @@ main:
jmp .dir_next jmp .dir_next
.dir_end: .dir_end:
shr rax, r14, 10 shr eax, nx2, 10
shr rdx, rax, 10 shr edx, eax, 10
and rax, 1023 and eax, 1023
and r14, 1023 and nx2, 1023
push r14, rax, rdx push nx2, eax, edx
call printf, .dir_endstr0 call printf, .dir_endstr0
add rsp, 24 add esp, 24
push r13, r12 push nx1, nx0
call printf, .dir_endstr1 call printf, .dir_endstr1
add rsp, 16 add esp, 16
pop r15, r14 pop nx3, nx2
pop r13, r12 pop nx1, nx0
leave leave
jmp .print_prompt jmp .print_prompt
; special case: direcory ; special case: direcory
.dir_is_dir: .dir_is_dir:
inc r13 inc nx1
; use printf instead of print ; use printf instead of print
; because it returns the # of ; because it returns the # of
; printed characters ; printed characters
call printf, .dir_buf call printf, .dir_buf
blte 11, rax, .dir_no_pad blte 11, eax, .dir_no_pad
sub rcx, 11, rax sub ecx, 11, eax
dec rcx dec ecx
.dir.l: .dir.l:
prn ' ' prn ' '
@ -1372,15 +1372,15 @@ main:
.try_exec: .try_exec:
; try without appending ".com" ; try without appending ".com"
mov rax, Sys.OpenFile mov eax, Sys.OpenFile
mov ax0, argv0 mov ax0, argv0
trap 0 trap 0
; we good? ; we good?
blte zero, rax, .do_exec blte zero, eax, .do_exec
; nope, append ".com" and try again ; nope, append ".com" and try again
sub rcx, argbuf.size, 5 sub ecx, argbuf.size, 5
scasb ax0, zero ; find null-term scasb ax0, zero ; find null-term
mov b[ax0+0], '.' ; ".com" mov b[ax0+0], '.' ; ".com"
mov b[ax0+1], 'c' mov b[ax0+1], 'c'
@ -1389,34 +1389,34 @@ main:
nul b[ax0+4] nul b[ax0+4]
; try again ; try again
mov rax, Sys.OpenFile mov eax, Sys.OpenFile
mov ax0, argv0 mov ax0, argv0
trap 0 trap 0
; still no good? ; still no good?
bltz rax, .exec_not_found bltz eax, .exec_not_found
.do_exec: .do_exec:
; load file into memory ; load file into memory
mov ax0, rax mov ax0, eax
mov ax1, 0x108000 mov ax1, 0x108000
mov ax2, 0x8000 mov ax2, 0x8000
mov rax, Sys.ReadFile mov eax, Sys.ReadFile
trap 0 trap 0
; save load address ; save load address
mov rcx, rax mov ecx, eax
; close file ; close file
mov rax, Sys.CloseFile mov eax, Sys.CloseFile
trap 0 trap 0
; read anything? ; read anything?
bltz rcx, .couldnt_read bltz ecx, .couldnt_read
jrcxz .empty_file jrcxz .empty_file
; all good, let's go ; all good, let's go
mov rax, Sys.ExecuteInFrame mov eax, Sys.ExecuteInFrame
mov ax0, 0x108000 mov ax0, 0x108000
mov ax1, 5 mov ax1, 5
trap 0 trap 0
@ -1429,59 +1429,59 @@ main:
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
.handle_ERASE: .handle_ERASE:
mov rax, Sys.RemoveFile mov eax, Sys.RemoveFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .couldnt_remove bltz eax, .couldnt_remove
jmp .handle_MAKE ; re-create it back jmp .handle_MAKE ; re-create it back
.handle_MAKE: .handle_MAKE:
mov rax, Sys.CreateFile mov eax, Sys.CreateFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .couldnt_open bltz eax, .couldnt_open
jmp .print_prompt jmp .print_prompt
.handle_PRINT: .handle_PRINT:
mov rax, Sys.OpenFile mov eax, Sys.OpenFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .file_not_found bltz eax, .file_not_found
mov ax0, rax mov ax0, eax
mov ax1, 0x108000 mov ax1, 0x108000
mov ax2, 0x8000 mov ax2, 0x8000
mov rax, Sys.ReadFile mov eax, Sys.ReadFile
trap 0 trap 0
mov rcx, rax mov ecx, eax
mov rax, Sys.CloseFile mov eax, Sys.CloseFile
trap 0 trap 0
bltz rcx, .couldnt_read bltz ecx, .couldnt_read
jrcxz .empty_file jrcxz .empty_file
call nprint, 0x108000, rcx call nprint, 0x108000, ecx
jmp .print_prompt jmp .print_prompt
.handle_REMOVE: .handle_REMOVE:
mov rax, Sys.RemoveFile mov eax, Sys.RemoveFile
mov ax0, q[argv1pos] mov ax0, q[argv1pos]
bzr ax0, .need_params bzr ax0, .need_params
trap 0 trap 0
bltz rax, .couldnt_remove bltz eax, .couldnt_remove
jmp .print_prompt jmp .print_prompt
# 230 "command.k" 2 # 230 "command.k" 2
@ -1496,12 +1496,12 @@ main:
.handle_DATE: .handle_DATE:
call GetTimeUTC call GetTimeUTC
mov rcx, b[rax+4] mov ecx, b[eax+4]
inc rcx inc ecx
push b[rax+3], rcx, w[rax+6] push b[eax+3], ecx, w[eax+6]
call printf, .datefmt call printf, .datefmt
add rsp, 40 add esp, 40
jmp .print_prompt jmp .print_prompt
@ -1512,22 +1512,22 @@ main:
jmp .print_prompt jmp .print_prompt
.handle_ECHO: .handle_ECHO:
mov rax, q[argv1pos] mov eax, q[argv1pos]
jraxz .echo.end jraxz .echo.end
call print, rax call print, eax
.echo.end: .echo.end:
prn 10 prn 10
jmp .print_prompt jmp .print_prompt
.handle_EXIT: .handle_EXIT:
mov rax, Sys.Shutdown mov eax, Sys.Shutdown
trap 0 trap 0
jmp .print_prompt jmp .print_prompt
.handle_HALT: .handle_HALT:
mov rax, Sys.EnterHaltMode mov eax, Sys.EnterHaltMode
trap 0 trap 0
jmp .print_prompt jmp .print_prompt
@ -1542,16 +1542,16 @@ main:
.handle_TIME: .handle_TIME:
call GetTimeUTC call GetTimeUTC
push b[rax], b[rax+1], b[rax+2] push b[eax], b[eax+1], b[eax+2]
call printf, .timefmt call printf, .timefmt
add rsp, 24 add esp, 24
jmp .print_prompt jmp .print_prompt
.timefmt = "%d:%d:%d\n" .timefmt = "%d:%d:%d\n"
.handle_VERS: .handle_VERS:
call print, cmd.versionstr call print, cmd.veesionstr
prn 10 prn 10
jmp .print_prompt jmp .print_prompt
@ -1591,12 +1591,12 @@ main:
.helpmsg.prompt = " PROMPT Change the command line prompt\n" .helpmsg.prompt = " PROMPT Change the command line prompt\n"
.helpmsg.remove = " REMOVE Delete a file (permanently)\n" .helpmsg.remove = " REMOVE Delete a file (permanently)\n"
.helpmsg.time = " TIME Display current time of day\n" .helpmsg.time = " TIME Display current time of day\n"
.helpmsg.ver = " VERS Display current COMMAND.COM version\n" .helpmsg.ver = " VERS Display current COMMAND.COM veesion\n"
.exec_not_found: .exec_not_found:
push argv0 push argv0
call printf, .enf_errmsg call printf, .enf_errmsg
add rsp, 8 add esp, 8
jmp .print_prompt jmp .print_prompt
@ -1605,7 +1605,7 @@ main:
.file_not_found: .file_not_found:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .fnf_errmsg call printf, .fnf_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -1614,7 +1614,7 @@ main:
.empty_file: .empty_file:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .ef_errmsg call printf, .ef_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -1623,7 +1623,7 @@ main:
.couldnt_open: .couldnt_open:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .cno_errmsg call printf, .cno_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -1632,7 +1632,7 @@ main:
.couldnt_remove: .couldnt_remove:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .cne_errmsg call printf, .cne_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt
@ -1641,7 +1641,7 @@ main:
.couldnt_read: .couldnt_read:
push q[argv1pos], argv0 push q[argv1pos], argv0
call printf, .cnr_errmsg call printf, .cnr_errmsg
add rsp, 16 add esp, 16
jmp .print_prompt jmp .print_prompt

View File

@ -1005,8 +1005,8 @@ abort:
; Entry point ; Entry point
; ;
start: start:
mov rsp, 0x104000 mov esp, 0x104000
mov rbp, zero mov ebp, zero
;dump ;dump
@ -1151,14 +1151,14 @@ DISK.WriteFile:
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
DefaultExceptionHandler: DefaultExceptionHandler:
mov rsp, 0x105800 mov esp, 0x105800
mov ax1, r12 mov ax1, nx0
bzr r12, DefaultTrapHandler.handle_Shutdown bzr nx0, DefaultTrapHandler.handle_Shutdown
bltu 11, r12, .unknown bltu 11, nx0, .unknown
mov rsi, .err_ukn mov esi, .err_ukn
lea ax0, b[rsi + r12 * 32] lea ax0, b[esi + nx0 * 32]
call ScreenOfDeath call ScreenOfDeath
.unknown: .unknown:
@ -1182,8 +1182,8 @@ DefaultExceptionHandler:
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
ScreenOfDeath: ScreenOfDeath:
push r12 push nx0
mov r12, ax0 mov nx0, ax0
prn 10 prn 10
prn 0x8BF00001 prn 0x8BF00001
@ -1193,13 +1193,13 @@ ScreenOfDeath:
call printf, .scr1 call printf, .scr1
pop pop
bnz r14, .not_con bnz nx2, .not_con
push .scr2_con push .scr2_con
jmp .do_print jmp .do_print
.not_con: .not_con:
; rframes #2-#3-#4 belong to kernel ; rframes #2-#3-#4 belong to kernel
blt 4, r14, .not_krn blt 4, nx2, .not_krn
push .scr2_krn push .scr2_krn
jmp .do_print jmp .do_print
@ -1207,11 +1207,11 @@ ScreenOfDeath:
push .scr2_usr push .scr2_usr
.do_print: .do_print:
push r14, r12 push nx2, nx0
call printf, .scr2 call printf, .scr2
add rsp, 24 add esp, 24
call dumprf, r14 call dumprf, nx2
prn 10 prn 10
call print, .scr3 call print, .scr3
@ -1220,11 +1220,11 @@ ScreenOfDeath:
pause pause
pause pause
scan rax scan eax
jraxz .loop jraxz .loop
beq rax, 0x0A, DefaultTrapHandler.handle_Exit beq eax, 0x0A, DefaultTrapHandler.handle_Exit
beq rax, 0x1B, DefaultTrapHandler.handle_Shutdown beq eax, 0x1B, DefaultTrapHandler.handle_Shutdown
jmp .loop jmp .loop
@ -1243,27 +1243,27 @@ ScreenOfDeath:
; See the LICENSE file in the project root for more information. ; See the LICENSE file in the project root for more information.
TrapHandlers.prolog: TrapHandlers.prolog:
nul rbp nul ebp
; rax = caller's cr1 ; eax = caller's cr1
call RFS.LoadReg, r14, $cr1 call RFS.LoadReg, nx2, $cr1
; we don't preserve the r12 we got ; we don't preserve the nx0 we got
mov r12, rax mov nx0, eax
nul rdx nul edx
jmp rcx jmp ecx
TrapHandlers.epilog: TrapHandlers.epilog:
; TRAP return values: RAX-RDX ; TRAP return values: eax-edx
mov ax2, rax mov ax2, eax
call RFS.StoreReg, r14, $rax call RFS.StoreReg, nx2, $eax
mov ax2, rdx mov ax2, edx
call RFS.StoreReg, r14, $rdx call RFS.StoreReg, nx2, $edx
call IDT.DoneHandling, r13 call IDT.DoneHandling, nx1
iret iret
@ -1273,42 +1273,42 @@ TrapHandlers.epilog:
DefaultTrapHandler: DefaultTrapHandler:
.init: .init:
mov rcx, .text mov ecx, .text
mov rsp, 0x104800 mov esp, 0x104800
jmp TrapHandlers.prolog jmp TrapHandlers.prolog
.text: .text:
call RFS.LoadReg, r14, $rax call RFS.LoadReg, nx2, $eax
call RFS.LoadArgs, r14 call RFS.LoadArgs, nx2
; will be optimized with a table ; will be optimized with a table
; when we have a "finished" consistent API ; when we have a "finished" consistent API
jraxz .handle_Shutdown jraxz .handle_Shutdown
beq rax, Sys.Exit, .handle_Exit beq eax, Sys.Exit, .handle_Exit
beq rax, Sys.ExecuteInFrame, .handle_EIF beq eax, Sys.ExecuteInFrame, .handle_EIF
beq rax, Sys.ReadFile, .handle_ReadFile beq eax, Sys.ReadFile, .handle_ReadFile
beq rax, Sys.OpenFile, .handle_OpenFile beq eax, Sys.OpenFile, .handle_OpenFile
beq rax, Sys.CloseFile, .handle_CloseFile beq eax, Sys.CloseFile, .handle_CloseFile
beq rax, Sys.CreateFile, .handle_CreateFile beq eax, Sys.CreateFile, .handle_CreateFile
beq rax, Sys.RemoveFile, .handle_RemoveFile beq eax, Sys.RemoveFile, .handle_RemoveFile
beq rax, Sys.FindNext, .handle_FindNext beq eax, Sys.FindNext, .handle_FindNext
beq rax, Sys.FindFirst, .handle_FindFirst beq eax, Sys.FindFirst, .handle_FindFirst
beq rax, Sys.EnterHaltMode, .handle_HaltMode beq eax, Sys.EnterHaltMode, .handle_HaltMode
.sod: .sod:
call ScreenOfDeath, .badsyscall, r13 call ScreenOfDeath, .badsyscall, nx1
.wrong: .wrong:
call ScreenOfDeath, .badparams, r13 call ScreenOfDeath, .badparams, nx1
.fini.savecx: .fini.savecx:
mov ax2, rcx mov ax2, ecx
call RFS.StoreReg, r14, $rcx call RFS.StoreReg, nx2, $ecx
.fini: .fini:
jmp TrapHandlers.epilog jmp TrapHandlers.epilog
.badsyscall = "Invalid syscall number in RAX" .badsyscall = "Invalid syscall number in eax"
.badparams = "Invalid syscall parameters" .badparams = "Invalid syscall parameters"
;------------------------------------------------; ;------------------------------------------------;
@ -1320,46 +1320,46 @@ DefaultTrapHandler:
; ;
.handle_Exit: .handle_Exit:
; deactivate current rframe ; deactivate current rframe
bzr r14, .hE_nz ; unless it's 0... bzr nx2, .hE_nz ; unless it's 0...
call RFS.DeactivateFrame, r14 call RFS.DeactivateFrame, nx2
.hE_nz: .hE_nz:
; open COMMAND.COM ; open COMMAND.COM
call DISK.OpenFile, .cmdcom call DISK.OpenFile, .cmdcom
; crash on failure ; crash on failure
bltz rax, abort bltz eax, abort
; load at 0x108000 ; load at 0x108000
mov ax1, 0x108000 mov ax1, 0x108000
mov ax2, 0x80000 mov ax2, 0x80000
call DISK.ReadFile, rax call DISK.ReadFile, eax
; assume that COMMAND.COM being ; assume that COMMAND.COM being
; less then 4KB means something ; less then 4KB means something
; went wrong ; went wrong
blt rax, 0x1000, abort blt eax, 0x1000, abort
; close the handle ; close the handle
call DISK.CloseFile, rax call DISK.CloseFile, eax
; code address ; code address
mov ax2, 0x100000 mov ax2, 0x100000
call RFS.StoreReg, zero, $rip call RFS.StoreReg, zero, $eip
; usermode ; usermode
mov ax2, 3 mov ax2, 3
call RFS.StoreReg, zero, $cr0 call RFS.StoreReg, zero, $cr0
mov rcx, 0x108000 mov ecx, 0x108000
sub rcx, 0x100000 sub ecx, 0x100000
; code offset ; code offset
mov ax2, rcx mov ax2, ecx
call RFS.StoreReg, zero, $cr1 call RFS.StoreReg, zero, $cr1
; return frame ; return frame
nul r14 nul nx2
jmp .fini jmp .fini
@ -1368,39 +1368,39 @@ DefaultTrapHandler:
.handle_EIF: .handle_EIF:
blt ax1, 5, .wrong blt ax1, 5, .wrong
; RIP can't be <1MB ; eip can't be <1MB
mov rcx, 0x100000 mov ecx, 0x100000
blt ax0, rcx, .wrong blt ax0, ecx, .wrong
; add old CR1 ; add old CR1
add ax0, r12 add ax0, nx0
; real RIP can't be <1MB+32KB either ; real eip can't be <1MB+32KB either
; (kernel + cmdcom personal space) ; (kernel + cmdcom personal space)
add rdx, rcx, 0x8000 add edx, ecx, 0x8000
blt ax0, rcx, .wrong blt ax0, ecx, .wrong
; save rframe and compute new CR1 ; save rframe and compute new CR1
mov rbx, ax1 mov ebx, ax1
sub rdi, ax0, rcx sub edi, ax0, ecx
; activate rframe ; activate rframe
call RFS.ActivateFrame, rbx call RFS.ActivateFrame, ebx
; save new CR1 ; save new CR1
mov ax2, rdi mov ax2, edi
call RFS.StoreReg, rbx, $cr1 call RFS.StoreReg, ebx, $cr1
; interruptible user mode ; interruptible user mode
mov ax2, 3 mov ax2, 3
call RFS.StoreReg, rbx, $cr0 call RFS.StoreReg, ebx, $cr0
; set RIP = 1MB ; set eip = 1MB
mov ax2, rcx mov ax2, ecx
call RFS.StoreReg, rbx, $rip call RFS.StoreReg, ebx, $eip
; change return frame ; change return frame
mov r14, rbx mov nx2, ebx
jmp .fini jmp .fini
@ -1408,27 +1408,27 @@ DefaultTrapHandler:
; Disk API ; Disk API
; ;
.handle_FindFirst: .handle_FindFirst:
add ax0, r12 add ax0, nx0
call DISK.FindFirst call DISK.FindFirst
jmp .fini.savecx jmp .fini.savecx
.handle_FindNext: .handle_FindNext:
add ax0, r12 add ax0, nx0
call DISK.FindNext call DISK.FindNext
jmp .fini.savecx jmp .fini.savecx
.handle_OpenFile: .handle_OpenFile:
add ax0, r12 add ax0, nx0
call DISK.OpenFile call DISK.OpenFile
jmp .fini jmp .fini
.handle_CreateFile: .handle_CreateFile:
add ax0, r12 add ax0, nx0
call DISK.CreateFile call DISK.CreateFile
jmp .fini jmp .fini
.handle_RemoveFile: .handle_RemoveFile:
add ax0, r12 add ax0, nx0
call DISK.RemoveFile call DISK.RemoveFile
jmp .fini jmp .fini
@ -1437,7 +1437,7 @@ DefaultTrapHandler:
jmp .fini jmp .fini
.handle_ReadFile: .handle_ReadFile:
add ax1, r12 add ax1, nx0
call DISK.ReadFile call DISK.ReadFile
jmp .fini jmp .fini

View File

@ -986,8 +986,8 @@ abort:
# 8 "hello.k" 2 # 8 "hello.k" 2
main: main:
mov rsp, 0x104000 mov esp, 0x104000
nul rbp nul ebp
call print, .hellow call print, .hellow