Adding upstream version 4.00~pre55+dfsg.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-common.h
blob0a0c8c4e5f1274c57fcace51c41967ae57ce8fbd
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
12 * conditions:
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
31 #include <stdio.h>
32 #include <syslinux/pxe.h>
33 #include <console.h>
34 #include <consoles.h>
35 #include <syslinux/vesacon.h>
36 #include "sys/pci.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>
48 #include "cpuid.h"
49 #include "dmi/dmi.h"
50 #include "hdt-ata.h"
51 #include "../lib/sys/vesa/vesa.h"
52 #include <vpd/vpd.h>
53 #include <libansi.h>
55 /* Declare a variable or data structure as unused. */
56 #define __unused __attribute__ (( unused ))
58 /* This two values are used for switching for the menu to the CLI mode */
59 #define HDT_SWITCH_TO_CLI "hdt_switch_to_cli"
60 #define HDT_RETURN_TO_CLI 100
61 #define MAX_VESA_MODES 255
63 /* The maximum number of commands we can process */
64 #define MAX_NB_AUTO_COMMANDS 255
65 /* The maximum size of a command */
66 #define AUTO_COMMAND_SIZE 255
67 /* The char that separate two commands */
68 #define AUTO_SEPARATOR ";"
69 /* The char that surround the list of commands */
70 #define AUTO_DELIMITER "'"
72 /* Graphic to load in background when using the vesa mode */
73 #define CLI_DEFAULT_BACKGROUND "backgnd.png"
75 /* The maximum number of lines */
76 #define MAX_CLI_LINES 20
77 #define MAX_VESA_CLI_LINES 24
79 /* Defines if the cli is quiet*/
80 bool quiet;
82 /* Defines if we must use the vesa mode */
83 bool vesamode;
85 /* Defines the number of lines in the console
86 * Default is 20 for a std console */
87 extern int max_console_lines;
89 extern int display_line_nb;
90 extern bool disable_more_printf;
92 #define pause_printf() do {\
93 printf("--More--");\
94 get_key(stdin, 0);\
95 printf("\033[2K\033[1G\033[1F\n");\
96 } while (0);
98 /* The brokeness of that macro is that
99 * it assumes that __VA_ARGS__ contains
100 * one \n (and only one)
102 #define more_printf(...) do {\
103 if (__likely(!disable_more_printf)) {\
104 if (display_line_nb == max_console_lines) {\
105 display_line_nb=0;\
106 printf("\n--More--");\
107 get_key(stdin, 0);\
108 printf("\033[2K\033[1G\033[1F");\
110 display_line_nb++;\
112 printf(__VA_ARGS__);\
113 } while (0);
115 /* Display CPU registers for debugging purposes */
116 static inline void printregs(const com32sys_t * r)
118 printf("eflags = %08x ds = %04x es = %04x fs = %04x gs = %04x\n"
119 "eax = %08x ebx = %08x ecx = %08x edx = %08x\n"
120 "ebp = %08x esi = %08x edi = %08x esp = %08x\n",
121 r->eflags.l, r->ds, r->es, r->fs, r->gs,
122 r->eax.l, r->ebx.l, r->ecx.l, r->edx.l,
123 r->ebp.l, r->esi.l, r->edi.l, r->_unused_esp.l);
126 struct s_pxe {
127 uint16_t vendor_id;
128 uint16_t product_id;
129 uint16_t subvendor_id;
130 uint16_t subproduct_id;
131 uint8_t rev;
132 uint8_t pci_bus;
133 uint8_t pci_dev;
134 uint8_t pci_func;
135 uint8_t base_class;
136 uint8_t sub_class;
137 uint8_t prog_intf;
138 uint8_t nictype;
139 char mac_addr[18]; /* The current mac address */
140 uint8_t ip_addr[4];
141 pxe_bootp_t dhcpdata; /* The dhcp answer */
142 struct pci_device *pci_device; /* The matching pci device */
143 uint8_t pci_device_pos; /* It position in our pci sorted list */
146 struct s_vesa_mode_info {
147 struct vesa_mode_info mi;
148 uint16_t mode;
151 struct s_vesa {
152 uint8_t major_version;
153 uint8_t minor_version;
154 struct s_vesa_mode_info vmi[MAX_VESA_MODES];
155 uint8_t vmi_count;
156 uint16_t total_memory;
157 char vendor[256];
158 char product[256];
159 char product_revision[256];
160 uint16_t software_rev;
163 struct s_hardware {
164 s_dmi dmi; /* DMI table */
165 s_cpu cpu; /* CPU information */
166 s_vpd vpd; /* VPD information */
167 struct pci_domain *pci_domain; /* PCI Devices */
168 struct driveinfo disk_info[256]; /* Disk Information */
169 uint32_t mbr_ids[256]; /* MBR ids */
170 int disks_count; /* Number of detected disks */
171 struct s_pxe pxe;
172 struct s_vesa vesa;
173 unsigned long detected_memory_size; /* The detected memory size (in KB) */
175 int pci_ids_return_code;
176 int modules_pcimap_return_code;
177 int modules_alias_return_code;
178 int nb_pci_devices;
179 bool is_dmi_valid;
180 bool is_pxe_valid;
181 bool is_vesa_valid;
182 bool is_vpd_valid;
184 bool dmi_detection; /* Does the dmi stuff has already been detected? */
185 bool pci_detection; /* Does the pci stuff has already been detected? */
186 bool cpu_detection; /* Does the cpu stuff has already been detected? */
187 bool disk_detection; /* Does the disk stuff has already been detected? */
188 bool pxe_detection; /* Does the pxe stuff has already been detected? */
189 bool vesa_detection; /* Does the vesa sutff have been already detected? */
190 bool vpd_detection; /* Does the vpd stuff has already been detected? */
191 bool memory_detection; /* Does the memory size got detected ?*/
193 char syslinux_fs[22];
194 const struct syslinux_version *sv;
195 char modules_pcimap_path[255];
196 char modules_alias_path[255];
197 char pciids_path[255];
198 char memtest_label[255];
199 char reboot_label[255];
200 char auto_label[AUTO_COMMAND_SIZE];
201 char vesa_background[255];
204 void reset_more_printf(void);
205 const char *find_argument(const char **argv, const char *argument);
206 char *remove_spaces(char *p);
207 char *remove_trailing_lf(char *p);
208 char *skip_spaces(char *p);
209 char *del_multi_spaces(char *p);
210 int detect_dmi(struct s_hardware *hardware);
211 int detect_vpd(struct s_hardware *hardware);
212 void detect_disks(struct s_hardware *hardware);
213 void detect_pci(struct s_hardware *hardware);
214 void cpu_detect(struct s_hardware *hardware);
215 int detect_pxe(struct s_hardware *hardware);
216 void init_hardware(struct s_hardware *hardware);
217 void clear_screen(void);
218 void detect_syslinux(struct s_hardware *hardware);
219 void detect_parameters(const int argc, const char *argv[],
220 struct s_hardware *hardware);
221 int detect_vesa(struct s_hardware *hardware);
222 void detect_memory(struct s_hardware *hardware);
223 void init_console(struct s_hardware *hardware);
224 #endif