Skip to content

Commit

Permalink
fix the imcomplete hypercall and now the example/testHypercall can ru…
Browse files Browse the repository at this point in the history
…n and get timetick
  • Loading branch information
Yourens committed May 29, 2014
1 parent e828c47 commit 601bbaa
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/Makefile
Expand Up @@ -33,6 +33,7 @@ SUBDIRS= \
partitions-threads \
rtems-guest \
myHelloWorld \
testHypercall \

# mutexes \ ### deprecated Makefile
# mutexes-timed \ ### deprecated Makefile
Expand Down
4 changes: 4 additions & 0 deletions examples/testHypercall/Makefile
@@ -0,0 +1,4 @@
BUILD = --models=model.aadl --no-run
TESTS = compile-x86

include $(POK_PATH)/misc/mk/examples.mk
74 changes: 74 additions & 0 deletions examples/testHypercall/hello.c
@@ -0,0 +1,74 @@
/*
* POK header
*
* The following file is a part of the POK project. Any modification should
* made according to the POK licence. You CANNOT use this file or a part of
* this file is this part of a file for your own project
*
* For more information on the POK licence, please see our LICENCE FILE
*
* Please follow the coding guidelines described in doc/CODING_GUIDELINES
*
* Copyright (c) 2007-2013 POK team
*
* Created by phipse on Wed May 15 13:12:32 2013
*/

#include <libc/stdio.h>
#include <core/time.h>
#include <core/thread.h>
#include <core/hypercall.h>
static unsigned counter = 0;

void time_handler( unsigned vector, void* frame )
{
(void) frame;
(void)vector;
counter++;
}


void register_handler()
{
pok_ret_t ret = pok_hypercall2( POK_HYPERCALL_IRQ_REGISTER_HANDLER, 0, (uint32_t)&time_handler );
if( ret != POK_ERRNO_OK )
printf( "Couldn't register handler\n");
}


/* this shows, that the handler registration doesn't work propperly.
* If we don't try to register the handler, the program executes propperly.
*/

static int flag = 0;
int user_hello( void )
{
printf( "Hello POK world!\n");
// if (flag < 1)
// {
// register_handler();
// flag++;
// }
pok_time_t tmp = 0;
uint8_t _level = 0;

printf( "Forever spin\n");
for( ;; )
{
pok_hypercall2(POK_HYPERCALL_GETTICK, (uint32_t)(&tmp),0);
if( tmp >= 2000 && tmp <= 3000 )
{
pok_hypercall1( POK_HYPERCALL_IRQ_PARTITION_DISABLE, _level );
printf( "Counter: %u\n", counter );
}
if( tmp >= 6000 && tmp <= 8000 )
{
pok_hypercall1( POK_HYPERCALL_IRQ_PARTITION_ENABLE, _level );
printf( "Counter: %u\n", counter );
}

printf( "Clock gettick: %u \n", tmp );
}

return 0;
}
100 changes: 100 additions & 0 deletions examples/testHypercall/model.aadl
@@ -0,0 +1,100 @@
--
-- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2013 POK team
--
-- Created by phipse on Wed May 15 13:12:32 2013
--



package myHello

public


with Data_Model;
with POK;

virtual processor partition
properties
POK::Scheduler => RR;
POK::Additional_Features => (x86_vmm, libc_stdio, console);
end partition;


virtual processor implementation partition.impl
end partition.impl;


processor x86
end x86;

processor implementation x86.impl
subcomponents
part1 : virtual processor partition.impl;
properties
POK::Architecture => x86;
POK::BSP => x86_qemu_vmm;
POK::Major_Frame => 1000ms;
POK::Scheduler => static;
POK::Slots => (500ms);
POK::Slots_Allocation => ( reference (part1));
end x86.impl;


process myProcess
end myProcess;

process implementation myProcess.impl
subcomponents
thr1 : thread mythread.impl;
properties
POK::Needed_Memory_Size => 120Kbyte;
end myProcess.impl;


thread mythread
properties
Source_Stack_Size => 30Kbyte;
end mythread;

