Changeset 84176f3 in mainline for boot


Ignore:
Timestamp:
2019-04-10T15:04:17Z (7 years ago)
Author:
Jakub Jermář <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8df0306
Parents:
b58728f
git-author:
Petr Pavlu <setup@…> (2019-03-31 14:09:57)
git-committer:
Jakub Jermář <jakub@…> (2019-04-10 15:04:17)
Message:

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.

Location:
boot
Files:
13 added
7 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile.build

    rb58728f r84176f3  
    3737
    3838AFLAGS = --fatal-warnings
    39 LDFLAGS = -Wl,--fatal-warnings,--warn-common
     39LDFLAGS = -Wl,--fatal-warnings,--warn-common $(EXTRA_LDFLAGS)
    4040
    4141COMMON_CFLAGS = $(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
  • boot/Makefile.grub

    rb58728f r84176f3  
    6464endif
    6565
     66ifeq ($(GRUB_LOADER),multiboot)
    6667        for module in $(COMPONENTS) ; do \
    6768                cp "$$module" $(BOOT)/ ; \
    6869        done
     70endif
     71ifeq ($(GRUB_LOADER),chainloader)
     72        cp "$(BOOT_OUTPUT)" $(BOOT)/
     73endif
    6974
    7075        echo "set default=0" > $(BOOT_CONFIG)
     
    8388
    8489        echo "menuentry 'HelenOS $(RELEASE)' --class helenos --class os {" >> $(BOOT_CONFIG)
     90ifeq ($(GRUB_LOADER),multiboot)
    8591        for module in $(MODULES) ; do \
    8692                echo "  echo 'Loading $$module'" >> $(BOOT_CONFIG) ; \
     
    9197                fi \
    9298        done
     99endif
     100ifeq ($(GRUB_LOADER),chainloader)
     101        echo "  echo 'Loading $(BOOT_OUTPUT)'" >> $(BOOT_CONFIG)
     102        echo "  chainloader /boot/$(BOOT_OUTPUT)" >> $(BOOT_CONFIG)
     103        echo "  boot" >> $(BOOT_CONFIG)
     104endif
    93105        echo "}" >> $(BOOT_CONFIG)
    94106
  • boot/arch/amd64/Makefile.inc

    rb58728f r84176f3  
    7474BUILD = Makefile.empty
    7575POSTBUILD = Makefile.grub
     76GRUB_LOADER = multiboot
  • boot/doc/doxygroups.h

    rb58728f r84176f3  
    1111 *     @ingroup boot
    1212 */
     13
     14/**    @addtogroup boot_arm64 arm64
     15 *     @ingroup boot
     16 */
  • boot/genarch/include/genarch/efi.h

    rb58728f r84176f3  
    3232#include <arch/types.h>
    3333
     34#define EFI_SUCCESS  0
     35#define EFI_ERROR(code) (((sysarg_t) 1 << (sizeof(sysarg_t) * 8 - 1)) | (code))
     36#define EFI_LOAD_ERROR  EFI_ERROR(1)
     37#define EFI_UNSUPPORTED  EFI_ERROR(3)
     38#define EFI_BUFFER_TOO_SMALL  EFI_ERROR(5)
     39
     40typedef uint64_t efi_status_t;
     41
    3442typedef struct {
    3543        uint64_t signature;
     
    5664} efi_guid_t;
    5765
    58 typedef struct {
    59         efi_guid_t guid;
    60         void *table;
    61 } efi_configuration_table_t;
    62 
    63 typedef struct {
    64         efi_table_header_t hdr;
    65         char *fw_vendor;
    66         uint32_t fw_revision;
    67         void *cons_in_handle;
    68         void *cons_in;
    69         void *cons_out_handle;
    70         void *cons_out;
    71         void *cons_err_handle;
    72         void *cons_err;
    73         void *runtime_services;
    74         void *boot_services;
    75         sysarg_t conf_table_entries;
    76         efi_configuration_table_t *conf_table;
    77 } efi_system_table_t;
     66typedef enum {
     67        EFI_ALLOCATE_ANY_PAGES,
     68        EFI_ALLOCATE_MAX_ADDRESS,
     69        EFI_ALLOCATE_ADDRESS
     70} efi_allocate_type_t;
    7871
    7972typedef enum {
     
    9184        EFI_MEMORY_MAPPED_IO,
    9285        EFI_MEMORY_MAPPED_IO_PORT_SPACE,
    93         EFI_PAL_CODE
     86        EFI_PAL_CODE,
     87        EFI_PERSISTENT_MEMORY
    9488} efi_memory_type_t;
     89
     90#define EFI_MEMORY_UC             UINT64_C(0x0000000000000001)
     91#define EFI_MEMORY_WC             UINT64_C(0x0000000000000002)
     92#define EFI_MEMORY_WT             UINT64_C(0x0000000000000004)
     93#define EFI_MEMORY_WB             UINT64_C(0x0000000000000008)
     94#define EFI_MEMORY_UCE            UINT64_C(0x0000000000000010)
     95#define EFI_MEMORY_WP             UINT64_C(0x0000000000001000)
     96#define EFI_MEMORY_RP             UINT64_C(0x0000000000002000)
     97#define EFI_MEMORY_XP             UINT64_C(0x0000000000004000)
     98#define EFI_MEMORY_NV             UINT64_C(0x0000000000008000)
     99#define EFI_MEMORY_MORE_RELIABLE  UINT64_C(0x0000000000010000)
     100#define EFI_MEMORY_RO             UINT64_C(0x0000000000020000)
     101#define EFI_MEMORY_RUNTIME        UINT64_C(0x8000000000000000)
    95102
    96103typedef struct {
     
    102109} efi_v1_memdesc_t;
    103110
     111typedef struct {
     112        efi_guid_t guid;
     113        void *table;
     114} efi_configuration_table_t;
     115
     116typedef struct efi_simple_text_output_protocol {
     117        void *reset;
     118        efi_status_t (*output_string)(struct efi_simple_text_output_protocol *,
     119            int16_t *);
     120        void *test_string;
     121        void *query_mode;
     122        void *set_mode;
     123        void *set_attribute;
     124        void *clear_screen;
     125        void *set_cursor_position;
     126        void *enable_cursor;
     127        void *mode;
     128} efi_simple_text_output_protocol_t;
     129
     130typedef struct {
     131        efi_table_header_t hdr;
     132        void *raise_TPL;
     133        void *restore_TPL;
     134        efi_status_t (*allocate_pages)(efi_allocate_type_t, efi_memory_type_t,
     135            sysarg_t, uint64_t *);
     136        efi_status_t (*free_pages)(uint64_t, sysarg_t);
     137        efi_status_t (*get_memory_map)(sysarg_t *, efi_v1_memdesc_t *,
     138            sysarg_t *, sysarg_t *, uint32_t *);
     139        efi_status_t (*allocate_pool)(efi_memory_type_t, sysarg_t, void **);
     140        efi_status_t (*free_pool)(void *);
     141        void *create_event;
     142        void *set_timer;
     143        void *wait_for_event;
     144        void *signal_event;
     145        void *close_event;
     146        void *check_event;
     147        void *install_protocol_interface;
     148        void *reinstall_protocol_interface;
     149        void *uninstall_protocol_interface;
     150        void *handle_protocol;
     151        void *reserved;
     152        void *register_protocol_notify;
     153        void *locate_handle;
     154        void *locate_device_path;
     155        void *install_configuration_table;
     156        void *load_image;
     157        void *start_image;
     158        void *exit;
     159        void *unload_image;
     160        efi_status_t (*exit_boot_services)(void *, sysarg_t);
     161        void *get_next_monotonic_count;
     162        void *stall;
     163        void *set_watchdog_timer;
     164        void *connect_controller;
     165        void *disconnect_controller;
     166        void *open_protocol;
     167        void *close_protocol;
     168        void *open_protocol_information;
     169        void *protocols_per_handle;
     170        void *locate_handle_buffer;
     171        void *locate_protocol;
     172        void *install_multiple_protocol_interfaces;
     173        void *uninstall_multiple_protocol_intefaces;
     174        void *calculate_crc32;
     175        void *copy_mem;
     176        void *set_mem;
     177        void *create_event_ex;
     178} efi_boot_services_t;
     179
     180typedef struct {
     181        efi_table_header_t hdr;
     182        char *fw_vendor;
     183        uint32_t fw_revision;
     184        void *cons_in_handle;
     185        void *cons_in;
     186        void *cons_out_handle;
     187        efi_simple_text_output_protocol_t *cons_out;
     188        void *cons_err_handle;
     189        efi_simple_text_output_protocol_t *cons_err;
     190        void *runtime_services;
     191        efi_boot_services_t *boot_services;
     192        sysarg_t conf_table_entries;
     193        efi_configuration_table_t *conf_table;
     194} efi_system_table_t;
     195
    104196#define EFI_PAGE_SIZE   4096
    105197
    106198extern void *efi_vendor_table_find(efi_system_table_t *, efi_guid_t);
     199extern efi_status_t efi_get_memory_map(efi_system_table_t *, sysarg_t *,
     200    efi_v1_memdesc_t **, sysarg_t *, sysarg_t *, uint32_t *);
    107201
    108202#endif
  • boot/genarch/src/efi.c

    rb58728f r84176f3  
    4242        return NULL;
    4343}
     44
     45efi_status_t efi_get_memory_map(efi_system_table_t *st,
     46    sysarg_t *memory_map_size, efi_v1_memdesc_t **memory_map, sysarg_t *map_key,
     47    sysarg_t *descriptor_size, uint32_t *descriptor_version)
     48{
     49        efi_status_t status;
     50
     51        *memory_map_size = 8 * sizeof(**memory_map);
     52
     53        do {
     54                /* Allocate space for the memory map. */
     55                status = st->boot_services->allocate_pool(EFI_LOADER_DATA,
     56                    *memory_map_size, (void **) memory_map);
     57                if (status != EFI_SUCCESS)
     58                        return status;
     59
     60                /* Try to obtain the map. */
     61                status = st->boot_services->get_memory_map(memory_map_size,
     62                    *memory_map, map_key, descriptor_size, descriptor_version);
     63                if (status == EFI_SUCCESS)
     64                        return status;
     65
     66                /* An error occurred, release the allocated memory. */
     67                st->boot_services->free_pool(*memory_map);
     68        } while (status == EFI_BUFFER_TOO_SMALL);
     69
     70        return status;
     71}
  • boot/generic/include/align.h

    rb58728f r84176f3  
    4949#define ALIGN_UP(s, a)  (((s) + ((a) - 1)) & ~((a) - 1))
    5050
     51/** Check alignment.
     52 *
     53 * @param s Address or size to be checked for alignment.
     54 * @param a Size of alignment, must be a power of 2.
     55 */
     56#define IS_ALIGNED(s, a)  (ALIGN_UP((s), (a)) == (s))
     57
    5158#endif
    5259
Note: See TracChangeset for help on using the changeset viewer.