diff options
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/boot/boot.hpp | 66 | ||||
| -rw-r--r-- | arch/x86_64/src/boot/boot.S (renamed from arch/x86_64/src/boot/boot.s) | 19 | ||||
| -rw-r--r-- | arch/x86_64/src/memory.cpp | 5 |
4 files changed, 74 insertions, 18 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index d1af777..a32a0f5 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -34,7 +34,7 @@ target_sources("arch-x86_64" PRIVATE #]============================================================================] target_sources("arch-x86_64" PRIVATE - "src/boot/boot.s" + "src/boot/boot.S" "src/boot/crti.s" "src/boot/crtn.s" "src/boot/multiboot.s" diff --git a/arch/x86_64/include/x86_64/boot/boot.hpp b/arch/x86_64/include/x86_64/boot/boot.hpp new file mode 100644 index 0000000..066e49e --- /dev/null +++ b/arch/x86_64/include/x86_64/boot/boot.hpp @@ -0,0 +1,66 @@ +#ifndef TEACHOS_X86_64_BOOT_BOOT_H +#define TEACHOS_X86_64_BOOT_BOOT_H + +#ifdef __ASSEMBLER__ +/** + * @brief The number of huge pages to map during bootstrap. + */ +#define HUGE_PAGES_TO_MAP (16) + +/** + * @brief The magic value to be set in eax by the multiboot 2 loader. + */ +#define MULTIBOOT2_MAGIC (0x36d76289) + +/** + * @brief The "A" bit in a GDT entry. + */ +#define GDT_ACCESSED (1 << 40) + +/** + * @brief The "R/W" bit in a GDT entry + */ +#define GDT_READ_WRITE (1 << 41) + +/** + * @brief The "E" bit in a GDT entry. + */ +#define GDT_EXECUTABLE (1 << 43) + +/** + * @brief The "S" bit in a GDT entry. + */ +#define GDT_DESCRIPTOR_TYPE (1 << 44) + +/** + * @brief The "P" bit in a GDT entry. + */ +#define GDT_PRESENT (1 << 47) + +/** + * @brief The "L" bit in a GDT entry. + */ +#define GDT_LONG_MODE (1 << 53) + +#else + +#include "arch/asm_pointer.hpp" + +#include <multiboot2/information.hpp> + +extern "C" +{ + /** + * @brief A pointer to the multiboot 2 information structure provided by the boot loader. + */ + extern teachos::arch::asm_pointer<multiboot2::information_view> multiboot_information_pointer; + + /** + * @brief A pointer to the VGA text mode buffer. + */ + extern teachos::arch::asm_pointer<std::pair<char, std::byte>> vga_buffer_pointer; +} + +#endif + +#endif diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.S index 7a46795..d65c865 100644 --- a/arch/x86_64/src/boot/boot.s +++ b/arch/x86_64/src/boot/boot.S @@ -1,3 +1,5 @@ +#include "x86_64/boot/boot.hpp" + /** * @brief Uninitialized data for the bootstrapping process. */ @@ -33,18 +35,12 @@ stack_top: * @brief A basic GDT for long mode. */ global_descriptor_table: -.set GDT_ACCESSED, 40 -.set GDT_READ_WRITE, 41 -.set GDT_EXECUTABLE, 43 -.set GDT_DESCRIPTOR_TYPE, 44 -.set GDT_PRESENT, 47 -.set GDT_LONG_MODE, 53 global_descriptor_table_null = . - global_descriptor_table .quad 0 global_descriptor_table_code = . - global_descriptor_table -.quad (1 << GDT_ACCESSED) | (1 << GDT_READ_WRITE) | (1 << GDT_EXECUTABLE) | (1 << GDT_DESCRIPTOR_TYPE) | (1 << GDT_PRESENT) | (1 << GDT_LONG_MODE) +.quad GDT_ACCESSED | GDT_READ_WRITE | GDT_EXECUTABLE | GDT_DESCRIPTOR_TYPE | GDT_PRESENT | GDT_LONG_MODE global_descriptor_table_data = . - global_descriptor_table -.quad (1 << GDT_ACCESSED) | (1 << GDT_READ_WRITE) | (1 << GDT_DESCRIPTOR_TYPE) | (1 << GDT_PRESENT) +.quad GDT_ACCESSED | GDT_READ_WRITE | GDT_DESCRIPTOR_TYPE | GDT_PRESENT global_descriptor_table_end: message_prefix_panic: .string "Panic: " @@ -110,7 +106,6 @@ vga_buffer_pointer: .quad 0xb8000 * @param %ebx The Multiboot 2 information pointer. * @return void This function does not return. */ -.global _start _start: call 0f 0: @@ -145,7 +140,6 @@ _start: * * @return This function never returns. */ -.global halt _halt: function_start @@ -227,7 +221,6 @@ _panic: _assert_loaded_by_multiboot2_loader: pie_function_start - .set MULTIBOOT2_MAGIC, 0x36d76289 cmp $MULTIBOOT2_MAGIC, %eax je 1f lea (message_not_loaded_by_multiboot2 - 0b)(%esi), %eax @@ -316,8 +309,6 @@ _prepare_page_maps: pie_function_start push %ebx - .set HUGE_PAGES_TO_MAP, 16 - /* Map the P4 table recursively */ lea (page_map_level_4 - 0b)(%esi), %eax mov %eax, %ebx @@ -362,7 +353,7 @@ _prepare_page_maps: * set up for use. * * @return void - */For + */ _enable_paging: pie_function_start diff --git a/arch/x86_64/src/memory.cpp b/arch/x86_64/src/memory.cpp index 2b16beb..a31627b 100644 --- a/arch/x86_64/src/memory.cpp +++ b/arch/x86_64/src/memory.cpp @@ -2,14 +2,13 @@ #include "kern/error.hpp" -#include "arch/asm_pointer.hpp" -#include "x86_64/memory/region_allocator.hpp" +#include "x86_64/boot/boot.hpp" #include <multiboot2/information.hpp> #include <atomic> -extern "C" teachos::arch::asm_pointer<multiboot2::information_view> multiboot_information_pointer; +// extern "C" teachos::arch::asm_pointer<multiboot2::information_view> multiboot_information_pointer; namespace teachos::arch::memory { |
