]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/wimboot.h
added Spanish (Latinoamérica) translation (#1865)
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / wimboot.h
1 #ifndef _WIMBOOT_H
2 #define _WIMBOOT_H
3
4 /*
5 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23 /**
24 * @file
25 *
26 * WIM boot loader
27 *
28 */
29
30 /** Debug switch */
31 #ifndef DEBUG
32 #define DEBUG 1
33 #endif
34
35 /** Base segment address
36 *
37 * We place everything at 2000:0000, since this region is used by the
38 * Microsoft first-stage loaders (e.g. pxeboot.n12, etfsboot.com).
39 */
40 #define BASE_SEG 0x2000
41
42 /** Base linear address */
43 #define BASE_ADDRESS ( BASE_SEG << 4 )
44
45 /** 64 bit long mode code segment */
46 #define LM_CS 0x10
47
48 /** 32 bit protected mode flat code segment */
49 #define FLAT_CS 0x20
50
51 /** 32 bit protected mode flat data segment */
52 #define FLAT_DS 0x30
53
54 /** 16 bit real mode code segment */
55 #define REAL_CS 0x50
56
57 /** 16 bit real mode data segment */
58 #define REAL_DS 0x60
59
60 #ifndef ASSEMBLY
61
62 #include <stdint.h>
63 #include <bootapp.h>
64 #include <cmdline.h>
65
66 /** Construct wide-character version of a string constant */
67 #define L( x ) _L ( x )
68 #define _L( x ) L ## x
69
70 /** Page size */
71 #define PAGE_SIZE 4096
72
73 /**
74 * Calculate start page number
75 *
76 * @v address Address
77 * @ret page Start page number
78 */
79 static inline unsigned int page_start ( const void *address ) {
80 return ( ( ( intptr_t ) address ) / PAGE_SIZE );
81 }
82
83 /**
84 * Calculate end page number
85 *
86 * @v address Address
87 * @ret page End page number
88 */
89 static inline unsigned int page_end ( const void *address ) {
90 return ( ( ( ( intptr_t ) address ) + PAGE_SIZE - 1 ) / PAGE_SIZE );
91 }
92
93 /**
94 * Calculate page length
95 *
96 * @v start Start address
97 * @v end End address
98 * @ret num_pages Number of pages
99 */
100 static inline unsigned int page_len ( const void *start, const void *end ) {
101 return ( page_end ( end ) - page_start ( start ) );
102 }
103
104 /**
105 * Bochs magic breakpoint
106 *
107 */
108 static inline void bochsbp ( void ) {
109 __asm__ __volatile__ ( "xchgw %bx, %bx" );
110 }
111
112 /** Debugging output */
113 #define DBG(...) do { \
114 if ( ( DEBUG & 1 ) && ( ! cmdline_quiet ) ) { \
115 printf ( __VA_ARGS__ ); \
116 } \
117 } while ( 0 )
118
119 /** Verbose debugging output */
120 #define DBG2(...) do { \
121 if ( ( DEBUG & 2 ) && ( ! cmdline_quiet ) ) { \
122 printf ( __VA_ARGS__ ); \
123 } \
124 } while ( 0 )
125
126 /* Branch prediction macros */
127 #define likely( x ) __builtin_expect ( !! (x), 1 )
128 #define unlikely( x ) __builtin_expect ( (x), 0 )
129
130 /* Mark parameter as unused */
131 #define __unused __attribute__ (( unused ))
132
133 #if __x86_64__
134 static inline void call_real ( struct bootapp_callback_params *params ) {
135 /* Not available in 64-bit mode */
136 ( void ) params;
137 }
138 static inline void call_interrupt ( struct bootapp_callback_params *params ) {
139 /* Not available in 64-bit mode */
140 ( void ) params;
141 }
142 static inline void reboot ( void ) {
143 /* Not available in 64-bit mode */
144 }
145 #else
146 extern void call_real ( struct bootapp_callback_params *params );
147 extern void call_interrupt ( struct bootapp_callback_params *params );
148 extern void __attribute__ (( noreturn )) reboot ( void );
149 #endif
150
151 extern void __attribute__ (( noreturn, format ( printf, 1, 2 ) ))
152 die ( const char *fmt, ... );
153
154 extern unsigned long __stack_chk_guard;
155 extern void init_cookie ( void );
156
157 #endif /* ASSEMBLY */
158
159 #endif /* _WIMBOOT_H */