Skip to content

Commit

Permalink
Adds kernel assert statements
Browse files Browse the repository at this point in the history
  • Loading branch information
HAKarlsson committed Nov 6, 2023
1 parent e5be7e7 commit 50657b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/inc/plat/qemu_virt.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define INIT_CAPS \
{ \
[0] = cap_mk_pmp(0x20005fff, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x80100000, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \
[2] = cap_mk_memory(0x10000000, 0x10001000, MEM_RW), \
[3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \
[4] = cap_mk_time(0, 0, S3K_SLOT_CNT), \
Expand Down
2 changes: 1 addition & 1 deletion common/inc/plat/sifive_unleashed.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define INIT_CAPS \
{ \
[0] = cap_mk_pmp(0x20005fff, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x80100000, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \
[2] = cap_mk_memory(0x10010000, 0x10011000, MEM_RW), \
[3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \
[4] = cap_mk_time(1, 0, S3K_SLOT_CNT), \
Expand Down
13 changes: 13 additions & 0 deletions kernel/src/cap_util.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#include "cap_util.h"

#include "altc/altio.h"
#include "kassert.h"

cap_t cap_mk_time(hart_t hart, time_slot_t bgn, time_slot_t end)
{
KASSERT(bgn < end);
#if S3K_MIN_HART > 0
KASSERT(hart >= S3K_MIN_HART);
#endif
KASSERT(hart <= S3K_MAX_HART);
KASSERT(end <= S3K_SLOT_CNT);
cap_t cap;
cap.type = CAPTY_TIME;
cap.time.hart = hart;
Expand All @@ -16,6 +23,8 @@ cap_t cap_mk_time(hart_t hart, time_slot_t bgn, time_slot_t end)
cap_t cap_mk_memory(addr_t bgn, addr_t end, rwx_t rwx)
{
uint64_t tag = bgn >> MAX_BLOCK_SIZE;
KASSERT(bgn < end);
KASSERT(end <= (tag + 1) << MAX_BLOCK_SIZE);
cap_t cap;
cap.mem.type = CAPTY_MEMORY;
cap.mem.tag = tag;
Expand All @@ -40,6 +49,8 @@ cap_t cap_mk_pmp(napot_t addr, rwx_t rwx)

cap_t cap_mk_monitor(pid_t bgn, pid_t end)
{
KASSERT(bgn < end);
KASSERT(end <= S3K_PROC_CNT);
cap_t cap;
cap.mon.type = CAPTY_MONITOR;
cap.mon.bgn = bgn;
Expand All @@ -50,6 +61,8 @@ cap_t cap_mk_monitor(pid_t bgn, pid_t end)

cap_t cap_mk_channel(chan_t bgn, chan_t end)
{
KASSERT(bgn < end);
KASSERT(end <= S3K_CHAN_CNT);
cap_t cap;
cap.chan.type = CAPTY_CHANNEL;
cap.chan.bgn = bgn;
Expand Down

0 comments on commit 50657b0

Please sign in to comment.