Monday, November 8, 2010

My First Objective-C

List.h:

#import <objc/Object.h>

@interface List : Object                          // List is a subclass of the superclass Object
{
    int list[100];                                // These are instance variables.
    int size;
}


/* Public methods */
- free;
- (int) addEntry: (int) num;
- print;

/* Private methods */
/* Other programs should not use these methods. */

- resetSize;

@end


List.m:

#import "List.h"

@implementation List

+ new                                           // factory method
{
    self = [super new];
    [self resetSize];
    return self;
}


- free
{
    return [super free];
}


- (int) addEntry: (int) num
{
    list[size++] = num;
    return size;
}


- print
{
    int i;

    printf("\n");
    for (i = 0; i < size; ++i)
        printf ("%i ", list[i]);
        puts("");
    return self;                                // Always return self
                                                                                                // if n
othing else makes sense.
}


- resetSize
{
    size = 0;
    return self;
}
Stack.h:
#import <objc/Object.h>

typedef struct StackLink {
        struct StackLink        *next;
        //void                  *data;
        int                     data;
} StackLink;


@interface Stack : Object
{
        StackLink *top;
    unsigned int size;
}

- free;
- push: (int) anInt;
- addEntry: (int) anInt;
- (int) pop;
- (unsigned int) size;

@end
Stack.m:
#import "Stack.h"
#import <stdlib.h>

@implementation Stack

#define NULL_LINK (StackLink *) 0

+ new
{
    self = [super new];
    top = NULL_LINK; //(StackLink *) 0;
    return self;
}


- free
{
    StackLink *next;

    while (top != NULL_LINK)
    {
        next = top->next;
        free ((char *) top);
        top = next;
    }
    return [super free];
}


- push: (int) value
{
    StackLink *newLink;

    newLink = (StackLink *) malloc (sizeof (StackLink));
    if (newLink == 0)
    {
        fprintf(stderr, "Out of memory\n");
        return nil;
    }
    newLink->data = value;
    newLink->next = top;
    top = newLink;
    size++;

    return self;
}


- addEntry: (int) value
{
        return [self push: value];
}

- (int) pop
{
    int value;
    StackLink *topLink;

    if (0 != size)
    {
        topLink = top;
        top = top->next;
        value = topLink->data;
        free (topLink);
        size--;
    }
    else
    {
        value = 0;
    }
    return value;
}


- (unsigned int) size
{
    return size;
}

- print
{
        StackLink *startLink;
        int i = size;

        startLink = top;

        while (startLink) {
                printf("Stack[%d] = %d\n", i, startLink->data);
                startLink = startLink->next;
                i--;
        }
        return self;
}

@end
main.m:
#import <objc/Object.h>
#import "List.h"
#import "Stack.h"

//int main(int argc, char *argv[])

void perform (id obj)
{
        [obj addEntry: 5];
        [obj print];
        [obj addEntry: 6];
        [obj addEntry: 3];
        [obj print];
}

main()
{
        id list;

        list = [List new];
        perform(list);
        [list free];

        id stack;
        stack = [Stack new];
        perform(stack);
        [stack free];
        printf("\n");
        return 0;
}

Makefile:
.SUFFIXES: .o .m

.m.o:
        $(CC) -c $(CFLAGS) $< -o $@

# Macros

CC=gcc

#CFLAGS=-Wall -Wno-import -mtune=core2 -mfpmath=sse -ffast-math -msse3 -fobjc-exceptions
CFLAGS=-Wno-import -mtune=core2 -g

LDFLAGS=-lobjc
SRCS=main.m List.m Stack.m
OBJS=$(SRCS:.m=.o)
EXECUTABLE=main

.PHONY: all

all: $(EXECUTABLE)

$(EXECUTABLE): $(OBJS)
        $(CC) $(LDFLAGS) -o $@ $(OBJS)

#$(OBJS): $(SRCS)
#       echo "$(CC) -c $(CFLAGS) $< -o $@"

clean:
        rm -f *.o $(EXECUTABLE)

TAGS: $(SRCS)
        ctags -R $(SRCS)

Tuesday, November 2, 2010

MiniDuckSimulator.java


import java.io.Console;

/**
 * @author mlutfi
 *
 */
public class MiniDuckSimulator {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Duck mallard = new MallardDuck();
  mallard.display();
  mallard.performQuack();
  mallard.performFly();
  
  Duck model = new ModelDuck();
  model.display();
  model.performFly();
  model.setFlyBehavior(new FlyRocketPowered());
  model.performFly();
 }
}

Sunday, October 31, 2010

How to block certain inbound IP addresses

Create a file /etc/iptables/blockip.sh:

