Add the missing .lar4 and .sar4 for powerpc.

Inspired by the sparc code (mach/sparc/libem/lar.s).  My powerpc code
might still have bugs, but it's enough for examples/hilo.mod to work.

May need to 'make clean' or touch a build.lua file, so ackbuilder can
notice the new lar4.s and sar4.s files and build them.
This commit is contained in:
George Koehler 2016-09-17 23:55:55 -04:00
parent ff4a7e3d2a
commit 03b067e1d5
3 changed files with 92 additions and 0 deletions

View file

@ -13,6 +13,10 @@
! r3 = ptr to descriptor
! r4 = index
! r5 = address of array
! Yields:
! r3 = address of element
! r0 = size of element (used by .lar4, .sar4)
! Preserves r10 for .lar4, .sar4
.define .aar4
.aar4:

43
mach/powerpc/libem/lar4.s Normal file
View file

@ -0,0 +1,43 @@
#
#include "powerpc.h"
.sect .text
! Load from bounds-checked array.
!
! On entry:
! r3 = ptr to descriptor
! r4 = index
! r5 = address of array
.define .lar4
.lar4:
mfspr r10, lr
bl .aar4
mtspr lr, r10
! r3 = ptr to element
! r0 = size of element
cmpi cr0, 0, r0, 1
bc IFFALSE, EQ, 1f
! Load 1 byte.
lbz r4, 0(r3)
stwu r4, -4(sp)
bclr ALWAYS, 0, 0
1:
cmpi cr0, 0, r0, 2
bc IFFALSE, EQ, 2f
! Load 2 bytes.
lhz r4, 0(r3)
stwu r4, -4(sp)
bclr ALWAYS, 0, 0
2:
! Load r0 bytes, where r0 must be a positive multiple of 4.
subf sp, r0, sp ! move stack pointer down
or r5, r0, r0 ! index r5 = length r0
3:
addic. r5, r5, -4 ! r5 -= 4
lwzx r4, r5, r3
stwx r4, r5, sp
bc IFTRUE, GT, 3b ! loop if r5 > 0
bclr ALWAYS, 0, 0

45
mach/powerpc/libem/sar4.s Normal file
View file

@ -0,0 +1,45 @@
#
#include "powerpc.h"
.sect .text
! Store to bounds-checked array.
!
! On entry:
! r3 = ptr to descriptor
! r4 = index
! r5 = address of array
.define .sar4
.sar4:
mfspr r10, lr
bl .aar4
mtspr lr, r10
! r3 = ptr to element
! r0 = size of element
cmpi cr0, 0, r0, 1
bc IFFALSE, EQ, 1f
! Store 1 byte.
lwz r4, 0(sp)
addi sp, sp, 4
stb r4, 0(r3)
bclr ALWAYS, 0, 0
1:
cmpi cr0, 0, r0, 2
bc IFFALSE, EQ, 2f
! Store 2 bytes.
lwz r4, 0(sp)
addi sp, sp, 4
sth r4, 0(r3)
bclr ALWAYS, 0, 0
2:
! Store r0 bytes, where r0 must be a positive multiple of 4.
or r5, r0, r0 ! index r5 = length r0
3:
addic. r5, r5, -4 ! r5 -= 4
lwzx r4, r5, sp
stwx r4, r5, r3
bc IFTRUE, GT, 3b ! loop if r5 > 0
add sp, r0, sp ! move stack pointer up
bclr ALWAYS, 0, 0