Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mallachiev-p3041-ne…
Browse files Browse the repository at this point in the history
…t-20161124
  • Loading branch information
mkurmag committed Dec 7, 2016
2 parents a43c153 + d8b5dda commit f804f36
Show file tree
Hide file tree
Showing 161 changed files with 4,827 additions and 2,610 deletions.
48 changes: 47 additions & 1 deletion boards/x86-qemu/pit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,43 @@

#include <bsp/bsp.h>

#include <asp/entries.h>

#define OSCILLATOR_RATE 1193180 /** The oscillation rate of x86 clock */
#define PIT_BASE 0x40

/* Two parts of system time, each one can be upated atomically. */
volatile uint32_t system_time_low;
volatile uint32_t system_time_high;

/*
* Hardcoded calendar time at the beginning of the OS loading.
*
* Could be obtained on https://www.timeanddate.com/.
*/
static time_t base_calendar_time = 1480330081; // On 28.11.2016


void ja_bsp_process_timer(interrupt_frame* frame)
{
(void) frame;
pok_pic_eoi (PIT_IRQ);
CLOCK_HANDLER;

uint32_t system_time_low_new = system_time_low + (1000000000 / POK_TIMER_FREQUENCY);
if(system_time_low_new < (1000000000 / POK_TIMER_FREQUENCY)) {
// Overflow of low part.
system_time_high++;
}

system_time_low = system_time_low_new;

jet_on_tick();
}

void pok_x86_qemu_timer_init(void)
{
system_time_low = system_time_high = 0;

uint16_t pit_freq;

pit_freq = POK_TIMER_FREQUENCY;
Expand All @@ -49,4 +74,25 @@ void pok_x86_qemu_timer_init(void)
pok_pic_unmask (PIT_IRQ);
}

pok_time_t ja_system_time(void)
{
uint32_t low, high;
uint32_t high1 = system_time_high;

/*
* Repeat reading parts of time while high part is updated during
* that reading.
*/
do {
high = high1;
low = system_time_low;
high1 = system_time_high;
} while(high != high1);

return (((uint64_t)(high) << 32) + low);
}

time_t ja_calendar_time(void)
{
return base_calendar_time + (time_t)(ja_system_time() / 1000000000);
}
4 changes: 2 additions & 2 deletions examples/syspart-network-queue-nc/P2/config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Partition>
<Definition Name="P2" System="true"/>
<!-- Amount of ram allocated (code + stack + static variables) -->
<Memory Bytes="2M" />
<!-- Amount of ram allocated (code + stack + static variables) + heap -->
<Memory Bytes="1M" Heap="1M"/>

<!-- Number of threads that can be created in this partition.
Note that this number doesn't include main and error handler threads,
Expand Down
13 changes: 7 additions & 6 deletions kernel/arch/ppc/include/arch/deployment.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ struct ja_ppc_space
{
/* Physical address of memory chunk. */
uintptr_t phys_base;
/*
* Size of the memory for normal use.
* Everything above is used for stack.
*/
/* Size of the memory for code and static data. */
size_t size_normal;

uint32_t ustack_state; // State of the user stack allocator.
/* Size of the memory for heap */
size_t size_heap;
/* Total size of memory block */
size_t size_total;
/* State of the user stack allocator. */
uint32_t ustack_state;
};

