[openfirmware] [commit] r3708 - cpu/ppc cpu/ppc/ppcsim cpu/x86/Linux forth/wrapper

repository service svn at openfirmware.info
Sun Jan 19 02:21:04 CET 2014


Author: wmb
Date: Sun Jan 19 02:21:01 2014
New Revision: 3708
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3708

Log:
1) Eliminated some C compiler warnings by being strict about return values.
2) Fixed the PowerPC build.

Modified:
   cpu/ppc/basefw.bth
   cpu/ppc/kerncode.fth
   cpu/ppc/ppcsim/ppcsim.c
   cpu/x86/Linux/Makefile
   cpu/x86/Linux/Makefile.ppcforth
   forth/wrapper/logger.c
   forth/wrapper/wrapper.c

Modified: cpu/ppc/basefw.bth
==============================================================================
--- cpu/ppc/basefw.bth	Sat Jan 11 07:24:15 2014	(r3707)
+++ cpu/ppc/basefw.bth	Sun Jan 19 02:21:01 2014	(r3708)
@@ -69,6 +69,8 @@
    fload ${BP}/ofw/fs/cdfs/loadpkg.fth	\ ISO 9660 CD-ROM file system reader
 end-support-package
 
+fload ${BP}/ofw/disklabel/gpttools.fth
+
 support-package: disk-label
    fload ${BP}/ofw/disklabel/loadpkg.fth	\ Disk label package
 end-support-package

Modified: cpu/ppc/kerncode.fth
==============================================================================
--- cpu/ppc/kerncode.fth	Sat Jan 11 07:24:15 2014	(r3707)
+++ cpu/ppc/kerncode.fth	Sun Jan 19 02:21:01 2014	(r3708)
@@ -88,6 +88,7 @@
 :-h skip-branch     " addi ip,ip,/branch"                      evaluate  ;-h
 :-h literal-to-tos  " lwzu tos,/token(ip)"                     evaluate  ;-h
 :-h literal-to-t0   " lwzu t0,/token(ip)"                      evaluate  ;-h
+:-h tliteral-to-t0  " lwzu t0,/token(ip)  add t0,t0,base"      evaluate  ;-h
 :-h rdrop           " addi rp,rp,1cell"                        evaluate  ;-h
 :-h rdrop3          " addi rp,rp,3cells"                       evaluate  ;-h
 
@@ -191,21 +192,22 @@
 meta definitions
 
 code isdefer  ( xt -- )
-   literal-to-t0
+   tliteral-to-t0
    lwz    t0,/cf(t0)   \ User number in t0
+   subfc  tos,base,tos
    stwx   tos,t0,up
    pop-tos
 c;
 
 code isvalue  ( n -- )
-   literal-to-t0
+   tliteral-to-t0
    lwz    t0,/cf(t0)   \ User number in t0
    stwx   tos,t0,up
    pop-tos
 c;
 
 code isuser  ( n -- )
-   literal-to-t0
+   tliteral-to-t0
    lwz    t0,/cf(t0)   \ User number in t0
    stwx   tos,t0,up
    pop-tos
@@ -218,7 +220,7 @@
 c;
 
 code isvariable ( n -- )
-   literal-to-t0
+   tliteral-to-t0
    stw    tos,/cf(t0)
    pop-tos
 c;
@@ -384,6 +386,15 @@
    pop-tos
 c;
 
+\ ($endof) is the same as branch, and ($endcase) is the same as drop,
+\ but redefining them this way makes the decompiler much easier.
+code ($endof)    (s -- )
+   take-branch
+c;
+code ($endcase)  (s n -- )
+   pop-tos
+c;
+
 assembler
 mlabel dofalse
    addi    tos,r0,0
@@ -762,6 +773,145 @@
    pop2
 c;
 
