mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 00:27:52 +01:00
pretty up GDT a little, and other stuff
also thanks internet for the boilerplate
This commit is contained in:
@@ -2,7 +2,26 @@
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
OverEmptyLines: 2
|
||||
SpacesBeforeTrailingComments: 1
|
||||
AlignOperands: Align
|
||||
AlignEscapedNewlines: Right
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
@@ -57,7 +76,6 @@ SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 0
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
|
||||
@@ -38,7 +38,7 @@ real_start() {
|
||||
extern "C" void _start(void) {
|
||||
_sse_setup();
|
||||
barrier();
|
||||
gdt_setup();
|
||||
Arch::GDT::gdt_setup();
|
||||
barrier();
|
||||
idt_init();
|
||||
barrier();
|
||||
|
||||
@@ -74,16 +74,19 @@ gdt_code_user:
|
||||
db PRESENT | USER | NOT_SYS | EXEC | RW ; Access
|
||||
db GRAN_4K | LONG_MODE | 0xF ; Flags & Limit (high, bits 16-19)
|
||||
db 0 ; Base (high, bits 24-31)
|
||||
|
||||
global gdt_tss:data
|
||||
gdt_tss:
|
||||
dq 0x00000000 ;TODO
|
||||
dq 0x00000000
|
||||
dq 0x00000000
|
||||
global gdt_tss_user:data
|
||||
gdt_tss_user:
|
||||
dq 0x00000000 ;TODO
|
||||
dq 0x00000000
|
||||
dq 0x00000000
|
||||
|
||||
global gdt_end:data
|
||||
gdt_end:
|
||||
|
||||
global gdtr:data
|
||||
gdtr:
|
||||
dw gdt_end - gdt_null - 1
|
||||
@@ -93,20 +96,23 @@ section .text
|
||||
global _gdt_setup:function (_gdt_setup.end - _gdt_setup)
|
||||
_gdt_setup:
|
||||
LGDT [gdtr]
|
||||
; Reload CS register:
|
||||
PUSH (gdt_code - gdt_null); Push code segment to stack, 0x08 is a stand-in for your code segment
|
||||
LEA RAX, [rel .flush] ; Load address of .reload_CS into RAX
|
||||
; Reload CS register
|
||||
PUSH (gdt_code - gdt_null) ; Push code segment to stack
|
||||
LEA RAX, [rel .flush] ; Load address of .flush into RAX
|
||||
PUSH RAX ; Push this value to the stack
|
||||
RETFQ ; Perform a far return, RETFQ or LRETQ depending on syntax
|
||||
|
||||
.flush:
|
||||
|
||||
; Reload data segment registers
|
||||
MOV AX, (gdt_data - gdt_null) ; 0x10 is a stand-in for your data segment
|
||||
MOV AX, (gdt_data - gdt_null)
|
||||
MOV DS, AX
|
||||
MOV ES, AX
|
||||
MOV FS, AX
|
||||
MOV GS, AX
|
||||
MOV SS, AX
|
||||
MOV AX, (gdt_tss - gdt_null)
|
||||
|
||||
ltr AX
|
||||
RET
|
||||
.end:
|
||||
|
||||
@@ -3,16 +3,20 @@
|
||||
//
|
||||
|
||||
#include "gdt.hpp"
|
||||
#include "asserts.hpp"
|
||||
#include "misc.hpp"
|
||||
#include <cstddef>
|
||||
namespace Arch::GDT {
|
||||
static tss_entry_struct tss_entry;
|
||||
static tss_entry_struct tss_entry_user;
|
||||
|
||||
static struct tss_entry_struct tss_entry;
|
||||
static struct tss_entry_struct tss_entry_user;
|
||||
static constexpr size_t INT_STACK_SIZE = 16384;
|
||||
static constexpr size_t RSP_STACK_SIZE = 16384;
|
||||
|
||||
#define INT_STACK_SIZE 16384
|
||||
#define RSP_STACK_SIZE 16384
|
||||
static uint64_t int_stack[INT_STACK_SIZE];
|
||||
static uint64_t rsp_stack[RSP_STACK_SIZE];
|
||||
|
||||
//
|
||||
void gdt_setup() {
|
||||
uint32_t tss_limit = sizeof(tss_entry);
|
||||
uint64_t tss_base = (uint64_t) &tss_entry;
|
||||
@@ -30,10 +34,14 @@ void gdt_setup() {
|
||||
gdt_tss.base_high = (tss_base >> 24) & 0xFFFFFFFFFF;
|
||||
|
||||
tss_entry.ist1 = (((uintptr_t) int_stack + (INT_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8;
|
||||
if ((tss_entry.ist1 & 0xFULL) != 8) _hcf();
|
||||
assert((tss_entry.ist1 & 0xFULL) == 8);
|
||||
|
||||
tss_entry.rsp0 = (((uintptr_t) rsp_stack + (RSP_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8;
|
||||
if ((tss_entry.rsp0 & 0xFULL) != 8) _hcf();
|
||||
assert((tss_entry.rsp0 & 0xFULL) == 8);
|
||||
|
||||
barrier(); // The asm function might clobber registers
|
||||
_gdt_setup();
|
||||
barrier();
|
||||
}
|
||||
|
||||
} // namespace Arch::GDT
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Arch::GDT {
|
||||
struct gdt_entry_bits {
|
||||
unsigned int limit_low : 16;
|
||||
unsigned int base_low : 24;
|
||||
@@ -19,6 +20,9 @@ struct gdt_entry_bits {
|
||||
unsigned int big : 1; // 32-bit opcodes for code, uint32_t stack for data
|
||||
unsigned int gran : 1; // 1 to use 4k page addressing, 0 for byte addressing
|
||||
unsigned int base_high : 8;
|
||||
|
||||
//
|
||||
uint64_t selector() volatile;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct gdt_tss_entry_bits {
|
||||
@@ -53,9 +57,10 @@ struct tss_entry_struct {
|
||||
uint32_t reserved4;
|
||||
} __attribute__((packed));
|
||||
|
||||
extern "C" void _gdt_setup();
|
||||
void gdt_setup();
|
||||
|
||||
extern "C" {
|
||||
void _gdt_setup();
|
||||
extern volatile struct gdt_entry_bits gdt_null;
|
||||
extern volatile struct gdt_entry_bits gdt_code_16;
|
||||
extern volatile struct gdt_entry_bits gdt_data_16;
|
||||
@@ -68,13 +73,19 @@ extern volatile struct gdt_entry_bits gdt_data_user;
|
||||
extern volatile struct gdt_tss_entry_bits gdt_tss;
|
||||
extern volatile struct gdt_tss_entry_bits gdt_tss_user;
|
||||
|
||||
extern volatile struct gdt_entry_bits gdt_end;/// It is not a pointer!
|
||||
extern volatile struct gdt_entry_bits gdt_end; // It is not a pointer!
|
||||
|
||||
extern struct {
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} gdtr;
|
||||
} __attribute__((packed)) gdtr;
|
||||
}
|
||||
|
||||
inline uint64_t gdt_entry_bits::selector() volatile {
|
||||
return (((uint64_t) this) - ((uint64_t) &gdt_null));
|
||||
}
|
||||
|
||||
} // namespace Arch::GDT
|
||||
|
||||
#define GDTSEL(x) (((uint64_t) &x) - ((uint64_t) &gdt_null))
|
||||
|
||||
#endif
|
||||
@@ -37,7 +37,7 @@ void idt_set_descriptor(uint8_t vector, void (*isr)(), uint8_t flags) {
|
||||
idt_entry_t *descriptor = &idt[vector];
|
||||
|
||||
descriptor->isr_low = (uint64_t) isr & 0xFFFF;
|
||||
descriptor->kernel_cs = GDTSEL(gdt_code);
|
||||
descriptor->kernel_cs = Arch::GDT::gdt_code.selector();
|
||||
descriptor->ist = 1;
|
||||
descriptor->attributes = flags;
|
||||
descriptor->isr_mid = ((uint64_t) isr >> 16) & 0xFFFF;
|
||||
|
||||
@@ -59,10 +59,13 @@ struct limine_uuid {
|
||||
|
||||
struct limine_file {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) address;
|
||||
LIMINE_PTR(void *)
|
||||
address;
|
||||
uint64_t size;
|
||||
LIMINE_PTR(char *) path;
|
||||
LIMINE_PTR(char *) cmdline;
|
||||
LIMINE_PTR(char *)
|
||||
path;
|
||||
LIMINE_PTR(char *)
|
||||
cmdline;
|
||||
uint32_t media_type;
|
||||
uint32_t unused;
|
||||
uint32_t tftp_ip;
|
||||
@@ -76,23 +79,28 @@ struct limine_file {
|
||||
|
||||
/* Boot info */
|
||||
|
||||
#define LIMINE_BOOTLOADER_INFO_REQUEST { LIMINE_COMMON_MAGIC, 0xf55038d8e2a1202f, 0x279426fcf5f59740 }
|
||||
#define LIMINE_BOOTLOADER_INFO_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0xf55038d8e2a1202f, 0x279426fcf5f59740 }
|
||||
|
||||
struct limine_bootloader_info_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(char *) name;
|
||||
LIMINE_PTR(char *) version;
|
||||
LIMINE_PTR(char *)
|
||||
name;
|
||||
LIMINE_PTR(char *)
|
||||
version;
|
||||
};
|
||||
|
||||
struct limine_bootloader_info_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_bootloader_info_response *) response;
|
||||
LIMINE_PTR(struct limine_bootloader_info_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Stack size */
|
||||
|
||||
#define LIMINE_STACK_SIZE_REQUEST { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
|
||||
#define LIMINE_STACK_SIZE_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
|
||||
|
||||
struct limine_stack_size_response {
|
||||
uint64_t revision;
|
||||
@@ -101,13 +109,15 @@ struct limine_stack_size_response {
|
||||
struct limine_stack_size_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_stack_size_response *) response;
|
||||
LIMINE_PTR(struct limine_stack_size_response *)
|
||||
response;
|
||||
uint64_t stack_size;
|
||||
};
|
||||
|
||||
/* HHDM */
|
||||
|
||||
#define LIMINE_HHDM_REQUEST { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }
|
||||
#define LIMINE_HHDM_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }
|
||||
|
||||
struct limine_hhdm_response {
|
||||
uint64_t revision;
|
||||
@@ -117,12 +127,14 @@ struct limine_hhdm_response {
|
||||
struct limine_hhdm_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_hhdm_response *) response;
|
||||
LIMINE_PTR(struct limine_hhdm_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Framebuffer */
|
||||
|
||||
#define LIMINE_FRAMEBUFFER_REQUEST { LIMINE_COMMON_MAGIC, 0x9d5827dcd881dd75, 0xa3148604f6fab11b }
|
||||
#define LIMINE_FRAMEBUFFER_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x9d5827dcd881dd75, 0xa3148604f6fab11b }
|
||||
|
||||
#define LIMINE_FRAMEBUFFER_RGB 1
|
||||
|
||||
@@ -141,7 +153,8 @@ struct limine_video_mode {
|
||||
};
|
||||
|
||||
struct limine_framebuffer {
|
||||
LIMINE_PTR(void *) address;
|
||||
LIMINE_PTR(void *)
|
||||
address;
|
||||
uint64_t width;
|
||||
uint64_t height;
|
||||
uint64_t pitch;
|
||||
@@ -155,27 +168,32 @@ struct limine_framebuffer {
|
||||
uint8_t blue_mask_shift;
|
||||
uint8_t unused[7];
|
||||
uint64_t edid_size;
|
||||
LIMINE_PTR(void *) edid;
|
||||
LIMINE_PTR(void *)
|
||||
edid;
|
||||
/* Response revision 1 */
|
||||
uint64_t mode_count;
|
||||
LIMINE_PTR(struct limine_video_mode **) modes;
|
||||
LIMINE_PTR(struct limine_video_mode **)
|
||||
modes;
|
||||
};
|
||||
|
||||
struct limine_framebuffer_response {
|
||||
uint64_t revision;
|
||||
uint64_t framebuffer_count;
|
||||
LIMINE_PTR(struct limine_framebuffer **) framebuffers;
|
||||
LIMINE_PTR(struct limine_framebuffer **)
|
||||
framebuffers;
|
||||
};
|
||||
|
||||
struct limine_framebuffer_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_framebuffer_response *) response;
|
||||
LIMINE_PTR(struct limine_framebuffer_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Terminal */
|
||||
|
||||
#define LIMINE_TERMINAL_REQUEST { LIMINE_COMMON_MAGIC, 0xc8ac59310c2b0844, 0xa68d0c7265d38878 }
|
||||
#define LIMINE_TERMINAL_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0xc8ac59310c2b0844, 0xa68d0c7265d38878 }
|
||||
|
||||
#define LIMINE_TERMINAL_CB_DEC 10
|
||||
#define LIMINE_TERMINAL_CB_BELL 20
|
||||
@@ -214,28 +232,34 @@ typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uin
|
||||
struct LIMINE_DEPRECATED limine_terminal {
|
||||
uint64_t columns;
|
||||
uint64_t rows;
|
||||
LIMINE_PTR(struct limine_framebuffer *) framebuffer;
|
||||
LIMINE_PTR(struct limine_framebuffer *)
|
||||
framebuffer;
|
||||
};
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal_response {
|
||||
uint64_t revision;
|
||||
uint64_t terminal_count;
|
||||
LIMINE_PTR(struct limine_terminal **) terminals;
|
||||
LIMINE_PTR(limine_terminal_write) write;
|
||||
LIMINE_PTR(struct limine_terminal **)
|
||||
terminals;
|
||||
LIMINE_PTR(limine_terminal_write)
|
||||
write;
|
||||
};
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_terminal_response *) response;
|
||||
LIMINE_PTR(limine_terminal_callback) callback;
|
||||
LIMINE_PTR(struct limine_terminal_response *)
|
||||
response;
|
||||
LIMINE_PTR(limine_terminal_callback)
|
||||
callback;
|
||||
};
|
||||
|
||||
LIMINE_DEPRECATED_IGNORE_END
|
||||
|
||||
/* Paging mode */
|
||||
|
||||
#define LIMINE_PAGING_MODE_REQUEST { LIMINE_COMMON_MAGIC, 0x95c1a0edab0944cb, 0xa4e5cb3842f7488a }
|
||||
#define LIMINE_PAGING_MODE_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x95c1a0edab0944cb, 0xa4e5cb3842f7488a }
|
||||
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
#define LIMINE_PAGING_MODE_X86_64_4LVL 0
|
||||
@@ -266,14 +290,16 @@ struct limine_paging_mode_response {
|
||||
struct limine_paging_mode_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_paging_mode_response *) response;
|
||||
LIMINE_PTR(struct limine_paging_mode_response *)
|
||||
response;
|
||||
uint64_t mode;
|
||||
uint64_t flags;
|
||||
};
|
||||
|
||||
/* 5-level paging */
|
||||
|
||||
#define LIMINE_5_LEVEL_PAGING_REQUEST { LIMINE_COMMON_MAGIC, 0x94469551da9b3192, 0xebe5e86db7382888 }
|
||||
#define LIMINE_5_LEVEL_PAGING_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x94469551da9b3192, 0xebe5e86db7382888 }
|
||||
|
||||
LIMINE_DEPRECATED_IGNORE_START
|
||||
|
||||
@@ -284,14 +310,16 @@ struct LIMINE_DEPRECATED limine_5_level_paging_response {
|
||||
struct LIMINE_DEPRECATED limine_5_level_paging_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_5_level_paging_response *) response;
|
||||
LIMINE_PTR(struct limine_5_level_paging_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
LIMINE_DEPRECATED_IGNORE_END
|
||||
|
||||
/* SMP */
|
||||
|
||||
#define LIMINE_SMP_REQUEST { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
|
||||
#define LIMINE_SMP_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
|
||||
|
||||
struct limine_smp_info;
|
||||
|
||||
@@ -305,7 +333,8 @@ struct limine_smp_info {
|
||||
uint32_t processor_id;
|
||||
uint32_t lapic_id;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
LIMINE_PTR(limine_goto_address)
|
||||
goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
@@ -314,7 +343,8 @@ struct limine_smp_response {
|
||||
uint32_t flags;
|
||||
uint32_t bsp_lapic_id;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct limine_smp_info **) cpus;
|
||||
LIMINE_PTR(struct limine_smp_info **)
|
||||
cpus;
|
||||
};
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
@@ -324,7 +354,8 @@ struct limine_smp_info {
|
||||
uint32_t gic_iface_no;
|
||||
uint64_t mpidr;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
LIMINE_PTR(limine_goto_address)
|
||||
goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
@@ -333,7 +364,8 @@ struct limine_smp_response {
|
||||
uint32_t flags;
|
||||
uint64_t bsp_mpidr;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct limine_smp_info **) cpus;
|
||||
LIMINE_PTR(struct limine_smp_info **)
|
||||
cpus;
|
||||
};
|
||||
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
@@ -342,7 +374,8 @@ struct limine_smp_info {
|
||||
uint32_t processor_id;
|
||||
uint64_t hartid;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
LIMINE_PTR(limine_goto_address)
|
||||
goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
@@ -351,7 +384,8 @@ struct limine_smp_response {
|
||||
uint32_t flags;
|
||||
uint64_t bsp_hartid;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct limine_smp_info **) cpus;
|
||||
LIMINE_PTR(struct limine_smp_info **)
|
||||
cpus;
|
||||
};
|
||||
|
||||
#else
|
||||
@@ -361,13 +395,15 @@ struct limine_smp_response {
|
||||
struct limine_smp_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_smp_response *) response;
|
||||
LIMINE_PTR(struct limine_smp_response *)
|
||||
response;
|
||||
uint64_t flags;
|
||||
};
|
||||
|
||||
/* Memory map */
|
||||
|
||||
#define LIMINE_MEMMAP_REQUEST { LIMINE_COMMON_MAGIC, 0x67cf3d9d378a806f, 0xe304acdfc50c3c62 }
|
||||
#define LIMINE_MEMMAP_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x67cf3d9d378a806f, 0xe304acdfc50c3c62 }
|
||||
|
||||
#define LIMINE_MEMMAP_USABLE 0
|
||||
#define LIMINE_MEMMAP_RESERVED 1
|
||||
@@ -387,18 +423,21 @@ struct limine_memmap_entry {
|
||||
struct limine_memmap_response {
|
||||
uint64_t revision;
|
||||
uint64_t entry_count;
|
||||
LIMINE_PTR(struct limine_memmap_entry **) entries;
|
||||
LIMINE_PTR(struct limine_memmap_entry **)
|
||||
entries;
|
||||
};
|
||||
|
||||
struct limine_memmap_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_memmap_response *) response;
|
||||
LIMINE_PTR(struct limine_memmap_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Entry point */
|
||||
|
||||
#define LIMINE_ENTRY_POINT_REQUEST { LIMINE_COMMON_MAGIC, 0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a }
|
||||
#define LIMINE_ENTRY_POINT_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a }
|
||||
|
||||
typedef void (*limine_entry_point)(void);
|
||||
|
||||
@@ -409,102 +448,124 @@ struct limine_entry_point_response {
|
||||
struct limine_entry_point_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_entry_point_response *) response;
|
||||
LIMINE_PTR(limine_entry_point) entry;
|
||||
LIMINE_PTR(struct limine_entry_point_response *)
|
||||
response;
|
||||
LIMINE_PTR(limine_entry_point)
|
||||
entry;
|
||||
};
|
||||
|
||||
/* Kernel File */
|
||||
|
||||
#define LIMINE_KERNEL_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
|
||||
#define LIMINE_KERNEL_FILE_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
|
||||
|
||||
struct limine_kernel_file_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_file *) kernel_file;
|
||||
LIMINE_PTR(struct limine_file *)
|
||||
kernel_file;
|
||||
};
|
||||
|
||||
struct limine_kernel_file_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_kernel_file_response *) response;
|
||||
LIMINE_PTR(struct limine_kernel_file_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Module */
|
||||
|
||||
#define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
|
||||
#define LIMINE_MODULE_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
|
||||
|
||||
#define LIMINE_INTERNAL_MODULE_REQUIRED (1 << 0)
|
||||
|
||||
struct limine_internal_module {
|
||||
LIMINE_PTR(const char *) path;
|
||||
LIMINE_PTR(const char *) cmdline;
|
||||
LIMINE_PTR(const char *)
|
||||
path;
|
||||
LIMINE_PTR(const char *)
|
||||
cmdline;
|
||||
uint64_t flags;
|
||||
};
|
||||
|
||||
struct limine_module_response {
|
||||
uint64_t revision;
|
||||
uint64_t module_count;
|
||||
LIMINE_PTR(struct limine_file **) modules;
|
||||
LIMINE_PTR(struct limine_file **)
|
||||
modules;
|
||||
};
|
||||
|
||||
struct limine_module_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_module_response *) response;
|
||||
LIMINE_PTR(struct limine_module_response *)
|
||||
response;
|
||||
|
||||
/* Request revision 1 */
|
||||
uint64_t internal_module_count;
|
||||
LIMINE_PTR(struct limine_internal_module **) internal_modules;
|
||||
LIMINE_PTR(struct limine_internal_module **)
|
||||
internal_modules;
|
||||
};
|
||||
|
||||
/* RSDP */
|
||||
|
||||
#define LIMINE_RSDP_REQUEST { LIMINE_COMMON_MAGIC, 0xc5e77b6b397e7b43, 0x27637845accdcf3c }
|
||||
#define LIMINE_RSDP_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0xc5e77b6b397e7b43, 0x27637845accdcf3c }
|
||||
|
||||
struct limine_rsdp_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) address;
|
||||
LIMINE_PTR(void *)
|
||||
address;
|
||||
};
|
||||
|
||||
struct limine_rsdp_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_rsdp_response *) response;
|
||||
LIMINE_PTR(struct limine_rsdp_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* SMBIOS */
|
||||
|
||||
#define LIMINE_SMBIOS_REQUEST { LIMINE_COMMON_MAGIC, 0x9e9046f11e095391, 0xaa4a520fefbde5ee }
|
||||
#define LIMINE_SMBIOS_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x9e9046f11e095391, 0xaa4a520fefbde5ee }
|
||||
|
||||
struct limine_smbios_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) entry_32;
|
||||
LIMINE_PTR(void *) entry_64;
|
||||
LIMINE_PTR(void *)
|
||||
entry_32;
|
||||
LIMINE_PTR(void *)
|
||||
entry_64;
|
||||
};
|
||||
|
||||
struct limine_smbios_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_smbios_response *) response;
|
||||
LIMINE_PTR(struct limine_smbios_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* EFI system table */
|
||||
|
||||
#define LIMINE_EFI_SYSTEM_TABLE_REQUEST { LIMINE_COMMON_MAGIC, 0x5ceba5163eaaf6d6, 0x0a6981610cf65fcc }
|
||||
#define LIMINE_EFI_SYSTEM_TABLE_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x5ceba5163eaaf6d6, 0x0a6981610cf65fcc }
|
||||
|
||||
struct limine_efi_system_table_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) address;
|
||||
LIMINE_PTR(void *)
|
||||
address;
|
||||
};
|
||||
|
||||
struct limine_efi_system_table_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_efi_system_table_response *) response;
|
||||
LIMINE_PTR(struct limine_efi_system_table_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Boot time */
|
||||
|
||||
#define LIMINE_BOOT_TIME_REQUEST { LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
|
||||
#define LIMINE_BOOT_TIME_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
|
||||
|
||||
struct limine_boot_time_response {
|
||||
uint64_t revision;
|
||||
@@ -514,12 +575,14 @@ struct limine_boot_time_response {
|
||||
struct limine_boot_time_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_boot_time_response *) response;
|
||||
LIMINE_PTR(struct limine_boot_time_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Kernel address */
|
||||
|
||||
#define LIMINE_KERNEL_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
|
||||
#define LIMINE_KERNEL_ADDRESS_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
|
||||
|
||||
struct limine_kernel_address_response {
|
||||
uint64_t revision;
|
||||
@@ -530,22 +593,26 @@ struct limine_kernel_address_response {
|
||||
struct limine_kernel_address_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_kernel_address_response *) response;
|
||||
LIMINE_PTR(struct limine_kernel_address_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
/* Device Tree Blob */
|
||||
|
||||
#define LIMINE_DTB_REQUEST { LIMINE_COMMON_MAGIC, 0xb40ddb48fb54bac7, 0x545081493f81ffb7 }
|
||||
#define LIMINE_DTB_REQUEST \
|
||||
{ LIMINE_COMMON_MAGIC, 0xb40ddb48fb54bac7, 0x545081493f81ffb7 }
|
||||
|
||||
struct limine_dtb_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) dtb_ptr;
|
||||
LIMINE_PTR(void *)
|
||||
dtb_ptr;
|
||||
};
|
||||
|
||||
struct limine_dtb_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_dtb_response *) response;
|
||||
LIMINE_PTR(struct limine_dtb_response *)
|
||||
response;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -33,13 +33,13 @@ void setup_syscalls() {
|
||||
uint64_t bytes;
|
||||
} __attribute__((__packed__)) newstar{};
|
||||
|
||||
newstar.star.ret_cs_ss = (GDTSEL(gdt_data_user) - 8) | 0x3;
|
||||
assert(newstar.star.ret_cs_ss + 8 == (GDTSEL(gdt_data_user) | 0x3));
|
||||
assert(newstar.star.ret_cs_ss + 16 == (GDTSEL(gdt_code_user) | 0x3));
|
||||
newstar.star.ret_cs_ss = (Arch::GDT::gdt_data_user.selector() - 8) | 0x3;
|
||||
assert(newstar.star.ret_cs_ss + 8 == (Arch::GDT::gdt_data_user.selector() | 0x3));
|
||||
assert(newstar.star.ret_cs_ss + 16 == (Arch::GDT::gdt_code_user.selector() | 0x3));
|
||||
|
||||
newstar.star.call_cs_ss = (GDTSEL(gdt_code));
|
||||
assert(newstar.star.call_cs_ss == GDTSEL(gdt_code));
|
||||
assert(newstar.star.call_cs_ss + 8 == GDTSEL(gdt_data));
|
||||
newstar.star.call_cs_ss = (Arch::GDT::gdt_code.selector());
|
||||
assert(newstar.star.call_cs_ss == Arch::GDT::gdt_code.selector());
|
||||
assert(newstar.star.call_cs_ss + 8 == Arch::GDT::gdt_data.selector());
|
||||
|
||||
wrmsr(0xc0000081, newstar.bytes);
|
||||
wrmsr(0xc0000082, reinterpret_cast<uint64_t>(&_syscall_entrypoint));
|
||||
|
||||
@@ -30,8 +30,8 @@ void sanity_check_frame(struct task_frame *cur_frame) {
|
||||
assert(cur_frame->ss != 0);
|
||||
assert(cur_frame->cs != 0);
|
||||
assert(cur_frame->sp != 0);
|
||||
assert2((cur_frame->ss == GDTSEL(gdt_data) || (cur_frame->ss == GDTSEL(gdt_data_user)) | 0x3), "SS wrong!");
|
||||
assert2((cur_frame->cs == GDTSEL(gdt_code) || (cur_frame->ss == GDTSEL(gdt_code_user)) | 0x3), "CS wrong!");
|
||||
assert2((cur_frame->ss == Arch::GDT::gdt_data.selector() || (cur_frame->ss == Arch::GDT::gdt_data_user.selector()) | 0x3), "SS wrong!");
|
||||
assert2((cur_frame->cs == Arch::GDT::gdt_code.selector() || (cur_frame->ss == Arch::GDT::gdt_code_user.selector()) | 0x3), "CS wrong!");
|
||||
}
|
||||
|
||||
std::atomic<uint64_t> max_pid = 0;
|
||||
@@ -120,8 +120,8 @@ struct Task *new_ktask(void (*fn)(), const char *name, bool start) {
|
||||
assert((newt->frame.sp & 0xFULL) == 8);
|
||||
|
||||
newt->frame.ip = (uint64_t) fn;
|
||||
newt->frame.cs = GDTSEL(gdt_code);
|
||||
newt->frame.ss = GDTSEL(gdt_data);
|
||||
newt->frame.cs = Arch::GDT::gdt_code.selector();
|
||||
newt->frame.ss = Arch::GDT::gdt_data.selector();
|
||||
|
||||
for (int i = 0; i < 512; i++) newt->fxsave[i] = 0;
|
||||
|
||||
@@ -157,8 +157,8 @@ struct Task *new_utask(void (*entrypoint)(), const char *name) {
|
||||
strcpy(name, newt->name);
|
||||
|
||||
newt->frame.ip = (uint64_t) entrypoint;
|
||||
newt->frame.cs = GDTSEL(gdt_code_user) | 0x3;
|
||||
newt->frame.ss = GDTSEL(gdt_data_user) | 0x3;
|
||||
newt->frame.cs = Arch::GDT::gdt_code_user.selector() | 0x3;
|
||||
newt->frame.ss = Arch::GDT::gdt_data_user.selector() | 0x3;
|
||||
|
||||
for (int i = 0; i < 512; i++) newt->fxsave[i] = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user