; ; os.s ; ; RISC OS kernel interface ; ; © 1994-1998 Straylight ; ;----- Licensing note ------------------------------------------------------- ; ; This file is part of Straylight's Steel library. ; ; Steel is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2, or (at your option) ; any later version. ; ; Steel is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with Steel. If not, write to the Free Software Foundation, ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;----- Standard stuff ------------------------------------------------------- GET libs:header GET libs:swis ;----- Generic SWI interface ------------------------------------------------ AREA |C$$Code|,CODE,READONLY GET libs:s.swihack ; --- os_swi --- ; ; On entry: a1 == SWI number ; a2 == pointer to register set EXPORT os_swi os_swi STMFD R13!,{R1,R4-R10,R14} ;Save registers BIC R10,R0,#&20000 ;Strip the X bit LDMIA R1,{R0-R9} ;Load lots of registers MOV R14,PC ;Set return address LDR PC,_swihack ;And call the hacky routine LDR R10,[R13],#4 ;Reload regset pointer STMIA R10,{R0-R9} ;Save output registers LDMFD R13!,{R4-R10,PC}^ ;And return to caller LTORG ; --- os_swix --- ; ; On entry: a1 == SWI number ; a2 == pointer to register set EXPORT os_swix os_swix STMFD R13!,{R1,R4-R10,R14} ;Save registers ORR R10,R0,#&20000 ;Set the X bit LDMIA R1,{R0-R9} ;Load lots of registers MOV R14,PC ;Set return address LDR PC,_swihack ;And call the hacky routine LDR R10,[R13],#4 ;Reload regset pointer STMIA R10,{R0-R9} ;Save output registers MOVVC R0,#0 ;Return zero on no error LDMFD R13!,{R4-R10,PC}^ ;And return to caller LTORG ;----- Fixed-parameter non-returning SWI interfaces ------------------------- ; --- os_swi0, os_swi1, os_swi2, os_swi3 --- ; ; On entry: a1 == SWI number ; a2,a3,a4 == R0,R1,R2 on entry to SWI ; On exit: a1 == pointer to possible error EXPORT os_swi0 EXPORT os_swi1 EXPORT os_swi2 EXPORT os_swi3 os_swi0 os_swi1 os_swi2 os_swi3 STMFD R13!,{R4-R10,R14} ;Save registers ORR R10,R0,#&20000 ;Set the X bit MOV R0,R1 MOV R1,R2 MOV R2,R3 MOV R14,PC ;Set return address LDR PC,_swihack ;And call the hacky routine MOVVC R0,#0 ;Return zero on no error LDMFD R13!,{R4-R10,PC}^ ;And return to caller LTORG ; --- os_swi4, os_swi5, os_swi6 --- ; ; On entry: a1 == SWI number ; a2,a3,a4 == R0,R1,R2 on entry to SWI ; [sp,#0],[sp,#4],[sp,#8] == R3,R4,R5 on entry to SWI ; On exit: a1 == pointer to possible error EXPORT os_swi4 EXPORT os_swi5 EXPORT os_swi6 os_swi4 os_swi5 os_swi6 MOV R12,R12 ;Remember stack position STMFD R13!,{R1,R4-R10,R14} ;Save registers ORR R10,R0,#&20000 ;Set the X bit MOV R0,R1 MOV R1,R2 MOV R2,R3 LDMIA R12,{R3-R5} MOV R14,PC ;Set return address LDR PC,_swihack ;And call the hacky routine MOVVC R0,#0 ;Return zero on no error LDMFD R13!,{R4-R10,PC}^ ;And return to caller LTORG ;----- Fixed-parameter, returning SWI interfaces ---------------------------- ; --- os__doSWI --- ; ; CAUTION: NOTHING LIKE APCS ; ; On entry: R0-R5 == SWI registers ; R6-R11 == where to output registers ; R14 == SWI number ; sp points to saved R4-R11 and R14 on stack ; On exit: R0 == pointer to possible error os__doSWI ROUT STMFD sp!,{R6-R11} ;Save the pointers away ORR R10,R14,#&20000 ;Put in the X bit anyway MOV R14,PC LDR PC,_swihack ADDVS sp,sp,#24 ;Point back at saved regs LDMVSFD sp!,{R4-R11,pc}^ ;If it failed, return now ; --- Refind the the pointers and store --- LDMFD sp!,{R6-R11} ;Get the output pointers CMP R6,#0 STRNE R0,[R6] CMP R7,#0 STRNE R1,[R7] CMP R8,#0 STRNE R2,[R8] CMP R9,#0 STRNE R3,[R9] CMP R10,#0 STRNE R4,[R10] CMP R11,#0 STRNE R5,[R11] ; --- Now return to the caller --- MOV R0,#0 ;There was no error LDMFD sp!,{R4-R11,pc}^ ;Return to caller LTORG ; --- os_swi1r --- EXPORT os_swi1r os_swi1r MOV ip,sp STMFD sp!,{R4-R11,lr} ;We corrupt lots of registers MOV R14,R0 MOV R0,R1 MOV R6,R2 MOV R7,#0 MOV R8,#0 MOV R9,#0 MOV R10,#0 MOV R11,#0 B os__doSWI ; --- os_swi2r --- EXPORT os_swi2r os_swi2r MOV ip,sp STMFD sp!,{R4-R11,lr} ;We corrupt lots of registers MOV R14,R0 MOV R0,R1 MOV R1,R2 MOV R6,R3 LDMIA ip!,{R7} MOV R8,#0 MOV R9,#0 MOV R10,#0 MOV R11,#0 B os__doSWI ; --- os_swi3r --- EXPORT os_swi3r os_swi3r MOV ip,sp STMFD sp!,{R4-R11,lr} ;We corrupt lots of registers MOV R14,R0 MOV R0,R1 MOV R1,R2 MOV R2,R3 LDMIA ip!,{R6-R8} MOV R9,#0 MOV R10,#0 MOV R11,#0 B os__doSWI ; --- os_swi4r --- EXPORT os_swi4r os_swi4r MOV ip,sp STMFD sp!,{R4-R11,lr} ;We corrupt lots of registers MOV R14,R0 MOV R0,R1 MOV R1,R2 MOV R2,R3 LDMIA ip!,{R3} LDMIA ip!,{R6-R9} MOV R10,#0 MOV R11,#0 B os__doSWI ; --- os_swi5r --- EXPORT os_swi5r os_swi5r MOV ip,sp STMFD sp!,{R4-R11,lr} ;We corrupt lots of registers MOV R14,R0 MOV R0,R1 MOV R1,R2 MOV R2,R3 LDMIA ip!,{R3,R4} LDMIA ip!,{R6-R10} MOV R11,#0 B os__doSWI ; --- os_swi6r --- EXPORT os_swi6r os_swi6r MOV ip,sp STMFD sp!,{R4-R11,lr} ;We corrupt lots of registers MOV R14,R0 MOV R0,R1 MOV R1,R2 MOV R2,R3 LDMIA ip!,{R3-R5} LDMIA ip!,{R6-R11} B os__doSWI ;----- Variable number of registers ----------------------------------------- ; --- os_swiv --- ; ; On entry: a1 == SWI number ; a2... == registers ; On exit: a1 == pointer to possible to area EXPORT os_swiv os_swiv MOV R12,R13 STMFD R13!,{R4-R10,R14} ;Save registers ORR R10,R0,#&20000 ;Set the X bit MOV R0,R1 MOV R1,R2 MOV R2,R3 LDMIA R12,{R3-R9} MOV R14,PC ;Set return address LDR PC,_swihack ;And call the hacky routine MOVVC R0,#0 ;Return zero on no error LDMFD R13!,{R4-R10,PC}^ ;And return to caller LTORG ; --- os_swivr --- ; ; On entry: a1 == SWI number ; a2 == pointer to os_regset ; a3... == registers to pass ; On exit: a1 == pointer to possible error EXPORT os_swivr os_swivr MOV R12,R13 STMFD R13!,{R1,R4-R10,R14} ;Save registers ORR R10,R0,#&20000 ;Set the X bit MOV R0,R2 MOV R1,R3 LDMIA R12,{R2-R9} MOV R14,PC ;Set return address LDR PC,_swihack ;And call the hacky routine LDR R12,[R13],#4 ;Load regset pointer LDMVCIA R12,{R0-R9} ;Save all of them away MOVVC R0,#0 ;Return zero on no error LDMFD R13!,{R4-R10,PC}^ ;And return to caller LTORG ;----- Veneers to specific routines ----------------------------------------- ; --- os_byte --- ; ; On entry: a1 == reason code for OS_Byte ; a2 == pointer to x value ; a3 == pointer to y value EXPORT os_byte os_byte STMFD sp!,{v1,v2,lr} ;Save registers away MOV v1,a2 MOV v2,a3 LDR a2,[v1] LDR a3,[v2] SWI XOS_Byte STRVC a2,[v1] STRVC a3,[v2] MOVVC a1,#0 LDMFD sp!,{v1,v2,pc}^ ; --- os_word --- ; ; On entry: a1 == reason code for OS_Word ; a2 == pointer to parameter block EXPORT os_word os_word SWI XOS_Word MOVVC a1,#0 MOVS pc,lr ; --- os_gbpb --- ; ; On entry: a1 == pointer to `reg block' EXPORT os_gbpb os_gbpb STMFD sp!,{a1,v1-v6,lr} LDMIA a1,{a1-a4,v1-v6} SWI XOS_GBPB LDR lr,[sp],#4 STMVCIA lr,{a1-a4,v1-v6} MOVVC a1,#0 LDMFD sp!,{v1-v6,pc}^ LTORG ; --- os_file --- ; ; On entry: a1 == pointer to `reg block' EXPORT os_file os_file STMFD sp!,{a1,v1-v6,lr} LDMIA a1,{a1-a4,v1-v6} SWI XOS_File LDR lr,[sp],#4 STMVCIA lr,{a1-a4,v1-v6} MOVVC a1,#0 LDMFD sp!,{v1-v6,pc}^ LTORG ; --- os_args --- ; ; On entry: a1 == pointer to a real reg block EXPORT os_args os_args STMFD sp!,{a1,v1-v6,lr} LDMIA a1,{a1-a4,v1-v6} SWI XOS_Args LDR lr,[sp],#4 STMVCIA lr,{a1-a4,v1-v6} MOVVC a1,#0 LDMFD sp!,{v1-v6,pc}^ LTORG ; --- os_find --- ; ; On entry: a1 == pointer to a real reg block EXPORT os_find os_find STMFD sp!,{a1,v1-v6,lr} LDMIA a1,{a1-a4,v1-v6} SWI XOS_Find LDR lr,[sp],#4 STMVCIA lr,{a1-a4,v1-v6} MOVVC a1,#0 LDMFD sp!,{v1-v6,pc}^ LTORG ; --- os_cli --- ; ; On entry: a1 == pointer to command string EXPORT os_cli os_cli SWI XOS_CLI MOVVC a1,#0 MOVS pc,lr ; --- os_read_var_val --- ; ; On entry: a1 == pointer to variable name ; a2 == pointer to buffer to store the value ; a3 == size of the buffer EXPORT os_read_var_val os_read_var_val STMFD sp!,{v1,lr} MOV a4,#0 MOV v1,#3 SWI XOS_ReadVarVal MOV v1,#0 MOVVS a3,#0 STRB v1,[a2,a3] MOVVC a1,#0 LDMFD sp!,{v1,pc}^ ;----- That's all, folks ---------------------------------------------------- END