Re: Experimenting the vm-tz example on the Freescale i.mx6 SDB

Mahdi Aichouch <[email protected]>
Newsgroups gmane.comp.micro-kernel.l4.devel
Message-ID <CAGBLRX63fNZpb+sQfBJv8Ro9AE8mu_nbxv37BHeDF7kusM1pFw@mail.gmail.com>
Hello Adam,

I tried to do as you suggested, and I added a loop in order to map a small
chunk of memory at time.

When I tried to map 1 KB at a time and 2 KB at a time, I received this
error from the first call to
 l4sigma0_map_iomem ( ) function:

...
Vmm started
j = 0 addr = 0x0
Cannot map nonsecure memory Phys, virt or size not aligned
...

Then, I tried to add 4KB at a time, and I received the same error as before
at the first call to
the l4sigma0_map_iomem ( ) function, that is:

...
Vmm started
j = 0 addr = 0x0
Cannot map nonsecure memory No fpage received
...


I also tried with 4 KB, 8 KB, 16 KB, 32 KB,...
I get the same error: "No fpage received"


This is the code of the loop that I added:

  int ram_size = 0x1000; //4 KB


  int address  = 0x0;
  int j;
  for(j = 0; j < 256; j++) {
    fault = l4sigma0_map_iomem(sigma0_cap.cap(), Ram_base, Ram_base,
ram_size, 1);
    printf("j = %d addr = 0x%x\n", j, address);
    address += ram_size;
    if (fault) {
      printf("Cannot map nonsecure memory %s\n",
l4sigma0_map_errstr(fault));
      exit(1);
    }
  }


Could you please tell me what else should I check to track down the source
of the error.
Thank you very much in advance.

Kindest regards,

Mahdi

PS: I attached the main.cc file of my vm-tz example.








On Wed, Mar 25, 2015 at 10:19 AM, Mahdi Aichouch <[email protected]> wrote:

