Add memtest support.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-common.c
blob289d74e3700a2660de0841e896aa06eb60e32c6d
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 #include <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <getkey.h>
33 #include "syslinux/config.h"
34 #include "../lib/sys/vesa/vesa.h"
35 #include "hdt-common.h"
36 #include <disk/util.h>
37 #include <disk/mbrs.h>
38 #include <memory.h>
40 /* ISOlinux requires a 8.3 format */
41 void convert_isolinux_filename(char *filename, struct s_hardware *hardware)
43 /* Exit if we are not running ISOLINUX */
44 if (hardware->sv->filesystem != SYSLINUX_FS_ISOLINUX)
45 return;
46 /* Searching the dot */
47 char *dot = strchr(filename, '.');
48 /* Exiting if no dot exists in that string */
49 if (dot == NULL)
50 return;
51 /* Exiting if the extension is 3 char or less */
52 if (strlen(dot) <= 4)
53 return;
55 /* We have an extension bigger than .blah
56 * so we have to shorten it to 3*/
57 dot[4] = '\0';
60 void detect_parameters(const int argc, const char *argv[],
61 struct s_hardware *hardware)
63 /* Quiet mode - make the output more quiet */
64 quiet = true;
66 /* Silent mode - make not output at all */
67 silent = false;
69 /* Vesa mode isn't set until we explictly call it */
70 vesamode = false;
72 /* Automode isn't the default*/
73 automode = false;
75 /* Menu mode is the default*/
76 menumode = true;
78 for (int i = 1; i < argc; i++) {
79 if (!strncmp(argv[i], "quiet", 5)) {
80 quiet = true;
81 } else if (!strncmp(argv[i], "silent", 6)) {
82 silent = true;
83 } else if (!strncmp(argv[i], "verbose", 7)) {
84 quiet = false;
85 } else if (!strncmp(argv[i], "modules_pcimap=", 15)) {
86 strlcpy(hardware->modules_pcimap_path, argv[i] + 15,
87 sizeof(hardware->modules_pcimap_path));
88 convert_isolinux_filename(hardware->modules_pcimap_path, hardware);
89 } else if (!strncmp(argv[i], "pciids=", 7)) {
90 strlcpy(hardware->pciids_path, argv[i] + 7,
91 sizeof(hardware->pciids_path));
92 convert_isolinux_filename(hardware->pciids_path, hardware);
93 } else if (!strncmp(argv[i], "modules_alias=", 14)) {
94 strlcpy(hardware->modules_alias_path, argv[i] + 14,
95 sizeof(hardware->modules_alias_path));
96 convert_isolinux_filename(hardware->modules_alias_path, hardware);
97 } else if (!strncmp(argv[i], "memtest=", 8)) {
98 strlcpy(hardware->memtest_label, argv[i] + 8,
99 sizeof(hardware->memtest_label));
100 convert_isolinux_filename(hardware->memtest_label, hardware);
101 } else if (!strncmp(argv[i], "vesa", 4)) {
102 vesamode = true;
103 max_console_lines = MAX_VESA_CLI_LINES;
104 /* If the user defines a background image */
105 if (!strncmp(argv[i], "vesa=", 5)) {
106 strlcpy(hardware->vesa_background, argv[i] + 5,
107 sizeof(hardware->vesa_background));
109 } else if (!strncmp(argv[i], "novesa", 6)) {
110 vesamode = false;
111 max_console_lines = MAX_CLI_LINES;
112 } else if (!strncmp(argv[i], "nomenu", 6)) {
113 menumode = false;
114 } else if (!strncmp(argv[i], "dump_filename=", 14)) {
115 strlcpy(hardware->dump_filename, argv[i] + 14,
116 sizeof(hardware->dump_filename));
117 } else if (!strncmp(argv[i], "dump_path=", 10)) {
118 strlcpy(hardware->dump_path, argv[i] + 10,
119 sizeof(hardware->dump_path));
120 } else if (!strncmp(argv[i], "tftp_ip=", 8)) {
121 strlcpy(hardware->tftp_ip, argv[i] + 8,
122 sizeof(hardware->tftp_ip));
123 } else if (!strncmp(argv[i], "postexec=", 9)) {
124 /* The postexec= parameter is separated in several argv[]
125 * as it can contains spaces.
126 * We use the AUTO_DELIMITER char to define the limits
127 * of this parameter.
128 * i.e postexec='linux memtest.bin'
131 char *argument = (char*)argv[i]+10;
132 /* Extracting the first parameter */
133 strcpy(hardware->postexec, argument);
135 /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */
136 while ((strchr(argument, AUTO_DELIMITER) == NULL) && (i+1<argc)) {
137 i++;
138 argument = (char *)argv[i];
139 strcat(hardware->postexec, " ");
140 strcat(hardware->postexec, argument);
143 hardware->postexec[strlen(hardware->postexec) - 1] = 0;
144 } else if (!strncmp(argv[i], "auto=", 5)) {
145 /* The auto= parameter is separated in several argv[]
146 * as it can contains spaces.
147 * We use the AUTO_DELIMITER char to define the limits
148 * of this parameter.
149 * i.e auto='show dmi; show pci'
152 automode=true;
153 char *argument = (char*)argv[i]+6;
154 /* Extracting the first parameter */
155 strcpy(hardware->auto_label, argument);
157 /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */
158 while ((strchr(argument, AUTO_DELIMITER) == NULL) && (i+1<argc)) {
159 i++;
160 argument = (char *)argv[i];
161 strcat(hardware->auto_label, " ");
162 strcat(hardware->auto_label, argument);
165 hardware->auto_label[strlen(hardware->auto_label) - 1] = 0;
170 void detect_syslinux(struct s_hardware *hardware)
172 hardware->sv = syslinux_version();
173 switch (hardware->sv->filesystem) {
174 case SYSLINUX_FS_SYSLINUX:
175 strlcpy(hardware->syslinux_fs, "SYSlinux", 9);
176 break;
177 case SYSLINUX_FS_PXELINUX:
178 strlcpy(hardware->syslinux_fs, "PXElinux", 9);
179 break;
180 case SYSLINUX_FS_ISOLINUX:
181 strlcpy(hardware->syslinux_fs, "ISOlinux", 9);
182 break;
183 case SYSLINUX_FS_EXTLINUX:
184 strlcpy(hardware->syslinux_fs, "EXTlinux", 9);
185 break;
186 case SYSLINUX_FS_UNKNOWN:
187 default:
188 strlcpy(hardware->syslinux_fs, "Unknown Bootloader",
189 sizeof hardware->syslinux_fs);
190 break;
194 void init_hardware(struct s_hardware *hardware)
196 hardware->pci_ids_return_code = 0;
197 hardware->modules_pcimap_return_code = 0;
198 hardware->modules_alias_return_code = 0;
199 hardware->cpu_detection = false;
200 hardware->pci_detection = false;
201 hardware->disk_detection = false;
202 hardware->disks_count = 0;
203 hardware->dmi_detection = false;
204 hardware->pxe_detection = false;
205 hardware->vesa_detection = false;
206 hardware->vpd_detection = false;
207 hardware->memory_detection = false;
208 hardware->acpi_detection = false;
209 hardware->nb_pci_devices = 0;
210 hardware->is_dmi_valid = false;
211 hardware->is_pxe_valid = false;
212 hardware->is_vpd_valid = false;
213 hardware->is_acpi_valid = false;
214 hardware->pci_domain = NULL;
215 hardware->detected_memory_size = 0;
216 hardware->physical_cpu_count =1; /* we have at least one cpu */
218 /* Cleaning structures */
219 memset(hardware->disk_info, 0, sizeof(hardware->disk_info));
220 memset(hardware->mbr_ids, 0, sizeof(hardware->mbr_ids));
221 memset(&hardware->dmi, 0, sizeof(s_dmi));
222 memset(&hardware->cpu, 0, sizeof(s_cpu));
223 memset(&hardware->pxe, 0, sizeof(struct s_pxe));
224 memset(&hardware->vesa, 0, sizeof(struct s_vesa));
225 memset(&hardware->vpd, 0, sizeof(s_vpd));
226 memset(&hardware->acpi, 0, sizeof(s_acpi));
227 memset(hardware->syslinux_fs, 0, sizeof hardware->syslinux_fs);
228 memset(hardware->pciids_path, 0, sizeof hardware->pciids_path);
229 memset(hardware->modules_pcimap_path, 0,
230 sizeof hardware->modules_pcimap_path);
231 memset(hardware->modules_alias_path, 0,
232 sizeof hardware->modules_alias_path);
233 memset(hardware->memtest_label, 0, sizeof hardware->memtest_label);
234 memset(hardware->auto_label, 0, sizeof hardware->auto_label);
235 memset(hardware->dump_path, 0, sizeof hardware->dump_path);
236 memset(hardware->dump_filename, 0, sizeof hardware->dump_filename);
237 memset(hardware->vesa_background, 0, sizeof hardware->vesa_background);
238 memset(hardware->tftp_ip, 0, sizeof hardware->tftp_ip);
239 memset(hardware->postexec, 0, sizeof hardware->postexec);
240 strcat(hardware->dump_path, "hdt");
241 strcat(hardware->dump_filename, "%{m}+%{p}+%{v}");
242 strcat(hardware->pciids_path, "pci.ids");
243 strcat(hardware->modules_pcimap_path, "modules.pcimap");
244 strcat(hardware->modules_alias_path, "modules.alias");
245 strcat(hardware->memtest_label, "memtest");
246 strlcpy(hardware->vesa_background, CLI_DEFAULT_BACKGROUND,
247 sizeof(hardware->vesa_background));
251 * Detecting if a DMI table exist
252 * if yes, let's parse it
254 int detect_dmi(struct s_hardware *hardware)
256 if (hardware->dmi_detection == true)
257 return -1;
258 hardware->dmi_detection = true;
259 if (dmi_iterate(&hardware->dmi) == -ENODMITABLE) {
260 hardware->is_dmi_valid = false;
261 return -ENODMITABLE;
264 parse_dmitable(&hardware->dmi);
265 hardware->is_dmi_valid = true;
266 return 0;
270 * Detecting ACPI
271 * if yes, let's parse it
273 int detect_acpi(struct s_hardware *hardware)
275 int retval;
276 if (hardware->acpi_detection == true)
277 return -1;
278 hardware->acpi_detection = true;
279 if ((retval=parse_acpi(&hardware->acpi)) != ACPI_FOUND) {
280 hardware->is_acpi_valid = false;
281 return retval;
284 hardware->is_acpi_valid = true;
285 return retval;
289 * vpd_detection - populate the VPD structure
291 * VPD is a structure available on IBM machines.
292 * It is documented at:
293 * http://www.pc.ibm.com/qtechinfo/MIGR-45120.html
294 * (XXX the page seems to be gone)
296 int detect_vpd(struct s_hardware *hardware)
298 if (hardware->vpd_detection)
299 return -1;
300 else
301 hardware->vpd_detection = true;
303 if (vpd_decode(&hardware->vpd) == -ENOVPDTABLE) {
304 hardware->is_vpd_valid = false;
305 return -ENOVPDTABLE;
306 } else {
307 hardware->is_vpd_valid = true;
308 return 0;
312 /* Detection vesa stuff*/
313 int detect_vesa(struct s_hardware *hardware)
315 static com32sys_t rm;
316 struct vesa_general_info *gi;
317 struct vesa_mode_info *mi;
318 uint16_t mode, *mode_ptr;
319 char *oem_ptr;
320 int rv = -1;
322 if (hardware->vesa_detection == true)
323 return -1;
325 hardware->vesa_detection = true;
326 hardware->is_vesa_valid = false;
328 gi = lmalloc(sizeof(*gi));
329 if (!gi)
330 return -1;
332 mi = lmalloc(sizeof(*mi));
333 if (!mi)
334 goto out;
336 gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
337 rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
338 rm.edi.w[0] = OFFS(gi);
339 rm.es = SEG(gi);
340 __intcall(0x10, &rm, &rm);
342 if (rm.eax.w[0] != 0x004F) {
343 goto out;
346 mode_ptr = GET_PTR(gi->video_mode_ptr);
347 oem_ptr = GET_PTR(gi->oem_vendor_name_ptr);
348 strlcpy(hardware->vesa.vendor, oem_ptr, sizeof(hardware->vesa.vendor));
349 oem_ptr = GET_PTR(gi->oem_product_name_ptr);
350 strlcpy(hardware->vesa.product, oem_ptr, sizeof(hardware->vesa.product));
351 oem_ptr = GET_PTR(gi->oem_product_rev_ptr);
352 strlcpy(hardware->vesa.product_revision, oem_ptr,
353 sizeof(hardware->vesa.product_revision));
355 hardware->vesa.major_version = (gi->version >> 8) & 0xff;
356 hardware->vesa.minor_version = gi->version & 0xff;
357 hardware->vesa.total_memory = gi->total_memory;
358 hardware->vesa.software_rev = gi->oem_software_rev;
360 hardware->vesa.vmi_count = 0;
362 while ((mode = *mode_ptr++) != 0xFFFF) {
364 rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
365 rm.ecx.w[0] = mode;
366 rm.edi.w[0] = OFFS(mi);
367 rm.es = SEG(mi);
368 __intcall(0x10, &rm, &rm);
370 /* Must be a supported mode */
371 if (rm.eax.w[0] != 0x004f)
372 continue;
374 /* Saving detected values */
375 memcpy(&hardware->vesa.vmi[hardware->vesa.vmi_count].mi, mi,
376 sizeof(struct vesa_mode_info));
377 hardware->vesa.vmi[hardware->vesa.vmi_count].mode = mode;
379 hardware->vesa.vmi_count++;
381 hardware->is_vesa_valid = true;
383 rv = 0;
384 out:
385 lfree(mi);
386 lfree(gi);
387 return rv;
390 /* Try to detect disks from port 0x80 to 0xff */
391 void detect_disks(struct s_hardware *hardware)
393 int i = -1;
394 int err;
396 if (hardware->disk_detection)
397 return;
399 hardware->disk_detection = true;
400 for (int drive = 0x80; drive < 0xff; drive++) {
401 i++;
402 hardware->disk_info[i].disk = drive;
403 err = get_drive_parameters(&hardware->disk_info[i]);
406 * Do not print output when drive does not exist or
407 * doesn't support int13 (cdrom, ...)
409 if (err == -1 || !hardware->disk_info[i].cbios)
410 continue;
412 /* Detect MBR */
413 hardware->mbr_ids[i] = get_mbr_id(&hardware->disk_info[i]);
415 hardware->disks_count++;
419 int detect_pxe(struct s_hardware *hardware)
421 void *dhcpdata;
423 size_t dhcplen;
424 t_PXENV_UNDI_GET_NIC_TYPE gnt;
426 if (hardware->pxe_detection == true)
427 return -1;
428 hardware->pxe_detection = true;
429 hardware->is_pxe_valid = false;
430 memset(&gnt, 0, sizeof(t_PXENV_UNDI_GET_NIC_TYPE));
431 memset(&hardware->pxe, 0, sizeof(struct s_pxe));
433 /* This code can only work if pxelinux is loaded */
434 if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) {
435 return -1;
437 // printf("PXE: PXElinux detected\n");
438 if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
439 pxe_bootp_t *dhcp = &hardware->pxe.dhcpdata;
440 memcpy(&hardware->pxe.dhcpdata, dhcpdata,
441 sizeof(hardware->pxe.dhcpdata));
442 snprintf(hardware->pxe.mac_addr, sizeof(hardware->pxe.mac_addr),
443 "%02x:%02x:%02x:%02x:%02x:%02x", dhcp->CAddr[0],
444 dhcp->CAddr[1], dhcp->CAddr[2], dhcp->CAddr[3],
445 dhcp->CAddr[4], dhcp->CAddr[5]);
447 /* Saving our IP address in a easy format */
448 hardware->pxe.ip_addr[0] = hardware->pxe.dhcpdata.yip & 0xff;
449 hardware->pxe.ip_addr[1] = hardware->pxe.dhcpdata.yip >> 8 & 0xff;
450 hardware->pxe.ip_addr[2] = hardware->pxe.dhcpdata.yip >> 16 & 0xff;
451 hardware->pxe.ip_addr[3] = hardware->pxe.dhcpdata.yip >> 24 & 0xff;
453 if (!pxe_get_nic_type(&gnt)) {
454 switch (gnt.NicType) {
455 case PCI_NIC:
456 hardware->is_pxe_valid = true;
457 hardware->pxe.vendor_id = gnt.info.pci.Vendor_ID;
458 hardware->pxe.product_id = gnt.info.pci.Dev_ID;
459 hardware->pxe.subvendor_id = gnt.info.pci.SubVendor_ID;
460 hardware->pxe.subproduct_id =
461 gnt.info.pci.SubDevice_ID,
462 hardware->pxe.rev = gnt.info.pci.Rev;
463 hardware->pxe.pci_bus = (gnt.info.pci.BusDevFunc >> 8) & 0xff;
464 hardware->pxe.pci_dev = (gnt.info.pci.BusDevFunc >> 3) & 0x7;
465 hardware->pxe.pci_func = gnt.info.pci.BusDevFunc & 0x03;
466 hardware->pxe.base_class = gnt.info.pci.Base_Class;
467 hardware->pxe.sub_class = gnt.info.pci.Sub_Class;
468 hardware->pxe.prog_intf = gnt.info.pci.Prog_Intf;
469 hardware->pxe.nictype = gnt.NicType;
470 break;
471 case CardBus_NIC:
472 hardware->is_pxe_valid = true;
473 hardware->pxe.vendor_id = gnt.info.cardbus.Vendor_ID;
474 hardware->pxe.product_id = gnt.info.cardbus.Dev_ID;
475 hardware->pxe.subvendor_id = gnt.info.cardbus.SubVendor_ID;
476 hardware->pxe.subproduct_id =
477 gnt.info.cardbus.SubDevice_ID,
478 hardware->pxe.rev = gnt.info.cardbus.Rev;
479 hardware->pxe.pci_bus =
480 (gnt.info.cardbus.BusDevFunc >> 8) & 0xff;
481 hardware->pxe.pci_dev =
482 (gnt.info.cardbus.BusDevFunc >> 3) & 0x7;
483 hardware->pxe.pci_func = gnt.info.cardbus.BusDevFunc & 0x03;
484 hardware->pxe.base_class = gnt.info.cardbus.Base_Class;
485 hardware->pxe.sub_class = gnt.info.cardbus.Sub_Class;
486 hardware->pxe.prog_intf = gnt.info.cardbus.Prog_Intf;
487 hardware->pxe.nictype = gnt.NicType;
488 break;
489 case PnP_NIC:
490 default:
491 return -1;
492 break;
495 /* The firt pass try to find the exact pci device */
496 hardware->pxe.pci_device = NULL;
497 hardware->pxe.pci_device_pos = 0;
498 struct pci_device *pci_device;
499 int pci_number = 0;
500 for_each_pci_func(pci_device, hardware->pci_domain) {
501 pci_number++;
502 if ((__pci_bus == hardware->pxe.pci_bus) &&
503 (__pci_slot == hardware->pxe.pci_dev) &&
504 (__pci_func == hardware->pxe.pci_func) &&
505 (pci_device->vendor == hardware->pxe.vendor_id)
506 && (pci_device->product == hardware->pxe.product_id)) {
507 hardware->pxe.pci_device = pci_device;
508 hardware->pxe.pci_device_pos = pci_number;
509 return 0;
513 /* If we reach that part, it means the pci device pointed by
514 * the pxe rom wasn't found in our list.
515 * Let's try to find the device only by its pci ids.
516 * The pci device we'll match is maybe not exactly the good one
517 * as we can have the same pci id several times.
518 * At least, the pci id, the vendor/product will be right.
519 * That's clearly a workaround for some weird cases.
520 * This should happend very unlikely */
521 hardware->pxe.pci_device = NULL;
522 hardware->pxe.pci_device_pos = 0;
523 pci_number = 0;
524 for_each_pci_func(pci_device, hardware->pci_domain) {
525 pci_number++;
526 if ((pci_device->vendor == hardware->pxe.vendor_id)
527 && (pci_device->product == hardware->pxe.product_id)) {
528 hardware->pxe.pci_device = pci_device;
529 hardware->pxe.pci_device_pos = pci_number;
530 return 0;
536 return 0;
539 void detect_memory(struct s_hardware *hardware) {
540 if (hardware->memory_detection == false) {
541 hardware->memory_detection = true;
542 hardware->detected_memory_size = detect_memsize();
546 void detect_pci(struct s_hardware *hardware)
548 if (hardware->pci_detection == true)
549 return;
550 hardware->pci_detection = true;
552 hardware->nb_pci_devices = 0;
554 /* Scanning to detect pci buses and devices */
555 hardware->pci_domain = pci_scan();
557 if (!hardware->pci_domain)
558 return;
560 /* Gathering addtional information */
561 gather_additional_pci_config(hardware->pci_domain);
563 struct pci_device *pci_device;
564 for_each_pci_func(pci_device, hardware->pci_domain) {
565 hardware->nb_pci_devices++;
568 if (!quiet) {
569 more_printf("PCI: %d devices detected\n", hardware->nb_pci_devices);
570 more_printf("PCI: Resolving names\n");
572 /* Assigning product & vendor name for each device */
573 hardware->pci_ids_return_code =
574 get_name_from_pci_ids(hardware->pci_domain, hardware->pciids_path);
576 if (!quiet)
577 more_printf("PCI: Resolving class names\n");
578 /* Assigning class name for each device */
579 hardware->pci_ids_return_code =
580 get_class_name_from_pci_ids(hardware->pci_domain,
581 hardware->pciids_path);
583 if (!quiet)
584 more_printf("PCI: Resolving module names\n");
585 /* Detecting which kernel module should match each device using modules.pcimap */
586 hardware->modules_pcimap_return_code =
587 get_module_name_from_pcimap(hardware->pci_domain,
588 hardware->modules_pcimap_path);
590 /* Detecting which kernel module should match each device using modules.alias */
591 hardware->modules_alias_return_code =
592 get_module_name_from_alias(hardware->pci_domain,
593 hardware->modules_alias_path);
597 void cpu_detect(struct s_hardware *hardware)
599 if (hardware->cpu_detection == true)
600 return;
601 detect_cpu(&hardware->cpu);
602 /* Old processors doesn't manage the identify commands
603 * Let's use the dmi value in that case */
604 if (strlen(remove_spaces(hardware->cpu.model)) == 0)
605 strlcpy(hardware->cpu.model, hardware->dmi.processor.version,
606 sizeof(hardware->cpu.model));
608 /* Some CPUs like to put many spaces in the model name
609 * That makes some weird display in console/menu
610 * Let's remove that mulitple spaces */
611 strlcpy(hardware->cpu.model,del_multi_spaces(hardware->cpu.model),sizeof(hardware->cpu.model));
613 if ((hardware->is_acpi_valid) && (hardware->acpi.madt.valid)) {
614 hardware->physical_cpu_count=hardware->acpi.madt.processor_local_apic_count / hardware->cpu.num_cores;
616 hardware->cpu_detection = true;
620 * Find the last instance of a particular command line argument
621 * (which should include the final =; do not use for boolean arguments)
623 const char *find_argument(const char **argv, const char *argument)
625 int la = strlen(argument);
626 const char **arg;
627 const char *ptr = NULL;
629 for (arg = argv; *arg; arg++) {
630 if (!memcmp(*arg, argument, la))
631 ptr = *arg + la;
634 return ptr;
637 void clear_screen(void)
639 move_cursor_to_next_line();
640 disable_utf8();
641 set_g1_special_char();
642 set_us_g0_charset();
643 display_cursor(false);
644 clear_entire_screen();
645 gotoxy(0,0);
646 reset_more_printf();
649 /* remove begining spaces */
650 char *skip_spaces(char *p)
652 while (*p && *p <= ' ') {
653 p++;
656 return p;
659 /* remove trailing & begining spaces */
660 char *remove_spaces(char *p)
662 char *save = p;
663 p += strlen(p) - 1;
664 while (*p && *p <= ' ') {
665 *p = '\0';
666 p--;
668 p = save;
669 while (*p && *p <= ' ') {
670 p++;
673 return p;
676 /* remove trailing LF */
677 char *remove_trailing_lf(char *p)
679 char *save = p;
680 p += strlen(p) - 1;
681 while (*p && *p == 10) {
682 *p = '\0';
683 p--;
685 p = save;
687 return p;
690 /* delete multiple spaces, one is enough */
691 char *del_multi_spaces(char *p)
693 /* Saving the original pointer */
694 char *save = p;
696 /* Let's parse the complete string
697 * As we search for a double spacing
698 * we have to be sure then string is
699 * long enough to be processed */
700 while (*p && *(p + 1)) {
702 /* If we have two consecutive spaces */
703 if ((*p == ' ') && (*(p + 1) == ' ')) {
705 /* Let's copy to the current position
706 * the content from the second space*/
707 strlcpy(p, p + 1, strlen(p + 1));
709 /* Don't increment the pointer as we
710 * changed the content of the current position*/
711 continue;
714 /* Nothing as been found, let's see on the next char */
715 p++;
717 /* Returning the original pointer */
718 return save;
721 /* Reset the more_printf counter */
722 void reset_more_printf(void)
724 display_line_nb = 0;
727 int draw_background(const char *what)
729 if (!what)
730 return vesacon_default_background();
731 else
732 return vesacon_load_background(what);
735 void init_console(struct s_hardware *hardware)
737 if (vesamode) {
738 openconsole(&dev_rawcon_r, &dev_vesaserial_w);
739 draw_background(hardware->vesa_background);
740 } else
741 console_ansi_raw();
744 void detect_hardware(struct s_hardware *hardware)
746 if (!quiet)
747 more_printf("ACPI: Detecting\n");
748 detect_acpi(hardware);
750 if (!quiet)
751 more_printf("MEMORY: Detecting\n");
752 detect_memory(hardware);
754 if (!quiet)
755 more_printf("DMI: Detecting Table\n");
756 if (detect_dmi(hardware) == -ENODMITABLE) {
757 more_printf("DMI: ERROR ! Table not found ! \n");
758 more_printf("DMI: Many hardware components will not be detected ! \n");
759 } else {
760 if (!quiet)
761 more_printf("DMI: Table found ! (version %u.%u)\n",
762 hardware->dmi.dmitable.major_version,
763 hardware->dmi.dmitable.minor_version);
766 if (!quiet)
767 more_printf("CPU: Detecting\n");
768 cpu_detect(hardware);
770 if (!quiet)
771 more_printf("DISKS: Detecting\n");
772 detect_disks(hardware);
774 if (!quiet)
775 more_printf("VPD: Detecting\n");
776 detect_vpd(hardware);
778 detect_pci(hardware);
779 if (!quiet)
780 more_printf("PCI: %d Devices Found\n", hardware->nb_pci_devices);
782 if (!quiet)
783 more_printf("PXE: Detecting\n");
784 detect_pxe(hardware);
786 if (!quiet)
787 more_printf("VESA: Detecting\n");
788 detect_vesa(hardware);