2023-04-04 17:59:05 +02:00
|
|
|
use std::str::Chars;
|
|
|
|
|
|
|
|
/// Define the BurritOS running time basic unit
|
2023-04-05 14:51:50 +02:00
|
|
|
pub struct BurritosTime {
|
2023-03-29 17:16:08 +02:00
|
|
|
seconds: i64,
|
|
|
|
nanos: i64
|
|
|
|
}
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// A unique identifier for a thread executed within a user program
|
2023-03-29 17:16:08 +02:00
|
|
|
pub struct ThreadId{
|
|
|
|
id: u64
|
|
|
|
}
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// The system call interface. These are the operations the BurritOS
|
|
|
|
/// kernel needs to support, to be able to run user programs.
|
2023-04-05 14:51:50 +02:00
|
|
|
pub struct TError {
|
2023-03-29 17:16:08 +02:00
|
|
|
t: i32
|
|
|
|
}
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// A unique identifier for an open BurritOS file.
|
|
|
|
pub struct OpenFiledId{
|
|
|
|
id: u64
|
|
|
|
}
|
|
|
|
|
|
|
|
/// System calls concerning semaphores management
|
|
|
|
pub struct SemId{
|
|
|
|
id: u64
|
|
|
|
}
|
|
|
|
|
|
|
|
/// System calls concerning locks management
|
|
|
|
pub struct LockId{
|
|
|
|
id: u64
|
|
|
|
}
|
|
|
|
|
|
|
|
/// System calls concerning conditions variables.
|
|
|
|
pub struct CondId{
|
|
|
|
id: u64
|
|
|
|
}
|
2023-04-05 12:53:34 +02:00
|
|
|
|
|
|
|
extern "C" {
|
2023-04-04 17:59:05 +02:00
|
|
|
|
2023-04-05 14:52:46 +02:00
|
|
|
///Stop BurritOS, and print out performance stats
|
2023-03-29 17:16:08 +02:00
|
|
|
fn Shutdown() -> ();
|
2023-04-04 17:59:05 +02:00
|
|
|
|
2023-04-05 14:50:58 +02:00
|
|
|
/// Return the time spent running BurritOS
|
|
|
|
/// ## Param
|
|
|
|
/// - **t** a struct to define the time unit
|
2023-04-05 14:51:50 +02:00
|
|
|
fn SysTime(t: BurritosTime) -> ();
|
2023-04-04 17:59:05 +02:00
|
|
|
|
2023-04-05 14:50:58 +02:00
|
|
|
/// This user program is done
|
|
|
|
/// ## Param
|
|
|
|
/// - **status** status at the end of execution *(status = 0 means exited normally)*.
|
2023-03-29 17:16:08 +02:00
|
|
|
fn Exit(status: i32) -> ();
|
2023-04-04 17:59:05 +02:00
|
|
|
|
2023-04-05 14:50:58 +02:00
|
|
|
/// Run the executable, stored in the BurritOS file "name", and return the
|
|
|
|
/// master thread identifier
|
2023-04-05 12:53:34 +02:00
|
|
|
fn Exec(name: *const char) -> ThreadId;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Create a new thread in the current process
|
|
|
|
/// Return thread identifier
|
2023-04-05 12:53:34 +02:00
|
|
|
fn newThread(debug_name: *const char, func: i32, arg: i32) -> ThreadId;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Only return once the the thread "id" has finished.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Join (id: ThreadId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Yield the CPU to another runnable thread, whether in this address space
|
|
|
|
/// or not.
|
2023-03-29 17:16:08 +02:00
|
|
|
fn Yield() -> ();
|
|
|
|
|
2023-04-04 17:59:05 +02:00
|
|
|
/// Print the last error message with the personalized one "mess"
|
2023-04-05 12:53:34 +02:00
|
|
|
fn PError(mess: *const char) -> ();
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Create a BurritOS file, with "name"
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Create(name: *const char, size: i32) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Open the Nachos file "name", and return an "OpenFileId" that can
|
|
|
|
/// be used to read and write to the file.
|
2023-04-05 12:53:34 +02:00
|
|
|
fn Open(name: *const char) -> OpenFiledId;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Write "size" bytes from "buffer" to the open file.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Write(buffer: *const char, size: i32, id: OpenFiledId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// 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).
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Read(buffer: *const char, size: i32, id:OpenFiledId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Seek to a specified offset into an opened file
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Seek(offset: i32, id: OpenFiledId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Close the file, we're done reading and writing to it.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Close(id: OpenFiledId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Remove the file
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Remove(name: *const char) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
/// system calls concerning directory management ///
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// Create a new repertory
|
|
|
|
/// Return a negative number if an error ocurred.
|
2023-04-05 12:53:34 +02:00
|
|
|
fn mkdir(name: *const char) -> t_length;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Destroy a repertory, which must be empty.
|
|
|
|
/// Return a negative number if an error ocurred.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn Rmdir(name: *const char) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// List the content of BurritOS FileSystem
|
2023-04-05 14:51:50 +02:00
|
|
|
fn FSList() -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Create a semaphore, initialising it at count.
|
|
|
|
/// Return a Semid, which will enable to do operations on this
|
|
|
|
/// semaphore
|
2023-04-05 12:53:34 +02:00
|
|
|
fn SemCreate(debug_name: *const char, count: i32) -> SemId;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Destroy a semaphore identified by sema.
|
|
|
|
/// Return a negative number if an error occured during the destruction
|
2023-04-05 14:51:50 +02:00
|
|
|
fn SemDestroy(sema: SemId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Do the operation P() on the semaphore sema
|
2023-04-05 14:51:50 +02:00
|
|
|
fn P(sema: SemId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Do the operation V() on the semaphore sema
|
2023-04-05 14:51:50 +02:00
|
|
|
fn V(sema: SemId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Create a lock.
|
|
|
|
/// Return an identifier
|
2023-04-05 12:53:34 +02:00
|
|
|
fn LockCreate(debug_name: *const char) -> LockId;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Destroy a lock.
|
|
|
|
/// Return a negative number if an error ocurred
|
|
|
|
/// during the destruction.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn LockDestroy(id: LockId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Do the operation Acquire on the lock id.
|
|
|
|
/// Return a negative number if an error ocurred.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn LockAcquire(id: LockId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Do the operation Release on the lock id.
|
|
|
|
/// Return a negative number if an error ocurred.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn LockRelease(id: LockId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Create a new condition variable
|
2023-04-05 12:53:34 +02:00
|
|
|
fn CondCreate(debug_name: *const char) -> CondId;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Destroy a condition variable.
|
|
|
|
/// Return a negative number if an error ocurred.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn CondDestroy(id: CondId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Do the operation Wait on a condition variable.
|
|
|
|
/// Returns a negative number if an error ocurred.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn CondWait(id: CondId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Do the operation Signal on a condition variable (wake up only one thread).
|
|
|
|
/// Return a negative number if an error ocurred.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn CondSignal(id: CondId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Do the operation Signal on a condition variable (wake up all threads).
|
|
|
|
/// Return a negative number if an error ocurred.
|
2023-04-05 14:51:50 +02:00
|
|
|
fn CondBroadcast(id: CondId) -> TError;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
2023-04-05 14:50:58 +02:00
|
|
|
/// # System calls concerning serial port and console
|
2023-04-04 17:59:05 +02:00
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
///Send the message on the serial communication link.
|
|
|
|
/// Returns the number of bytes successfully sent.
|
2023-04-05 12:53:34 +02:00
|
|
|
fn TtySend(mess: *const char) -> i32;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// 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.
|
2023-04-05 12:53:34 +02:00
|
|
|
fn TtyReceive(mess: *const char, length: i32) -> i32;
|
2023-04-04 17:59:05 +02:00
|
|
|
|
|
|
|
/// Map an opened file in memory. Size is the size to be mapped in bytes.
|
|
|
|
fn Mmap(id: OpenFiledId, size: i32) -> *mut ();
|
|
|
|
|
|
|
|
/// For debug purpose
|
|
|
|
fn Debug(param: i32)-> ();
|
2023-03-29 17:16:08 +02:00
|
|
|
}
|