Merge into main the new state of the operating system/kernel #1
							
								
								
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,3 +1,8 @@
 | 
			
		||||
build
 | 
			
		||||
CON
 | 
			
		||||
.vscode
 | 
			
		||||
isodir/
 | 
			
		||||
root/
 | 
			
		||||
*.iso
 | 
			
		||||
*.img
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								Makefile
									
									
									
									
									
								
							@ -19,12 +19,27 @@ OBJ_LINK_LIST = $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OFILES) $(CRTEND_OBJ) $(CRTN_OBJ)
 | 
			
		||||
INTERNAL_OBJS = $(CRTI_OBJ) $(OFILES) $(CRTN_OBJ)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
all: clean build
 | 
			
		||||
all: clean build clean_up
 | 
			
		||||
 | 
			
		||||
build: build_kernel run 
 | 
			
		||||
build: build_kernel 
 | 
			
		||||
 | 
			
		||||
run:
 | 
			
		||||
	$(EMULATOR)  -kernel $(BUILD_DIR)/myos.bin -serial file:CON -vga std -monitor stdio -display gtk -m 2G -cpu core2duo -drive file=demodisk.img
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
clean_iso: 
 | 
			
		||||
	if [[ -a isodir/* ]] ; then rm isodir/* -d ; fi
 | 
			
		||||
	if [ -f barinkOS.iso ] ; then rm barinkOS.iso ; fi
 | 
			
		||||
	
 | 
			
		||||
iso: clean_iso build
 | 
			
		||||
	mkdir -p isodir/boot/grub
 | 
			
		||||
	cp build/myos.bin isodir/boot/myos.bin
 | 
			
		||||
	cp src/grub.cfg isodir/boot/grub/grub.cfg
 | 
			
		||||
	grub-mkrescue -o barinkOS.iso isodir
 | 
			
		||||
	
 | 
			
		||||
clean_up:
 | 
			
		||||
	rm build/*.o
 | 
			
		||||
 | 
			
		||||
test:
 | 
			
		||||
	$(EMULATOR)  -kernel $(BUILD_DIR)/myos.bin -serial file:CON -vga std -monitor stdio -display gtk -m 2G -cpu core2duo 
 | 
			
		||||
 | 
			
		||||
build_kernel: $(OBJ_LINK_LIST)
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								src/grub.cfg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/grub.cfg
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
menuentry "BarinkOS"{
 | 
			
		||||
    multiboot /boot/myos.bin
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										73
									
								
								src/kernel/bootcheck.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								src/kernel/bootcheck.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,73 @@
 | 
			
		||||
#pragma once 
 | 
			
		||||
#include "multiboot.h"
 | 
			
		||||
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
    #include "arch/i386/tty/kterm.h"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CheckMBT ( multiboot_info_t*  mbt  ){
 | 
			
		||||
      /* Set MBI to the addresss of the multiboot information structure*/
 | 
			
		||||
        multiboot_info_t * mbi = (multiboot_info_t *) mbt;
 | 
			
		||||
 | 
			
		||||
        /* Print out the flags */
 | 
			
		||||
        printf("flags = 0x%x\n", (unsigned) mbi->flags);
 | 
			
		||||
 | 
			
		||||
        /* Are mem_* valid? */
 | 
			
		||||
        if ( CHECK_FLAG(mbi->flags,0)){
 | 
			
		||||
            printf("mem_lower = %uKB, mem_upper = %uKB\n");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* is boot device valid ? */
 | 
			
		||||
        if (CHECK_FLAG (mbi->flags, 1)){
 | 
			
		||||
            printf("boot_device = 0x0%x\n", (unsigned) mbi->boot_device);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* is the command line passed? */
 | 
			
		||||
        if (CHECK_FLAG ( mbi->flags,2)){
 | 
			
		||||
            printf("cmdline = %s\n", (char *) mbi->cmdline);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Are mods_* valid? */
 | 
			
		||||
        if(CHECK_FLAG ( mbi->flags, 3)){
 | 
			
		||||
            multiboot_module_t *mod;
 | 
			
		||||
            int i;
 | 
			
		||||
 | 
			
		||||
            printf("mods count = %d, mods_addr = 0x%x\n", (int) mbi->mods_count, (int) mbi->mods_addr);
 | 
			
		||||
 | 
			
		||||
            for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){
 | 
			
		||||
                printf(" mod start = 0x%x, mod_end = 0x%x, cmdline = %s\n", (unsigned) mod->mod_start, (unsigned) mod->mod_end, (char*) mod->cmdline);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Bits 4 and 5 are mutually exclusive! */
 | 
			
		||||
        if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG(mbi->flags, 5)){
 | 
			
		||||
            printf("Both bits 4 and 5 are set.\n");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Is the symbol table of a.out valid? */
 | 
			
		||||
        if (CHECK_FLAG(mbi->flags, 4)){
 | 
			
		||||
            multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym);
 | 
			
		||||
 | 
			
		||||
            printf( "multiboot_aout_symbol_table: tabsize = 0x%0x, strsize = 0x%x, addr = 0x%x\n", 
 | 
			
		||||
            (unsigned) multiboot_aout_sym->tabsize,
 | 
			
		||||
            (unsigned) multiboot_aout_sym->strsize,
 | 
			
		||||
            (unsigned) multiboot_aout_sym->addr);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Is the section header table of ELF valid? */
 | 
			
		||||
        if (CHECK_FLAG(mbi->flags, 5)){
 | 
			
		||||
            multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec);
 | 
			
		||||
 | 
			
		||||
            printf("multiboot_elf_sec: num = %u, size = 0x%x, addr = 0x%x, shnd = 0x%x\n",
 | 
			
		||||
            (unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size,
 | 
			
		||||
            (unsigned) multiboot_elf_sec->addr, (unsigned)  multiboot_elf_sec->shndx);
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -1,92 +1,33 @@
 | 
			
		||||
#include "kernel.h"
 | 
			
		||||
 | 
			
		||||
#include "arch/i386/gdt/gdtc.h"
 | 
			
		||||
extern "C" {
 | 
			
		||||
 | 
			
		||||
     multiboot_info_t *mbi;
 | 
			
		||||
    void early_main(unsigned long magic, unsigned long addr){
 | 
			
		||||
 | 
			
		||||
        /** initialize terminal interface */ 
 | 
			
		||||
        kterm_init();
 | 
			
		||||
      
 | 
			
		||||
       
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        if (magic != MULTIBOOT_BOOTLOADER_MAGIC){
 | 
			
		||||
            printf("Invalid magic number: 0x%x\n", (unsigned) magic);
 | 
			
		||||
            printf("Invalid magic number: 0x%x\n",  magic);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Set MBI to the addresss of the multiboot information structure*/
 | 
			
		||||
        mbi = (multiboot_info_t *) addr;
 | 
			
		||||
        CheckMBT(  (multiboot_info_t *) addr);
 | 
			
		||||
 | 
			
		||||
        /* Print out the flags */
 | 
			
		||||
        printf("flags = 0x%x\n", (unsigned) mbi->flags);
 | 
			
		||||
 | 
			
		||||
        /* Are mem_* valid? */
 | 
			
		||||
        if ( CHECK_FLAG(mbi->flags,0)){
 | 
			
		||||
            printf("mem_lower = %uKB, mem_upper = %uKB\n");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* is boot device valid ? */
 | 
			
		||||
        if (CHECK_FLAG (mbi->flags, 1)){
 | 
			
		||||
            printf("boot_device = 0x0%x\n", (unsigned) mbi->boot_device);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* is the command line passed? */
 | 
			
		||||
        if (CHECK_FLAG ( mbi->flags,2)){
 | 
			
		||||
            printf("cmdline = %s\n", (char *) mbi->cmdline);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Are mods_* valid? */
 | 
			
		||||
        if(CHECK_FLAG ( mbi->flags, 3)){
 | 
			
		||||
            multiboot_module_t *mod;
 | 
			
		||||
            int i;
 | 
			
		||||
 | 
			
		||||
            printf("mods count = %d, mods_addr = 0x%x\n", (int) mbi->mods_count, (int) mbi->mods_addr);
 | 
			
		||||
 | 
			
		||||
            for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){
 | 
			
		||||
                printf(" mod start = 0x%x, mod_end = 0x%x, cmdline = %s\n", (unsigned) mod->mod_start, (unsigned) mod->mod_end, (char*) mod->cmdline);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Bits 4 and 5 are mutually exclusive! */
 | 
			
		||||
        if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG(mbi->flags, 5)){
 | 
			
		||||
            printf("Both bits 4 and 5 are set.\n");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Is the symbol table of a.out valid? */
 | 
			
		||||
        if (CHECK_FLAG(mbi->flags, 4)){
 | 
			
		||||
            multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym);
 | 
			
		||||
 | 
			
		||||
            printf( "multiboot_aout_symbol_table: tabsize = 0x%0x, strsize = 0x%x, addr = 0x%x\n", 
 | 
			
		||||
            (unsigned) multiboot_aout_sym->tabsize,
 | 
			
		||||
            (unsigned) multiboot_aout_sym->strsize,
 | 
			
		||||
            (unsigned) multiboot_aout_sym->addr);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Is the section header table of ELF valid? */
 | 
			
		||||
        if (CHECK_FLAG(mbi->flags, 5)){
 | 
			
		||||
            multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec);
 | 
			
		||||
 | 
			
		||||
            printf("multiboot_elf_sec: num = %u, size = 0x%x, addr = 0x%x, shnd = 0x%x\n",
 | 
			
		||||
            (unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size,
 | 
			
		||||
            (unsigned) multiboot_elf_sec->addr, (unsigned)  multiboot_elf_sec->shndx);
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
        multiboot_info_t* mbt = (multiboot_info_t*) addr;
 | 
			
		||||
 | 
			
		||||
        // Map the kernel
 | 
			
		||||
        //initPhysicalMemoryManager();
 | 
			
		||||
 | 
			
		||||
        // AAAAAH memory map, Yes please!
 | 
			
		||||
        /* Are mmap_* valid? */
 | 
			
		||||
        if (CHECK_FLAG(mbi->flags, 6)){
 | 
			
		||||
            multiboot_memory_map_t *mmap;
 | 
			
		||||
        if (CHECK_FLAG(mbt->flags, 6)){
 | 
			
		||||
            multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) mbt->mmap_addr;
 | 
			
		||||
            
 | 
			
		||||
            printf("mmap_addr = 0x%x, mmap_length = 0x%x\n",
 | 
			
		||||
            (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length);
 | 
			
		||||
            (unsigned) mbt->mmap_addr, (unsigned) mbt->mmap_length);
 | 
			
		||||
            
 | 
			
		||||
            for (mmap = (multiboot_memory_map_t *) mbi->mmap_addr; 
 | 
			
		||||
                (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; 
 | 
			
		||||
                mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
 | 
			
		||||
            for (mmap;  (unsigned long) mmap < mbt->mmap_addr + mbt->mmap_length;  mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
 | 
			
		||||
                    
 | 
			
		||||
                    printf(
 | 
			
		||||
                        "size = 0x%x, base_addr = 0x%x%08x, length = 0x%x%08x, type = 0x%x\n",
 | 
			
		||||
 | 
			
		||||
@ -2,10 +2,13 @@
 | 
			
		||||
extern "C" {
 | 
			
		||||
    #include "../libc/include/string.h"
 | 
			
		||||
    #include "arch/i386/tty/kterm.h"
 | 
			
		||||
    #include "pmm.h"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#include "multiboot.h"
 | 
			
		||||
#include "bootcheck.h"
 | 
			
		||||
#include "arch/i386/idt/idt.h"
 | 
			
		||||
 | 
			
		||||
#include "MMU.h"
 | 
			
		||||
#include "io.h"
 | 
			
		||||
#include "time.h"
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user