> Hello Adam,
>
> Thank you again for your answer.
>
> Please find below the execution's log from the start of L4 kernel until
> the stop of the vm-tz test:
>
> L4 Bootstrapper
>   Build: #21 Tue Mar 17 15:28:32 CET 2015, 4.8.3 20140320 (prerelease)
>   Scanning up to 1024 MB RAM, starting at offset 32MB
>   Memory size is 1024MB (10000000 - 4fffffff)
>   RAM: 0000000010000000 - 000000004fffffff: 1048576kB
>   Total RAM: 1024MB
>   Scanning fiasco
>   Scanning sigma0
>   Scanning moe
>   Moving up to 5 modules behind 11100000
>   moving module 02 { 110a6000-110df63f } -> { 11196000-111cf63f } [235072]
>   moving module 01 { 1109c000-110a538b } -> { 1118c000-1119538b } [37772]
>   moving module 00 { 11044000-1109bb17 } -> { 11134000-1118bb17 } [359192]
>   moving module 04 { 1102a000-1104365b } -> { 1111a000-1113365b } [104028]
>   moving module 03 { 11010000-11029473 } -> { 11100000-11119473 } [103540]
>   Loading fiasco
>   Loading sigma0
>   Loading moe
>   find kernel info page...
>   found kernel info page at 0x10002000
> Regions of list 'regions'
>     [ 10000000,  100000e3] {       e4} Root   mbi_rt
>     [ 10001000,  10001aff] {      b00} Kern   fiasco
>     [ 10002000,  10066fff] {    65000} Kern   fiasco
>     [ 10090000,  10096edf] {     6ee0} Sigma0 sigma0
>     [ 10098000,  1009e177] {     6178} Sigma0 sigma0
>     [ 10140000,  10171d77] {    31d78} Root   moe
>     [ 10178000,  101934ab] {    1b4ac} Root   moe
>     [ 11000000,  1100f4ff] {     f500} Boot   bootstrap
>     [ 11100000,  11133fff] {    34000} Root   Module
>   API Version: (87) experimental
>   Sigma0 config    ip:10090100 sp:00000000
>   Roottask config  ip:10140260 sp:00000000
>   Starting kernel fiasco at 100012c8
> Number of IRQs available at this GIC: 160
> FPU0: Arch: VFPv3(3), Part: VFPv3(30), r: 4, v: 9, i: 41, t: hard, p:
> dbl/sngl
> L2: ID=410000c7 Type=9e340340 Aux=02070000 WMask=ffff S=0
> L2: Type L2C-310 Size = 1024kB  Ways=16 Waysize=64
> GIC: Switching IRQ 58 to secure
> SERIAL ESC: allocated IRQ 58 for serial uart
> Not using serial hack in slow timer handler.
> Welcome to Fiasco.OC (arm)!
> L4/Fiasco.OC arm microkernel (C) 1998-2013 TU Dresden
> Rev: rexported compiled with gcc 4.8.3 for i.MX6    []
> Build: #4 Tue Mar 17 14:55:01 CET 2015
>
> GIC: Switching IRQ 29 to secure
> Calibrating timer loop... done.
> MDB: use page size: 20
> MDB: use page size: 12
> SIGMA0: Hello!
>   KIP @ 10002000
>   allocated 4KB for maintenance structures
> SIGMA0: Dump of all resource maps
> RAM:------------------------
> [4:10000000;10000fff]
> [0:10067000;1008ffff]
> [0:10097000;10097fff]
> [0:1009f000;1013ffff]
> [4:10140000;10171fff]
> [0:10172000;10177fff]
> [4:10178000;10193fff]
> [0:10194000;110fffff]
> [4:11100000;11133fff]
> [0:11134000;4effffff]
> IOMEM:----------------------
> [0:0;fffffff]
> [0:50000000;ffffffff]
> MOE: Hello world
> MOE: found 1031204 KByte free memory
> MOE: found RAM from 10000000 to 4f000000
> MOE: allocated 1008 KByte for the page array @0x10194000
> MOE: virtual user address space [0-bfffffff]
> MOE: rom name space cap -> [C:501000]
>   BOOTFS: [11100000-11119474] [C:503000] l4re
>   BOOTFS: [1111a000-1113365c] [C:504000] vm-tz
> MOE: cmdline: moe --init=rom/vm-tz
> MOE: Starting: rom/vm-tz
> MOE: loading 'rom/vm-tz'
> Vmm started
> Cannot map nonsecure memory No fpage received
> MOE: task 270000679 exited with 1
>
>
>
> Kindest regards,
>
> Mahdi
>
>
> On Mon, Mar 23, 2015 at 11:33 AM, Mahdi Aichouch <[email protected]>
> wrote:
>
>> Hello Adam,
>>
>> Thank you very much for your answer!
>>
>> I configured the Ram_base to 0x20000000 for the normal-world OS and the
>> Ram_size to
>> 0x10000000 (256 MB).
>>
>> The secure world OS is loaded at 0x10000000 according to the link address
>> of fiasco
>> kernel on the i.mx6, and has 256 MB of Ram.
>>
>> When I start the vm-tz example, the reserve_area( ) method is executed
>> successfully,
>>
>> ...
>>
>> l4_addr_t v = Ram_base;
>> L4Re::chksys(env->rm()->reserve_area(&v, Ram_size, L4Re::Rm::Reserved));
>>
>> fault = l4sigma0_map_iomem(sigma0_cap.cap(), Ram_base, Ram_base,
>> Ram_size, 1);
>> if (fault) {
>>    printf("Cannot map nonsecure memory: %s\n",
>> l4sigma0_map_errstr(fault));
>>    exit(1);
>> }
>>
>> ...
>>
>> but the l4sigma0_map_iomem( ) returns an error:
>>
>> ...
>> Vmm started
>> Cannot map nonsecure memory No fpage received
>> MOE: task 270000679 exited with 1
>>
>> Then the programs stops executing, the setup_linux(vmstate) function is
>> not
>> executed, and the ATAG data structure is not copied.
>>
>> Do you have an idea of what might cause this fault.
>>
>> Thank you very much in advance.
>>
>> Best regars,
>> Mahdi
>>
>>
>>
>> On Fri, Mar 20, 2015 at 9:48 AM, Mahdi Aichouch <[email protected]>
>> wrote:
>>
>>> Hello,
>>>
>>> I am trying to test the "vm-tz", and I created a new entry in the
>>> "/src/l4/conf/modules.list".
>>>
>>> entry tz_vm
>>> roottask moe --init=rom/vm-tz
>>> module l4re
>>> module vm-tz
>>>
>>> Is my entry correct? Or there is some missing modules?
>>> How to know what modules should be included?
>>>
>>> Does someone has a successful running configuration.
>>> Is it possible to share with us a working configuration.
>>>
>>> Thank you very much in advance.
>>>
>>> Best regards,
>>>
>>> Mahdi
>>>
>>>
>>>
>>>
>>> On Tue, Mar 17, 2015 at 4:39 PM, Mahdi Aichouch <[email protected]>
>>> wrote:
>>>
>>>> Hello,
>>>>
>>>> I was able to correct the error related to the creation of the VM, by
>>>> recompiling the fiasco kernel using
>>>> the "trustzone secure side" as an Execution Model option instead of the
>>>> "Standard Mode".
>>>>
>>>> Now the code goes further and it stops at
>>>>
>>>> l4sigma0_map_iomem(sigma0_cap.cap(), Ram_base, Ram_base, Ram_size, 1);
>>>>
>>>> which return the following error:
>>>>
>>>> MOE: Hello world
>>>> MOE: found 1031204 KByte free memory
>>>> MOE: found RAM from 10000000 to 4f000000
>>>> MOE: allocated 1008 KByte for the page array @0x10194000
>>>> MOE: virtual user address space [0-bfffffff]
>>>> MOE: rom name space cap -> [C:501000]
>>>>   BOOTFS: [11100000-11119474] [C:503000] l4re
>>>>   BOOTFS: [1111a000-1113365c] [C:504000] vm-tz
>>>> MOE: cmdline: moe --init=rom/vm-tz
>>>> MOE: Starting: rom/vm-tz
>>>> MOE: loading 'rom/vm-tz'
>>>> Vmm started
>>>> Cannot map nonsecure memory No fpage received
>>>>
>>>> I used the same memory parameters of the example, that is,
>>>> the RAM base of the non secure world is 0x20000000, and
>>>> the RAM size is 0x00100000.
>>>>
>>>> Could someone help me to correct this.
>>>>
>>>> Thank you very much in advance.
>>>>
>>>> Best regards,
>>>> Mahdi
>>>>
>>>>
>>>> On Tue, Mar 17, 2015 at 2:46 PM, Mahdi Aichouch <[email protected]>
>>>> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I am trying to experiment the "vm-tz" example on the Freescale i.mx6
>>>>> SDB board.
>>>>>
>>>>> At first, my goal is to understand the example, thus I am interested
>>>>> in running
>>>>> a simple test kernel instead of a full linux kernel.
>>>>>
>>>>> Specifically, I am trying to reproduce the experimentation of the
>>>>> article related to the trustzone
>>>>> implementation on Fiasco.OC L4re, "ARM Trustzone as a Virtualization
>>>>> Technique in Embedded Systems".
>>>>> In particular, it is mentioned in the article at the "Implementation"
>>>>> paragraph that "Multiplexing two or more OS is supported by our design."
>>>>> I would like to investigate this point.
>>>>>
>>>>> I created a new entry to generate the vm-tz binary.
>>>>> I added the following entry to the "src/l4/conf/modules.list" file :
>>>>>
>>>>> entry tz_vm
>>>>> roottask moe --init=rom/vm-tz
>>>>> module l4re
>>>>> module vm-tz
>>>>>
>>>>> Is my configuration entry correct, is there any missing modules that
>>>>> are required by the example?
>>>>>
>>>>> I tested the binary on the board using tftp, and I obtained the
>>>>> following results:
>>>>>
>>>>> L4 Bootstrapper
>>>>>   Build: #12 Tue Mar 17 12:10:02 CET 2015, 4.8.3 20140320 (prerelease)
>>>>>   Scanning up to 1024 MB RAM, starting at offset 32MB
>>>>>   Memory size is 1024MB (10000000 - 4fffffff)
>>>>>   RAM: 0000000010000000 - 000000004fffffff: 1048576kB
>>>>>   Total RAM: 1024MB
>>>>>   Scanning fiasco
>>>>>   Scanning sigma0
>>>>>   Scanning moe
>>>>>   Moving up to 5 modules behind 11100000
>>>>>   moving module 02 { 110a5000-110de63f } -> { 11195000-111ce63f }
>>>>> [235072]
>>>>>   moving module 01 { 1109b000-110a438b } -> { 1118b000-1119438b }
>>>>> [37772]
>>>>>   moving module 00 { 11044000-1109a0c7 } -> { 11134000-1118a0c7 }
>>>>> [352456]
>>>>>   moving module 04 { 1102a000-11043597 } -> { 1111a000-11133597 }
>>>>> [103832]
>>>>>   moving module 03 { 11010000-11029473 } -> { 11100000-11119473 }
>>>>> [103540]
>>>>>   Loading fiasco
>>>>>   Loading sigma0
>>>>>   Loading moe
>>>>>   find kernel info page...
>>>>>   found kernel info page at 0x10002000
>>>>> Regions of list 'regions'
>>>>>     [ 10000000,  100000e3] {       e4} Root   mbi_rt
>>>>>     [ 10001000,  10001aff] {      b00} Kern   fiasco
>>>>>     [ 10002000,  10062fff] {    61000} Kern   fiasco
>>>>>     [ 10090000,  10096edf] {     6ee0} Sigma0 sigma0
>>>>>     [ 10098000,  1009e177] {     6178} Sigma0 sigma0
>>>>>     [ 10140000,  10171d77] {    31d78} Root   moe
>>>>>     [ 10178000,  101934ab] {    1b4ac} Root   moe
>>>>>     [ 11000000,  1100f4ff] {     f500} Boot   bootstrap
>>>>>     [ 11100000,  11133fff] {    34000} Root   Module
>>>>>   API Version: (87) experimental
>>>>>   Sigma0 config    ip:10090100 sp:00000000
>>>>>   Roottask config  ip:10140260 sp:00000000
>>>>>   Starting kernel fiasco at 100012c8
>>>>> Number of IRQs available at this GIC: 160
>>>>> FPU0: Arch: VFPv3(3), Part: VFPv3(30), r: 4, v: 9, i: 41, t: hard, p:
>>>>> dbl/sngl
>>>>> L2: ID=410000c7 Type=9e340340 Aux=02070000 WMask=ffff S=0
>>>>> L2: Type L2C-310 Size = 1024kB  Ways=16 Waysize=64
>>>>> SERIAL ESC: allocated IRQ 58 for serial uart
>>>>> Not using serial hack in slow timer handler.
>>>>> Welcome to Fiasco.OC (arm)!
>>>>> L4/Fiasco.OC arm microkernel (C) 1998-2013 TU Dresden
>>>>> Rev: rexported compiled with gcc 4.8.3 for i.MX6    []
>>>>> Build: #3 Wed Mar 11 16:43:41 CET 2015
>>>>>
>>>>> Calibrating timer loop... done.
>>>>> MDB: use page size: 20
>>>>> MDB: use page size: 12
>>>>> SIGMA0: Hello!
>>>>>   KIP @ 10002000
>>>>>   allocated 4KB for maintenance structures
>>>>> SIGMA0: Dump of all resource maps
>>>>> RAM:------------------------
>>>>> [4:10000000;10000fff]
>>>>> [0:10063000;1008ffff]
>>>>> [0:10097000;10097fff]
>>>>> [0:1009f000;1013ffff]
>>>>> [4:10140000;10171fff]
>>>>> [0:10172000;10177fff]
>>>>> [4:10178000;10193fff]
>>>>> [0:10194000;110fffff]
>>>>> [4:11100000;11133fff]
>>>>> [0:11134000;4effffff]
>>>>> IOMEM:----------------------
>>>>> [0:0;fffffff]
>>>>> [0:50000000;ffffffff]
>>>>> MOE: Hello world
>>>>> MOE: found 1031220 KByte free memory
>>>>> MOE: found RAM from 10000000 to 4f000000
>>>>> MOE: allocated 1008 KByte for the page array @0x10194000
>>>>> MOE: virtual user address space [0-bfffffff]
>>>>> MOE: rom name space cap -> [C:501000]
>>>>>   BOOTFS: [11100000-11119474] [C:503000] l4re
>>>>>   BOOTFS: [1111a000-11133598] [C:504000] vm-tz
>>>>> MOE: cmdline: moe --init=rom/vm-tz
>>>>> MOE: Starting: rom/vm-tz
>>>>> MOE: loading 'rom/vm-tz'
>>>>> Vmm started
>>>>> terminate called after throwing an instance of 'N2L413Runtime_errorE'
>>>>> MOE: task 270000679 exited with 127
>>>>>
>>>>> The code stops at the beginning when it tries to create a VM :
>>>>>
>>>>> L4Re::chksys(env->factory()->create_vm(vm));
>>>>>
>>>>> After reading through the code, I saw that the code example is
>>>>> expecting a linux-image and an initrd to be provided. Is it possible to
>>>>> tell me where these should be added in the build directory? In my test
>>>>> case, the linux-image will be replaced by a simple kernel image.
>>>>>
>>>>> Could someone help me to correct my test case.
>>>>>
>>>>> Many thanks in advance.
>>>>>
>>>>> Best regards,
>>>>> Mahdi
>>>>>
>>>>
>>>>
>>>
>>
>

