Merge branch 'limine2' into limine

This commit is contained in:
TomAwezome 2022-08-21 06:41:47 -04:00
commit f2f7fa953f
5 changed files with 58 additions and 15 deletions

View file

@ -70,7 +70,7 @@ if [ ! -d "ovmf" ]; then
fi
echo "Testing..."
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -bios ovmf/OVMF.fd
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -bios ovmf/OVMF.fd -no-reboot -no-shutdown
echo "Deleting temp folder..."
rm -rf $TMPDIR

View file

@ -33,7 +33,7 @@ MEM_E820:: DU8 MEM_E820_ENTRIES_NUM * sizeof(CMemE820) DUP (0);
MEM_PHYSICAL_SPACE:: DU64 0;
SYS_GDT_PTR:: DU16 sizeof(CGDT) - 1;
DU64 0;
SYS_PCI_BUSES:: DU16 0;
SYS_PCI_BUSES:: DU16 256;
ALIGN 16, OC_NOP
@ -71,6 +71,9 @@ SYS_FRAMEBUFFER_EDID_ADDR: DU8 sizeof(U8 *);
SYS_VBE_INFO:: DU8 sizeof(CVBEInfo) DUP(0);
SYS_VBE_MODES:: DU8 sizeof(CVBEModeShort) * VBE_MODES_NUM DUP(0);
ALIGN 16, OC_NOP
DU64 0x5439581381193aaf, 0x2a8a30e69ec9f845;
SYS_VBE_FINAL_MODE:: DU8 sizeof(CVBEMode) DUP(0);
SYS_VBE_FINAL_MODE_NUM::DU16 0; //mode number of final mode set
#assert $$ - SYS_KERNEL == sizeof(CKernel) - sizeof(CZXE)

View file

@ -89,9 +89,8 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
MOV AX, CGDT.boot_ds //LOAD DS SELECTOR
MOV DS, AX
BTS U32 [SYS_RUN_LEVEL], RLf_32BIT
MOV ESI, U32 [SYS_BOOT_PATCH_TABLE_BASE]
MOV EDI, U32 [MEM_BOOT_BASE]
//MOV ESI, U32 [SYS_BOOT_PATCH_TABLE_BASE]
//MOV EDI, U32 [MEM_BOOT_BASE]
MOV AX, CGDT.ds
MOV DS, AX
@ -104,6 +103,7 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
//Patch abs addresses
MOV ECX, U32 CPatchTableAbsAddr.abs_address_count[ESI]
LEA ESI, U32 CPatchTableAbsAddr.abs_address[ESI]
@@05: LODSD
ADD EAX, EDI
ADD U32 [EAX], EDI
@ -114,6 +114,7 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
DU16 CGDT.cs32;
@@10: BTS U32 [SYS_RUN_LEVEL], RLf_PATCHED
BTS U32 [SYS_RUN_LEVEL], RLf_32BIT
CALL SYS_FIND_PCIBIOS_SERVICE_DIR
CALL SYS_FIND_PCI_SERVICES

View file