+\ Find the first occurence of bvalue, returning the residual string
+code bscan  ( adr len bvalue -- adr' len' )
+   mr    t1,tos        \ t1:bvalue
+   lwz   tos,0(sp)     \ tos:len
+   addi  sp,sp,1cell   \ Move stack pointer by one
+
+   cmpi  0,0,tos,0  0=  if  \ Bail out if len=0
+      next
+   then
+
+   lwz   t0,0(sp)      \ t0:adr
+
+   addi  t0,t0,-1      \ Account for pre-incrementing
+   begin
+      lbzu   t2,1(t0)
+      cmp    0,0,t1,t2  =  if
+         stw  t0,0(sp)
+         next
+      then
+      addic.  tos,tos,-1
+   0= until
+
+   addi t0,t0,1
+   stw  t0,0(sp)
+c;
+
+code wscan  ( adr len wvalue -- adr' len' )
+   mr    t1,tos        \ t1:lvalue
+   lwz   tos,0(sp)     \ tos:len
+   addi  sp,sp,1cell   \ Move stack pointer by one
+
+   cmpi  0,0,tos,0  0=  if  \ Bail out if len=0
+      next
+   then
+
+   lwz   t0,0(sp)      \ t0:adr
+
+   addi  t0,t0,-2      \ Account for pre-incrementing
+   begin
+      lhzu   t2,2(t0)
+      cmp    0,0,t1,t2  =  if
+         stw  t0,0(sp)
+         next
+      then
+      addic.  tos,tos,-2
+   0= until
+
+   addi t0,t0,2
+   stw  t0,0(sp)
+c;
+
+code lscan  ( adr len lvalue -- adr' len' )
+   mr    t1,tos        \ t1:lvalue
+   lwz   tos,0(sp)     \ tos:len
+   addi  sp,sp,1cell   \ Move stack pointer by one
+
+   cmpi  0,0,tos,0  0=  if  \ Bail out if len=0
+      next
+   then
+
+   lwz   t0,0(sp)      \ t0:adr
+
+   addi  t0,t0,-4      \ Account for pre-incrementing
+   begin
+      lwzu   t2,4(t0)
+      cmp    0,0,t1,t2  =  if
+         stw  t0,0(sp)
+         next
+      then
+      addic.  tos,tos,-4
+   0= until
+
+   addi t0,t0,4
+   stw  t0,0(sp)
+c;
+
+\ Skip initial occurrences of bvalue, returning the residual length
+code bskip  ( adr len bvalue -- residue )
+   mr    t1,tos        \ t1:bvalue
+   lwz   tos,0(sp)     \ tos:len
+   lwz   t0,1cell(sp)  \ t0:adr
+   addi  sp,sp,2cells  \ Move stack pointer by two
+
+   cmpi  0,0,tos,0  0=  if  \ Bail out if len=0
+      next
+   then
+
+   addi  t0,t0,-1      \ Account for pre-incrementing
+   begin
+      lbzu   t2,1(t0)
+      cmp    0,0,t1,t2  <>  if
+         next
+      then
+      addic.  tos,tos,-1
+   0= until
+c;
+
+\ Skip initial occurrences of wvalue, returning the residual length
+code wskip  ( adr len wvalue -- residue )
+   mr    t1,tos        \ t1:bvalue
+   lwz   tos,0(sp)     \ tos:len
+   lwz   t0,1cell(sp)  \ t0:adr
+   addi  sp,sp,2cells  \ Move stack pointer by two
+
+   cmpi  0,0,tos,0  0=  if  \ Bail out if len=0
+      next
+   then
+
+   addi  t0,t0,-2      \ Account for pre-incrementing
+   begin
+      lhzu   t2,2(t0)
+      cmp    0,0,t1,t2  <>  if
+         next
+      then
+      addic.  tos,tos,-2
+   0= until
+c;
+
+\ Skip initial occurrences of bvalue, returning the residual length
+code lskip  ( adr len lvalue -- residue )
+   mr    t1,tos        \ t1:bvalue
+   lwz   tos,0(sp)     \ tos:len
+   lwz   t0,1cell(sp)  \ t0:adr
+   addi  sp,sp,2cells  \ Move stack pointer by two
+
+   cmpi  0,0,tos,0  0=  if  \ Bail out if len=0
+      next
+   then
+
+   addi  t0,t0,-4      \ Account for pre-incrementing
+   begin
+      lwzu   t2,4(t0)
+      cmp    0,0,t1,t2  <>  if
+         next
+      then
+      addic.  tos,tos,-4
+   0= until
+c;
+
 code noop (s -- )  c;
 
 code lowbyte   (s n -- low )   andi. tos,tos,h#ff  c;

