mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
create readonly page for kernel information
=> map this into the user-space => applications are able to read status information
This commit is contained in:
parent
ade3629df2
commit
1ac0c41af1
3 changed files with 31 additions and 11 deletions
|
@ -49,11 +49,13 @@ align 4
|
|||
global cpu_freq
|
||||
global boot_processor
|
||||
global cpu_online
|
||||
global timer_ticks
|
||||
base dq 0
|
||||
limit dq 0
|
||||
cpu_freq dd 0
|
||||
boot_processor dd -1
|
||||
cpu_online dd 0
|
||||
timer_ticks dq 0
|
||||
|
||||
SECTION .text
|
||||
align 4
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <asm/tss.h>
|
||||
|
||||
extern tss_t task_state_segments[MAX_CORES];
|
||||
extern uint64_t base;
|
||||
|
||||
size_t* get_current_stack(void)
|
||||
{
|
||||
|
@ -135,8 +136,9 @@ typedef struct {
|
|||
*/
|
||||
static int load_task(load_args_t* largs)
|
||||
{
|
||||
uint32_t i, offset, idx;
|
||||
uint32_t addr, npages;
|
||||
uint32_t i;
|
||||
uint64_t offset, idx;
|
||||
uint64_t addr, npages;
|
||||
size_t stack = 0, heap = 0;
|
||||
size_t flags;
|
||||
elf_header_t header;
|
||||
|
@ -206,7 +208,7 @@ static int load_task(load_args_t* largs)
|
|||
ret = -ENOMEM;
|
||||
goto Lerr;
|
||||
}
|
||||
|
||||
|
||||
flags = PG_USER;
|
||||
if (has_nx() && !(prog_header.flags & PF_X))
|
||||
flags |= PG_XD;
|
||||
|
@ -256,7 +258,7 @@ static int load_task(load_args_t* largs)
|
|||
goto Lerr;
|
||||
}
|
||||
|
||||
stack = header.entry*2; // virtual address of the stack
|
||||
stack = (1ULL << 34ULL); // virtual address of the stack
|
||||
flags = PG_USER|PG_RW;
|
||||
if (has_nx() && !(prog_header.flags & PF_X))
|
||||
flags |= PG_XD;
|
||||
|
@ -267,6 +269,7 @@ static int load_task(load_args_t* largs)
|
|||
goto Lerr;
|
||||
}
|
||||
memset((void*) stack, 0x00, npages*PAGE_SIZE);
|
||||
//kprintf("stack located at 0x%zx (0x%zx)\n", stack, addr);
|
||||
|
||||
// create vma regions for the user-level stack
|
||||
flags = VMA_CACHEABLE|VMA_USER;
|
||||
|
@ -349,6 +352,13 @@ static int load_task(load_args_t* largs)
|
|||
// clear fpu state => currently not supported
|
||||
curr_task->flags &= ~(TASK_FPU_USED|TASK_FPU_INIT);
|
||||
|
||||
// map readonly kernel info into the user-space => vsyscall
|
||||
if (has_nx())
|
||||
page_map(header.entry - PAGE_SIZE, base, 1, PG_USER|PG_XD);
|
||||
else
|
||||
page_map(header.entry - PAGE_SIZE, base, 1, PG_USER);
|
||||
vma_add(header.entry - PAGE_SIZE, header.entry, VMA_READ|VMA_CACHEABLE|VMA_USER);
|
||||
|
||||
//vma_dump();
|
||||
|
||||
asm volatile ("swapgs");
|
||||
|
|
|
@ -270,7 +270,6 @@ main()
|
|||
b[j] = 2.0;
|
||||
c[j] = 0.0;
|
||||
}
|
||||
|
||||
printf(HLINE);
|
||||
|
||||
if ( (quantum = checktick()) >= 1)
|
||||
|
@ -300,7 +299,7 @@ main()
|
|||
printf("For best results, please be sure you know the\n");
|
||||
printf("precision of your system timer.\n");
|
||||
printf(HLINE);
|
||||
|
||||
|
||||
/* --- MAIN LOOP --- repeat test cases NTIMES times --- */
|
||||
|
||||
scalar = 3.0;
|
||||
|
@ -387,7 +386,6 @@ checktick()
|
|||
double t1, t2, timesfound[M];
|
||||
|
||||
/* Collect a sequence of M unique time values from the system. */
|
||||
|
||||
for (i = 0; i < M; i++) {
|
||||
t1 = mysecond();
|
||||
while( ((t2=mysecond()) - t1) < 1.0E-6 )
|
||||
|
@ -418,6 +416,15 @@ checktick()
|
|||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
extern unsigned int get_cpufreq();
|
||||
|
||||
inline static unsigned long long rdtscp(void)
|
||||
{
|
||||
unsigned long long lo, hi;
|
||||
asm volatile ("rdtscp" : "=a"(lo), "=d"(hi) :: "%rcx");
|
||||
return (hi << 32 | lo);
|
||||
}
|
||||
|
||||
double mysecond()
|
||||
{
|
||||
#if 0
|
||||
|
@ -428,16 +435,17 @@ double mysecond()
|
|||
i = gettimeofday(&tp,&tzp);
|
||||
return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );
|
||||
#else
|
||||
static clock_t start, init = 0;
|
||||
static unsigned long long start;
|
||||
static int init = 0;
|
||||
double ret;
|
||||
|
||||
if (init) {
|
||||
ret = (double) (clock() - start) / (double) CLOCKS_PER_SEC;
|
||||
ret = (double) (rdtscp() - start) / ((double) get_cpufreq() * 1000000.0);
|
||||
} else {
|
||||
start = clock();
|
||||
printf("CPU frequency: %d MHz\n", get_cpufreq());
|
||||
start = rdtscp();
|
||||
init = 1;
|
||||
ret = 0.0;
|
||||
//printf("CLOCKS_PER_SEC = %d\n", CLOCKS_PER_SEC);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue