public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] RISC-V: Add gdb sim and newlib nano support. Fix a few misc minor bugs.
@ 2017-12-26 20:32 Jim Wilson
  0 siblings, 0 replies; only message in thread
From: Jim Wilson @ 2017-12-26 20:32 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9588ff7555057ea1f62fda35e60428b5fa2ce943

commit 9588ff7555057ea1f62fda35e60428b5fa2ce943
Author: Jim Wilson <jimw@sifive.com>
Date:   Tue Dec 26 12:30:27 2017 -0800

    RISC-V: Add gdb sim and newlib nano support.  Fix a few misc minor bugs.

Diff:
---
 libgloss/riscv/Makefile.in | 55 +++++++++++++++++++++++++++++++++++++++++-----
 libgloss/riscv/nano.specs  | 23 +++++++++++++++++++
 libgloss/riscv/sim.specs   | 10 +++++++++
 libgloss/riscv/sys_sbrk.c  | 29 ++++++++++++++++++++++++
 4 files changed, 111 insertions(+), 6 deletions(-)

diff --git a/libgloss/riscv/Makefile.in b/libgloss/riscv/Makefile.in
index 5035759..579dd95 100644
--- a/libgloss/riscv/Makefile.in
+++ b/libgloss/riscv/Makefile.in
@@ -40,6 +40,9 @@ gloss_srcs = \
 	sys_wait.c \
 	sys_write.c 
 
+gloss_specs = \
+	nano.specs sim.specs
+
 # Extra files
 
 crt0_asm      = crt0.S
@@ -117,10 +120,20 @@ gloss_c_deps = $(patsubst %.c, %.d, $(notdir $(gloss_c_srcs)))
 $(gloss_c_objs) : %.o : %.c
 	$(COMPILE) -c $<
 
-objs += $(gloss_c_objs)
+gloss_objs += $(gloss_c_objs)
 deps += $(gloss_c_deps)
 junk += $(gloss_c_deps) $(gloss_c_objs)
 
+sim_c_objs = $(patsubst %.c, sim-%.o, $(notdir $(gloss_c_srcs)))
+sim_c_deps = $(patsubst %.c, sim-%.d, $(notdir $(gloss_c_srcs)))
+
+$(sim_c_objs): sim-%.o : %.c
+	$(COMPILE) -c -DUSING_SIM_SPECS -o $@ $<
+
+sim_objs += $(sim_c_objs)
+deps += $(sim_c_deps)
+junk += $(sim_c_deps) $(sim_c_objs)
+
 #-------------------------------------------------------------------------
 # Build Object Files from Assembly Source
 #-------------------------------------------------------------------------
@@ -130,25 +143,49 @@ gloss_asm_objs = $(patsubst %.S, %.o, $(notdir $(gloss_asm_srcs)))
 gloss_asm_deps = $(patsubst %.S, %.d, $(notdir $(gloss_asm_srcs)))
 
 $(gloss_asm_objs) : %.o : %.S
-	$(COMPILE) -c $<
+	$(COMPILE) -c -o $@ $<
 
-objs += $(gloss_asm_objs)
+gloss_objs += $(gloss_asm_objs)
 deps += $(gloss_asm_deps)
 junk += $(gloss_asm_deps) $(gloss_asm_objs)
 
+sim_asm_objs = $(patsubst %.S, sim-%.o, $(notdir $(gloss_asm_srcs)))
+sim_asm_deps = $(patsubst %.S, sim-%.d, $(notdir $(gloss_asm_srcs)))
+
+$(sim_asm_objs) : sim-%.o : %.S
+	$(COMPILE) -c -DUSING_SIM_SPECS -o $@ $<
+
+sim_objs += $(sim_asm_objs)
+deps += $(sim_asm_deps)
+junk += $(sim_asm_deps) $(sim_asm_objs)
+
 #-------------------------------------------------------------------------
 # Build libgloss.a
 #-------------------------------------------------------------------------
 
 gloss_lib  = libgloss.a
-$(gloss_lib) : $(objs)
+$(gloss_lib) : $(gloss_objs)
 	$(AR) rcv $@ $^
 	$(RANLIB) $@
 
-junk += $(gloss_libs)
+junk += $(gloss_lib)
 
 install_hdrs += $(gloss_hdrs)
 install_libs += $(gloss_lib)
