From c4a0bc2571162ad83fc51eb823f1c535336041bf Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 16 Aug 2020 00:44:53 +0200 Subject: Added psf/gui to libgui ...and some other things --- libc/inc/assert.h | 11 +++++++++++ libc/inc/cpu.h | 3 +++ libc/inc/sys.h | 7 ++++++- 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/inc/assert.h b/libc/inc/assert.h index 91c4ccd..a553444 100644 --- a/libc/inc/assert.h +++ b/libc/inc/assert.h @@ -5,10 +5,21 @@ #include +#ifdef kernel #define assert(exp) \ if (!(exp)) { \ printf("%s:%d: %s: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp); \ __asm__ volatile("cli\nhlt"); \ } +#elif defined(userspace) +#include +#define assert(exp) \ + if (!(exp)) { \ + printf("%s:%d: %s: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp); \ + sys0(SYS_LOOP); \ + } +#else +#error "No lib target specified. Please use -Dkernel or -Duserspace" +#endif #endif diff --git a/libc/inc/cpu.h b/libc/inc/cpu.h index 2d367cb..c25dc60 100644 --- a/libc/inc/cpu.h +++ b/libc/inc/cpu.h @@ -13,11 +13,14 @@ void insl(u16 port, void *addr, int n); void outb(u16 port, u8 data); void outw(u16 port, u16 data); void outl(u16 port, u32 data); + +#ifdef kernel void cli(); void sti(); void hlt(); void idle(); void loop(); +#endif static inline void spinlock(int *ptr) { diff --git a/libc/inc/sys.h b/libc/inc/sys.h index 16d3c4f..d95b760 100644 --- a/libc/inc/sys.h +++ b/libc/inc/sys.h @@ -4,7 +4,9 @@ #ifndef SYS_H #define SYS_H -enum sys { SYS_LOOP, SYS_MALLOC, SYS_FREE, SYS_EXEC, SYS_EXIT }; +enum sys { SYS_LOOP, SYS_MALLOC, SYS_FREE, SYS_READ, SYS_WRITE, SYS_EXEC, SYS_EXIT }; + +#if defined(userspace) int sys0(enum sys num); int sys1(enum sys num, int d1); @@ -18,6 +20,8 @@ int sys5(enum sys num, int d1, int d2, int d3, int d4, int d5); */ #define loop() sys0(SYS_LOOP) +#define read(path) (void *)sys1(SYS_READ, (int)path) +#define write(path, buf) sys2(SYS_WRITE, (int)path, buf) #define exec(path) sys1(SYS_EXEC, (int)path) #define exit() \ sys0(SYS_EXIT); \ @@ -25,3 +29,4 @@ int sys5(enum sys num, int d1, int d2, int d3, int d4, int d5); } #endif +#endif -- cgit v1.2.3