]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/wimboot.h
5 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
35 /** Base segment address
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).
40 #define BASE_SEG 0x2000
42 /** Base linear address */
43 #define BASE_ADDRESS ( BASE_SEG << 4 )
45 /** 64 bit long mode code segment */
48 /** 32 bit protected mode flat code segment */
51 /** 32 bit protected mode flat data segment */
54 /** 16 bit real mode code segment */
57 /** 16 bit real mode data segment */
66 /** Construct wide-character version of a string constant */
67 #define L( x ) _L ( x )
68 #define _L( x ) L ## x
71 #define PAGE_SIZE 4096
74 * Calculate start page number
77 * @ret page Start page number
79 static inline unsigned int page_start ( const void *address
) {
80 return ( ( ( intptr_t ) address
) / PAGE_SIZE
);
84 * Calculate end page number
87 * @ret page End page number
89 static inline unsigned int page_end ( const void *address
) {
90 return ( ( ( ( intptr_t ) address
) + PAGE_SIZE
- 1 ) / PAGE_SIZE
);
94 * Calculate page length
96 * @v start Start address
98 * @ret num_pages Number of pages
100 static inline unsigned int page_len ( const void *start
, const void *end
) {
101 return ( page_end ( end
) - page_start ( start
) );
105 * Bochs magic breakpoint
108 static inline void bochsbp ( void ) {
109 __asm__
__volatile__ ( "xchgw %bx, %bx" );
112 /** Debugging output */
113 #define DBG(...) do { \
114 if ( ( DEBUG & 1 ) && ( ! cmdline_quiet ) ) { \
115 printf ( __VA_ARGS__ ); \
119 /** Verbose debugging output */
120 #define DBG2(...) do { \
121 if ( ( DEBUG & 2 ) && ( ! cmdline_quiet ) ) { \
122 printf ( __VA_ARGS__ ); \
126 /* Branch prediction macros */
127 #define likely( x ) __builtin_expect ( !! (x), 1 )
128 #define unlikely( x ) __builtin_expect ( (x), 0 )
130 /* Mark parameter as unused */
131 #define __unused __attribute__ (( unused ))
134 static inline void call_real ( struct bootapp_callback_params
*params
) {
135 /* Not available in 64-bit mode */
138 static inline void call_interrupt ( struct bootapp_callback_params
*params
) {
139 /* Not available in 64-bit mode */
142 static inline void reboot ( void ) {
143 /* Not available in 64-bit mode */
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 );
151 extern void __attribute__ (( noreturn
, format ( printf
, 1, 2 ) ))
152 die ( const char *fmt
, ... );
154 extern unsigned long __stack_chk_guard
;
155 extern void init_cookie ( void );
157 #endif /* ASSEMBLY */
159 #endif /* _WIMBOOT_H */