From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BC01C3857721 for ; Thu, 10 Aug 2023 17:45:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC01C3857721 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691689529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=G+g6ZWs7iOUKowFTDYlwbdjA8d5ukQdfeBGsBpXG3Qk=; b=L/s3ztbJEQIQNNa6q2EFh7c1IN6Dcf6OC69s9sEcPOSjCm0M+fSAME9jko7EQsrvdDYErL b+iY1RXmNb/f3qlEJUlfgJgV4JE+aL/CMNKBllYjnmxBr630vVoBiEL/X9t679ze/sx7ha yzk3BAjk3WuZisZ/LH3uqLZXa2NK2N0= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-HrsV9KRmNqiYqBkGobOu9g-1; Thu, 10 Aug 2023 13:45:25 -0400 X-MC-Unique: HrsV9KRmNqiYqBkGobOu9g-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-4fe6b399119so178744e87.1 for ; Thu, 10 Aug 2023 10:45:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691689523; x=1692294323; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=G+g6ZWs7iOUKowFTDYlwbdjA8d5ukQdfeBGsBpXG3Qk=; b=Pf3mJYUkG2N7hrJWXiMv2cZ5Bk900zRPDAMWWNXyCzL0t6fCebSZUBhU8uIJ9Lq5a6 UNh0OZ6r1xquEZhRCW7xFwuDRG3K8sYffiq8QbVvvzec+9hvGvU8kOjPg2/L3vUe+7HO 6zlYjoHPxTcix8+lTS9Ck73F65lnXlRufFI/+mZGGrGJhiQ2ipr1yTrta49QUmF7ASLo uTdeGKPT1GhLRq5YPzK09stDaFlYJ/30ksVyiEUP3sHLTqXYYIWggIyHZE6Lt5tesvTx LWeEHL2zUO1vJht93crOYVwTnrIJ5DTYysl8LogxOhnPP92M9sG2c3QNWZJsq7ssse67 0Qnw== X-Gm-Message-State: AOJu0YwmucNJE6NJyLtYvt28z3eJH19owpLsEzWAkrYe9UE9oJnfG8fH Sm7nJDYZB//l6Ahs4uR+OZSCRnOGOKwic7Kq3wBZgip4pZ13xi6yeYFgEAPDBMHzwDvXTLaf97s zUBvE6RKULY3q+nIn53VK9EMp8W9EPOuk8kDc5zL0kw== X-Received: by 2002:a05:6512:518:b0:4fb:e790:2d56 with SMTP id o24-20020a056512051800b004fbe7902d56mr2003379lfb.6.1691689523066; Thu, 10 Aug 2023 10:45:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvEtdWVSfUFSso8VcAYbdCswt01DNOJIn+eLiiKzYVwq2j5R1ab1IAJXIXO2NG6z49TFOb4aoMBCTrQtE6G4w= X-Received: by 2002:a05:6512:518:b0:4fb:e790:2d56 with SMTP id o24-20020a056512051800b004fbe7902d56mr2003363lfb.6.1691689522351; Thu, 10 Aug 2023 10:45:22 -0700 (PDT) MIME-Version: 1.0 References: <20230809222131.29475-1-petrisko@cs.washington.edu> <20230809222131.29475-2-petrisko@cs.washington.edu> In-Reply-To: <20230809222131.29475-2-petrisko@cs.washington.edu> From: Jeff Johnston Date: Thu, 10 Aug 2023 13:45:10 -0400 Message-ID: Subject: Re: [PATCH 1/2] Adding a LittleFS-based self-contained target to libgloss To: Dan Petrisko Cc: newlib@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="0000000000000cf187060295290e" X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000000cf187060295290e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Dan, Thanks for the updates. A few more comments. Your readme states that adding -dramfs to the end of a target will enable the support, but there is no logic yet added here to the top-level configure.ac to specify building in dramfs directory. Libgloss has recently been cleaned up to move all configuration into the top-level libgloss directory (none of the targets have their own configure.in/configure.ac). The way it is now, building libgloss/dramfs would have to be done manually in the dramfs directory. There is a comment mentioning risc-v and configure.ac in your configure.in file. Regards, -- Jeff J. On Wed, Aug 9, 2023 at 6:22=E2=80=AFPM Dan Petrisko wrote: > Co-authored-by: Bandhav Veluri > Co-authored-by: farzamgl > Co-authored-by: taylor-bsg > --- > .gitmodules | 0 > COPYING.LIBGLOSS | 27 +++++ > libgloss/dramfs/Makefile.in | 230 > +++++++++++++++++++++++++++++++++++++ > libgloss/dramfs/README.md | 158 +++++++++++++++++++++++++ > libgloss/dramfs/configure.in | 45 ++++++++ > libgloss/dramfs/crt0.S | 44 +++++++ > libgloss/dramfs/sys_close.c | 41 +++++++ > libgloss/dramfs/sys_execve.c | 40 +++++++ > libgloss/dramfs/sys_exit.c | 41 +++++++ > libgloss/dramfs/sys_fork.c | 39 +++++++ > libgloss/dramfs/sys_fstat.c | 48 ++++++++ > libgloss/dramfs/sys_getpid.c | 36 ++++++ > libgloss/dramfs/sys_gettimeofday.c | 40 +++++++ > libgloss/dramfs/sys_isatty.c | 36 ++++++ > libgloss/dramfs/sys_kill.c | 40 +++++++ > libgloss/dramfs/sys_link.c | 38 ++++++ > libgloss/dramfs/sys_lseek.c | 44 +++++++ > libgloss/dramfs/sys_open.c | 64 +++++++++++ > libgloss/dramfs/sys_read.c | 67 +++++++++++ > libgloss/dramfs/sys_sbrk.c | 49 ++++++++ > libgloss/dramfs/sys_stat.c | 50 ++++++++ > libgloss/dramfs/sys_times.c | 35 ++++++ > libgloss/dramfs/sys_unlink.c | 39 +++++++ > libgloss/dramfs/sys_wait.c | 39 +++++++ > libgloss/dramfs/sys_write.c | 52 +++++++++ > 25 files changed, 1342 insertions(+) > create mode 100644 .gitmodules > create mode 100644 libgloss/dramfs/Makefile.in > create mode 100644 libgloss/dramfs/README.md > create mode 100644 libgloss/dramfs/configure.in > create mode 100644 libgloss/dramfs/crt0.S > create mode 100644 libgloss/dramfs/sys_close.c > create mode 100644 libgloss/dramfs/sys_execve.c > create mode 100644 libgloss/dramfs/sys_exit.c > create mode 100644 libgloss/dramfs/sys_fork.c > create mode 100644 libgloss/dramfs/sys_fstat.c > create mode 100644 libgloss/dramfs/sys_getpid.c > create mode 100644 libgloss/dramfs/sys_gettimeofday.c > create mode 100644 libgloss/dramfs/sys_isatty.c > create mode 100644 libgloss/dramfs/sys_kill.c > create mode 100644 libgloss/dramfs/sys_link.c > create mode 100644 libgloss/dramfs/sys_lseek.c > create mode 100644 libgloss/dramfs/sys_open.c > create mode 100644 libgloss/dramfs/sys_read.c > create mode 100644 libgloss/dramfs/sys_sbrk.c > create mode 100644 libgloss/dramfs/sys_stat.c > create mode 100644 libgloss/dramfs/sys_times.c > create mode 100644 libgloss/dramfs/sys_unlink.c > create mode 100644 libgloss/dramfs/sys_wait.c > create mode 100644 libgloss/dramfs/sys_write.c > > diff --git a/.gitmodules b/.gitmodules > new file mode 100644 > index 000000000..e69de29bb > diff --git a/COPYING.LIBGLOSS b/COPYING.LIBGLOSS > index c7a4c2924..0b30092a2 100644 > --- a/COPYING.LIBGLOSS > +++ b/COPYING.LIBGLOSS > @@ -425,3 +425,30 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING > NEGLIGENCE OR OTHERWISE) > ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF T= HE > POSSIBILITY OF SUCH DAMAGE. > > +(21) - University of Washington (*-*-*-dramfs targets) > + > +Copyright (c) 2023, University of Washington > +All rights reserved. > + > +Redistribution and use in source and binary forms, with or without > +modification, are permitted provided that the following conditions are > met: > + * Redistributions of source code must retain the above copyright > + notice, this list of conditions and the following disclaimer. > + * Redistributions in binary form must reproduce the above copyright > + notice, this list of conditions and the following disclaimer in the > + documentation and/or other materials provided with the distributio= n. > + * Neither the name of the University of Washington nor the > + names of its contributors may be used to endorse or promote produc= ts > + derived from this software without specific prior written > permission. > + > +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS > IS" AND > +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > +DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY > +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAG= ES > +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED > AND > +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TO= RT > +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF > THIS > +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + > diff --git a/libgloss/dramfs/Makefile.in b/libgloss/dramfs/Makefile.in > new file mode 100644 > index 000000000..4d3d5013e > --- /dev/null > +++ b/libgloss/dramfs/Makefile.in > @@ -0,0 +1,230 @@ > +#-----------------------------------------------------------------------= -- > +# Source files > +#-----------------------------------------------------------------------= -- > +gloss_srcs =3D \ > + sys_close.c \ > + sys_execve.c \ > + sys_exit.c \ > + sys_fork.c \ > + sys_fstat.c \ > + sys_getpid.c \ > + sys_gettimeofday.c \ > + sys_isatty.c \ > + sys_kill.c \ > + sys_link.c \ > + sys_lseek.c \ > + sys_open.c \ > + sys_read.c \ > + sys_sbrk.c \ > + sys_stat.c \ > + sys_times.c \ > + sys_unlink.c \ > + sys_wait.c \ > + sys_write.c > + > +# Extra files > + > +crt0_asm =3D crt0.S > + > +# Multilib support variables. > +# TOP is used instead of MULTI{BUILD,SRC}TOP. > + > +MULTIDIRS =3D > +MULTISUBDIR =3D > +MULTIDO =3D true > +MULTICLEAN =3D true > + > +#-----------------------------------------------------------------------= -- > +# Basic setup > +#-----------------------------------------------------------------------= -- > + > +# Remove all default implicit rules since they can cause subtle bugs > +# and they just make things run slower > + > +.SUFFIXES: > +% : %,v > +% : RCS/%,v > +% : RCS/% > +% : s.% > +% : SCCS/s.% > + > +# Default is to build the prereqs of the all target (defined at bottom) > + > +default : all > +.PHONY : default > + > +# Source directory > + > +obj_dir :=3D . > +src_dir :=3D @srcdir@ > +VPATH :=3D $(src_dir) $(src_dir)/machine > + > +# Installation directories > + > +prefix :=3D @prefix@ > +DESTDIR ?=3D $(prefix) > + > +install_hdrs_dir :=3D $(DESTDIR)$(prefix)/$(target_alias)/include/machine > +install_libs_dir =3D $(DESTDIR)$(prefix)/$(target_alias)/lib${MULTISUBD= IR} > +install_bins_dir :=3D $(DESTDIR)$(prefix)/$(target_alias)/bin > + > +#-----------------------------------------------------------------------= -- > +# Programs and flags > +#-----------------------------------------------------------------------= -- > + > +# C compiler > + > +CC :=3D @CC@ > +CFLAGS :=3D @CFLAGS@ > +CFLAGS +=3D -mcmodel=3Dmedany > +CPPFLAGS :=3D -I$(obj_dir) -I$(src_dir) $(dramfs_incs) -mcmodel=3Dm= edany > +COMPILE :=3D $(CC) -MMD -MP $(CPPFLAGS) $(CFLAGS) > + > +# Library creation > + > +AR :=3D @AR@ > +RANLIB :=3D @RANLIB@ > + > +# Installation > + > +INSTALL :=3D @INSTALL@ > +INSTALL_DATA :=3D @INSTALL_DATA@ > + > +#-----------------------------------------------------------------------= -- > +# Build Object Files from C Source > +#-----------------------------------------------------------------------= -- > + > +gloss_c_srcs =3D $(filter %.c, $(gloss_srcs)) > +gloss_c_objs =3D $(patsubst %.c, %.o, $(notdir $(gloss_c_srcs))) > +gloss_c_deps =3D $(patsubst %.c, %.d, $(notdir $(gloss_c_srcs))) > + > +$(gloss_c_objs) : %.o : %.c > + $(COMPILE) -c $< > + > +gloss_objs +=3D $(gloss_c_objs) > +deps +=3D $(gloss_c_deps) > +junk +=3D $(gloss_c_deps) $(gloss_c_objs) > + > +#-----------------------------------------------------------------------= -- > +# Build Object Files from Assembly Source > +#-----------------------------------------------------------------------= -- > + > +gloss_asm_srcs =3D $(filter %.S, $(gloss_srcs)) > +gloss_asm_objs =3D $(patsubst %.S, %.o, $(notdir $(gloss_asm_srcs))) > +gloss_asm_deps =3D $(patsubst %.S, %.d, $(notdir $(gloss_asm_srcs))) > + > +$(gloss_asm_objs) : %.o : %.S > + $(COMPILE) -c -o $@ $< > + > +gloss_objs +=3D $(gloss_asm_objs) > +deps +=3D $(gloss_asm_deps) > +junk +=3D $(gloss_asm_deps) $(gloss_asm_objs) > + > +#-----------------------------------------------------------------------= -- > +# Build libgloss.a > +#-----------------------------------------------------------------------= -- > + > +gloss_lib =3D libgloss.a > +$(gloss_lib) : $(gloss_objs) > + $(AR) rcv $@ $^ > + $(RANLIB) $@ > + > +junk +=3D $(gloss_lib) > + > +install_hdrs +=3D $(gloss_hdrs) > +install_libs +=3D $(gloss_lib) > +install_specs +=3D $(gloss_specs) > +install_bins +=3D $(gloss_bins) > + > +#-----------------------------------------------------------------------= -- > +# Build crt0.o > +#-----------------------------------------------------------------------= -- > + > +crt0_obj =3D $(patsubst %.S, %.o, $(crt0_asm)) > +crt0_deps =3D $(patsubst %.S, %.d, $(crt0_asm)) > + > +$(crt0_obj) : %.o : %.S > + $(COMPILE) -c $< > + > +deps +=3D $(crt0_deps) > +junk +=3D $(crt0_deps) $(crt0_obj) > + > +install_libs +=3D $(crt0_obj) > + > +#-----------------------------------------------------------------------= -- > +# Autodependency files > +#-----------------------------------------------------------------------= -- > + > +-include $(deps) > + > +deps : $(deps) > +.PHONY : deps > + > +#-----------------------------------------------------------------------= -- > +# Installation > +#-----------------------------------------------------------------------= -- > + > +install_hdrs_wdir +=3D $(addprefix $(src_dir)/, $(install_hdrs)) > +install-hdrs : $(install_hdrs_wdir) > + test -d $(install_hdrs_dir) || mkdir -p $(install_hdrs_dir) > + for file in $^; do \ > + $(INSTALL_DATA) $$file $(install_hdrs_dir)/; \ > + done > + > +install-libs : $(install_libs) > + test -d $(install_libs_dir) || mkdir -p $(install_libs_dir) > + for file in $^; do \ > + $(INSTALL_DATA) $$file $(install_libs_dir)/$$file; \ > + done > + > +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-bins : $(install_bins) > + test -d $(install_bins_dir) || mkdir -p $(install_bins_dir) > + for file in $^; do \ > + $(INSTALL) $$file $(install_bins_dir)/; \ > + done > + > +install : install-hdrs install-libs install-specs install-bins > +.PHONY : install install-hdrs install-libs > + > +#-----------------------------------------------------------------------= -- > +# Regenerate configure information > +#-----------------------------------------------------------------------= -- > + > +configure_prereq =3D \ > + $(src_dir)/configure.in \ > + > +$(src_dir)/configure : $(configure_prereq) > + cd $(src_dir) && autoconf > + > +config.status : $(src_dir)/configure > + ./config.status --recheck > + > +Makefile : $(src_dir)/Makefile.in config.status > + ./config.status > + > +dist_junk +=3D config.status Makefile config.log > + > +#-----------------------------------------------------------------------= -- > +# Default > +#-----------------------------------------------------------------------= -- > + > +all : $(install_libs) $(install_bins) > +.PHONY : all > + > +#-----------------------------------------------------------------------= -- > +# Clean up junk > +#-----------------------------------------------------------------------= -- > + > +clean : > + rm -rf *~ \#* $(junk) > + > +distclean : > + rm -rf *~ \#* $(junk) $(dist_junk) > + > +.PHONY : clean distclean > diff --git a/libgloss/dramfs/README.md b/libgloss/dramfs/README.md > new file mode 100644 > index 000000000..09b92b1a1 > --- /dev/null > +++ b/libgloss/dramfs/README.md > @@ -0,0 +1,158 @@ > +# Newlib/DRAMFS > +###### Bandhav Veluri and Michael Taylor, Bespoke Silicon Group UW > + > +Note: Mirror changes to this file to > https://github.com/bespoke-silicon-group/bsg_newlib_dramfs/blob/dramfs/RE= ADME.md > + > +## Introduction > + > +Newlib is a light-weight C standard library implementation for embedded > systems. It elegantly separates system specific functionality (system > calls) into an easily portable portion called Libgloss. Libgloss contains > system call implementations for different architectures/systems in it. > Porting Newlib to an architecture/system essentially involves porting the= se > system call implementations in Libgloss. Complete guide for porting Newlib > can be found in [5]. > + > +Running POSIX programs on bare metal systems require some sort of > implementation for file i/o and malloc. Malloc depends on just one > system-call called sbrk, which essentially increments or decrements heap > pointer as and when requested. Whereas, file i/o requires an actual file > system, or an interface that can mimic a file system. This Newlib port us= es > an open-source lightweight file-system designed for embedded flash file > systems by ARM called LittleFS (LFS). LittleFS also supports a DRAM-based > file system, which is the one we use. > + > +The idea is to implement file i/o syscalls by simply translating them to > LFS function calls, which in turn will operate on memory, rather than > trying to use a more complex I/O emulation facility, like proxy kernels, > that package up I/O calls and ship them over to a host. This allows for > more reproducible I/O emulation, since the host is no longer an > asynchronous process. It also eliminates the infrastructure pain caused by > mapping these proxy-IO calls to different embodiments of the design -- > simulator, VCS, verilator, FPGA emulation, ASIC testboard, and PCI-e host= ed > chip. > + > +## Installation > + > +Newlib/Dramfs is intended to be a separate Board Support Package (BSP) in > Newlib. Newlib can be configured to install this BSP by setting the target > to end with `dramfs`: > + > +``` > +$ ./configure --target=3D--dramfs > [] > +``` > + > +Since this BSP works with any ISA, architecture field could be anything! > + > +## Porting > + > +Porting Newlib/Dramfs requires following four steps: > +1. Implement `dramfs_exit(int)` (routine to exit the execution > environment). > +2. Implement `dramfs_sendchar(char)` (routine to output non-file I/O (for > debugging etc)). > +3. Implment C-runtime initiation including a call to `dramfs_fs_init()` > in it. > +4. Implement linker command script including definition of `_end` symbol > (heap pointer) in it. > + > +#### 1, 2. Interfacing functions: > +``` > +/* > + * dramfs_intf.c > + * > + * Sample Implementation of Newlib/DRAMFS interface > + */ > + > +#include > +#include // This header is installed with this BSP! > + > +void dramfs_exit(int exit_status) { > + if(exit_status =3D=3D EXIT_SUCCESS) { > + // Exit the environment successfully > + > + // Replace this with code to exit > + // successfully on your system. > + } else { > + // Exit the environment with failure > + > + // Replace this with code to exit > + // with failure on your system. > + } > + > + // do nothing until we exit > + while(1); > +} > + > +void dramfs_sendchar(char ch) { > + // code to display =E2=80=98ch=E2=80=99 > + // in many cases you may just want to have a memory > + // mapped I/O location that you write to > + // whether that is simulator magic, a NOC, a UART, or PCIe. > +} > +``` > + > +#### 3. Adding `dramfs_fs_init` call to C-runtime initialization code: > + > +The function `dramfs_fs_init` (implemented in this BSP) has to called > before calling the main. This step mounts the LittleFS image using a tiny > block device driver implemeted by us. A sample C-runtime initialization is > provided below: > + > +``` > +# Sample crt.S > +# > +# This is architecture specific; hence user would implement this code > +# Following example is for a RISC-V system. > + > +.section .crtbegin,"a" > + > +.globl _start > +_start: > + > + # initialize global pointer > + la gp, _gp > + > + # initialize stack pointer > + la sp, _sp > + > + call dramfs_fs_init # initialize dramfs > + lw a0, 0(sp) # argc > + lw a1, -4(sp) # argv > + li a2, 0 # envp =3D NULL > + call main > + tail exit > + > +2: > + # Should never this point > + j 2b > +``` > + > +#### 4. Defining `_end` symbol in the linker command file: > + > +This can be done as shown in the sample linker script below: > + > +``` > +/* link.ld */ > +/* Sample linker command file */ > + > +SECTIONS > +{ > + . =3D 0x80000000; /* text and data start at 0x80000000 */ > + > + .text : { > + *(.crtbegin) > + *(.text) > + *(.text.startup) > + *(.text.*) > + } > + > + .data : { > + *(.data*) > + *(.rodata*) > + *(.sdata .sdata.* .srodata*) > + } > + > + /* global pointer */ > + _gp =3D .; > + > + .bss : { > + *(.bss*) > + *(.sbss*) > + } > + > + /* Initial heap pointer */ > + _end =3D . ; > + > + /* Initial stack pointer */ > + _sp =3D 0x81000000; > +} > +``` > + > +#### 5. Creating the DRAM lfs.c > + > +See instructions at https://github.com/bsg-external/bsg_dramfs_mklfs > + > +## Notes > + > +- Newlib is implemented on top of a set of operating system syscalls > listed in [4]. Newlib/dramfs currently implements `sbrk`, `open`, `close`, > `read`, `write`, `exit`, `lseek`, `stat` and `fstat`. These are sufficient > to handle the vast majority of newlib POSIX calls. For those that are not > supported, they return setting appropriate error number. We plan to > increase this set over time, and also encourage your pull requests. > +- Block size and count can be tweaked to improve performance depending on > your system. More on this can be understood from [2]. > +- Current implementations of syscalls are *not* thread-safe. So, this can > only be used for single threaded programs as of now. > + > +## References > + > +[1] Bootstrapping Idea: > https://drive.google.com/open?id=3D1_Ie94nZvyvMjEb1GQTPzfcBNaVs6xfVXZ_bHT= H5_z3k > > +[2] LittleFS: https://github.com/ARMmbed/littlefs > +[3] RISC-V BSP: > https://github.com/riscv/riscv-newlib/tree/riscv-newlib-3.1.0/libgloss/ri= scv > > +[4] Newlib OS interface: https://sourceware.org/newlib/libc.html#Syscalls > > +[5] Newlib porting guide: > https://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html > diff --git a/libgloss/dramfs/configure.in b/libgloss/dramfs/configure.in > new file mode 100644 > index 000000000..5694013d4 > --- /dev/null > +++ b/libgloss/dramfs/configure.in > @@ -0,0 +1,45 @@ > +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +# configure.ac for riscv libgloss and crt0 > +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +#-----------------------------------------------------------------------= -- > +# Setup > +#-----------------------------------------------------------------------= -- > + > +AC_INIT([crt0.S]) > +AC_CONFIG_SRCDIR([crt0.S]) > +AC_CONFIG_AUX_DIR([${srcdir}/../..]) > + > +#-----------------------------------------------------------------------= -- > +# Checks for programs > +#-----------------------------------------------------------------------= -- > + > +LIB_AC_PROG_CC > +AC_CHECK_TOOL([AR],[ar]) > +AC_CHECK_TOOL([RANLIB],[ranlib]) > +AC_PROG_INSTALL > + > +#-----------------------------------------------------------------------= -- > +# Output > +#-----------------------------------------------------------------------= -- > + > +if test "$srcdir" =3D "." ; then > + if test "${with_target_subdir}" !=3D "." ; then > + libgloss_topdir=3D"${srcdir}/${with_multisrctop}../../.." > + else > + libgloss_topdir=3D"${srcdir}/${with_multisrctop}../.." > + fi > +else > + libgloss_topdir=3D"${srcdir}/../.." > +fi > +AC_CONFIG_AUX_DIR($libgloss_topdir) > +AC_CONFIG_FILES(Makefile, > +. ${libgloss_topdir}/config-ml.in, > +srcdir=3D${srcdir} > +target=3D${target} > +with_multisubdir=3D${with_multisubdir} > +ac_configure_args=3D"${ac_configure_args} --enable-multilib" > +CONFIG_SHELL=3D${CONFIG_SHELL-/bin/sh} > +libgloss_topdir=3D${libgloss_topdir} > +) > +AC_OUTPUT > diff --git a/libgloss/dramfs/crt0.S b/libgloss/dramfs/crt0.S > new file mode 100644 > index 000000000..218d23104 > --- /dev/null > +++ b/libgloss/dramfs/crt0.S > @@ -0,0 +1,44 @@ > +/* Copyright (c) 2017 SiFive Inc. All rights reserved. > + > + This copyrighted material is made available to anyone wishing to use, > + modify, copy, or redistribute it subject to the terms and conditions > + of the FreeBSD License. This program is distributed in the hope that > + it will be useful, but WITHOUT ANY WARRANTY expressed or implied, > + including the implied warranties of MERCHANTABILITY or FITNESS FOR > + A PARTICULAR PURPOSE. A copy of this license is available at > + http://www.opensource.org/licenses. > +*/ > + > +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +# crt0.S : Entry point for RISC-V user programs > +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > + .text > + .global _start > + .type _start, @function > +_start: > + # Initialize global pointer > +.option push > +.option norelax > +1:auipc gp, %pcrel_hi(__global_pointer$) > + addi gp, gp, %pcrel_lo(1b) > +.option pop > + > + # Clear the bss segment > + la a0, _edata > + la a2, _end > + sub a2, a2, a0 > + li a1, 0 > + call memset > + > + la a0, __libc_fini_array # Register global termination functions > + call atexit # to be called upon exit > + call __libc_init_array # Run global initialization functions > + > + call dramfs_fs_init # initialize dramfs > + lw a0, 0(sp) # a0 =3D argc > + addi a1, sp, __SIZEOF_POINTER__ # a1 =3D argv > + li a2, 0 # a2 =3D envp =3D NULL > + call main > + tail exit > + .size _start, .-_start > diff --git a/libgloss/dramfs/sys_close.c b/libgloss/dramfs/sys_close.c > new file mode 100644 > index 000000000..fcb0a4faa > --- /dev/null > +++ b/libgloss/dramfs/sys_close.c > @@ -0,0 +1,41 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include "dramfs_fdtable.h" > +#include "dramfs_fs.h" > + > +/* Close a file. */ > +int > +_close(int fd) > +{ > + if(dramfs_check_fd(fd) < 0) { > + return -1; > + } > + > + return dramfs_free_fd(fd); > +} > diff --git a/libgloss/dramfs/sys_execve.c b/libgloss/dramfs/sys_execve.c > new file mode 100644 > index 000000000..8448ed6ae > --- /dev/null > +++ b/libgloss/dramfs/sys_execve.c > @@ -0,0 +1,40 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +#undef errno > +extern int errno; > + > +/* Transfer control to a new process. Minimal implementation for a > + system without processes from newlib documentation. */ > +int > +_execve(const char *name, char *const argv[], char *const env[]) > +{ > + errno =3D ENOMEM; > + return -1; > +} > diff --git a/libgloss/dramfs/sys_exit.c b/libgloss/dramfs/sys_exit.c > new file mode 100644 > index 000000000..d402bbe09 > --- /dev/null > +++ b/libgloss/dramfs/sys_exit.c > @@ -0,0 +1,41 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include "dramfs_fs.h" > + > +/* Exit a program without cleaning up files. */ > +void > +_exit(int exit_status) { > + // close stdio > + close(0); > + close(1); > + close(2); > + > + dramfs_exit(exit_status); > + while(1); > +} > diff --git a/libgloss/dramfs/sys_fork.c b/libgloss/dramfs/sys_fork.c > new file mode 100644 > index 000000000..6994ad55c > --- /dev/null > +++ b/libgloss/dramfs/sys_fork.c > @@ -0,0 +1,39 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +#undef errno > +extern int errno; > + > +/* Create a new process. Minimal implementation for a system without > + processes from newlib documentation. */ > +int _fork() > +{ > + errno =3D EAGAIN; > + return -1; > +} > diff --git a/libgloss/dramfs/sys_fstat.c b/libgloss/dramfs/sys_fstat.c > new file mode 100644 > index 000000000..2ba8952da > --- /dev/null > +++ b/libgloss/dramfs/sys_fstat.c > @@ -0,0 +1,48 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > + > +int > +_fstat(int file, struct stat *st) > +{ > + lfs_file_t *fptr; > + struct lfs_info finfo; > + > + if(dramfs_check_fd(file) < 0) > + return -1; > + else > + fptr =3D dramfs_get_file(file); > + > + st->st_mode =3D S_IFREG; > + st->st_size =3D (off_t) fptr->size; > + st->st_blksize =3D (blksize_t) dramfs_fs_cfg.block_size; > + st->st_blocks =3D (blkcnt_t) dramfs_fs_cfg.block_count; > + return 0; > +} > diff --git a/libgloss/dramfs/sys_getpid.c b/libgloss/dramfs/sys_getpid.c > new file mode 100644 > index 000000000..15ea50a09 > --- /dev/null > +++ b/libgloss/dramfs/sys_getpid.c > @@ -0,0 +1,36 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +/* Get process id. This is sometimes used to generate strings unlikely > + to conflict with other processes. Minimal implementation for a > + system without processes just returns 1. */ > + > +int > +_getpid() > +{ > + return 1; > +} > diff --git a/libgloss/dramfs/sys_gettimeofday.c > b/libgloss/dramfs/sys_gettimeofday.c > new file mode 100644 > index 000000000..ac66268bf > --- /dev/null > +++ b/libgloss/dramfs/sys_gettimeofday.c > @@ -0,0 +1,40 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +#undef errno > +extern int errno; > + > +/* Get the current time. Only relatively correct. */ > +int > +_gettimeofday(struct timeval *tp, void *tzp) > +{ > + errno =3D EINVAL; > + return -1; > +} > diff --git a/libgloss/dramfs/sys_isatty.c b/libgloss/dramfs/sys_isatty.c > new file mode 100644 > index 000000000..f372dfda2 > --- /dev/null > +++ b/libgloss/dramfs/sys_isatty.c > @@ -0,0 +1,36 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +/* Query whether output stream is a terminal. For consistency with the > + other minimal implementations, which only support output to stdout, > + this minimal implementation is suggested by the newlib docs. */ > + > +int > +_isatty(int file) > +{ > + return 1; > +} > diff --git a/libgloss/dramfs/sys_kill.c b/libgloss/dramfs/sys_kill.c > new file mode 100644 > index 000000000..3a2597d25 > --- /dev/null > +++ b/libgloss/dramfs/sys_kill.c > @@ -0,0 +1,40 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +#undef errno > +extern int errno; > + > +/* Send a signal. Minimal implementation for a system without processes > + just causes an error. */ > +int > +_kill(int pid, int sig) > +{ > + errno =3D EINVAL; > + return -1; > +} > diff --git a/libgloss/dramfs/sys_link.c b/libgloss/dramfs/sys_link.c > new file mode 100644 > index 000000000..fd2af719d > --- /dev/null > +++ b/libgloss/dramfs/sys_link.c > @@ -0,0 +1,38 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +#undef errno > +extern int errno; > + > +/* Establish a new name for an existing file. Minimal implementation */ > +int _link(const char *old_name, const char *new_name) > +{ > + errno =3D EMLINK; > + return -1; > +} > diff --git a/libgloss/dramfs/sys_lseek.c b/libgloss/dramfs/sys_lseek.c > new file mode 100644 > index 000000000..27c25c305 > --- /dev/null > +++ b/libgloss/dramfs/sys_lseek.c > @@ -0,0 +1,44 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > + > +/* Set position in a file. */ > +off_t > +_lseek(int file, off_t ptr, int dir) > +{ > + lfs_file_t *fptr; > + > + if(dramfs_check_fd(file) < 0) > + return -1; > + else > + fptr =3D dramfs_get_file(file); > + > + return lfs_file_seek(&dramfs_fs, fptr, ptr, dir); > +} > diff --git a/libgloss/dramfs/sys_open.c b/libgloss/dramfs/sys_open.c > new file mode 100644 > index 000000000..5580d5c4d > --- /dev/null > +++ b/libgloss/dramfs/sys_open.c > @@ -0,0 +1,64 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include "dramfs_fdtable.h" > +#include "dramfs_fs.h" > + > +/* Open a file. */ > +int > +_open(const char *name, int flags, int mode) > +{ > + int fd =3D dramfs_reserve_fd(); > + int lfs_flags =3D 0; > + > + // File open flags mapping > + lfs_flags |=3D (flags & O_RDONLY ) ? LFS_O_RDONLY : 0; > + lfs_flags |=3D (flags & O_WRONLY ) ? LFS_O_WRONLY : 0; > + lfs_flags |=3D (flags & O_RDWR ) ? LFS_O_RDWR : 0; > + lfs_flags |=3D (flags & O_APPEND ) ? LFS_O_APPEND : 0; > + lfs_flags |=3D (flags & O_CREAT ) ? LFS_O_CREAT : 0; > + lfs_flags |=3D (flags & O_TRUNC ) ? LFS_O_TRUNC : 0; > + lfs_flags |=3D (flags & O_EXCL ) ? LFS_O_EXCL : 0; > + lfs_flags |=3D (flags & O_NONBLOCK) ? LFS_O_NONBLOCK : 0; > + > + if(fd < 0) { > + return -1; > + } else { > + lfs_file_t *fptr =3D dramfs_get_file(fd); > + > + int ret =3D lfs_file_open(&dramfs_fs, fptr, name, lfs_flags); > + > + if(ret < 0) { > + errno =3D ret; > + return -1; > + } else { > + return fd; > + } > + } > +} > diff --git a/libgloss/dramfs/sys_read.c b/libgloss/dramfs/sys_read.c > new file mode 100644 > index 000000000..8ef6b6a45 > --- /dev/null > +++ b/libgloss/dramfs/sys_read.c > @@ -0,0 +1,67 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include "dramfs_fdtable.h" > +#include "dramfs_fs.h" > + > +/* Read from a file. */ > +ssize_t _read(int fd, void *ptr, size_t len) > +{ > + if(dramfs_check_fd(fd) < 0) { > + return -1; > + } > + > + if(fd =3D=3D 0) { > + uint8_t *data =3D (uint8_t *)ptr; > + > + // Return early on len =3D=3D 0 > + if (len =3D=3D 0) return (ssize_t) 0; > + > + int ch; > + if (dramfs_nonblock_fd(fd) =3D=3D 0) { > + // Block to read just 1 character to start > + while ((ch =3D dramfs_getchar()) =3D=3D -1); > + } else { > + // Read the first character, and return immediately if it's EOF > + if ((ch =3D dramfs_getchar()) =3D=3D -1) return (ssize_t) 0; > + } > + > + // Keep reading until new > + int i =3D 0; > + do { > + data[i++] =3D ch; > + if (i =3D=3D len) break; > + } while ((ch =3D dramfs_getchar()) !=3D -1); > + > + return (ssize_t) i; > + } > + > + lfs_file_t *fptr =3D dramfs_get_file(fd); > + return (ssize_t) lfs_file_read(&dramfs_fs, fptr, ptr, (lfs_size_t) len= ); > +} > diff --git a/libgloss/dramfs/sys_sbrk.c b/libgloss/dramfs/sys_sbrk.c > new file mode 100644 > index 000000000..300356a08 > --- /dev/null > +++ b/libgloss/dramfs/sys_sbrk.c > @@ -0,0 +1,49 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +// Dynamic allocation in the dram > +// TODO: add mutex > +extern char _end[]; /* _end is set in the linker command file */ > + > +char *heap_ptr =3D _end; > + > +/* > + * 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; > + > + base =3D heap_ptr; > + heap_ptr +=3D nbytes; > + > + return base; > +} > diff --git a/libgloss/dramfs/sys_stat.c b/libgloss/dramfs/sys_stat.c > new file mode 100644 > index 000000000..f19309e16 > --- /dev/null > +++ b/libgloss/dramfs/sys_stat.c > @@ -0,0 +1,50 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > + > +/* Status of a file (by name). */ > + > +int > +_stat(const char *file, struct stat *st) > +{ > + struct lfs_info finfo; > + > + int res =3D lfs_stat(&dramfs_fs, file, &finfo); > + if(res < 0) { > + errno =3D res; > + return -1; > + } else { > + st->st_mode =3D S_IFREG; > + st->st_size =3D (off_t) finfo.size; > + st->st_blksize =3D (blksize_t) dramfs_fs_cfg.block_size; > + st->st_blocks =3D (blkcnt_t) dramfs_fs_cfg.block_count; > + return 0; > + } > +} > diff --git a/libgloss/dramfs/sys_times.c b/libgloss/dramfs/sys_times.c > new file mode 100644 > index 000000000..1c8ed9ceb > --- /dev/null > +++ b/libgloss/dramfs/sys_times.c > @@ -0,0 +1,35 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +/* Timing info for current process. Minimal implementation */ > +clock_t > +_times(struct tms *buf) > +{ > + return -1; > +} > diff --git a/libgloss/dramfs/sys_unlink.c b/libgloss/dramfs/sys_unlink.c > new file mode 100644 > index 000000000..4f4c4c750 > --- /dev/null > +++ b/libgloss/dramfs/sys_unlink.c > @@ -0,0 +1,39 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +#undef errno > +extern int errno; > + > +/* Remove a file's directory entry. */ > +int > +_unlink(const char *name) > +{ > + errno =3D ENOENT; > + return -1; > +} > diff --git a/libgloss/dramfs/sys_wait.c b/libgloss/dramfs/sys_wait.c > new file mode 100644 > index 000000000..b593511fe > --- /dev/null > +++ b/libgloss/dramfs/sys_wait.c > @@ -0,0 +1,39 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +#undef errno > +extern int errno; > + > +/* Wait for a child process. Minimal implementation for a system without > + processes just causes an error. */ > +int _wait(int *status) > +{ > + errno =3D ECHILD; > + return -1; > +} > diff --git a/libgloss/dramfs/sys_write.c b/libgloss/dramfs/sys_write.c > new file mode 100644 > index 000000000..082ef748d > --- /dev/null > +++ b/libgloss/dramfs/sys_write.c > @@ -0,0 +1,52 @@ > +/* > + * Copyright (c) 2023, University of Washington > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions are > met: > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > the > + * documentation and/or other materials provided with the > distribution. > + * * Neither the name of the University of Washington nor the > + * names of its contributors may be used to endorse or promote > products > + * derived from this software without specific prior written > permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > IMPLIED > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > + * DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF WASHINGTON BE LIABLE FOR > ANY > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR > SERVICES; > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER > CAUSED AND > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include "dramfs_fdtable.h" > +#include "dramfs_fs.h" > + > +/* Write to a file. */ > +ssize_t > +_write(int fd, const void *ptr, size_t len) > +{ > + if(dramfs_check_fd(fd) < 0) { > + return -1; > + } > + > + // write to console if it's stdout > + if(fd =3D=3D 1 || fd=3D=3D2) { > + for(int i=3D0; i + char* cp =3D (char*) ptr; > + dramfs_sendchar(cp[i]); > + } > + return len; > + } > + > + lfs_file_t *fptr =3D dramfs_get_file(fd); > + return (ssize_t) lfs_file_write(&dramfs_fs, fptr, ptr, (lfs_size_t) > len); > +} > -- > 2.16.5 > > --0000000000000cf187060295290e--