1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Erwan Velu - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
29 #ifndef DEFINE_HDT_COMMON_H
30 #define DEFINE_HDT_COMMON_H
32 #include <syslinux/pxe.h>
35 #include <syslinux/vesacon.h>
38 #include <disk/bootloaders.h>
39 #include <disk/errno_disk.h>
40 #include <disk/error.h>
41 #include <disk/geom.h>
42 #include <disk/mbrs.h>
43 #include <disk/msdos.h>
44 #include <disk/partition.h>
45 #include <disk/swsusp.h>
46 #include <disk/read.h>
51 #include "../lib/sys/vesa/vesa.h"
54 #include <acpi/acpi.h>
56 /* Declare a variable or data structure as unused. */
57 #define __unused __attribute__ (( unused ))
59 /* This two values are used for switching for the menu to the CLI mode */
60 #define HDT_SWITCH_TO_CLI "hdt_switch_to_cli"
61 #define HDT_RETURN_TO_CLI 100
62 #define MAX_VESA_MODES 255
64 /* This value is used for rebooting from the menu mode */
65 #define HDT_REBOOT "hdt_reboot"
67 /* The maximum number of commands we can process */
68 #define MAX_NB_AUTO_COMMANDS 255
69 /* The maximum size of a command */
70 #define AUTO_COMMAND_SIZE 255
71 /* The char that separate two commands */
72 #define AUTO_SEPARATOR ";"
73 /* The char that surround the list of commands */
74 #define AUTO_DELIMITER "'"
76 /* Graphic to load in background when using the vesa mode */
77 #define CLI_DEFAULT_BACKGROUND "backgnd.png"
79 /* The maximum number of lines */
80 #define MAX_CLI_LINES 20
81 #define MAX_VESA_CLI_LINES 24
83 /* Defines if the cli is quiet*/
86 /* Defines if we must use the vesa mode */
89 /* Defines if we must use the menu mode */
92 /* Defines if we are running the auto mode */
95 /* Defines the number of lines in the console
96 * Default is 20 for a std console */
97 extern int max_console_lines
;
99 extern int display_line_nb
;
100 extern bool disable_more_printf
;
102 #define pause_printf() do {\
105 printf("\033[2K\033[1G\033[1F\n");\
108 /* The brokeness of that macro is that
109 * it assumes that __VA_ARGS__ contains
110 * one \n (and only one)
112 #define more_printf(...) do {\
113 if (__likely(!disable_more_printf)) {\
114 if (display_line_nb == max_console_lines) {\
116 printf("\n--More--");\
118 printf("\033[2K\033[1G\033[1F");\
122 printf(__VA_ARGS__);\
125 /* Display CPU registers for debugging purposes */
126 static inline void printregs(const com32sys_t
* r
)
128 printf("eflags = %08x ds = %04x es = %04x fs = %04x gs = %04x\n"
129 "eax = %08x ebx = %08x ecx = %08x edx = %08x\n"
130 "ebp = %08x esi = %08x edi = %08x esp = %08x\n",
131 r
->eflags
.l
, r
->ds
, r
->es
, r
->fs
, r
->gs
,
132 r
->eax
.l
, r
->ebx
.l
, r
->ecx
.l
, r
->edx
.l
,
133 r
->ebp
.l
, r
->esi
.l
, r
->edi
.l
, r
->_unused_esp
.l
);
139 uint16_t subvendor_id
;
140 uint16_t subproduct_id
;
149 char mac_addr
[18]; /* The current mac address */
151 pxe_bootp_t dhcpdata
; /* The dhcp answer */
152 struct pci_device
*pci_device
; /* The matching pci device */
153 uint8_t pci_device_pos
; /* It position in our pci sorted list */
156 struct s_vesa_mode_info
{
157 struct vesa_mode_info mi
;
162 uint8_t major_version
;
163 uint8_t minor_version
;
164 struct s_vesa_mode_info vmi
[MAX_VESA_MODES
];
166 uint16_t total_memory
;
169 char product_revision
[256];
170 uint16_t software_rev
;
174 s_dmi dmi
; /* DMI table */
175 s_cpu cpu
; /* CPU information */
176 uint8_t physical_cpu_count
; /* Number of physical cpu */
177 s_vpd vpd
; /* VPD information */
179 struct pci_domain
*pci_domain
; /* PCI Devices */
180 struct driveinfo disk_info
[256]; /* Disk Information */
181 uint32_t mbr_ids
[256]; /* MBR ids */
182 int disks_count
; /* Number of detected disks */
185 unsigned long detected_memory_size
; /* The detected memory size (in KB) */
187 int pci_ids_return_code
;
188 int modules_pcimap_return_code
;
189 int modules_alias_return_code
;
197 bool dmi_detection
; /* Does the dmi stuff has already been detected? */
198 bool pci_detection
; /* Does the pci stuff has already been detected? */
199 bool cpu_detection
; /* Does the cpu stuff has already been detected? */
200 bool disk_detection
; /* Does the disk stuff has already been detected? */
201 bool pxe_detection
; /* Does the pxe stuff has already been detected? */
202 bool vesa_detection
; /* Does the vesa sutff have been already detected? */
203 bool vpd_detection
; /* Does the vpd stuff has already been detected? */
204 bool memory_detection
; /* Does the memory size got detected ?*/
205 bool acpi_detection
; /* Does the acpi got detected ?*/
207 char syslinux_fs
[22];
208 const struct syslinux_version
*sv
;
209 char modules_pcimap_path
[255];
210 char modules_alias_path
[255];
211 char pciids_path
[255];
212 char memtest_label
[255];
213 char auto_label
[AUTO_COMMAND_SIZE
];
214 char vesa_background
[255];
217 void reset_more_printf(void);
218 const char *find_argument(const char **argv
, const char *argument
);
219 char *remove_spaces(char *p
);
220 char *remove_trailing_lf(char *p
);
221 char *skip_spaces(char *p
);
222 char *del_multi_spaces(char *p
);
223 int detect_dmi(struct s_hardware
*hardware
);
224 int detect_vpd(struct s_hardware
*hardware
);
225 void detect_disks(struct s_hardware
*hardware
);
226 void detect_pci(struct s_hardware
*hardware
);
227 void cpu_detect(struct s_hardware
*hardware
);
228 int detect_pxe(struct s_hardware
*hardware
);
229 void init_hardware(struct s_hardware
*hardware
);
230 void clear_screen(void);
231 void detect_syslinux(struct s_hardware
*hardware
);
232 int detect_acpi(struct s_hardware
*hardware
);
233 void detect_parameters(const int argc
, const char *argv
[],
234 struct s_hardware
*hardware
);
235 int detect_vesa(struct s_hardware
*hardware
);
236 void detect_memory(struct s_hardware
*hardware
);
237 void init_console(struct s_hardware
*hardware
);
238 void detect_hardware(struct s_hardware
*hardware
);