This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 6/6] RISC-V: Rewrite gdb sim support to work with split syscalls.c file.


From 13a004fbf047a2e4d2e5a9c1b3dde41c2781f0f0 Mon Sep 17 00:00:00 2001
From: Jim Wilson <jimw@sifive.com>
Date: Tue, 14 Nov 2017 11:11:56 -0800
Subject: [PATCH 6/6] RISC-V: Rewrite gdb sim support to work with split
 syscalls.c file.

---
 libgloss/riscv/Makefile.in | 35 +++++++++++++++++++++++------------
 libgloss/riscv/sim.specs   |  2 ++
 libgloss/riscv/sys_sbrk.c  | 29 +++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/libgloss/riscv/Makefile.in b/libgloss/riscv/Makefile.in
index 175a8d4..579dd95 100644
--- a/libgloss/riscv/Makefile.in
+++ b/libgloss/riscv/Makefile.in
@@ -124,6 +124,16 @@ 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
 #-------------------------------------------------------------------------
@@ -133,12 +143,22 @@ 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 $@ $<
 
 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
 #-------------------------------------------------------------------------
@@ -158,21 +178,12 @@ install_specs += $(gloss_specs)
 # Build libsim.a
 #-------------------------------------------------------------------------
 
-sbrk.o: $(src_dir)/../sbrk.c
-	$(COMPILE) -c $<
-sim-syscalls.o: syscalls.c
-	$(COMPILE) -c -DUSING_SIM_SPECS -o $@ $<
-
-sim_c_objs = sbrk.o sim-syscalls.o
-sim_c_deps = $(patsubst %.o, %.d, $(notdir $(sim_c_objs)))
-
 sim_lib  = libsim.a
-$(sim_lib) : $(sim_c_objs)
+$(sim_lib) : $(sim_objs)
 	$(AR) rcv $@ $^
 	$(RANLIB) $@
 
-deps += $(sim_c_deps)
-junk += $(sim_lib) $(sim_c_objs) $(sim_c_deps)
+junk += $(sim_lib)
 
 install_libs += $(sim_lib)
 
diff --git a/libgloss/riscv/sim.specs b/libgloss/riscv/sim.specs
index fe1f149..31fde69 100644
--- a/libgloss/riscv/sim.specs
+++ b/libgloss/riscv/sim.specs
@@ -1,3 +1,5 @@
+# Spec file for gdb simulator.
+
 %rename lib	sim_lib
 %rename link	sim_link
 
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
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]