_______________________________________________
l4-hackers mailing list
[email protected]
http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
main.cc (text/x-c++src, 6.6 KB)
/*
 * (c) 2009-2012 Adam Lackorzynski <[email protected]>,
 *               Alexander Warg <[email protected]>,
 *               Torsten Frenzel <[email protected]>
 *     economic rights: Technische Universität Dresden (Germany)
 *
 * This file is part of TUD:OS and distributed under the terms of the
 * GNU General Public License 2.
 * Please see the COPYING-GPL-2 file for details.
 */
#include <l4/re/env>
#include <l4/re/util/env_ns>
#include <l4/re/c/namespace.h>
#include <l4/re/dataspace>
#include <l4/re/c/util/cap_alloc.h>
#include <l4/re/error_helper>
#include <l4/sys/factory>
#include <l4/sys/vm>
#include <l4/sigma0/sigma0.h>
#include <l4/util/util.h>
#include <l4/sys/cache.h>
#include <l4/vcpu/vcpu>
#include <l4/sys/thread>

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>

/*
 * This is a simple example to demonstrate how to
 * startup a Linux in Vm.
 *
 * This example has some prerequisites:
 *
 * 1. The Linux image name: 'rom/vm-linux-image'
 *
 * 2. The Linux image link/start address: 0x9000000
 *
 * 3. The Linux RAM disk name: 'rom/linux-initrd'
 *
 * 4. The VM physical memory: 0x8000000 - 0xc000000
 */

