From 411caac86f43a9567eff2d8c3ea0d52831356310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Wed, 5 Apr 2023 10:53:34 +0000 Subject: [PATCH] Assembly lib --- .gitignore | 2 ++ test/Makefile => Makefile | 11 ++++--- test/Makefile.config => Makefile.config | 0 test/Makefile.tests => Makefile.rules | 3 ++ Makefile.userlib | 0 build.rs | 3 -- {test/userlib => src/kernel}/syscall.rs | 33 ++++++++++--------- .../riscv_instructions/boolean_logic/Makefile | 4 +-- .../jump_instructions/Makefile | 4 +-- .../simple_arithmetics/Makefile | 4 +-- .../riscv_instructions/syscall_tests/Makefile | 4 +-- test/userlib/Makefile | 7 ---- userlib/Makefile | 7 ++++ {test/userlib => userlib}/ldscript.lds | 0 {test/userlib => userlib}/libnachos.c | 0 {test/userlib => userlib}/libnachos.h | 0 {test/userlib => userlib}/sys.s | 0 {test/userlib => userlib}/syscall.h | 0 18 files changed, 43 insertions(+), 39 deletions(-) rename test/Makefile => Makefile (64%) rename test/Makefile.config => Makefile.config (100%) rename test/Makefile.tests => Makefile.rules (96%) create mode 100644 Makefile.userlib rename {test/userlib => src/kernel}/syscall.rs (86%) delete mode 100644 test/userlib/Makefile create mode 100644 userlib/Makefile rename {test/userlib => userlib}/ldscript.lds (100%) rename {test/userlib => userlib}/libnachos.c (100%) rename {test/userlib => userlib}/libnachos.h (100%) rename {test/userlib => userlib}/sys.s (100%) rename {test/userlib => userlib}/syscall.h (100%) diff --git a/.gitignore b/.gitignore index 58e09e4..a60c662 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.iml /*.txt /.vscode +*.a +*.o diff --git a/test/Makefile b/Makefile similarity index 64% rename from test/Makefile rename to Makefile index 2cf5313..9daf3b6 100644 --- a/test/Makefile +++ b/Makefile @@ -7,24 +7,25 @@ all: dumps user_lib tests # Main targets # -build: user_lib - $(MAKE) build -C riscv_instructions/ +instruction_tests: + $(MAKE) build -C test/riscv_instructions/ dumps: - $(MAKE) dumps -C riscv_instructions/ + $(MAKE) dumps -C test/riscv_instructions/ mkdir -p ${TOPDIR}/target/dumps/ find . -path ${TOPDIR}/target -prune -o -name '*.dump' -exec mv {} ${TOPDIR}/target/dumps/ \; user_lib: $(MAKE) -C userlib/ + mv ${TOPDIR}/userlib/sys.a ${TOPDIR}/src/sys.a tests: user_lib - $(MAKE) tests -C riscv_instructions/ + $(MAKE) tests -C test/riscv_instructions/ mkdir -p ${TOPDIR}/target/guac/ find . -name '*.guac' -exec mv {} ${TOPDIR}/target/guac/ \; clean: $(MAKE) clean -C userlib/ - $(MAKE) clean -C riscv_instructions/ + $(MAKE) clean -C test/riscv_instructions/ $(RM) -rf $(TOPDIR)/target \ No newline at end of file diff --git a/test/Makefile.config b/Makefile.config similarity index 100% rename from test/Makefile.config rename to Makefile.config diff --git a/test/Makefile.tests b/Makefile.rules similarity index 96% rename from test/Makefile.tests rename to Makefile.rules index 14dba3d..58fab4b 100644 --- a/test/Makefile.tests +++ b/Makefile.rules @@ -18,6 +18,9 @@ CFLAGS = $(RISCV_CFLAGS) $(INCPATH) %.o: %.c $(GCC) $(CFLAGS) -c $< +%.a: %.o + $(AR) $(ARFLAGS) $@ $< + %.dump: %.o $(RISCV_OBJCOPY) -j .text -O $(DUMP_FORMAT) $< $@ diff --git a/Makefile.userlib b/Makefile.userlib new file mode 100644 index 0000000..e69de29 diff --git a/build.rs b/build.rs index 7b5ec8a..ea3850b 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,2 @@ fn main() { - cc::Build::new() - .file("test/userlib/sys.s") - .compile("my-asm-lib"); } \ No newline at end of file diff --git a/test/userlib/syscall.rs b/src/kernel/syscall.rs similarity index 86% rename from test/userlib/syscall.rs rename to src/kernel/syscall.rs index 54b82ba..14ceeb7 100644 --- a/test/userlib/syscall.rs +++ b/src/kernel/syscall.rs @@ -36,7 +36,8 @@ pub struct LockId{ pub struct CondId{ id: u64 } -extern "C"{ + +extern "C" { ///Stop Nachos, and print out performance stats fn Shutdown() -> (); @@ -49,11 +50,11 @@ extern "C"{ /// Run the executable, stored in the Nachos file "name", and return the /// master thread identifier - fn Exec(name: *char) -> ThreadId; + fn Exec(name: *const char) -> ThreadId; /// Create a new thread in the current process /// Return thread identifier - fn newThread(debug_name: *char, func: i32, arg: i32) -> ThreadId; + fn newThread(debug_name: *const char, func: i32, arg: i32) -> ThreadId; /// Only return once the the thread "id" has finished. fn Join (id: ThreadId) -> t_error; @@ -63,24 +64,24 @@ extern "C"{ fn Yield() -> (); /// Print the last error message with the personalized one "mess" - fn PError(mess: *char) -> (); + fn PError(mess: *const char) -> (); /// Create a BurritOS file, with "name" - fn Create(name: *char, size: i32) -> t_error; + fn Create(name: *const char, size: i32) -> t_error; /// Open the Nachos file "name", and return an "OpenFileId" that can /// be used to read and write to the file. - fn Open(name: *char) -> OpenFiledId; + fn Open(name: *const char) -> OpenFiledId; /// Write "size" bytes from "buffer" to the open file. - fn Write(buffer: *char, size: i32, id: OpenFiledId) -> t_error; + fn Write(buffer: *const char, size: i32, id: OpenFiledId) -> t_error; /// Read "size" bytes from the open file into "buffer". /// Return the number of bytes actually read -- if the open file isn't /// long enough, or if it is an I/O device, and there aren't enough /// characters to read, return whatever is available (for I/O devices, /// you should always wait until you can return at least one character). - fn Read(buffer: *char, size: i32, id:OpenFiledId) -> t_error; + fn Read(buffer: *const char, size: i32, id:OpenFiledId) -> t_error; /// Seek to a specified offset into an opened file fn Seek(offset: i32, id: OpenFiledId) -> t_error; @@ -89,7 +90,7 @@ extern "C"{ fn Close(id: OpenFiledId) -> t_error; /// Remove the file - fn Remove(name: *char) -> t_error; + fn Remove(name: *const char) -> t_error; //////////////////////////////////////////////////// /// system calls concerning directory management /// @@ -97,11 +98,11 @@ extern "C"{ /// Create a new repertory /// Return a negative number if an error ocurred. - fn mkdir(name: *char) -> t_length; + fn mkdir(name: *const char) -> t_length; /// Destroy a repertory, which must be empty. /// Return a negative number if an error ocurred. - fn Rmdir(name: *char) -> t_error; + fn Rmdir(name: *const char) -> t_error; /// List the content of BurritOS FileSystem fn FSList() -> t_error; @@ -109,7 +110,7 @@ extern "C"{ /// Create a semaphore, initialising it at count. /// Return a Semid, which will enable to do operations on this /// semaphore - fn SemCreate(debug_name: *char, count: i32) -> SemId; + fn SemCreate(debug_name: *const char, count: i32) -> SemId; /// Destroy a semaphore identified by sema. /// Return a negative number if an error occured during the destruction @@ -123,7 +124,7 @@ extern "C"{ /// Create a lock. /// Return an identifier - fn LockCreate(debug_name: *char) -> LockId; + fn LockCreate(debug_name: *const char) -> LockId; /// Destroy a lock. /// Return a negative number if an error ocurred @@ -139,7 +140,7 @@ extern "C"{ fn LockRelease(id: LockId) -> t_error; /// Create a new condition variable - fn CondCreate(debug_name: *char) -> CondId; + fn CondCreate(debug_name: *const char) -> CondId; /// Destroy a condition variable. /// Return a negative number if an error ocurred. @@ -163,12 +164,12 @@ extern "C"{ ///Send the message on the serial communication link. /// Returns the number of bytes successfully sent. - fn TtySend(mess: *char) -> i32; + fn TtySend(mess: *const char) -> i32; /// Wait for a message comming from the serial communication link. /// The length of the buffer where the bytes will be copied is given as a parameter. /// Returns the number of characters actually received. - fn TtyReceive(mess: *char, length: i32) -> i32; + fn TtyReceive(mess: *const char, length: i32) -> i32; /// Map an opened file in memory. Size is the size to be mapped in bytes. fn Mmap(id: OpenFiledId, size: i32) -> *mut (); diff --git a/test/riscv_instructions/boolean_logic/Makefile b/test/riscv_instructions/boolean_logic/Makefile index e9b0a52..b0d2554 100644 --- a/test/riscv_instructions/boolean_logic/Makefile +++ b/test/riscv_instructions/boolean_logic/Makefile @@ -7,8 +7,8 @@ dumps: comparisons.dump if.dump switch.dump tests: comparisons.guac if.guac switch.guac -TOPDIR = ../.. -include $(TOPDIR)/Makefile.tests +TOPDIR = ../../.. +include $(TOPDIR)/Makefile.rules clean: $(RM) comparisons comparisons.o if if.o diff --git a/test/riscv_instructions/jump_instructions/Makefile b/test/riscv_instructions/jump_instructions/Makefile index 71ce3c0..72523a3 100644 --- a/test/riscv_instructions/jump_instructions/Makefile +++ b/test/riscv_instructions/jump_instructions/Makefile @@ -9,7 +9,7 @@ tests: jump.guac ret.guac clean: $(RM) jump jump.o ret ret.o -TOPDIR = ../.. -include $(TOPDIR)/Makefile.tests +TOPDIR = ../../.. +include $(TOPDIR)/Makefile.rules $(PROGRAMS): % : $(USERLIB)/sys.o $(USERLIB)/libnachos.o %.o \ No newline at end of file diff --git a/test/riscv_instructions/simple_arithmetics/Makefile b/test/riscv_instructions/simple_arithmetics/Makefile index 9b42a4b..1d3dcf2 100644 --- a/test/riscv_instructions/simple_arithmetics/Makefile +++ b/test/riscv_instructions/simple_arithmetics/Makefile @@ -10,7 +10,7 @@ tests: unsigned_addition.guac unsigned_division.guac unsigned_multiplication.gua clean: $(RM) unsigned_addition unsigned_addition.o unsigned_division unsigned_division.o unsigned_multiplication unsigned_multiplication.o unsigned_substraction unsigned_substraction.o -TOPDIR = ../.. -include $(TOPDIR)/Makefile.tests +TOPDIR = ../../.. +include $(TOPDIR)/Makefile.rules $(PROGRAMS): % : $(USERLIB)/sys.o $(USERLIB)/libnachos.o %.o \ No newline at end of file diff --git a/test/riscv_instructions/syscall_tests/Makefile b/test/riscv_instructions/syscall_tests/Makefile index 62b3741..e528387 100644 --- a/test/riscv_instructions/syscall_tests/Makefile +++ b/test/riscv_instructions/syscall_tests/Makefile @@ -10,7 +10,7 @@ tests: halt.guac prints.guac clean: $(RM) halt.o halt prints prints.o -TOPDIR = ../.. -include $(TOPDIR)/Makefile.tests +TOPDIR = ../../.. +include $(TOPDIR)/Makefile.rules $(PROGRAMS): % : $(USERLIB)/sys.o $(USERLIB)/libnachos.o %.o \ No newline at end of file diff --git a/test/userlib/Makefile b/test/userlib/Makefile deleted file mode 100644 index 6a5c70f..0000000 --- a/test/userlib/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -TOPDIR = ../ -include $(TOPDIR)/Makefile.tests - -default: sys.o libnachos.o - -clean: - $(RM) libnachos.o sys.o \ No newline at end of file diff --git a/userlib/Makefile b/userlib/Makefile new file mode 100644 index 0000000..79d7bd9 --- /dev/null +++ b/userlib/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../ +include $(TOPDIR)/Makefile.rules + +default: sys.a libnachos.a + +clean: + $(RM) libnachos.a sys.a libnachos.o sys.o \ No newline at end of file diff --git a/test/userlib/ldscript.lds b/userlib/ldscript.lds similarity index 100% rename from test/userlib/ldscript.lds rename to userlib/ldscript.lds diff --git a/test/userlib/libnachos.c b/userlib/libnachos.c similarity index 100% rename from test/userlib/libnachos.c rename to userlib/libnachos.c diff --git a/test/userlib/libnachos.h b/userlib/libnachos.h similarity index 100% rename from test/userlib/libnachos.h rename to userlib/libnachos.h diff --git a/test/userlib/sys.s b/userlib/sys.s similarity index 100% rename from test/userlib/sys.s rename to userlib/sys.s diff --git a/test/userlib/syscall.h b/userlib/syscall.h similarity index 100% rename from test/userlib/syscall.h rename to userlib/syscall.h