Changes in kernel/genarch/src/multiboot/multiboot.c [32817cc:d99c1d2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/multiboot/multiboot.c
r32817cc rd99c1d2 33 33 */ 34 34 35 #include <genarch/multiboot/multiboot.h> 35 36 #include <typedefs.h> 36 #include <genarch/multiboot/multiboot.h>37 37 #include <config.h> 38 38 #include <str.h> 39 #include <macros.h> 39 40 40 41 /** Extract command name from the multiboot module command line. 41 42 * 42 * @param buf Destination buffer (will be always NULL-terminated).43 * @param s izeSize of destination buffer (in bytes).43 * @param buf Destination buffer (will always NULL-terminate). 44 * @param sz Size of destination buffer (in bytes). 44 45 * @param cmd_line Input string (the command line). 45 46 * 46 47 */ 47 void multiboot_extract_command(char *buf, size_t size, const char *cmd_line)48 static void extract_command(char *buf, size_t sz, const char *cmd_line) 48 49 { 49 50 /* Find the first space. */ … … 68 69 69 70 /* Copy the command. */ 70 str_ncpy(buf, size, start, (size_t) (end - start)); 71 } 72 73 static void multiboot_modules(uint32_t count, multiboot_module_t *mods) 74 { 75 for (uint32_t i = 0; i < count; i++) { 76 if (init.cnt >= CONFIG_INIT_TASKS) 77 break; 78 79 init.tasks[init.cnt].paddr = mods[i].start; 80 init.tasks[init.cnt].size = mods[i].end - mods[i].start; 81 82 /* Copy command line, if available. */ 83 if (mods[i].string) { 84 multiboot_extract_command(init.tasks[init.cnt].name, 85 CONFIG_TASK_NAME_BUFLEN, MULTIBOOT_PTR(mods[i].string)); 86 } else 87 init.tasks[init.cnt].name[0] = 0; 88 89 init.cnt++; 90 } 91 } 92 93 static void multiboot_memmap(uint32_t length, multiboot_memmap_t *memmap) 94 { 95 uint32_t pos = 0; 96 97 while ((pos < length) && (e820counter < MEMMAP_E820_MAX_RECORDS)) { 98 e820table[e820counter] = memmap->mm_info; 99 100 /* Compute address of next structure. */ 101 uint32_t size = sizeof(memmap->size) + memmap->size; 102 memmap = (multiboot_memmap_t *) ((uintptr_t) memmap + size); 103 pos += size; 104 105 e820counter++; 106 } 71 str_ncpy(buf, sz, start, (size_t) (end - start)); 107 72 } 108 73 … … 113 78 * 114 79 * @param signature Should contain the multiboot signature. 115 * @param info Multiboot information structure. 116 * 80 * @param mi Pointer to the multiboot information structure. 117 81 */ 118 void multiboot_info_parse(uint32_t signature, const multiboot_info_t * info)82 void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi) 119 83 { 120 if (signature != MULTIBOOT_LOADER_MAGIC) 121 return; 84 uint32_t flags; 122 85 123 /* Copy modules information. */ 124 if ((info->flags & MULTIBOOT_INFO_FLAGS_MODS) != 0) 125 multiboot_modules(info->mods_count, 126 (multiboot_module_t *) MULTIBOOT_PTR(info->mods_addr)); 86 if (signature == MULTIBOOT_LOADER_MAGIC) 87 flags = mi->flags; 88 else { 89 /* No multiboot info available. */ 90 flags = 0; 91 } 92 93 /* Copy module information. */ 94 uint32_t i; 95 if ((flags & MBINFO_FLAGS_MODS) != 0) { 96 init.cnt = min(mi->mods_count, CONFIG_INIT_TASKS); 97 multiboot_mod_t *mods 98 = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr); 99 100 for (i = 0; i < init.cnt; i++) { 101 init.tasks[i].addr = PA2KA(mods[i].start); 102 init.tasks[i].size = mods[i].end - mods[i].start; 103 104 /* Copy command line, if available. */ 105 if (mods[i].string) { 106 extract_command(init.tasks[i].name, 107 CONFIG_TASK_NAME_BUFLEN, 108 MULTIBOOT_PTR(mods[i].string)); 109 } else 110 init.tasks[i].name[0] = 0; 111 } 112 } else 113 init.cnt = 0; 127 114 128 115 /* Copy memory map. */ 129 if ((info->flags & MULTIBOOT_INFO_FLAGS_MMAP) != 0) 130 multiboot_memmap(info->mmap_length, 131 (multiboot_memmap_t *) MULTIBOOT_PTR(info->mmap_addr)); 116 117 if ((flags & MBINFO_FLAGS_MMAP) != 0) { 118 int32_t mmap_length = mi->mmap_length; 119 multiboot_mmap_t *mme = MULTIBOOT_PTR(mi->mmap_addr); 120 e820counter = 0; 121 122 i = 0; 123 while ((mmap_length > 0) && (i < MEMMAP_E820_MAX_RECORDS)) { 124 e820table[i++] = mme->mm_info; 125 126 /* Compute address of next structure. */ 127 uint32_t size = sizeof(mme->size) + mme->size; 128 mme = ((void *) mme) + size; 129 mmap_length -= size; 130 } 131 132 e820counter = i; 133 } else 134 e820counter = 0; 132 135 } 133 136
Note:
See TracChangeset
for help on using the changeset viewer.