static void error(const char *str)
{
  printf("%s", str);
  exit(1);
}

static void dump_vm_state(l4_vm_tz_state *s)
{
  printf("pc:%08lx cpsr:%08lx\n",
         s->pc, s->cpsr);
  printf("r0:%08lx r1:%08lx r2:%08lx r3:%08lx\n",
         s->r[0], s->r[1], s->r[2], s->r[3]);
  printf("r4:%08lx r5:%08lx r6:%08lx r7:%08lx\n",
         s->r[4], s->r[5], s->r[6], s->r[7]);
  printf("r8:%08lx r9:%08lx r10:%08lx r11:%08lx\n",
         s->r[8], s->r[9], s->r[10], s->r[11]);
  printf("r12:%08lx\n",
         s->r[12]);
  printf("lr_svc:%08lx sp_svc:%08lx spsr_svc:%08lx\n",
         s->svc.lr, s->svc.sp, s->svc.spsr);
}


enum {
    //Ram_base  = 0x60000000, //E
    Ram_base    = 0x20000000, // T2
    Ram_size    = 0x00100000,
    Start_addr  = Ram_base   + 0x8000,
    Atag_addr   = Start_addr + 0x100,
    Initrd_addr = Ram_base   + 0x400000, // +2MB
};

#define ATAG_NONE	0x00000000
#define ATAG_CORE	0x54410001
#define ATAG_MEM	0x54410002
#define ATAG_INITRD2	0x54420005
#define ATAG_CMDLINE	0x54410009

