0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOT_BOOT_H
0015 #define BOOT_BOOT_H
0016
0017 #define STACK_SIZE 1024
0018
0019 #ifndef __ASSEMBLY__
0020
0021 #include <linux/stdarg.h>
0022 #include <linux/types.h>
0023 #include <linux/edd.h>
0024 #include <asm/setup.h>
0025 #include <asm/asm.h>
0026 #include "bitops.h"
0027 #include "ctype.h"
0028 #include "cpuflags.h"
0029 #include "io.h"
0030
0031
0032 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
0033
0034 extern struct setup_header hdr;
0035 extern struct boot_params boot_params;
0036
0037 #define cpu_relax() asm volatile("rep; nop")
0038
0039 static inline void io_delay(void)
0040 {
0041 const u16 DELAY_PORT = 0x80;
0042 outb(0, DELAY_PORT);
0043 }
0044
0045
0046
0047 static inline u16 ds(void)
0048 {
0049 u16 seg;
0050 asm("movw %%ds,%0" : "=rm" (seg));
0051 return seg;
0052 }
0053
0054 static inline void set_fs(u16 seg)
0055 {
0056 asm volatile("movw %0,%%fs" : : "rm" (seg));
0057 }
0058 static inline u16 fs(void)
0059 {
0060 u16 seg;
0061 asm volatile("movw %%fs,%0" : "=rm" (seg));
0062 return seg;
0063 }
0064
0065 static inline void set_gs(u16 seg)
0066 {
0067 asm volatile("movw %0,%%gs" : : "rm" (seg));
0068 }
0069 static inline u16 gs(void)
0070 {
0071 u16 seg;
0072 asm volatile("movw %%gs,%0" : "=rm" (seg));
0073 return seg;
0074 }
0075
0076 typedef unsigned int addr_t;
0077
0078 static inline u8 rdfs8(addr_t addr)
0079 {
0080 u8 *ptr = (u8 *)absolute_pointer(addr);
0081 u8 v;
0082 asm volatile("movb %%fs:%1,%0" : "=q" (v) : "m" (*ptr));
0083 return v;
0084 }
0085 static inline u16 rdfs16(addr_t addr)
0086 {
0087 u16 *ptr = (u16 *)absolute_pointer(addr);
0088 u16 v;
0089 asm volatile("movw %%fs:%1,%0" : "=r" (v) : "m" (*ptr));
0090 return v;
0091 }
0092 static inline u32 rdfs32(addr_t addr)
0093 {
0094 u32 *ptr = (u32 *)absolute_pointer(addr);
0095 u32 v;
0096 asm volatile("movl %%fs:%1,%0" : "=r" (v) : "m" (*ptr));
0097 return v;
0098 }
0099
0100 static inline void wrfs8(u8 v, addr_t addr)
0101 {
0102 u8 *ptr = (u8 *)absolute_pointer(addr);
0103 asm volatile("movb %1,%%fs:%0" : "+m" (*ptr) : "qi" (v));
0104 }
0105 static inline void wrfs16(u16 v, addr_t addr)
0106 {
0107 u16 *ptr = (u16 *)absolute_pointer(addr);
0108 asm volatile("movw %1,%%fs:%0" : "+m" (*ptr) : "ri" (v));
0109 }
0110 static inline void wrfs32(u32 v, addr_t addr)
0111 {
0112 u32 *ptr = (u32 *)absolute_pointer(addr);
0113 asm volatile("movl %1,%%fs:%0" : "+m" (*ptr) : "ri" (v));
0114 }
0115
0116 static inline u8 rdgs8(addr_t addr)
0117 {
0118 u8 *ptr = (u8 *)absolute_pointer(addr);
0119 u8 v;
0120 asm volatile("movb %%gs:%1,%0" : "=q" (v) : "m" (*ptr));
0121 return v;
0122 }
0123 static inline u16 rdgs16(addr_t addr)
0124 {
0125 u16 *ptr = (u16 *)absolute_pointer(addr);
0126 u16 v;
0127 asm volatile("movw %%gs:%1,%0" : "=r" (v) : "m" (*ptr));
0128 return v;
0129 }
0130 static inline u32 rdgs32(addr_t addr)
0131 {
0132 u32 *ptr = (u32 *)absolute_pointer(addr);
0133 u32 v;
0134 asm volatile("movl %%gs:%1,%0" : "=r" (v) : "m" (*ptr));
0135 return v;
0136 }
0137
0138 static inline void wrgs8(u8 v, addr_t addr)
0139 {
0140 u8 *ptr = (u8 *)absolute_pointer(addr);
0141 asm volatile("movb %1,%%gs:%0" : "+m" (*ptr) : "qi" (v));
0142 }
0143 static inline void wrgs16(u16 v, addr_t addr)
0144 {
0145 u16 *ptr = (u16 *)absolute_pointer(addr);
0146 asm volatile("movw %1,%%gs:%0" : "+m" (*ptr) : "ri" (v));
0147 }
0148 static inline void wrgs32(u32 v, addr_t addr)
0149 {
0150 u32 *ptr = (u32 *)absolute_pointer(addr);
0151 asm volatile("movl %1,%%gs:%0" : "+m" (*ptr) : "ri" (v));
0152 }
0153
0154
0155 static inline bool memcmp_fs(const void *s1, addr_t s2, size_t len)
0156 {
0157 bool diff;
0158 asm volatile("fs; repe; cmpsb" CC_SET(nz)
0159 : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
0160 return diff;
0161 }
0162 static inline bool memcmp_gs(const void *s1, addr_t s2, size_t len)
0163 {
0164 bool diff;
0165 asm volatile("gs; repe; cmpsb" CC_SET(nz)
0166 : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
0167 return diff;
0168 }
0169
0170
0171 extern char _end[];
0172 extern char *HEAP;
0173 extern char *heap_end;
0174 #define RESET_HEAP() ((void *)( HEAP = _end ))
0175 static inline char *__get_heap(size_t s, size_t a, size_t n)
0176 {
0177 char *tmp;
0178
0179 HEAP = (char *)(((size_t)HEAP+(a-1)) & ~(a-1));
0180 tmp = HEAP;
0181 HEAP += s*n;
0182 return tmp;
0183 }
0184 #define GET_HEAP(type, n) \
0185 ((type *)__get_heap(sizeof(type),__alignof__(type),(n)))
0186
0187 static inline bool heap_free(size_t n)
0188 {
0189 return (int)(heap_end-HEAP) >= (int)n;
0190 }
0191
0192
0193
0194 void copy_to_fs(addr_t dst, void *src, size_t len);
0195 void *copy_from_fs(void *dst, addr_t src, size_t len);
0196 void copy_to_gs(addr_t dst, void *src, size_t len);
0197 void *copy_from_gs(void *dst, addr_t src, size_t len);
0198
0199
0200 int enable_a20(void);
0201
0202
0203 int query_apm_bios(void);
0204
0205
0206 struct biosregs {
0207 union {
0208 struct {
0209 u32 edi;
0210 u32 esi;
0211 u32 ebp;
0212 u32 _esp;
0213 u32 ebx;
0214 u32 edx;
0215 u32 ecx;
0216 u32 eax;
0217 u32 _fsgs;
0218 u32 _dses;
0219 u32 eflags;
0220 };
0221 struct {
0222 u16 di, hdi;
0223 u16 si, hsi;
0224 u16 bp, hbp;
0225 u16 _sp, _hsp;
0226 u16 bx, hbx;
0227 u16 dx, hdx;
0228 u16 cx, hcx;
0229 u16 ax, hax;
0230 u16 gs, fs;
0231 u16 es, ds;
0232 u16 flags, hflags;
0233 };
0234 struct {
0235 u8 dil, dih, edi2, edi3;
0236 u8 sil, sih, esi2, esi3;
0237 u8 bpl, bph, ebp2, ebp3;
0238 u8 _spl, _sph, _esp2, _esp3;
0239 u8 bl, bh, ebx2, ebx3;
0240 u8 dl, dh, edx2, edx3;
0241 u8 cl, ch, ecx2, ecx3;
0242 u8 al, ah, eax2, eax3;
0243 };
0244 };
0245 };
0246 void intcall(u8 int_no, const struct biosregs *ireg, struct biosregs *oreg);
0247
0248
0249 int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *buffer, int bufsize);
0250 int __cmdline_find_option_bool(unsigned long cmdline_ptr, const char *option);
0251 static inline int cmdline_find_option(const char *option, char *buffer, int bufsize)
0252 {
0253 unsigned long cmd_line_ptr = boot_params.hdr.cmd_line_ptr;
0254
0255 if (cmd_line_ptr >= 0x100000)
0256 return -1;
0257
0258 return __cmdline_find_option(cmd_line_ptr, option, buffer, bufsize);
0259 }
0260
0261 static inline int cmdline_find_option_bool(const char *option)
0262 {
0263 unsigned long cmd_line_ptr = boot_params.hdr.cmd_line_ptr;
0264
0265 if (cmd_line_ptr >= 0x100000)
0266 return -1;
0267
0268 return __cmdline_find_option_bool(cmd_line_ptr, option);
0269 }
0270
0271
0272 int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
0273 int check_knl_erratum(void);
0274 int validate_cpu(void);
0275
0276
0277 extern int early_serial_base;
0278 void console_init(void);
0279
0280
0281 void query_edd(void);
0282
0283
0284 void __attribute__((noreturn)) die(void);
0285
0286
0287 void detect_memory(void);
0288
0289
0290 void __attribute__((noreturn)) go_to_protected_mode(void);
0291
0292
0293 void __attribute__((noreturn))
0294 protected_mode_jump(u32 entrypoint, u32 bootparams);
0295
0296
0297 int sprintf(char *buf, const char *fmt, ...);
0298 int vsprintf(char *buf, const char *fmt, va_list args);
0299 int printf(const char *fmt, ...);
0300
0301
0302 void initregs(struct biosregs *regs);
0303
0304
0305 int strcmp(const char *str1, const char *str2);
0306 int strncmp(const char *cs, const char *ct, size_t count);
0307 size_t strnlen(const char *s, size_t maxlen);
0308 unsigned int atou(const char *s);
0309 unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);
0310 size_t strlen(const char *s);
0311 char *strchr(const char *s, int c);
0312
0313
0314 void puts(const char *);
0315 void putchar(int);
0316 int getchar(void);
0317 void kbd_flush(void);
0318 int getchar_timeout(void);
0319
0320
0321 void set_video(void);
0322
0323
0324 int set_mode(u16 mode);
0325 int mode_defined(u16 mode);
0326 void probe_cards(int unsafe);
0327
0328
0329 void vesa_store_edid(void);
0330
0331 #endif
0332
0333 #endif