Corey Tabaka | 8469724 | 2009-03-26 02:32:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009 Corey Tabaka |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <err.h> |
| 24 | #include <debug.h> |
| 25 | #include <arch/x86/mmu.h> |
| 26 | #include <platform.h> |
| 27 | #include "platform_p.h" |
Corey Tabaka | b3f6cac | 2009-04-01 17:35:12 -0400 | [diff] [blame] | 28 | #include <platform/pc.h> |
Corey Tabaka | 8469724 | 2009-03-26 02:32:01 -0400 | [diff] [blame] | 29 | #include <platform/multiboot.h> |
| 30 | #include <platform/console.h> |
| 31 | #include <platform/keyboard.h> |
Corey Tabaka | b0bd183 | 2009-04-03 01:17:52 -0400 | [diff] [blame] | 32 | #include <dev/pci.h> |
Corey Tabaka | 8469724 | 2009-03-26 02:32:01 -0400 | [diff] [blame] | 33 | |
| 34 | extern multiboot_info_t *_multiboot_info; |
| 35 | extern unsigned int _heap_end; |
| 36 | |
| 37 | void platform_init_mmu_mappings(void) |
| 38 | { |
| 39 | /* do some memory map initialization */ |
| 40 | } |
| 41 | |
| 42 | |
| 43 | void platform_init_multiboot_info(void) |
| 44 | { |
| 45 | unsigned int i; |
| 46 | |
| 47 | if (_multiboot_info) { |
| 48 | if (_multiboot_info->flags & MB_INFO_MEM_SIZE) { |
| 49 | _heap_end = _multiboot_info->mem_upper * 1024; |
| 50 | } |
| 51 | |
| 52 | if (_multiboot_info->flags & MB_INFO_MMAP) { |
| 53 | memory_map_t *mmap = (memory_map_t *) (_multiboot_info->mmap_addr - 4); |
| 54 | |
| 55 | dprintf(DEBUG, "mmap length: %u\n", _multiboot_info->mmap_length); |
| 56 | |
| 57 | for (i=0; i < _multiboot_info->mmap_length / sizeof(memory_map_t); i++) { |
| 58 | dprintf(DEBUG, "base=%08x, length=%08x, type=%02x\n", |
| 59 | mmap[i].base_addr_low, mmap[i].length_low, mmap[i].type); |
| 60 | |
| 61 | if (mmap[i].type == MB_MMAP_TYPE_AVAILABLE && mmap[i].base_addr_low >= _heap_end) { |
| 62 | _heap_end = mmap[i].base_addr_low + mmap[i].length_low; |
| 63 | } else if (mmap[i].type != MB_MMAP_TYPE_AVAILABLE && mmap[i].base_addr_low >= _heap_end) { |
| 64 | /* |
| 65 | * break on first memory hole above default heap end for now. |
| 66 | * later we can add facilities for adding free chunks to the |
| 67 | * heap for each segregated memory region. |
| 68 | */ |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void platform_early_init(void) |
| 77 | { |
| 78 | /* update the heap end so we can take advantage of more ram */ |
| 79 | platform_init_multiboot_info(); |
| 80 | |
| 81 | /* get the text console working */ |
| 82 | platform_init_console(); |
| 83 | |
| 84 | /* initialize the interrupt controller */ |
| 85 | platform_init_interrupts(); |
| 86 | |
| 87 | /* initialize the timer */ |
| 88 | platform_init_timer(); |
| 89 | } |
| 90 | |
| 91 | void platform_init(void) |
| 92 | { |
| 93 | platform_init_keyboard(); |
| 94 | |
Corey Tabaka | b0bd183 | 2009-04-03 01:17:52 -0400 | [diff] [blame] | 95 | pci_init(); |
Corey Tabaka | 8469724 | 2009-03-26 02:32:01 -0400 | [diff] [blame] | 96 | } |
| 97 | |