/*
Expand Down
19 changes: 17 additions & 2 deletions kernel/arch/ppc/space.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ struct jet_kernel_shared_data* __kuser ja_space_shared_data(jet_space_id space_i
return (struct jet_kernel_shared_data* __kuser)POK_PARTITION_MEMORY_BASE;
}

size_t ja_user_space_maximum_alignment = 16;
static const size_t ja_user_space_maximum_alignment = 16;

void __user* ja_space_get_heap(jet_space_id space_id)
{
struct ja_ppc_space* space = &ja_spaces[space_id - 1];

return POK_PARTITION_MEMORY_BASE + (char __user*)
ALIGN_VAL((unsigned long)space->size_normal, ja_user_space_maximum_alignment);
}

void ja_space_switch (jet_space_id space_id)
{
Expand Down Expand Up @@ -260,8 +268,15 @@ void pok_arch_space_init (void)

for(int i = 0; i < ja_spaces_n; i++)
{
struct ja_ppc_space* space = &ja_spaces[i];

space->size_total = space->size_normal;
if(space->size_heap > 0) {
space->size_total = ALIGN_VAL((unsigned long)space->size_total, ja_user_space_maximum_alignment)
+ space->size_heap;
}
// This should be checked when generate deployment.c too.
assert(ja_spaces[i].size_normal < POK_PARTITION_MEMORY_SIZE);
assert(space->size_total < POK_PARTITION_MEMORY_SIZE);
}
}

Expand Down
28 changes: 24 additions & 4 deletions kernel/arch/ppc/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@
#include "reg.h"
#include "timer.h"
#include <cons.h>
#include <asp/entries.h>

/* First value of decrementer. */
static uint64_t time_first;


/* Last time when decr was set. */
static uint64_t time_last;

/* Decrementer optimal value. */
static uint32_t time_inter;

/*
* Hardcoded calendar time at the beginning of the OS loading.
*
* Could be obtained on https://www.timeanddate.com/.
*/
static time_t base_calendar_time = 1480330081; // On 28.11.2016