@ -96,7 +96,7 @@ CTSS *TSSNew(I64 cpu_num)
tss->tr = offset(CGDT.tr) + cpu_num * 16;
tss->tr_ring3= offset(CGDT.tr_ring3) + cpu_num * 16;
d = (&sys_gdt)(U8 *) + tss->tr;
d = (0x80d8)(U8 *) + tss->tr;
d1 = d(U8 *) + 4;
*d = 0x0000FFFF;
*d1 = 0x008F8900;
@ -106,7 +106,7 @@ CTSS *TSSNew(I64 cpu_num)
*d1++ = tss >> 32;
*d1 = 0;
d = (&sys_gdt)(U8 *) + tss->tr_ring3;
d = (0x80d8)(U8 *) + tss->tr_ring3;
d1 = d(U8 *) + 4;
*d = 0x0000FFFF;
*d1 = 0x008FE900;
@ -193,6 +193,7 @@ U0 MPAPICInit()
RAXSet(Gs->tss->tr);
LTR AX
if (Gs->num)
{
IntInit1;

View file

@ -13,6 +13,11 @@ static volatile struct limine_kernel_address_request kernel_address_request = {
.revision = 0
};
static volatile struct limine_hhdm_request hhdm_request = {
.id = LIMINE_HHDM_REQUEST,
.revision = 0
};
static volatile struct limine_memmap_request memmap_request = {
.id = LIMINE_MEMMAP_REQUEST,
.revision = 0
@ -135,11 +140,41 @@ struct E801 get_E801(void) {
return E801;
}
struct CVBEMode {
uint16_t attributes, pad0[7], pitch, width, height;
uint8_t pad1[3], bpp, pad2, memory_model, pad[12];
uint32_t framebuffer;
uint16_t pad3[9];
uint32_t max_pixel_clock;
uint8_t reserved[190];
} __attribute__((packed));
void _start(void) {
struct limine_file *kernel = module_request.response->modules[0];
struct CKernel *CKernel = (void *)0x7c00;
memcpy(CKernel, kernel->address, kernel->size);
struct CVBEMode *sys_vbe_mode;
for (uint64_t *p = (uint64_t *)CKernel; ; p++) {
if (*p != 0x5439581381193aaf) {
continue;
}
p++;
if (*p != 0x2a8a30e69ec9f845) {
continue;
}
p++;
sys_vbe_mode = (void *)p;
break;
}
struct limine_framebuffer *fb = framebuffer_request.response->framebuffers[0];
sys_vbe_mode->pitch = fb->pitch;
sys_vbe_mode->width = fb->width;
sys_vbe_mode->height = fb->height;
sys_vbe_mode->bpp = fb->bpp;
sys_vbe_mode->framebuffer = (uintptr_t)fb->address - hhdm_request.response->offset;
void *CORE0_32BIT_INIT;
for (uint64_t *p = (uint64_t *)CKernel; ; p++) {
if (*p != 0xaa23c08ed10bd4d7) {
@ -157,17 +192,20 @@ void _start(void) {
CKernel->boot_src = BOOT_SRC_RAM;
CKernel->boot_blk = 0;
CKernel->boot_patch_table_base = (uintptr_t)CKernel + CKernel->h.patch_table_offset;
// asm volatile ("jmp ." ::"a"(CKernel->boot_patch_table_base));
CKernel->sys_run_level = RLF_VESA | RLF_16BIT;
CKernel->boot_base = (uintptr_t)&CKernel->jmp;
CKernel->sys_gdt.boot_ds.lo = 0x000093000000ffff;
CKernel->sys_gdt.boot_cs.lo = 0x00009a000000ffff;
CKernel->sys_gdt.cs32.lo = 0x00cf9a000000ffff;
CKernel->sys_gdt.cs64.lo = 0x00af9b000000ffff;
CKernel->sys_gdt.cs64_ring3.lo = 0x00affb000000ffff;
CKernel->sys_gdt.ds.lo = 0x00af93000000ffff;
CKernel->sys_gdt.ds_ring3.lo = 0x00aff3000000ffff;
CKernel->sys_gdt.boot_ds.lo = 0x00CF92000000FFFF;
CKernel->sys_gdt.boot_cs.lo = 0x00CF9A000000FFFF;
CKernel->sys_gdt.cs32.lo = 0x00CF9A000000FFFF;
CKernel->sys_gdt.cs64.lo = 0x00209A0000000000;
CKernel->sys_gdt.cs64_ring3.lo = 0x0020FA0000000000;
CKernel->sys_gdt.ds.lo = 0x00CF92000000FFFF;
CKernel->sys_gdt.ds_ring3.lo = 0x00CFF2000000FFFF;
CKernel->sys_gdt_ptr.limit = sizeof(CKernel->sys_gdt) - 1;
CKernel->sys_gdt_ptr.base = (void *)&CKernel->sys_gdt;
@ -207,7 +245,7 @@ void _start(void) {
void *target_addr = (void *)lower - kernel_address_request.response->virtual_base;
target_addr += kernel_address_request.response->physical_base;
asm volatile ("jmp *%0" :: "a"(target_addr), "b"(CORE0_32BIT_INIT), "c"(&CKernel->sys_gdt_ptr) : "memory");
asm volatile ("jmp *%0" :: "a"(target_addr), "b"(CORE0_32BIT_INIT), "c"(&CKernel->sys_gdt_ptr), "S"(CKernel->boot_patch_table_base), "D"(CKernel->boot_base) : "memory");
__builtin_unreachable();
}