source: mainline/boot/arch/arm64/src/asm.S@ 5631c9c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5631c9c was 84176f3, checked in by Jakub Jermář <jakub@…>, 6 years ago

arm64: Add support for the architecture

This changeset adds basic support to run HelenOS on AArch64, targeting
the QEMU virt platform.

Boot:

  • Boot relies on the EDK II firmware, GRUB2 for EFI and the HelenOS bootloader (UEFI application). EDK II loads GRUB2 from a CD, GRUB2 loads the HelenOS bootloader (via UEFI) which loads OS components.
  • UEFI applications use the PE/COFF format and must be relocatable. The first problem is solved by manually having the PE/COFF headers and tables written in assembler. The relocatable requirement is addressed by compiling the code with -fpic and having the bootloader relocate itself at its startup.

Kernel:

  • Kernel code for AArch64 consists mostly of stubbing out various architecture-specific hooks: virtual memory management, interrupt and exception handling, context switching (including FPU lazy switching), support for virtual timer, atomic sequences and barriers, cache and TLB maintenance, thread and process initialization.
  • The patch adds a kernel driver for GICv2 (interrupt controller).
  • The PL011 kernel driver is extended to allow userspace to take ownership of the console.
  • The current code is not able to dynamically obtain information about available devices on the underlying machine. The port instead implements a machine-func interface similar to the one implemented by arm32. It defines a machine for the QEMU AArch64 virt platform. The configuration (device addresses and IRQ numbers) is then baked into the machine definition.

User space:

  • Uspace code for AArch64 similarly mostly implements architecture-specific hooks: context saving/restoring, syscall support, TLS support.

The patchset allows to boot the system but user interaction with the OS
is not yet possible.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2015 Petr Pavlu
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <abi/asmtool.h>
30#include <arch/arch.h>
31#include <arch/regutils.h>
32
33.section BOOTSTRAP
34
35/* MS-DOS stub */
36msdos_stub:
37 .ascii "MZ" /* MS-DOS signature */
38 .space 0x3a /* Ignore fields up to byte at 0x3c */
39 .long pe_header - msdos_stub /* Offset to the PE header */
40
41/* Portable Executable header */
42pe_header:
43 /* PE signature */
44 .ascii "PE\x0\x0"
45
46 /* COFF File Header */
47 .short 0xaa64 /* Machine = IMAGE_FILE_MACHINE_ARM64 */
48 .short 1 /* Number of sections */
49 .long 0 /* Time date stamp */
50 .long 0 /* Pointer to symbol table */
51 .long 0 /* Number of symbols */
52 .short sec_table - opt_header /* Size of optional header */
53 /* Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE |
54 * IMAGE_FILE_LARGE_ADDRESS_AWARE */
55 .short 0x22
56
57 /* Optional header standard fields */
58opt_header:
59 .short 0x20b /* Magic = PE32+ */
60 .byte 0 /* Major linker version */
61 .byte 0 /* Minor linker version */
62 .long payload_end - msdos_stub /* Size of code */
63 .long 0 /* Size of initialized data */
64 .long 0 /* Size of uninitialized data */
65 .long start - msdos_stub /* Address of entry point */
66 .long start - msdos_stub /* Base of code */
67
68 /* Optional header Windows-specific fields */
69 .quad 0 /* Image base */
70 .long 4 /* Section alignment */
71 .long 4 /* File alignment */
72 .short 0 /* Major operating system version */
73 .short 0 /* Minor operating system version */
74 .short 0 /* Major image version */
75 .short 0 /* Minor image version */
76 .short 0 /* Major subsystem version */
77 .short 0 /* Minor subsystem version */
78 .long 0 /* Win32 version value */
79 .long payload_end - msdos_stub /* Size of image */
80 .long start - msdos_stub /* Size of headers */
81 .long 0 /* Checksum */
82 .short 10 /* Subsystem = EFI application */
83 .short 0 /* DLL characteristics */
84 .quad 0 /* Size of stack reserve */
85 .quad 0 /* Size of stack commit */
86 .quad 0 /* Size of heap reserve */
87 .quad 0 /* Size of heap commit */
88 .long 0 /* Loader flags */
89 .long 0 /* Number of RVA and sizes */
90
91sec_table:
92 .ascii ".text\x0\x0\x0" /* Name */
93 .long payload_end - start /* Virtual size */
94 .long start - msdos_stub /* Virtual address */
95 .long payload_end - start /* Size of raw data */
96 .long start - msdos_stub /* Pointer to raw data */
97 .long 0 /* Pointer to relocations */
98 .long 0 /* Pointer to line numbers */
99 .short 0 /* Number of relocations */
100 .short 0 /* Number of line numbers */
101 /* Characteristics = IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE |
102 * IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE */
103 .long 0xe0000020
104
105SYMBOL(start)
106 .hidden start
107
108 /*
109 * Parameters:
110 * x0 is the image handle.
111 * x1 is a pointer to the UEFI system table.
112 */
113
114 /*
115 * Stay on the UEFI stack. Its size is at least 128 kB, plenty for this
116 * boot loader.
117 */
118 stp x29, x30, [sp, #-32]!
119 mov x29, sp
120 stp x0, x1, [sp, #16]
121
122 /*
123 * Self-relocate the image. Pass a load address of the image (x0) and a
124 * pointer to the dynamic array (x1).
125 */
126 adr x0, msdos_stub
127 adrp x1, _DYNAMIC
128 add x1, x1, #:lo12:_DYNAMIC
129 bl self_relocate
130 cbnz x0, 0f
131
132 /*
133 * Pass the image handle (x0), a pointer to the UEFI system table (x1),
134 * and the image load address (x2) to the boostrap function.
135 */
136 ldp x0, x1, [sp, #16]
137 adr x2, msdos_stub
138 bl bootstrap
139
1400:
141 ldp x29, x30, [sp], #32
142 ret
143
144FUNCTION_BEGIN(halt)
145 .hidden halt
146
147 b halt
148FUNCTION_END(halt)
149
150FUNCTION_BEGIN(jump_to_kernel)
151 .hidden jump_to_kernel
152
153 /*
154 * Parameters:
155 * x0 is kernel entry point.
156 * x1 is pointer to the bootinfo structure.
157 */
158
159 /* Disable MMU (removes the identity mapping provided by UEFI). */
160 mrs x2, sctlr_el1
161 bic x2, x2, #SCTLR_M_FLAG
162 msr sctlr_el1, x2
163 isb
164
165 br x0
166FUNCTION_END(jump_to_kernel)
Note: See TracBrowser for help on using the repository browser.