diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 6 | ||||
-rw-r--r-- | kernel/drivers/cpu.c | 20 | ||||
-rw-r--r-- | kernel/drivers/fb.c | 4 | ||||
-rw-r--r-- | kernel/entry.asm | 41 | ||||
-rw-r--r-- | kernel/features/io.c | 4 | ||||
-rw-r--r-- | kernel/features/mm.c | 10 | ||||
-rw-r--r-- | kernel/inc/fb.h | 2 | ||||
-rw-r--r-- | kernel/inc/io.h | 2 | ||||
-rw-r--r-- | kernel/inc/mm.h | 2 | ||||
-rw-r--r-- | kernel/inc/multiboot.h | 124 | ||||
-rw-r--r-- | kernel/link.ld | 2 | ||||
-rw-r--r-- | kernel/main.c | 19 | ||||
-rw-r--r-- | kernel/multiboot.c | 17 |
13 files changed, 219 insertions, 34 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 60b4ee7..e51469d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,6 +1,8 @@ # MIT License, Copyright (c) 2020 Marvin Borner # acpi.o fpu.o -COBJS = main.o \ +COBJS = entry_asm.o \ + main.o \ + multiboot.o \ drivers/interrupts.o \ drivers/interrupts_asm.o \ drivers/cpu.o \ @@ -37,4 +39,4 @@ all: compile compile: $(COBJS) @mkdir -p $(BUILD)/apps/kernel/ - @$(LD) -N -z max-page-size=0x1000 -ekernel_main -Tlink.ld -o $(BUILD)/apps/kernel/exec -L$(BUILD) $+ -lk + @$(LD) -N -z max-page-size=0x1000 -eboot_entry -Tlink.ld -o $(BUILD)/apps/kernel/exec -L$(BUILD) $+ -lk diff --git a/kernel/drivers/cpu.c b/kernel/drivers/cpu.c index 62b0328..2c86008 100644 --- a/kernel/drivers/cpu.c +++ b/kernel/drivers/cpu.c @@ -91,17 +91,19 @@ void fpu_restore(void) __asm__ volatile("fxrstor (%0)" ::"r"(fpu_state)); } -PROTECTED extern u32 tss_entry; void tss_set_stack(u32 ss, u32 esp) { - assert(tss_entry && ss && esp); - struct { - u32 prev; - u32 esp0; - u32 ss0; - } *tss = (void *)tss_entry; - tss->esp0 = esp; - tss->ss0 = ss; + UNUSED(ss); + UNUSED(esp); + return; + /* assert(tss_entry && ss && esp); */ + /* struct { */ + /* u32 prev; */ + /* u32 esp0; */ + /* u32 ss0; */ + /* } *tss = (void *)tss_entry; */ + /* tss->esp0 = esp; */ + /* tss->ss0 = ss; */ } CLEAR static struct cpuid cpuid(u32 code) diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c index f62c486..7c02919 100644 --- a/kernel/drivers/fb.c +++ b/kernel/drivers/fb.c @@ -60,9 +60,9 @@ void fb_map_buffer(struct page_dir *dir, struct vid_info *boot) memory_map_identity(dir, memory_range_around((u32)vbe->fb, size), MEMORY_USER); } -CLEAR void fb_install(struct vid_info *boot) +CLEAR void fb_install(void) { - info = boot; + //info = boot; struct io_dev *dev = zalloc(sizeof(*dev)); dev->control = fb_ioctl; diff --git a/kernel/entry.asm b/kernel/entry.asm new file mode 100644 index 0000000..10b6b25 --- /dev/null +++ b/kernel/entry.asm @@ -0,0 +1,41 @@ +bits 32 + +%define STACK_POINTER 0x00500000 ; The initial stack pointer in kernel mode +%define MULTIBOOT_MAGIC 0x1badb002 +%define MULTIBOOT_PAGE_ALIGN 0x1 +%define MULTIBOOT_MEMORY_INFO 0x2 +%define MULTIBOOT_VIDEO_MODE 0x4 +%define MULTIBOOT_FLAGS (MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_VIDEO_MODE) +%define MULTIBOOT_CHECKSUM -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) + +section .text +align 4 + +dd MULTIBOOT_MAGIC +dd MULTIBOOT_FLAGS +dd MULTIBOOT_CHECKSUM + +; MULTIBOOT_MEMORY_INFO +dd 0x00000000 +dd 0x00000000 +dd 0x00000000 +dd 0x00000000 +dd 0x00000000 + +; MULTIBOOT_VIDEO_MODE +dd 0x00000000 +dd 1280 +dd 1024 +dd 32 + +global boot_entry +extern kernel_main +boot_entry: + mov esp, STACK_POINTER + push ebx + push eax + + cli + call kernel_main + hlt + jmp $ diff --git a/kernel/features/io.c b/kernel/features/io.c index ac599e2..eb4b7a5 100644 --- a/kernel/features/io.c +++ b/kernel/features/io.c @@ -208,7 +208,7 @@ void io_unblock_pid(u32 pid) proc_yield(); } -CLEAR void io_install(struct boot_info *boot) +CLEAR void io_install(void) { for (u32 i = 0; i < IO_MAX; i++) io_listeners[i] = list_new(); @@ -230,6 +230,6 @@ CLEAR void io_install(struct boot_info *boot) timer_install(); logger_install(); - fb_install(boot->vid); + fb_install(); bus_install(); } diff --git a/kernel/features/mm.c b/kernel/features/mm.c index a3812bd..39a6316 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -719,10 +719,10 @@ void memory_user_hook(void) } } -CLEAR void memory_install(struct boot_info *boot) +CLEAR void memory_install(void) { - struct mem_info *mem_info = boot->mem; - struct vid_info *vid_info = boot->vid; + struct mem_info *mem_info = NULL; + struct vid_info *vid_info = NULL; for (struct mmap_boot *p = mem_info->start; (u32)(p - mem_info->start) < mem_info->size; p++) { @@ -774,10 +774,10 @@ CLEAR void memory_install(struct boot_info *boot) // Map framebuffer memory_map_identity(&kernel_dir, memory_range_around((u32)vid_info->vbe, 0x1000), MEMORY_NONE); - fb_map_buffer(virtual_kernel_dir(), vid_info); + /* fb_map_buffer(virtual_kernel_dir(), vid_info); */ // Map TSS - memory_map_identity(&kernel_dir, memory_range_around(boot->tss, 0x1000), MEMORY_NONE); + //memory_map_identity(&kernel_dir, memory_range_around(boot->tss, 0x1000), MEMORY_NONE); // Unmap NULL byte/page struct memory_range zero = memory_range(0, PAGE_SIZE); diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h index 052f3d2..46f9020 100644 --- a/kernel/inc/fb.h +++ b/kernel/inc/fb.h @@ -7,6 +7,6 @@ #include <mm.h> void fb_map_buffer(struct page_dir *dir, struct vid_info *boot) NONNULL; -void fb_install(struct vid_info *boot) NONNULL; +void fb_install(void) NONNULL; #endif diff --git a/kernel/inc/io.h b/kernel/inc/io.h index ed7920e..5d51f89 100644 --- a/kernel/inc/io.h +++ b/kernel/inc/io.h @@ -16,7 +16,7 @@ struct io_dev { res (*ready)(void); }; -void io_install(struct boot_info *boot); +void io_install(void); void io_add(enum io_type io, struct io_dev *dev) NONNULL; // No NONNULL on syscalls diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h index e912fec..1652695 100644 --- a/kernel/inc/mm.h +++ b/kernel/inc/mm.h @@ -146,6 +146,6 @@ res memory_sys_free(struct page_dir *dir, u32 addr); res memory_sys_shaccess(struct page_dir *dir, u32 id, u32 *addr, u32 *size); void memory_user_hook(void); -void memory_install(struct boot_info *boot) NONNULL; +void memory_install(void) NONNULL; #endif diff --git a/kernel/inc/multiboot.h b/kernel/inc/multiboot.h new file mode 100644 index 0000000..f9851fb --- /dev/null +++ b/kernel/inc/multiboot.h @@ -0,0 +1,124 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef MULTIBOOT_H +#define MULTIBOOT_H + +#define MULTIBOOT_MAGIC 0x2badb002 +#define MULTIBOOT_INFO_MEMORY 0x00000001 +#define MULTIBOOT_INFO_BOOTDEV 0x00000002 +#define MULTIBOOT_INFO_CMDLINE 0x00000004 +#define MULTIBOOT_INFO_MODS 0x00000008 +#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 +#define MULTIBOOT_INFO_ELF_SHDR 0x00000020 +#define MULTIBOOT_INFO_MEM_MAP 0x00000040 +#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 +#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 +#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 +#define MULTIBOOT_INFO_APM_TABLE 0x00000400 +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 + +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + +#define MULTIBOOT_MEMORY_AVAILABLE 1 +#define MULTIBOOT_MEMORY_RESERVED 2 +#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 +#define MULTIBOOT_MEMORY_NVS 4 +#define MULTIBOOT_MEMORY_BADRAM 5 + +#include <def.h> + +struct multiboot_aout_symbol_table { + u32 tabsize; + u32 strsize; + u32 addr; + u32 reserved; +}; + +struct multiboot_elf_section_header_table { + u32 num; + u32 size; + u32 addr; + u32 shndx; +}; + +struct multiboot_info { + u32 flags; + + u32 mem_lower; + u32 mem_upper; + + u32 boot_device; + + u32 cmdline; + + u32 mods_count; + u32 mods_addr; + + union { + struct multiboot_aout_symbol_table aout_sym; + struct multiboot_elf_section_header_table elf_sec; + } u; + + u32 mmap_length; + u32 mmap_addr; + + u32 drives_length; + u32 drives_addr; + + u32 config_table; + + u32 boot_loader_name; + + u32 apm_table; + + u32 vbe_control_info; + u32 vbe_mode_info; + u16 vbe_mode; + u16 vbe_interface_seg; + u16 vbe_interface_off; + u16 vbe_interface_len; + + u64 framebuffer_addr; + u32 framebuffer_pitch; + u32 framebuffer_width; + u32 framebuffer_height; + u8 framebuffer_bpp; + u8 framebuffer_type; + union { + struct { + u32 framebuffer_palette_addr; + u16 framebuffer_palette_num_colors; + } palette; + struct { + u8 framebuffer_red_field_position; + u8 framebuffer_red_mask_size; + u8 framebuffer_green_field_position; + u8 framebuffer_green_mask_size; + u8 framebuffer_blue_field_position; + u8 framebuffer_blue_mask_size; + } colors; + } framebuffer_colors; +}; + +struct multiboot_mmap_entry { + u32 size; + u64 addr; + u64 len; + u32 type; +} PACKED; + +struct multiboot_mod_list { + u32 mod_start; + u32 mod_end; + + u32 cmdline; + + u32 pad; +}; + +void multiboot_init(u32 magic, u32 addr); + +#endif diff --git a/kernel/link.ld b/kernel/link.ld index d213070..830603d 100644 --- a/kernel/link.ld +++ b/kernel/link.ld @@ -1,5 +1,5 @@ OUTPUT_ARCH(i386) -ENTRY(kernel_main) +ENTRY(boot_entry) phys = 0x00100000; SECTIONS diff --git a/kernel/main.c b/kernel/main.c index e558126..e0e544b 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -9,6 +9,7 @@ #include <load.h> #include <mem.h> #include <mm.h> +#include <multiboot.h> #include <net.h> #include <pci.h> #include <rand.h> @@ -19,21 +20,19 @@ PROTECTED extern u32 __stack_chk_guard; PROTECTED u32 __stack_chk_guard; -PROTECTED u32 tss_entry = 0; -PROTECTED u32 boot_drive = 0; - -int kernel_main(struct boot_info *boot); // Decl -int kernel_main(struct boot_info *boot) +int kernel_main(u32 magic, u32 addr); // Decl +int kernel_main(u32 magic, u32 addr) { // Serial connection serial_install(); serial_print("\nKernel was compiled at " __TIME__ " on " __DATE__ "\n"); - serial_print("Serial connected.\n"); + serial_print("Serial connected. LOOPING!\n"); - tss_entry = boot->tss; - boot_drive = boot->drive; + multiboot_init(magic, addr); + while (1) + ; - memory_install(boot); + memory_install(); memory_switch_dir(virtual_kernel_dir()); cpu_enable_features(); @@ -47,7 +46,7 @@ int kernel_main(struct boot_info *boot) ata_install(); pci_install(); interrupts_install(); - io_install(boot); + io_install(); // Enable drivers sti(); diff --git a/kernel/multiboot.c b/kernel/multiboot.c new file mode 100644 index 0000000..eafe4c5 --- /dev/null +++ b/kernel/multiboot.c @@ -0,0 +1,17 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include <assert.h> +#include <def.h> +#include <multiboot.h> + +static struct multiboot_info *info = NULL; + +void multiboot_init(u32 magic, u32 addr) +{ + assert(magic == MULTIBOOT_MAGIC); + info = (void *)addr; + + if (info->flags & MULTIBOOT_INFO_CMDLINE) { + printf("CMDLINE: '%s'\n", info->cmdline); + } +} |