diff --git a/.rootkeys b/.rootkeys index b7530f2a50..99a845f769 100644 --- a/.rootkeys +++ b/.rootkeys @@ -317,6 +317,7 @@ 3ddb79bcBQF85CfLS4i1WGZ4oLLaCA xen/arch/x86/Rules.mk 3e5636e5FAYZ5_vQnmgwFJfSdmO5Mw xen/arch/x86/acpi.c 3ddb79bcsjinG9k1KcvbVBuas1R2dA xen/arch/x86/apic.c +3ddb79c4yGZ7_22QAFFwPzqP4NSHwA xen/arch/x86/boot/mkelf32.c 3ddb79bcSC_LvnmFlX-T5iTgaR0SKg xen/arch/x86/boot/x86_32.S 40e42bdbNu4MjI750THP_8J1S-Sa0g xen/arch/x86/boot/x86_64.S 3ddb79bcUrk2EIaM5VsT6wUudH1kkg xen/arch/x86/delay.c @@ -398,6 +399,11 @@ 3ddb79bfl1H1arbB0pzAEC2uPmY_3g xen/drivers/pci/setup-irq.c 3ddb79bfJaf0bkE1Y67bnll8-kjEPg xen/drivers/pci/setup-res.c 3ddb79bfIcCWJsBDNcQQE3ok2Azn-Q xen/drivers/pci/syscall.c +3eb3c87fc79FXLA6R9TvdBJNTvQDwA xen/figlet/LICENSE +3eb3c87fPL2T_zBb0bHlbZY-ACEKRw xen/figlet/Makefile +3eb3c87fmKYTC5GCh_rydFakZp9ayw xen/figlet/README +3eb3c87fdQKQ5OBGbM-KjZfi9Us4ng xen/figlet/figlet.c +3eb3c87fS7DNbg0i6yhFs28UIqAK5g xen/figlet/xen.flf 40715b2cFpte_UNWnBZW0Du7z9AhTQ xen/include/acpi/acconfig.h 40715b2cEQWX-PaxEH30qI48K1krnQ xen/include/acpi/acdebug.h 40715b2c_7j-oy3ZNAuqE3IFNPzArg xen/include/acpi/acdisasm.h @@ -532,10 +538,3 @@ 3ddb79c0BnA20PbgmuMPSGIBljNRQw xen/include/xen/time.h 403a3edbG9K5uZjuY19_LORbQGmFbA xen/include/xen/trace.h 3ddb79c1-kVvF8cVa0k3ZHDdBMj01Q xen/include/xen/types.h -3ddb79c4x8dvwPtzclghWAKFWpEBFA xen/tools/Makefile -3ddb79c4yGZ7_22QAFFwPzqP4NSHwA xen/tools/elf-reloc.c -3eb3c87fc79FXLA6R9TvdBJNTvQDwA xen/tools/figlet/LICENSE -3eb3c87fPL2T_zBb0bHlbZY-ACEKRw xen/tools/figlet/Makefile -3eb3c87fmKYTC5GCh_rydFakZp9ayw xen/tools/figlet/README -3eb3c87fdQKQ5OBGbM-KjZfi9Us4ng xen/tools/figlet/figlet.c -3eb3c87fS7DNbg0i6yhFs28UIqAK5g xen/tools/figlet/xen.flf diff --git a/BitKeeper/etc/ignore b/BitKeeper/etc/ignore index 88f1211183..8f11ded149 100644 --- a/BitKeeper/etc/ignore +++ b/BitKeeper/etc/ignore @@ -21,14 +21,17 @@ tools/*/build/lib*/*.py tools/misc/miniterm/miniterm tools/misc/xen_cpuperf tools/xentrace/xentrace +xen/arch/x86/boot/mkelf32 xen/drivers/pci/classlist.h xen/drivers/pci/devlist.h xen/drivers/pci/gen-devlist xen/include/asm xen/include/hypervisor-ifs/arch xen/include/xen/compile.h -xen/tools/elf-reloc -xen/tools/figlet/figlet +xen/figlet/figlet xen/xen xen/xen-syms xen/xen.* +tools/xfrd/xfrd +xen/tools/elf-reloc +xen/tools/figlet/figlet diff --git a/tools/examples/network b/tools/examples/network index 49ce29da0a..1c0505f6f3 100755 --- a/tools/examples/network +++ b/tools/examples/network @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh #============================================================================ # Example Xen network start/stop script. # Xend calls a network script when it starts. @@ -54,9 +54,10 @@ transfer_addrs () { fi # Address lines start with 'inet' and have the device in them. # Replace 'inet' with 'ip addr add' and change the device name $src - # to 'dev $src'. + # to 'dev $src'. Remove netmask as we'll add routes later. ip addr show dev ${src} | egrep '^ *inet' | sed -e " s/inet/ip addr add/ +s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)/[0-9]\+@\1@ s/${src}/dev ${dst}/ " | sh -e } diff --git a/tools/python/xen/util/ip.py b/tools/python/xen/util/ip.py index 8f93687139..9dd558a178 100644 --- a/tools/python/xen/util/ip.py +++ b/tools/python/xen/util/ip.py @@ -2,6 +2,7 @@ import os import re import socket import struct +import errno def _readlines(fd): """Version of readlines safe against EINTR. diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 68724a63cc..629068e090 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -72,12 +72,12 @@ def blkdev_name_to_number(name): """Take the given textual block-device name (e.g., '/dev/sda1', 'hda') and return the device number used by the OS. """ - if not re.match( '/dev/', name ): + if not re.match( '^/dev/', name ): name = '/dev/' + name return os.stat(name).st_rdev -def lookup_raw_partn(partition): +def lookup_raw_partn(name): """Take the given block-device name (e.g., '/dev/sda1', 'hda') and return a dictionary { device, start_sector, nr_sectors, type } @@ -87,40 +87,26 @@ def lookup_raw_partn(partition): type: 'Disk' or identifying name for partition type """ - if not re.match( '/dev/', partition ): - partition = '/dev/' + partition - - """Try and match non-standard scsi raid arraysa - """ - if re.match( '/dev/cciss/c[0-9]+d[0-9]+p[0-9]+', partition ): - drive = re.split( 'p[0-9]+', partition )[0] + p = name + + if not re.match( '^/dev/', name ): + p = '/dev/' + name + + fd = os.popen( '/sbin/sfdisk -s ' + p + ' 2>/dev/null' ) + line = _readline(fd) + if line: + return [ { 'device' : blkdev_name_to_number(p), + 'start_sector' : long(0), + 'nr_sectors' : long(line) * 2, + 'type' : 'Disk' } ] else: - drive = re.split( '[0-9]', partition )[0] - - if drive == partition: - fd = os.popen( '/sbin/sfdisk -s ' + drive + ' 2>/dev/null' ) - line = _readline(fd) - if line: - return [ { 'device' : blkdev_name_to_number(drive), - 'start_sector' : long(0), - 'nr_sectors' : long(line) * 2, - 'type' : 'Disk' } ] - return None - - # determine position on disk - fd = os.popen( '/sbin/sfdisk -d ' + drive + ' 2>/dev/null' ) - - #['/dev/sda3 : start= 16948575, size=16836120, Id=83, bootable\012'] - lines = _readlines(fd) - for line in lines: - m = re.search( '^' + partition + '\s*: start=\s*([0-9]+), ' + - 'size=\s*([0-9]+), Id=\s*(\S+).*$', line) - if m: - return [ { 'device' : blkdev_name_to_number(drive), - 'start_sector' : long(m.group(1)), - 'nr_sectors' : long(m.group(2)), - 'type' : m.group(3) } ] - + # see if this is a hex device number + if re.match( '^(0x)?[0-9a-fA-F]+$', name ): + return [ { 'device' : string.atoi(name,16), + 'start_sector' : long(0), + 'nr_sectors' : long(1L<<63), + 'type' : 'Disk' } ] + return None def lookup_disk_uname(uname): @@ -143,7 +129,7 @@ def make_disk(dom, uname, dev, mode, recreate=0): """ segments = lookup_disk_uname(uname) if not segments: - raise VmError("vbd: Segments not found: uname=%s" % uname) + raise VmError("vbd: Segments not foundXXXXXX: uname=%s" % uname) if len(segments) > 1: raise VmError("vbd: Multi-segment vdisk: uname=%s" % uname) segment = segments[0] diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index 5874af70ff..d8ac0d43e6 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -78,11 +78,10 @@ class Xm: """ self.name = args[0] if len(args) < 2: - self.err("Missing command\nTry '%s help' for more information." - % self.name) - help = self.helparg(args) + args.append('help') + help = self.helparg(args) p = self.getprog(args[1], self.unknown) - if help: + if help or len(args) < 2: p.help(args[1:]) else: p.main(args[1:]) diff --git a/tools/python/xen/xm/opts.py b/tools/python/xen/xm/opts.py index 9bae32e082..d66d30a7a3 100644 --- a/tools/python/xen/xm/opts.py +++ b/tools/python/xen/xm/opts.py @@ -331,6 +331,7 @@ class Opts: else: p = self.vals.defaults if os.path.exists(p): + print 'Using config file %s\n' % (p) self.load(p, help) break else: diff --git a/xen/Makefile b/xen/Makefile index a9fcf91e18..d65f8df8ca 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -27,14 +27,13 @@ dist: $(TARGET) $(MAKE) prefix=`pwd`/../install dist=yes install clean: delete-links - $(MAKE) -C tools clean + $(MAKE) -C figlet clean $(MAKE) -C common clean $(MAKE) -C drivers clean $(MAKE) -C arch/$(TARGET_ARCH) clean rm -f *.o $(TARGET)* *~ core $(GENERATED_FILES) $(TARGET): delete-unfresh-files make-links $(GENERATED_FILES) - $(MAKE) -C tools $(MAKE) -C common $(MAKE) -C drivers $(MAKE) -C arch/$(TARGET_ARCH) @@ -65,7 +64,7 @@ include/xen/compile.h: @LANG=C echo \#define XEN_EXTRAVERSION \"$(XEN_EXTRAVERSION)\" >> $@ @LANG=C echo >> $@ @LANG=C echo \#define XEN_BANNER \\ >> $@ - cd tools/figlet && make && ./figlet Xen $(XEN_VERSION).$(XEN_SUBVERSION)$(XEN_EXTRAVERSION) 1>>../../$@ && cd ../.. + cd ./figlet && make && ./figlet Xen $(XEN_VERSION).$(XEN_SUBVERSION)$(XEN_EXTRAVERSION) 1>>../$@ && cd .. @LANG=C echo >> $@ .PHONY: $(GENERATED_FILES) make-links delete-links default diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 1290f0420f..48c3556464 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -9,30 +9,16 @@ endif OBJS += $(patsubst %.S,%.o,$(wildcard $(TARGET_SUBARCH)/*.S)) OBJS += $(patsubst %.c,%.o,$(wildcard $(TARGET_SUBARCH)/*.c)) -ifeq ($(TARGET_SUBARCH),x86_32) -LINK_BASE := 0xFC500000 # Xen is linked here -LOAD_BASE := 0x00100000 # Xen is loaded here -endif - -ifeq ($(TARGET_SUBARCH),x86_64) -LINK_BASE := 0xFFFF830000100000 # Xen is linked here -LOAD_BASE := 0x0000000000100000 # Xen is loaded here -endif - -# What happens here? We link object files together, starting at LINK_BASE -# (a very high address). But the bootloader cannot put things there, so we -# initially load at LOAD_BASE. A tool called `elf-reloc' is used to modify -# segment offsets from LINK_BASE-relative to LOAD_BASE-relative. -# (NB. Linux gets round this by turning its image into raw binary, then -# wrapping that with a low-memory bootstrapper.) -default: boot/$(TARGET_SUBARCH).o $(OBJS) +default: boot/$(TARGET_SUBARCH).o $(OBJS) boot/mkelf32 $(LD) $(LDFLAGS) -r -o arch.o $(OBJS) $(LD) $(LDFLAGS) -T $(TARGET_SUBARCH)/xen.lds -N \ boot/$(TARGET_SUBARCH).o $(ALL_OBJS) -o $(TARGET)-syms - objcopy -R .note -R .comment -S $(TARGET)-syms $(TARGET) - $(BASEDIR)/tools/elf-reloc $(LINK_BASE) $(LOAD_BASE) $(TARGET) + ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 + +boot/mkelf32: boot/mkelf32.c + $(HOSTCC) $(HOSTCFLAGS) -o $@ $< clean: - rm -f *.o *~ core boot/*.o boot/*~ boot/core - rm -f $(TARGET_SUBARCH)/*.o $(TARGET_SUBARCH)/*~ - rm -f $(TARGETSUBARCH)/core + rm -f *.o *~ core boot/*.o boot/*~ boot/core boot/mkelf32 + rm -f x86_32/*.o x86_32/*~ x86_32/core + rm -f x86_64/*.o x86_64/*~ x86_64/core diff --git a/xen/arch/x86/boot/mkelf32.c b/xen/arch/x86/boot/mkelf32.c new file mode 100644 index 0000000000..286a61315a --- /dev/null +++ b/xen/arch/x86/boot/mkelf32.c @@ -0,0 +1,294 @@ +/****************************************************************************** + * mkelf32.c + * + * Usage: elf-prefix + * + * Converts an Elf32 or Elf64 executable binary into a simple Elf32 + * image comprising a single chunk to be loaded at . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Here I'm taking care not to conflict with possible typedef's in + * standard headers by instead using the macro namespace. + */ +#undef u8 +#undef u16 +#undef u32 +#undef u64 +#undef s8 +#undef s16 +#undef s32 +#undef s64 +#define u8 unsigned char +#define u16 unsigned short +#define u32 unsigned int +#define s8 signed char +#define s16 signed short +#define s32 signed int +#if defined(__i386__) +#define u64 unsigned long long +#define s64 signed long long +#else +#define u64 unsigned long +#define s64 signed long +#endif + +#include "../../../include/xen/elf.h" + +#define DYNAMICALLY_FILLED 0 +#define RAW_OFFSET 128 + +static Elf32_Ehdr out_ehdr = { + { ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* EI_MAG{0-3} */ + ELFCLASS32, /* EI_CLASS */ + ELFDATA2LSB, /* EI_DATA */ + EV_CURRENT, /* EI_VERSION */ + 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* e_ident */ + ET_EXEC, /* e_type */ + EM_386, /* e_machine */ + EV_CURRENT, /* e_version */ + DYNAMICALLY_FILLED, /* e_entry */ + sizeof(Elf32_Ehdr), /* e_phoff */ + DYNAMICALLY_FILLED, /* e_shoff */ + 0, /* e_flags */ + sizeof(Elf32_Ehdr), /* e_ehsize */ + sizeof(Elf32_Phdr), /* e_phentsize */ + 1, /* e_phnum */ + sizeof(Elf32_Shdr), /* e_shentsize */ + 3, /* e_shnum */ + 2 /* e_shstrndx */ +}; + +static Elf32_Phdr out_phdr = { + PT_LOAD, /* p_type */ + RAW_OFFSET, /* p_offset */ + DYNAMICALLY_FILLED, /* p_vaddr */ + DYNAMICALLY_FILLED, /* p_paddr */ + DYNAMICALLY_FILLED, /* p_filesz */ + DYNAMICALLY_FILLED, /* p_memsz */ + PF_R|PF_W|PF_X, /* p_flags */ + 64 /* p_align */ +}; + +static u8 out_shstrtab[] = "\0.text\0.shstrtab"; + +static Elf32_Shdr out_shdr[] = { + { 0 }, + { 1, /* sh_name */ + SHT_PROGBITS, /* sh_type */ + SHF_WRITE|SHF_ALLOC|SHF_EXECINSTR, /* sh_flags */ + DYNAMICALLY_FILLED, /* sh_addr */ + RAW_OFFSET, /* sh_offset */ + DYNAMICALLY_FILLED, /* sh_size */ + 0, /* sh_link */ + 0, /* sh_info */ + 64, /* sh_addralign */ + 0 /* sh_entsize */ + }, + { 7, /* sh_name */ + SHT_STRTAB, /* sh_type */ + 0, /* sh_flags */ + 0, /* sh_addr */ + DYNAMICALLY_FILLED, /* sh_offset */ + sizeof(out_shstrtab), /* sh_size */ + 0, /* sh_link */ + 0, /* sh_info */ + 1, /* sh_addralign */ + 0 /* sh_entsize */ + } +}; + +static void do_write(int fd, void *data, int len) +{ + int done, left = len; + char *p = data; + + while ( left != 0 ) + { + if ( (done = write(fd, p, left)) == -1 ) + { + if ( errno == EINTR ) + continue; + fprintf(stderr, "Error writing output image: %d (%s).\n", + errno, strerror(errno)); + exit(1); + } + + left -= done; + p += done; + } +} + +static void do_read(int fd, void *data, int len) +{ + int done, left = len; + char *p = data; + + while ( left != 0 ) + { + if ( (done = read(fd, p, left)) == -1 ) + { + if ( errno == EINTR ) + continue; + fprintf(stderr, "Error reading input image: %d (%s).\n", + errno, strerror(errno)); + exit(1); + } + + left -= done; + p += done; + } +} + +int main(int argc, char **argv) +{ + u32 loadbase, dat_siz, mem_siz; + char *inimage, *outimage; + int infd, outfd; + char buffer[1024]; + int bytes, todo; + + Elf32_Ehdr in32_ehdr; + Elf32_Phdr in32_phdr; + + Elf64_Ehdr in64_ehdr; + Elf64_Phdr in64_phdr; + + if ( argc != 4 ) + { + fprintf(stderr, "Usage: mkelf32 \n"); + return 1; + } + + inimage = argv[1]; + outimage = argv[2]; + loadbase = strtoul(argv[3], NULL, 16); + + infd = open(inimage, O_RDONLY); + if ( infd == -1 ) + { + fprintf(stderr, "Failed to open input image '%s': %d (%s).\n", + inimage, errno, strerror(errno)); + return 1; + } + + do_read(infd, &in32_ehdr, sizeof(in32_ehdr)); + if ( !IS_ELF(in32_ehdr) || + (in32_ehdr.e_ident[EI_DATA] != ELFDATA2LSB) ) + { + fprintf(stderr, "Input image must be a little-endian Elf image.\n"); + return 1; + } + + switch ( in32_ehdr.e_ident[EI_CLASS] ) + { + case ELFCLASS32: + if ( in32_ehdr.e_phentsize != sizeof(in32_phdr) ) + { + fprintf(stderr, "Bad program header size (%d != %d).\n", + (int)in32_ehdr.e_phentsize, (int)sizeof(in32_phdr)); + return 1; + } + + if ( in32_ehdr.e_phnum != 1 ) + { + fprintf(stderr, "Expect precisly 1 program header; found %d.\n", + (int)in32_ehdr.e_phnum); + return 1; + } + + (void)lseek(infd, in32_ehdr.e_phoff, SEEK_SET); + do_read(infd, &in32_phdr, sizeof(in32_phdr)); + + (void)lseek(infd, in32_phdr.p_offset, SEEK_SET); + dat_siz = (u32)in32_phdr.p_filesz; + mem_siz = (u32)in32_phdr.p_memsz; + break; + + case ELFCLASS64: + (void)lseek(infd, 0, SEEK_SET); + do_read(infd, &in64_ehdr, sizeof(in64_ehdr)); + + if ( in64_ehdr.e_phentsize != sizeof(in64_phdr) ) + { + fprintf(stderr, "Bad program header size (%d != %d).\n", + (int)in64_ehdr.e_phentsize, (int)sizeof(in64_phdr)); + return 1; + } + + if ( in64_ehdr.e_phnum != 1 ) + { + fprintf(stderr, "Expect precisly 1 program header; found %d.\n", + (int)in64_ehdr.e_phnum); + return 1; + } + + (void)lseek(infd, in64_ehdr.e_phoff, SEEK_SET); + do_read(infd, &in64_phdr, sizeof(in64_phdr)); + + (void)lseek(infd, in64_phdr.p_offset, SEEK_SET); + dat_siz = (u32)in64_phdr.p_filesz; + mem_siz = (u32)in64_phdr.p_memsz; + break; + + default: + fprintf(stderr, "Input image must be a 32- or 64-bit Elf image.\n"); + return 1; + } + + out_ehdr.e_entry = loadbase; + out_ehdr.e_shoff = RAW_OFFSET + dat_siz; + + out_phdr.p_vaddr = loadbase; + out_phdr.p_paddr = loadbase; + out_phdr.p_filesz = dat_siz; + out_phdr.p_memsz = mem_siz; + + out_shdr[1].sh_addr = loadbase; + out_shdr[1].sh_size = dat_siz; + out_shdr[2].sh_offset = RAW_OFFSET + dat_siz + sizeof(out_shdr); + + outfd = open(outimage, O_WRONLY|O_CREAT|O_TRUNC, 0775); + if ( outfd == -1 ) + { + fprintf(stderr, "Failed to open output image '%s': %d (%s).\n", + outimage, errno, strerror(errno)); + return 1; + } + + do_write(outfd, &out_ehdr, sizeof(out_ehdr)); + do_write(outfd, &out_phdr, sizeof(out_phdr)); + + if ( (bytes = RAW_OFFSET - sizeof(out_ehdr) - sizeof(out_phdr)) < 0 ) + { + fprintf(stderr, "Header overflow.\n"); + return 1; + } + do_write(outfd, buffer, bytes); + + for ( bytes = 0; bytes < dat_siz; bytes += todo ) + { + todo = ((dat_siz - bytes) > sizeof(buffer)) ? + sizeof(buffer) : (dat_siz - bytes); + do_read(infd, buffer, todo); + do_write(outfd, buffer, todo); + } + + do_write(outfd, &out_shdr[0], sizeof(out_shdr)); + do_write(outfd, out_shstrtab, sizeof(out_shstrtab)); + do_write(outfd, buffer, 4-((sizeof(out_shstrtab)+dat_siz)&3)); + + close(infd); + close(outfd); + + return 0; +} diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index ab5219f64c..a765141910 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -1,10 +1,11 @@ #include #include #include +#include #define SECONDARY_CPU_FLAG 0xA5A5A5A5 - .text + .text .code32 ENTRY(start) @@ -13,11 +14,11 @@ ENTRY(start) .org 0x004 /*** MULTIBOOT HEADER ****/ /* Magic number indicating a Multiboot header. */ - .long 0x1BADB002 - /* Flags to bootloader (see Multiboot spec). */ - .long 0x00000002 - /* Checksum: must be the negated sum of the first two fields. */ - .long -0x1BADB004 + .long 0x1BADB002 + /* Flags to bootloader (see Multiboot spec). */ + .long 0x00000002 + /* Checksum: must be the negated sum of the first two fields. */ + .long -0x1BADB004 .org 0x010 .asciz "Bad CPU: does not support 64-bit (long) mode." @@ -66,38 +67,30 @@ __start: mov $0x20,%ecx # X86_CR4_PAE mov %ecx,%cr4 - cmp $(SECONDARY_CPU_FLAG),%ebx - je start_paging - mov %ebx,0x1001e0 /* Multiboot info struct */ mov %eax,0x1001e4 /* Multiboot magic value */ - /* Initialize mappings of 1GB of memory. */ - mov $0x103000,%edi /* idle_pg_table_l2 */ - mov $0x1e3,%eax /* PRESENT+RW+A+D+PSE+GLOBAL */ - mov $512,%ecx -1: stosl - add $0x200000,%eax - loop 1b - -start_paging: + /* Load pagetable base register. */ mov $0x101000,%eax /* idle_pg_table */ mov %eax,%cr3 + + /* Set up EFER (Extended Feature Enable Register). */ + movl $MSR_EFER, %ecx + rdmsr + /* Long Mode, SYSCALL/SYSRET, No-Execute */ + movl $(EFER_LME|EFER_SCE|EFER_NX),%eax + wrmsr + mov $0x80050033,%eax /* hi-to-lo: PG,AM,WP,NE,ET,MP,PE */ mov %eax,%cr0 jmp 1f + 1: /* Now in compatibility mode. Long-jump into 64-bit mode. */ - ljmp $(__HYPERVISOR_CS64),$0x1000e0 - - .code64 - .org 0x00e0 - - /* Jump to high mappings. */ - mov high_start(%rip),%rax - push %rax - ret -__high_start: + ljmp $(__HYPERVISOR_CS64),$0x100100 + .code64 + .org 0x0100 + /* Install relocated selectors (FS/GS unused). */ lgdt gdt_descr(%rip) mov $(__HYPERVISOR_DS),%ecx @@ -112,9 +105,15 @@ __high_start: mov stack_start(%rip),%rsp /* Reset EFLAGS (subsumes CLI and CLD). */ - pushq $0 - popf + pushq $0 + popf + /* Jump to high mappings. */ + mov high_start(%rip),%rax + push %rax + ret +__high_start: + lidt idt_descr(%rip) cmp $(SECONDARY_CPU_FLAG),%ebx @@ -139,19 +138,15 @@ __high_start: add $8,%rdi loop 1b - xor %rax,%rax mov 0x1001e0,%eax /* Multiboot info struct */ lea start(%rip),%rbx sub $0x100000,%rbx add %rbx,%rax push %rax - xor %rax,%rax mov 0x1001e4,%eax /* Multiboot magic value */ push %rax - /* Call into main C routine. This should never return.*/ - call cmain - ud2 /* Force a panic (invalid opcode). */ + call cmain /* This is the default interrupt handler. */ int_msg: @@ -167,7 +162,9 @@ ignore_int: 1: jmp 1b .code32 - + + .org 0x1e0 + /*** DESCRIPTOR TABLES ***/ .globl SYMBOL_NAME(idt) @@ -192,35 +189,51 @@ ENTRY(gdt_table) .word 0 gdt_descr: - .word (LAST_RESERVED_GDT_ENTRY*8)+7 + .word (LAST_RESERVED_GDT_ENTRY*8)+7 SYMBOL_NAME(gdt): .quad SYMBOL_NAME(gdt_table) .word 0 idt_descr: - .word 256*8-1 + .word 256*8-1 SYMBOL_NAME(idt): - .quad SYMBOL_NAME(idt_table) + .quad SYMBOL_NAME(idt_table) ENTRY(stack_start) - .quad SYMBOL_NAME(cpu0_stack) + 8100 - __PAGE_OFFSET + .quad SYMBOL_NAME(cpu0_stack) + 8100 high_start: .quad __high_start +/* Initial PML4 -- level-4 page table */ .org 0x1000 ENTRY(idle_pg_table) ENTRY(idle_pg_table_4) .quad 0x0000000000102007 # PML4[0] .fill 261,8,0 .quad 0x0000000000102007 # PML4[262] + +/* Initial PDP -- level-3 page table */ .org 0x2000 ENTRY(idle_pg_table_l3) .quad 0x0000000000103007 + +/* Initial PDE -- level-2 page table. */ .org 0x3000 ENTRY(idle_pg_table_l2) + .macro identmap from=0, count=512 + .if \count-1 + identmap "(\from+0)","(\count/2)" + identmap "(\from+(0x200000*(\count/2)))","(\count/2)" + .else + .quad 0x00000000000001e3 + \from + .endif + .endm + identmap /* Too orangey for crows :-) */ + .org 0x4000 ENTRY(cpu0_stack) # Initial stack is 8kB + .org 0x6000 ENTRY(stext) ENTRY(_stext) diff --git a/xen/arch/x86/x86_32/xen.lds b/xen/arch/x86/x86_32/xen.lds index 5947ebada5..bb9f327802 100644 --- a/xen/arch/x86/x86_32/xen.lds +++ b/xen/arch/x86/x86_32/xen.lds @@ -1,9 +1,14 @@ /* ld script to make i386 Linux kernel - * Written by Martin Mares ; + * Written by Martin Mares + * Modifified for i386 Xen by Keir Fraser */ OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") OUTPUT_ARCH(i386) ENTRY(start) +PHDRS +{ + text PT_LOAD ; +} SECTIONS { . = 0xFC400000 + 0x100000; @@ -12,61 +17,61 @@ SECTIONS *(.text) *(.fixup) *(.gnu.warning) - } = 0x9090 - .text.lock : { *(.text.lock) } /* out-of-line lock text */ + } :text =0x9090 + .text.lock : { *(.text.lock) } :text /* out-of-line lock text */ _etext = .; /* End of text section */ - .rodata : { *(.rodata) *(.rodata.*) } - .kstrtab : { *(.kstrtab) } + .rodata : { *(.rodata) *(.rodata.*) } :text + .kstrtab : { *(.kstrtab) } :text . = ALIGN(16); /* Exception table */ __start___ex_table = .; - __ex_table : { *(__ex_table) } + __ex_table : { *(__ex_table) } :text __stop___ex_table = .; __start___ksymtab = .; /* Kernel symbol table */ - __ksymtab : { *(__ksymtab) } + __ksymtab : { *(__ksymtab) } :text __stop___ksymtab = .; __start___kallsyms = .; /* All kernel symbols */ - __kallsyms : { *(__kallsyms) } + __kallsyms : { *(__kallsyms) } :text __stop___kallsyms = .; .data : { /* Data */ *(.data) CONSTRUCTORS - } + } :text _edata = .; /* End of data section */ . = ALIGN(8192); /* init_task */ - .data.init_task : { *(.data.init_task) } + .data.init_task : { *(.data.init_task) } :text . = ALIGN(4096); /* Init code and data */ __init_begin = .; - .text.init : { *(.text.init) } - .data.init : { *(.data.init) } + .text.init : { *(.text.init) } :text + .data.init : { *(.data.init) } :text . = ALIGN(16); __setup_start = .; - .setup.init : { *(.setup.init) } + .setup.init : { *(.setup.init) } :text __setup_end = .; __initcall_start = .; - .initcall.init : { *(.initcall.init) } + .initcall.init : { *(.initcall.init) } :text __initcall_end = .; . = ALIGN(4096); __init_end = .; . = ALIGN(4096); - .data.page_aligned : { *(.data.idt) } + .data.page_aligned : { *(.data.idt) } :text . = ALIGN(32); - .data.cacheline_aligned : { *(.data.cacheline_aligned) } + .data.cacheline_aligned : { *(.data.cacheline_aligned) } :text __bss_start = .; /* BSS */ .bss : { *(.bss) - } + } :text _end = . ; /* Sections to be discarded */ diff --git a/xen/arch/x86/x86_64/xen.lds b/xen/arch/x86/x86_64/xen.lds index d189a27e03..cdf1a6168e 100644 --- a/xen/arch/x86/x86_64/xen.lds +++ b/xen/arch/x86/x86_64/xen.lds @@ -1,7 +1,12 @@ /* Excerpts written by Martin Mares */ +/* Modified for x86-64 Xen by Keir Fraser */ OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") OUTPUT_ARCH(i386:x86-64) ENTRY(start) +PHDRS +{ + text PT_LOAD ; +} SECTIONS { . = 0xFFFF830000100000; @@ -10,61 +15,61 @@ SECTIONS *(.text) *(.fixup) *(.gnu.warning) - } = 0x9090 - .text.lock : { *(.text.lock) } /* out-of-line lock text */ + } :text = 0x9090 + .text.lock : { *(.text.lock) } :text /* out-of-line lock text */ _etext = .; /* End of text section */ - .rodata : { *(.rodata) *(.rodata.*) } - .kstrtab : { *(.kstrtab) } + .rodata : { *(.rodata) *(.rodata.*) } :text + .kstrtab : { *(.kstrtab) } :text . = ALIGN(16); /* Exception table */ __start___ex_table = .; - __ex_table : { *(__ex_table) } + __ex_table : { *(__ex_table) } :text __stop___ex_table = .; __start___ksymtab = .; /* Kernel symbol table */ - __ksymtab : { *(__ksymtab) } + __ksymtab : { *(__ksymtab) } :text __stop___ksymtab = .; __start___kallsyms = .; /* All kernel symbols */ - __kallsyms : { *(__kallsyms) } + __kallsyms : { *(__kallsyms) } :text __stop___kallsyms = .; .data : { /* Data */ *(.data) CONSTRUCTORS - } + } :text _edata = .; /* End of data section */ . = ALIGN(8192); /* init_task */ - .data.init_task : { *(.data.init_task) } + .data.init_task : { *(.data.init_task) } :text . = ALIGN(4096); /* Init code and data */ __init_begin = .; - .text.init : { *(.text.init) } - .data.init : { *(.data.init) } + .text.init : { *(.text.init) } :text + .data.init : { *(.data.init) } :text . = ALIGN(16); __setup_start = .; - .setup.init : { *(.setup.init) } + .setup.init : { *(.setup.init) } :text __setup_end = .; __initcall_start = .; - .initcall.init : { *(.initcall.init) } + .initcall.init : { *(.initcall.init) } :text __initcall_end = .; . = ALIGN(4096); __init_end = .; . = ALIGN(4096); - .data.page_aligned : { *(.data.idt) } + .data.page_aligned : { *(.data.idt) } :text . = ALIGN(32); - .data.cacheline_aligned : { *(.data.cacheline_aligned) } + .data.cacheline_aligned : { *(.data.cacheline_aligned) } :text __bss_start = .; /* BSS */ .bss : { *(.bss) - } + } :text _end = . ; /* Sections to be discarded */ diff --git a/xen/tools/figlet/LICENSE b/xen/figlet/LICENSE similarity index 100% rename from xen/tools/figlet/LICENSE rename to xen/figlet/LICENSE diff --git a/xen/tools/figlet/Makefile b/xen/figlet/Makefile similarity index 100% rename from xen/tools/figlet/Makefile rename to xen/figlet/Makefile diff --git a/xen/tools/figlet/README b/xen/figlet/README similarity index 100% rename from xen/tools/figlet/README rename to xen/figlet/README diff --git a/xen/tools/figlet/figlet.c b/xen/figlet/figlet.c similarity index 100% rename from xen/tools/figlet/figlet.c rename to xen/figlet/figlet.c diff --git a/xen/tools/figlet/xen.flf b/xen/figlet/xen.flf similarity index 100% rename from xen/tools/figlet/xen.flf rename to xen/figlet/xen.flf diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h index b66ccd2ff7..a412963fd9 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -71,8 +71,8 @@ #define _EFER_NX 11 /* No execute enable */ #define EFER_SCE (1<<_EFER_SCE) -#define EFER_LME (1< - * - * Relocates from address to address by - * frobbing the Elf headers. Segment contents are unmodified. - */ - -#include -#include -#include - -typedef unsigned long Elf32_Addr; -typedef unsigned short Elf32_Half; -typedef unsigned long Elf32_Off; -typedef unsigned long Elf32_Word; - -typedef struct { - unsigned char e_ident[16]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; - -typedef struct { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - -#define offsetof(_f,_p) ((unsigned long)&(((_p *)0)->_f)) - - -/* Add @reloc_distance to address at offset @off in file @fp. */ -void reloc(FILE *fp, long off, unsigned long reloc_distance) -{ - unsigned long base; - fseek(fp, off, SEEK_SET); - fread(&base, sizeof(base), 1, fp); - base += reloc_distance; - fseek(fp, off, SEEK_SET); - fwrite(&base, sizeof(base), 1, fp); - -} - - -int main(int argc, char **argv) -{ - unsigned long old_base, new_base, reloc_distance; - long virt_section, phys_section; - char *image_name; - FILE *fp; - Elf32_Off phoff; - Elf32_Half phnum, phentsz; - int i; - - if ( argc != 4 ) - { - fprintf(stderr, "Usage: elf-reloc \n"); - return(1); - } - - old_base = strtoul(argv[1], NULL, 16); - new_base = strtoul(argv[2], NULL, 16); - image_name = argv[3]; - - fp = fopen(image_name, "rb+"); - if ( !fp ) - { - fprintf(stderr, "Failed to load image!\n"); - return(1); - } - - reloc_distance = new_base - old_base; - - /* First frob the entry address. */ - reloc(fp, offsetof(e_entry, Elf32_Ehdr), reloc_distance); - - fseek(fp, offsetof(e_phoff, Elf32_Ehdr), SEEK_SET); - fread(&phoff, sizeof(phoff), 1, fp); - fseek(fp, offsetof(e_phnum, Elf32_Ehdr), SEEK_SET); - fread(&phnum, sizeof(phnum), 1, fp); - fseek(fp, offsetof(e_phentsize, Elf32_Ehdr), SEEK_SET); - fread(&phentsz, sizeof(phentsz), 1, fp); - - virt_section = (long)phoff + offsetof(p_vaddr, Elf32_Phdr); - phys_section = (long)phoff + offsetof(p_paddr, Elf32_Phdr); - for ( i = 0; i < phnum; i++ ) - { - reloc(fp, phys_section, reloc_distance); - reloc(fp, virt_section, reloc_distance); - phys_section += phentsz; - virt_section += phentsz; - } - - fclose(fp); - - return(0); -}