aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-08 17:43:59 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-08 18:04:03 +0300
commite134202611a50b358c147c92bfb8a7f443030b8b (patch)
treeac7c31824adcf41a63e4d2c5e141f5149cc55b1a /include
parent7e828ec1e1479ff9a8afe845539d08ca0dfada5f (diff)
downloadkmi-e134202611a50b358c147c92bfb8a7f443030b8b.tar.gz
kmi-e134202611a50b358c147c92bfb8a7f443030b8b.zip
fix LLVM
+ Anything extern is right out as LLVM doesn't produce correct code for them. Maybe if I added some extra attributes but I'm skeptical. Replaced with static variables and getters/setters. + Inline ASM is apparently a bit buggy, so use an assembly stub when jumping to init. + Minimize work done in main() to minimize chance of LLVM doing something silly. Still not 100% certain that I shouldn't just write the main() as an assembly stub in arch/riscv64 to be absolutely sure everything works as intended. + Make .kernel.start section SHF_ALLOC, otherwise lld complains about pc-relative addressing Probably some other stuff as well that I'm forgetting right now. But at least with LLVM14 LTO seems to work, which is pretty cool?
Diffstat (limited to 'include')
-rw-r--r--include/arch/vmem.h6
-rw-r--r--include/kmi/bkl.h13
-rw-r--r--include/kmi/conf.h35
-rw-r--r--include/kmi/dmem.h12
-rw-r--r--include/kmi/mem.h110
5 files changed, 67 insertions, 109 deletions
diff --git a/include/arch/vmem.h b/include/arch/vmem.h
index e62c112..a19f555 100644
--- a/include/arch/vmem.h
+++ b/include/arch/vmem.h
@@ -148,10 +148,14 @@ vm_t setup_kernel_io(struct vmem *b, vm_t paddr);
* address space and the kernel address space in the other.
* Called at boot, not allowed to allocate memory.
*
+ * @param load_addr Where in physical memory kernel was loaded to. Could in
+ * theory be fetched from \ref get_load_addr(), but the fewer globals are
+ * touched during initialization the better.
+ *
* @return The vmem node used to build the address space. Probably statically
* allocated.
*/
-struct vmem *init_mapping();
+struct vmem *init_mapping(uintptr_t load_addr);
/**
* Create new virtual memory space.
diff --git a/include/kmi/bkl.h b/include/kmi/bkl.h
index 9ea6ccd..39e3ef9 100644
--- a/include/kmi/bkl.h
+++ b/include/kmi/bkl.h
@@ -12,19 +12,10 @@
#include <kmi/lock.h>
-/** Big Kenrel Lock. */
-extern spinlock_t bkl;
-
/** Lock the Big Kernel Lock. */
-static inline void bkl_lock()
-{
- spin_lock(&bkl);
-}
+void bkl_lock();
/** Unlock the Big Kernel Lock. */
-static inline void bkl_unlock()
-{
- spin_unlock(&bkl);
-}
+void bkl_unlock();
#endif /* KMI_BKL_H */
diff --git a/include/kmi/conf.h b/include/kmi/conf.h
index 8e33a5f..02b8c4f 100644
--- a/include/kmi/conf.h
+++ b/include/kmi/conf.h
@@ -14,36 +14,25 @@
/**
* Provides access to the runtime global parameter.
- * \remark Note that runtime parameter passing is not yet implemented, and I might
- * implement per-thread stack sizes as well.
- * \global
- * \todo This should probably be a function instead.
- */
-extern size_t __thread_stack_size;
-
-/**
- * Provides access to the runtime global parameter.
- * Must be at most RPC_STACK_TOP - RPC_STACK_BASE.
- * Essentially, each thread gets allocated this many bytes of total stack space
- * that will be used during thread migrations. Each migration instance may at
- * most take up __rpc_stack_size bytes, and during a thread migration the
- * currently available free stack space is checked.
- *
- * Previous instances are unmapped, making them unaccessible to the current
- * instance.
+ * @remark I might implement per-thread stack sizes at some point.
*
- * \see __thread_stack_size.
- * \global
- * \todo This should probably also be a function instead.
+ * @return Size of a regular thread stack, primarily just used to pass to \ref
+ * alloc_stack().
*/
-extern size_t __call_stack_size;
+size_t thread_stack_size();
/**
* Provides access to the runtime global parameter. This sets the maximum size
* a single rpc stack instance can be.
*
- * \global
+ * @return Size of one RPC stack entry, generally a single RPC shouldn't take
+ * up all of the available RPC stack space so we limit how much each call is
+ * allowed at a maximum, effectively enforcing a minimum number of RPC calls
+ * that a thread must be allowed to execute.
+ *
+ * I feel like this description is overly complicated but I can't think of a way
+ * to say it more clearly at the moment.
*/
-extern size_t __rpc_stack_size;
+size_t rpc_stack_size();
#endif /* KMI_CONF_H */
diff --git a/include/kmi/dmem.h b/include/kmi/dmem.h
index 6fd590f..697e55a 100644
--- a/include/kmi/dmem.h
+++ b/include/kmi/dmem.h
@@ -13,18 +13,6 @@
#include <kmi/types.h>
#include <kmi/vmem.h>
-/** Provides access to the global parameter. \global */
-extern pm_t __pre_base;
-
-/** Provides access to the global parameter. \global */
-extern pm_t __pre_top;
-
-/** Provides access to the global parameter. \global */
-extern pm_t __post_base;
-
-/** Provides access to the global parameter. \global */
-extern pm_t __post_top;
-
/**
* Initialize device memory.
* @note Currently I assume there is only one RAM region. This may not be the
diff --git a/include/kmi/mem.h b/include/kmi/mem.h
index e840683..6c62d31 100644
--- a/include/kmi/mem.h
+++ b/include/kmi/mem.h
@@ -13,6 +13,49 @@
#include <kmi/types.h>
#include <arch/mem.h>
+/** Maximum number of page orders allowed. Likely massively overkill. */
+#define NUM_ORDERS 10
+
+/** Give names to page orders. */
+enum mm_order {
+ /** NULL marker. */
+ MM_MIN = -1,
+
+ /** Base order. */
+ MM_O0 = 0,
+
+ /** Order 1. */
+ MM_O1 = 1,
+
+ /** Order 2. */
+ MM_O2 = 2,
+
+ /** Order 3. */
+ MM_O3 = 3,
+
+ /** Order 4. */
+ MM_O4 = 4,
+
+ /** Order 5. */
+ MM_O5 = 5,
+
+ /** Order 6. */
+ MM_O6 = 6,
+
+ /** Order 7. */
+ MM_O7 = 7,
+
+ /** Order 8. */
+ MM_O8 = 8,
+
+ /** Order 9. */
+ MM_O9 = 9,
+
+ /** Number of orders */
+ MM_NUM,
+};
+
+
/**
* Convert physical memory address \c paddr to index of page order \c order.
*
@@ -37,7 +80,7 @@
* @param order Order to query.
* @return Starting offset of order bits.
*/
-#define order_shift(order) (__mm_shifts[order])
+size_t order_shift(enum mm_order order);
/**
* Get number of order bits in an address.
@@ -45,7 +88,7 @@
* @param order Order to query.
* @return Width in bits of order bits.
*/
-#define order_width(order) (__mm_widths[order])
+size_t order_width(enum mm_order order);
/**
* Get size of order, as in how many pages of one order lower it can contain.
@@ -53,21 +96,21 @@
* @param order Order to query.
* @return Number of pages of one order lower this order can contain.
*/
-#define order_size(order) (__mm_sizes[order])
+size_t order_size(enum mm_order order);
/**
* Get highest order supported by the current configuration.
*
* @return Max supported order.
*/
-#define max_order() (__mm_max_order)
+enum mm_order max_order();
/**
* Get base page shift.
*
* @return Page shift.
*/
-#define page_shift() (__mm_page_shift)
+size_t page_shift();
/**
* Get number of elements needed to represent this order.
@@ -142,63 +185,6 @@
/** @} */
-/** Maximum number of page orders allowed. Likely massively overkill. */
-#define NUM_ORDERS 10
-
-/** Give names to page orders. */
-enum mm_order {
- /** NULL marker. */
- MM_MIN = -1,
-
- /** Base order. */
- MM_O0 = 0,
-
- /** Order 1. */
- MM_O1 = 1,
-
- /** Order 2. */
- MM_O2 = 2,
-
- /** Order 3. */
- MM_O3 = 3,
-
- /** Order 4. */
- MM_O4 = 4,
-
- /** Order 5. */
- MM_O5 = 5,
-
- /** Order 6. */
- MM_O6 = 6,
-
- /** Order 7. */
- MM_O7 = 7,
-
- /** Order 8. */
- MM_O8 = 8,
-
- /** Order 9. */
- MM_O9 = 9,
-
- /** Number of orders */
- MM_NUM,
-};
-
-/** Gives access to global page order shift information. \global */
-extern size_t __mm_shifts[NUM_ORDERS];
-
-/** Gives access to global page order width information. \global */
-extern size_t __mm_widths[NUM_ORDERS];
-
-/** Gives access to global page order size information. \global */
-extern size_t __mm_sizes[NUM_ORDERS];
-
-/** Gives access to global base page shift. \global */
-extern size_t __mm_page_shift;
-
-/** Gives access to global maximum order size. \global */
-extern enum mm_order __mm_max_order;
-
/**
* Find nearest order to size.
*