Generating 32 bit code
Tom Hughes
tom at compton.nu
Sat Apr 1 14:55:30 BST 2000
The attached patches for DefMod should allow it to generate 32 bit
code when given the -32bit switch. This switch has three effcts:
* When using -l objasm is invoked with -apcs 3/32Bit
* Generated code doesn't attempt to restore flags on exit
from a veneer
* Generated code uses MRS to return flags for those SWIs
which need to return them
This patch also marks generated code as PIC because I believe it
always is and we might as well tell the truth ;-)
Tom
--
Tom Hughes (tom at compton.nu)
http://www.compton.nu/
...How about a little fire, scarecrow?
-------------- next part --------------
Index: defmod
===================================================================
RCS file: /home/cvs/riscos/oslib/Tools/DefMod/y/defmod,v
retrieving revision 1.2
diff -c -r1.2 defmod
*** defmod 2000/03/04 12:42:54 1.2
--- defmod 2000/04/01 11:44:39
***************
*** 985,990 ****
--- 985,991 ----
int i;
enum {None, Objasm, C_Header, C_Plus_Plus_Header, C_Help, Library, Hdr,
Asm_Help, C_Strong, Asm_Strong} option = None;
+ enum {APCS26, APCS32} mode = APCS26;
char *output = NULL;
trace_initialise ("Trace$To");
***************
*** 1031,1036 ****
--- 1032,1038 ----
"Usage: DefMod <type> [-v] [-help] "
"[-o <output-dir> | > <output-file>] "
"[-byte_wide <byte-wide-file>] "
+ "[-26bit | -32bit] "
"< <module-interface-file>\r"
"Purpose: generate output from a module interface file\r"
"-v\t\t" "verbose\r"
***************
*** 1042,1047 ****
--- 1044,1051 ----
"types defined elsewhere\r"
"<byte-wide-file>\t" "file containing whitespace-separated "
"names of byte-wide types\r"
+ "-26bit\t\t" "generate 26 bit code\r"
+ "-32bit\t\t" "generate 32 bit code\r"
"<type> is one of:\r"
"\t-asmhelp\t" "SrcEdit assembler help file\r"
***************
*** 1113,1118 ****
--- 1117,1130 ----
if ((error = xosfind_close (f)) != NULL)
goto finish;
}
+ else if (strcmp (argv [i], "-26bit") == 0)
+ {
+ mode = APCS26;
+ }
+ else if (strcmp (argv [i], "-32bit") == 0)
+ {
+ mode = APCS32;
+ }
i++;
}
***************
*** 1128,1134 ****
switch (option)
{ case Objasm:
if ((error = objasm_output (stdout, Title, Author, needses,
! consts, types, swis, /*separate?*/ FALSE, SKIP)) != NULL)
goto finish;
break;
--- 1140,1147 ----
switch (option)
{ case Objasm:
if ((error = objasm_output (stdout, Title, Author, needses,
! consts, types, swis, /*separate?*/ FALSE,
! mode == APCS32, SKIP)) != NULL)
goto finish;
break;
***************
*** 1159,1165 ****
case Library:
if (output != NULL)
if ((error = objasm_output (SKIP, Title, Author, needses,
! consts, types, swis, /*separate?*/ TRUE, output)) !=
NULL)
goto finish;
break;
--- 1172,1179 ----
case Library:
if (output != NULL)
if ((error = objasm_output (SKIP, Title, Author, needses,
! consts, types, swis, /*separate?*/ TRUE,
! mode == APCS32, output)) !=
NULL)
goto finish;
break;
-------------- next part --------------
Index: objasm
===================================================================
RCS file: /home/cvs/riscos/oslib/Tools/DefMod/c/objasm,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 objasm
*** objasm 2000/02/16 23:14:46 1.1.1.3
--- objasm 2000/04/01 13:28:12
***************
*** 377,382 ****
--- 377,383 ----
char *swi,
def_s s,
bool nonx,
+ bool apcs32,
lookup_t types
)
{
***************
*** 678,684 ****
}
else
{
! reg = 15; /*PC*/
store_byte = FALSE;
}
--- 679,696 ----
}
else
{
! if (apcs32)
! {
! reg = (nonx && !Set_Elem (0, s->value)) ? 0 : 1;
!
! if ((rc = Emit2 (file, "MRS", SWI_Names [reg], "CPSR")) < 0)
! goto finish;
! }
! else
! {
! reg = 15; /*PC*/
! }
!
store_byte = FALSE;
}
***************
*** 743,753 ****
else
{
/*Value to return?*/
! if (!(s->value == NONE || s->value == 1 << 0))
/*If no value is wanted, or if R0 is required, leave R alone.*/
! if ((rc = Emit2 (file, "MOV", "R",
! SWI_Names [def_bit_index (s->value, 0)])) < 0)
! goto finish;
}
}
else
--- 755,775 ----
else
{
/*Value to return?*/
! if (!(s->value == NONE || Set_Elem (0, s->value)))
! {
/*If no value is wanted, or if R0 is required, leave R alone.*/
! if (apcs32 && Set_Elem(def_FLAGS, s->value))
! {
! if ((rc = Emit2 (file, "MRS", "R", "CPSR")) < 0)
! goto finish;
! }
! else
! {
! if ((rc = Emit2 (file, "MOV", "R",
! SWI_Names [def_bit_index (s->value, 0)])) < 0)
! goto finish;
! }
! }
}
}
else
***************
*** 761,771 ****
else
{
/*Value to return?*/
! if (!(s->value == NONE || s->value == 1 << 0))
/*If no value is wanted, or if R0 is required, leave R alone.*/
! if ((rc = Emit2 (file, "MOV", "R",
! SWI_Names [def_bit_index (s->value, 0)])) < 0)
! goto finish;
}
}
--- 783,803 ----
else
{
/*Value to return?*/
! if (!(s->value == NONE || Set_Elem (0, s->value)))
! {
/*If no value is wanted, or if R0 is required, leave R alone.*/
! if (apcs32 && Set_Elem(def_FLAGS, s->value))
! {
! if ((rc = Emit2 (file, "MRS", "R", "CPSR")) < 0)
! goto finish;
! }
! else
! {
! if ((rc = Emit2 (file, "MOV", "R",
! SWI_Names [def_bit_index (s->value, 0)])) < 0)
! goto finish;
! }
! }
}
}
***************
*** 784,790 ****
{
if ((rc = Format_APCS_List (s1,
v | (mode == LR_STACKED? 1 << 15: 0),
! /*hat?*/ mode == LR_STACKED)) < 0)
goto finish;
if ((rc = Emit2 (file, "LDMFD", "SP!", s1)) < 0)
goto finish;
--- 816,822 ----
{
if ((rc = Format_APCS_List (s1,
v | (mode == LR_STACKED? 1 << 15: 0),
! /*hat?*/ mode == LR_STACKED && !apcs32)) < 0)
goto finish;
if ((rc = Emit2 (file, "LDMFD", "SP!", s1)) < 0)
goto finish;
***************
*** 810,821 ****
if (mode == LR_IN_IP)
{
! if ((rc = Emit2 (file, "MOVS", "PC", "IP")) < 0)
goto finish;
}
else if (mode == LR_PRESERVED)
{
! if ((rc = Emit2 (file, "MOVS", "PC", "LR")) < 0)
goto finish;
}
--- 842,853 ----
if (mode == LR_IN_IP)
{
! if ((rc = Emit2 (file, apcs32? "MOV": "MOVS", "PC", "IP")) < 0)
goto finish;
}
else if (mode == LR_PRESERVED)
{
! if ((rc = Emit2 (file, apcs32? "MOV": "MOVS", "PC", "LR")) < 0)
goto finish;
}
***************
*** 847,852 ****
--- 879,885 ----
lookup_t swis,
bool separate, /*if |separate|, output is to the directory |output|; otherwise,
to the file |file|.*/
+ bool apcs32,
char *output
)
{
***************
*** 902,908 ****
if ((rc = Emit_Line (file)) < 0)
goto finish;
! if ((rc = Emit2 (file, "AREA", "|SWI$$Code|", "CODE, READONLY")) < 0)
goto finish;
if ((rc = Emit_Line (file)) < 0)
goto finish;
--- 935,941 ----
if ((rc = Emit_Line (file)) < 0)
goto finish;
! if ((rc = Emit2 (file, "AREA", "|SWI$$Code|", "CODE, READONLY, PIC")) < 0)
goto finish;
if ((rc = Emit_Line (file)) < 0)
goto finish;
***************
*** 919,927 ****
if (!s->absent)
{
! if ((rc = Emit_Code (file, swi, s, FALSE, types)) < 0)
goto finish;
! if ((rc = Emit_Code (file, swi, s, TRUE, types)) < 0)
goto finish;
}
--- 952,960 ----
if (!s->absent)
{
! if ((rc = Emit_Code (file, swi, s, FALSE, apcs32, types)) < 0)
goto finish;
! if ((rc = Emit_Code (file, swi, s, TRUE, apcs32, types)) < 0)
goto finish;
}
***************
*** 938,944 ****
{
char name1 [FILENAME_MAX + 1], name2 [FILENAME_MAX + 1],
cmd [1024];
! int count = 0, len, context1, var_type;
/*Ensure the directory exists.*/
if ((error = xosfile_create_dir (output, 0)) != NULL)
--- 971,977 ----
{
char name1 [FILENAME_MAX + 1], name2 [FILENAME_MAX + 1],
cmd [1024];
! int count = 0;
/*Ensure the directory exists.*/
if ((error = xosfile_create_dir (output, 0)) != NULL)
***************
*** 1034,1045 ****
goto finish;
if ((rc = Emit2 (object, "AREA",
! "|SWI$$Code|", "CODE, READONLY")) < 0)
goto finish;
if ((rc = Emit_Line (object)) < 0)
goto finish;
! if ((rc = Emit_Code (object, swi, s, nonx, types)) < 0)
goto finish;
if ((rc = Emit0 (object, "END")) < 0)
--- 1067,1078 ----
goto finish;
if ((rc = Emit2 (object, "AREA",
! "|SWI$$Code|", "CODE, READONLY, PIC")) < 0)
goto finish;
if ((rc = Emit_Line (object)) < 0)
goto finish;
! if ((rc = Emit_Code (object, swi, s, nonx, apcs32, types)) < 0)
goto finish;
if ((rc = Emit0 (object, "END")) < 0)
***************
*** 1054,1065 ****
#if 0
if ((rc = sprintf (cmd, "ObjAsm -from %s.%s -to %s.%s "
! "-stamp -quit", prefix_dir, name1, prefix_dir, name2))
< 0)
goto finish;
#else
if ((rc = sprintf (cmd, "ObjAsm -from %s -to %s "
! "-stamp -quit", name1, name2)) < 0)
goto finish;
#endif
--- 1087,1100 ----
#if 0
if ((rc = sprintf (cmd, "ObjAsm -from %s.%s -to %s.%s "
! "-stamp -quit -apcs 3/%dbit/SWstackcheck", prefix_dir,
! name1, prefix_dir, name2, apcs32 ? 32 : 26))
< 0)
goto finish;
#else
if ((rc = sprintf (cmd, "ObjAsm -from %s -to %s "
! "-stamp -quit -apcs 3/%dbit/SWstackcheck",
! name1, name2, apcs32 ? 32 : 26)) < 0)
goto finish;
#endif
-------------- next part --------------
Index: objasm
===================================================================
RCS file: /home/cvs/riscos/oslib/Tools/DefMod/h/objasm,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 objasm
*** objasm 2000/02/14 22:36:10 1.1.1.1
--- objasm 2000/04/01 11:29:07
***************
*** 5,10 ****
#include <stdio.h>
extern os_error *objasm_output (FILE *, char *, char *, lookup_t, lookup_t,
! lookup_t, lookup_t, bool, char *output);
#endif
--- 5,10 ----
#include <stdio.h>
extern os_error *objasm_output (FILE *, char *, char *, lookup_t, lookup_t,
! lookup_t, lookup_t, bool, bool, char *output);
#endif
More information about the oslib-team
mailing list