public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libgloss: Resolve compilation errors for mips.
@ 2024-01-04 13:59 Roger Sayle
  2024-01-04 23:54 ` Mike Frysinger
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2024-01-04 13:59 UTC (permalink / raw)
  To: newlib; +Cc: 'Jeff Law'

[-- Attachment #1: Type: text/plain, Size: 766 bytes --]


This patch fixes some compilation issues in libgloss when
building a cross-compiler for mips.  This mostly requires new
function prototypes, similar to the changes recently made
by Jeff Law for other targets.

2024-01-04  Roger Sayle  <roger@nextmovesoftware.com>

libgloss/ChangeLog
	* kill.c: Prototype _exit.
	* mips/cfe_mem.c (__libcfe_meminit): Add casts to avoid compilation
	warnings/errors.
	* mips/cma101.c: Prototype __cpu_timer_poll and __cpu_flush.
	* mips/syscalls.c: Prototype get_mem_info.
	(sbrk): Add casts to avoid compilation warnings/errors.
	* mips/test.c: Prototype outbyte and print. Fix return type of main.
	* print.c: Prototype outbyte.  Make ptr argument const char*.
	* putnum.c: Update prototype of print to const char*.

Ok?
Roger
--


[-- Attachment #2: libgloss.patch --]
[-- Type: application/octet-stream, Size: 3829 bytes --]

diff --git a/libgloss/kill.c b/libgloss/kill.c
index a0eaee75b..a53ba331a 100644
--- a/libgloss/kill.c
+++ b/libgloss/kill.c
@@ -14,6 +14,8 @@
  */
 #include "glue.h"
 
+extern void _exit (int);
+
 /*
  * kill -- go out via exit...
  */
diff --git a/libgloss/mips/cfe_mem.c b/libgloss/mips/cfe_mem.c
index 87caabf8c..41b871eef 100644
--- a/libgloss/mips/cfe_mem.c
+++ b/libgloss/mips/cfe_mem.c
@@ -58,7 +58,7 @@ __libcfe_meminit (void)
   /* If the user has provided a memory-limit function, use it to
      determine the end of usable memory.  */
   if (&__libcfe_mem_limit != NULL)
-    memtop = __libcfe_mem_limit ();
+    memtop = (unsigned long)__libcfe_mem_limit ();
   else
     {
       uint64_t start, length, type;
@@ -80,7 +80,7 @@ __libcfe_meminit (void)
             {
               /* Did not find an available entry containing _end.
                  Assume a minimal amount of memory (1MB).  */
-              memtop = _end + (1 * 1024 * 1024);
+              memtop = (unsigned int)(_end + (1 * 1024 * 1024));
               break;
             }
 
diff --git a/libgloss/mips/cma101.c b/libgloss/mips/cma101.c
index e8f381864..ba58b1d5f 100644
--- a/libgloss/mips/cma101.c
+++ b/libgloss/mips/cma101.c
@@ -133,6 +133,7 @@ set_pclock (void)
   return;
 }
 
+extern void __cpu_timer_poll (int);
 #define PCLOCK_WAIT(x)  __cpu_timer_poll((x) * pclock)
 
 /* NOTE: On the Cogent CMA101 board the LCD controller will sometimes
@@ -178,6 +179,7 @@ lcd_display (int line, const char *msg)
 extern unsigned int __buserr_count(void);
 extern void __default_buserr_handler(void);
 extern void __restore_buserr_handler(void);
+extern void __cpu_flush(void);
 
 /* Allow the user to provide his/her own defaults.  */
 unsigned int __sizemem_default;
diff --git a/libgloss/mips/syscalls.c b/libgloss/mips/syscalls.c
index 3ab543674..4661b97be 100644
--- a/libgloss/mips/syscalls.c
+++ b/libgloss/mips/syscalls.c
@@ -5,6 +5,7 @@
 #include "regs.S"
 
 extern char _end[];
+extern void *get_mem_info (void*);
 
 /* FIXME: This is not ideal, since we do a get_mem_info() call for
    every sbrk() call. */
@@ -31,8 +32,8 @@ sbrk (nbytes)
   /* NOTE: The value returned from the get_mem_info call is the amount
      of memory, and not the address of the (last byte + 1) */
 
-  if (((size_t)heap_ptr >= heap_start) && ((size_t)heap_ptr < (heap_start + mem.size))) {
-    avail = (heap_start + mem.size) - (size_t)heap_ptr;
+  if ((heap_ptr >= heap_start) && (heap_ptr < (heap_start + mem.size))) {
+    avail = (unsigned int)((heap_start + mem.size) - heap_ptr);
     base = heap_ptr;
   } /* else will fail since "nbytes" will be greater than zeroed "avail" value */
 
diff --git a/libgloss/mips/test.c b/libgloss/mips/test.c
index a99347914..b580ea933 100644
--- a/libgloss/mips/test.c
+++ b/libgloss/mips/test.c
@@ -1,4 +1,7 @@
-main()
+extern int outbyte(unsigned char byte);
+extern void print (const char *);
+
+int main()
 {
   outbyte ('&');
   outbyte ('@');
@@ -9,5 +12,5 @@ main()
   
   print ("\r\nDone...");
 
-  return;
+  return 0;
 }
diff --git a/libgloss/print.c b/libgloss/print.c
index 76d543b67..3b7f91606 100644
--- a/libgloss/print.c
+++ b/libgloss/print.c
@@ -14,11 +14,13 @@
  */
 #include "glue.h"
 
+extern int outbyte (char x);
+
 /*
  * print -- do a raw print of a string
  */ 
 void
-print (char *ptr)
+print (const char *ptr)
 {
   while (*ptr) {
     outbyte (*ptr++);
diff --git a/libgloss/putnum.c b/libgloss/putnum.c
index 6e1051e24..1720098bd 100644
--- a/libgloss/putnum.c
+++ b/libgloss/putnum.c
@@ -14,7 +14,7 @@
  */
 #include "glue.h"
 
-extern void print (char *ptr);
+extern void print (const char *ptr);
 
 /*
  * putnum -- print a 32 bit number in hex

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libgloss: Resolve compilation errors for mips.
  2024-01-04 13:59 [PATCH] libgloss: Resolve compilation errors for mips Roger Sayle
@ 2024-01-04 23:54 ` Mike Frysinger
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2024-01-04 23:54 UTC (permalink / raw)
  To: Roger Sayle; +Cc: newlib, 'Jeff Law'

