From: Robert Pengelly Date: Wed, 7 Aug 2024 11:11:41 +0000 (+0100) Subject: Fixed off by 1 bugs X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=86f4463935d24402153ad8a89687a2a4b427433d;p=chimaera.git Fixed off by 1 bugs --- diff --git a/build/chimaera.img b/build/chimaera.img index c557ec3..2979e9a 100644 Binary files a/build/chimaera.img and b/build/chimaera.img differ diff --git a/build/chimaera.vhd b/build/chimaera.vhd index 4f0093b..cb81b98 100644 Binary files a/build/chimaera.vhd and b/build/chimaera.vhd differ diff --git a/src/apps/hello/hello.asm b/src/apps/hello/hello.asm index 1e8ab64..805c24e 100644 --- a/src/apps/hello/hello.asm +++ b/src/apps/hello/hello.asm @@ -44,7 +44,7 @@ _main: mov bx, ax mov ax, HEX (4202) - mov cx, 1024 + mov cx, 4096 xor dx, dx int HEX (21) jc .exit @@ -59,7 +59,7 @@ _main: jc .exit mov ax, HEX (4200) - mov cx, 16 + mov cx, 1000 xor dx, dx int HEX (21) jc .exit diff --git a/src/kernel/file.asm b/src/kernel/file.asm index 2b67d1f..92957e2 100644 --- a/src/kernel/file.asm +++ b/src/kernel/file.asm @@ -1162,7 +1162,7 @@ _write_file: push bp mov bp, sp - sub sp, 12 + sub sp, 16 push bx push cx @@ -1221,6 +1221,13 @@ _write_file.truncate: mov bx, ax + and dx, dx + jz .L3 + + inc bx + +.L3: + mov ax, es:[si + 62] mov dx, es:[si + 64] @@ -1228,6 +1235,14 @@ _write_file.truncate: div cx mov cx, ax + + and dx, dx + jz .L3 + + inc cx + +.L4: + xchg bx, cx mov ax, es:[si + 58] @@ -1241,11 +1256,11 @@ _write_file.truncate_walk: and bx, bx jz _write_file.truncate_ok + dec cx + call cs:[_next_cluster] jc _write_file.truncate_ok - dec cx - dec bx jnz _write_file.truncate_walk @@ -1254,6 +1269,9 @@ _write_file.truncate_ok: mov ax, word ptr [bp - 6] mov dx, word ptr [bp - 4] + mov word ptr [bp - 16], ax + mov word ptr [bp - 14], dx + mov word ptr [bp - 12], cx _write_file.truncate_loop: @@ -1321,21 +1339,59 @@ _write_file.truncate_done: and bx, bx jz _write_file.truncate_update - mov ax, es:[si + 58] - mov dx, es:[si + 60] + mov cx, word ptr [bp - 12] + + cmp cx, 2 + jb _write_file.truncate_expand_done + + sub cx, 2 + +_write_file.truncate_expand: + + and cx, cx + jz _write_file.truncate_expand_done + + call cs:[_find_free] + jc _write_file.truncate_expand_done + + push bx + push cx + + mov bx, dx + mov cx, ax + + mov ax, word ptr [bp - 16] + mov dx, word ptr [bp - 14] + + call cs:[_update_cluster] + mov word ptr [bp - 16], cx + mov word ptr [bp - 14], bx + + pop cx + pop bx + + dec cx + jnz _write_file.truncate_expand + +_write_file.truncate_expand_done: + push bx push cx mov bx, HEX (FFFF) mov cx, HEX (FFF8) + mov ax, word ptr [bp - 16] + mov dx, word ptr [bp - 14] + call cs:[_update_cluster] pop cx pop bx - dec word ptr [bp - 12] + mov ax, es:[si + 58] + mov dx, es:[si + 60] _write_file.truncate_update: @@ -1469,6 +1525,13 @@ _write_file.extend: mov bx, ax + and dx, dx + jz .L2 + + inc bx + +.L2: + mov ax, es:[si + 62] mov dx, es:[si + 64] @@ -1477,6 +1540,13 @@ _write_file.extend: mov cx, ax + and dx, dx + jz .L1 + + inc cx + +.L1: + mov ax, es:[si + 58] mov dx, es:[si + 60] @@ -1741,7 +1811,7 @@ _write_file.done: pop cx pop bx - add sp, 12 + add sp, 16 clc mov ax, word ptr [bp - 2] @@ -1761,7 +1831,7 @@ _write_file.error: pop cx pop bx - add sp, 12 + add sp, 16 stc mov ax, 5