summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86/Makefrag.am5
-rw-r--r--arch/x86/machine/biosmem.c7
-rw-r--r--arch/x86/machine/boot.c (renamed from arch/x86/machine/init.c)61
-rw-r--r--arch/x86/machine/boot.h68
-rw-r--r--arch/x86/machine/boot_asm.S (renamed from arch/x86/machine/boot.S)32
-rw-r--r--arch/x86/machine/cpu.c13
-rw-r--r--arch/x86/machine/init.h82
-rw-r--r--arch/x86/machine/param.h15
8 files changed, 128 insertions, 155 deletions
diff --git a/arch/x86/Makefrag.am b/arch/x86/Makefrag.am
index 7a905e54..929c1d33 100644
--- a/arch/x86/Makefrag.am
+++ b/arch/x86/Makefrag.am
@@ -18,14 +18,13 @@ x15_SOURCES += \
arch/x86/machine/acpimp.h \
arch/x86/machine/biosmem.c \
arch/x86/machine/biosmem.h \
+ arch/x86/machine/boot.c \
+ arch/x86/machine/boot_asm.S \
arch/x86/machine/boot.h \
- arch/x86/machine/boot.S \
arch/x86/machine/cpu.c \
arch/x86/machine/cpu_asm.S \
arch/x86/machine/cpu.h \
arch/x86/machine/endian.h \
- arch/x86/machine/init.c \
- arch/x86/machine/init.h \
arch/x86/machine/io.h \
arch/x86/machine/lapic.c \
arch/x86/machine/lapic.h \
diff --git a/arch/x86/machine/biosmem.c b/arch/x86/machine/biosmem.c
index 1ae2dbd5..c761a772 100644
--- a/arch/x86/machine/biosmem.c
+++ b/arch/x86/machine/biosmem.c
@@ -27,7 +27,6 @@
#include <lib/string.h>
#include <machine/biosmem.h>
#include <machine/boot.h>
-#include <machine/init.h>
#include <machine/multiboot.h>
#include <vm/vm_kmem.h>
#include <vm/vm_page.h>
@@ -220,7 +219,7 @@ biosmem_setup_allocator(struct multiboot_info *mbi)
max_heap_end = vm_page_trunc(max_heap_end);
if (max_heap_start >= max_heap_end)
- init_panic("unable to find memory for the boot allocator");
+ boot_panic("unable to find memory for the boot allocator");
biosmem_heap_start = max_heap_start;
biosmem_heap_free = max_heap_start;
@@ -279,14 +278,14 @@ biosmem_bootalloc(unsigned int nr_pages)
char *ptr;
if (nr_pages == 0)
- init_panic("attempt to allocate 0 pages");
+ boot_panic("attempt to allocate 0 pages");
free = biosmem_heap_free;
page = free;
free += PAGE_SIZE * nr_pages;
if ((free <= biosmem_heap_start) || (free > biosmem_heap_end))
- init_panic("unable to allocate memory");
+ boot_panic("unable to allocate memory");
biosmem_heap_free = free;
diff --git a/arch/x86/machine/init.c b/arch/x86/machine/boot.c
index ac1b3474..ea864cd6 100644
--- a/arch/x86/machine/init.c
+++ b/arch/x86/machine/boot.c
@@ -26,7 +26,6 @@
#include <machine/biosmem.h>
#include <machine/boot.h>
#include <machine/cpu.h>
-#include <machine/init.h>
#include <machine/multiboot.h>
#include <machine/pit.h>
#include <machine/pmap.h>
@@ -43,18 +42,18 @@
#define INIT_VGACHARS (80 * 25)
#define INIT_VGACOLOR 0x7
-char init_stack[BOOT_STACK_SIZE] __aligned(8) __bootdata;
-char init_ap_stack[BOOT_STACK_SIZE] __aligned(8) __bootdata;
-unsigned long init_ap_id __bootdata;
-unsigned long init_ap_boot_stack_addr __bootdata;
+char boot_stack[BOOT_STACK_SIZE] __aligned(8) __bootdata;
+char boot_ap_stack[BOOT_STACK_SIZE] __aligned(8) __bootdata;
+unsigned long boot_ap_id __bootdata;
+unsigned long boot_ap_stack_addr __bootdata;
/*
* Copy of the multiboot data passed by the boot loader.
*/
-static struct multiboot_info init_mbi __bootdata;
+static struct multiboot_info boot_mbi __bootdata;
void __boot
-init_panic(const char *msg)
+boot_panic(const char *msg)
{
uint16_t *ptr, *end;
const char *s;
@@ -81,23 +80,23 @@ init_panic(const char *msg)
}
pmap_pte_t * __boot
-init_paging(uint32_t eax, const struct multiboot_info *mbi)
+boot_setup_paging(uint32_t eax, const struct multiboot_info *mbi)
{
pmap_pte_t *pdir, *ptps, *pte, *id_pte;
unsigned long i, nr_pages, nr_ptps, kern_start, kern_end;
if (eax != MULTIBOOT_LOADER_MAGIC)
- init_panic("not started by a multiboot compliant boot loader");
+ boot_panic("not started by a multiboot compliant boot loader");
if (!(mbi->flags & MULTIBOOT_LOADER_MEMORY))
- init_panic("missing basic memory information");
+ boot_panic("missing basic memory information");
/*
* Save the multiboot data passed by the boot loader and initialize the
* bootstrap allocator.
*/
- init_mbi = *mbi;
- biosmem_bootstrap(&init_mbi);
+ boot_mbi = *mbi;
+ biosmem_bootstrap(&boot_mbi);
/*
* Create the kernel virtual mapping. Two mappings are actually established,
@@ -150,7 +149,7 @@ init_paging(uint32_t eax, const struct multiboot_info *mbi)
}
pmap_pte_t * __boot
-init_ap_paging(void)
+boot_ap_setup_paging(void)
{
#ifdef PAE
cpu_enable_pae();
@@ -164,7 +163,7 @@ init_ap_paging(void)
* Copy physical memory into a kernel allocated buffer.
*/
static void * __init
-init_save_boot_data_copy(const void *ptr, size_t size)
+boot_save_boot_data_copy(const void *ptr, size_t size)
{
unsigned long map_addr;
size_t map_size;
@@ -196,41 +195,41 @@ init_save_boot_data_copy(const void *ptr, size_t size)
* TODO Handle more boot data such as debugging symbols.
*/
static void __init
-init_save_boot_data(void)
+boot_save_boot_data(void)
{
uint32_t i;
- if (init_mbi.flags & MULTIBOOT_LOADER_CMDLINE)
- init_mbi.cmdline = init_save_boot_data_copy(init_mbi.cmdline,
- init_mbi.unused0);
+ if (boot_mbi.flags & MULTIBOOT_LOADER_CMDLINE)
+ boot_mbi.cmdline = boot_save_boot_data_copy(boot_mbi.cmdline,
+ boot_mbi.unused0);
else
- init_mbi.cmdline = NULL;
+ boot_mbi.cmdline = NULL;
- if (init_mbi.flags & MULTIBOOT_LOADER_MODULES) {
+ if (boot_mbi.flags & MULTIBOOT_LOADER_MODULES) {
struct multiboot_module *mod;
size_t size;
- size = init_mbi.mods_count * sizeof(struct multiboot_module);
- init_mbi.mods_addr = init_save_boot_data_copy(init_mbi.mods_addr, size);
+ size = boot_mbi.mods_count * sizeof(struct multiboot_module);
+ boot_mbi.mods_addr = boot_save_boot_data_copy(boot_mbi.mods_addr, size);
- for (i = 0; i < init_mbi.mods_count; i++) {
- mod = &init_mbi.mods_addr[i];
+ for (i = 0; i < boot_mbi.mods_count; i++) {
+ mod = &boot_mbi.mods_addr[i];
size = mod->mod_end - mod->mod_start;
- mod->mod_start = init_save_boot_data_copy(mod->mod_start, size);
+ mod->mod_start = boot_save_boot_data_copy(mod->mod_start, size);
mod->mod_end = mod->mod_start + size;
if (mod->string != NULL)
- mod->string = init_save_boot_data_copy(mod->string,
+ mod->string = boot_save_boot_data_copy(mod->string,
mod->reserved);
}
} else {
- init_mbi.mods_count = 0;
- init_mbi.mods_addr = NULL;
+ boot_mbi.mods_count = 0;
+ boot_mbi.mods_addr = NULL;
}
}
void __init
-init(void)
+boot_main(void)
{
cpu_setup();
pmap_bootstrap();
@@ -240,7 +239,7 @@ init(void)
cpu_info(cpu_current());
biosmem_setup();
vm_setup();
- init_save_boot_data();
+ boot_save_boot_data();
biosmem_free_usable();
vm_phys_info();
pit_setup();
@@ -251,7 +250,7 @@ init(void)
}
void __init
-init_ap(void)
+boot_ap(void)
{
cpu_ap_setup();
cpu_info(cpu_current());
diff --git a/arch/x86/machine/boot.h b/arch/x86/machine/boot.h
index 69b8f5a2..4c7efb54 100644
--- a/arch/x86/machine/boot.h
+++ b/arch/x86/machine/boot.h
@@ -19,6 +19,7 @@
#define _X86_BOOT_H
#include <lib/macros.h>
+#include <machine/param.h>
/*
* The kernel is physically loaded at BOOT_OFFSET by the boot loader. It
@@ -31,13 +32,13 @@
#ifdef __LP64__
#define KERNEL_OFFSET DECL_CONST(0xffffffff80000000, UL)
#else /* __LP64__ */
-#define KERNEL_OFFSET DECL_CONST(0xc0000000, UL)
+#define KERNEL_OFFSET VM_MAX_ADDRESS
#endif /* __LP64__ */
/*
* Size of the stack used to bootstrap the kernel.
*/
-#define BOOT_STACK_SIZE 4096
+#define BOOT_STACK_SIZE PAGE_SIZE
/*
* Address where the MP trampoline code is copied and run at.
@@ -49,7 +50,9 @@
#ifndef __ASSEMBLY__
-#include <lib/macros.h>
+#include <lib/stdint.h>
+#include <machine/multiboot.h>
+#include <machine/pmap.h>
/*
* Virtual to physical address translation macro.
@@ -71,14 +74,69 @@ extern char _boot;
extern char _eboot;
/*
+ * Stack used to bootstrap the kernel.
+ */
+extern char boot_stack[BOOT_STACK_SIZE];
+
+/*
+ * Common stack used by APs to bootstrap.
+ */
+extern char boot_ap_stack[BOOT_STACK_SIZE];
+
+/*
+ * This variable contains the CPU ID of an AP during its early boot.
+ */
+extern unsigned long boot_ap_id;
+
+/*
+ * After its early boot, an AP enables paging and jumps to virtual
+ * addresses. At this point, it switches to a per-AP preallocated
+ * stack. This variable contains the (virtual) address of that stack.
+ */
+extern unsigned long boot_ap_stack_addr;
+
+/*
* Size of the trampoline code used for APs.
*/
-extern unsigned long boot_ap_size;
+extern unsigned long boot_mp_trampoline_size;
/*
* Address of the MP trampoline code.
*/
-void boot_ap_start(void);
+void boot_mp_trampoline(void);
+
+/*
+ * Print the given message and halt the system immediately.
+ *
+ * This function allows early initialization code to print something helpful
+ * before printk is available.
+ */
+void __noreturn boot_panic(const char *s);
+
+/*
+ * This function is called by the bootstrap code before paging is enabled.
+ * It establishes a direct mapping of the kernel at virtual addresses and
+ * returns the physical address of the page directory. It is up to the
+ * caller to actually enable paging.
+ */
+pmap_pte_t * boot_setup_paging(uint32_t eax, const struct multiboot_info *mbi);
+
+/*
+ * This function is called by the AP bootstrap code before paging is enabled.
+ * It merely returns the physical address of the already existing kernel page
+ * directory.
+ */
+pmap_pte_t * boot_ap_setup_paging(void);
+
+/*
+ * Main entry point, called directly after basic paging is initialized.
+ */
+void boot_main(void);
+
+/*
+ * Entry point for APs.
+ */
+void boot_ap(void);
#endif /* __ASSEMBLY__ */
diff --git a/arch/x86/machine/boot.S b/arch/x86/machine/boot_asm.S
index ece1bb89..e8d10697 100644
--- a/arch/x86/machine/boot.S
+++ b/arch/x86/machine/boot_asm.S
@@ -27,7 +27,7 @@
* the MP trampoline code.
*/
#define BOOT_MP_ADDR_PTOT(addr) (BOOT_MP_TRAMPOLINE_ADDR + (addr) \
- - boot_ap_start)
+ - boot_mp_trampoline)
.section .boothdr, "wax"
@@ -71,9 +71,9 @@ ENTRY(_start)
#endif
/*
- * Set up the init stack.
+ * Set up the boot stack.
*/
- movl $(init_stack + BOOT_STACK_SIZE), %esp
+ movl $(boot_stack + BOOT_STACK_SIZE), %esp
movl %esp, %ebp
/*
@@ -81,7 +81,7 @@ ENTRY(_start)
*/
pushl %ebx
pushl %eax
- call init_paging
+ call boot_setup_paging
movl %eax, %cr3
movl %cr0, %eax
orl $CPU_CR0_PG, %eax
@@ -95,14 +95,14 @@ ENTRY(_start)
/*
* Reset the stack, use high addresses.
*/
- movl $(init_stack + BOOT_STACK_SIZE + KERNEL_OFFSET), %esp
+ movl $(boot_stack + BOOT_STACK_SIZE + KERNEL_OFFSET), %esp
movl %esp, %ebp
/*
* Prevent stack tracing from searching previous frames.
*/
pushl $0
- jmp init
+ jmp boot_main
#endif /* __LP64__ */
/*
@@ -138,15 +138,15 @@ ENTRY(boot_ap_start32)
1:
/*
- * Set up the init stack.
+ * Set up the boot stack.
*/
- movl $(init_ap_stack + BOOT_STACK_SIZE), %esp
+ movl $(boot_ap_stack + BOOT_STACK_SIZE), %esp
movl %esp, %ebp
/*
* Enable paging.
*/
- call init_ap_paging
+ call boot_ap_setup_paging
movl %eax, %cr3
movl %cr0, %eax
orl $CPU_CR0_PG, %eax
@@ -157,7 +157,7 @@ ENTRY(boot_ap_start32)
/*
* Switch to the boot stack preallocated for this AP by the BSP.
*/
- movl init_ap_boot_stack_addr, %esp
+ movl boot_ap_stack_addr, %esp
addl $BOOT_STACK_SIZE, %esp
movl %esp, %ebp
@@ -165,7 +165,7 @@ ENTRY(boot_ap_start32)
* Prevent stack tracing from searching previous frames.
*/
pushl $0
- jmp init_ap
+ jmp boot_ap
/*
* Never reached.
@@ -178,7 +178,7 @@ END(boot_ap_start32)
* must enable protected mode to jump back into the kernel.
*/
.align 8
-ENTRY(boot_ap_start)
+ENTRY(boot_mp_trampoline)
.code16
cli
xorw %ax, %ax
@@ -204,7 +204,7 @@ ENTRY(boot_ap_start)
movw %ax, %fs
movw %ax, %gs
ljmp $8, $boot_ap_start32
-END(boot_ap_start)
+END(boot_mp_trampoline)
DATA(boot_ap_gdtr)
.word (8 * 3)
@@ -238,6 +238,6 @@ DATA(boot_gdt)
.word 0x00cf
END(boot_gdt)
-DATA(boot_ap_size)
- .long . - boot_ap_start
-END(boot_ap_size)
+DATA(boot_mp_trampoline_size)
+ .long . - boot_mp_trampoline
+END(boot_mp_trampoline_size)
diff --git a/arch/x86/machine/cpu.c b/arch/x86/machine/cpu.c
index 0595f76d..cab7624d 100644
--- a/arch/x86/machine/cpu.c
+++ b/arch/x86/machine/cpu.c
@@ -28,7 +28,6 @@
#include <machine/biosmem.h>
#include <machine/boot.h>
#include <machine/cpu.h>
-#include <machine/init.h>
#include <machine/io.h>
#include <machine/lapic.h>
#include <machine/mps.h>
@@ -353,16 +352,16 @@ cpu_mp_start_aps(void)
assert(BOOT_MP_TRAMPOLINE_ADDR < BIOSMEM_BASE);
assert(vm_page_aligned(BOOT_MP_TRAMPOLINE_ADDR));
- assert(boot_ap_size <= PAGE_SIZE);
+ assert(boot_mp_trampoline_size <= PAGE_SIZE);
/* Set up the AP trampoline code */
- ptr = vm_kmem_map_pa(BOOT_MP_TRAMPOLINE_ADDR, boot_ap_size,
+ ptr = vm_kmem_map_pa(BOOT_MP_TRAMPOLINE_ADDR, boot_mp_trampoline_size,
&map_addr, &map_size);
if (ptr == NULL)
panic("cpu: unable to map trampoline area in kernel map");
- memcpy(ptr, boot_ap_start, boot_ap_size);
+ memcpy(ptr, boot_mp_trampoline, boot_mp_trampoline_size);
vm_kmem_unmap_pa(map_addr, map_size);
/* Set up the warm reset vector */
@@ -389,8 +388,8 @@ cpu_mp_start_aps(void)
if (cpu->boot_stack == 0)
panic("unable to allocate boot stack for cpu%u", i);
- init_ap_id = i;
- init_ap_boot_stack_addr = cpu->boot_stack;
+ boot_ap_id = i;
+ boot_ap_stack_addr = cpu->boot_stack;
lapic_ipi_init_assert(cpu->apic_id);
cpu_delay(200);
@@ -447,7 +446,7 @@ cpu_mp_setup(void)
void __init
cpu_ap_setup(void)
{
- cpu_init(&cpu_array[init_ap_id]);
+ cpu_init(&cpu_array[boot_ap_id]);
cpu_check(cpu_current());
lapic_ap_setup();
}
diff --git a/arch/x86/machine/init.h b/arch/x86/machine/init.h
deleted file mode 100644
index 79122c4d..00000000
--- a/arch/x86/machine/init.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2010, 2012 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 _X86_INIT_H
-#define _X86_INIT_H
-
-#include <lib/macros.h>
-#include <lib/stdint.h>
-#include <machine/boot.h>
-#include <machine/multiboot.h>
-#include <machine/pmap.h>
-
-/*
- * Stack used to bootstrap the kernel.
- */
-extern char init_stack[BOOT_STACK_SIZE];
-
-/*
- * Common stack used by APs to bootstrap.
- */
-extern char init_ap_stack[BOOT_STACK_SIZE];
-
-/*
- * This variable contains the CPU ID of an AP during its early boot.
- */
-extern unsigned long init_ap_id;
-
-/*
- * After its early boot, an AP enables paging and jumps to virtual
- * addresses. At this point, it switches to a per-AP preallocated
- * stack. This variable contains the (virtual) address of that stack.
- */
-extern unsigned long init_ap_boot_stack_addr;
-
-/*
- * Print the given message and halt the system immediately.
- *
- * This function allows early initialization code to print something helpful
- * before printk is available.
- */
-void __noreturn init_panic(const char *s);
-
-/*
- * This function is called by the bootstrap code before paging is enabled.
- * It establishes a direct mapping of the kernel at virtual addresses and
- * returns the physical address of the page directory. It is up to the
- * caller to actually enable paging.
- */
-pmap_pte_t * init_paging(uint32_t eax, const struct multiboot_info *mbi);
-
-/*
- * This function is called by the AP bootstrap code before paging is enabled.
- * It merely returns the physical address of the already existing kernel page
- * directory.
- */
-pmap_pte_t * init_ap_paging(void);
-
-/*
- * Main entry point, called directly after basic paging is initialized.
- */
-void init(void);
-
-/*
- * Entry point for APs.
- */
-void init_ap(void);
-
-#endif /* _X86_INIT_H */
diff --git a/arch/x86/machine/param.h b/arch/x86/machine/param.h
index 2b5553d7..d806b192 100644
--- a/arch/x86/machine/param.h
+++ b/arch/x86/machine/param.h
@@ -18,7 +18,6 @@
#ifndef _X86_PARAM_H
#define _X86_PARAM_H
-#include <machine/boot.h>
#include <lib/macros.h>
#define __LITTLE_ENDIAN__
@@ -38,18 +37,20 @@
/*
* 4 KiB virtual pages.
*/
-#define PAGE_SHIFT 12
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1 << PAGE_SHIFT)
+#define PAGE_MASK (PAGE_SIZE - 1)
/*
- * User space boundaries.
+ * Kernel stack size for threads and interrupt handlers.
*/
-#define VM_MIN_ADDRESS DECL_CONST(0, UL)
-#define VM_MAX_ADDRESS KERNEL_OFFSET
+#define STACK_SIZE PAGE_SIZE
/*
- * Kernel stack size for threads and interrupt handlers.
+ * User space boundaries.
*/
-#define STACK_SIZE 4096
+#define VM_MIN_ADDRESS DECL_CONST(0, UL)
+#define VM_MAX_ADDRESS DECL_CONST(0xc0000000, UL)
/*
* Size of a linear mapping of PTEs (see the pmap module).