thread implementation mythread.impl
calls
call1 : { pspg : subprogram user_hello; };
properties
dispatch_protocol => periodic;
period => 1000ms;
deadline => 1000ms;
compute_execution_time => 1ms .. 2ms;
end mythread.impl;



subprogram user_hello
properties
source_name => "user_hello";
source_language => C;
POK::Source_Location => "../../../hello.o";
end user_hello;


system node
end node;

system implementation node.impl
subcomponents
cpu : processor x86.impl;
part1 : process myProcess.impl;
properties
Actual_Processor_Binding => (reference (cpu.part1)) applies to part1;
end node.impl;
end myHello;
3 changes: 2 additions & 1 deletion kernel/arch/x86/event.c
Expand Up @@ -38,8 +38,9 @@ pok_ret_t pok_event_init ()
#endif

pok_syscall_init (); //syscall register IDT index POK_SYSCALL_INT_NUMBER, i.e., 42;

#ifdef POK_NEEDS_X86_VMM
pok_hypercall_init(); //hypercall register IDT index POK_HYPERCALL_INT_NUMBER, i.e,24;
#endif /* POK_NEEDS_X86_VMM */
return (POK_ERRNO_OK);
}

Expand Down
1 change: 1 addition & 0 deletions kernel/arch/x86/event.h
Expand Up @@ -73,6 +73,7 @@ pok_ret_t pok_idt_init();
pok_ret_t pok_exception_init();
pok_ret_t pok_event_init();
pok_ret_t pok_syscall_init();
pok_ret_t pok_hypercall_init();

#endif /* !__POK_X86_EVENT_H__ */

8 changes: 8 additions & 0 deletions kernel/core/hypercall.c
Expand Up @@ -69,6 +69,14 @@ pok_ret_t pok_core_hypercall (const pok_hypercall_id_t hypercall_id,
return pok_bsp_irq_partition_ack(args->arg1);
break;
#endif /* POK_NEEDS_X86_VMM */

#if 1//defined POK_NEEDS_GETTICK
case POK_SYSCALL_GETTICK:
POK_CHECK_PTR_OR_RETURN(infos->partition, args->arg1 + infos->base_addr)
return pok_gettick_by_pointer ((uint64_t*) (args->arg1 + infos->base_addr));
break;
#endif

default:
#ifdef POK_NEEDS_ERROR_HANDLING
pok_error_declare( POK_ERROR_KIND_ILLEGAL_REQUEST);
Expand Down
1 change: 1 addition & 0 deletions kernel/include/core/hypercall.h
Expand Up @@ -7,6 +7,7 @@
typedef enum
{
POK_HYPERCALL_CONSWRITE =10,
POK_HYPERCALL_GETTICK = 20,
/* Register an irq handler from a partition */
POK_HYPERCALL_IRQ_REGISTER_HANDLER = 25,
POK_HYPERCALL_IRQ_UNREGISTER_HANDLER = 26,
Expand Down
6 changes: 3 additions & 3 deletions libpok/arch/x86/hypercall.c
@@ -1,15 +1,15 @@

#include <core/syscall.h>
#include <core/hypercall.h>
#include <types.h>

pok_ret_t pok_do_hypercall (pok_syscall_id_t syscall_id, pok_syscall_args_t* args)
pok_ret_t pok_do_hypercall (pok_hypercall_id_t hypercall_id, pok_hypercall_args_t* args)
{
pok_ret_t ret;
uint32_t args_addr;
uint32_t id;

args_addr = (uint32_t) args;
id = (uint32_t) syscall_id;
id = (uint32_t) hypercall_id;

asm volatile ( "movl %1,%%eax \n\t"
"movl %2,%%ebx \n\t"
Expand Down
1 change: 1 addition & 0 deletions libpok/include/core/hypercall.h
Expand Up @@ -7,6 +7,7 @@
typedef enum
{
POK_HYPERCALL_CONSWRITE =10,
POK_HYPERCALL_GETTICK = 20,
/* Register an irq handler from a partition */
POK_HYPERCALL_IRQ_REGISTER_HANDLER = 25,
POK_HYPERCALL_IRQ_UNREGISTER_HANDLER = 26,
Expand Down

0 comments on commit 601bbaa

Please sign in to comment.