summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
Diffstat (limited to 'kern')
-rw-r--r--kern/bootstrap.c7
-rw-r--r--kern/limits.h29
-rw-r--r--kern/log2.h45
-rw-r--r--kern/startup.c2
-rw-r--r--kern/stdint.h30
-rw-r--r--kern/thread.c14
-rw-r--r--kern/thread.h2
7 files changed, 123 insertions, 6 deletions
diff --git a/kern/bootstrap.c b/kern/bootstrap.c
index a2ff8aa..93b104b 100644
--- a/kern/bootstrap.c
+++ b/kern/bootstrap.c
@@ -262,10 +262,9 @@ void bootstrap_create(void)
panic ("ERROR in executing boot script: %s",
boot_script_error_string (losers));
}
- /* XXX we could free the memory used
- by the boot loader's descriptors and such. */
- for (n = 0; n < boot_info.mods_count; n++)
- vm_page_create(bmods[n].mod_start, bmods[n].mod_end);
+
+ /* Free usable memory. */
+ /* XXX biosmem_free_usable(); */
}
static void
diff --git a/kern/limits.h b/kern/limits.h
new file mode 100644
index 0000000..fa46853
--- /dev/null
+++ b/kern/limits.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010-2014 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _KERN_LIMITS_H
+#define _KERN_LIMITS_H
+
+#define CHAR_BIT 8
+
+#ifdef __LP64__
+#define LONG_BIT 64
+#else /* __LP64__ */
+#define LONG_BIT 32
+#endif /* __LP64__ */
+
+#endif /* _KERN_LIMITS_H */
diff --git a/kern/log2.h b/kern/log2.h
new file mode 100644
index 0000000..c9cc5be
--- /dev/null
+++ b/kern/log2.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * Integer base 2 logarithm operations.
+ */
+
+#ifndef _KERN_LOG2_H
+#define _KERN_LOG2_H
+
+#include <kern/assert.h>
+#include <kern/limits.h>
+
+static inline unsigned int
+ilog2(unsigned long x)
+{
+ assert(x != 0);
+ return LONG_BIT - __builtin_clzl(x) - 1;
+}
+
+static inline unsigned int
+iorder2(unsigned long size)
+{
+ assert(size != 0);
+
+ if (size == 1)
+ return 0;
+
+ return ilog2(size - 1) + 1;
+}
+
+#endif /* _KERN_LOG2_H */
diff --git a/kern/startup.c b/kern/startup.c
index 30cff5c..bebb52c 100644
--- a/kern/startup.c
+++ b/kern/startup.c
@@ -110,8 +110,8 @@ void setup_main(void)
panic_init();
sched_init();
- vm_mem_bootstrap();
rdxtree_cache_init();
+ vm_mem_bootstrap();
ipc_bootstrap();
vm_mem_init();
ipc_init();
diff --git a/kern/stdint.h b/kern/stdint.h
new file mode 100644
index 0000000..d6794c4
--- /dev/null
+++ b/kern/stdint.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2010, 2011 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _KERN_STDINT_H
+#define _KERN_STDINT_H
+
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+
+#endif /* _KERN_STDINT_H */
diff --git a/kern/thread.c b/kern/thread.c
index 6137a33..e46035f 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -123,6 +123,15 @@ decl_simple_lock_data(, stack_lock_data)/* splsched only */
*/
static struct kmem_cache stack_cache;
+vm_offset_t
+thread_bootstrap_stack_alloc(void)
+{
+ vm_offset_t stack;
+ stack = kmem_cache_alloc(&stack_cache);
+ assert ((stack & (KERNEL_STACK_SIZE-1)) == 0);
+ return stack;
+}
+
/*
* stack_alloc_try:
*
@@ -220,7 +229,7 @@ void stack_privilege(
thread->stack_privilege = current_stack();
}
-void thread_init(void)
+void thread_bootstrap(void)
{
kmem_cache_init(&thread_cache, "thread", sizeof(struct thread), 0,
NULL, 0);
@@ -233,7 +242,10 @@ void thread_init(void)
kmem_cache_init(&stack_cache, "stack",
KERNEL_STACK_SIZE, KERNEL_STACK_SIZE,
NULL, 0);
+}
+void thread_init(void)
+{
/*
* Fill in a template thread for fast initialization.
* [Fields that must be (or are typically) reset at
diff --git a/kern/thread.h b/kern/thread.h
index adf8b86..9728e12 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -351,6 +351,8 @@ extern void stack_collect(void);
* Kernel-only routines
*/
+extern void thread_bootstrap(void);
+extern vm_offset_t thread_bootstrap_stack_alloc(void);
extern void thread_init(void);
extern void thread_reference(thread_t);
extern void thread_deallocate(thread_t);