1# SPDX-License-Identifier: Apache-2.0
2# Copyright (c) 2019 Intel Corp.
3
4set(SUPPORTED_EMU_PLATFORMS qemu)
5
6if(NOT CONFIG_REBOOT)
7  set(REBOOT_FLAG -no-reboot)
8endif()
9
10if(CONFIG_X86_64)
11  set(QEMU_binary_suffix x86_64)
12  set(QEMU_CPU_TYPE_${ARCH} qemu64,+x2apic)
13  if("${CONFIG_MP_MAX_NUM_CPUS}" STREQUAL "1")
14    # icount works with 1 CPU so we can enable it here.
15    # FIXME: once this works across configs, remove this line and set
16    # CONFIG_QEMU_ICOUNT_SHIFT in defconfig instead.
17    list(APPEND QEMU_EXTRA_FLAGS -icount shift=5,align=off,sleep=off -rtc clock=vm)
18  endif()
19else()
20  set(QEMU_CPU_TYPE_${ARCH} qemu32,+nx,+pae)
21endif()
22
23if(CONFIG_XIP)
24  # Extra 4MB to emulate flash area
25  math(EXPR QEMU_MEMORY_SIZE_MB "${CONFIG_SRAM_SIZE} / 1024 + 4")
26elseif(CONFIG_BOARD_QEMU_X86_TINY AND CONFIG_DEMAND_PAGING
27       AND NOT CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT)
28  # Flash is at 4MB-8MB, so need this to be large enough
29  math(EXPR QEMU_MEMORY_SIZE_MB "8")
30else()
31  math(EXPR QEMU_MEMORY_SIZE_MB "${CONFIG_SRAM_SIZE} / 1024")
32endif()
33
34set(QEMU_CPU_FLAGS "")
35if(CONFIG_X86_MMX)
36  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "mmx")
37  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "mmxext")
38endif()
39if(CONFIG_X86_SSE)
40  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "sse")
41endif()
42if(CONFIG_X86_SSE2)
43  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "sse2")
44endif()
45if(CONFIG_X86_SSE3)
46  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "pni")
47endif()
48if(CONFIG_X86_SSSE3)
49  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "ssse3")
50endif()
51if(CONFIG_X86_SSE41)
52  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "sse4.1")
53endif()
54if(CONFIG_X86_SSE42)
55  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "sse4.2")
56endif()
57if(CONFIG_X86_SSE4A)
58  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "sse4a")
59endif()
60if(NOT CONFIG_X86_64 AND CONFIG_CACHE_MANAGEMENT)
61  string(JOIN "," QEMU_CPU_FLAGS "${QEMU_CPU_FLAGS}" "clflush")
62endif()
63
64set(QEMU_FLAGS_${ARCH}
65  -m ${QEMU_MEMORY_SIZE_MB}
66  -cpu ${QEMU_CPU_TYPE_${ARCH}}${QEMU_CPU_FLAGS}
67  -machine q35
68  -device isa-debug-exit,iobase=0xf4,iosize=0x04
69  ${REBOOT_FLAG}
70  -nographic
71  )
72
73if(NOT CONFIG_ACPI)
74  list(APPEND QEMU_FLAGS_${ARCH} -machine acpi=off)
75endif()
76
77# TODO: Support debug
78# board_set_debugger_ifnset(qemu)
79# debugserver: QEMU_EXTRA_FLAGS += -s -S
80# debugserver: qemu
81
82if(CONFIG_BOARD_QEMU_X86_TINY AND CONFIG_DEMAND_PAGING
83   AND NOT CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT)
84  # This is to map the flash so it is accessible.
85  math(EXPR QEMU_FLASH_SIZE_KB "${CONFIG_FLASH_SIZE} * 1024")
86  set(X86_EXTRA_GEN_MMU_ARGUMENTS
87      --map ${CONFIG_FLASH_BASE_ADDRESS},${QEMU_FLASH_SIZE_KB},W)
88endif()
89