diff --git a/sys/include/sys/bootinfo.h b/sys/include/sys/bootinfo.h new file mode 100644 index 0000000..dfb2b78 --- /dev/null +++ b/sys/include/sys/bootinfo.h @@ -0,0 +1,32 @@ +#include + +#define N_BIOS_GEOM 8 + +struct bootinfo { + u_int32_t bi_version; + u_int32_t bi_kernelname; /* represents a char * */ + u_int32_t bi_nfs_diskless; /* struct nfs_diskless * */ + /* End of fields that are always present. */ +#define bi_endcommon bi_n_bios_used + u_int32_t bi_n_bios_used; + u_int32_t bi_bios_geom[N_BIOS_GEOM]; + u_int32_t bi_size; + u_int8_t bi_memsizes_valid; + u_int8_t bi_bios_dev; /* bootdev BIOS unit number */ + u_int8_t bi_pad[2]; + u_int32_t bi_basemem; + u_int32_t bi_extmem; + u_int32_t bi_symtab; /* struct symtab * */ + u_int32_t bi_esymtab; /* struct symtab * */ + /* Items below only from advanced bootloader */ + u_int32_t bi_kernend; /* end of kernel space */ + u_int32_t bi_envp; /* environment */ + u_int32_t bi_modulep; /* preloaded modules */ + uint32_t bi_memdesc_version; /* EFI memory desc version */ + uint64_t bi_memdesc_size; /* sizeof EFI memory desc */ + uint64_t bi_memmap; /* pa of EFI memory map */ + uint64_t bi_memmap_size; /* size of EFI memory map */ + uint64_t bi_hcdp; /* DIG64 HCDP table */ + uint64_t bi_fpswa; /* FPSWA interface */ + uint64_t bi_systab; /* pa of EFI system table */ +}; diff --git a/sys/init/main.c b/sys/init/main.c index 9a068c1..8b4ebbe 100644 --- a/sys/init/main.c +++ b/sys/init/main.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,18 @@ #define B_CONTROLLERSHIFT 20 #define B_CONTROLLERMASK 0xf #define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK) +/* + * Constants for converting boot-style device number to type, + * adaptor (uba, mba, etc), unit number and partition number. + * Type (== major device number) is in the low byte + * for backward compatibility. Except for that of the "magic + * number", each mask applies to the shifted value. + * Format: + * (4) (8) (4) (8) (8) + * -------------------------------- + * |MA | SLICE | UN| PART | TYPE | + * -------------------------------- + */ #define B_SLICESHIFT 20 #define B_SLICEMASK 0xff #define B_SLICE(val) (((val)>>B_SLICESHIFT) & B_SLICEMASK) @@ -57,6 +70,7 @@ #define B_TYPEMASK 0xff #define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK) + /***************************************************************************************** Desc: The Kernels Descriptor table: 0 - 0x00 - Dummy Entry @@ -98,6 +112,11 @@ static char *argv_init[2] = { "init", NULL, }; // ARGV For Initial Proccess static char *envp_init[6] = { "HOME=/", "PWD=/", "PATH=/bin:/sbin:/usr/bin:/usr/sbin", "USER=root", "GROUP=admin", NULL, }; //ENVP For Initial Proccess +struct bootinfo _bootinfo; +char _kernelname[512]; +u_long _bootdev; +u_long _boothowto; + /** * \brief This is the entry point into the os where all of the kernels sub systems are started up. * @@ -119,7 +138,7 @@ /* New Root Mount Point */ //Old 2 new 10 kprintf("[0x%X][0x%X:0x%X:0x%X:0x%X:0x%X:0x%X]\n", B_ADAPTOR(rootdev), B_CONTROLLER(rootdev), B_SLICE(rootdev), B_UNIT(rootdev), B_PARTITION(rootdev), B_TYPE(rootdev)); - //if ( vfs_mount( 0x1, B_PARTITION(rootdev) + 2, 0x0, 0xAA, "sys", "rw" ) != 0x0 ) { + //if ( vfs_mount( B_UNIT(_bootdev), B_PARTITION(_bootdev), 0x0, 0xAA, "sys", "rw" ) != 0x0 ) { if (vfs_mount(0x1, 0x2, 0x0, 0xAA, "sys", "rw") != 0x0) { kprintf("Problem Mounting sys Mount Point\n"); } @@ -141,13 +160,20 @@ kprintf("MemoryMap: [0x%X]\n", vmmMemoryMap); kprintf("Starting OS\n"); - execThread(systemTask, 0x2000, 0x0); - execFile("sys:/bin/init", argv_init, envp_init, 0x0); /* OS Initializer */ //kprintf("SDE Thread Start! [0x%X]\n", &sdeThread); //execThread(&sdeThread, 0x2000,0x0); + kprintf("Kernel Name: [%s], Boot How To [0x%X], Boot Dev: [0x%X]\n", _kernelname, _boothowto, _bootdev); + kprintf("B_TYPE(0x%X), B_SLICE(0x%X), B_UNIT(0x%X), B_PARTITION(0x%X)\n", B_TYPE(_bootdev), B_SLICE(_bootdev), B_UNIT(_bootdev), B_PARTITION(_bootdev)); + kprintf("_bootinfo.bi_version: 0x%X\n", _bootinfo.bi_version); + kprintf("_bootinfo.bi_size: 0x%X\n", _bootinfo.bi_size); + kprintf("_bootinfo.bi_bios_dev: 0x%X\n", _bootinfo.bi_bios_dev); + + execThread(systemTask, 0x2000, 0x0); + execFile("sys:/bin/init", argv_init, envp_init, 0x0); /* OS Initializer */ + irqEnable(0x0); while (0x1) diff --git a/sys/init/start.S b/sys/init/start.S index 830a02f..edbd77b 100644 --- a/sys/init/start.S +++ b/sys/init/start.S @@ -26,6 +26,14 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define BI_VERSION 0x0 +#define BI_KERNELNAME 0x4 +#define BI_ENDCOMMON 12 +#define BI_SIZE 48 +#define BOOTINFO_SIZE 135 +#define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */ + + .globl _start .text .code32 @@ -35,6 +43,7 @@ movl %esp,%ebp pushl $0x00000002 popfl + /* Clear the BSS */ movl $(_end),%ecx movl $(__bss_start),%edi @@ -43,6 +52,14 @@ cld rep stosb + + /* Fix Up GS/FS */ + mov %dx,%ax + mov %ax,%fs + mov %ax,%gs + + /* Get Boot Args */ + call get_bootargs /* Load GDT */ lgdtl (loadGDT) @@ -72,5 +89,90 @@ pushl $0xBEEF; // Marker subl $0xE,%esp; call kmain +get_bootargs: + /* + * The old style disk boot blocks fake a frame on the stack and + * did an lret to get here. The frame on the stack has a return + * address of 0. + */ + + cmpl $0,4(%ebp) + je old_boot + + /* + * We have some form of return address, so this is either the + * old diskless netboot code, or the new uniform code. That can + * be detected by looking at the 5th argument, if it is 0 + * we are being booted by the new uniform boot code. + */ + cmpl $0,24(%ebp) + je new_boot + + hlt +new_boot: + movl 28(%ebp),%ebx /* &bootinfo.version */ + movl BI_VERSION(%ebx),%eax + cmpl $1,%eax /* We only understand version 1 */ + je 1f + movl $1,%eax /* Return status */ + leave + /* + * XXX this returns to our caller's caller (as is required) since + * we didn't set up a frame and our caller did. + */ + hlt /* MrO */ + ret +1: + /* + * If we have a kernelname copy it in + */ + movl BI_KERNELNAME(%ebx),%esi + cmpl $0,%esi + je 2f /* No kernelname */ + movl 512,%ecx /* Brute force!!! */ + movl $_kernelname,%edi + cmpb $'/',(%esi) /* Make sure it starts with a slash */ + je 1f + movb $'/',(%edi) + incl %edi + decl %ecx +1: + cld + rep + movsb + +2: + /* + * Determine the size of the boot loader's copy of the bootinfo + * struct. This is impossible to do properly because old versions + * of the struct don't contain a size field and there are 2 old + * versions with the same version number. + */ + movl $BI_ENDCOMMON,%ecx /* prepare for sizeless version */ + testl $RB_BOOTINFO,8(%ebp) /* bi_size (and bootinfo) valid? */ + je got_bi_size /* no, sizeless version */ + movl BI_SIZE(%ebx),%ecx +got_bi_size: + + /* + * Copy the common part of the bootinfo struct + */ + movl %ebx,%esi + movl $_bootinfo,%edi + cmpl $BOOTINFO_SIZE,%ecx + jbe got_common_bi_size + movl $BOOTINFO_SIZE,%ecx +got_common_bi_size: + cld + rep + movsb +old_boot: + movl 8(%ebp),%eax + movl %eax,(_boothowto) + movl 12(%ebp),%eax + movl %eax,(_bootdev) + + ret + .data .comm kStack,0x1000