#define tag_size(type)	((sizeof(struct tag_header) + sizeof(struct type)) >> 2)

struct tag_header
{
  l4_uint32_t size;
  l4_uint32_t tag;
};

struct tag_core
{
  l4_uint32_t flags;
  l4_uint32_t pagesize;
  l4_uint32_t rootdev;
};

struct tag_mem
{
  l4_uint32_t	size;
  l4_uint32_t	start;
};

struct tag_cmdline
{
  char    cmdline[128];
};

struct tag_initrd
{
  l4_uint32_t start;
  l4_uint32_t size;
};

static struct init_tags
{
  struct tag_header hdr1;
  struct tag_core   core;
  struct tag_header hdr2;
  struct tag_mem    mem;
  struct tag_header hdr3;
  struct tag_cmdline cmdline;
  struct tag_header hdr4;
  struct tag_initrd initrd;
  struct tag_header hdr5;
} init_tags = {
	{ tag_size(tag_core), ATAG_CORE },
	{ 1, L4_PAGESIZE, 0xff },
	{ tag_size(tag_mem), ATAG_MEM },
	{ Ram_size, Ram_base },
	{ tag_size(tag_cmdline), ATAG_CMDLINE },
	{ "root=/dev/ram0 earlyprintk=serial console=ttyAMA0 init=/bin/sh" },
	{ tag_size(tag_initrd), ATAG_INITRD2 },
	{ Initrd_addr, 0 },
	{ 0, ATAG_NONE }
};

