Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Wilson <jimw@sifive.com>2017-12-26 23:30:27 +0300
committerJim Wilson <jimw@sifive.com>2017-12-26 23:31:33 +0300
commit9588ff7555057ea1f62fda35e60428b5fa2ce943 (patch)
treecbef39020bb978b75eaf518df68a7e7cf537e5be /libgloss/riscv
parent28d5b98038dd18797375f4ff6a11fecd59809b22 (diff)
RISC-V: Add gdb sim and newlib nano support. Fix a few misc minor bugs.
Diffstat (limited to 'libgloss/riscv')
-rw-r--r--libgloss/riscv/Makefile.in55
-rw-r--r--libgloss/riscv/nano.specs23
-rw-r--r--libgloss/riscv/sim.specs10
-rw-r--r--libgloss/riscv/sys_sbrk.c29
4 files changed, 111 insertions, 6 deletions
diff --git a/libgloss/riscv/Makefile.in b/libgloss/riscv/Makefile.in
index 503575975..579dd9554 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 000000000..89fd23176
--- /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 000000000..31fde6906
--- /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 036b897f4..19802fb7b 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