Skip to content

Commit

Permalink
ch2: add x86_64 support
Browse files Browse the repository at this point in the history
Files are modified from Mini-OS.
  • Loading branch information
koukaipan committed Aug 25, 2013
1 parent 6d55feb commit 6986255
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 1 deletion.
8 changes: 7 additions & 1 deletion chapter2/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
XEN_SRC = ../../src/xen-4.2.1

#ARCH dependent
XEN_TARGET_ARCH = x86_32
XEN_TARGET_ARCH = x86_64
ifeq ($(XEN_TARGET_ARCH),x86_32)
ARCH_CFLAGS := -m32 -march=i686
ARCH_LDFLAGS := -m elf_i386 -T x86_32.lds
ARCH_ASFLAGS := -m32
ARCH_OBJS := bootstrap.x86_32.o
endif
ifeq ($(XEN_TARGET_ARCH),x86_64)
ARCH_CFLAGS := -m64
ARCH_ASFLAGS := -m64
ARCH_LDFLAGS := -m elf_x86_64 -T x86_64.lds
ARCH_OBJS := bootstrap.x86_64.o
endif

CPPFLAGS += -I$(XEN_SRC)/xen/include/public $(ARCH_CPPFLAGS)
LDFLAGS += -nostdlib $(ARCH_LDFLAGS)
Expand Down
34 changes: 34 additions & 0 deletions chapter2/bootstrap.x86_64.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <arch-x86_64.h>

.section __xen_guest
.ascii "GUEST_OS=Mini-OS"
.ascii ",XEN_VER=xen-3.0"
.ascii ",VIRT_BASE=0x0" /* &_text from minios_x86_64.lds */
.ascii ",ELF_PADDR_OFFSET=0x0"
.ascii ",HYPERCALL_PAGE=0x2"
.ascii ",LOADER=generic"
.byte 0
.text

#define ENTRY(X) .globl X ; X :
.globl _start, shared_info, hypercall_page


_start:
cld
movq stack_start(%rip),%rsp
andq $(~(8192-1)), %rsp
movq %rsi,%rdi
call start_kernel

stack_start:
.quad stack+(2*8192)

/* Unpleasant -- the PTE that maps this page is actually overwritten */
/* to map the real shared-info page! :-) */
.org 0x1000
shared_info:
.org 0x2000

hypercall_page:
.org 0x3000
27 changes: 27 additions & 0 deletions chapter2/hypercall-x86_64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef __HYPERCALL_X86_64_H__
#define __HYPERCALL_X86_64_H__

#include <xen.h>

#define __STR(x) #x
#define STR(x) __STR(x)

#define _hypercall3(type, name, a1, a2, a3) \
({ \
long __res, __ign1, __ign2, __ign3; \
__asm__ volatile ( \
"call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
: "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
"=d" (__ign3) \
: "1" ((long)(a1)), "2" ((long)(a2)), \
"3" ((long)(a3)) \
: "memory" ); \
(type)__res; \
})

static inline int HYPERVISOR_console_io(int cmd, int count, char *str)
{
return _hypercall3(int, console_io, cmd, count, str);
}

#endif
2 changes: 2 additions & 0 deletions chapter2/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#if defined (__i686__)
#include "hypercall-x86_32.h"
#elif defined (__x86_64__)
#include "hypercall-x86_64.h"
#else
#error "Unsupported architecture"
#endif
Expand Down
74 changes: 74 additions & 0 deletions chapter2/x86_64.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SECTIONS
{
. = 0x0;
_text = .; /* Text and read-only data */
.text : {
*(.text)
*(.gnu.warning)
} = 0x9090

_etext = .; /* End of text section */

.rodata : { *(.rodata) *(.rodata.*) }
. = ALIGN(4096);
_erodata = .;

/* newlib initialization functions */
. = ALIGN(64 / 8);
PROVIDE (__preinit_array_start = .);
.preinit_array : { *(.preinit_array) }
PROVIDE (__preinit_array_end = .);
PROVIDE (__init_array_start = .);
.init_array : { *(.init_array) }
PROVIDE (__init_array_end = .);
PROVIDE (__fini_array_start = .);
.fini_array : { *(.fini_array) }
PROVIDE (__fini_array_end = .);

.ctors : {
__CTOR_LIST__ = .;
*(.ctors)
CONSTRUCTORS
QUAD(0)
__CTOR_END__ = .;
}

.dtors : {
__DTOR_LIST__ = .;
*(.dtors)
QUAD(0)
__DTOR_END__ = .;
}

.data : { /* Data */
*(.data)
}

_edata = .; /* End of data section */

__bss_start = .; /* BSS */
.bss : {
*(.bss)
*(.app.bss)
}
_end = . ;

/* Sections to be discarded */
/DISCARD/ : {
*(.text.exit)
*(.data.exit)
*(.exitcall.exit)
}

/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
}

0 comments on commit 6986255

Please sign in to comment.