Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added red-black tree implementation from linux
[palacios.git] / palacios / src / palacios / vmm_instr_emulator.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #define addr_t unsigned long
5
6
7
8
9 void test() {
10   int a = 10;
11   int b;
12
13   asm ("movl %1, %%eax\n\t"
14        "movl %%eax, %0\n\t"
15        :"=r"(b)        /* output */
16        :"r"(a)         /* input */
17        :"%eax"         /* clobbered register */
18        );       
19
20 }
21
22 void get_flags(addr_t * flags) {
23   addr_t tmp;
24   asm  ("pushfq\n\t"
25         "pop %0\n\t"
26         :"=r"(tmp)
27         : 
28         );
29
30   *flags = tmp;
31 }
32
33 void adc64(int * dst, int * src, addr_t * flags) {
34   int tmp_dst = *dst, tmp_src = *src;
35   addr_t tmp_flags = *flags;
36
37   char * inst = "adcl";
38
39   // Some of the flags values are not copied out in a pushf, we save them here
40   addr_t flags_rsvd = *flags & ~0xfffe7fff;
41
42   asm volatile (
43        "pushfq\r\n"
44        "push %3\r\n"
45        "popfq\r\n"
46        "adcl %2, %0\r\n"
47        "pushfq\r\n"
48        "pop %1\r\n"
49        "popfq\r\n"
50        : "=a"(tmp_dst),"=c"(tmp_flags)
51        : "b"(tmp_src),"c"(tmp_flags), "0"(tmp_dst)
52     );
53
54   *dst = tmp_dst;
55   *flags = tmp_flags;
56   *flags |= flags_rsvd;
57
58 }
59
60
61 void adc32(int * dst, int * src, addr_t * flags) {
62   int tmp_dst = *dst, tmp_src = *src;
63   addr_t tmp_flags = *flags;
64
65   
66   asm volatile (
67        "pushfd\r\n"
68         "push %3\r\n"
69         "popfd\r\n"
70         "adcl %2, %0\r\n"
71         "pushfd\r\n"
72         "pop %1\r\n"
73         "popfd\r\n"
74         : "=a"(tmp_dst),"=c"(tmp_flags)
75        : "b"(tmp_src),"c"(tmp_flags), "0"(tmp_dst)
76     );
77
78   *dst = tmp_dst;
79   *flags = tmp_flags;
80
81 }
82
83
84 int main(int argc, char ** argv) {
85   addr_t flags;
86   int dest = 4;
87   int src = 5;
88   
89   printf("sizeof ulong: %d\n", sizeof(unsigned long));
90
91   printf("Getting flags\n");
92   get_flags(&flags);
93   flags = flags | 0x1;
94
95   printf("Flags=0x%x\n", flags);
96   test();
97   printf("Adding\n");
98   adc64(&dest, &src, &flags);
99   printf("Result=%d\n", dest);
100
101 }