POK(kernelpart)
arch.h File Reference

Generic interface to handle architectures. More...

#include <types.h>
#include <errno.h>

Go to the source code of this file.

Functions

pok_ret_t pok_arch_init ()
pok_ret_t pok_arch_preempt_disable ()
pok_ret_t pok_arch_preempt_enable ()
pok_ret_t pok_arch_idle ()
pok_ret_t pok_arch_event_register (uint8_t vector, void(*handler)(void))
uint32_t pok_context_create (uint32_t thread_id, uint32_t stack_size, uint32_t entry)
void pok_context_switch (uint32_t *old_sp, uint32_t new_sp)
pok_ret_t pok_create_space (uint8_t partition_id, uint32_t addr, uint32_t size)
uint32_t pok_space_base_vaddr (uint32_t addr)
void pok_dispatch_space (uint8_t partition_id, uint32_t user_pc, uint32_t user_sp, uint32_t kernel_sp, uint32_t arg1, uint32_t arg2)
uint32_t pok_space_context_create (uint8_t partition_id, uint32_t entry_rel, uint32_t stack_rel, uint32_t arg1, uint32_t arg2)
void pok_space_context_restart (uint32_t sp, uint32_t entry, uint32_t user_stack)
pok_ret_t pok_space_switch (uint8_t old_partition_id, uint8_t new_partition_id)
uint32_t pok_thread_stack_addr (const uint8_t partition_id, const uint32_t local_thread_id)

Detailed Description

Generic interface to handle architectures.

Author:
Julian Pidancet
Julien Delange
Date:
2008-2009

Definition in file arch.h.


Function Documentation

pok_ret_t pok_arch_event_register ( uint8_t  vector,
void(*)(void)  handler 
)

Register an event (for example, an interruption)

Attach the handler to the given trap number (vector).

See also:
pok_sparc_isr

Definition at line 83 of file arch.c.

{
(void) vector;
(void) handler;
return (POK_ERRNO_OK);
}
pok_ret_t pok_arch_idle ( )

Function that do nothing. Useful for the idle task for example.

Definition at line 74 of file arch.c.

{
while (1)
{
}
return (POK_ERRNO_OK);
}
pok_ret_t pok_arch_init ( )

Function that initializes architecture concerns.

Initialize all SPARC managers (traps, syscalls, space).

Definition at line 43 of file arch.c.

{
set_msr (MSR_IP);
#if POK_NEEDS_PARTITIONS
#endif
return (POK_ERRNO_OK);
}
pok_ret_t pok_arch_preempt_disable ( )

Disable interruptions

Definition at line 53 of file arch.c.

{
unsigned int msr;
msr = get_msr();
msr &= ~MSR_EE;
set_msr(msr);
return (POK_ERRNO_OK);
}
pok_ret_t pok_arch_preempt_enable ( )

Enable interruptions

Definition at line 63 of file arch.c.

{
unsigned int msr;
msr = get_msr();
msr |= MSR_EE;
set_msr(msr);
return (POK_ERRNO_OK);
}
uint32_t pok_context_create ( uint32_t  thread_id,
uint32_t  stack_size,
uint32_t  entry 
)
void pok_context_switch ( uint32_t old_sp,
uint32_t  new_sp 
)
pok_ret_t pok_create_space ( uint8_t  partition_id,
uint32_t  addr,
uint32_t  size 
)

Set ptd and pte for the given partition.

Definition at line 42 of file space.c.

{
#ifdef POK_NEEDS_DEBUG
printf ("pok_create_space: %d: %x %x\n", partition_id, addr, size);
#endif
spaces[partition_id].phys_base = addr;
spaces[partition_id].size = size;
return (POK_ERRNO_OK);
}
void pok_dispatch_space ( uint8_t  partition_id,
uint32_t  user_pc,
uint32_t  user_sp,
uint32_t  kernel_sp,
uint32_t  arg1,
uint32_t  arg2 
)

Definition at line 114 of file space.c.

{
uint32_t code_sel;
uint32_t data_sel;
code_sel = GDT_BUILD_SELECTOR (GDT_PARTITION_CODE_SEGMENT (partition_id), 0, 3);
data_sel = GDT_BUILD_SELECTOR (GDT_PARTITION_DATA_SEGMENT (partition_id), 0, 3);
sp = (uint32_t) &ctx;
memset (&ctx, 0, sizeof (interrupt_frame));
ctx.es = ctx.ds = ctx.ss = data_sel;
ctx.__esp = (uint32_t) (&ctx.error); /* for pusha */
ctx.eip = user_pc;
ctx.eax = arg1;
ctx.ebx = arg2;
ctx.cs = code_sel;
ctx.eflags = 1 << 9;
ctx.esp = user_sp;
tss_set_esp0 (kernel_sp);
asm ("mov %0, %%esp \n"
"pop %%es \n"
"pop %%ds \n"
"popa \n"
"addl $4, %%esp \n"
"iret \n"
:
: "m" (sp)
);
}
uint32_t pok_space_base_vaddr ( uint32_t  addr)
Returns:
partition virtual base adress.
See also:
SPARC_PARTITION_BASE_VADDR

Definition at line 64 of file space.c.

{
(void) addr;
return (0);
}
uint32_t pok_space_context_create ( uint8_t  id,
uint32_t  entry_rel,
uint32_t  stack_rel,
uint32_t  arg1,
uint32_t  arg2 
)

Create a new context in the given space

Initilize thread stack.

Definition at line 72 of file space.c.

{
context_t* ctx;
char* stack_addr;
(void) partition_id;
vctx = (volatile_context_t *)
(stack_addr + KERNEL_STACK_SIZE - sizeof (volatile_context_t));
ctx = (context_t *)((char *)vctx - sizeof (context_t) + 8);
memset (ctx, 0, sizeof (*ctx));
memset (vctx, 0, sizeof (*vctx));
vctx->r3 = arg1;
vctx->r4 = arg2;
vctx->sp = stack_rel - 12;
vctx->srr0 = entry_rel;
vctx->srr1 = MSR_EE | MSR_IP | MSR_DR | MSR_IR | MSR_PR;
ctx->sp = (uint32_t) &vctx->sp;
#ifdef POK_NEEDS_DEBUG
printf ("space_context_create %d: entry=%x stack=%x arg1=%x arg2=%x ksp=%x\n",
partition_id, entry_rel, stack_rel, arg1, arg2, &vctx->sp);
#endif
return (uint32_t)ctx;
}
void pok_space_context_restart ( uint32_t  sp,
uint32_t  entry,
uint32_t  user_stack 
)
pok_ret_t pok_space_switch ( uint8_t  old_partition_id,
uint8_t  new_partition_id 
)

Switch from one space to another

Switch adress space in MMU (context register).

Definition at line 55 of file space.c.

{
(void) old_partition_id;
/* printf ("space_switch %u -> %u\n", old_partition_id, new_partition_id); */
asm volatile ("mtsr %0,%1" : : "r"(0), "r"(PPC_SR_KP | new_partition_id));
return (POK_ERRNO_OK);
}
uint32_t pok_thread_stack_addr ( const uint8_t  partition_id,
const uint32_t  local_thread_id 
)

Returns the stack address for a the thread number N in a partition.

  • partition_id indicates the partition that contains the thread.
  • local_thread_id the thread-id of the thread inside the partition.
Returns:
the stack address of the thread.

Compute the stack adress for the given thread.

Definition at line 92 of file arch.c.

{
return pok_partitions[partition_id].size - 16 - (local_thread_id * POK_USER_STACK_SIZE);
}