static void copyblob(l4_addr_t dst, l4_addr_t src, size_t sz)
{
  assert(dst > Ram_base && dst + sz <= Ram_base + Ram_size);
  memcpy((void *)dst, (void *)src, sz);
  l4_cache_clean_data(dst, dst + sz);
}

static void setup_linux(l4_vm_tz_state *vmstate)
{
  const L4Re::Env *env = L4Re::Env::env();
  L4::Cap<L4Re::Dataspace> vm_ds_cap;
  L4::Cap<L4Re::Dataspace> initrd_cap;
  l4_addr_t vm_image_addr = 0;
  l4_size_t vm_image_size = 0;
  l4_addr_t initrd_addr = 0;
  l4_size_t initrd_size = 0;

  L4Re::Util::Env_ns ns;
  if (!(vm_ds_cap = ns.query<L4Re::Dataspace>("rom/vm-linux-image-tz")))
    error("Cannot query vm image\n");

  vm_image_size = vm_ds_cap->size();

  if (env->rm()->attach(&vm_image_addr, l4_round_page(vm_image_size),
                        L4Re::Rm::Search_addr | L4Re::Rm::Read_only,
                        vm_ds_cap, 0, 0))
    error("Cannot attach vm image\n");

  if (!(initrd_cap = ns.query<L4Re::Dataspace>("rom/linux-initrd")))
      error("Cannot query initrd image\n");

  initrd_size = initrd_cap->size();

  if (env->rm()->attach(&initrd_addr, l4_round_page(initrd_size),
                        L4Re::Rm::Search_addr | L4Re::Rm::Read_only,
                        initrd_cap, 0, 0))
    error("Cannot attach initrd image\n");

  // fixup Initrd size in ATAG structure
  init_tags.initrd.size = initrd_size;

  copyblob(Start_addr,  vm_image_addr, vm_image_size);
  copyblob(Initrd_addr, initrd_addr, initrd_size);
  copyblob(Atag_addr,   (l4_addr_t)&init_tags, sizeof(init_tags));

  // Initialize Vm state according to Linux's requirements

  vmstate->pc = Start_addr;
  vmstate->cpsr = 0x13;
  vmstate->r[0] = 0;            // R0=0 According to the spec
  vmstate->r[1] = 827;	        // R1=1 Machine architecture
  vmstate->r[2] = Atag_addr;    // R2=2 ATAG pointer
}

