Compare commits
2 Commits
c6c12d93a0
...
c936910199
Author | SHA1 | Date | |
---|---|---|---|
c936910199 | |||
922fee88c7 |
23
Makefile
23
Makefile
@ -23,25 +23,26 @@ clean:
|
|||||||
rm -f mop2.iso base.img
|
rm -f mop2.iso base.img
|
||||||
|
|
||||||
base:
|
base:
|
||||||
dd if=/dev/zero of=base.img bs=1M count=32
|
dd if=/dev/zero of=base.img bs=1M count=10
|
||||||
mformat -F -i base.img ::
|
mformat -F -i base.img ::
|
||||||
mcopy -i base.img Makefile ::
|
mcopy -i base.img Makefile ::
|
||||||
mdir -i base.img ::
|
mdir -i base.img ::
|
||||||
|
|
||||||
iso:
|
iso:
|
||||||
rm -rf iso_root
|
@rm -rf iso_root
|
||||||
mkdir -p iso_root/boot
|
@mkdir -p iso_root/boot
|
||||||
cp -v kernel/mop2 iso_root/boot
|
@cp -v kernel/mop2 iso_root/boot
|
||||||
mkdir -p iso_root/boot/limine
|
@cp -v base.img iso_root
|
||||||
cp -v limine.conf limine/limine-bios.sys limine/limine-bios-cd.bin \
|
@mkdir -p iso_root/boot/limine
|
||||||
|
@cp -v limine.conf limine/limine-bios.sys limine/limine-bios-cd.bin \
|
||||||
limine/limine-uefi-cd.bin iso_root/boot/limine
|
limine/limine-uefi-cd.bin iso_root/boot/limine
|
||||||
mkdir -p iso_root/EFI/BOOT
|
@mkdir -p iso_root/EFI/BOOT
|
||||||
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT
|
@cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT
|
||||||
cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT
|
@cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT
|
||||||
xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \
|
@xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \
|
||||||
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
|
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
|
||||||
-apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \
|
-apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \
|
||||||
-efi-boot-part --efi-boot-image --protective-msdos-label \
|
-efi-boot-part --efi-boot-image --protective-msdos-label \
|
||||||
iso_root -o mop2.iso
|
iso_root -o mop2.iso
|
||||||
./limine/limine bios-install mop2.iso
|
@./limine/limine bios-install mop2.iso
|
||||||
|
|
||||||
|
@ -40,12 +40,19 @@ static volatile struct limine_framebuffer_request FB_REQ = {
|
|||||||
.id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0,
|
.id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static volatile struct limine_module_request MODULE_REQ = {
|
||||||
|
.id = LIMINE_MODULE_REQUEST, .revision = 0,
|
||||||
|
};
|
||||||
|
|
||||||
void bootinfo_init(void) {
|
void bootinfo_init(void) {
|
||||||
if (FB_REQ.response == NULL || FB_REQ.response->framebuffer_count < 1) {
|
if (FB_REQ.response == NULL || FB_REQ.response->framebuffer_count < 1) {
|
||||||
hal_hang();
|
hal_hang();
|
||||||
}
|
}
|
||||||
BOOT_INFO.fb = FB_REQ.response->framebuffers[0];
|
BOOT_INFO.fb = FB_REQ.response->framebuffers[0];
|
||||||
|
|
||||||
|
struct limine_module_response *modulesres= MODULE_REQ.response;
|
||||||
|
BOOT_INFO.modules = modulesres;
|
||||||
|
|
||||||
struct limine_paging_mode_response *pagingres = PAGING_REQ.response;
|
struct limine_paging_mode_response *pagingres = PAGING_REQ.response;
|
||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__)
|
||||||
if (pagingres->mode != LIMINE_PAGING_MODE_X86_64_4LVL) {
|
if (pagingres->mode != LIMINE_PAGING_MODE_X86_64_4LVL) {
|
||||||
|
@ -22,6 +22,7 @@ typedef struct {
|
|||||||
LIMINE_PTR(struct limine_smp_response *) smp;
|
LIMINE_PTR(struct limine_smp_response *) smp;
|
||||||
uint64_t smp_bspindex;
|
uint64_t smp_bspindex;
|
||||||
LIMINE_PTR(struct limine_framebuffer *) fb;
|
LIMINE_PTR(struct limine_framebuffer *) fb;
|
||||||
|
LIMINE_PTR(struct limine_module_response *) modules;
|
||||||
} BootInfo;
|
} BootInfo;
|
||||||
|
|
||||||
extern BootInfo BOOT_INFO;
|
extern BootInfo BOOT_INFO;
|
||||||
|
@ -55,7 +55,7 @@ static uint64_t gdt_curretbase(void) {
|
|||||||
return gdtr.base;
|
return gdtr.base;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gdt_setenty(GdtEntry *entry, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
|
void gdt_setentry(GdtEntry *entry, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
|
||||||
entry->baselow = base & 0xffff;
|
entry->baselow = base & 0xffff;
|
||||||
entry->basemid = (base >> 16) & 0xff;
|
entry->basemid = (base >> 16) & 0xff;
|
||||||
entry->basehigh = (base >> 24) & 0xff;
|
entry->basehigh = (base >> 24) & 0xff;
|
||||||
@ -74,7 +74,7 @@ void gdt_init(void) {
|
|||||||
uint64_t tss_base = (uint64_t)&tss;
|
uint64_t tss_base = (uint64_t)&tss;
|
||||||
uint32_t tss_limit = sizeof(tss) - 1;
|
uint32_t tss_limit = sizeof(tss) - 1;
|
||||||
|
|
||||||
gdt_setenty(&curgdt->tsslow, tss_base & 0xFFFFFFFF, tss_limit, GDT_PRESENT | GDT_TSS, 0x0);
|
gdt_setentry(&curgdt->tsslow, tss_base & 0xFFFFFFFF, tss_limit, GDT_PRESENT | GDT_TSS, 0x0);
|
||||||
|
|
||||||
GdtEntry *tsshigh = &curgdt->tsshigh;
|
GdtEntry *tsshigh = &curgdt->tsshigh;
|
||||||
tsshigh->baselow = (tss_base >> 32) & 0xffff;
|
tsshigh->baselow = (tss_base >> 32) & 0xffff;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
|
#include "idt.h"
|
||||||
|
|
||||||
void hal_init(void) {
|
void hal_init(void) {
|
||||||
if (!serial_init()) {
|
if (!serial_init()) {
|
||||||
@ -11,6 +12,7 @@ void hal_init(void) {
|
|||||||
}
|
}
|
||||||
LOG("hal", "serial init\n");
|
LOG("hal", "serial init\n");
|
||||||
gdt_init();
|
gdt_init();
|
||||||
|
idt_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((noreturn)) void hal_hang(void) {
|
__attribute__((noreturn)) void hal_hang(void) {
|
||||||
|
25
kernel/hal/x86_64/idt.c
Normal file
25
kernel/hal/x86_64/idt.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include "idt.h"
|
||||||
|
#include "kprintf.h"
|
||||||
|
|
||||||
|
#define ENTRIES 256
|
||||||
|
static IdtGate idtgates[ENTRIES] = {0};
|
||||||
|
static Idt idt;
|
||||||
|
|
||||||
|
void idt_setgate(int i, uint64_t handler, uint8_t flags) {
|
||||||
|
idtgates[i].isrlow = (uint16_t)handler;
|
||||||
|
idtgates[i].kernelcs = 40;
|
||||||
|
idtgates[i].ist = 0;
|
||||||
|
idtgates[i].resv = 0;
|
||||||
|
idtgates[i].attrs = flags;
|
||||||
|
idtgates[i].isrmid = (uint16_t)(handler >> 16);
|
||||||
|
idtgates[i].isrhigh = (uint16_t)(handler >> 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void idt_init(void) {
|
||||||
|
idt.base = (uint64_t)&idtgates;
|
||||||
|
idt.limit = ENTRIES * sizeof(IdtGate) - 1;
|
||||||
|
asm volatile("lidt %0" :: "m"(idt) : "memory");
|
||||||
|
|
||||||
|
LOG("idt", "idt init\n");
|
||||||
|
}
|
24
kernel/hal/x86_64/idt.h
Normal file
24
kernel/hal/x86_64/idt.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef HAL_IDT_H_
|
||||||
|
#define HAL_IDT_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "compiler/attr.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t isrlow;
|
||||||
|
uint16_t kernelcs;
|
||||||
|
uint8_t ist;
|
||||||
|
uint8_t attrs;
|
||||||
|
uint16_t isrmid;
|
||||||
|
uint32_t isrhigh;
|
||||||
|
uint32_t resv;
|
||||||
|
} PACKED IdtGate;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t limit;
|
||||||
|
uint64_t base;
|
||||||
|
} PACKED Idt;
|
||||||
|
|
||||||
|
void idt_init(void);
|
||||||
|
|
||||||
|
#endif // HAL_IDT_H_
|
@ -1,3 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
qemu-system-x86_64 -m 4g -cdrom mop2.iso -boot d -serial stdio $@
|
set -x
|
||||||
|
|
||||||
|
qemu-system-x86_64 -cpu qemu64,+pdpe1gb -m 4G -cdrom mop2.iso -boot d -serial stdio $@
|
||||||
|
Reference in New Issue
Block a user