Modified: cpu/ppc/ppcsim/ppcsim.c
==============================================================================
--- cpu/ppc/ppcsim/ppcsim.c	Sat Jan 11 07:24:15 2014	(r3707)
+++ cpu/ppc/ppcsim/ppcsim.c	Sun Jan 19 02:21:01 2014	(r3708)
@@ -1805,19 +1805,19 @@
 power:
 		if (!TBAR)
 		    printf("Unimplemented POWER instruction %08lx (%s) at %lx\n",
-		           (long)instruction, (long)opname, (long)CIA);
+		           (long)instruction, opname, (long)CIA);
 		goto trapout;
 
 unimplemented:
 		if (!TBAR)
 		    printf("Unimplemented instruction %08lx (%s)at %lx\n",
-		           (long)instruction, (long)opname, (long)CIA);
+		           (long)instruction, opname, (long)CIA);
 		goto trapout;
 
 illegal:
 		if (!TBAR)
 		    printf("Illegal instruction %08lx at %lx\n",
-			   (long)instruction, (long)CIA, (long)0);
+			   (long)instruction, (long)CIA);
 
 trapout:
 		if (TBAR) {
@@ -1875,7 +1875,7 @@
 	 "      r0         r1         r2         r3         r4         r5\n"
 	);
 	printf(
-	 "%8x   %8x   %8x   %8x   %8x   %8x\n\n",
+	 "%8lx   %8lx   %8lx   %8lx   %8lx   %8lx\n\n",
 	 greg[ 0],  greg[ 1],   greg[ 2],  greg[ 3],  greg[ 4],  greg[ 5]
 	);
 
@@ -1883,7 +1883,7 @@
 	 "      r6         r7         r8         r9         r10        r11\n"
 	);
 	printf(
-	 "%8x   %8x   %8x   %8x   %8x   %8x\n\n",
+	 "%8lx   %8lx   %8lx   %8lx   %8lx   %8lx\n\n",
 	 greg[ 6],  greg[ 7],   greg[ 8],  greg[ 9],  greg[10],  greg[11]
 	);
 #endif
@@ -1891,24 +1891,24 @@
 	 " r20  t0    r21  t1    r22  t2    r23  t3    r24  t4    r25  t5\n"
 	);
 	printf(
-	 "%8x   %8x   %8x   %8x   %8x   %8x\n\n",
+	 "%8lx   %8lx   %8lx   %8lx   %8lx   %8lx\n\n",
 	 greg[20],  greg[21],   greg[22],  greg[23],  greg[24],  greg[25]
 	);
 	printf(
 	 " r26 base   r27  up    r28 tos    r29  ip    r30  rp    r31  sp\n"
 	);
 	printf(
-	 "%8x   %8x   %8x   %8x   %8x   %8x\n\n",
+	 "%8lx   %8lx   %8lx   %8lx   %8lx   %8lx\n\n",
 	 greg[26],  greg[27],   greg[28],  greg[29],  greg[30],  greg[31]
 	);
