[boot] Stage 2
This commit is contained in:
parent
a86253784f
commit
8e49e88857
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,5 +4,6 @@ toaruos-initrd
|
||||
*.swp
|
||||
bootloader/stage1.bin
|
||||
bootloader/stage2.bin
|
||||
initrd/boot
|
||||
initrd/kernel
|
||||
initrd/stage2
|
||||
.gdb_history
|
||||
|
38
Makefile
38
Makefile
@ -45,7 +45,7 @@ kernel/start.o: kernel/start.asm
|
||||
################
|
||||
# Ram disk #
|
||||
################
|
||||
toaruos-initrd: initrd bootloader/stage1.bin initrd/boot/kernel
|
||||
toaruos-initrd: initrd bootloader/stage1.bin 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
|
||||
@ -55,18 +55,18 @@ toaruos-initrd: initrd bootloader/stage1.bin initrd/boot/kernel
|
||||
### Ram Disk installers...
|
||||
|
||||
# Kernel
|
||||
initrd/boot/kernel: toaruos-kernel
|
||||
@mkdir -p initrd/boot
|
||||
@cp toaruos-kernel initrd/boot/kernel
|
||||
initrd/kernel: toaruos-kernel
|
||||
@cp toaruos-kernel initrd/kernel
|
||||
|
||||
# Second-stage bootloader
|
||||
initrd/boot/stage2: bootloader/stage2.bin
|
||||
@mkdir -p initrd/boot
|
||||
initrd/stage2: bootloader/stage2.bin
|
||||
@cp bootloader/stage2.bin initrd/boot/stage2
|
||||
|
||||
################
|
||||
# Bootloader #
|
||||
################
|
||||
|
||||
# Stage 1
|
||||
bootloader/stage1/main.o: bootloader/stage1/main.c
|
||||
@${ECHO} -n "\033[32m CC $<\033[0m"
|
||||
@${GCC} ${CFLAGS} -c -o $@ $<
|
||||
@ -82,6 +82,26 @@ bootloader/stage1.bin: bootloader/stage1/main.o bootloader/stage1/start.o bootlo
|
||||
@${LD} -o bootloader/stage1.bin -T bootloader/stage1/link.ld bootloader/stage1/start.o bootloader/stage1/main.o
|
||||
@${ECHO} "\r\033[32;1m ld $<\033[0m"
|
||||
|
||||
# Stage 2
|
||||
bootloader/stage2/main.o: bootloader/stage2/main.c
|
||||
@${ECHO} -n "\033[32m CC $<\033[0m"
|
||||
@${GCC} ${CFLAGS} -c -o $@ $<
|
||||
@${ECHO} "\r\033[32;1m CC $<\033[0m"
|
||||
|
||||
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/stage2.bin: bootloader/stage2/main.o bootloader/stage2/start.o bootloader/stage2/link.ld
|
||||
@${ECHO} -n "\033[32m ld $<\033[0m"
|
||||
@${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"
|
||||
|
||||
|
||||
###############
|
||||
# clean #
|
||||
###############
|
||||
clean:
|
||||
@${ECHO} -n "\033[31m RM Cleaning... \033[0m"
|
||||
@-rm -f toaruos-kernel
|
||||
@ -91,6 +111,8 @@ clean:
|
||||
@-rm -f kernel/core/fs/*.o
|
||||
@-rm -f bootloader/stage1.bin
|
||||
@-rm -f bootloader/stage1/*.o
|
||||
@-rm -f initrd/boot/stage2
|
||||
@-rm -f initrd/boot/kernel
|
||||
@-rm -f bootloader/stage2.bin
|
||||
@-rm -f bootloader/stage2/*.o
|
||||
@-rm -f initrd/stage2
|
||||
@-rm -f initrd/kernel
|
||||
@${ECHO} "\r\033[31;1m RM Finished cleaning.\033[0m\033[K"
|
||||
|
28
bootloader/stage2/link.ld
Normal file
28
bootloader/stage2/link.ld
Normal file
@ -0,0 +1,28 @@
|
||||
OUTPUT_FORMAT(binary)
|
||||
ENTRY(_start)
|
||||
load = 0x7e00;
|
||||
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)
|
||||
}
|
||||
/DISCARD/ :
|
||||
{
|
||||
*(.bss)
|
||||
*(.comment)
|
||||
*(.eh_frame)
|
||||
*(.note.gnu.build-id)
|
||||
}
|
||||
}
|
28
bootloader/stage2/main.c
Normal file
28
bootloader/stage2/main.c
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Mr. Boots Stage 1
|
||||
*/
|
||||
|
||||
/*
|
||||
* 16-bit bootloader
|
||||
*/
|
||||
__asm__(".code16gcc\n");
|
||||
|
||||
void kprint(short s)
|
||||
{
|
||||
__asm__ __volatile__ ("movw %0, %%si\n"
|
||||
"call _print" : : "l" ((short)s));
|
||||
}
|
||||
|
||||
/*
|
||||
* Main entry point
|
||||
*/
|
||||
int main() {
|
||||
kprint((short)(int)"Welcome to C!\r\n");
|
||||
|
||||
/* And that's it for now... */
|
||||
__asm__ __volatile__ ("hlt");
|
||||
while (1) {};
|
||||
|
||||
/* Uh oh */
|
||||
return -1;
|
||||
}
|
46
bootloader/stage2/start.s
Normal file
46
bootloader/stage2/start.s
Normal file
@ -0,0 +1,46 @@
|
||||
#
|
||||
# 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
|
||||
|
||||
movw $bmsga, %si # Print "Starting..."
|
||||
calll _print # ...
|
||||
|
||||
.extern main # Jump the C main entry point...
|
||||
calll main
|
||||
|
||||
movw $bmsgb, %si # We should not be here...
|
||||
calll _print # ...
|
||||
hlt
|
||||
|
||||
_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
|
||||
|
||||
.data
|
||||
|
||||
bmsga:
|
||||
.string "Starting Stage 2...\r\n"
|
||||
bmsgb:
|
||||
.string "Critical failure!\r\n"
|
Loading…
Reference in New Issue
Block a user