linux/arch/x86/boot/boot.h
<<
>>
Prefs
   1/* -*- linux-c -*- ------------------------------------------------------- *
   2 *
   3 *   Copyright (C) 1991, 1992 Linus Torvalds
   4 *   Copyright 2007 rPath, Inc. - All Rights Reserved
   5 *   Copyright 2009 Intel Corporation; author H. Peter Anvin
   6 *
   7 *   This file is part of the Linux kernel, and is made available under
   8 *   the terms of the GNU General Public License version 2.
   9 *
  10 * ----------------------------------------------------------------------- */
  11
  12/*
  13 * Header file for the real-mode kernel code
  14 */
  15
  16#ifndef BOOT_BOOT_H
  17#define BOOT_BOOT_H
  18
  19#define STACK_SIZE      512     /* Minimum number of bytes for stack */
  20
  21#ifndef __ASSEMBLY__
  22
  23#include <stdarg.h>
  24#include <linux/types.h>
  25#include <linux/edd.h>
  26#include <asm/boot.h>
  27#include <asm/setup.h>
  28#include "bitops.h"
  29#include <asm/cpufeature.h>
  30#include <asm/processor-flags.h>
  31
  32/* Useful macros */
  33#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
  34
  35#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
  36
  37extern struct setup_header hdr;
  38extern struct boot_params boot_params;
  39
  40/* Basic port I/O */
  41static inline void outb(u8 v, u16 port)
  42{
  43        asm volatile("outb %0,%1" : : "a" (v), "dN" (port));
  44}
  45static inline u8 inb(u16 port)
  46{
  47        u8 v;
  48        asm volatile("inb %1,%0" : "=a" (v) : "dN" (port));
  49        return v;
  50}
  51
  52static inline void outw(u16 v, u16 port)
  53{
  54        asm volatile("outw %0,%1" : : "a" (v), "dN" (port));
  55}
  56static inline u16 inw(u16 port)
  57{
  58        u16 v;
  59        asm volatile("inw %1,%0" : "=a" (v) : "dN" (port));
  60        return v;
  61}
  62
  63static inline void outl(u32 v, u16 port)
  64{
  65        asm volatile("outl %0,%1" : : "a" (v), "dN" (port));
  66}
  67static inline u32 inl(u32 port)
  68{
  69        u32 v;
  70        asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
  71        return v;
  72}
  73
  74static inline void io_delay(void)
  75{
  76        const u16 DELAY_PORT = 0x80;
  77        asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
  78}
  79
  80/* These functions are used to reference data in other segments. */
  81
  82static inline u16 ds(void)
  83{
  84        u16 seg;
  85        asm("movw %%ds,%0" : "=rm" (seg));
  86        return seg;
  87}
  88
  89static inline void set_fs(u16 seg)
  90{
  91        asm volatile("movw %0,%%fs" : : "rm" (seg));
  92}
  93static inline u16 fs(void)
  94{
  95        u16 seg;
  96        asm volatile("movw %%fs,%0" : "=rm" (seg));
  97        return seg;
  98}
  99
 100static inline void set_gs(u16 seg)
 101{
 102        asm volatile("movw %0,%%gs" : : "rm" (seg));
 103}
 104static inline u16 gs(void)
 105{
 106        u16 seg;
 107        asm volatile("movw %%gs,%0" : "=rm" (seg));
 108        return seg;
 109}
 110
 111typedef unsigned int addr_t;
 112
 113static inline u8 rdfs8(addr_t addr)
 114{
 115        u8 v;
 116        asm volatile("movb %%fs:%1,%0" : "=q" (v) : "m" (*(u8 *)addr));
 117        return v;
 118}
 119static inline u16 rdfs16(addr_t addr)
 120{
 121        u16 v;
 122        asm volatile("movw %%fs:%1,%0" : "=r" (v) : "m" (*(u16 *)addr));
 123        return v;
 124}
 125static inline u32 rdfs32(addr_t addr)
 126{
 127        u32 v;
 128        asm volatile("movl %%fs:%1,%0" : "=r" (v) : "m" (*(u32 *)addr));
 129        return v;
 130}
 131
 132static inline void wrfs8(u8 v, addr_t addr)
 133{
 134        asm volatile("movb %1,%%fs:%0" : "+m" (*(u8 *)addr) : "qi" (v));
 135}
 136static inline void wrfs16(u16 v, addr_t addr)
 137{
 138        asm volatile("movw %1,%%fs:%0" : "+m" (*(u16 *)addr) : "ri" (v));
 139}
 140static inline void wrfs32(u32 v, addr_t addr)
 141{
 142        asm volatile("movl %1,%%fs:%0" : "+m" (*(u32 *)addr) : "ri" (v));
 143}
 144
 145static inline u8 rdgs8(addr_t addr)
 146{
 147        u8 v;
 148        asm volatile("movb %%gs:%1,%0" : "=q" (v) : "m" (*(u8 *)addr));
 149        return v;
 150}
 151static inline u16 rdgs16(addr_t addr)
 152{
 153        u16 v;
 154        asm volatile("movw %%gs:%1,%0" : "=r" (v) : "m" (*(u16 *)addr));
 155        return v;
 156}
 157static inline u32 rdgs32(addr_t addr)
 158{
 159        u32 v;
 160        asm volatile("movl %%gs:%1,%0" : "=r" (v) : "m" (*(u32 *)addr));
 161        return v;
 162}
 163
 164static inline void wrgs8(u8 v, addr_t addr)
 165{
 166        asm volatile("movb %1,%%gs:%0" : "+m" (*(u8 *)addr) : "qi" (v));
 167}
 168static inline void wrgs16(u16 v, addr_t addr)
 169{
 170        asm volatile("movw %1,%%gs:%0" : "+m" (*(u16 *)addr) : "ri" (v));
 171}
 172static inline void wrgs32(u32 v, addr_t addr)
 173{
 174        asm volatile("movl %1,%%gs:%0" : "+m" (*(u32 *)addr) : "ri" (v));
 175}
 176
 177/* Note: these only return true/false, not a signed return value! */
 178static inline int memcmp(const void *s1, const void *s2, size_t len)
 179{
 180        u8 diff;
 181        asm("repe; cmpsb; setnz %0"
 182            : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
 183        return diff;
 184}
 185
 186static inline int memcmp_fs(const void *s1, addr_t s2, size_t len)
 187{
 188        u8 diff;
 189        asm volatile("fs; repe; cmpsb; setnz %0"
 190                     : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
 191        return diff;
 192}
 193static inline int memcmp_gs(const void *s1, addr_t s2, size_t len)
 194{
 195        u8 diff;
 196        asm volatile("gs; repe; cmpsb; setnz %0"
 197                     : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
 198        return diff;
 199}
 200
 201static inline int isdigit(int ch)
 202{
 203        return (ch >= '0') && (ch <= '9');
 204}
 205
 206/* Heap -- available for dynamic lists. */
 207extern char _end[];
 208extern char *HEAP;
 209extern char *heap_end;
 210#define RESET_HEAP() ((void *)( HEAP = _end ))
 211static inline char *__get_heap(size_t s, size_t a, size_t n)
 212{
 213        char *tmp;
 214
 215        HEAP = (char *)(((size_t)HEAP+(a-1)) & ~(a-1));
 216        tmp = HEAP;
 217        HEAP += s*n;
 218        return tmp;
 219}
 220#define GET_HEAP(type, n) \
 221        ((type *)__get_heap(sizeof(type),__alignof__(type),(n)))
 222
 223static inline bool heap_free(size_t n)
 224{
 225        return (int)(heap_end-HEAP) >= (int)n;
 226}
 227
 228/* copy.S */
 229
 230void copy_to_fs(addr_t dst, void *src, size_t len);
 231void *copy_from_fs(void *dst, addr_t src, size_t len);
 232void copy_to_gs(addr_t dst, void *src, size_t len);
 233void *copy_from_gs(void *dst, addr_t src, size_t len);
 234void *memcpy(void *dst, void *src, size_t len);
 235void *memset(void *dst, int c, size_t len);
 236
 237#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
 238#define memset(d,c,l) __builtin_memset(d,c,l)
 239
 240/* a20.c */
 241int enable_a20(void);
 242
 243/* apm.c */
 244int query_apm_bios(void);
 245
 246/* bioscall.c */
 247struct biosregs {
 248        union {
 249                struct {
 250                        u32 edi;
 251                        u32 esi;
 252                        u32 ebp;
 253                        u32 _esp;
 254                        u32 ebx;
 255                        u32 edx;
 256                        u32 ecx;
 257                        u32 eax;
 258                        u32 _fsgs;
 259                        u32 _dses;
 260                        u32 eflags;
 261                };
 262                struct {
 263                        u16 di, hdi;
 264                        u16 si, hsi;
 265                        u16 bp, hbp;
 266                        u16 _sp, _hsp;
 267                        u16 bx, hbx;
 268                        u16 dx, hdx;
 269                        u16 cx, hcx;
 270                        u16 ax, hax;
 271                        u16 gs, fs;
 272                        u16 es, ds;
 273                        u16 flags, hflags;
 274                };
 275                struct {
 276                        u8 dil, dih, edi2, edi3;
 277                        u8 sil, sih, esi2, esi3;
 278                        u8 bpl, bph, ebp2, ebp3;
 279                        u8 _spl, _sph, _esp2, _esp3;
 280                        u8 bl, bh, ebx2, ebx3;
 281                        u8 dl, dh, edx2, edx3;
 282                        u8 cl, ch, ecx2, ecx3;
 283                        u8 al, ah, eax2, eax3;
 284                };
 285        };
 286};
 287void intcall(u8 int_no, const struct biosregs *ireg, struct biosregs *oreg);
 288
 289/* cmdline.c */
 290int cmdline_find_option(const char *option, char *buffer, int bufsize);
 291int cmdline_find_option_bool(const char *option);
 292
 293/* cpu.c, cpucheck.c */
 294struct cpu_features {
 295        int level;              /* Family, or 64 for x86-64 */
 296        int model;
 297        u32 flags[NCAPINTS];
 298};
 299extern struct cpu_features cpu;
 300int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
 301int validate_cpu(void);
 302
 303/* edd.c */
 304void query_edd(void);
 305
 306/* header.S */
 307void __attribute__((noreturn)) die(void);
 308
 309/* mca.c */
 310int query_mca(void);
 311
 312/* memory.c */
 313int detect_memory(void);
 314
 315/* pm.c */
 316void __attribute__((noreturn)) go_to_protected_mode(void);
 317
 318/* pmjump.S */
 319void __attribute__((noreturn))
 320        protected_mode_jump(u32 entrypoint, u32 bootparams);
 321
 322/* printf.c */
 323int sprintf(char *buf, const char *fmt, ...);
 324int vsprintf(char *buf, const char *fmt, va_list args);
 325int printf(const char *fmt, ...);
 326
 327/* regs.c */
 328void initregs(struct biosregs *regs);
 329
 330/* string.c */
 331int strcmp(const char *str1, const char *str2);
 332size_t strnlen(const char *s, size_t maxlen);
 333unsigned int atou(const char *s);
 334
 335/* tty.c */
 336void puts(const char *);
 337void putchar(int);
 338int getchar(void);
 339void kbd_flush(void);
 340int getchar_timeout(void);
 341
 342/* video.c */
 343void set_video(void);
 344
 345/* video-mode.c */
 346int set_mode(u16 mode);
 347int mode_defined(u16 mode);
 348void probe_cards(int unsafe);
 349
 350/* video-vesa.c */
 351void vesa_store_edid(void);
 352
 353#endif /* __ASSEMBLY__ */
 354
 355#endif /* BOOT_BOOT_H */
 356