読者です 読者をやめる 読者になる 読者になる

BHyVeビルドめも8

DragonFlyBSD BHyVe

( ..)φカキカキ
vmx.cのこの行のコンパイルエラーを取るために色々調べたことはメモっとかないと100%忘れそうなのでw

error = vmwrite(VMCS_HOST_TR_BASE, (u_long)PCPU_GET(tssp)); 

コンパイルエラーはこれ

/usr/src/sys/platform/pc64/vmm/intel/vmx.c:802: error: implicit declaration of function ‘PCPU_GET’
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:802: error: nested extern declaration of ‘PCPU_GET’
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:802: error: ‘tssp’ undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:802: error: (Each undeclared identifier is reported only once
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:802: error: for each function it appears in.)

PCPU_GETはマクロでstruct pcpuにあるメンバ変数”pc_tssp”にアクセスするためのもの。 これはFreeBSDだとamd64/include/pcpu.hでこんな感じで定義されてて、このPCPU_MD_FIELDSがsys/pcpu.hのstruct pcpuの定義内で使われてます。

#define PCPU_MD_FIELDS                                                  \\
        char    pc_monitorbuf[128] __aligned(128); /* cache line */     \\
        struct  pcpu *pc_prvspace;      /* Self-reference */            \\
        struct  pmap *pc_curpmap;                                       \\
        struct  amd64tss *pc_tssp;      /* TSS segment active on CPU */ \\
        struct  amd64tss *pc_commontssp;/* Common TSS for the CPU */    \\
        register_t pc_rsp0;                                             \\
        register_t pc_scratch_rsp;      /* User %rsp in syscall */      \\
        u_int   pc_apic_id;                                             \\
        u_int   pc_acpi_id;             /* ACPI CPU id */               \\
        /* Pointer to the CPU %fs descriptor */                         \\
        struct user_segment_descriptor  *pc_fs32p;                      \\
        /* Pointer to the CPU %gs descriptor */                         \\
        struct user_segment_descriptor  *pc_gs32p;                      \\
        /* Pointer to the CPU LDT descriptor */                         \\
        struct system_segment_descriptor *pc_ldt;                       \\
        /* Pointer to the CPU TSS descriptor */                         \\
        struct system_segment_descriptor *pc_tss;                       \\
        u_int   pc_cmci_mask            /* MCx banks for CMCI */        \\
        PCPU_XEN_FIELDS

なので、DragonFlyでコンパイルするためにはstruct pcpuに該当するものと、pc_tsspの型”struct amd64tss”に該当するものを探さないとだめ。
そして探したところ、platform/pc64/include/globaldata.hにあるstruct mdglobaldataじゃないかとなり、
そのなかのメンバ変数gd_common_tssが当りが怪しい感じ!これの型はstruct x86_64tssだし、これっぽいかなーと。
そうするとvmwrite()のほうも多分これに合わせて修正は必要ですね。
呼び出しするときはlongにキャストしているけど、関数内でどう使ってるかはまだ見てないですが。
さて、このmdglobaldataにアクセスする方法も必要ですねぇ。
ということで探すとこんな感じでアクセスできるのでこれに必要なヘッダは何かというとこれまたglobaldata.hでした。

struct mdglobaldata *gd = mdcpu;

こんなマクロでした。

#define mdcpu           ((struct mdglobaldata *)_get_mycpu())

これでコンパイルすると…

