libmeinos: +llist2
[meinos.git] / kernel2 / multiboot.c
blobad5b8ae3aa8010716ec1f3ee19af778610433d14
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
20 #include <sizes.h>
21 #include <stddef.h>
22 #include <debug.h>
23 #include <multiboot.h>
25 /// Pointer to multiboot structure
26 multiboot_info_t *multiboot_info;
28 /**
29 * Initializes Multiboot
30 * @param mbi Multiboot sturcture
31 * @return 0=Success; -1=Failure
33 int multiboot_init(multiboot_info_t *mbi) {
34 multiboot_info = mbi;
35 return 0;
38 /**
39 * Gets amount of lower memory
40 * @return Amount of lower memory
42 size_t multiboot_get_memlower() {
43 return ((size_t)multiboot_info->mem_lower)*KBYTES;
46 /**
47 * Gets amount of upper memory
48 * @return Amount of upper memory
50 size_t multiboot_get_memupper() {
51 return ((size_t)multiboot_info->mem_upper)*KBYTES;
54 /**
55 * Gets bootdevice
56 * @return Bootdevice
58 int multiboot_get_bootdev() {
59 return *((int*)(multiboot_info->boot_device));
62 /**
63 * Gets command line
64 * @return Command line
66 char* multiboot_get_cmdline() {
67 return (char*)(multiboot_info->cmdline);
70 /**
71 * Gets list of modules
72 * @param i Number of Module
73 * @param name Reference for name pointer
74 * @param size Reference for module size
76 void *multiboot_get_mod(size_t i,char **name,size_t *size) {
77 if (i>=multiboot_info->mods_count) return NULL;
78 multiboot_mod_t *mod = ((multiboot_mod_t*)(multiboot_info->mods_addr))+i;
79 if (name!=NULL) *name = (char*)(mod->mod_name);
80 if (size!=NULL) *size = mod->mod_end-mod->mod_start;
81 return (void*)(mod->mod_start);
84 /**
85 * Gets name of bootloader
86 * @return Name of bootloader
88 char *multiboot_get_bootloader() {
89 return (char*)(multiboot_info->boot_loader_name);
92 /**
93 * Gets a memory map item
94 * @param item Number of item
95 * @param addr Reference for memory block's base address
96 * @param length Reference for memory block's length
97 * @param type Reference for memory block's type
98 * @return 0=Success; -1=Failure
100 int multiboot_get_mmap(int item,void **addr,size_t *length,multiboot_mmap_type_t *type) {
101 if (!multiboot_checkflag(multiboot_info,6)) return -1;
102 multiboot_mmape_t *mmap;
103 size_t i = 0;
105 for (mmap=(multiboot_mmape_t*)multiboot_info->mmap_addr;(unsigned long)mmap<multiboot_info->mmap_addr+multiboot_info->mmap_length;mmap=(multiboot_mmape_t*)((unsigned long)mmap+mmap->size+sizeof(mmap->size))) {
106 if (i==item) {
107 if (addr!=NULL) *addr = (void*)((unsigned int)mmap->base);
108 if (length!=NULL) *length = mmap->length;
109 if (type!=NULL) *type = mmap->type;
110 return 0;
112 i++;
115 return -1;