summaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
authorstefan <stefan@s00.xyz>2023-04-15 05:02:02 +0000
committerstefan <stefan@s00.xyz>2023-04-15 05:02:02 +0000
commitaf1ce4b2e637ceb418ea72d51c49a3eee276a938 (patch)
tree4d6a33644f8489e4f582f6e320bd6581b94fb642 /sys/include
parent8cceb31dcaf4641d43f324fa3301b37859ebfade (diff)
downloadsv-af1ce4b2e637ceb418ea72d51c49a3eee276a938.tar.gz
added multiprocessor support
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/printf.h1
-rw-r--r--sys/include/sbi.h74
-rw-r--r--sys/include/spinlock.h8
3 files changed, 74 insertions, 9 deletions
diff --git a/sys/include/printf.h b/sys/include/printf.h
index 76debc3..fd9a092 100644
--- a/sys/include/printf.h
+++ b/sys/include/printf.h
@@ -2,6 +2,7 @@
#define _KPRINTF_H
int puts(const char *);
+void printf_init(void);
void printf(const char *, ...);
#endif /* _KPRINTF_H */
diff --git a/sys/include/sbi.h b/sys/include/sbi.h
index 0dbcd02..1c0fc7f 100644
--- a/sys/include/sbi.h
+++ b/sys/include/sbi.h
@@ -1,16 +1,76 @@
-#ifndef _SBICALL_H
-#define _SBICALL_H
+#ifndef _SBI_H
+#define _SBI_H
struct sbiret {
long err;
long val;
};
-struct sbiret sbi_ecall(int _eid, int _fid, unsigned long _a0, unsigned long _a1,
- unsigned long _a2, unsigned long _a3, unsigned long _a4, unsigned long _a5);
+#define SBI_SUCCESS 0
+#define SBI_ERR_FAILED -1
+#define SBI_ERR_NOT_SUPPORTED -2
+#define SBI_ERR_INVALD_PARAM -3
+#define SBI_ERR_DENIED -4
+#define SBI_ERR_INVALID_ADDRESS -5
+#define SBI_ERR_ALREADY_AVAILABLE -6
+#define SBI_ERR_ALREADY_STARTED -7
+#define SBI_ERR_ALREADY_STOPPED -8
-void sbi_console_putchar(int c);
-void sbi_shutdown(void);
+enum HART_STATUS {
+ STARTED,
+ STOPPED,
+ START_PENDING,
+ STOP_PENDING,
+ SUSPENDED,
+ SUSPEND_PENDING,
+ RESUME_PENDING
+};
+
+static inline struct sbiret
+sbi_ecall(int ext, int fid, unsigned long arg0,
+ unsigned long arg1, unsigned long arg2,
+ unsigned long arg3, unsigned long arg4,
+ unsigned long arg5)
+{
+ struct sbiret ret;
+
+ register unsigned long a0 asm ("a0") = (unsigned long)(arg0);
+ register unsigned long a1 asm ("a1") = (unsigned long)(arg1);
+ register unsigned long a2 asm ("a2") = (unsigned long)(arg2);
+ register unsigned long a3 asm ("a3") = (unsigned long)(arg3);
+ register unsigned long a4 asm ("a4") = (unsigned long)(arg4);
+ register unsigned long a5 asm ("a5") = (unsigned long)(arg5);
+ register unsigned long a6 asm ("a6") = (unsigned long)(fid);
+ register unsigned long a7 asm ("a7") = (unsigned long)(ext);
+ asm volatile ("ecall"
+ : "+r" (a0), "+r" (a1)
+ : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7)
+ : "memory");
+ ret.err = a0;
+ ret.val = a1;
+
+ return ret;
+}
+
+static inline void
+sbi_console_putchar(int c)
+{
+ sbi_ecall(1, 0, c, 0, 0, 0, 0, 0);
+}
+
+static inline void
+sbi_shutdown(void)
+{
+ sbi_ecall(8, 0, 0, 0, 0, 0, 0, 0);
+}
+
+static inline struct sbiret
+sbi_hart_start(unsigned long hartid, unsigned long start_addr, unsigned long opaque)
+{
+ struct sbiret r = sbi_ecall(0x48534D, 0, hartid, start_addr, opaque, 0, 0, 0);
+ return r;
+}
+#define _start_hart(tp, a) sbi_hart_start(tp, a, 0);
-#endif /* _SBICALL_H */
+#endif /* _SBI_H */
diff --git a/sys/include/spinlock.h b/sys/include/spinlock.h
index 3400445..ef81499 100644
--- a/sys/include/spinlock.h
+++ b/sys/include/spinlock.h
@@ -3,9 +3,13 @@
struct spinlock {
int locked;
- const char *name;
+ int tp;
};
-void initlock(struct spinlock *, const char *);
+void initlock(struct spinlock *);
+
+void acquire(struct spinlock *);
+
+void release(struct spinlock *);
#endif /* _LOCK_H */