--------------------------------------------------------------
>>> Kernel build for BHYVE started on Wed Jul  4 21:51:03 JST 2012
--------------------------------------------------------------
===> BHYVE
cd /usr/src/sys/config;  PATH=/usr/obj/usr/src/ctools_x86_64_x86_64/usr/sbin:/usr/obj/usr/src/ctools_x86_64_x86_64/usr/bin:/usr/obj/usr/src/ctools_x86_64_x86_64/bin:/usr/obj/usr/src/ctools_x86_64_x86_64/usr/games:/usr/obj/usr/src/btools_x86_64/usr/sbin:/usr/obj/usr/src/btools_x86_64/usr/bin:/usr/obj/usr/src/btools_x86_64/bin:/usr/obj/usr/src/btools_x86_64/usr/games:/usr/pkg/bin  config  -d /usr/obj/usr/src/sys/BHYVE  /usr/src/sys/config/BHYVE
Kernel build directory is /usr/obj/usr/src/sys/BHYVE
cd /usr/obj/usr/src/sys/BHYVE;  MAKEOBJDIRPREFIX=/usr/obj/usr/src/world_x86_64  OBJTREE=/usr/obj  MACHINE_ARCH=x86_64  MACHINE=x86_64  MACHINE_PLATFORM=pc64  OBJFORMAT_PATH=/usr/obj/usr/src/ctools_x86_64_x86_64  HOST_CCVER=gcc44  CCVER=gcc44  BINUTILSVER=binutils221  DESTDIR=/usr/obj/usr/src/world_x86_64  INSTALL="sh /usr/src/tools/install.sh"  PATH=/usr/obj/usr/src/ctools_x86_64_x86_64/usr/sbin:/usr/obj/usr/src/ctools_x86_64_x86_64/usr/bin:/usr/obj/usr/src/ctools_x86_64_x86_64/bin:/usr/obj/usr/src/ctools_x86_64_x86_64/usr/games:/usr/obj/usr/src/btools_x86_64/usr/sbin:/usr/obj/usr/src/btools_x86_64/usr/bin:/usr/obj/usr/src/btools_x86_64/bin:/usr/obj/usr/src/btools_x86_64/usr/games:/usr/pkg/bin make KERNEL=kernel all
cc -c -O -pipe  -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual  -Wold-style-definition -std=c99 -Wold-style-declaration -g -nostdinc -I. -Iinclude -I/usr/src/sys -I/usr/src/sys/../include -I/usr/obj/usr/src/sys/BHYVE -I"/usr/src/sys/dev/acpica5" -I"/usr/src/sys/contrib/dev/acpica-unix/include" -I/usr/src/sys/dev/netif/ath/hal -I/usr/src/sys/dev/netif/ath/hal/ath_hal  -D_KERNEL -include opt_global.h  -finline-limit=8000 --param inline-unit-growth=100 --param large-function-growth=1000 -fno-common -ffreestanding -mpreferred-stack-boundary=4 -fno-stack-protector -mcmodel=kernel -mno-red-zone -mfpmath=387 -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4 -mno-sse4a  -mno-sse5 -mno-abm -mno-aes -mno-avx -mno-pclmul -mno-popcnt -msoft-float -fno-asynchronous-unwind-tables -fno-omit-frame-pointer  /usr/src/sys/platform/pc64/vmm/intel/vmx.c -Werror
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:120: error: array type has incomplete element type
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:159: error: 'SI_SUB_KLD' undeclared here (not in a function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c: In function 'vmx_set_pcpu_defaults':
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:804: error: aggregate value used where an integer was expected
cc1: warnings being treated as errors
/usr/src/sys/platform/pc64/vmm/intel/vmx.c: In function 'vmx_inject_nmi':
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:931: error: implicit declaration of function 'CTR3'
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:931: error: nested extern declaration of 'CTR3'
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:931: error: 'KTR_GEN' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:931: error: (Each undeclared identifier is reported only once
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:931: error: for each function it appears in.)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:931: error: 'curcpu' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c: In function 'vmx_inject_interrupts':
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1010: error: implicit declaration of function 'CTR4'
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1010: error: nested extern declaration of 'CTR4'
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1010: error: 'KTR_GEN' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1010: error: 'curcpu' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c: In function 'vmx_exit_process':
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1155: error: 'KTR_GEN' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1155: error: 'curcpu' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c: In function 'vmx_run':
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1314: error: 'TDF_ASTPENDING' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1317: error: implicit declaration of function 'enable_intr'
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1317: error: nested extern declaration of 'enable_intr'
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1341: error: 'KTR_GEN' undeclared (first use in this function)
/usr/src/sys/platform/pc64/vmm/intel/vmx.c:1341: error: 'curcpu' undeclared (first use in this function)
*** Error code 1

Stop in /usr/obj/usr/src/sys/BHYVE.
*** Error code 1

Stop in /usr/src.
*** Error code 1

Stop in /usr/src.

PCPU_GETのところのコンパイルエラー解決キタ━(゜∀゜)━!