+install_specs += $(gloss_specs)
+
+#-------------------------------------------------------------------------
+# Build libsim.a
+#-------------------------------------------------------------------------
+
+sim_lib  = libsim.a
+$(sim_lib) : $(sim_objs)
+	$(AR) rcv $@ $^
+	$(RANLIB) $@
+
+junk += $(sim_lib)
+
+install_libs += $(sim_lib)
 
 #-------------------------------------------------------------------------
 # Build crt0.o
@@ -191,7 +228,13 @@ install-libs : $(install_libs)
 		$(INSTALL_DATA) $$file $(install_libs_dir)/$$file; \
 	done
 
-install : install-hdrs install-libs 
+install-specs : $(install_specs)
+	test -d $(install_libs_dir) || mkdir -p $(install_libs_dir)
+	for file in $^; do \
+		$(INSTALL_DATA) $$file $(install_libs_dir)/; \
+	done
+
+install : install-hdrs install-libs install-specs
 .PHONY : install install-hdrs install-libs
 
 #-------------------------------------------------------------------------
diff --git a/libgloss/riscv/nano.specs b/libgloss/riscv/nano.specs
new file mode 100644
index 0000000..89fd231
--- /dev/null
+++ b/libgloss/riscv/nano.specs
@@ -0,0 +1,23 @@
+%rename link                nano_link
+%rename link_gcc_c_sequence                nano_link_gcc_c_sequence
+%rename cpp		nano_cpp
+
+*cpp:
+-isystem =/include/newlib-nano %(nano_cpp)
+
+*nano_libc:
+-lc_nano
+
+*nano_libgloss:
+%{specs=nosys.specs:-lnosys} %{!specs=nosys.specs:-lgloss_nano}
+
+*link_gcc_c_sequence:
+%(nano_link_gcc_c_sequence) --start-group %G %(nano_libc) %(nano_libgloss) --end-group
+
+*link:
+%(nano_link) %:replace-outfile(-lc -lc_nano) %:replace-outfile(-lg -lg_nano)
+
+*lib:
+%{!shared:%{g*:-lg_nano} %{!p:%{!pg:-lc_nano}}%{p:-lc_p}%{pg:-lc_p}}
+
+# ??? Maybe put --gc-sections option in here?
diff --git a/libgloss/riscv/sim.specs b/libgloss/riscv/sim.specs
new file mode 100644
index 0000000..31fde69
--- /dev/null
+++ b/libgloss/riscv/sim.specs
@@ -0,0 +1,10 @@
+# Spec file for gdb simulator.
+
+%rename lib	sim_lib
+%rename link	sim_link
+
+*lib:
+--start-group -lc -lsim --end-group
+
+*link:
+%(sim_link) %:replace-outfile(-lgloss -lsim)
diff --git a/libgloss/riscv/sys_sbrk.c b/libgloss/riscv/sys_sbrk.c
index 036b897..19802fb 100644
--- a/libgloss/riscv/sys_sbrk.c
+++ b/libgloss/riscv/sys_sbrk.c
@@ -1,3 +1,31 @@
+#ifdef USING_SIM_SPECS
+
+// Gdb simulator requires that sbrk be implemented without a syscall.
+extern char _end[];                /* _end is set in the linker command file */
+char *heap_ptr;
+
+/*
+ * sbrk -- changes heap size size. Get nbytes more
+ *         RAM. We just increment a pointer in what's
+ *         left of memory on the board.
+ */
+char *
+_sbrk (nbytes)
+     int nbytes;
+{
+  char        *base;
+
+  if (!heap_ptr)
+    heap_ptr = (char *)&_end;
+  base = heap_ptr;
+  heap_ptr += nbytes;
+
+  return base;
+}
+
+#else
+
+// QEMU uses a syscall.
 #include <machine/syscall.h>
 #include <sys/types.h>
 #include "internal_syscall.h"
@@ -25,3 +53,4 @@ _sbrk(ptrdiff_t incr)
   heap_end += incr;
   return (void *)(heap_end - incr);
 }
+#endif


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-12-26 20:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-26 20:32 [newlib-cygwin] RISC-V: Add gdb sim and newlib nano support. Fix a few misc minor bugs Jim Wilson

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).