[-- Attachment #1: Type: text/plain, Size: 1740 bytes --]

On 04 Jan 2024 13:59, Roger Sayle wrote:
> --- a/libgloss/kill.c
> +++ b/libgloss/kill.c
>
> +extern void _exit (int);

missing noreturn markings.  can this file include stdlib.h instead ?

> --- a/libgloss/mips/cfe_mem.c
> +++ b/libgloss/mips/cfe_mem.c
>
> -    memtop = __libcfe_mem_limit ();
> +    memtop = (unsigned long)__libcfe_mem_limit ();

if memtop is supposed to be a pointer, then it should be a pointer, not an
integer.

ignoring that, never use long or int to cast pointers.  this is what
uintptr_t is designed for.

> --- a/libgloss/mips/syscalls.c
> +++ b/libgloss/mips/syscalls.c
>
>  extern char _end[];
> +extern void *get_mem_info (void*);

seems like mips should have a header for its prototypes rather than duplicating
it across multiple files, and so it makes sure it's defined correctly both in
the callers & definitions.  seems like get_mem_info takes a struct pointer, not
a void.

> -  if (((size_t)heap_ptr >= heap_start) && ((size_t)heap_ptr < (heap_start + mem.size))) {
> -    avail = (heap_start + mem.size) - (size_t)heap_ptr;
> +  if ((heap_ptr >= heap_start) && (heap_ptr < (heap_start + mem.size))) {
> +    avail = (unsigned int)((heap_start + mem.size) - heap_ptr);

use ptrdiff_t to hold the difference between pointers, don't cast like this.

> --- a/libgloss/print.c
> +++ b/libgloss/print.c
>
>  #include "glue.h"
>
> +extern int outbyte (char x);

outbyte is already defined in glue.h which is included here

> --- a/libgloss/putnum.c
> +++ b/libgloss/putnum.c
> @@ -14,7 +14,7 @@
>   */
>  #include "glue.h"
>  
> -extern void print (char *ptr);
> +extern void print (const char *ptr);

this prob should be moved to glue.h instead
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-04 23:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04 13:59 [PATCH] libgloss: Resolve compilation errors for mips Roger Sayle
2024-01-04 23:54 ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).