mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
map cmdline 1:1 into the virtual address space, refactoring of the code
This commit is contained in:
parent
451a36176f
commit
070d5fac66
5 changed files with 24 additions and 17 deletions
|
@ -167,25 +167,16 @@ static void fpu_init_xsave(union fpu_state* fpu)
|
|||
xs->fxsave.mxcsr = 0x1f80;
|
||||
}
|
||||
|
||||
static char* cmdline = 0;
|
||||
|
||||
static uint32_t get_frequency_from_mbinfo(void)
|
||||
{
|
||||
if (mb_info && (mb_info->flags & MULTIBOOT_INFO_CMDLINE))
|
||||
{
|
||||
int i;
|
||||
|
||||
cmdline = (char*) vma_alloc(PAGE_SIZE, VMA_READ|VMA_WRITE|VMA_CACHEABLE);
|
||||
if (BUILTIN_EXPECT(!cmdline, 0))
|
||||
// search in the command line for cpu frequency
|
||||
char* found = strstr((char*) mb_info->cmdline, "-freq");
|
||||
if (!found)
|
||||
return 0;
|
||||
|
||||
page_map((size_t) cmdline, mb_info->cmdline & PAGE_MASK, 1, PG_GLOBAL|PG_RW|PG_PRESENT);
|
||||
cmdline = (char*) ((size_t) cmdline | (mb_info->cmdline & ~PAGE_MASK));
|
||||
|
||||
for(i=0; (cmdline[i] != '\0') && (cmdline[i] != ' '); i++)
|
||||
;
|
||||
|
||||
return atoi(cmdline+i+1);
|
||||
return atoi(found+strlen("-freq"));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <hermit/spinlock.h>
|
||||
#include <hermit/tasks.h>
|
||||
|
||||
#include <asm/multiboot.h>
|
||||
#include <asm/irq.h>
|
||||
#include <asm/page.h>
|
||||
|
||||
|
@ -303,6 +304,11 @@ int page_init(void)
|
|||
kputs("Detect Go runtime! Consequently, HermitCore zeroed heap.\n");
|
||||
}
|
||||
|
||||
if (mb_info && ((mb_info->cmdline & PAGE_MASK) != ((size_t) mb_info & PAGE_MASK))) {
|
||||
kprintf("Map multiboot cmdline 0x%x into the virtual address space\n", mb_info->cmdline);
|
||||
page_map((size_t) mb_info->cmdline & PAGE_MASK, mb_info->cmdline & PAGE_MASK, 1, PG_GLOBAL|PG_RW|PG_PRESENT);
|
||||
}
|
||||
|
||||
/* Replace default pagefault handler */
|
||||
irq_uninstall_handler(14);
|
||||
irq_install_handler(14, page_fault_handler);
|
||||
|
|
|
@ -347,6 +347,8 @@ int memory_init(void)
|
|||
last->end = end_addr;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: mb_info and mb_info->cmdline should be marked as reserevd
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,9 +75,15 @@ int vma_init(void)
|
|||
#endif
|
||||
|
||||
if (mb_info) {
|
||||
ret = vma_add((size_t)mb_info, (size_t)mb_info + PAGE_SIZE, VMA_READ|VMA_WRITE);
|
||||
ret = vma_add((size_t)mb_info & PAGE_MASK, ((size_t)mb_info & PAGE_MASK) + PAGE_SIZE, VMA_READ|VMA_WRITE);
|
||||
if (BUILTIN_EXPECT(ret, 0))
|
||||
goto out;
|
||||
|
||||
if ((mb_info->cmdline & PAGE_MASK) != ((size_t) mb_info & PAGE_MASK)) {
|
||||
ret = vma_add((size_t)mb_info->cmdline & PAGE_MASK, ((size_t)mb_info->cmdline & PAGE_MASK) + PAGE_SIZE, VMA_READ|VMA_WRITE);
|
||||
if (BUILTIN_EXPECT(ret, 0))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
|
|
|
@ -72,6 +72,7 @@ static unsigned int qemu = 0;
|
|||
static pid_t id = 0;
|
||||
static unsigned int port = HERMIT_PORT;
|
||||
static char tmpname[] = "/tmp/hermit-XXXXXX";
|
||||
static char cmdline[MAX_PATH] = "";
|
||||
|
||||
extern char **environ;
|
||||
|
||||
|
@ -109,6 +110,7 @@ static char* cpufreq(void)
|
|||
const char* pcreErrorStr = NULL;
|
||||
int creErrorOffset = 0;
|
||||
char line[2048];
|
||||
const char* match = NULL;
|
||||
int rc, results[10];
|
||||
|
||||
pcre* reCompiled = pcre_compile(pattern, PCRE_ANCHORED, &pcreErrorStr, &creErrorOffset, NULL);
|
||||
|
@ -124,13 +126,13 @@ static char* cpufreq(void)
|
|||
if ((rc = pcre_exec(reCompiled, 0, line, 2048, 0, 0, results, 10)) < 0)
|
||||
continue;
|
||||
|
||||
const char* match = NULL;
|
||||
pcre_get_substring(line, results, rc, 1, &(match));
|
||||
|
||||
snprintf(cmdline, MAX_PATH, "-freq%s", match);
|
||||
fclose(fp);
|
||||
pcre_free_substring(match);
|
||||
pcre_free(reCompiled);
|
||||
|
||||
return (char*)match;
|
||||
return cmdline;
|
||||
}
|
||||
|
||||
return "0";
|
||||
|
|
Loading…
Add table
Reference in a new issue