Skip to content
This repository was archived by the owner on Mar 18, 2023. It is now read-only.

Commit ba1cb78

Browse files
authored
Merge pull request #25 from luisdallos/multi_level_pointer_write_support
engine: Implement multi-level pointer write support.
2 parents 71d4a8f + 728530a commit ba1cb78

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

engine/engine_asm.S

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -344,33 +344,56 @@ type_6:
344344
*
345345
* 8-bit write
346346
* 6-aaaaaaa 000000vv
347-
* 00000000 iiiiiiii
347+
* 0000nnnn iiiiiiii
348+
* pppppppp pppppppp # 1st. extra pointer line, required if @n > 1
349+
* ........ ........
350+
* pppppppp pppppppp # N-th. extra pointer line, required if @n > ((N << 1) - 1)
348351
*
349352
* 16-bit write
350353
* 6-aaaaaaa 0000vvvv
351-
* 00010000 iiiiiiii
354+
* 0001nnnn iiiiiiii
355+
* pppppppp pppppppp
356+
* ........ ........
357+
* pppppppp pppppppp
352358
*
353359
* 32-bit write
354360
* 6-aaaaaaa vvvvvvvv
355-
* 00020000 iiiiiiii
356-
*
357-
* Loads 32-bit base address from address @a, adds offset @i to it, and
358-
* constantly writes the value @v to the final address.
361+
* 0002nnnn iiiiiiii
362+
* pppppppp pppppppp
363+
* ........ ........
364+
* pppppppp pppppppp
365+
*
366+
* Loads 32-bit base address from address @a and adds offset @i to it
367+
* to get either the final address (normal pointer write, where @n == 1,
368+
* @n being the number of times to point) or a new pointer location
369+
* (multi-level pointer write, where @n > 1), in the multi-level pointer
370+
* write case, continue by loading 32-bit base address from the pointer
371+
* location computed at the previous iteration and adding offset @p
372+
* to it, keep doing this until all (@n - 1) offsets @p have been
373+
* processed, and constantly writes the value @v to the final address.
359374
*/
360-
lw $t5, 0($a0)
375+
lhu $a2, 10($t2) /* $a2: write type (0 for 8 bit, 1 for 16 bit, 2 for 32 bit) */
376+
lhu $t6, 8($t2) /* $t6: number of times to point (@n) */
377+
andi $a2, 0xf
378+
srl $t7, $t6, 1 /* $t7: number of extra pointer lines = (@n >> 1) */
361379
li $at, 0x3ffffffc
380+
1:
381+
lw $t5, 0($a0) /* $t5: base address, $a0: pointer location */
382+
lw $a3, 12($t2) /* $a3: pointer offset */
362383
and $t5, $at
363-
beqz $t5, 1f
364-
lhu $a2, 10($t2)
365-
lw $a3, 12($t2)
366-
addu $t5, $a3
367-
beqzl $a2, 1f
368-
sb $a1, 0($t5)
384+
beqz $t5, 2f /* stop execution if base address is zero */
385+
addu $a0, $t5, $a3 /* adds pointer offset to the base address */
386+
addiu $t6, -1 /* decrement @n */
387+
bgtz $t6, 1b /* if @n > 0, continue with the next pointer offset */
388+
addiu $t2, 4
389+
beqzl $a2, 2f
390+
sb $a1, 0($a0)
369391
addiu $a2, -1
370-
beqzl $a2, 1f
371-
sh $a1, 0($t5)
372-
sw $a1, 0($t5)
373-
1:
392+
beqzl $a2, 2f
393+
sh $a1, 0($a0)
394+
sw $a1, 0($a0)
395+
2:
396+
addu $t4, $t7
374397
b next
375398
addiu $t4, 1
376399
type_7:

0 commit comments

Comments
 (0)