-	printf("pc %x  LR %x  CTR %x  CR %x",
-		pc,    LR,    CTR,    CR.all
+	printf("pc %lx  LR %lx  CTR %lx  CR %lx",
+		pc,     LR,     CTR,     CR.all
 	);
 #ifndef SIMROM
-	printf("  CALLS: %x", greg[29]	/* IP */);
+	printf("  CALLS: %lx", greg[29]	/* IP */);
 
 	if (greg[30])
-		printf(" %x %x %x",
+		printf(" %lx %lx %lx",
 		 ((u_long *)greg[30])[0],	/* Return stack */
 		 ((u_long *)greg[30])[1],
 		 ((u_long *)greg[30])[2]
@@ -1919,13 +1919,13 @@
 dumpallregs()
 {
         int i;
-	for (i=0; i<8 ; i++)  printf("%9x", greg[i]);  putchar('\n');
-	for (   ; i<16; i++)  printf("%9x", greg[i]);  putchar('\n');
-	for (   ; i<24; i++)  printf("%9x", greg[i]);  putchar('\n');
-	for (   ; i<32; i++)  printf("%9x", greg[i]);  putchar('\n');
+	for (i=0; i<8 ; i++)  printf("%9lx", greg[i]);  putchar('\n');
+	for (   ; i<16; i++)  printf("%9lx", greg[i]);  putchar('\n');
+	for (   ; i<24; i++)  printf("%9lx", greg[i]);  putchar('\n');
+	for (   ; i<32; i++)  printf("%9lx", greg[i]);  putchar('\n');
 
-	printf("pc %x  LR %x  CTR %x  CR %x  ",
-		pc,    LR,    CTR,    CR.all
+	printf("pc %lx  LR %lx  CTR %lx  CR %lx  ",
+		pc,     LR,     CTR,     CR.all
 	);
 	printf("\n");
 }
@@ -1956,7 +1956,7 @@
 	u_long *reladr;
 
 	reladr = (u_long *) &xmem[ (int)adr ];
-	printf("%x: %8x %8x %8x %8x %8x %8x %8x %8x\n",
+	printf("%lx: %8lx %8lx %8lx %8lx %8lx %8lx %8lx %8lx\n",
 		adr,
 		reladr[0], reladr[1], reladr[2], reladr[3],
 		reladr[4], reladr[5], reladr[6], reladr[7]
@@ -1983,7 +1983,7 @@
 	IABR = 0;
 	stepping = 1;
 
-	printf("%x %x %s ", pc, greg[29], name);
+	printf("%lx %lx %s ", pc, greg[29], name);
 	for (done=0; !done; ) {
 		printf(" : ");
 #ifndef SIMROM
@@ -1994,13 +1994,14 @@
 #endif
 		switch(c)
 		{
-			case 'b':  scanf("%x", &IABR); stepping = 0; break;
+			int res;
+			case 'b':  res = scanf("%lx", &IABR); stepping = 0; break;
 			case 'n':  IABR = greg[27]; stepping = 0; break;
-			case 'u':  scanf("%x", &arg);
+			case 'u':  res = scanf("%x", &arg);
 				   dumpmem((long)(greg[27]+arg));
 				   GETLINE;
 				   break;
-			case 'm':  scanf("%x", &arg);
+			case 'm':  res = scanf("%x", &arg);
 				   dumpmem((long)arg);
 				   GETLINE;
 				   break;

Modified: cpu/x86/Linux/Makefile
==============================================================================
--- cpu/x86/Linux/Makefile	Sat Jan 11 07:24:15 2014	(r3707)
+++ cpu/x86/Linux/Makefile	Sun Jan 19 02:21:01 2014	(r3708)
@@ -44,7 +44,7 @@
 	@ln -sf forth x86forth
 
 xinflate.lo: ${ZIPDIR}/inflate.c
-	${CC} -c ${MFLAGS} -Wall -fno-stack-protector -ffreestanding -D_FORTIFY_SOURCE=0 -DNEED_BCOPY -O3 -fpic $< -o $@
+	${CC} -c ${MFLAGS} -Wall -fno-builtin -fno-stack-protector -ffreestanding -DNEED_BCOPY -O2 -fpic $< -o $@
 
 xinflate.o: xinflate.lo
 	${LD} -melf_i386 -T inflate.ld $< -o $@

Modified: cpu/x86/Linux/Makefile.ppcforth
==============================================================================
--- cpu/x86/Linux/Makefile.ppcforth	Sat Jan 11 07:24:15 2014	(r3707)
+++ cpu/x86/Linux/Makefile.ppcforth	Sun Jan 19 02:21:01 2014	(r3708)
@@ -5,6 +5,8 @@
 BP=../../..
 
 CFLAGS = -DPPCSIM -DTARGET_POWERPC
+CFLAGS += -m32
+LFLAGS += -m32
 
 CC = gcc
 

Modified: forth/wrapper/logger.c
==============================================================================
--- forth/wrapper/logger.c	Sat Jan 11 07:24:15 2014	(r3707)
+++ forth/wrapper/logger.c	Sun Jan 19 02:21:01 2014	(r3708)
@@ -241,6 +241,7 @@
 void log_command_line(int argc, char *argv[])
 {
     int i;
+    char *pret;
     char cwdbuf[MAXPATHLEN*2];
 
 #ifdef __unix__
@@ -278,7 +279,7 @@
     sprintf(info, "host: %s\n", hostname);
     record(&misc);
 
-    getcwd(cwdbuf, 128);
+    pret = getcwd(cwdbuf, 128);
     sprintf(info, "cwd: %s\n", cwdbuf);
     record(&misc);
 }

Modified: forth/wrapper/wrapper.c
==============================================================================
--- forth/wrapper/wrapper.c	Sat Jan 11 07:24:15 2014	(r3707)
+++ forth/wrapper/wrapper.c	Sun Jan 19 02:21:01 2014	(r3708)
@@ -326,10 +326,6 @@
 extern void log_command_line(int, char **);
 extern void log_env(char *, char *);
 
-#if !defined(LinuxPOWERPC) && !defined(__APPLE__)
-  extern int	read(), write();
-#endif
-
 INTERNAL char *	substr();
 INTERNAL long	path_open();
 INTERNAL void	keymode();
@@ -348,7 +344,11 @@
   long c_key();
   long s_bye();
   void restoremode();
+#ifdef PPCSIM
+  void simulate(char *, char *, char *, long (**)(), char *, int, char **, int);
+#else
   void simulate(char *, char *, char *, long (**)(), char *, int, char **);
+#endif
   long find(long, int, long, char *);
 #else
   INTERNAL long	c_key();
@@ -710,12 +710,14 @@
 void
 set_bp(void)
 {
+	char *pret;
+	int ret;
 	char here[MAXPATHLEN];
-	getcwd(here, MAXPATHLEN);
-	getcwd(bpval, MAXPATHLEN);
+	pret = getcwd(here, MAXPATHLEN);
+	pret = getcwd(bpval, MAXPATHLEN);
 	while (1) {
 		if (access(host_cpu, F_OK) == 0) {
-			getcwd(hostdirval, MAXPATHLEN);
+			pret = getcwd(hostdirval, MAXPATHLEN);
 			strcat(hostdirval, "/");
 			strcat(hostdirval, host_cpu);
 			strcat(hostdirval, "/");
@@ -723,14 +725,14 @@
 		}
 		if (access("ofw", F_OK) == 0)
 			break;
-		chdir("..");
-		getcwd(bpval, MAXPATHLEN);
+		ret = chdir("..");
+		pret = getcwd(bpval, MAXPATHLEN);
 		if (strcmp(bpval, "/") == 0) {
 			bpval[0] = '\0';
 			break;
 		}
 	}
-	chdir(here);
+	ret = chdir(here);
 }
 
 struct woptions {  char *dashopt; char *forthopt; } woptions[] =
@@ -1112,6 +1114,7 @@
 #endif
 
 #ifdef TARGET_POWERPC
+#ifndef PPCSIM
 # ifdef NOGLUE
 	{ long toc_entry[2]; int c;
 		toc_entry[1] = 0;
@@ -1127,6 +1130,7 @@
 	s_bye(0L);
 # endif
 #endif
+#endif
 
 #ifdef __APPLE_CC__
 	{
@@ -1694,16 +1698,16 @@
 INTERNAL long
 c_expect(long max, char *buffer)
 {
-	int c = 0;
+	int c = 0, ret;
 	register char *p = buffer;
 
 	linemode();
 
 	fflush(stdout);
-	read(0, &c, 1);
+	ret = read(0, &c, 1);
 	while (max--  &&  c != '\n'  &&  c != EOF ) {
 		*p++ = c;
-		read(0, &c, 1);
+		ret = read(0, &c, 1);
 	}
 	keymode();
 	return ( (long)(p - buffer) );
@@ -1756,9 +1760,10 @@
 void
 error(char *str1, char *str2)
 {
-	write(2,str1,strlen(str1));
-	write(2,str2,strlen(str2));
-	write(2,"\n",1);
+	int ret;
+	ret = write(2,str1,strlen(str1));
+	ret = write(2,str2,strlen(str2));
+	ret = write(2,"\n",1);
 }
 
 
@@ -1791,11 +1796,11 @@
 
 char output_filename[MAXPATHLEN];
 #ifdef USE_STDIO
-#define NONE -1
-int output_fd = NONE;
+  #define NONE (FILE *)0
+  FILE *output_fd = NONE;
 #else
-#define NONE (FILE *)0
-FILE *output_fd = NONE;
+  #define NONE -1
+  int output_fd = NONE;
 #endif
 
 #ifdef USE_STDIO
@@ -1849,7 +1854,7 @@
 	if (result != -1) {
 		strcpy(output_filename, name);
 		output_fd = result;
-	}		
+	}
 #else
 #ifdef __unix__
 	result = open(expand_name(name), O_RDWR|O_CREAT|O_TRUNC, (int)mode);
@@ -1858,8 +1863,8 @@
 #endif
 	if (result != -1) {
 		strcpy(output_filename, name);
-		output_fd = (FILE *)result;
-	}		
+		output_fd = result;
+	}
 #endif
 	return((long)result);
 }



More information about the openfirmware mailing list