diff --git a/compiler/globals.pas b/compiler/globals.pas index 056271c740..2c1214a39a 100644 --- a/compiler/globals.pas +++ b/compiler/globals.pas @@ -271,6 +271,10 @@ interface palmos_applicationid : string[4] = 'FPCA'; {$endif m68k} +{$ifdef powerpc} + { default calling convention used on MorphOS } + syscall_convention : string = 'LEGACY'; +{$endif powerpc} procedure abstract; @@ -2169,7 +2173,10 @@ end; end. { $Log$ - Revision 1.156 2005-01-04 16:20:51 florian + Revision 1.157 2005-01-04 17:40:33 karoly + + sysv style syscalls added for MorphOS + + Revision 1.156 2005/01/04 16:20:51 florian * fixed nan et al. handling on arm Revision 1.155 2004/12/28 20:43:01 hajny diff --git a/compiler/pdecsub.pas b/compiler/pdecsub.pas index f4988cea66..bca7a76f55 100644 --- a/compiler/pdecsub.pas +++ b/compiler/pdecsub.pas @@ -1208,6 +1208,24 @@ begin {$ifdef powerpc} if target_info.system in [system_powerpc_morphos,system_m68k_amiga] then begin + if idtoken=_LEGACY then + begin + consume(_LEGACY); + include(pd.procoptions,po_syscall_legacy); + end + else if idtoken=_SYSV then + begin + consume(_SYSV); + include(pd.procoptions,po_syscall_sysv); + end + else + if syscall_convention='LEGACY' then + include(pd.procoptions,po_syscall_legacy) + else if syscall_convention='SYSV' then + include(pd.procoptions,po_syscall_sysv) + else + internalerror(2005010404); + if consume_sym(sym,symtable) then begin if (sym.typ=globalvarsym) and @@ -1217,13 +1235,16 @@ begin ) then begin tprocdef(pd).libsym:=sym; - vs:=tparavarsym.create('$syscalllib',paranr_syscall,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]); - paramanager.parseparaloc(vs,'A6'); - pd.parast.insert(vs); + if po_syscall_legacy in tprocdef(pd).procoptions then + begin + vs:=tparavarsym.create('$syscalllib',paranr_syscall,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]); + paramanager.parseparaloc(vs,'A6'); + pd.parast.insert(vs); + end; end else Message(parser_e_32bitint_or_pointer_variable_expected); - end; + end; (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside); (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside); end; @@ -2344,7 +2365,10 @@ const end. { $Log$ - Revision 1.222 2004-12-27 17:32:06 peter + Revision 1.223 2005-01-04 17:40:33 karoly + + sysv style syscalls added for MorphOS + + Revision 1.222 2004/12/27 17:32:06 peter * don't parse public,private,protected as procdirectives, leave procdirective parsing before any other check is done diff --git a/compiler/powerpc/nppccal.pas b/compiler/powerpc/nppccal.pas index d63b7ececa..505fe615cd 100644 --- a/compiler/powerpc/nppccal.pas +++ b/compiler/powerpc/nppccal.pas @@ -67,6 +67,7 @@ implementation end; end; + procedure tppccallnode.do_syscall; var tmpref: treference; @@ -74,32 +75,61 @@ implementation case target_info.system of system_powerpc_morphos: begin - cg.getcpuregister(exprasmlist,NR_R0); - cg.getcpuregister(exprasmlist,NR_R3); + if po_syscall_sysv in tprocdef(procdefinition).procoptions then + begin + cg.getcpuregister(exprasmlist,NR_R0); + cg.getcpuregister(exprasmlist,NR_R31); + + reference_reset(tmpref); + tmpref.symbol := objectlibrary.newasmsymbol(tglobalvarsym(tprocdef(procdefinition).libsym).mangledname,AB_EXTERNAL,AT_DATA); + tmpref.refaddr := addr_hi; + exprasmlist.concat(taicpu.op_reg_ref(A_LIS,NR_R31,tmpref)); + tmpref.base := NR_R31; + tmpref.refaddr := addr_lo; + exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R31,tmpref)); + + exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R0,NR_R31,-tprocdef(procdefinition).extnumber)); + exprasmlist.concat(taicpu.op_reg(A_MTCTR,NR_R0)); + exprasmlist.concat(taicpu.op_none(A_BCTRL)); - { store call offset into R3 } - exprasmlist.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber)); + cg.ungetcpuregister(exprasmlist,NR_R31); + cg.ungetcpuregister(exprasmlist,NR_R0); + end + else if po_syscall_legacy in tprocdef(procdefinition).procoptions then + begin + cg.getcpuregister(exprasmlist,NR_R0); + cg.getcpuregister(exprasmlist,NR_R3); - { prepare LR, and call function } - reference_reset_base(tmpref,NR_R2,100); { 100 ($64) is EmulDirectCallOS offset } - exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref)); - exprasmlist.concat(taicpu.op_reg(A_MTLR,NR_R0)); - exprasmlist.concat(taicpu.op_none(A_BLRL)); + { store call offset into R3 } + exprasmlist.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber)); - cg.ungetcpuregister(exprasmlist,NR_R0); - cg.ungetcpuregister(exprasmlist,NR_R3); + { prepare LR, and call function } + reference_reset_base(tmpref,NR_R2,100); { 100 ($64) is EmulDirectCallOS offset } + exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref)); + exprasmlist.concat(taicpu.op_reg(A_MTLR,NR_R0)); + exprasmlist.concat(taicpu.op_none(A_BLRL)); + + cg.ungetcpuregister(exprasmlist,NR_R0); + cg.ungetcpuregister(exprasmlist,NR_R3); + end + else + internalerror(2005010403); end; else internalerror(2004042901); end; end; + begin ccallnode:=tppccallnode; end. { $Log$ - Revision 1.31 2004-12-06 18:06:37 jonas + Revision 1.32 2005-01-04 17:40:33 karoly + + sysv style syscalls added for MorphOS + + Revision 1.31 2004/12/06 18:06:37 jonas * only set/clear bit 6 of cr in case of varargs for the sysv abi Revision 1.30 2004/10/15 09:30:13 mazen diff --git a/compiler/scandir.pas b/compiler/scandir.pas index 5734c54b71..4b94945c1a 100644 --- a/compiler/scandir.pas +++ b/compiler/scandir.pas @@ -876,6 +876,23 @@ implementation do_message(scan_f_user_defined); end; +{$ifdef powerpc} + procedure dir_syscall; + var + sctype : string; + begin + if not (target_info.system in [system_powerpc_morphos]) then + comment (V_Warning,'Syscall directive is useless on this target.'); + current_scanner.skipspace; + + sctype:=current_scanner.readid; + if (sctype='LEGACY') or (sctype='SYSV') then + syscall_convention:=sctype + else + comment (V_Warning,'Invalid Syscall directive ignored.'); + end; +{$endif} + procedure dir_threading; var mac : tmacro; @@ -1128,6 +1145,9 @@ implementation AddDirective('STACKFRAMES',directive_all, @dir_stackframes); AddDirective('STATIC',directive_all, @dir_static); AddDirective('STOP',directive_all, @dir_stop); +{$ifdef powerpc} + AddDirective('SYSCALL',directive_all, @dir_syscall); +{$endif powerpc} AddDirective('THREADING',directive_all, @dir_threading); AddDirective('THREADNAME',directive_all, @dir_threadname); AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress); @@ -1149,7 +1169,10 @@ begin end. { $Log$ - Revision 1.48 2005-01-04 16:18:57 florian + Revision 1.49 2005-01-04 17:40:33 karoly + + sysv style syscalls added for MorphOS + + Revision 1.48 2005/01/04 16:18:57 florian * prepared for fpu mode depended define Revision 1.47 2004/11/06 17:58:10 peter diff --git a/compiler/symconst.pas b/compiler/symconst.pas index 41c357b782..f644a87143 100644 --- a/compiler/symconst.pas +++ b/compiler/symconst.pas @@ -249,7 +249,10 @@ type po_has_public_name, po_forward, po_global, - po_has_inlininginfo + po_has_inlininginfo, + { The two different kind of syscalls on MorphOS } + po_syscall_legacy, + po_syscall_sysv ); tprocoptions=set of tprocoption; @@ -429,7 +432,10 @@ initialization end. { $Log$ - Revision 1.96 2004-12-05 12:28:11 peter + Revision 1.97 2005-01-04 17:40:33 karoly + + sysv style syscalls added for MorphOS + + Revision 1.96 2004/12/05 12:28:11 peter * procvar handling for tp procvar mode fixed * proc to procvar moved from addrnode to typeconvnode * inlininginfo is now allocated only for inline routines that diff --git a/compiler/tokens.pas b/compiler/tokens.pas index 113cea90cc..71b5bd9736 100644 --- a/compiler/tokens.pas +++ b/compiler/tokens.pas @@ -226,7 +226,9 @@ type _UNIMPLEMENTED, _IMPLEMENTATION, _INITIALIZATION, - _RESOURCESTRING + _RESOURCESTRING, + _LEGACY, + _SYSV ); const @@ -455,7 +457,9 @@ const (str:'UNIMPLEMENTED' ;special:false;keyword:m_all;op:NOTOKEN), (str:'IMPLEMENTATION';special:false;keyword:m_all;op:NOTOKEN), (str:'INITIALIZATION';special:false;keyword:m_initfinal;op:NOTOKEN), - (str:'RESOURCESTRING';special:false;keyword:m_class;op:NOTOKEN) + (str:'RESOURCESTRING';special:false;keyword:m_class;op:NOTOKEN), + (str:'LEGACY' ;special:false;keyword:m_none;op:NOTOKEN), + (str:'SYSV' ;special:false;keyword:m_none;op:NOTOKEN) ); var @@ -516,7 +520,10 @@ end; end. { $Log$ - Revision 1.32 2004-10-24 20:01:08 peter + Revision 1.33 2005-01-04 17:40:33 karoly + + sysv style syscalls added for MorphOS + + Revision 1.32 2004/10/24 20:01:08 peter * remove saveregister calling convention Revision 1.31 2004/07/05 23:25:34 olle