static uint64_t get_timebase(void)
{
while (1) {
Expand Down Expand Up @@ -76,19 +88,27 @@ void pok_arch_decr_int (void)
do
{
err = set_decrementer();
pok_tick_counter += 1;
} while (err != POK_ERRNO_OK);


pok_sched_on_time_changed ();
jet_on_tick();
}

void ja_time_init (void)
{
time_inter = pok_bsp.timebase_freq / POK_TIMER_FREQUENCY;
printf("Timer interval: %lu\n", time_inter);
time_last = get_timebase ();
time_first = time_last = get_timebase ();
set_decrementer();

mtspr(SPRN_TCR, TCR_DIE); // enable decrementer
}

pok_time_t ja_system_time(void)
{
return ((get_timebase() - time_first) / time_inter) * 1000000;
}

time_t ja_calendar_time(void)
{
return base_calendar_time + (time_t)(ja_system_time() / 1000000000);
}
6 changes: 3 additions & 3 deletions kernel/arch/ppc/uaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ static pok_bool_t ppc_check_access(const void* __user addr, size_t size,

/*
* Currently, there are 2 segments accessible to user:
* 1. [POK_PARTITION_MEMORY_BASE; POK_PARTITION_MEMORY_BASE + space->size_normal)
* 1. [POK_PARTITION_MEMORY_BASE; POK_PARTITION_MEMORY_BASE + space->size_total)
* code and data
* 2. [space->ustack_state; POK_PARTITION_MEMORY_BASE + POK_PARTITION_MEMORY_SIZE)
* stacks
*/

if(end < start) return FALSE; // Segments doesn't cross NULL.

if(end <= space->size_normal + POK_PARTITION_MEMORY_BASE)
if(end <= space->size_total + POK_PARTITION_MEMORY_BASE)
{
return (start >= POK_PARTITION_MEMORY_BASE);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ pok_bool_t ja_check_access_exec(void* __user addr, jet_space_id space_id)
/*
* Only single segment could be executed by user:
* [POK_PARTITION_MEMORY_BASE; POK_PARTITION_MEMORY_BASE + space->size_normal)
* code and data
* code
*/

return (start < POK_PARTITION_MEMORY_BASE + space->size_normal)
Expand Down
28 changes: 21 additions & 7 deletions kernel/arch/x86/include/arch/deployment.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,39 @@ struct ja_x86_space
uintptr_t phys_base;

/*
* Total size for partition's use.
* Size of the memory (code and static data).
*
* Calculated upon space initialization.
* Set in deployment.c.
*/
size_t size_total;
size_t size_normal;

/*
* Size of the memory for normal use.
* Size of the memory (heap).
*
* Set in deployment.c.
*/
size_t size_normal;
size_t size_heap;

/*
* Size of the memory for stacks, above size_normal.
* Size of the memory for stacks.
*
* Set in deployment.c.
*/
size_t size_stack;

/*
* Total size for partition's use.
*
* Calculated upon space initialization.
*/
size_t size_total;

/*
* Offset from the beginning of the space to the ending of the heap.
*
* Calculated upon space initialization.
*/
size_t heap_end;
/*
* Memory currently used for stacks.
*/
Expand Down
34 changes: 27 additions & 7 deletions kernel/arch/x86/space.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ struct jet_kernel_shared_data* __kuser ja_space_shared_data(jet_space_id space_i
return (struct jet_kernel_shared_data* __kuser)space->phys_base;
}

size_t ja_user_space_maximum_alignment = 16;
static const size_t ja_user_space_maximum_alignment = 16;

void __user* ja_space_get_heap(jet_space_id space_id)
{
struct ja_x86_space* space = &ja_spaces[space_id - 1];

return (void __user*)(space->heap_end - space->size_heap);
}


jet_space_id current_space_id = 0;

Expand Down Expand Up @@ -122,14 +130,26 @@ void ja_space_init(void)
for(int i = 0; i < ja_spaces_n; i++)
{
struct ja_x86_space* space = &ja_spaces[i];

/*
* Code and data segments should be aligned on 4k;
* stack should be aligned on 16; (why?)
* total size should be aligned on 4k;
*/
size_t size_total = space->size_normal;

size_t size_total_min = ALIGN_VAL(space->size_normal, 16) + space->size_stack;
space->size_total = ALIGN_VAL(size_total_min, 0x1000);
if(space->size_heap > 0)
{
/* Heap should be aligned on 16; (why?) */
size_total = ALIGN_VAL(size_total, 16) + space->size_heap;
}

// Store intermediate result.
space->heap_end = size_total;

/* Stack should be aligned on 16; (why?) */
size_total = ALIGN_VAL(size_total, 16) + space->size_stack;

/* Such a way, next space will have alignment suitable for code and data. */
space->size_total = ALIGN_VAL(size_total, 0x1000);

if(space->phys_base == 0)
{
Expand Down Expand Up @@ -193,7 +213,7 @@ jet_space_id ja_space_get_current (void)
return current_space_id;
}

// TODO: Storage for floating point registers and operations with it.
// TODO: Storage for floating point registers and operations with them.
struct jet_fp_store
{
int todo;
Expand All @@ -207,7 +227,7 @@ struct jet_fp_store
struct jet_fp_store* ja_alloc_fp_store(void)
{
struct jet_fp_store* res = ja_mem_alloc_aligned(sizeof(*res), 4);

return res;
}

Expand Down
6 changes: 3 additions & 3 deletions kernel/arch/x86/uaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ static pok_bool_t x86_check_access(const void* __user addr, size_t size,

/*
* Currently, there are 2 segments accessible to user:
* 1. [POK_PARTITION_MEMORY_BASE; POK_PARTITION_MEMORY_BASE + space->size_normal)
* code and data
* 1. [POK_PARTITION_MEMORY_BASE; POK_PARTITION_MEMORY_BASE + space->heap_end)
* code,data and heap
* 2. [POK_PARTITION_MEMORY_BASE + space->size_total - space->size_stack_used; POK_PARTITION_MEMORY_BASE + space->size_total)
* stacks
*/

if(end < start) return FALSE; // Segments doesn't cross NULL.

if(end <= space->size_normal + POK_PARTITION_MEMORY_BASE)
if(end <= space->heap_end + POK_PARTITION_MEMORY_BASE)
{
return (start >= POK_PARTITION_MEMORY_BASE);
}
Expand Down
3 changes: 0 additions & 3 deletions kernel/core/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ void jet_boot (void)
pok_network_init();
#endif

#if defined (POK_NEEDS_TIME) || defined (POK_NEEDS_SCHED) || defined (POK_NEEDS_THREADS)
pok_time_init();
#endif
#ifdef POK_NEEDS_PARTITIONS
pok_partition_arinc_init_all();
#endif
Expand Down
Loading

0 comments on commit f804f36

Please sign in to comment.