Use extended mnemonics and ha16/lo16.

Remove wrong comment: that's a right shift, not a left shift.
This commit is contained in:
George Koehler 2018-01-11 20:04:27 -05:00
parent 103d44c27c
commit f1304e1a3c
4 changed files with 20 additions and 29 deletions

View file

@ -32,7 +32,7 @@ begtext:
lwz r3, 0(sp) ! r3 = argc
addi r4, sp, 4 ! r4 = argv
rlwinm r5, r3, 32-2, 2, 31 ! shift left 2 bits
srwi r5, r3, 2
add r5, r5, r4
addi r5, r5, 8 ! r5 = env

View file

@ -12,16 +12,7 @@
.sect .text
EINVAL = 22
#define IFFALSE 4
#define IFTRUE 12
#define ALWAYS 20
#define LT 0
#define GT 1
#define EQ 2
#define OV 3
#define EINVAL 22
! Perform a Linux system call.
@ -32,21 +23,21 @@ __syscall:
lwz r4, 8(sp)
lwz r5, 12(sp)
sc 0
bclr IFFALSE, OV, 0
bnslr
! On error, r3 contains the errno.
! It just so happens that errnos 1-34 are the same in Linux as in ACK.
cmpi cr0, 0, r3, 1
bc IFTRUE, LT, 2f
cmpi cr0, 0, r3, 34
bc IFTRUE, GT, 2f
cmpwi r3, 1
blt 2f
cmpwi r3, 34
bgt 2f
3:
li32 r4, _errno
stw r3, 0(r4)
addi r3, r0, -1
bclr ALWAYS, 0, 0
lis r4, ha16[_errno]
stw r3, lo16[_errno](r4)
li r3, -1
blr
2:
addi r3, r0, EINVAL
li r3, EINVAL
b 3b

View file

@ -29,7 +29,7 @@ begtext:
lwz r3, 0(sp) ! r3 = argc
addi r4, sp, 4 ! r4 = argv
rlwinm r5, r3, 32-2, 2, 31 ! shift left 2 bits
srwi r5, r3, 2
add r5, r5, r4
addi r5, r5, 8 ! r5 = env

View file

@ -1,7 +1,7 @@
.sect .text
.define .set_errno
.set_errno:
li32 r10, _errno
stw r3, 0(r10) ! set errno
addi r3, r0, -1 ! return -1
bclr 20, 0, 0
lis r4, ha16[_errno]
stw r3, lo16[_errno](r4) ! set errno
li r3, -1 ! return -1
blr