xref: /aosp_15_r20/external/crosvm/kernel_loader/src/test_elf.S (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1# Copyright 2022 The ChromiumOS Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# Build instructions:
6#  x86_64-linux-gnu-as test_elf.S -o test_elf.o
7#  x86_64-linux-gnu-ld test_elf.o -o test_elf.bin -T test_elf.ld
8
9    .intel_syntax noprefix
10
11    .section .rodata
12hello_world:
13    .string "Hello world!\n"
14    .set hello_size, .-hello_world
15
16    .text
17    .globl _start
18_start:
19    lea rsi, [rip + hello_world]    # rsi -> message string
20    mov rcx, hello_size             # rcx = length of message
21    mov dx, 0x3F8                   # dx = COM1 port
22
23.print_loop:
24    # Wait for the transmit buffer to be empty by polling the line status.
25    add dx, 5                       # dx = line status register
26.wait_empty:
27    in al, dx                       # read line status
28    test al, 0x20                   # check buffer empty flag
29    jz .wait_empty                  # keep waiting if flag is not set
30
31.wait_done:
32    sub dx, 5                       # dx = data register
33
34    # Load a byte of the message and send it to the serial port.
35    lodsb                           # load message byte from RSI to AL
36    out dx, al                      # send byte to serial port
37    dec rcx                         # rcx--
38    jnz .print_loop                 # repeat if rcx != 0
39
40.done:
41    int3                            # cause vcpu to exit
42