Kernel can now succesfully boot
This commit is contained in:
parent
b3558c2508
commit
461136c643
11 changed files with 132 additions and 37 deletions
54
kernel/build
54
kernel/build
|
@ -1,35 +1,49 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
DIR="${BASH_SOURCE%/*}"
|
(
|
||||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
set -e
|
||||||
|
|
||||||
. "$DIR/functions"
|
DIR="${BASH_SOURCE%/*}"
|
||||||
|
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||||
|
|
||||||
get_version
|
. "$DIR/functions"
|
||||||
|
|
||||||
cp config.aphro config.aphro.tmp
|
rm config.aphro.tmp
|
||||||
|
cp config.aphro config.aphro.tmp
|
||||||
|
|
||||||
export $(grep -Ev '^#' config.aphro.tmp | xargs)
|
export $(grep -Ev '^#' config.aphro.tmp | xargs)
|
||||||
|
|
||||||
cd ../kernel
|
get_version
|
||||||
|
|
||||||
cargo build --target i686-unknown-none.json --release -Zbuild-std --bin entrypoint
|
if [[ "$CFG_VERSION" != "$VERSION" ]]; then
|
||||||
# build the kernel's entrypoint
|
echo -n "[WARN] Configuration version \"$CFG_VERSION\" is different then actual version \"$VERSION\""
|
||||||
|
if [[ "$CONT_WITH_DIFFERENT_VERSION" != "true" ]]; then
|
||||||
|
echo "; not continuing"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
cp target/i686-unknown-none/release/entrypoint kernel.flat
|
cd ../kernel
|
||||||
# copy it out
|
|
||||||
|
|
||||||
rm -rf grub aphrodite.iso aphrodite-grub.iso
|
cargo build --target i686-unknown-none.json --release -Zbuild-std --bin entrypoint
|
||||||
|
# build the kernel's entrypoint
|
||||||
|
|
||||||
if [[ $CONFIG_BUILD_GRUB = "true" ]]; then
|
cp target/i686-unknown-none/release/entrypoint kernel.flat
|
||||||
cp -r ./grub_template ./grub
|
# copy it out
|
||||||
|
|
||||||
cp kernel.flat ./grub/boot/aphrodite.kernel
|
rm -rf grub aphrodite.iso aphrodite-grub.iso
|
||||||
|
|
||||||
sed -i "s@%{VERSION}@$VERSION@g" ./grub/boot/grub/grub.cfg
|
if [[ $CONFIG_BUILD_GRUB = "true" ]]; then
|
||||||
|
cp -r ./grub_template ./grub
|
||||||
|
|
||||||
grub-mkrescue -o aphrodite-grub.iso grub
|
cp kernel.flat ./grub/boot/aphrodite.kernel
|
||||||
cp aphrodite-grub.iso aphrodite.iso
|
|
||||||
fi
|
|
||||||
|
|
||||||
reset_version_vars
|
sed -i "s@%{VERSION}@$VERSION@g" ./grub/boot/grub/grub.cfg
|
||||||
|
|
||||||
|
grub-mkrescue -o aphrodite-grub.iso grub
|
||||||
|
cp aphrodite-grub.iso aphrodite.iso
|
||||||
|
fi
|
||||||
|
|
||||||
|
reset_version_vars
|
||||||
|
)
|
|
@ -3,9 +3,15 @@ fn main() {
|
||||||
|
|
||||||
// Begin checks
|
// Begin checks
|
||||||
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_DISABLE_MULTIBOOT2_SUPPORT, values("true", "false", none()))"#);
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_DISABLE_MULTIBOOT2_SUPPORT, values("true", "false", none()))"#);
|
||||||
|
|
||||||
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_HALT_ON_PANIC, values("true", "false", none()))"#);
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_HALT_ON_PANIC, values("true", "false", none()))"#);
|
||||||
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_SPIN_ON_PANIC, values("true", "false", none()))"#);
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_SPIN_ON_PANIC, values("true", "false", none()))"#);
|
||||||
|
|
||||||
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_EXIT_LOOP_ON_INVALID_LENGTH, values("true", "false", none()))"#);
|
||||||
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_PANIC_ON_INVALID_LENGTH, values("true", "false", none()))"#);
|
||||||
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_WARN_ON_INVALID_LENGTH, values("true", "false", none()))"#);
|
||||||
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_ERROR_ON_INVALID_LENGTH, values("true", "false", none()))"#);
|
||||||
|
|
||||||
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_OUTPUT_DEBUG, values("true", "false", none()))"#);
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_OUTPUT_DEBUG, values("true", "false", none()))"#);
|
||||||
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_OUTPUT_INFO, values("true", "false", none()))"#);
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_OUTPUT_INFO, values("true", "false", none()))"#);
|
||||||
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_OUTPUT_WARN, values("true", "false", none()))"#);
|
println!(r#"cargo:rustc-check-cfg=cfg(CONFIG_PREUSER_OUTPUT_WARN, values("true", "false", none()))"#);
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
./build
|
set -e
|
||||||
./emulate
|
|
||||||
|
DIR="${BASH_SOURCE%/*}"
|
||||||
|
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||||
|
|
||||||
|
. $DIR/build
|
||||||
|
. $DIR/emulate
|
|
@ -1,4 +1,6 @@
|
||||||
# config.aphro for aphrodite devel-83f6c5c-out-of-tree
|
# config.aphro for aphrodite devel-b3558c2-out-of-tree
|
||||||
|
CFG_VERSION=devel-b3558c2-out-of-tree
|
||||||
|
CONT_WITH_DIFFERENT_VERSION=false
|
||||||
|
|
||||||
# Begin metadata
|
# Begin metadata
|
||||||
|
|
||||||
|
@ -10,14 +12,23 @@ VERSION=generate
|
||||||
|
|
||||||
# Begin configs
|
# Begin configs
|
||||||
CONFIG_DISABLE_MULTIBOOT2_SUPPORT=false
|
CONFIG_DISABLE_MULTIBOOT2_SUPPORT=false
|
||||||
CONFIG_PREUSER_HALT_ON_PANIC=false
|
|
||||||
CONFIG_PREUSER_SPIN_ON_PANIC=true
|
|
||||||
|
|
||||||
|
# Panic behavior. When debugging, generally halt on panic is more useful.
|
||||||
|
CONFIG_PREUSER_HALT_ON_PANIC=true
|
||||||
|
CONFIG_PREUSER_SPIN_ON_PANIC=false
|
||||||
|
|
||||||
|
CONFIG_PREUSER_EXIT_LOOP_ON_INVALID_LENGTH=false
|
||||||
|
CONFIG_PREUSER_PANIC_ON_INVALID_LENGTH=true
|
||||||
|
CONFIG_PREUSER_WARN_ON_INVALID_LENGTH=true
|
||||||
|
CONFIG_PREUSER_ERROR_ON_INVALID_LENGTH=true
|
||||||
|
|
||||||
|
# Whether to output various levels of messages.
|
||||||
CONFIG_PREUSER_OUTPUT_DEBUG=true
|
CONFIG_PREUSER_OUTPUT_DEBUG=true
|
||||||
CONFIG_PREUSER_OUTPUT_INFO=true
|
CONFIG_PREUSER_OUTPUT_INFO=true
|
||||||
CONFIG_PREUSER_OUTPUT_WARN=true
|
CONFIG_PREUSER_OUTPUT_WARN=true
|
||||||
CONFIG_PREUSER_OUTPUT_ERROR=true
|
CONFIG_PREUSER_OUTPUT_ERROR=true
|
||||||
CONFIG_PREUSER_OUTPUT_FATAL=true
|
CONFIG_PREUSER_OUTPUT_FATAL=true
|
||||||
|
|
||||||
|
# Whether to build an iso with GRUB. Used in ./build.
|
||||||
CONFIG_BUILD_GRUB=true
|
CONFIG_BUILD_GRUB=true
|
||||||
# End configs
|
# End configs
|
|
@ -1,4 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
cd ../emulation
|
cd ../emulation
|
||||||
bochs -q
|
bochs -q
|
|
@ -1,8 +1,5 @@
|
||||||
function get_version() {
|
function get_version() {
|
||||||
local TEMP_SUFFIX
|
local TEMP_SUFFIX
|
||||||
if [[ $VERSION = "generate" ]]; then
|
|
||||||
unset VERSION
|
|
||||||
fi
|
|
||||||
if git diff-index HEAD -- 2>&1 > /dev/null
|
if git diff-index HEAD -- 2>&1 > /dev/null
|
||||||
then
|
then
|
||||||
TEMP_SUFFIX="-out-of-tree"
|
TEMP_SUFFIX="-out-of-tree"
|
||||||
|
@ -10,6 +7,9 @@ function get_version() {
|
||||||
SUFFIX="$SUFFIX$TEMP_SUFFIX"
|
SUFFIX="$SUFFIX$TEMP_SUFFIX"
|
||||||
|
|
||||||
VERSION="${VERSION:-devel-$(git rev-parse --short HEAD)$SUFFIX}"
|
VERSION="${VERSION:-devel-$(git rev-parse --short HEAD)$SUFFIX}"
|
||||||
|
if [[ "$VERSION" == "generate" ]]; then
|
||||||
|
VERSION="devel-$(git rev-parse --short HEAD)$SUFFIX"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset_version_vars() {
|
function reset_version_vars() {
|
||||||
|
|
Binary file not shown.
|
@ -1,8 +1,8 @@
|
||||||
set timeout=15
|
set timeout=15
|
||||||
set default=0
|
set default=0
|
||||||
|
|
||||||
menuentry "Aphrodite" --class aphrodite --class kernel --class os $menuentry_id_option 'aphrodite-basic-generate' {
|
menuentry "Aphrodite" --class aphrodite --class kernel --class os $menuentry_id_option 'aphrodite-basic-devel-b3558c2-out-of-tree' {
|
||||||
echo 'Loading Aphrodite aphrodite-generate ...'
|
echo 'Loading Aphrodite aphrodite-devel-b3558c2-out-of-tree ...'
|
||||||
multiboot2 /boot/aphrodite.kernel
|
multiboot2 /boot/aphrodite.kernel
|
||||||
boot
|
boot
|
||||||
}
|
}
|
Binary file not shown.
|
@ -39,6 +39,23 @@ pub fn u32_as_u8_slice(mut value: u32) -> [u8; 10] {
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts an u8 to an [u8; 3].
|
||||||
|
pub fn u8_as_u8_slice(mut value: u8) -> [u8; 3] {
|
||||||
|
let mut buf = [0u8; 3];
|
||||||
|
let mut i = 2;
|
||||||
|
if value == 0 {
|
||||||
|
buf[0] = b'0';
|
||||||
|
}
|
||||||
|
while value > 0 {
|
||||||
|
let digit = value%10;
|
||||||
|
let char = b'0' + digit as u8;
|
||||||
|
buf[i] = char;
|
||||||
|
value = value / 10;
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
|
buf
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts an usize(32 or 64 bit) to an [u8; 10].
|
/// Converts an usize(32 or 64 bit) to an [u8; 10].
|
||||||
pub fn usize_as_u8_slice(mut value: usize) -> [u8; 20] {
|
pub fn usize_as_u8_slice(mut value: usize) -> [u8; 20] {
|
||||||
let mut buf = [0u8; 20];
|
let mut buf = [0u8; 20];
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![allow(unexpected_cfgs)]
|
#![allow(unexpected_cfgs)]
|
||||||
|
#![allow(static_mut_refs)]
|
||||||
#![feature(ptr_metadata)]
|
#![feature(ptr_metadata)]
|
||||||
|
#![feature(cfg_match)]
|
||||||
|
|
||||||
use core::{arch::asm, ffi::CStr, panic::PanicInfo};
|
use core::{arch::asm, ffi::CStr, panic::PanicInfo};
|
||||||
use aphrodite::multiboot2::{BootInfo, CString, ColorInfo, FramebufferInfo, MemoryMap, PaletteColorDescriptor, RawMemoryMap, RootTag, Tag};
|
use aphrodite::multiboot2::{BootInfo, CString, ColorInfo, FramebufferInfo, MemoryMap, PaletteColorDescriptor, RawMemoryMap, RootTag, Tag};
|
||||||
|
@ -159,8 +161,8 @@ extern "C" fn _start() -> ! {
|
||||||
// ...before the BootInfo's bootloader_name is set.
|
// ...before the BootInfo's bootloader_name is set.
|
||||||
},
|
},
|
||||||
8 => { // Framebuffer info
|
8 => { // Framebuffer info
|
||||||
if current_tag.tag_len < 40 { // Unexpected size, something is probably up
|
if current_tag.tag_len < 31 { // Unexpected size, something is probably up
|
||||||
panic!("size of framebuffer info tag < 40");
|
panic!("size of framebuffer info tag < 31");
|
||||||
}
|
}
|
||||||
let framebufferinfo: *const FramebufferInfo = ptr as *const FramebufferInfo;
|
let framebufferinfo: *const FramebufferInfo = ptr as *const FramebufferInfo;
|
||||||
let colorinfo: ColorInfo;
|
let colorinfo: ColorInfo;
|
||||||
|
@ -192,14 +194,31 @@ extern "C" fn _start() -> ! {
|
||||||
BI.color_info = Some(colorinfo);
|
BI.color_info = Some(colorinfo);
|
||||||
},
|
},
|
||||||
_ => { // Unknown/unimplemented tag type, ignore
|
_ => { // Unknown/unimplemented tag type, ignore
|
||||||
sinfos("Unknown tag type ");
|
swarnings("Unknown tag type ");
|
||||||
sinfobnpln(&aphrodite::u32_as_u8_slice(current_tag.tag_type));
|
swarningbnpln(&aphrodite::u32_as_u8_slice(current_tag.tag_type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sinfounp(b'\n');
|
sinfounp(b'\n');
|
||||||
ptr = ptr + current_tag.tag_len as usize;
|
ptr = (ptr + current_tag.tag_len as usize + 7) & !7;
|
||||||
if ptr>end_addr {
|
if ptr>end_addr {
|
||||||
panic!("current tag length would put pointer out-of-bounds")
|
cfg_match! {
|
||||||
|
cfg(all(CONFIG_PREUSER_ERROR_ON_INVALID_LENGTH = "true", CONFIG_PREUSER_PANIC_ON_INVALID_LENGTH = "false")) => {
|
||||||
|
serrorsln("Current tag length would put pointer out-of-bounds; CONFIG_PREUSER_ERROR_ON_INVALID_LENGTH is set, continuing");
|
||||||
|
}
|
||||||
|
cfg(all(CONFIG_PREUSER_WARN_ON_INVALID_LENGTH = "true", CONFIG_PREUSER_PANIC_ON_INVALID_LENGTH = "false")) => {
|
||||||
|
swarningsln("Current tag length would put pointer out-of-bounds; CONFIG_PREUSER_WARN_ON_INVALID_LENGTH is set, continuing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg_match! {
|
||||||
|
cfg(not(CONFIG_PREUSER_PANIC_ON_INVALID_LENGTH = "false")) => {
|
||||||
|
panic!("current tag length would put pointer out-of-bounds")
|
||||||
|
}
|
||||||
|
cfg(CONFIG_PREUSER_EXIT_LOOP_ON_INVALID_LENGTH = "true") => {
|
||||||
|
sinfos("Exiting loop as current tag length would put pointer out-of-bounds ");
|
||||||
|
sinfosnpln("and CONFIG_PREUSER_EXIT_LOOP_ON_INVALID_LENGTH is set");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
current_tag = core::ptr::read_volatile(ptr as *const Tag);
|
current_tag = core::ptr::read_volatile(ptr as *const Tag);
|
||||||
}
|
}
|
||||||
|
@ -209,8 +228,29 @@ extern "C" fn _start() -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sdebugsln("Bootloader information has been successfully loaded");
|
||||||
|
soutputu(b'\n');
|
||||||
|
unsafe {
|
||||||
|
if BI.framebuffer_info.clone().is_some() {
|
||||||
|
let framebuffer_info = BI.framebuffer_info.clone().unwrap();
|
||||||
|
sdebugs("Framebuffer width: ");
|
||||||
|
sdebugbnpln(&aphrodite::u32_as_u8_slice(framebuffer_info.width));
|
||||||
|
sdebugs("Framebuffer height: ");
|
||||||
|
sdebugbnpln(&aphrodite::u32_as_u8_slice(framebuffer_info.height));
|
||||||
|
sdebugs("Framebuffer pitch: ");
|
||||||
|
sdebugbnpln(&aphrodite::u32_as_u8_slice(framebuffer_info.pitch));
|
||||||
|
sdebugs("Framebuffer address: ");
|
||||||
|
sdebugbnpln(&aphrodite::usize_as_u8_slice(framebuffer_info.address as usize));
|
||||||
|
sdebugs("Framebuffer bpp: ");
|
||||||
|
sdebugbnpln(&aphrodite::u8_as_u8_slice(framebuffer_info.bpp));
|
||||||
|
sdebugs("Framebuffer type: ");
|
||||||
|
sdebugbnpln(&aphrodite::u8_as_u8_slice(framebuffer_info.fb_type));
|
||||||
|
sdebugs("Framebuffer length: ");
|
||||||
|
sdebugbnpln(&aphrodite::usize_as_u8_slice(framebuffer_info.len));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
panic!("kernel exited");
|
panic!("kernel unexpectedly exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(link_section = ".panic")]
|
#[unsafe(link_section = ".panic")]
|
||||||
|
|
Loading…
Add table
Reference in a new issue