Assembly lib

This commit is contained in:
François Autin 2023-04-05 10:53:34 +00:00
parent 0fd2815a59
commit 411caac86f
18 changed files with 43 additions and 39 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
*.iml
/*.txt
/.vscode
*.a
*.o

View File

@ -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

View File

@ -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) $< $@

0
Makefile.userlib Normal file
View File

View File

@ -1,5 +1,2 @@
fn main() {
cc::Build::new()
.file("test/userlib/sys.s")
.compile("my-asm-lib");
}

View File

@ -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 ();

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,7 +0,0 @@
TOPDIR = ../
include $(TOPDIR)/Makefile.tests
default: sys.o libnachos.o
clean:
$(RM) libnachos.o sys.o

7
userlib/Makefile Normal file
View File

@ -0,0 +1,7 @@
TOPDIR = ../
include $(TOPDIR)/Makefile.rules
default: sys.a libnachos.a
clean:
$(RM) libnachos.a sys.a libnachos.o sys.o