Revert "[boot] A third stage? Really?"

This reverts commit c23080c46c.
This commit is contained in:
Kevin Lange 2011-02-21 19:36:18 -06:00
parent c23080c46c
commit ebd3efb47b
14 changed files with 65 additions and 179 deletions

3
.gitignore vendored
View File

@ -4,8 +4,7 @@ toaruos-initrd
*.swp
bootloader/stage1.bin
bootloader/stage2.bin
bootloader/stage3.bin
initrd/kernel
initrd/stage3
initrd/stage2
.gdb_history
testdisk

View File

@ -45,12 +45,11 @@ kernel/start.o: kernel/start.asm
################
# Ram disk #
################
toaruos-initrd: initrd bootloader/stage1.bin bootloader/stage2.bin initrd/stage3 initrd/kernel
toaruos-initrd: initrd bootloader/stage1.bin initrd/stage2 initrd/kernel
@${ECHO} -n "\033[32m initrd Generating initial RAM disk\033[0m"
@-rm -f toaruos-initrd
@${GENEXT} -d initrd -q -b 249 toaruos-initrd
@${DD} if=bootloader/stage1.bin of=toaruos-initrd 2>/dev/null
@${DD} if=bootloader/stage2.bin of=toaruos-initrd seek=1 count=1 bs=512 2>/dev/null
@${ECHO} "\r\033[32;1m initrd Generated initial RAM disk image\033[0m"
### Ram Disk installers...
@ -60,8 +59,8 @@ initrd/kernel: toaruos-kernel
@cp toaruos-kernel initrd/kernel
# Second-stage bootloader
initrd/stage3: bootloader/stage3.bin
@cp bootloader/stage3.bin initrd/stage3
initrd/stage2: bootloader/stage2.bin
@cp bootloader/stage2.bin initrd/stage2
################
# Bootloader #
@ -70,7 +69,7 @@ initrd/stage3: bootloader/stage3.bin
# Stage 1
bootloader/stage1/main.o: bootloader/stage1/main.c
@${ECHO} -n "\033[32m CC $<\033[0m"
@${GCC} ${CFLAGS} -I./kernel/include/ -c -o $@ $<
@${GCC} ${CFLAGS} -c -o $@ $<
@${ECHO} "\r\033[32;1m CC $<\033[0m"
bootloader/stage1/start.o: bootloader/stage1/start.s
@ -86,30 +85,25 @@ 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} -I./kernel/include/ -c -o $@ $<
@${GCC} ${CFLAGS} -c -o $@ $<
@${ECHO} "\r\033[32;1m CC $<\033[0m"
bootloader/stage2.bin: bootloader/stage2/main.o bootloader/stage2/link.ld
@${ECHO} -n "\033[32m ld $<\033[0m"
@${LD} -o bootloader/stage2.bin -T bootloader/stage2/link.ld bootloader/stage2/main.o
@${ECHO} "\r\033[32;1m ld $<\033[0m"
# Stage 3
bootloader/stage3/main.o: bootloader/stage3/main.c
@${ECHO} -n "\033[32m CC $<\033[0m"
@${GCC} ${CFLAGS} -I./kernel/include/ -c -o $@ $<
@${ECHO} "\r\033[32;1m CC $<\033[0m"
bootloader/stage3/start.o: bootloader/stage3/start.s
bootloader/stage2/start.o: bootloader/stage2/start.s
@${ECHO} -n "\033[32m yasm $<\033[0m"
@${YASM} -f elf32 -p gas -o $@ $<
@${ECHO} "\r\033[32;1m yasm $<\033[0m"
bootloader/stage3.bin: bootloader/stage3/main.o bootloader/stage3/start.o bootloader/stage3/link.ld
bootloader/stage2.bin: bootloader/stage2/main.o bootloader/stage2/start.o bootloader/stage2/link.ld
@${ECHO} -n "\033[32m ld $<\033[0m"
@${LD} -o bootloader/stage3.bin -T bootloader/stage3/link.ld bootloader/stage3/start.o bootloader/stage3/main.o
@${LD} -o bootloader/stage2.bin -T bootloader/stage2/link.ld bootloader/stage2/start.o bootloader/stage2/main.o
@${ECHO} "\r\033[32;1m ld $<\033[0m"
testdisk: bootloader/stage1.bin bootloader/stage2.bin
@${ECHO} "\033[31;1m WARN This disk is a temporary development test only!\033[0m"
@${ECHO} -n "\033[34m -- Building tesdisk...\033[0m"
@cat bootloader/stage1.bin bootloader/stage2.bin > testdisk
@${ECHO} "\r\033[34;1m -- Testdisk compiled. \033[0m"
###############
# clean #
###############
@ -124,9 +118,7 @@ clean:
@-rm -f bootloader/stage1/*.o
@-rm -f bootloader/stage2.bin
@-rm -f bootloader/stage2/*.o
@-rm -f bootloader/stage3.bin
@-rm -f bootloader/stage3/*.o
@-rm -f initrd/stage3
@-rm -f initrd/stage2
@-rm -f initrd/kernel
@-rm -f testdisk
@${ECHO} "\r\033[31;1m RM Finished cleaning.\033[0m\033[K"

View File

@ -7,16 +7,8 @@
*/
__asm__(".code16gcc\n");
#include <ext2.h>
#define PRINT(s) __asm__ ("movw %0, %%si\ncall _print" : : "l"((short)(int)s))
#define EXT2_SUPER_OFFSET 0x6000
#define EXT2_START 0x5C00
#define ext2_get_block(block) (void *)(EXT2_START + (0x400 << sblock->log_block_size * block))
/*
* Read some sectors from the first hard drive
*/
void read(unsigned char count, unsigned char sector, short segment, short offset)
{
__asm__ __volatile__ (
@ -40,28 +32,10 @@ void read(unsigned char count, unsigned char sector, short segment, short offset
*/
void main()
{
/*
* Read the EXT2 Super Block
*/
read(2,3,0,EXT2_SUPER_OFFSET);
ext2_superblock_t * sblock = (ext2_superblock_t *)EXT2_SUPER_OFFSET;
ext2_bgdescriptor_t * rblock = (ext2_bgdescriptor_t *)(EXT2_SUPER_OFFSET + 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 *)((uintptr_t)itable + sblock->inode_size);
void * block;
ext2_dir_t * direntry = NULL;
block = (void *)ext2_get_block((rnode->block[0]));
uint32_t dir_offset = 0;
while (dir_offset < rnode->size) {
ext2_dir_t * d_ent = (ext2_dir_t *)((uintptr_t)block + dir_offset);
if (((char *)&d_ent->name)[0] == 's') {
direntry = d_ent;
break;
}
dir_offset += d_ent->rec_len;
}
*((unsigned int *)0x5000) = direntry->inode;
read(1,2,0,0x7e00);
/* Stage 2 */
PRINT("Loading... ");
read(2,2,0,0x7e00);
PRINT("Ready.\r\n");
/* Let's do this... */
__asm__ __volatile__ ("jmp $0x00, $0x7e00");
}

View File

@ -9,8 +9,24 @@
_start:
movw $0x00,%ax # Initialize segments...
movw %ax,%ds # ... data
movw %ax,%es # ... e?
movw %ax,%ss # ... selector
movw $0x7bf0,%sp # stack pointer
.extern main # Jump the C main entry point...
jmp main
.global _print
_print:
movb $0x0E,%ah # set registers for
movb $0x00,%bh # bios video call
movb $0x07,%bl
_print.next:
lodsb # string stuff
orb %al,%al # if 0...
jz _print.return # return
int $0x10 # print character
jmp _print.next # continue
_print.return:
retl

View File

@ -1,8 +1,7 @@
OUTPUT_FORMAT(binary)
ENTRY(main)
ENTRY(_start)
load = 0x7e00;
phys = 0x0;
end = 0x1ff;
SECTIONS
{
.text load : AT(phys)
@ -19,9 +18,15 @@ SECTIONS
{
*(.rodata)
}
.end : AT(end)
.padding : AT (phys + SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata))
{
BYTE(0x01);
/* Pad so we have at least one sector */
. = ALIGN(4096);
/* Add an additional sector for good measure */
. = ALIGN(508);
/* End it with a sad face */
SHORT(0xada5);
SHORT(0xcefa);
}
/DISCARD/ :
{

View File

@ -7,18 +7,16 @@
*/
__asm__(".code16gcc\n");
#include <ext2.h>
#define EXT2_SUPER_OFFSET 0x6000
#define EXT2_START 0x5C00
#define PRINT(s) __asm__ ("movw %0, %%si\ncall _print" : : "l"((short)(int)s))
/*
* Main entry point
*/
void main()
{
ext2_superblock_t * sblock = (ext2_superblock_t *)EXT2_SUPER_OFFSET;
ext2_bgdescriptor_t * rblock = (ext2_bgdescriptor_t *)(EXT2_SUPER_OFFSET + 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 *)((uintptr_t)itable + sblock->inode_size * (*(uint32_t *)(0x5000)));
PRINT("== Mr. Boots Stage 2 Bootloader ==\r\n");
/* And that's it for now... */
__asm__ __volatile__ ("hlt");
while (1) {};
}

View File

@ -1,38 +0,0 @@
OUTPUT_FORMAT(binary)
ENTRY(_start)
load = 0x8000;
phys = 0x0;
SECTIONS
{
.text load : AT(phys)
{
*(.text)
. = ALIGN(4);
}
.data : AT(phys + SIZEOF(.text))
{
*(.data)
. = ALIGN(4);
}
.rodata : AT (phys + SIZEOF(.text) + SIZEOF(.data))
{
*(.rodata)
}
.padding : AT (phys + SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata))
{
/* Pad so we have at least one sector */
. = ALIGN(4096);
/* Add an additional sector for good measure */
. = ALIGN(508);
/* End it with a sad face */
SHORT(0xada5);
SHORT(0xcefa);
}
/DISCARD/ :
{
*(.bss)
*(.comment)
*(.eh_frame)
*(.note.gnu.build-id)
}
}

View File

@ -1,22 +0,0 @@
/*
* Mr. Boots Stage 1
*/
/*
* 16-bit bootloader
*/
__asm__(".code16gcc\n");
#define PRINT(s) __asm__ ("movw %0, %%si\ncall _print" : : "l"((short)(int)s))
/*
* Main entry point
*/
void main()
{
PRINT("== Mr. Boots Stage 2 Bootloader ==\r\n");
/* And that's it for now... */
__asm__ __volatile__ ("hlt");
while (1) {};
}

View File

@ -1,32 +0,0 @@
#
# Mr. Boots - Stage 2 (ASM entry point)
#
.code16
.text
.global _start
.global _print
_start:
movw $0x00,%ax # Initialize segments...
movw %ax,%ds # ... data
movw %ax,%es # ... e?
movw %ax,%ss # ... selector
movw $0x7bf0,%sp # stack pointer
.extern main # Jump the C main entry point...
jmp main
_print:
movb $0x0E,%ah # set registers for
movb $0x00,%bh # bios video call
movb $0x07,%bl
_print.next:
lodsb # string stuff
orb %al,%al # if 0...
jz _print.return # return
int $0x10 # print character
jmp _print.next # continue
_print.return:
retl

View File

@ -1,7 +1,8 @@
#ifndef EXT2_H
#define EXT2_h
#include <types.h>
#include <system.h>
#include <fs.h>
#define EXT2_SUPER_MAGIC 0xEF53

View File

@ -1,8 +1,6 @@
#ifndef FS_H
#define FS_H
#include <types.h>
#define FS_FILE 0x01
#define FS_DIRECTORY 0x02
#define FS_CHARDEVICE 0x04

View File

@ -1,7 +1,17 @@
#ifndef __SYSTEM_H
#define __SYSTEM_H
#include <types.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;
/* Unimportant Kernel Strings */
#define KERNEL_UNAME "ToAruOS"
#define KERNEL_VERSION_STRING "0.0.1"

View File

@ -1,14 +0,0 @@
#ifndef TYPES_H
#define TYPES_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;
#endif

View File

@ -30,7 +30,6 @@
*/
#include <system.h>
#include <fs.h>
#include <boot.h>
#include <ext2.h>