Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/kernel_loader/src/test_elf.S
5394 views
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
#
7
# For a 64-bit kernel:
8
# x86_64-linux-gnu-as test_elf.S -o test_elf64.o
9
# x86_64-linux-gnu-ld test_elf64.o -o test_elf64.bin -T test_elf.ld
10
#
11
# For a 32-bit kernel:
12
# i686-linux-gnu-as test_elf.S -o test_elf32.o
13
# i686-linux-gnu-ld test_elf32.o -o test_elf32.bin -T test_elf.ld
14
15
.intel_syntax noprefix
16
17
.section .rodata
18
hello_world:
19
.string "Hello world!\n"
20
.set hello_size, .-hello_world
21
22
.text
23
.globl _start
24
_start:
25
lea esi, [hello_world] # esi -> message string
26
mov ecx, hello_size # ecx = length of message
27
mov dx, 0x3F8 # dx = COM1 port
28
29
.print_loop:
30
# Wait for the transmit buffer to be empty by polling the line status.
31
add dx, 5 # dx = line status register
32
.wait_empty:
33
in al, dx # read line status
34
test al, 0x20 # check buffer empty flag
35
jz .wait_empty # keep waiting if flag is not set
36
37
.wait_done:
38
sub dx, 5 # dx = data register
39
40
# Load a byte of the message and send it to the serial port.
41
lodsb # load message byte from RSI to AL
42
out dx, al # send byte to serial port
43
loop .print_loop # repeat hello_size times
44
45
.done:
46
int3 # cause vcpu to exit
47
48