From: Robert Pengelly Date: Sat, 28 Sep 2024 21:20:00 +0000 (+0100) Subject: Batch improvements X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=4ae37013c76889aaa2b2db36e3cd6833245b3bff;p=chimaera.git Batch improvements --- diff --git a/build/chimaera.img b/build/chimaera.img deleted file mode 100644 index 9a4a3d2..0000000 Binary files a/build/chimaera.img and /dev/null differ diff --git a/build/chimaera.vhd b/build/chimaera.vhd deleted file mode 100644 index fffe6cb..0000000 Binary files a/build/chimaera.vhd and /dev/null differ diff --git a/src/apps/pcomm/Makefile.unix b/src/apps/pcomm/Makefile.unix index f52306e..6a79e6d 100644 --- a/src/apps/pcomm/Makefile.unix +++ b/src/apps/pcomm/Makefile.unix @@ -46,7 +46,7 @@ genver: genver.c gcc -o $@ $^ endif -pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o ll.o mkdir.o path.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writechr.o writedec.o writehex.o writestr.o xmalloc.o xrealloc.o xstrcpy.o ../../lib/crt/libc.a +pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o ll.o list.o mkdir.o path.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writechr.o writedec.o writehex.o writestr.o xmalloc.o xrealloc.o xstrcpy.o ../../lib/crt/libc.a ../../utils/binutils/slink --oformat msdos -o $@ $^ %.o: %.asm diff --git a/src/apps/pcomm/Makefile.w32 b/src/apps/pcomm/Makefile.w32 index 8b28d85..124d200 100644 --- a/src/apps/pcomm/Makefile.w32 +++ b/src/apps/pcomm/Makefile.w32 @@ -30,7 +30,7 @@ genhash.exe: genhash.c genver.exe: genver.c gcc -o $@ $^ -pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o ll.o mkdir.o path.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writedec.o writehex.o writestr.o xmalloc.o xrealloc.o xstrcpy.o ../../lib/crt/libc.a +pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o ll.o list.o mkdir.o path.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writedec.o writehex.o writestr.o xmalloc.o xrealloc.o xstrcpy.o ../../lib/crt/libc.a ../../utils/binutils/slink --oformat msdos -o $@ $^ %.o: %.asm diff --git a/src/apps/pcomm/list.asm b/src/apps/pcomm/list.asm new file mode 100644 index 0000000..4afa475 --- /dev/null +++ b/src/apps/pcomm/list.asm @@ -0,0 +1,92 @@ +;****************************************************************************** +; @file list.asm +;****************************************************************************** +%ifndef HEX +% define HEX(y) 0x##y +%endif + +;****************************************************************************** +; @function _list_push +;****************************************************************************** +global _list_push +_list_push: + + push bp + + mov bp, sp + sub sp, 2 + + push ax + push bx + push cx + push dx + push si + push di + push es + push ds + + mov ax, 4 + xor dx, dx + + push ax + push dx + + call _xmalloc + add sp, 4 + + mov word ptr [bp - 2], ax + mov es, ax + + xor bx, bx + + mov ax, word ptr [bp + 6] + mov es:[bx], ax + + mov bx, word ptr [bp + 4] + mov ax, [bx] + + and ax, ax + jnz _list_push.got_head + + mov ax, word ptr [bp - 2] + ;mov es, ax + ; + ;xor bx, bx + ;mov es:[bx + 2], ax + + mov di, word ptr [bp + 4] + mov [di], ax + + jmp _list_push.done + +_list_push.got_head: + + mov dx, ax + xor bx, bx + +_list_push.search: + + mov es, ax + mov ax, es:[bx + 2] + + and ax, ax + jnz _list_push.search + + mov dx, word ptr [bp - 2] + mov es:[bx + 2], dx + +_list_push.done: + + pop ds + pop es + pop di + pop si + pop dx + pop cx + pop bx + pop ax + + add sp, 2 + pop bp + + ret diff --git a/src/apps/pcomm/pcomm.asm b/src/apps/pcomm/pcomm.asm index 395aec2..a9c1ca3 100644 --- a/src/apps/pcomm/pcomm.asm +++ b/src/apps/pcomm/pcomm.asm @@ -11,6 +11,14 @@ global _main _main: + push bp + + mov bp, sp + sub sp, 4 + + mov word ptr [bp - 4], 0 + mov word ptr [bp - 2], 0 + mov ax, HEX (2523) mov dx, offset _cbreak_handler int HEX (21) @@ -29,6 +37,144 @@ _main: .L5: + push es + push di + push cx + + mov ax, cs:[_vec_scratch + 0] + mov es, ax + + mov cx, cs:[_vec_scratch + 4] + xor di, di + +.L110: + + and cx, cx + jz .L109 + + mov ax, es:[di] + + push ds + push ax + + mov ax, offset _scratch_list + push ax + + call _list_push + add sp, 2 + + pop ax + pop ds + add di, 2 + + dec cx + jnz .L110 + +.L109: + + mov ax, es + + and ax, ax + jz .L117 + + push ax + + call _free + add sp, 2 + +.L117: + + mov ax, cs + mov es, ax + + mov di, offset _vec_scratch + xor al, al + + mov cx, 6 + rep stosb + + mov ax, [_scratch_list] + xor di, di + +.L112: + + and ax, ax + jz .L111 + +.L113: + + mov es, ax + + push ds + push di + + mov ax, es:[di] + mov ds, ax + + xor bx, bx + + cmp byte ptr [bx], '@' + jne .L114 + + inc bx + +.L116: + + cmp byte ptr [bx], ' ' + jne .L115 + + inc bx + jmp .L116 + +.L114: + + cmp word ptr cs:[_echo_line], 0 + je .L115 + + call _writestr + call _crlf + +.L115: + + push bx + + call _process_line + add sp, 2 + + push ds + + call _free + add sp, 2 + + pop di + pop ds + + mov ax, word ptr es:[di + 2] + push es + + call _free + add sp, 2 + + mov [_scratch_list], ax + mov word ptr [bp - 2], ax + + cmp word ptr cs:[_vec_scratch + 4], 0 + je .L112 + + pop cx + pop di + pop es + + jmp .L5 + +.L111: + + mov word ptr [_scratch_list], 0 + + pop cx + pop di + pop es + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Free the current command history if there is one. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1469,6 +1615,7 @@ _get_env: push si push di push es + push ds mov si, cs:[_vec_env] mov cx, cs:[_vec_env + 4] @@ -1510,31 +1657,52 @@ _get_env: pop di pop es - xor ax, ax - push ax + xor si, si + push si - mov ax, offset _temp - push ax + call _strlen + add sp, 2 - call _strcpy - add sp, 4 + mov cx, ax + rep movsb - mov ax, word ptr [bp + 4] - push ax + inc di + pop ds - mov ax, offset _temp - push ax + mov si, word ptr [bp + 4] + push si + + call _strlen + add sp, 2 + + mov cx, ax + rep movsb + + mov ax, cs + mov ds, ax + + mov di, offset _temp + push di + + call _strlen + + add di, ax + inc di + + push di call _strcmp add sp, 4 - pop ds pop es pop cx and ax, ax jz .L93 + xor ax, ax + int 0x19 + pop ax pop es @@ -1556,6 +1724,7 @@ _get_env: .L90: + pop ds pop es pop di pop si @@ -1643,6 +1812,9 @@ _expand_vars: and ax, ax jz .L89 + mov si, bx + inc si + push si push ds @@ -1673,7 +1845,7 @@ _expand_vars: pop ds pop si - jmp .L84 + jmp .L87 .L89: @@ -2102,8 +2274,6 @@ _process_line: mov ax, cs mov ds, ax - mov bx, offset _formatted_command - call _get_command jc .L23 @@ -2561,7 +2731,7 @@ _read_batch: push bp mov bp, sp - sub sp, 6 + sub sp, 12 push ax push bx @@ -2572,6 +2742,9 @@ _read_batch: push es push ds + mov word ptr [bp - 12], 0 + mov word ptr [bp - 10], 0 + mov word ptr [bp - 8], 0 mov word ptr [bp - 6], 0 mov word ptr [bp - 4], 0 mov word ptr [bp - 2], 0 @@ -2613,7 +2786,7 @@ _read_batch.read_line: push ax push ax - lea ax, word ptr [bp - 6] + mov ax, offset _ll_scratch push ax call _load_line @@ -2626,7 +2799,7 @@ _read_batch.read_line: push bx push ds - mov ax, word ptr [bp - 6] + mov ax, [_ll_scratch] mov ds, ax xor bx, bx @@ -2652,39 +2825,48 @@ _read_batch.check: call _strlen add sp, 2 + mov cx, ax + inc cx + add di, ax dec di xor al, al stosb - cmp word ptr [bp + 6], 0 - je _read_batch.process + mov ax, cx + xor dx, dx - cmp byte ptr [bx], '@' - jne _read_batch.echo + push ax + push dx - inc bx + call _xmalloc + add sp, 4 -_read_batch.skip2: - - cmp byte ptr [bx], ' ' - jne _read_batch.process + mov es, ax - inc bx - jmp _read_batch.skip2 - -_read_batch.echo: - - call _writestr - call _crlf - -_read_batch.process: - - push bx + push ds + push di + push es - call _process_line - add sp, 2 + mov ax, cs + mov ds, ax + + mov ax, offset _vec_scratch + push ax + + call _vec_push + add sp, 4 + + pop di + pop ds + + xor ax, ax + push ax + push ax + + call _strcpy + add sp, 4 _read_batch.next: @@ -2724,7 +2906,7 @@ _read_batch.done: pop bx pop ax - add sp, 6 + add sp, 12 clc pop bp @@ -2741,7 +2923,7 @@ _read_batch.err: pop bx pop ax - add sp, 6 + add sp, 12 stc pop bp @@ -2774,7 +2956,7 @@ _param_blk: db 16 dup (0) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Error messages. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -_err_segmentation: db "Segmentation fault", HEX (0D), HEX (0A), HEX (00) +_err_nested: db "Too many nested loops", HEX (00) _err_invalid: db "Bad command or file name - ", HEX (00) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -2787,6 +2969,7 @@ _temp: db 257 dup (0) _autoexec: db "AUTOEXEC.BAT", HEX (00) _batch_flags: db "r", HEX (00) +_echo_line: dw HEX (0001) _in_batch: dw HEX (0000) _ll_scratch: dw HEX (0000) @@ -2798,6 +2981,9 @@ _insert: dw HEX (0000) global _need_ext _need_ext: dw HEX (0000) +global _scratch_list +_scratch_list: dw HEX (0000) + global _vec_history _vec_history: db 6 dup (0) @@ -2807,6 +2993,9 @@ _vec_env: db 6 dup (0) global _vec_paths _vec_paths: db 6 dup (0) +global _vec_scratch +_vec_scratch: db 6 dup (0) + global _curr_row _curr_row: db HEX (00) diff --git a/src/apps/pcomm/vector.asm b/src/apps/pcomm/vector.asm index 3e74644..35546c5 100644 --- a/src/apps/pcomm/vector.asm +++ b/src/apps/pcomm/vector.asm @@ -55,7 +55,7 @@ _vec_adjust.alloc: mov ax, [bx + 0] push ax - call _realloc + call _xrealloc add sp, 6 and ax, ax diff --git a/src/apps/pcomm/xrealloc.asm b/src/apps/pcomm/xrealloc.asm index e5692c4..8d101da 100644 --- a/src/apps/pcomm/xrealloc.asm +++ b/src/apps/pcomm/xrealloc.asm @@ -23,11 +23,11 @@ _xrealloc: and ax, ax jnz _xrealloc.done + + pop bp _xrealloc.error: - pop bp - mov ax, cs mov ds, ax diff --git a/src/kernel/mem.asm b/src/kernel/mem.asm index 9798ad1..19b9ff6 100644 --- a/src/kernel/mem.asm +++ b/src/kernel/mem.asm @@ -371,6 +371,9 @@ _resize_mem.search: mov cx, es + cmp cx, cs:[_free_seg] + jb _resize_mem.error + cmp cx, cs:[_max_seg] jae _resize_mem.ins @@ -400,6 +403,9 @@ _resize_mem.next: dec ax jnz _resize_mem.search + cmp si, cs:[_free_seg] + jb _resize_mem.error + cmp si, cs:[_max_seg] jae _resize_mem.max diff --git a/src/lib/crt/stdlib/realloc.asm b/src/lib/crt/stdlib/realloc.asm index 2bb888a..cb07c19 100644 --- a/src/lib/crt/stdlib/realloc.asm +++ b/src/lib/crt/stdlib/realloc.asm @@ -140,10 +140,10 @@ _realloc.alloc: mov cx, word ptr es:[di + 3] mov es, ax - cmp cx, bx + cmp cx, si jb _realloc.copy - mov cx, bx + mov cx, si _realloc.copy: