summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile16
-rw-r--r--asm/kernel_entry.asm3
-rw-r--r--asm/multiboot.s22
-rw-r--r--kernel/console.c4
-rw-r--r--kernel/kernel.c93
-rw-r--r--kernel/multiboot.h50
6 files changed, 158 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index 94d4c7a..8c50fba 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,8 @@
# main phony targets
-.PHONY: all new run newrun stick clean
+.PHONY: all new run newrun stick clean tags
+
############ some constants ############
@@ -86,7 +87,7 @@ ASM_MULTIBOOT_OBJ=$(patsubst %.s, %.o, $(ASM_MULTIBOOT))
all: $(FOOLOS) #$(FOOLOS_VDI)
new: clean all
-run: run-qemu
+run: run-qemu-debug
newrun: clean run
@@ -158,10 +159,11 @@ run-bochs: all
# run in qemu
run-qemu: all
- qemu-system-i386 $(FOOLOS)
+ qemu -enable-kvm $(FOOLOS)
run-qemu-debug: all
- qemu-system-i386 -s -S ~/temp/FoolOs/disk.img
+# qemu -enable-kvm -s -S ~/temp/FoolOs/disk.img
+ qemu -enable-kvm -s ~/temp/FoolOs/disk.img
############ create bootable usb image ############
@@ -173,4 +175,8 @@ stick: $(FOOLOS)
############ cleanup ############
clean: $(CLEANDIRS)
- -rm *.bin $(FOOLOS) $(FOOLOS_VDI) $(KERNEL_ENTRY) $(ASM_MULTIBOOT_OBJ) $(KERNEL_IMG) $(ASM_OBJECTS) $(OBJECTS) $(IMG_FILLUP) $(BIN_MBR) $(BIN_MP) $(BIN_STAGE2) $(DEPS) bochs.out bochs.log ne2k-tx.log ne2k-txdump.txt
+ -rm *.bin $(FOOLOS) $(FOOLOS_VDI) $(KERNEL_ENTRY) $(ASM_MULTIBOOT_OBJ) $(KERNEL_IMG) $(ASM_OBJECTS) $(OBJECTS) $(IMG_FILLUP) $(BIN_MBR) $(BIN_MP) $(BIN_STAGE2) $(DEPS) bochs.out bochs.log ne2k-tx.log ne2k-txdump.txt tags
+
+tags:
+ ctags --recurse=yes .
+
diff --git a/asm/kernel_entry.asm b/asm/kernel_entry.asm
index 7dacee3..71bedd1 100644
--- a/asm/kernel_entry.asm
+++ b/asm/kernel_entry.asm
@@ -1,3 +1,6 @@
+; DEPRECATED . use multiboot.s instead!
+
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/asm/multiboot.s b/asm/multiboot.s
index 08cc87e..a497e18 100644
--- a/asm/multiboot.s
+++ b/asm/multiboot.s
@@ -1,7 +1,11 @@
+# https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Boot-information-format
+# http://wiki.osdev.org/Bare_Bones
+
# Declare constants used for creating a multiboot header.
.set ALIGN, 1<<0 # align loaded modules on page boundaries
.set MEMINFO, 1<<1 # provide memory map
-.set FLAGS, ALIGN | MEMINFO # this is the Multiboot 'flag' field
+.set GFXINFO, 1<<2 # provide gfx info
+.set FLAGS, ALIGN | MEMINFO # | GFXINFO # this is the Multiboot 'flag' field
.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot
@@ -16,6 +20,17 @@
.long FLAGS
.long CHECKSUM
+.long 0 # we dont need this
+.long 0
+.long 0
+.long 0
+.long 0
+
+.long 0 #gfx_stuff
+.long 0
+.long 0
+.long 0
+
# Currently the stack pointer register (esp) points at anything and using it may
# cause massive harm. Instead, we'll provide our own stack. We will allocate
# room for a small temporary stack by creating a symbol at the bottom of it,
@@ -59,7 +74,10 @@ _start:
# We are now ready to actually execute C code. We cannot embed that in an
# assembly file, so we'll create a kernel.c file in a moment. In that file,
# we'll create a C entry point called kernel_main and call it here.
- call kernel_start
+
+ push %ebx #pass address of the multiboot information data structure
+ push %eax #pass eax, so kernel can check for magic number
+ call kernel_main
# In case the function returns, we'll want to put the computer into an
# infinite loop. To do that, we use the clear interrupt ('cli') instruction
diff --git a/kernel/console.c b/kernel/console.c
index b815c24..0a208bb 100644
--- a/kernel/console.c
+++ b/kernel/console.c
@@ -16,8 +16,8 @@
uint32_t console_init(){
scr_clear();
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init console");
- int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,"/binfont.bin");
- if(inode_nr!=-1)ext2_inode_content(EXT2_RAM_ADDRESS,inode_nr,0x8000000,0xffff); // load font;
+ // int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,"/binfont.bin");
+ // if(inode_nr!=-1)ext2_inode_content(EXT2_RAM_ADDRESS,inode_nr,0x8000000,0xffff); // load font;
return 0;
}
void console_del_char(){scr_backspace();}
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 8bd60ca..d0f1bce 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -13,6 +13,7 @@
#include "mem.h"
#include "vmem.h"
#include "interrupts.h"
+#include "multiboot.h"
#include "console.h"
@@ -23,31 +24,79 @@
#include "task.h"
-// mp informs us if this if this is the main processor
-void kernel_main(uint32_t initial_stack, int mp)
+void kernel_main(uint32_t eax,uint32_t ebx)
{
-/*
- int i=0;
- while(true)
- {
- size_t *terminal_buffer = (uint16_t*) 0xB8000;
- uint16_t c16='X';
- i++;
- if (i%2)c16='_';
-
- c16 = c16 | 4 << 8;
- terminal_buffer[2] = c16;
- }
- */
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kernel_main: eax=0x%08X ebx=0x%08X",eax,ebx);
-
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial_stack: 0x%08X",initial_stack);
//
// Configuring the PIT timer.
//
+
timer_init();
+ //
+ // Process Multiboot Header
+ //
+
+ if(eax!=0x2badb002)panic(FOOLOS_MODULE_NAME,"EAX was not set properly by your bootlaoder!");
+
+ multiboot_information *info;
+ info=ebx;
+ if(info->flags&&1<<9)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Loaded by: \"%s\"",info->boot_loader_name);
+ }
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"multiboot flags: 0x%08X",info->flags);
+
+ if(info->flags&&1<<0)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mem_lower: %d KB",info->mem_lower);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mem_upper: %d KB",info->mem_upper);
+ }
+
+ if(info->flags&&1<<2)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cmdline: \"%s\"",info->cmdline);
+ }
+
+ if(info->flags&&1<<3)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d modules loaded",info->mods_count);
+
+ multiboot_mod *mod=info->mods_addr;
+
+ for(int i=0;i<info->mods_count;i++)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mod at 0x08%X-0x08%X : %s",
+ mod->mod_start,mod->mod_end, mod->string);
+ mod++;
+ }
+ }
+
+ if(info->flags&&1<<6)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"memory map of length %d provided by bootloader",info->mmap_length);
+
+ uint32_t mmap_addr=info->mmap_addr;
+
+ while(mmap_addr<info->mmap_addr+info->mmap_length)
+ {
+ multiboot_mmap *mmap=mmap_addr;
+ uint32_t mem_start=mmap->base_addr;
+ uint32_t mem_end=mmap->base_addr+mmap->length;
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%08X - %08X / type: %d, size: %d",
+ mem_start, mem_end, mmap->type, mmap->size);
+
+ mmap_addr+=mmap->size+4;
+ }
+
+
+ }
+ else panic(FOOLOS_MODULE_NAME,"Unable to continue without memory map, sorry!");
+
//
// Memory Init
//
@@ -57,22 +106,24 @@ void kernel_main(uint32_t initial_stack, int mp)
// we know that here, the bootloader placed the memory map and
// the number of entries.
//
- mem_init((physical_address)0xa001,(int)(*((uint16_t *)(0xa000))));
+// mem_init((physical_address)0xa001,(int)(*((uint16_t *)(0xa000))));
+
//
// init output to screen
//
uint32_t physbase=console_init();
+
//
// Activate Virtual Memory (paging)
- pdirectory *dir=vmem_init(physbase);
+// pdirectory *dir=vmem_init(physbase);
// log buffered messages to console
log_log();
- //while(1);
+ while(1);
//
// Setup Interrupts (code segment: 0x08)
@@ -110,7 +161,7 @@ void kernel_main(uint32_t initial_stack, int mp)
//
// Initialize Multitasking
//
- task_init(dir); //; this will never return!
+ //task_init(dir); //; this will never return!
}
diff --git a/kernel/multiboot.h b/kernel/multiboot.h
new file mode 100644
index 0000000..874e473
--- /dev/null
+++ b/kernel/multiboot.h
@@ -0,0 +1,50 @@
+//# https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Boot-information-format
+
+
+#include <stdbool.h>
+#include <stdint.h>
+
+typedef struct multiboot_information_struct
+{
+ uint32_t flags;
+ uint32_t mem_lower;
+ uint32_t mem_upper;
+ uint32_t boot_device;
+ uint32_t cmdline;
+ uint32_t mods_count;
+ uint32_t mods_addr;
+ uint32_t mods_syms[4];
+ uint32_t mmap_length;
+ uint32_t mmap_addr;
+ uint32_t drives_length;
+ uint32_t drives_addr;
+ uint32_t config_table;
+ uint32_t boot_loader_name;
+ uint32_t amp_table;
+ uint32_t vbe_control_info;
+ uint32_t vbe_mode_info;
+ uint16_t vbe_mode;
+ uint16_t vbe_interface_seg;
+ uint16_t vbe_interface_off;
+ uint16_t vbe_interface_len;
+
+
+}multiboot_information;
+
+typedef struct multiboot_mmap_struct
+{
+ uint32_t size;
+ uint64_t base_addr;
+ uint64_t length;
+ uint32_t type;
+
+}multiboot_mmap;
+
+typedef struct multiboot_mod_struct
+{
+ uint32_t mod_start;
+ uint32_t mod_end;
+ uint32_t string;
+ uint32_t reserved;
+
+}multiboot_mod;