aboutsummaryrefslogtreecommitdiff
path: root/util/extensions/legacybios/arch/x86/multiboot.c
blob: a1793cf4253aabb49ad3f2f8527e69b160c8940f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2003 Stefan Reinauer
 *
 * See the file "COPYING" for further information about
 * the copyright and warranty status of this work.
 */

#include "config.h"
#include "types.h"
#include "multiboot.h"

/* Multiboot: Check if the bit BIT in FLAGS is set.  */
#define CHECK_FLAG(flags,bit)	((flags) & (1 << (bit)))

#ifdef DEBUG_CONSOLE
void cls(void);
void printk(const char *fmt, ...);
int uart_init(int port, unsigned long speed);
#endif

void legacybios(ucell romstart, ucell romend);

/* Check if MAGIC is valid and print the Multiboot information structure
   pointed by ADDR.  */

void cmain(unsigned long magic, unsigned long addr)
{
	multiboot_info_t *mbi;

#ifdef DEBUG_CONSOLE
	uart_init(SERIAL_PORT, SERIAL_SPEED);
	/* Clear the screen.  */
	cls();
#endif

	/* Am I booted by a Multiboot-compliant boot loader?  */
	if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
		printk("legacybios: loader not multiboot capable\n");
		return;
	}

	/* Set MBI to the address of the Multiboot information structure.  */
	mbi = (multiboot_info_t *) addr;

#ifdef DEBUG_BOOT
	/* Print out the flags.  */
	printk("flags = 0x%x\n", mbi->flags);

	/* Are mem_* valid?  */
	if (CHECK_FLAG(mbi->flags, 0))
		printk("mem_lower = %dKB, mem_upper = %dKB\n",
		       mbi->mem_lower, mbi->mem_upper);

	/* Is boot_device valid?  */
	if (CHECK_FLAG(mbi->flags, 1))
		printk("boot_device = 0x%x\n", mbi->boot_device);

	/* Is the command line passed?  */
	if (CHECK_FLAG(mbi->flags, 2))
		printk("cmdline = %s\n", (char *) mbi->cmdline);
#endif

#ifdef DEBUG_BOOT
	/* Bits 4 and 5 are mutually exclusive!  */
	if (CHECK_FLAG(mbi->flags, 4) && CHECK_FLAG(mbi->flags, 5)) {
		printk("panic: binary claims to be a.out and elf.\n");
		return;
	}
#endif

	/* Are mods_* valid?  */
	if (CHECK_FLAG(mbi->flags, 3)) {
		module_t *mod;
		unsigned int i;
#ifdef DEBUG_BOOT
		printk("mods_count = %d, mods_addr = 0x%x\n",
		       mbi->mods_count, mbi->mods_addr);
#endif
		for (i = 0, mod = (module_t *) mbi->mods_addr;
		     i < mbi->mods_count; i++, mod += sizeof(module_t)) {
			legacybios(mod->mod_start,  mod->mod_end);
#ifdef DEBUG_BOOT
			printk
			    (" mod_start = 0x%x, mod_end = 0x%x, string = %s\n",
			     mod->mod_start, mod->mod_end,
			     (char *) mod->string);
#endif
		}
	}

	return;
}