diff --git a/src/boot/grub/eltor b/src/boot/grub/eltor new file mode 100644 index 0000000..3748c94 Binary files /dev/null and b/src/boot/grub/eltor differ diff --git a/src/boot/kernel b/src/boot/kernel index f5cad6c..c158e45 100755 Binary files a/src/boot/kernel and b/src/boot/kernel differ diff --git a/src/doom/w_wad.c b/src/doom/w_wad.c index ac87439..246baca 100644 --- a/src/doom/w_wad.c +++ b/src/doom/w_wad.c @@ -188,7 +188,7 @@ void W_AddFile (char *filename) //printf (" adding %s\n",filename); startlump = numlumps; - if (strcmpi (filename+strlen(filename)-3 , "wad" ) ) + if (strcmpi (filename+strlen(filename)-3 , "wad" ) /*== 69 hahahahahah funny number why arent you laughing*/) { // single lump file fileinfo = &singleinfo; diff --git a/src/doomos.iso b/src/doomos.iso index e4b57b6..a493922 100644 Binary files a/src/doomos.iso and b/src/doomos.iso differ diff --git a/src/full.sh b/src/full.sh index bf31c9b..41446b9 100755 --- a/src/full.sh +++ b/src/full.sh @@ -106,6 +106,7 @@ mkdir -p isodir/boot mkdir -p isodir/boot/grub # module doom.wad cp boot/kernel isodir/boot/kernel +cp boot/grub/* isodir/boot/grub/ cp doom.wad isodir cp bg.png isodir/boot cat > isodir/boot/grub/grub.cfg << EOF @@ -114,7 +115,6 @@ set color_normal=white/black set color_highlight=black/white menuentry "DoomOS" { multiboot /boot/kernel - module2 raw file=doom.wad } EOF grub-mkrescue -o doomos.iso isodir diff --git a/src/kernel/isodir/doom.wad b/src/isodir/boot/doom.wad similarity index 100% rename from src/kernel/isodir/doom.wad rename to src/isodir/boot/doom.wad diff --git a/src/isodir/boot/grub/eltor b/src/isodir/boot/grub/eltor new file mode 100644 index 0000000..3748c94 Binary files /dev/null and b/src/isodir/boot/grub/eltor differ diff --git a/src/isodir/boot/grub/grub.cfg b/src/isodir/boot/grub/grub.cfg index 7daa94f..c53ad12 100644 --- a/src/isodir/boot/grub/grub.cfg +++ b/src/isodir/boot/grub/grub.cfg @@ -3,5 +3,4 @@ set color_normal=white/black set color_highlight=black/white menuentry "DoomOS" { multiboot /boot/kernel - module2 raw file=doom.wad } diff --git a/src/isodir/boot/grub/menu.lst b/src/isodir/boot/grub/menu.lst new file mode 100644 index 0000000..e4b1e3d --- /dev/null +++ b/src/isodir/boot/grub/menu.lst @@ -0,0 +1,6 @@ +default 0 + + +title DoomOS +kernel /boot/kernel +module doom.wad diff --git a/src/isodir/boot/grub/stage2_eltorito b/src/isodir/boot/grub/stage2_eltorito new file mode 100644 index 0000000..9e1617c Binary files /dev/null and b/src/isodir/boot/grub/stage2_eltorito differ diff --git a/src/isodir/boot/grub/stage2_eltorito:Zone.Identifier b/src/isodir/boot/grub/stage2_eltorito:Zone.Identifier new file mode 100644 index 0000000..053d112 --- /dev/null +++ b/src/isodir/boot/grub/stage2_eltorito:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=about:internet diff --git a/src/isodir/boot/kernel b/src/isodir/boot/kernel index f5cad6c..c158e45 100755 Binary files a/src/isodir/boot/kernel and b/src/isodir/boot/kernel differ diff --git a/src/kernel/boot.S b/src/kernel/boot.S index 9818937..9af8723 100644 --- a/src/kernel/boot.S +++ b/src/kernel/boot.S @@ -3,15 +3,16 @@ .set MEMINFO, 1 << 1 .set FLAGS, ALIGN | MEMINFO .set MAGIC, 0x1BADB002 +.set ALIGN_MODULES, 0x00000001 .set CHECKSUM, -(MAGIC + FLAGS) # multiboot .section .multiboot -.align 4 +.align 0x4 .long MAGIC .long FLAGS .long CHECKSUM -.long 0x36d76289 +# .long 0x36d76289 .section .bss .align 16 @@ -26,7 +27,6 @@ _start: movl $stack_top, %esp pushl %ebx - pushl %eax call main cli 1: diff --git a/src/kernel/bootNasm.s b/src/kernel/bootNasm.s new file mode 100644 index 0000000..1b86fa8 --- /dev/null +++ b/src/kernel/bootNasm.s @@ -0,0 +1,32 @@ +global entry +section .__mbHeader + +align 0x4 +MAGIC equ 0x1BADB002 +ALIGN_MODULES equ 0x00000001 +FLAGS equ 0 +SUM equ -(MAGIC + ALIGN_MODULES) + +section .text +align 4 + dd MAGIC + dd ALIGN_MODULES + dd FLAGS + dd SUM + +CSTACK_SIZE equ 80000 ; This is how big we want our stack to be + +entry: +mov esp, cstack + CSTACK_SIZE ; The ESP register holds the current position on the stack + +extern main +push ebx +call main + +jmp entry + +section .bss: + +align 16 +cstack: +resb CSTACK_SIZE ; resb == "reserve bytes" \ No newline at end of file diff --git a/src/kernel/controller/file.h b/src/kernel/controller/file.h index ec37e96..8b75751 100644 --- a/src/kernel/controller/file.h +++ b/src/kernel/controller/file.h @@ -20,34 +20,21 @@ typedef struct{ - char* ptr; - char* _tmpfname; - long int pos; - int fd; + int handle, pos, dataLen; + char name[255]; }FILE; +static int handleLen = 0; -/* -* Epic rambling -* -* so like the boot cd is ISO 9660 -* so we need to like -* like like load the fs lamo lil c0akfd0 fl -* -* is that enough likes? -*/ +static FILE files[255]; -// Path Table Entry -typedef struct { - int dirIndentifierLen, extAttrRecordLen, - locationOfExtent, dirNumOfPDir; - char directoryIdentifier[256]; - -} PathTableEntry ; +static unsigned int addrForWad; -static char* reverse(int num) { + + +/*static char* reverse(int num) { char full[100]; int i = 0; while (num > 0) { @@ -55,13 +42,31 @@ static char* reverse(int num) { num /= 10; } return full; -} +}*/ +static void reverse(char str[], int length) +{ + int start = 0; + int end = length - 1; + while (start < end) { + char temp = str[start]; + str[start] = str[end]; + str[end] = temp; + end--; + start++; + } +} +static uint32_t little_endian_to_uint32(uint8_t* bytes) { + uint32_t value = 0; + for (int i = 0; i < 4; i++) { + value |= bytes[i] << (i * 8); + } + return value; +} /* * Read from the Disk and * init the ISO 9660 FS */ - static void* mountBootDrive() { // Read volume descriptor uint16_t volumeDesc[2048]; @@ -79,33 +84,15 @@ static void* mountBootDrive() { } - /* - int size; - size += volumeDesc[132] | (volumeDesc[133] << 8) | (volumeDesc[134] << 16) | (volumeDesc[135] << 24); - size = 420; - - uint32_t lbaLoc; - lbaLoc += volumeDesc[140] | (volumeDesc[141] << 8) | (volumeDesc[142] << 16) | (volumeDesc[142] << 24); - char* f = reverse(size); - char debugFull[512] = "Path table size: "; - strcat(debugFull, f); - t_out(debugFull); - - // what ever, move on - uint16_t pathTableSys[size]; - int c = read_cdrom(0x1F0, 0, lbaLoc, size / 2000, &pathTableSys); - if (c < 0 || c > 0) { - // panic! - } - */ - // load entries } } - +static void fs_SetWadFile(unsigned int memAddr) { + addrForWad = memAddr; +} /* @@ -144,36 +131,152 @@ typedef struct { uint8_t nameLen; } dirEntry; -static void* readFile(const char* file) { -/*#define ROOTOFFSET 156 - // load PVD - uint16_t pvd[2048]; - int c = read_cdrom(0x1F0, 0, 16, 1, &pvd); - // get root directorywd - dirEntry root; - uint32_t rootLBA, rootExtentLength; - rootLBA = (pvd[ROOTOFFSET + 2] & 0xFF) | ((pvd[ROOTOFFSET + 3] >> 8) & 0xFF) | ((pvd[ROOTOFFSET + 4] >> 16) & 0xFF) | ((pvd[ROOTOFFSET + 5] >> 24) & 0xFF); - /*rootLBA |= pvd[ROOTOFFSET + 2] & 0xff; - rootLBA |= (pvd[ROOTOFFSET + 3] << 8) & 0xFF; - rootLBA |= (pvd[ROOTOFFSET + 4] << 16) & 0xFF; - rootLBA |= (pvd[ROOTOFFSET + 5] << 24) & 0xFF; - - +#define SECTOR_SIZE 2048 +typedef struct { + char name[32]; + uint8_t attributes; + uint32_t size; + uint32_t lba; +} DirectoryRecord; - //rootExtentLength += pvd[ROOTOFFSET + 10] | (pvd[ROOTOFFSET + 11] << 8) | (pvd[ROOTOFFSET + 12] << 16) | (pvd[ROOTOFFSET + 13] << 24); - // load - uint16_t dirEntData[2048]; - c = read_cdrom(0x1F0, 0, rootLBA, 1, &dirEntData); - char dirName[dirEntData[32]]; - for (int i = 0; i < dirEntData[32]; i++) { - dirName[i] = dirEntData[33 + i]; + + + +static void* splitAtCharIndex(const char* string, const char split, int index, char* out) { + int pos = 0, c = 0; + char tmp[256]; + for (int i = 0; i < strlen(string); i++) { + if (string[i] != split) { + out[c++] = string[i]; + } + else { + if (pos == index) return; + pos++; + c = 0; + } } - //t_out(dNum); - t_out(dirName);*/ } +static void* readFile(const char* file) { + // split + + + + + // check file existence +#define ROOTOFFSET 156 + // load PVD + uint8_t pvd[2048]; + int c = read_cdrom(0x1F0, 0, 16, 1, &pvd); + dirEntry root; + uint32_t rootLBA, rootExtentLength; + //rootLBA = (pvd[ROOTOFFSET + 2] & 0xFF) | ((pvd[ROOTOFFSET + 3] << 8) & 0xFF) | ((pvd[ROOTOFFSET + 4] << 16) & 0xFF) | ((pvd[ROOTOFFSET + 5] << 24) & 0xFF); + //rootExtentLength = (pvd[ROOTOFFSET + 10] & 0xFF) | ((pvd[ROOTOFFSET + 11] << 8) & 0xFF) | ((pvd[ROOTOFFSET + 12] << 16) & 0xFF) | ((pvd[ROOTOFFSET + 13] << 24) & 0xFF); + uint8_t LBAbytes[] = { pvd[ROOTOFFSET + 2], pvd[ROOTOFFSET + 3], pvd[ROOTOFFSET + 4], pvd[ROOTOFFSET + 5] }; + //uint8_t ExtentBytes[] = { pvd[ROOTOFFSET + 10], pvd[ROOTOFFSET + 11], pvd[ROOTOFFSET + 12], pvd[ROOTOFFSET + 13] }; + rootLBA = little_endian_to_uint32(LBAbytes); + rootExtentLength = pvd[ROOTOFFSET];//little_endian_to_uint32(ExtentBytes); + + uint32_t newof = (rootLBA);//+ ((rootExtentLength))); + + uint8_t dirEntData[2048]; + c = read_cdrom(0x1F0, 0, newof, 1, &dirEntData); + int currentpos = 000; + for (int i = 0; i < 5; i++) { + + + uint8_t locOfExtent[] = { dirEntData[currentpos + 2], dirEntData[currentpos + 3], dirEntData[currentpos + 4], dirEntData[currentpos + 5] }; + uint32_t loc = little_endian_to_uint32(locOfExtent); + + uint8_t lenBytes[] = { dirEntData[currentpos + 10], dirEntData[currentpos + 11], dirEntData[currentpos + 12], dirEntData[currentpos + 13] }; + uint32_t len = little_endian_to_uint32(lenBytes); + + // Print + uint8_t nameLength = dirEntData[currentpos + 32]; + char dirName[nameLength + 1]; + for (int i = 0; i < nameLength; i++) { + dirName[i] = dirEntData[currentpos + 33 + i]; + if (dirName[i] == ';') { + nameLength = i; + break; + } + } + dirName[nameLength] = '\0'; + + if (nameLength > 1) { + char split[256]; + splitAtCharIndex(file, '/', 1, split); + t_debug("GOT DIR: "); + t_debug(dirName); + //t_out(split); + if (strcmp(dirName, split) == 0) { + char debug[5]; + itoa(i, debug, 5, 10); + //reverse(debug, 2); + t_out(debug); + + + + // we're done here. create a file struct and we're off. + FILE tmp = {handleLen++, loc, len, dirName }; + files[handleLen] = tmp; + return; + } + } + + + + // Next + currentpos += dirEntData[currentpos]; + + + } +} + + + + +/* +* Epic rambling +* +* so like the boot cd is ISO 9660 +* so we need to like +* like like load the fs lamo lil c0akfd0 fl +* +* is that enough likes? +*/ +/* +// Path Table Entry +typedef struct { + int extentLoc, parentDirIndex; + char id[256]; + +} PathTableEntry; + +static void* readFile(const char* file) { +#define ROOTOFFSET 140 + // Path table + uint8_t pvd[2048]; + int c = read_cdrom(0x1F0, 0, 16, 1, &pvd); + // get root directorywd + uint32_t pathTableLBA; + uint8_t LBAbytes[] = {pvd[ROOTOFFSET], pvd[ROOTOFFSET + 2], pvd[ROOTOFFSET + 3], pvd[ROOTOFFSET + 4] }; + pathTableLBA = little_endian_to_uint32(LBAbytes); + char debug[5]; + itoa(pathTableLBA, debug, 5, 10); + reverse(debug, 2); + t_out(debug); + // Alright lets read it + uint8_t pathTable[2048]; + read_cdrom(0x1F0, 0, pathTableLBA, 1, &pathTable); + char dirName[20]; + for (int i = 0; i < 19; i++) { + dirName[i] = pathTable[8 + 10 + i]; + } + t_out(dirName); +}*/ typedef struct stat { int st_size; }fileinfo; @@ -181,8 +284,7 @@ typedef struct stat { static FILE* fopen(char* fileName, char* mode) { FILE* tmp; - // Load file from system - + return (void*)0; } @@ -219,15 +321,41 @@ static int mkdir(const char* path, int mode) { static int FS_open(const char* path, ...) { t_out("FS_Open called"); - t_out(path); - - return -1; // replace with handle + readFile(path); + return handleLen; } static int FS_close(int handle) { - return 1; // remove handle + t_out("FS_Close called"); + return 1; // remove handle } static int read(int handle, void* buf, int count) { - return 1; + t_out("we reading bois"); + uint32_t loc = files[handleLen].pos; + uint32_t size = files[handleLen].dataLen; + + char debug[5]; + itoa(count, debug, 5, 10); + //reverse(debug, 2); + t_out(debug); + + + + //asm("hlt"); + + // detemine buffer size + + + int sec = 1; + if (count > 2048) { + sec = count / 2048; + } + + uint16_t bufAll[sec * 2048]; + + int c = read_cdrom(0x1F0, 0, loc, sec, &bufAll); + + memcpy(buf, bufAll, count); + } static int write(int handle, void* buf, int count) { return 1; diff --git a/src/kernel/isodir/boot/doom.wad b/src/kernel/isodir/boot/doom.wad new file mode 100644 index 0000000..fd991d2 Binary files /dev/null and b/src/kernel/isodir/boot/doom.wad differ diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index fecce21..45a9fa4 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,7 +1,7 @@ #include "disp/tty.c" #include "controller/file.h" -#include "multiboot2.h" -void main(unsigned long magic, unsigned long addr) { +#include "multiboot.h" +void main(multiboot_info_t* mbd) { t_init(); // print out terminal stuff before we launch doom t_out("======================="); @@ -16,48 +16,30 @@ void main(unsigned long magic, unsigned long addr) { t_out(" V0.1"); t_out("======================="); - // read module - struct multiboot_tag* tag; - unsigned size; - size = *(unsigned*)addr; - for (tag = (struct multiboot_tag*)(addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag*)((multiboot_uint8_t*)tag + ((tag->size + 7) & ~7))) { - t_out("ran"); - switch (tag->type) { - case MULTIBOOT_TAG_TYPE_MODULE: - t_out("Module: "); - t_out(((struct multiboot_tag_module*)tag)->cmdline); - break; - case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME: - t_out("Bootloader: "); - t_out(((struct multiboot_tag_string*)tag)->string); - break; - case MULTIBOOT_TAG_TYPE_END: - t_out("MULTIBOOT_TAG_TYPE_END"); - break; - case MULTIBOOT_TAG_TYPE_BOOTDEV: - t_out("MULTIBOOT_TAG_TYPE_BOOTDEV"); - break; - case MULTIBOOT_TAG_TYPE_CMDLINE: - t_out("MULTIBOOT_TAG_TYPE_CMDLINE"); - break; - case MULTIBOOT_TAG_TYPE_MMAP: - t_out("MULTIBOOT_TAG_TYPE_MMAP"); - break; - case MULTIBOOT_TAG_TYPE_FRAMEBUFFER: - t_out("MULTIBOOT_TAG_TYPE_FRAMEBUFFER"); - break; - default: - t_out("Idk: "); - char t[200]; - itoa(tag->type, t, 200, 10); - t_out(t); - break; + mountBootDrive(); + + if (!(mbd->flags >> 6 & 0x1)) { + t_out("Fatal Error: Invalid Memory Map."); + asm("hlt"); + } + // Load memory map + for (int i = 0; i < mbd->mmap_length; i += sizeof(multiboot_memory_map_t)) { + multiboot_memory_map_t* mmmt = (multiboot_memory_map_t*)(mbd->mmap_addr + i); + // inform STDLIB where memory is + if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) { + MEMORYLOC loc = { mmmt->addr_low, mmmt->addr_high, mmmt->len_low, mmmt->len_high, mmmt->type }; + addMemoryLocation(loc); } } - mountBootDrive(); - //t_out("Init FS, Test read WAD From boot medium..."); - //t_out("Test results: [not finished] "); + processMemoryMap(); + char debugFull[20] = "Allocated blocks: "; + char debug[5]; + itoa(blocloc, debug, 5, 10); + reverse(debug, 2); + strcat(debugFull, debug); + t_out(debugFull); + // t_out("DoomOS: Init complete."); t_out("DoomOS: Launching Doom..."); t_out("====================================="); diff --git a/src/kernel/multiboot.h b/src/kernel/multiboot.h new file mode 100644 index 0000000..68e70eb --- /dev/null +++ b/src/kernel/multiboot.h @@ -0,0 +1,276 @@ +/* multiboot.h - Multiboot header file. */ +/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY + * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR + * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef MULTIBOOT_HEADER +#define MULTIBOOT_HEADER 1 + + /* How many bytes from the start of the file we search for the header. */ +#define MULTIBOOT_SEARCH 8192 +#define MULTIBOOT_HEADER_ALIGN 4 + +/* The magic field should contain this. */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* This should be in %eax. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* Alignment of multiboot modules. */ +#define MULTIBOOT_MOD_ALIGN 0x00001000 + +/* Alignment of the multiboot info structure. */ +#define MULTIBOOT_INFO_ALIGN 0x00000004 + +/* Flags set in the ’flags’ member of the multiboot header. */ + +/* Align all boot modules on i386 page (4KB) boundaries. */ +#define MULTIBOOT_PAGE_ALIGN 0x00000001 + +/* Must pass memory information to OS. */ +#define MULTIBOOT_MEMORY_INFO 0x00000002 + +/* Must pass video information to OS. */ +#define MULTIBOOT_VIDEO_MODE 0x00000004 + +/* This flag indicates the use of the address fields in the header. */ +#define MULTIBOOT_AOUT_KLUDGE 0x00010000 + +/* Flags to be set in the ’flags’ member of the multiboot info structure. */ + +/* is there basic lower/upper memory information? */ +#define MULTIBOOT_INFO_MEMORY 0x00000001 +/* is there a boot device set? */ +#define MULTIBOOT_INFO_BOOTDEV 0x00000002 +/* is the command-line defined? */ +#define MULTIBOOT_INFO_CMDLINE 0x00000004 +/* are there modules to do something with? */ +#define MULTIBOOT_INFO_MODS 0x00000008 + +/* These next two are mutually exclusive */ + +/* is there a symbol table loaded? */ +#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 +/* is there an ELF section header table? */ +#define MULTIBOOT_INFO_ELF_SHDR 0X00000020 + +/* is there a full memory map? */ +#define MULTIBOOT_INFO_MEM_MAP 0x00000040 + +/* Is there drive info? */ +#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 + +/* Is there a config table? */ +#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 + +/* Is there a boot loader name? */ +#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 + +/* Is there a APM table? */ +#define MULTIBOOT_INFO_APM_TABLE 0x00000400 + +/* Is there video information? */ +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 + +#ifndef ASM_FILE + +typedef unsigned char multiboot_uint8_t; +typedef unsigned short multiboot_uint16_t; +typedef unsigned int multiboot_uint32_t; +typedef unsigned long long multiboot_uint64_t; + +struct multiboot_header +{ + /* Must be MULTIBOOT_MAGIC - see above. */ + multiboot_uint32_t magic; + + /* Feature flags. */ + multiboot_uint32_t flags; + + /* The above fields plus this one must equal 0 mod 2^32. */ + multiboot_uint32_t checksum; + + /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ + multiboot_uint32_t header_addr; + multiboot_uint32_t load_addr; + multiboot_uint32_t load_end_addr; + multiboot_uint32_t bss_end_addr; + multiboot_uint32_t entry_addr; + + /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ + multiboot_uint32_t mode_type; + multiboot_uint32_t width; + multiboot_uint32_t height; + multiboot_uint32_t depth; +}; + +/* The symbol table for a.out. */ +struct multiboot_aout_symbol_table +{ + multiboot_uint32_t tabsize; + multiboot_uint32_t strsize; + multiboot_uint32_t addr; + multiboot_uint32_t reserved; +}; +typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; + +/* The section header table for ELF. */ +struct multiboot_elf_section_header_table +{ + multiboot_uint32_t num; + multiboot_uint32_t size; + multiboot_uint32_t addr; + multiboot_uint32_t shndx; +}; +typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; + +struct multiboot_info +{ + /* Multiboot info version number */ + multiboot_uint32_t flags; + + /* Available memory from BIOS */ + multiboot_uint32_t mem_lower; + multiboot_uint32_t mem_upper; + + /* "root" partition */ + multiboot_uint32_t boot_device; + + /* Kernel command line */ + multiboot_uint32_t cmdline; + + /* Boot-Module list */ + multiboot_uint32_t mods_count; + multiboot_uint32_t mods_addr; + + union + { + multiboot_aout_symbol_table_t aout_sym; + multiboot_elf_section_header_table_t elf_sec; + } u; + + /* Memory Mapping buffer */ + multiboot_uint32_t mmap_length; + multiboot_uint32_t mmap_addr; + + /* Drive Info buffer */ + multiboot_uint32_t drives_length; + multiboot_uint32_t drives_addr; + + /* ROM configuration table */ + multiboot_uint32_t config_table; + + /* Boot Loader Name */ + multiboot_uint32_t boot_loader_name; + + /* APM table */ + multiboot_uint32_t apm_table; + + /* Video */ + multiboot_uint32_t vbe_control_info; + multiboot_uint32_t vbe_mode_info; + multiboot_uint16_t vbe_mode; + multiboot_uint16_t vbe_interface_seg; + multiboot_uint16_t vbe_interface_off; + multiboot_uint16_t vbe_interface_len; + + multiboot_uint64_t framebuffer_addr; + multiboot_uint32_t framebuffer_pitch; + multiboot_uint32_t framebuffer_width; + multiboot_uint32_t framebuffer_height; + multiboot_uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + multiboot_uint8_t framebuffer_type; + union + { + struct + { + multiboot_uint32_t framebuffer_palette_addr; + multiboot_uint16_t framebuffer_palette_num_colors; + }; + struct + { + multiboot_uint8_t framebuffer_red_field_position; + multiboot_uint8_t framebuffer_red_mask_size; + multiboot_uint8_t framebuffer_green_field_position; + multiboot_uint8_t framebuffer_green_mask_size; + multiboot_uint8_t framebuffer_blue_field_position; + multiboot_uint8_t framebuffer_blue_mask_size; + }; + }; +}; +typedef struct multiboot_info multiboot_info_t; + +struct multiboot_color +{ + multiboot_uint8_t red; + multiboot_uint8_t green; + multiboot_uint8_t blue; +}; + +struct multiboot_mmap_entry +{ + multiboot_uint32_t size; + multiboot_uint32_t addr_low; + multiboot_uint32_t addr_high; + multiboot_uint32_t len_low; + multiboot_uint32_t len_high; +#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 + multiboot_uint32_t type; +} __attribute__((packed)); +typedef struct multiboot_mmap_entry multiboot_memory_map_t; + +struct multiboot_mod_list +{ + /* the memory used goes from bytes ’mod_start’ to ’mod_end-1’ inclusive */ + multiboot_uint32_t mod_start; + multiboot_uint32_t mod_end; + + /* Module command line */ + multiboot_uint32_t cmdline; + + /* padding to take it to 16 bytes (must be zero) */ + multiboot_uint32_t pad; +}; +typedef struct multiboot_mod_list multiboot_module_t; + +/* APM BIOS info. */ +struct multiboot_apm_info +{ + multiboot_uint16_t version; + multiboot_uint16_t cseg; + multiboot_uint32_t offset; + multiboot_uint16_t cseg_16; + multiboot_uint16_t dseg; + multiboot_uint16_t flags; + multiboot_uint16_t cseg_len; + multiboot_uint16_t cseg_16_len; + multiboot_uint16_t dseg_len; +}; + +#endif /* ! ASM_FILE */ + +#endif /* ! MULTIBOOT_HEADER */ \ No newline at end of file diff --git a/src/libc/include/stdio.h b/src/libc/include/stdio.h index fdd7b79..bbbe53b 100644 --- a/src/libc/include/stdio.h +++ b/src/libc/include/stdio.h @@ -40,9 +40,58 @@ static int printf(char* str, ...) { /* * memory (very sad) -* this will be handled in the future */ +// When the kernel is given control, we find the size and location of memory + +typedef struct { + uint32_t addr_low, addr_high, length_low, length_high, size; + int type; +} MEMORYLOC; + +static MEMORYLOC memorylocs[15]; +static int memPts = 0; + +static void addMemoryLocation(MEMORYLOC location) { + memorylocs[memPts++] = location; +} + +// allocate the memory + + +typedef struct { +#define MEMORY_FREE 0 + int used; + + int adderess, size; + + struct MEM_BLOCK* next; +} MEM_BLOCK; + +static MEM_BLOCK blocs[256]; +static int blocloc = 0; + +static void processMemoryMap() { + for (int i = 0; i < memPts; i++) { + uint64_t size = memorylocs[i].length_high << 32 | memorylocs[i].length_low; + uint64_t loc = memorylocs[i].addr_high << 32 | memorylocs[i].addr_low; + int constant = 10; // some random constant + + uint64_t offset = 0; + for (int j = 0; i < size / constant; i++) { + MEM_BLOCK tmp = { MEMORY_FREE, loc + offset, size / constant, 0}; + offset += loc + offset; + if (blocloc > 0) { + // We're not the first block, so we can set the last one to point to us + blocs[blocloc - 1].next = &tmp; + blocs[blocloc - 1].adderess = loc + offset; + } + blocs[blocloc++] = tmp; + } + } + +} + static void* malloc(int size) { unsigned char* g; return &g; diff --git a/src/libc/include/stdlib.h b/src/libc/include/stdlib.h index fd18b6d..dc6200c 100644 --- a/src/libc/include/stdlib.h +++ b/src/libc/include/stdlib.h @@ -66,13 +66,14 @@ static int abs(int n) { static void exit(int code) { + asm("hlt"); // to do: // 1. Disable graphics mode // 2. print out error code - // 3. return control to OS + // 3. panic } diff --git a/src/obj/boot.o b/src/obj/boot.o index 1c1f1e2..7071a42 100644 Binary files a/src/obj/boot.o and b/src/obj/boot.o differ diff --git a/src/obj/doom/am_map.o b/src/obj/doom/am_map.o index 889940b..a26650a 100644 Binary files a/src/obj/doom/am_map.o and b/src/obj/doom/am_map.o differ diff --git a/src/obj/doom/d_items.o b/src/obj/doom/d_items.o index e952406..ffc6fbb 100644 Binary files a/src/obj/doom/d_items.o and b/src/obj/doom/d_items.o differ diff --git a/src/obj/doom/d_net.o b/src/obj/doom/d_net.o index ffdec8a..d234cab 100644 Binary files a/src/obj/doom/d_net.o and b/src/obj/doom/d_net.o differ diff --git a/src/obj/doom/doomdef.o b/src/obj/doom/doomdef.o index 963f3c1..729912e 100644 Binary files a/src/obj/doom/doomdef.o and b/src/obj/doom/doomdef.o differ diff --git a/src/obj/doom/f_finale.o b/src/obj/doom/f_finale.o index ff725dc..e12facd 100644 Binary files a/src/obj/doom/f_finale.o and b/src/obj/doom/f_finale.o differ diff --git a/src/obj/doom/f_wipe.o b/src/obj/doom/f_wipe.o index 6a0e552..8280f9c 100644 Binary files a/src/obj/doom/f_wipe.o and b/src/obj/doom/f_wipe.o differ diff --git a/src/obj/doom/g_game.o b/src/obj/doom/g_game.o index a5b44ed..710fe49 100644 Binary files a/src/obj/doom/g_game.o and b/src/obj/doom/g_game.o differ diff --git a/src/obj/doom/hu_lib.o b/src/obj/doom/hu_lib.o index c44f950..8e8d47f 100644 Binary files a/src/obj/doom/hu_lib.o and b/src/obj/doom/hu_lib.o differ diff --git a/src/obj/doom/hu_stuff.o b/src/obj/doom/hu_stuff.o index 18a1054..f99a268 100644 Binary files a/src/obj/doom/hu_stuff.o and b/src/obj/doom/hu_stuff.o differ diff --git a/src/obj/doom/i_main.o b/src/obj/doom/i_main.o index 5083ca2..15618b0 100644 Binary files a/src/obj/doom/i_main.o and b/src/obj/doom/i_main.o differ diff --git a/src/obj/doom/i_net.o b/src/obj/doom/i_net.o index c4a1e32..562256d 100644 Binary files a/src/obj/doom/i_net.o and b/src/obj/doom/i_net.o differ diff --git a/src/obj/doom/i_sound.o b/src/obj/doom/i_sound.o index 8bc7a52..ebafd06 100644 Binary files a/src/obj/doom/i_sound.o and b/src/obj/doom/i_sound.o differ diff --git a/src/obj/doom/i_system.o b/src/obj/doom/i_system.o index 702e76e..6fa6d1c 100644 Binary files a/src/obj/doom/i_system.o and b/src/obj/doom/i_system.o differ diff --git a/src/obj/doom/i_video.o b/src/obj/doom/i_video.o index f44ed2c..7853cbd 100644 Binary files a/src/obj/doom/i_video.o and b/src/obj/doom/i_video.o differ diff --git a/src/obj/doom/info.o b/src/obj/doom/info.o index 6d570bb..57aeb1b 100644 Binary files a/src/obj/doom/info.o and b/src/obj/doom/info.o differ diff --git a/src/obj/doom/m_argv.o b/src/obj/doom/m_argv.o index 1d1ca70..b51c2c0 100644 Binary files a/src/obj/doom/m_argv.o and b/src/obj/doom/m_argv.o differ diff --git a/src/obj/doom/m_fixed.o b/src/obj/doom/m_fixed.o index 10dd160..57917f0 100644 Binary files a/src/obj/doom/m_fixed.o and b/src/obj/doom/m_fixed.o differ diff --git a/src/obj/doom/m_menu.o b/src/obj/doom/m_menu.o index 71f6c79..7d90844 100644 Binary files a/src/obj/doom/m_menu.o and b/src/obj/doom/m_menu.o differ diff --git a/src/obj/doom/m_misc.o b/src/obj/doom/m_misc.o index 2a15fd2..e789250 100644 Binary files a/src/obj/doom/m_misc.o and b/src/obj/doom/m_misc.o differ diff --git a/src/obj/doom/p_ceilng.o b/src/obj/doom/p_ceilng.o index 639fe54..d588427 100644 Binary files a/src/obj/doom/p_ceilng.o and b/src/obj/doom/p_ceilng.o differ diff --git a/src/obj/doom/p_doors.o b/src/obj/doom/p_doors.o index a8f9601..4849097 100644 Binary files a/src/obj/doom/p_doors.o and b/src/obj/doom/p_doors.o differ diff --git a/src/obj/doom/p_enemy.o b/src/obj/doom/p_enemy.o index b5076fe..408997f 100644 Binary files a/src/obj/doom/p_enemy.o and b/src/obj/doom/p_enemy.o differ diff --git a/src/obj/doom/p_floor.o b/src/obj/doom/p_floor.o index 2cb98da..5a47456 100644 Binary files a/src/obj/doom/p_floor.o and b/src/obj/doom/p_floor.o differ diff --git a/src/obj/doom/p_inter.o b/src/obj/doom/p_inter.o index 07e6a52..ff46500 100644 Binary files a/src/obj/doom/p_inter.o and b/src/obj/doom/p_inter.o differ diff --git a/src/obj/doom/p_lights.o b/src/obj/doom/p_lights.o index 882661e..e506b88 100644 Binary files a/src/obj/doom/p_lights.o and b/src/obj/doom/p_lights.o differ diff --git a/src/obj/doom/p_map.o b/src/obj/doom/p_map.o index 48c4109..8428669 100644 Binary files a/src/obj/doom/p_map.o and b/src/obj/doom/p_map.o differ diff --git a/src/obj/doom/p_maputl.o b/src/obj/doom/p_maputl.o index bd13234..c61a9cc 100644 Binary files a/src/obj/doom/p_maputl.o and b/src/obj/doom/p_maputl.o differ diff --git a/src/obj/doom/p_mobj.o b/src/obj/doom/p_mobj.o index db5de3d..50c40e9 100644 Binary files a/src/obj/doom/p_mobj.o and b/src/obj/doom/p_mobj.o differ diff --git a/src/obj/doom/p_plats.o b/src/obj/doom/p_plats.o index 44b4e16..db79740 100644 Binary files a/src/obj/doom/p_plats.o and b/src/obj/doom/p_plats.o differ diff --git a/src/obj/doom/p_pspr.o b/src/obj/doom/p_pspr.o index 8f96f26..88ab94b 100644 Binary files a/src/obj/doom/p_pspr.o and b/src/obj/doom/p_pspr.o differ diff --git a/src/obj/doom/p_saveg.o b/src/obj/doom/p_saveg.o index e4d6491..4fde6f1 100644 Binary files a/src/obj/doom/p_saveg.o and b/src/obj/doom/p_saveg.o differ diff --git a/src/obj/doom/p_setup.o b/src/obj/doom/p_setup.o index f5187f4..9a8c8c4 100644 Binary files a/src/obj/doom/p_setup.o and b/src/obj/doom/p_setup.o differ diff --git a/src/obj/doom/p_sight.o b/src/obj/doom/p_sight.o index f8f3768..94f7ac2 100644 Binary files a/src/obj/doom/p_sight.o and b/src/obj/doom/p_sight.o differ diff --git a/src/obj/doom/p_spec.o b/src/obj/doom/p_spec.o index 565f88a..96e9e56 100644 Binary files a/src/obj/doom/p_spec.o and b/src/obj/doom/p_spec.o differ diff --git a/src/obj/doom/p_switch.o b/src/obj/doom/p_switch.o index b112e8e..cdd5c9c 100644 Binary files a/src/obj/doom/p_switch.o and b/src/obj/doom/p_switch.o differ diff --git a/src/obj/doom/p_telept.o b/src/obj/doom/p_telept.o index 62ebdf5..d5d9ad4 100644 Binary files a/src/obj/doom/p_telept.o and b/src/obj/doom/p_telept.o differ diff --git a/src/obj/doom/p_tick.o b/src/obj/doom/p_tick.o index 0e03b43..3e42e15 100644 Binary files a/src/obj/doom/p_tick.o and b/src/obj/doom/p_tick.o differ diff --git a/src/obj/doom/p_user.o b/src/obj/doom/p_user.o index 8a5eb9d..2e9aa3c 100644 Binary files a/src/obj/doom/p_user.o and b/src/obj/doom/p_user.o differ diff --git a/src/obj/doom/r_bsp.o b/src/obj/doom/r_bsp.o index dc60524..bc2af18 100644 Binary files a/src/obj/doom/r_bsp.o and b/src/obj/doom/r_bsp.o differ diff --git a/src/obj/doom/r_data.o b/src/obj/doom/r_data.o index d339d86..dd9edc9 100644 Binary files a/src/obj/doom/r_data.o and b/src/obj/doom/r_data.o differ diff --git a/src/obj/doom/r_draw.o b/src/obj/doom/r_draw.o index 93a0107..12fb9c5 100644 Binary files a/src/obj/doom/r_draw.o and b/src/obj/doom/r_draw.o differ diff --git a/src/obj/doom/r_main.o b/src/obj/doom/r_main.o index efa6d3f..25a3aed 100644 Binary files a/src/obj/doom/r_main.o and b/src/obj/doom/r_main.o differ diff --git a/src/obj/doom/r_plane.o b/src/obj/doom/r_plane.o index 03e1c5d..c02df10 100644 Binary files a/src/obj/doom/r_plane.o and b/src/obj/doom/r_plane.o differ diff --git a/src/obj/doom/r_segs.o b/src/obj/doom/r_segs.o index 7168a2e..429cb2a 100644 Binary files a/src/obj/doom/r_segs.o and b/src/obj/doom/r_segs.o differ diff --git a/src/obj/doom/r_sky.o b/src/obj/doom/r_sky.o index 467abd6..654bc09 100644 Binary files a/src/obj/doom/r_sky.o and b/src/obj/doom/r_sky.o differ diff --git a/src/obj/doom/r_things.o b/src/obj/doom/r_things.o index 7dfa031..9902999 100644 Binary files a/src/obj/doom/r_things.o and b/src/obj/doom/r_things.o differ diff --git a/src/obj/doom/s_sounds.o b/src/obj/doom/s_sounds.o index 72d2940..f7e4a9a 100644 Binary files a/src/obj/doom/s_sounds.o and b/src/obj/doom/s_sounds.o differ diff --git a/src/obj/doom/st_lib.o b/src/obj/doom/st_lib.o index d465dd8..e38550b 100644 Binary files a/src/obj/doom/st_lib.o and b/src/obj/doom/st_lib.o differ diff --git a/src/obj/doom/st_stuff.o b/src/obj/doom/st_stuff.o index 65e9709..47e1fd8 100644 Binary files a/src/obj/doom/st_stuff.o and b/src/obj/doom/st_stuff.o differ diff --git a/src/obj/doom/v_video.o b/src/obj/doom/v_video.o index ccf4e51..d5a390b 100644 Binary files a/src/obj/doom/v_video.o and b/src/obj/doom/v_video.o differ diff --git a/src/obj/doom/w_wad.o b/src/obj/doom/w_wad.o index 98b7046..1e1aeed 100644 Binary files a/src/obj/doom/w_wad.o and b/src/obj/doom/w_wad.o differ diff --git a/src/obj/doom/wi_stuff.o b/src/obj/doom/wi_stuff.o index b6cc465..674f907 100644 Binary files a/src/obj/doom/wi_stuff.o and b/src/obj/doom/wi_stuff.o differ diff --git a/src/obj/doom/z_zone.o b/src/obj/doom/z_zone.o index fc81648..9c3230e 100644 Binary files a/src/obj/doom/z_zone.o and b/src/obj/doom/z_zone.o differ diff --git a/src/obj/hd.o b/src/obj/hd.o index 15e5a3f..2949e6a 100644 Binary files a/src/obj/hd.o and b/src/obj/hd.o differ diff --git a/src/obj/kernel.o b/src/obj/kernel.o index 795ffce..bf06973 100644 Binary files a/src/obj/kernel.o and b/src/obj/kernel.o differ diff --git a/src/obj/tty.o b/src/obj/tty.o index 8bfa4ae..d27fbfd 100644 Binary files a/src/obj/tty.o and b/src/obj/tty.o differ