Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Nov 2, 2024
1 parent 232c667 commit 2ac7cfd
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 8 deletions.
53 changes: 49 additions & 4 deletions doc/syscalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ fn write(handle: usize, buf: &mut [u8]) -> isize
fn open(path: &str, flags: usize) -> isize
```

The flags can be one or more of the following:

```rust
enum OpenFlag {
Read = 1,
Write = 2,
Append = 4,
Create = 8,
Truncate = 16,
Dir = 32,
Device = 64,
}
```

## CLOSE (0x06)

```rust
Expand All @@ -47,7 +61,7 @@ fn info(path: &str, info: &mut FileInfo) -> isize
This syscall will set the following attributes of the given structure:

```rust
pub struct FileInfo {
struct FileInfo {
kind: FileType,
size: u32,
time: u64,
Expand Down Expand Up @@ -87,12 +101,43 @@ fn sleep(seconds: f64)
fn poll(list: &[(usize, IO)]) -> isize
```

Given a list of file handles and `IO` operations:

```rust
enum IO {
Read,
Write,
}
```

This syscall will return the index of the first file handle in the list that is
ready for the given `IO` operation or a negative number if no operations are
available for any file handles.

For example polling the console will notify when a line is ready to be read,
or polling a socket will notify when it can receive or send.

## CONNECT (0x0D)

```rust
fn connect(handle, usize, addr: &str, port: u16) -> isize
fn connect(handle, usize, addr: IpAddress, port: u16) -> isize
```

Connect a socket to an endpoint at the given `IpAddress` and port:

```rust
struct Ipv4Address(pub [u8; 4]);

struct Ipv6Address(pub [u8; 16]);

enum IpAddress {
Ipv4(Ipv4Address),
Ipv6(Ipv6Address),
}
```

NOTE: Only IPv4 is currently supported.

## LISTEN (0x0E)

```rust
Expand All @@ -102,7 +147,7 @@ fn listen(handle, usize, port: u16) -> isize
## ACCEPT (0x0F)

```rust
fn accept(handle, usize, addr: &str) -> isize
fn accept(handle, usize, addr: IpAddress) -> isize
```

## ALLOC (0x10)
Expand All @@ -127,7 +172,7 @@ This syscall will return a integer corresponding to the `FileType` of the given
file handle when successful:

```rust
pub enum FileType {
enum FileType {
Dir = 0,
File = 1,
Device = 2,
Expand Down
50 changes: 46 additions & 4 deletions www/syscalls.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ <h2>OPEN (0x05)</h2>
<pre><code class="rust">fn open(path: &amp;str, flags: usize) -&gt; isize
</code></pre>

<p>The flags can be one or more of the following:</p>

<pre><code class="rust">enum OpenFlag {
Read = 1,
Write = 2,
Append = 4,
Create = 8,
Truncate = 16,
Dir = 32,
Device = 64,
}
</code></pre>

<h2>CLOSE (0x06)</h2>

<pre><code class="rust">fn close(handle: usize)
Expand All @@ -47,7 +60,7 @@ <h2>INFO (0x07)</h2>

<p>This syscall will set the following attributes of the given structure:</p>

<pre><code class="rust">pub struct FileInfo {
<pre><code class="rust">struct FileInfo {
kind: FileType,
size: u32,
time: u64,
Expand Down Expand Up @@ -82,19 +95,48 @@ <h2>POLL (0x0C)</h2>
<pre><code class="rust">fn poll(list: &amp;[(usize, IO)]) -&gt; isize
</code></pre>

<p>Given a list of file handles and <code>IO</code> operations:</p>

<pre><code class="rust">enum IO {
Read,
Write,
}
</code></pre>

<p>This syscall will return the index of the first file handle in the list that is
ready for the given <code>IO</code> operation or a negative number if no operations are
available for any file handles.</p>

<p>For example polling the console will notify when a line is ready to be read,
or polling a socket will notify when it can receive or send.</p>

<h2>CONNECT (0x0D)</h2>

<pre><code class="rust">fn connect(handle, usize, addr: &amp;str, port: u16) -&gt; isize
<pre><code class="rust">fn connect(handle, usize, addr: IpAddress, port: u16) -&gt; isize
</code></pre>

<p>Connect a socket to an endpoint at the given <code>IpAddress</code> and port:</p>

<pre><code class="rust">struct Ipv4Address(pub [u8; 4]);

struct Ipv6Address(pub [u8; 16]);

enum IpAddress {
Ipv4(Ipv4Address),
Ipv6(Ipv6Address),
}
</code></pre>

<p>NOTE: Only IPv4 is currently supported.</p>

<h2>LISTEN (0x0E)</h2>

<pre><code class="rust">fn listen(handle, usize, port: u16) -&gt; isize
</code></pre>

<h2>ACCEPT (0x0F)</h2>

<pre><code class="rust">fn accept(handle, usize, addr: &amp;str) -&gt; isize
<pre><code class="rust">fn accept(handle, usize, addr: IpAddress) -&gt; isize
</code></pre>

<h2>ALLOC (0x10)</h2>
Expand All @@ -115,7 +157,7 @@ <h2>KIND (0x12)</h2>
<p>This syscall will return a integer corresponding to the <code>FileType</code> of the given
file handle when successful:</p>

<pre><code class="rust">pub enum FileType {
<pre><code class="rust">enum FileType {
Dir = 0,
File = 1,
Device = 2,
Expand Down

0 comments on commit 2ac7cfd

Please sign in to comment.