Skip to content

Commit

Permalink
Fixes system calls with capability derive and read.
Browse files Browse the repository at this point in the history
  • Loading branch information
HAKarlsson committed Dec 4, 2024
1 parent cc7742e commit abb37cf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion common/src/s3k/s3k.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ s3k_cap_t s3k_mk_pmp(s3k_napot_t addr, s3k_rwx_t rwx)
return (s3k_cap_t){
.pmp = {
.type = S3K_CAPTY_PMP,
.addr = addr & 0xFFFFFFFFFF,
.addr = addr & 0xFFFFFFFF,
.rwx = rwx & 0x7,
.used = 0,
.slot = 0,
Expand Down
25 changes: 16 additions & 9 deletions common/src/s3k/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ typedef union {
struct {
s3k_val_t src_idx;
s3k_val_t dst_idx;
s3k_val_t cap_raw;
uint64_t cap_raw;
} cap_derive;

struct {
Expand Down Expand Up @@ -208,7 +208,7 @@ _Static_assert(sizeof(sys_args_t) == 32, "sys_args_t has the wrong size");
break; \
case 8: \
__asm__ volatile("ecall" \
: "=r"(t0), "+r"(a0) \
: "+r"(t0), "+r"(a0) \
: "r"(a1), "r"(a2), "r"(a3), "r"(a4), \
"r"(a5), "r"(a6), "r"(a7)); \
break; \
Expand Down Expand Up @@ -268,10 +268,12 @@ void s3k_sleep(s3k_val_t time)

s3k_err_t s3k_cap_read(s3k_cidx_t idx, s3k_cap_t *cap)
{
sys_args_t args = {.cap_read = {idx}};
s3k_ret_t ret = DO_ECALL(S3K_SYS_CAP_READ, args, sizeof(args.cap_read));
cap->raw = ret.val;
return ret.err;
register s3k_val_t t0 __asm__("t0") = S3K_SYS_CAP_READ;
register s3k_val_t a0 __asm__("a0") = idx;
register s3k_val_t a1 __asm__("a1");
__asm__ volatile("ecall" : "+r"(t0), "+r"(a0), "=r"(a1));
cap->raw = (uint64_t)a0 << 32 | (uint64_t)a1;
return t0;
}

s3k_err_t s3k_cap_move(s3k_cidx_t src, s3k_cidx_t dst)
Expand Down Expand Up @@ -563,9 +565,14 @@ s3k_err_t s3k_try_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid,
};
s3k_ret_t ret
= DO_ECALL(S3K_SYS_MON_CAP_READ, args, sizeof(args.mon_cap_read));
if (!ret.err)
cap->raw = ret.val;
return ret.err;
register s3k_val_t t0 __asm__("t0") = S3K_SYS_CAP_READ;
register s3k_val_t a0 __asm__("a0") = mon_idx;
register s3k_val_t a1 __asm__("a1") = pid;
register s3k_val_t a2 __asm__("a2") = idx;
__asm__ volatile("ecall" : "+r"(t0), "+r"(a0), "+r"(a1) : "r"(a2));
if (!t0)
cap->raw = (uint64_t)a0 << 32 | (uint64_t)a1;
return t0;
}

s3k_err_t s3k_try_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid,
Expand Down
2 changes: 1 addition & 1 deletion kernel/inc/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ typedef union {
struct {
val_t src_idx;
val_t dst_idx;
val_t cap_raw;
uint64_t cap_raw;
} cap_derive;

struct {
Expand Down

0 comments on commit abb37cf

Please sign in to comment.