summaryrefslogtreecommitdiff
path: root/arch/x86/machine/boot.h
blob: d30b3bebc5b948fa3ce32e24cb535d89a523f813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * 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 X86_BOOT_H
#define X86_BOOT_H

#include <stdnoreturn.h>

#include <kern/macros.h>
#include <machine/page.h>
#include <machine/pmap.h>

/*
 * Size of the stack used when booting a processor.
 */
#define BOOT_STACK_SIZE PAGE_SIZE

/*
 * Macros used by the very early panic functions.
 */
#define BOOT_CGAMEM     0xb8000
#define BOOT_CGACHARS   (80 * 25)
#define BOOT_CGACOLOR   0x7

/*
 * The kernel is physically loaded at BOOT_OFFSET by the boot loader. It
 * is divided in two parts: the .boot section which uses physical addresses
 * and the main kernel code and data at PMAP_KERNEL_OFFSET.
 *
 * See the linker script for more information.
 */
#define BOOT_OFFSET DECL_CONST(0x100000, UL)

/*
 * Virtual to physical address translation macro.
 */
#define BOOT_VTOP(addr) ((addr) - PMAP_KERNEL_OFFSET)

/*
 * Address where the MP trampoline code is copied and run at.
 *
 * It must reside at a free location in the first segment and be page
 * aligned.
 */
#define BOOT_MP_TRAMPOLINE_ADDR 0x7000

#ifndef __ASSEMBLER__

#include <kern/init.h>
#include <machine/multiboot.h>
#include <machine/pmap.h>

/*
 * Functions and data used before paging is enabled must be part of the .boot
 * and .bootdata sections respectively, so that they use physical addresses.
 * Once paging is enabled, their access relies on the kernel identity mapping.
 */
#define __boot __section(".boot.text")
#define __bootdata __section(".boot.data") __attribute__((used))

/*
 * Boundaries of the .boot section.
 */
extern char _boot;
extern char _boot_end;

/*
 * This variable contains the CPU ID of an AP during early initialization.
 */
extern unsigned int boot_ap_id;

/*
 * Size of the trampoline code used for APs.
 */
extern uint32_t boot_mp_trampoline_size;

/*
 * Address of the MP trampoline code.
 */
void boot_mp_trampoline(void);

/*
 * Helper functions available before paging is enabled.
 *
 * Any memory passed to these must also be accessible without paging.
 */
void * boot_memcpy(void *dest, const void *src, size_t n);
void * boot_memmove(void *dest, const void *src, size_t n);
void * boot_memset(void *s, int c, size_t n);
size_t boot_strlen(const char *s);
noreturn void 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(struct multiboot_raw_info *mbi,
                               unsigned long eax);

/*
 * Main entry point, called directly after basic paging is initialized.
 */
void boot_main(void);

/*
 * Entry point for APs.
 */
void boot_ap_main(void);

/*
 * Log kernel version and other architecture-specific information.
 */
void boot_log_info(void);

/*
 * This init operation provides :
 *  - boot data are saved
 */
INIT_OP_DECLARE(boot_save_data);

/*
 * This init operation provides :
 *  - all console devices are bootstrapped
 */
INIT_OP_DECLARE(boot_bootstrap_console);

/*
 * This init operation provides :
 *  - all console devices are fully initialized
 */
INIT_OP_DECLARE(boot_setup_console);

/*
 * This init operation provides :
 *  - physical memory has been loaded to the VM system
 */
INIT_OP_DECLARE(boot_load_vm_page_zones);

/*
 * This init operation provides :
 *  - all interrupt controllers have been registered
 */
INIT_OP_DECLARE(boot_setup_intr);

/*
 * This init operation provides :
 *  - all shutdown operations have been registered
 */
INIT_OP_DECLARE(boot_setup_shutdown);

#endif /* __ASSEMBLER__ */

#endif /* X86_BOOT_H */