2019-04-06 15:08:09 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
if("${ARCH}" STREQUAL "x86")
|
|
|
|
set_ifndef(QEMU_binary_suffix i386)
|
2020-12-02 23:33:36 +01:00
|
|
|
elseif("${ARCH}" STREQUAL "mips")
|
|
|
|
if(CONFIG_BIG_ENDIAN)
|
|
|
|
set_ifndef(QEMU_binary_suffix mips)
|
|
|
|
else()
|
|
|
|
set_ifndef(QEMU_binary_suffix mipsel)
|
|
|
|
endif()
|
2019-07-31 23:21:58 +02:00
|
|
|
elseif(DEFINED QEMU_ARCH)
|
|
|
|
set_ifndef(QEMU_binary_suffix ${QEMU_ARCH})
|
2017-12-21 22:45:45 +01:00
|
|
|
else()
|
|
|
|
set_ifndef(QEMU_binary_suffix ${ARCH})
|
|
|
|
endif()
|
2018-08-21 17:25:52 +02:00
|
|
|
|
|
|
|
set(qemu_alternate_path $ENV{QEMU_BIN_PATH})
|
|
|
|
if(qemu_alternate_path)
|
|
|
|
find_program(
|
|
|
|
QEMU
|
|
|
|
PATHS ${qemu_alternate_path}
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
NAMES qemu-system-${QEMU_binary_suffix}
|
|
|
|
)
|
|
|
|
else()
|
2017-12-21 22:45:45 +01:00
|
|
|
find_program(
|
|
|
|
QEMU
|
|
|
|
qemu-system-${QEMU_binary_suffix}
|
|
|
|
)
|
2018-08-21 17:25:52 +02:00
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
|
2021-07-28 18:15:24 +02:00
|
|
|
# We need to set up uefi-run and OVMF environment
|
|
|
|
# for testing UEFI method on qemu platforms
|
|
|
|
if(CONFIG_QEMU_UEFI_BOOT)
|
|
|
|
find_program(UEFI NAMES uefi-run REQUIRED)
|
|
|
|
if(DEFINED ENV{OVMF_FD_PATH})
|
|
|
|
set(OVMF_FD_PATH $ENV{OVMF_FD_PATH})
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Couldn't find an valid OVMF_FD_PATH.")
|
|
|
|
endif()
|
|
|
|
list(APPEND UEFI -b ${OVMF_FD_PATH} -q ${QEMU})
|
|
|
|
set(QEMU ${UEFI})
|
|
|
|
endif()
|
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
set(qemu_targets
|
2021-08-30 13:09:48 +02:00
|
|
|
run_qemu
|
|
|
|
debugserver_qemu
|
2017-12-21 22:45:45 +01:00
|
|
|
)
|
|
|
|
|
2017-12-30 14:36:39 +01:00
|
|
|
set(QEMU_FLAGS -pidfile)
|
|
|
|
if(${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
|
|
|
|
list(APPEND QEMU_FLAGS qemu\${QEMU_INSTANCE}.pid)
|
|
|
|
else()
|
|
|
|
list(APPEND QEMU_FLAGS qemu${QEMU_INSTANCE}.pid)
|
|
|
|
endif()
|
|
|
|
|
2022-10-06 16:42:24 +02:00
|
|
|
# If running with sysbuild, we need to ensure this variable is populated
|
|
|
|
zephyr_get(QEMU_PIPE)
|
2020-01-02 07:09:42 +01:00
|
|
|
# Set up chardev for console.
|
2017-12-21 22:45:45 +01:00
|
|
|
if(QEMU_PTY)
|
2020-01-02 07:09:42 +01:00
|
|
|
# Redirect console to a pseudo-tty, used for running automated tests.
|
|
|
|
list(APPEND QEMU_FLAGS -chardev pty,id=con,mux=on)
|
|
|
|
elseif(QEMU_PIPE)
|
|
|
|
# Redirect console to a pipe, used for running automated tests.
|
|
|
|
list(APPEND QEMU_FLAGS -chardev pipe,id=con,mux=on,path=${QEMU_PIPE})
|
2023-03-15 18:16:42 +01:00
|
|
|
# Create the pipe file before passing the path to QEMU.
|
|
|
|
foreach(target ${qemu_targets})
|
|
|
|
list(APPEND PRE_QEMU_COMMANDS_FOR_${target} COMMAND ${CMAKE_COMMAND} -E touch ${QEMU_PIPE})
|
|
|
|
endforeach()
|
2017-12-21 22:45:45 +01:00
|
|
|
else()
|
2020-01-02 07:09:42 +01:00
|
|
|
# Redirect console to stdio, used for manual debugging.
|
|
|
|
list(APPEND QEMU_FLAGS -chardev stdio,id=con,mux=on)
|
2017-12-21 22:45:45 +01:00
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2020-01-02 07:09:42 +01:00
|
|
|
# Connect main serial port to the console chardev.
|
|
|
|
list(APPEND QEMU_FLAGS -serial chardev:con)
|
|
|
|
|
2020-01-02 05:32:16 +01:00
|
|
|
# Connect semihosting console to the console chardev if configured.
|
2022-03-30 09:51:54 +02:00
|
|
|
if(CONFIG_SEMIHOST)
|
2020-01-02 05:32:16 +01:00
|
|
|
list(APPEND QEMU_FLAGS
|
|
|
|
-semihosting-config enable=on,target=auto,chardev=con
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-01-02 07:09:42 +01:00
|
|
|
# Connect monitor to the console chardev.
|
|
|
|
list(APPEND QEMU_FLAGS -mon chardev=con,mode=readline)
|
2017-11-24 16:13:15 +01:00
|
|
|
|
2020-05-19 21:24:25 +02:00
|
|
|
if(CONFIG_QEMU_ICOUNT)
|
2021-10-15 11:45:11 +02:00
|
|
|
if(CONFIG_QEMU_ICOUNT_SLEEP)
|
|
|
|
list(APPEND QEMU_FLAGS
|
|
|
|
-icount shift=${CONFIG_QEMU_ICOUNT_SHIFT},align=off,sleep=on
|
|
|
|
-rtc clock=vm)
|
|
|
|
else()
|
|
|
|
list(APPEND QEMU_FLAGS
|
2020-05-19 21:24:25 +02:00
|
|
|
-icount shift=${CONFIG_QEMU_ICOUNT_SHIFT},align=off,sleep=off
|
|
|
|
-rtc clock=vm)
|
2021-10-15 11:45:11 +02:00
|
|
|
endif()
|
2020-05-19 21:24:25 +02:00
|
|
|
endif()
|
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
# Add a BT serial device when building for bluetooth, unless the
|
|
|
|
# application explicitly opts out with NO_QEMU_SERIAL_BT_SERVER.
|
|
|
|
if(CONFIG_BT)
|
2019-06-24 11:46:48 +02:00
|
|
|
if(CONFIG_BT_NO_DRIVER)
|
|
|
|
set(NO_QEMU_SERIAL_BT_SERVER 1)
|
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
if(NOT NO_QEMU_SERIAL_BT_SERVER)
|
|
|
|
list(APPEND QEMU_FLAGS -serial unix:/tmp/bt-server-bredr)
|
2017-11-08 17:35:14 +01:00
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
endif()
|
2017-11-08 17:35:14 +01:00
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
# If we are running a networking application in QEMU, then set proper
|
|
|
|
# QEMU variables. This also allows two QEMUs to be hooked together and
|
|
|
|
# pass data between them. The QEMU flags are not set for standalone
|
2019-03-26 16:29:12 +01:00
|
|
|
# tests defined by CONFIG_NET_TEST. For PPP, the serial port file is
|
|
|
|
# not available if we run unit tests which define CONFIG_NET_TEST.
|
2017-12-21 22:45:45 +01:00
|
|
|
if(CONFIG_NETWORKING)
|
2018-10-16 13:27:21 +02:00
|
|
|
if(CONFIG_NET_QEMU_SLIP)
|
2019-01-07 13:04:06 +01:00
|
|
|
if((CONFIG_NET_SLIP_TAP) OR (CONFIG_IEEE802154_UPIPE))
|
2018-10-16 13:27:21 +02:00
|
|
|
set(QEMU_NET_STACK 1)
|
|
|
|
endif()
|
2019-03-26 16:29:12 +01:00
|
|
|
elseif((CONFIG_NET_QEMU_PPP) AND NOT (CONFIG_NET_TEST))
|
|
|
|
set(QEMU_NET_STACK 1)
|
2017-11-10 10:10:15 +01:00
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
endif()
|
2017-11-10 10:10:15 +01:00
|
|
|
|
2018-02-14 14:17:56 +01:00
|
|
|
# TO create independent pipes for each QEMU application set QEMU_PIPE_STACK
|
|
|
|
if(QEMU_PIPE_STACK)
|
|
|
|
list(APPEND qemu_targets
|
|
|
|
node
|
|
|
|
)
|
|
|
|
|
|
|
|
if(NOT QEMU_PIPE_ID)
|
|
|
|
set(QEMU_PIPE_ID 1)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND QEMU_FLAGS
|
|
|
|
-serial none
|
|
|
|
)
|
|
|
|
|
|
|
|
list(APPEND MORE_FLAGS_FOR_node
|
|
|
|
-serial pipe:/tmp/hub/ip-stack-node${QEMU_PIPE_ID}
|
|
|
|
-pidfile qemu-node${QEMU_PIPE_ID}.pid
|
|
|
|
)
|
|
|
|
|
|
|
|
set(PIPE_NODE_IN /tmp/hub/ip-stack-node${QEMU_PIPE_ID}.in)
|
|
|
|
set(PIPE_NODE_OUT /tmp/hub/ip-stack-node${QEMU_PIPE_ID}.out)
|
|
|
|
|
|
|
|
set(pipes
|
|
|
|
${PIPE_NODE_IN}
|
|
|
|
${PIPE_NODE_OUT}
|
|
|
|
)
|
|
|
|
|
|
|
|
set(destroy_pipe_commands
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove -f ${pipes}
|
|
|
|
)
|
|
|
|
|
|
|
|
set(create_pipe_commands
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory /tmp/hub
|
|
|
|
COMMAND mkfifo ${PIPE_NODE_IN}
|
|
|
|
COMMAND mkfifo ${PIPE_NODE_OUT}
|
|
|
|
)
|
|
|
|
|
|
|
|
set(PRE_QEMU_COMMANDS_FOR_node
|
|
|
|
${destroy_pipe_commands}
|
|
|
|
${create_pipe_commands}
|
|
|
|
)
|
|
|
|
|
|
|
|
elseif(QEMU_NET_STACK)
|
2017-12-21 22:45:45 +01:00
|
|
|
list(APPEND qemu_targets
|
|
|
|
client
|
|
|
|
server
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
foreach(target ${qemu_targets})
|
|
|
|
if((${target} STREQUAL client) OR (${target} STREQUAL server))
|
|
|
|
list(APPEND MORE_FLAGS_FOR_${target}
|
|
|
|
-serial pipe:/tmp/ip-stack-${target}
|
|
|
|
-pidfile qemu-${target}.pid
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
|
|
|
else()
|
2017-12-21 22:45:45 +01:00
|
|
|
# QEMU_INSTANCE is a command line argument to *make* (not cmake). By
|
|
|
|
# appending the instance name to the pid file we can easily run more
|
|
|
|
# instances of the same sample.
|
2017-12-30 14:36:39 +01:00
|
|
|
|
2019-03-26 16:29:12 +01:00
|
|
|
if(CONFIG_NET_QEMU_PPP)
|
|
|
|
if(${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
|
|
|
|
set(ppp_path unix:/tmp/ppp\${QEMU_INSTANCE})
|
|
|
|
else()
|
|
|
|
set(ppp_path unix:/tmp/ppp${QEMU_INSTANCE})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND MORE_FLAGS_FOR_${target}
|
|
|
|
-serial ${ppp_path}
|
|
|
|
)
|
2017-12-30 14:36:39 +01:00
|
|
|
else()
|
2019-03-26 16:29:12 +01:00
|
|
|
if(${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
|
|
|
|
set(tmp_file unix:/tmp/slip.sock\${QEMU_INSTANCE})
|
|
|
|
else()
|
|
|
|
set(tmp_file unix:/tmp/slip.sock${QEMU_INSTANCE})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND MORE_FLAGS_FOR_${target}
|
|
|
|
-serial ${tmp_file}
|
|
|
|
)
|
2017-12-30 14:36:39 +01:00
|
|
|
endif()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
|
|
set(PIPE_SERVER_IN /tmp/ip-stack-server.in)
|
|
|
|
set(PIPE_SERVER_OUT /tmp/ip-stack-server.out)
|
|
|
|
set(PIPE_CLIENT_IN /tmp/ip-stack-client.in)
|
|
|
|
set(PIPE_CLIENT_OUT /tmp/ip-stack-client.out)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
set(pipes
|
|
|
|
${PIPE_SERVER_IN}
|
|
|
|
${PIPE_SERVER_OUT}
|
|
|
|
${PIPE_CLIENT_IN}
|
|
|
|
${PIPE_CLIENT_OUT}
|
|
|
|
)
|
|
|
|
|
|
|
|
set(destroy_pipe_commands
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove -f ${pipes}
|
|
|
|
)
|
|
|
|
|
|
|
|
# TODO: Port to Windows. Perhaps using python? Or removing the
|
|
|
|
# need for mkfifo and create_symlink somehow.
|
|
|
|
set(create_pipe_commands
|
|
|
|
COMMAND mkfifo ${PIPE_SERVER_IN}
|
|
|
|
COMMAND mkfifo ${PIPE_SERVER_OUT}
|
|
|
|
)
|
|
|
|
if(PCAP)
|
|
|
|
list(APPEND create_pipe_commands
|
|
|
|
COMMAND mkfifo ${PIPE_CLIENT_IN}
|
|
|
|
COMMAND mkfifo ${PIPE_CLIENT_OUT}
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
2017-12-21 22:45:45 +01:00
|
|
|
else()
|
|
|
|
list(APPEND create_pipe_commands
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E create_symlink ${PIPE_SERVER_IN} ${PIPE_CLIENT_OUT}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E create_symlink ${PIPE_SERVER_OUT} ${PIPE_CLIENT_IN}
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
set(PRE_QEMU_COMMANDS_FOR_server
|
|
|
|
${destroy_pipe_commands}
|
|
|
|
${create_pipe_commands}
|
|
|
|
)
|
|
|
|
if(PCAP)
|
|
|
|
# Start a monitor application to capture traffic
|
|
|
|
#
|
|
|
|
# Assumes;
|
|
|
|
# PCAP has been set to the file where traffic should be captured
|
|
|
|
# NET_TOOLS has been set to the net-tools repo path
|
|
|
|
# net-tools/monitor_15_4 has been built beforehand
|
|
|
|
|
2018-01-11 15:46:44 +01:00
|
|
|
set_ifndef(NET_TOOLS ${ZEPHYR_BASE}/../net-tools) # Default if not set
|
2017-12-21 22:45:45 +01:00
|
|
|
|
|
|
|
list(APPEND PRE_QEMU_COMMANDS_FOR_server
|
2020-12-24 11:12:42 +01:00
|
|
|
COMMAND
|
|
|
|
#This command is run in the background using '&'. This prevents
|
|
|
|
#chaining other commands with '&&'. The command is enclosed in '{}'
|
|
|
|
#to fix this.
|
|
|
|
{
|
|
|
|
${NET_TOOLS}/monitor_15_4
|
|
|
|
${PCAP}
|
|
|
|
/tmp/ip-stack-server
|
2017-12-21 22:45:45 +01:00
|
|
|
/tmp/ip-stack-client
|
|
|
|
> /dev/null &
|
2020-12-24 11:12:42 +01:00
|
|
|
}
|
2017-12-21 22:45:45 +01:00
|
|
|
# TODO: Support cleanup of the monitor_15_4 process
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2018-02-14 14:17:56 +01:00
|
|
|
endif(QEMU_PIPE_STACK)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2022-11-02 12:24:29 +01:00
|
|
|
if(CONFIG_CAN AND NOT (CONFIG_NIOS2 OR CONFIG_SOC_LEON3))
|
2022-10-21 10:33:27 +02:00
|
|
|
# Add CAN bus 0
|
|
|
|
list(APPEND QEMU_FLAGS -object can-bus,id=canbus0)
|
|
|
|
|
|
|
|
if(NOT "${CONFIG_CAN_QEMU_IFACE_NAME}" STREQUAL "")
|
|
|
|
# Connect CAN bus 0 to host SocketCAN interface
|
|
|
|
list(APPEND QEMU_FLAGS
|
|
|
|
-object can-host-socketcan,id=canhost0,if=${CONFIG_CAN_QEMU_IFACE_NAME},canbus=canbus0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_CAN_KVASER_PCI)
|
|
|
|
# Emulate a single-channel Kvaser PCIcan card connected to CAN bus 0
|
|
|
|
list(APPEND QEMU_FLAGS -device kvaser_pci,canbus=canbus0)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-07-28 18:15:24 +02:00
|
|
|
if(CONFIG_X86_64 AND NOT CONFIG_QEMU_UEFI_BOOT)
|
2019-07-23 00:49:25 +02:00
|
|
|
# QEMU doesn't like 64-bit ELF files. Since we don't use any >4GB
|
|
|
|
# addresses, converting it to 32-bit is safe enough for emulation.
|
2020-01-07 07:35:15 +01:00
|
|
|
add_custom_target(qemu_image_target
|
2019-07-23 00:49:25 +02:00
|
|
|
COMMAND
|
|
|
|
${CMAKE_OBJCOPY}
|
|
|
|
-O elf32-i386
|
|
|
|
$<TARGET_FILE:${logical_target_for_zephyr_elf}>
|
2020-08-13 04:54:30 +02:00
|
|
|
${ZEPHYR_BINARY_DIR}/zephyr-qemu.elf
|
2019-10-19 00:09:18 +02:00
|
|
|
DEPENDS ${logical_target_for_zephyr_elf}
|
2019-07-23 00:49:25 +02:00
|
|
|
)
|
2020-01-07 07:35:15 +01:00
|
|
|
|
|
|
|
# Split the 'locore' and 'main' memory regions into separate executable
|
|
|
|
# images and specify the 'locore' as the boot kernel, in order to prevent
|
|
|
|
# the QEMU direct multiboot kernel loader from overwriting the BIOS and
|
|
|
|
# option ROM areas located in between the two memory regions.
|
|
|
|
# (for more details, refer to the issue zephyrproject-rtos/sdk-ng#168)
|
|
|
|
add_custom_target(qemu_locore_image_target
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_OBJCOPY}
|
|
|
|
-j .locore
|
2020-08-13 04:54:30 +02:00
|
|
|
${ZEPHYR_BINARY_DIR}/zephyr-qemu.elf
|
|
|
|
${ZEPHYR_BINARY_DIR}/zephyr-qemu-locore.elf
|
2020-01-07 07:35:15 +01:00
|
|
|
2>&1 | grep -iv \"empty loadable segment detected\" || true
|
|
|
|
DEPENDS qemu_image_target
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(qemu_main_image_target
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_OBJCOPY}
|
|
|
|
-R .locore
|
2020-08-13 04:54:30 +02:00
|
|
|
${ZEPHYR_BINARY_DIR}/zephyr-qemu.elf
|
|
|
|
${ZEPHYR_BINARY_DIR}/zephyr-qemu-main.elf
|
2020-01-07 07:35:15 +01:00
|
|
|
2>&1 | grep -iv \"empty loadable segment detected\" || true
|
|
|
|
DEPENDS qemu_image_target
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
qemu_kernel_target
|
|
|
|
DEPENDS qemu_locore_image_target qemu_main_image_target
|
|
|
|
)
|
|
|
|
|
2020-08-13 04:54:30 +02:00
|
|
|
set(QEMU_KERNEL_FILE "${ZEPHYR_BINARY_DIR}/zephyr-qemu-locore.elf")
|
2020-01-07 07:35:15 +01:00
|
|
|
|
|
|
|
list(APPEND QEMU_EXTRA_FLAGS
|
2020-08-13 04:54:30 +02:00
|
|
|
"-device;loader,file=${ZEPHYR_BINARY_DIR}/zephyr-qemu-main.elf"
|
2020-01-07 07:35:15 +01:00
|
|
|
)
|
2019-07-23 00:49:25 +02:00
|
|
|
endif()
|
|
|
|
|
2020-12-11 09:52:09 +01:00
|
|
|
if(CONFIG_IVSHMEM)
|
|
|
|
if(CONFIG_IVSHMEM_DOORBELL)
|
|
|
|
list(APPEND QEMU_FLAGS
|
|
|
|
-device ivshmem-doorbell,vectors=${CONFIG_IVSHMEM_MSI_X_VECTORS},chardev=ivshmem
|
|
|
|
-chardev socket,path=/tmp/ivshmem_socket,id=ivshmem
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
list(APPEND QEMU_FLAGS
|
|
|
|
-device ivshmem-plain,memdev=hostmem
|
|
|
|
-object memory-backend-file,size=${CONFIG_QEMU_IVSHMEM_PLAIN_MEM_SIZE}M,share,mem-path=/dev/shm/ivshmem,id=hostmem
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2023-01-16 14:22:41 +01:00
|
|
|
if(CONFIG_NVME)
|
|
|
|
if(qemu_alternate_path)
|
|
|
|
find_program(
|
|
|
|
QEMU_IMG
|
|
|
|
PATHS ${qemu_alternate_path}
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
NAMES qemu-img
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
find_program(
|
|
|
|
QEMU_IMG
|
|
|
|
qemu-img
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND QEMU_EXTRA_FLAGS
|
|
|
|
-drive file=${ZEPHYR_BINARY_DIR}/nvme_disk.img,if=none,id=nvm1
|
|
|
|
-device nvme,serial=deadbeef,drive=nvm1
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(qemu_nvme_disk
|
|
|
|
COMMAND
|
|
|
|
${QEMU_IMG}
|
|
|
|
create
|
|
|
|
${ZEPHYR_BINARY_DIR}/nvme_disk.img
|
|
|
|
1M
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_custom_target(qemu_nvme_disk)
|
|
|
|
endif()
|
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
if(NOT QEMU_PIPE)
|
|
|
|
set(QEMU_PIPE_COMMENT "\nTo exit from QEMU enter: 'CTRL+a, x'\n")
|
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-10-03 19:03:58 +02:00
|
|
|
# Don't just test CONFIG_SMP, there is at least one test of the lower
|
|
|
|
# level multiprocessor API that wants an auxiliary CPU but doesn't
|
|
|
|
# want SMP using it.
|
2022-10-18 18:38:59 +02:00
|
|
|
if(NOT CONFIG_MP_MAX_NUM_CPUS MATCHES "1")
|
|
|
|
list(APPEND QEMU_SMP_FLAGS -smp cpus=${CONFIG_MP_MAX_NUM_CPUS})
|
2019-02-14 17:20:47 +01:00
|
|
|
endif()
|
|
|
|
|
2017-12-21 22:45:45 +01:00
|
|
|
# Use flags passed in from the environment
|
|
|
|
set(env_qemu $ENV{QEMU_EXTRA_FLAGS})
|
|
|
|
separate_arguments(env_qemu)
|
|
|
|
list(APPEND QEMU_EXTRA_FLAGS ${env_qemu})
|
2017-12-07 00:23:19 +01:00
|
|
|
|
2023-10-09 14:57:39 +02:00
|
|
|
# Also append QEMU flags from config
|
|
|
|
if(NOT CONFIG_QEMU_EXTRA_FLAGS STREQUAL "")
|
|
|
|
set(config_qemu_flags ${CONFIG_QEMU_EXTRA_FLAGS})
|
|
|
|
separate_arguments(config_qemu_flags)
|
|
|
|
list(APPEND QEMU_EXTRA_FLAGS "${config_qemu_flags}")
|
|
|
|
endif()
|
|
|
|
|
2023-01-28 19:16:24 +01:00
|
|
|
list(APPEND MORE_FLAGS_FOR_debugserver_qemu -S)
|
|
|
|
|
|
|
|
if(NOT CONFIG_QEMU_GDBSERVER_LISTEN_DEV STREQUAL "")
|
|
|
|
list(APPEND MORE_FLAGS_FOR_debugserver_qemu -gdb "${CONFIG_QEMU_GDBSERVER_LISTEN_DEV}")
|
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
|
arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().
The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.
Limitations:
+ Right now the SDK lacks an x86_64 toolchain. The build will fall
back to a host toolchain if it finds no cross compiler defined,
which is tested to work on gcc 8.2.1 right now.
+ No x87/SSE/AVX usage is allowed. This is a stronger limitation than
other architectures where the instructions work from one thread even
if the context switch code doesn't support it. We are passing
-no-sse to prevent gcc from automatically generating SSE
instructions for non-floating-point purposes, which has the side
effect of changing the ABI. Future work to handle the FPU registers
will need to be combined with an "application" ABI distinct from the
kernel one (or just to require USERSPACE).
+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
of all memory. No MMU/USERSPACE support yet.
+ We are building with -mno-red-zone for stack size reasons, but this
is a valuable optimization. Enabling it requires automatic stack
switching, which requires a TSS, which means it has to happen after
MMU support.
+ The OS runs in 64 bit mode, but for compatibility reasons is
compiled to the 32 bit "X32" ABI. So while the full 64 bit
registers and instruction set are available, C pointers are 32 bits
long and Zephyr is constrained to run in the bottom 4G of memory.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-19 21:24:48 +02:00
|
|
|
# Architectures can define QEMU_KERNEL_FILE to use a specific output
|
|
|
|
# file to pass to qemu (and a "qemu_kernel_target" target to generate
|
|
|
|
# it), or set QEMU_KERNEL_OPTION if they want to replace the "-kernel
|
|
|
|
# ..." option entirely.
|
2021-07-28 18:15:24 +02:00
|
|
|
if(CONFIG_QEMU_UEFI_BOOT)
|
|
|
|
set(QEMU_UEFI_OPTION ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.efi)
|
|
|
|
list(APPEND QEMU_UEFI_OPTION --)
|
|
|
|
elseif(DEFINED QEMU_KERNEL_FILE)
|
arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().
The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.
Limitations:
+ Right now the SDK lacks an x86_64 toolchain. The build will fall
back to a host toolchain if it finds no cross compiler defined,
which is tested to work on gcc 8.2.1 right now.
+ No x87/SSE/AVX usage is allowed. This is a stronger limitation than
other architectures where the instructions work from one thread even
if the context switch code doesn't support it. We are passing
-no-sse to prevent gcc from automatically generating SSE
instructions for non-floating-point purposes, which has the side
effect of changing the ABI. Future work to handle the FPU registers
will need to be combined with an "application" ABI distinct from the
kernel one (or just to require USERSPACE).
+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
of all memory. No MMU/USERSPACE support yet.
+ We are building with -mno-red-zone for stack size reasons, but this
is a valuable optimization. Enabling it requires automatic stack
switching, which requires a TSS, which means it has to happen after
MMU support.
+ The OS runs in 64 bit mode, but for compatibility reasons is
compiled to the 32 bit "X32" ABI. So while the full 64 bit
registers and instruction set are available, C pointers are 32 bits
long and Zephyr is constrained to run in the bottom 4G of memory.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-19 21:24:48 +02:00
|
|
|
set(QEMU_KERNEL_OPTION "-kernel;${QEMU_KERNEL_FILE}")
|
|
|
|
elseif(NOT DEFINED QEMU_KERNEL_OPTION)
|
|
|
|
set(QEMU_KERNEL_OPTION "-kernel;$<TARGET_FILE:${logical_target_for_zephyr_elf}>")
|
2020-03-24 03:55:15 +01:00
|
|
|
elseif(DEFINED QEMU_KERNEL_OPTION)
|
|
|
|
string(CONFIGURE "${QEMU_KERNEL_OPTION}" QEMU_KERNEL_OPTION)
|
arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().
The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.
Limitations:
+ Right now the SDK lacks an x86_64 toolchain. The build will fall
back to a host toolchain if it finds no cross compiler defined,
which is tested to work on gcc 8.2.1 right now.
+ No x87/SSE/AVX usage is allowed. This is a stronger limitation than
other architectures where the instructions work from one thread even
if the context switch code doesn't support it. We are passing
-no-sse to prevent gcc from automatically generating SSE
instructions for non-floating-point purposes, which has the side
effect of changing the ABI. Future work to handle the FPU registers
will need to be combined with an "application" ABI distinct from the
kernel one (or just to require USERSPACE).
+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
of all memory. No MMU/USERSPACE support yet.
+ We are building with -mno-red-zone for stack size reasons, but this
is a valuable optimization. Enabling it requires automatic stack
switching, which requires a TSS, which means it has to happen after
MMU support.
+ The OS runs in 64 bit mode, but for compatibility reasons is
compiled to the 32 bit "X32" ABI. So while the full 64 bit
registers and instruction set are available, C pointers are 32 bits
long and Zephyr is constrained to run in the bottom 4G of memory.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-19 21:24:48 +02:00
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
|
|
|
|
foreach(target ${qemu_targets})
|
|
|
|
add_custom_target(${target}
|
|
|
|
${PRE_QEMU_COMMANDS}
|
|
|
|
${PRE_QEMU_COMMANDS_FOR_${target}}
|
2017-10-27 15:43:34 +02:00
|
|
|
COMMAND
|
2017-12-21 22:45:45 +01:00
|
|
|
${QEMU}
|
2021-07-28 18:15:24 +02:00
|
|
|
${QEMU_UEFI_OPTION}
|
2017-12-21 22:45:45 +01:00
|
|
|
${QEMU_FLAGS_${ARCH}}
|
|
|
|
${QEMU_FLAGS}
|
|
|
|
${QEMU_EXTRA_FLAGS}
|
|
|
|
${MORE_FLAGS_FOR_${target}}
|
2019-02-14 17:20:47 +01:00
|
|
|
${QEMU_SMP_FLAGS}
|
2017-12-21 22:45:45 +01:00
|
|
|
${QEMU_KERNEL_OPTION}
|
|
|
|
DEPENDS ${logical_target_for_zephyr_elf}
|
|
|
|
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
|
|
|
|
COMMENT "${QEMU_PIPE_COMMENT}[QEMU] CPU: ${QEMU_CPU_TYPE_${ARCH}}"
|
|
|
|
USES_TERMINAL
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().
The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.
Limitations:
+ Right now the SDK lacks an x86_64 toolchain. The build will fall
back to a host toolchain if it finds no cross compiler defined,
which is tested to work on gcc 8.2.1 right now.
+ No x87/SSE/AVX usage is allowed. This is a stronger limitation than
other architectures where the instructions work from one thread even
if the context switch code doesn't support it. We are passing
-no-sse to prevent gcc from automatically generating SSE
instructions for non-floating-point purposes, which has the side
effect of changing the ABI. Future work to handle the FPU registers
will need to be combined with an "application" ABI distinct from the
kernel one (or just to require USERSPACE).
+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
of all memory. No MMU/USERSPACE support yet.
+ We are building with -mno-red-zone for stack size reasons, but this
is a valuable optimization. Enabling it requires automatic stack
switching, which requires a TSS, which means it has to happen after
MMU support.
+ The OS runs in 64 bit mode, but for compatibility reasons is
compiled to the 32 bit "X32" ABI. So while the full 64 bit
registers and instruction set are available, C pointers are 32 bits
long and Zephyr is constrained to run in the bottom 4G of memory.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-19 21:24:48 +02:00
|
|
|
if(DEFINED QEMU_KERNEL_FILE)
|
2023-01-16 14:22:41 +01:00
|
|
|
add_dependencies(${target} qemu_nvme_disk qemu_kernel_target)
|
arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().
The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.
Limitations:
+ Right now the SDK lacks an x86_64 toolchain. The build will fall
back to a host toolchain if it finds no cross compiler defined,
which is tested to work on gcc 8.2.1 right now.
+ No x87/SSE/AVX usage is allowed. This is a stronger limitation than
other architectures where the instructions work from one thread even
if the context switch code doesn't support it. We are passing
-no-sse to prevent gcc from automatically generating SSE
instructions for non-floating-point purposes, which has the side
effect of changing the ABI. Future work to handle the FPU registers
will need to be combined with an "application" ABI distinct from the
kernel one (or just to require USERSPACE).
+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
of all memory. No MMU/USERSPACE support yet.
+ We are building with -mno-red-zone for stack size reasons, but this
is a valuable optimization. Enabling it requires automatic stack
switching, which requires a TSS, which means it has to happen after
MMU support.
+ The OS runs in 64 bit mode, but for compatibility reasons is
compiled to the 32 bit "X32" ABI. So while the full 64 bit
registers and instruction set are available, C pointers are 32 bits
long and Zephyr is constrained to run in the bottom 4G of memory.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-19 21:24:48 +02:00
|
|
|
endif()
|
2017-12-21 22:45:45 +01:00
|
|
|
endforeach()
|