[boot] Well now, we have a stage two that almost does something
This commit is contained in:
parent
6067f11faf
commit
20efbe7b74
2
Makefile
2
Makefile
@ -82,7 +82,7 @@ bootloader/stage1.bin: bootloader/stage1/main.o bootloader/stage1/start.o bootlo
|
||||
# Stage 2
|
||||
bootloader/stage2/main.o: bootloader/stage2/main.c
|
||||
@${ECHO} -n "\033[32m CC $<\033[0m"
|
||||
@${GCC} ${CFLAGS} -c -o $@ $<
|
||||
@${GCC} ${CFLAGS} -I./kernel/include -c -o $@ $<
|
||||
@${ECHO} "\r\033[32;1m CC $<\033[0m"
|
||||
|
||||
bootloader/stage2/start.o: bootloader/stage2/start.s
|
||||
|
@ -33,7 +33,7 @@ void read(unsigned char count, unsigned char sector, short segment, short offset
|
||||
void main()
|
||||
{
|
||||
PRINT("Loading... ");
|
||||
read(2,2,0,0x7e00);
|
||||
read(6,2,0,0x7e00);
|
||||
PRINT("Ready.\r\n");
|
||||
|
||||
/* Let's do this... */
|
||||
|
@ -21,7 +21,7 @@ SECTIONS
|
||||
.padding : AT (phys + SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata))
|
||||
{
|
||||
/* Pad so we have at least one sector */
|
||||
. = ALIGN(4096);
|
||||
. = ALIGN(512);
|
||||
/* Add an additional sector for good measure */
|
||||
. = ALIGN(508);
|
||||
/* End it with a sad face */
|
||||
|
@ -7,15 +7,88 @@
|
||||
*/
|
||||
__asm__(".code16gcc\n");
|
||||
|
||||
#define BOOTLOADER
|
||||
#include <ext2.h>
|
||||
|
||||
#define EXT2_SUPER_OFFSET 0x1000
|
||||
#define EXT2_START (EXT2_SUPER_OFFSET - 0x400)
|
||||
|
||||
#define ext2_get_block(block) (EXT2_START + (0x400 << sblock->log_block_size) * block)
|
||||
|
||||
#define PRINT(s) __asm__ ("movw %0, %%si\ncall _print" : : "l"((short)(int)s))
|
||||
|
||||
void read(unsigned char count, unsigned char sector, short segment, short offset)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"movw %0, %%es\n"
|
||||
"movw %1, %%bx\n"
|
||||
"movb %2, %%al\n"
|
||||
"movb $0, %%ch\n"
|
||||
"movb %3, %%cl\n"
|
||||
"movb $0, %%dh\n"
|
||||
"movb $0x80, %%dl\n"
|
||||
"movb $0x02, %%ah\n"
|
||||
"int $0x13" : :
|
||||
"l" (segment),
|
||||
"l" (offset),
|
||||
"m" (count),
|
||||
"m" (sector));
|
||||
}
|
||||
|
||||
/*
|
||||
* Main entry point
|
||||
*/
|
||||
void main()
|
||||
{
|
||||
PRINT("== Mr. Boots Stage 2 Bootloader ==\r\n");
|
||||
PRINT("M");
|
||||
/*
|
||||
* Load up the superblock
|
||||
*/
|
||||
read(16,3,0,EXT2_SUPER_OFFSET);
|
||||
ext2_superblock_t * sblock = (ext2_superblock_t *)(EXT2_START + 0x400);
|
||||
if (sblock->magic != EXT2_SUPER_MAGIC) {
|
||||
goto failure;
|
||||
}
|
||||
if (sblock->inode_size == 0) {
|
||||
sblock->inode_size = 128;
|
||||
}
|
||||
ext2_bgdescriptor_t * rblock = (ext2_bgdescriptor_t *)(EXT2_START + 0x400 + 0x400);
|
||||
ext2_inodetable_t * itable = (ext2_inodetable_t *)(EXT2_START + (0x400 << sblock->log_block_size) * rblock->inode_table);
|
||||
ext2_inodetable_t * rnode = (ext2_inodetable_t *)((unsigned short)(unsigned int)itable + (unsigned short)(unsigned int)sblock->inode_size);
|
||||
PRINT("r");
|
||||
|
||||
/*
|
||||
* Grab the first inode's data...
|
||||
*/
|
||||
read(2,9 + (ext2_get_block((rnode->block[0]))) / 0x200,0,EXT2_SUPER_OFFSET + 0xc00);
|
||||
void * block;
|
||||
ext2_dir_t * direntry = NULL;
|
||||
block = (void *)ext2_get_block((rnode->block[0]));
|
||||
|
||||
PRINT(". ");
|
||||
|
||||
uint32_t dir_offset = 0;
|
||||
dir_offset = 0;
|
||||
while (dir_offset < rnode->size) {
|
||||
ext2_dir_t * d_ent = (ext2_dir_t *)((unsigned short)(unsigned int)block + dir_offset);
|
||||
if (((char *)&d_ent->name)[0] == 'k'){
|
||||
direntry = d_ent;
|
||||
goto success;
|
||||
}
|
||||
dir_offset += d_ent->rec_len;
|
||||
}
|
||||
goto failure;
|
||||
success:
|
||||
PRINT("B");
|
||||
|
||||
|
||||
PRINT("o");
|
||||
PRINT("o");
|
||||
PRINT("t");
|
||||
PRINT("s");
|
||||
|
||||
failure:
|
||||
PRINT("\023");
|
||||
/* And that's it for now... */
|
||||
__asm__ __volatile__ ("hlt");
|
||||
while (1) {};
|
||||
|
@ -376,6 +376,10 @@ initrd_mount(
|
||||
initrd_root_block = (ext2_bgdescriptor_t *)((uintptr_t)initrd_start + 1024 + 1024);
|
||||
initrd_inode_table = (ext2_inodetable_t *)((uintptr_t)initrd_start + (1024 << initrd_superblock->log_block_size) * initrd_root_block->inode_table);
|
||||
ext2_inodetable_t * root_inode = ext2_get_inode(2);
|
||||
kprintf("[DEBUG] root block 0 is %d\n", root_inode->block[0]);
|
||||
kprintf("[DEBUG] root size is %d\n", root_inode->size);
|
||||
kprintf("[DEBUG] uid is %d\n", root_inode->uid);
|
||||
kprintf("[DEBUG] atime is %d\n", root_inode->atime);
|
||||
initrd_root = (fs_node_t *)malloc(sizeof(fs_node_t));
|
||||
assert(initrd_node_root(root_inode, initrd_root));
|
||||
fs_root = initrd_root;
|
||||
|
@ -1,8 +1,7 @@
|
||||
#ifndef EXT2_H
|
||||
#define EXT2_h
|
||||
|
||||
#include <system.h>
|
||||
#include <fs.h>
|
||||
#include <types.h>
|
||||
|
||||
#define EXT2_SUPER_MAGIC 0xEF53
|
||||
|
||||
|
@ -1,25 +1,12 @@
|
||||
#ifndef __SYSTEM_H
|
||||
#define __SYSTEM_H
|
||||
|
||||
/* Types */
|
||||
|
||||
#define NULL ((void *)0UL)
|
||||
|
||||
typedef unsigned long uintptr_t;
|
||||
typedef long size_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#include <types.h>
|
||||
|
||||
/* Unimportant Kernel Strings */
|
||||
#define KERNEL_UNAME "ToAruOS"
|
||||
#define KERNEL_VERSION_STRING "0.0.1"
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define INT32_MAX 0x7fffffffL
|
||||
#define UINT32_MAX 0xffffffffL
|
||||
|
||||
extern void *sbrk(uintptr_t increment);
|
||||
|
||||
/* Kernel Main */
|
||||
|
24
kernel/include/types.h
Normal file
24
kernel/include/types.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
/* Types */
|
||||
|
||||
#define NULL ((void *)0UL)
|
||||
|
||||
#ifndef BOOTLOADER
|
||||
typedef unsigned long uintptr_t;
|
||||
#else
|
||||
typedef unsigned short uintptr_t;
|
||||
#endif
|
||||
typedef unsigned long size_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define INT32_MAX 0x7fffffffL
|
||||
#define UINT32_MAX 0xffffffffL
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user