#!/bin/bash
# Simple iptables IP/subnet block script
# -------------------------------------------------------------------------
IPT=`which iptables`
SPAMLIST="spamlist"
SPAMDROPMSG="SPAM LIST DROP"
BADIPS=$(egrep -v -e "^#|^$" /etc/iptables/blocked.ips)

# create a new iptables list
$IPT -N $SPAMLIST

for ipblock in $BADIPS
do
   $IPT -A $SPAMLIST -s $ipblock -j LOG --log-prefix "$SPAMDROPMSG"
   $IPT -A $SPAMLIST -s $ipblock -j DROP
done

$IPT -I INPUT -j $SPAMLIST
$IPT -I OUTPUT -j $SPAMLIST
$IPT -I FORWARD -j $SPAMLIST

Create a file /etc/iptables/blocked.ips:

put IP addresses here! (one per line)


edit file /etc/boot.local and add this line:

/etc/iptables/blockip.sh

Saturday, October 30, 2010

Error in compiling QEMU-XEN

The following errors occurs when I did "make tool". For some reason, the file "cpu.h" in subdir
+ test -d git://xenbits.xensource.com/qemu-xen-4.0-testing.git
+ '[' '!' -d ioemu-remote ']'
+ rm -f ioemu-dir
+ ln -sf ioemu-remote ioemu-dir
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_arch_init_vcpu':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:47:5: warning: implicit declaration of function `cpu_x86_cpuid'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_has_msr_star':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:159:49: error: `MSR_STAR' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:159:49: note: each undeclared identifier is reported only once for each function it appears in
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `set_seg':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:219:27: error: `DESC_TYPE_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:220:29: error: `DESC_P_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:222:25: error: `DESC_B_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:223:23: error: `DESC_S_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:224:24: error: `DESC_L_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:225:23: error: `DESC_G_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:226:25: error: `DESC_AVL_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `get_seg':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:236:16: error: `DESC_TYPE_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:237:20: error: `DESC_P_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:238:17: error: `DESC_DPL_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:239:16: error: `DESC_B_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:240:14: error: `DESC_S_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:241:15: error: `DESC_L_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:242:14: error: `DESC_G_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:243:16: error: `DESC_AVL_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_getput_regs':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:265:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:265:42: error: `R_EAX' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:266:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:266:42: error: `R_EBX' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:267:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:267:42: error: `R_ECX' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:268:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:268:42: error: `R_EDX' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:269:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:269:42: error: `R_ESI' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:270:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:270:42: error: `R_EDI' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:271:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:271:42: error: `R_ESP' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:272:35: error: `CPUX86State' has no member named `regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:272:42: error: `R_EBP' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:284:38: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:285:35: error: `CPUX86State' has no member named `eip'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_put_fpu':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:299:18: error: `CPUX86State' has no member named `fpus'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:300:20: error: `CPUX86State' has no member named `fpstt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:301:18: error: `CPUX86State' has no member named `fpuc'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:303:19: error: `CPUX86State' has no member named `fptags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:304:24: error: `CPUX86State' has no member named `fpregs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:304:44: error: `CPUX86State' has no member named `fpregs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:305:24: error: `CPUX86State' has no member named `xmm_regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:305:46: error: `CPUX86State' has no member named `xmm_regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:306:20: error: `CPUX86State' has no member named `mxcsr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_put_sregs':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:316:15: error: `CPUX86State' has no member named `interrupt_bitmap'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:319:13: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:319:24: error: `VM_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:320:35: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:320:42: error: `R_CS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:321:35: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:321:42: error: `R_DS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:322:35: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:322:42: error: `R_ES' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:323:35: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:323:42: error: `R_FS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:324:35: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:324:42: error: `R_GS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:325:35: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:325:42: error: `R_SS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:327:29: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:328:29: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:329:29: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:330:29: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:331:29: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:332:29: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:334:13: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:334:23: error: `CR0_PE_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:342:28: error: `CPUX86State' has no member named `tr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:343:29: error: `CPUX86State' has no member named `ldt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:345:26: error: `CPUX86State' has no member named `idt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:346:25: error: `CPUX86State' has no member named `idt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:347:26: error: `CPUX86State' has no member named `gdt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:348:25: error: `CPUX86State' has no member named `gdt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:350:20: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:351:20: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:352:20: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:353:20: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:355:5: warning: implicit declaration of function `cpu_get_apic_tpr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:356:5: warning: implicit declaration of function `cpu_get_apic_base'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:358:21: error: `CPUX86State' has no member named `efer'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_put_msrs':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:379:35: error: `MSR_IA32_SYSENTER_CS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:379:60: error: `CPUX86State' has no member named `sysenter_cs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:380:35: error: `MSR_IA32_SYSENTER_ESP' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:380:61: error: `CPUX86State' has no member named `sysenter_esp'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:381:35: error: `MSR_IA32_SYSENTER_EIP' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:381:61: error: `CPUX86State' has no member named `sysenter_eip'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:383:32: error: `MSR_STAR' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:383:45: error: `CPUX86State' has no member named `star'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:384:35: error: `MSR_IA32_TSC' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:384:52: error: `CPUX86State' has no member named `tsc'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_get_fpu':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:408:8: error: `CPUX86State' has no member named `fpstt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:409:8: error: `CPUX86State' has no member named `fpus'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:410:8: error: `CPUX86State' has no member named `fpuc'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:412:5: error: `CPUX86State' has no member named `fptags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:413:15: error: `CPUX86State' has no member named `fpregs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:413:44: error: `CPUX86State' has no member named `fpregs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:414:15: error: `CPUX86State' has no member named `xmm_regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:414:46: error: `CPUX86State' has no member named `xmm_regs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:415:8: error: `CPUX86State' has no member named `mxcsr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_get_sregs': 
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:430:15: error: `CPUX86State' has no member named `interrupt_bitmap'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:434:17: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:434:24: error: `R_CS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:435:17: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:435:24: error: `R_DS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:436:17: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:436:24: error: `R_ES' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:437:17: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:437:24: error: `R_FS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:438:17: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:438:24: error: `R_GS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:439:17: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:439:24: error: `R_SS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:441:17: error: `CPUX86State' has no member named `tr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:442:17: error: `CPUX86State' has no member named `ldt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:444:8: error: `CPUX86State' has no member named `idt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:445:8: error: `CPUX86State' has no member named `idt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:446:8: error: `CPUX86State' has no member named `gdt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:447:8: error: `CPUX86State' has no member named `gdt'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:449:8: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:450:8: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:451:8: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:452:8: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:454:5: warning: implicit declaration of function `cpu_set_apic_base'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:456:8: error: `CPUX86State' has no member named `efer'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:467:18: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:467:40: error: `DESC_DPL_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:467:58: error: `HF_CPL_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:468:19: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:468:29: error: `CR0_PE_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:468:46: error: `HF_PE_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:468:60: error: `CR0_PE_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:469:19: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:469:31: error: `HF_MP_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:469:45: error: `CR0_MP_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:470:7: error: `HF_MP_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:470:20: error: `HF_EM_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:470:33: error: `HF_TS_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:471:19: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:471:31: error: `HF_TF_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:471:44: error: `HF_VM_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:471:57: error: `HF_IOPL_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:472:19: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:472:29: error: `CR4_OSFXSR_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:473:7: error: `HF_OSFXSR_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:473:25: error: `CR4_OSFXSR_SHIFT'  undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:475:12: error: `CPUX86State' has no member named `efer'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:475:21: error: `MSR_EFER_LMA' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:476:19: error: `HF_LMA_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:479:39: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:479:60: error: `DESC_L_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:480:19: error: `HF_CS32_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:480:34: error: `HF_SS32_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:480:49: error: `HF_CS64_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:482:23: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:482:44: error: `DESC_B_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:483:4: error: `DESC_B_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:483:19: error: `HF_CS32_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:484:23: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:485:19: error: `HF_SS32_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:486:18: error: `CPUX86State' has no member named `cr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:487:24: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:487:35: error: `VM_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:489:27: error: `HF_ADDSEG_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:491:32: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:492:36: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:493:36: error: `CPUX86State' has no member named `segs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:494:21: error: `HF_ADDSEG_SHIFT' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:497:8: error: `CPUX86State' has no member named `hflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:497:23: error: `CPUX86State' has no member named `hflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:497:34: error: `HF_PE_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:497:34: error: `HF_OSFXSR_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_get_msrs':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:512:23: error: `MSR_IA32_SYSENTER_CS' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:513:23: error: `MSR_IA32_SYSENTER_ESP' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:514:23: error: `MSR_IA32_SYSENTER_EIP' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:516:20: error: `MSR_STAR' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:517:23: error: `MSR_IA32_TSC' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:533:16: error: `CPUX86State' has no member named `sysenter_cs'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:536:16: error: `CPUX86State' has no member named `sysenter_esp'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:539:16: error: `CPUX86State' has no member named `sysenter_eip'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:542:16: error: `CPUX86State' has no member named `star'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:559:16: error: `CPUX86State' has no member named `tsc'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_arch_pre_run':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:618:13: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:618:24: error: `IF_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_arch_post_run':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:650:12: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:650:24: error: `IF_MASK' undeclared (first use in this function)
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:652:12: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:654:5: warning: implicit declaration of function `cpu_set_apic_tpr'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c: In function `kvm_handle_halt':
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:663:15: error: `CPUX86State' has no member named `eflags'
/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c:663:26: error: `IF_MASK' undeclared (first use in this function)
make[3]: *** [kvm.o] Error 1
make[2]: *** [subdir-i386-dm] Error 2
make[1]: *** [subdir-all-ioemu-dir] Error 2
make: *** [subdirs-all] Error 2
'

Quick fix: goto dir "target-i386" and perform:

myname@linux-bvhg:~/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386> gcc -I. -I.. -I/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386 -I/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir -MMD -MT kvm.o -MP -DNEED_CPU_H -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/tcg -I/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/tcg/x86_64 -I/home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/fpu  -DHAS_AUDIO -DHAS_AUDIO_CHOICE -DHAS_AUDIO -I/home/myname/src/xen-4.0-testing.hg//tools/libxc -I/home/myname/src/xen-4.0-testing.hg//tools/xenstore -I/home/myname/src/xen-4.0-testing.hg//tools/include -I/home/myname/src/xen-4.0-testing.hg//tools/blktap/lib -mtune=core2 -msse3 -O2 -m64 -mfpmath=sse -ffast-math -O2 -fomit-frame-pointer -m64 
 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement  -D__XEN_TOOLS__ -MMD -MF .subdirs-all.d  -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE  -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall  -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement  -D__XEN_TOOLS__ -MMD -MF .ioemu-dir-find.d  -D_LARGEFILE_SOURCE -D_LARGEFILE64 _SOURCE  -O2 -g -fno-strict-aliasing -Wall -Wundef -W endif-labels -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement  -D__XEN_TOOLS__ -MMD -MF .kvm.o.d  -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE  -Wno-unused -Wno-declaration-after-statement -Wno-pointer-sign  -DCONFIG_PASSTHROUGH  -I../hw  -m64 -Wno-unused -Wno-declaration-after-statement -Wno-pointer-sign  -DCONFIG_PASSTHROUGH   -c -o kvm.o /home/myname/src/xen-4.0-testing.hg/tools/ioemu-dir/target-i386/kvm.c

Xen Installation & Compilation


Installation from source

Xen 4.0 source code mercurial (hg) repository and changelog: http://xenbits.xen.org/xen-4.0-testing.hg
You can get Xen 4.0 with mercurial using the following command:
hg clone http://xenbits.xen.org/xen-4.0-testing.hg
Note that this will give you the LATEST version in xen-4.0-testing.hg repository! It might be a release candidate for next release or just some developer snapshot. See the changelog above for current status. You can also get a specific 'tag' from the repository like this:
hg clone -r RELEASE-4.0.1 http://xenbits.xen.org/xen-4.0-testing.hg
Alternatively you can download the Xen 4.0.x source tarball from http://www.xen.org/products/xen_source.html . Note that if you're planning to use Xen 4.0.0 tarball please see the Known Issues below for a note about supported pvops dom0 kernel versions.
NOTE!! during the Xen build process outbound git-protocol needs to be open in your network firewall! Xen build scripts need to access git:// repositories on git.kernel.org and xenbits.xen.org. Some people have reported issues accessing the remote repositories - these problems are most often caused by a broken Internet connection, broken firewall, or a broken NAT router you use.
This example will only build the new Xen 4.0 hypervisor and tools. This method does NOT download or build a (dom0) kernel from the xen.git repository. "make tools" part will download the xen qemu-dm ioemu for hvm guests from xenbits git repository and tools tarballs (unless you've already downloaded them yourself before building).
cd xen-4.0-testing.hg 
make xen 
make tools 
make stubdom
When the compilation process finishes you'll have the Xen hypervisor/tools binaries in "dist/" directory ready for installation:
make install-xen 
make install-tools 
make install-stubdom
And then compile your chosen new dom0 kernel, or use your existing dom0 kernel. Also update grub.conf to use the newly installed Xen 4.0 hypervisor.
See XenDom0Kernels wiki page for information about all the available Xen Dom0 capable kernels, and XenParavirtOps wiki page for more detailed information about Xen pvops dom0 kernels.
You can also compile Xen 4.0 together with the new default pvops dom0 kernel (Linux 2.6.32.x in Xen 4.0.1 and newer versions). This method downloads the kernel sources from xen.git repository during the build process:
make world
This will download the latest pvops dom0 kernel 2.6.32.x from Jeremy's xen.git repository during the build process. See the XenParavirtOps wiki page for more information about different pvops dom0 kernel versions. Also see the Known Issues below for supported pvops dom0 kernel versions.
NOTE about the old Xenlinux linux-2.6.18-xen kernels:
make kernels KERNELS="linux-2.6-xen0 linux-2.6-xenU"

Xen compilation

When I was trying to compile Xen-4.0.1, I got these messages:

make[1]: Entering directory `/xen-4.0-testing.hg/xen'
make -f Rules.mk _install
make[2]: Entering directory `/xen-4.0-testing.hg/xen'
make -C tools
make[3]: Entering directory `/xen-4.0-testing.hg/xen/tools'
[ -d figlet ] && make -C figlet
make[4]: Entering directory `/xen-4.0-testing.hg/xen/tools/figlet'
make[4]: `figlet' is up to date.
make[4]: Leaving directory `/xen-4.0-testing.hg/xen/tools/figlet'
make symbols
make[4]: Entering directory `/xen-4.0-testing.hg/xen/tools'
make[4]: `symbols' is up to date.
make[4]: Leaving directory `/xen-4.0-testing.hg/xen/tools'
make[3]: Leaving directory `/xen-4.0-testing.hg/xen/tools'
make -f /xen-4.0-testing.hg/xen/Rules.mk include/xen/compile.h
make[3]: Entering directory `/xen-4.0-testing.hg/xen'
 __  __            _  _    ___   ____              _                   
 \ \/ /___ _ __   | || |  / _ \ |___ \    _ __ ___/ |   _ __  _ __ ___ 
  \  // _ \ '_ \  | || |_| | | |  __) |__| '__/ __| |__| '_ \| '__/ _ \
  /  \  __/ | | | |__   _| |_| | / __/|__| | | (__| |__| |_) | | |  __/
 /_/\_\___|_| |_|    |_|(_)___(_)_____|  |_|  \___|_|  | .__/|_|  \___|
                                                       |_|             
