1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
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.
10 * ----------------------------------------------------------------------- */
13 * Header file for the real-mode kernel code
19 #define STACK_SIZE 512 /* Minimum number of bytes for stack */
24 #include <linux/types.h>
25 #include <linux/edd.h>
27 #include <asm/setup.h>
29 #include <asm/cpufeature.h>
30 #include <asm/processor-flags.h>
33 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
35 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
37 extern struct setup_header hdr
;
38 extern struct boot_params boot_params
;
41 static inline void outb(u8 v
, u16 port
)
43 asm volatile("outb %0,%1" : : "a" (v
), "dN" (port
));
45 static inline u8
inb(u16 port
)
48 asm volatile("inb %1,%0" : "=a" (v
) : "dN" (port
));
52 static inline void outw(u16 v
, u16 port
)
54 asm volatile("outw %0,%1" : : "a" (v
), "dN" (port
));
56 static inline u16
inw(u16 port
)
59 asm volatile("inw %1,%0" : "=a" (v
) : "dN" (port
));
63 static inline void outl(u32 v
, u16 port
)
65 asm volatile("outl %0,%1" : : "a" (v
), "dN" (port
));
67 static inline u32
inl(u32 port
)
70 asm volatile("inl %1,%0" : "=a" (v
) : "dN" (port
));
74 static inline void io_delay(void)
76 const u16 DELAY_PORT
= 0x80;
77 asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT
));
80 /* These functions are used to reference data in other segments. */
82 static inline u16
ds(void)
85 asm("movw %%ds,%0" : "=rm" (seg
));
89 static inline void set_fs(u16 seg
)
91 asm volatile("movw %0,%%fs" : : "rm" (seg
));
93 static inline u16
fs(void)
96 asm volatile("movw %%fs,%0" : "=rm" (seg
));
100 static inline void set_gs(u16 seg
)
102 asm volatile("movw %0,%%gs" : : "rm" (seg
));
104 static inline u16
gs(void)
107 asm volatile("movw %%gs,%0" : "=rm" (seg
));
111 typedef unsigned int addr_t
;
113 static inline u8
rdfs8(addr_t addr
)
116 asm volatile("movb %%fs:%1,%0" : "=q" (v
) : "m" (*(u8
*)addr
));
119 static inline u16
rdfs16(addr_t addr
)
122 asm volatile("movw %%fs:%1,%0" : "=r" (v
) : "m" (*(u16
*)addr
));
125 static inline u32
rdfs32(addr_t addr
)
128 asm volatile("movl %%fs:%1,%0" : "=r" (v
) : "m" (*(u32
*)addr
));
132 static inline void wrfs8(u8 v
, addr_t addr
)
134 asm volatile("movb %1,%%fs:%0" : "+m" (*(u8
*)addr
) : "qi" (v
));
136 static inline void wrfs16(u16 v
, addr_t addr
)
138 asm volatile("movw %1,%%fs:%0" : "+m" (*(u16
*)addr
) : "ri" (v
));
140 static inline void wrfs32(u32 v
, addr_t addr
)
142 asm volatile("movl %1,%%fs:%0" : "+m" (*(u32
*)addr
) : "ri" (v
));
145 static inline u8
rdgs8(addr_t addr
)
148 asm volatile("movb %%gs:%1,%0" : "=q" (v
) : "m" (*(u8
*)addr
));
151 static inline u16
rdgs16(addr_t addr
)
154 asm volatile("movw %%gs:%1,%0" : "=r" (v
) : "m" (*(u16
*)addr
));
157 static inline u32
rdgs32(addr_t addr
)
160 asm volatile("movl %%gs:%1,%0" : "=r" (v
) : "m" (*(u32
*)addr
));
164 static inline void wrgs8(u8 v
, addr_t addr
)
166 asm volatile("movb %1,%%gs:%0" : "+m" (*(u8
*)addr
) : "qi" (v
));
168 static inline void wrgs16(u16 v
, addr_t addr
)
170 asm volatile("movw %1,%%gs:%0" : "+m" (*(u16
*)addr
) : "ri" (v
));
172 static inline void wrgs32(u32 v
, addr_t addr
)
174 asm volatile("movl %1,%%gs:%0" : "+m" (*(u32
*)addr
) : "ri" (v
));
177 /* Note: these only return true/false, not a signed return value! */
178 static inline int memcmp(const void *s1
, const void *s2
, size_t len
)
181 asm("repe; cmpsb; setnz %0"
182 : "=qm" (diff
), "+D" (s1
), "+S" (s2
), "+c" (len
));
186 static inline int memcmp_fs(const void *s1
, addr_t s2
, size_t len
)
189 asm volatile("fs; repe; cmpsb; setnz %0"
190 : "=qm" (diff
), "+D" (s1
), "+S" (s2
), "+c" (len
));
193 static inline int memcmp_gs(const void *s1
, addr_t s2
, size_t len
)
196 asm volatile("gs; repe; cmpsb; setnz %0"
197 : "=qm" (diff
), "+D" (s1
), "+S" (s2
), "+c" (len
));
201 static inline int isdigit(int ch
)
203 return (ch
>= '0') && (ch
<= '9');
206 /* Heap -- available for dynamic lists. */
209 extern char *heap_end
;
210 #define RESET_HEAP() ((void *)( HEAP = _end ))
211 static inline char *__get_heap(size_t s
, size_t a
, size_t n
)
215 HEAP
= (char *)(((size_t)HEAP
+(a
-1)) & ~(a
-1));
220 #define GET_HEAP(type, n) \
221 ((type *)__get_heap(sizeof(type),__alignof__(type),(n)))
223 static inline bool heap_free(size_t n
)
225 return (int)(heap_end
-HEAP
) >= (int)n
;
230 void copy_to_fs(addr_t dst
, void *src
, size_t len
);
231 void *copy_from_fs(void *dst
, addr_t src
, size_t len
);
232 void copy_to_gs(addr_t dst
, void *src
, size_t len
);
233 void *copy_from_gs(void *dst
, addr_t src
, size_t len
);
234 void *memcpy(void *dst
, void *src
, size_t len
);
235 void *memset(void *dst
, int c
, size_t len
);
237 #define memcpy(d,s,l) __builtin_memcpy(d,s,l)
238 #define memset(d,c,l) __builtin_memset(d,c,l)
241 int enable_a20(void);
244 int query_apm_bios(void);
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
;
287 void intcall(u8 int_no
, const struct biosregs
*ireg
, struct biosregs
*oreg
);
290 int cmdline_find_option(const char *option
, char *buffer
, int bufsize
);
291 int cmdline_find_option_bool(const char *option
);
293 /* cpu.c, cpucheck.c */
294 struct cpu_features
{
295 int level
; /* Family, or 64 for x86-64 */
299 extern struct cpu_features cpu
;
300 int check_cpu(int *cpu_level_ptr
, int *req_level_ptr
, u32
**err_flags_ptr
);
301 int validate_cpu(void);
304 void query_edd(void);
307 void __attribute__((noreturn
)) die(void);
313 int detect_memory(void);
316 void __attribute__((noreturn
)) go_to_protected_mode(void);
319 void __attribute__((noreturn
))
320 protected_mode_jump(u32 entrypoint
, u32 bootparams
);
323 int sprintf(char *buf
, const char *fmt
, ...);
324 int vsprintf(char *buf
, const char *fmt
, va_list args
);
325 int printf(const char *fmt
, ...);
328 void initregs(struct biosregs
*regs
);
331 int strcmp(const char *str1
, const char *str2
);
332 size_t strnlen(const char *s
, size_t maxlen
);
333 unsigned int atou(const char *s
);
336 void puts(const char *);
339 void kbd_flush(void);
340 int getchar_timeout(void);
343 void set_video(void);
346 int set_mode(u16 mode
);
347 int mode_defined(u16 mode
);
348 void probe_cards(int unsafe
);
351 void vesa_store_edid(void);
353 #endif /* __ASSEMBLY__ */
355 #endif /* BOOT_BOOT_H */