int main()
{
  L4::Cap<void> sigma0_cap;
  L4::Cap<L4::Vm> vm = L4Re::chkcap(L4Re::Util::cap_alloc.alloc<L4::Vm>());
  const L4Re::Env *env = L4Re::Env::env();
  int fault;

  printf("Vmm started\n");

  L4Re::chksys(env->factory()->create_vm(vm));


  if (!(sigma0_cap = L4Re::Env::env()->get_cap<void>("sigma0")))
    error("Cannot query sigma0 cap\n");

   

  l4_addr_t v = Ram_base;
  L4Re::chksys(env->rm()->reserve_area(&v, Ram_size, L4Re::Rm::Reserved));

  int ram_size = 0x800; //2 KB
  int address  = 0x0;
  int j;
  for(j = 0; j < 512; j++) {
    fault = l4sigma0_map_iomem(sigma0_cap.cap(), Ram_base, Ram_base, ram_size, 1);
    printf("j = %d addr = 0x%x\n", j, address);
    address += ram_size;
    if (fault) {
      printf("Cannot map nonsecure memory %s\n", l4sigma0_map_errstr(fault));
      exit(1);
    }
  }

  L4vcpu::Vcpu *vcpu;
  l4_addr_t _vmstate;

  int r = L4vcpu::Vcpu::ext_alloc(&vcpu, &_vmstate);
  if (r)
    {
      printf("Failed to allocate virtualization data structures: %d\n", r);
      return 0;
    }

  l4_vm_tz_state *vmstate = (l4_vm_tz_state *)_vmstate;

  vcpu->task(vm);
  vcpu->state()->set(L4_VCPU_F_FPU_ENABLED);
  vcpu->saved_state()->set(L4_VCPU_F_USER_MODE | L4_VCPU_F_FPU_ENABLED);


  setup_linux(vmstate);

  L4::Cap<L4::Thread> me;
  L4Re::chksys(me->vcpu_control_ext((l4_addr_t)vcpu));


  while (1)
    {
      printf("VM run\n");
      int ret = l4_error(me->vcpu_resume_commit(me->vcpu_resume_start()));
      if (ret < 0)
	{
	  printf("VM run failed with %d\n", ret);
	  return -1;
	}
      else
	printf("VM exit\n");

      // do nothing but dump the state and sleep a second
      dump_vm_state(vmstate);
     
      l4_sleep(1000);
    }
  
  return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.