make[3]: Leaving directory `/xen-4.0-testing.hg/xen'
[ -e include/asm ] || ln -sf asm-x86 include/asm
make -f /xen-4.0-testing.hg/xen/Rules.mk -C include
make[3]: Entering directory `/xen-4.0-testing.hg/xen/include'
make[3]: Nothing to be done for `all'.
make[3]: Leaving directory `/xen-4.0-testing.hg/xen/include'
make -f /xen-4.0-testing.hg/xen/Rules.mk -C arch/x86 asm-offsets.s
make[3]: Entering directory `/xen-4.0-testing.hg/xen/arch/x86'
make[3]: `asm-offsets.s' is up to date.
make[3]: Leaving directory `/xen-4.0-testing.hg/xen/arch/x86'
make -f /xen-4.0-testing.hg/xen/Rules.mk include/asm-x86/asm-offsets.h
make[3]: Entering directory `/xen-4.0-testing.hg/xen'
make[3]: `include/asm-x86/asm-offsets.h' is up to date.
make[3]: Leaving directory `/xen-4.0-testing.hg/xen'
make -f /xen-4.0-testing.hg/xen/Rules.mk -C arch/x86 /xen-4.0-testing.hg/xen/xen
make[3]: Entering directory `/xen-4.0-testing.hg/xen/arch/x86'
make -f /xen-4.0-testing.hg/xen/Rules.mk -C /xen-4.0-testing.hg/xen/arch/x86/boot built_in.o
make[4]: Entering directory `/xen-4.0-testing.hg/xen/arch/x86/boot'
RELOC=0x7c000 XEN_BITSPERLONG=64 make -f build32.mk reloc.S
make[5]: Entering directory `/xen-4.0-testing.hg/xen/arch/x86/boot'
make[5]: *** ../../../../.config: Is a directory.  Stop.
make[5]: Leaving directory `/xen-4.0-testing.hg/xen/arch/x86/boot'
make[4]: *** [reloc.S] Error 2
make[4]: Leaving directory `/xen-4.0-testing.hg/xen/arch/x86/boot'
make[3]: *** [/xen-4.0-testing.hg/xen/arch/x86/boot/built_in.o] Error 2
make[3]: Leaving directory `/xen-4.0-testing.hg/xen/arch/x86'
make[2]: *** [/xen-4.0-testing.hg/xen/xen] Error 2
make[2]: Leaving directory `/xen-4.0-testing.hg/xen'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/xen-4.0-testing.hg/xen'
make: *** [install-xen] Error 2

The message showed me that it was expecting the .config exist in the root folder. I copied the file from /usr/src/linux (kernel source) and recompile. it worked!