1
0
Fork 0
mirror of https://gitlab.com/bztsrc/bootboot.git synced 2023-02-13 20:54:32 -05:00
This commit is contained in:
bzt 2021-01-17 18:20:46 +01:00
parent 0c9f8e0dbd
commit b977f1c067
9 changed files with 172 additions and 69 deletions

View file

@ -29,21 +29,23 @@
#
CFLAGS = -Wall -fpic -ffreestanding -fno-stack-protector -nostdinc -nostdlib -I../../dist/
LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment
all: mykernel.x86_64.elf mykernel.aarch64.elf
mykernel.x86_64.elf: kernel.c
x86_64-elf-gcc $(CFLAGS) -mno-red-zone -c kernel.c -o kernel.o
x86_64-elf-ld -r -b binary -o font.o font.psf
x86_64-elf-ld -nostdlib -nostartfiles -T link.ld kernel.o font.o -o mykernel.x86_64.elf
x86_64-elf-strip -s -K mmio -K fb -K bootboot -K environment mykernel.x86_64.elf
x86_64-elf-ld $(LDFLAGS) kernel.o font.o -o mykernel.x86_64.elf
x86_64-elf-strip $(STRIPFLAGS) mykernel.x86_64.elf
x86_64-elf-readelf -hls mykernel.x86_64.elf >mykernel.x86_64.txt
mykernel.aarch64.elf: kernel.c
aarch64-elf-gcc $(CFLAGS) -c kernel.c -o kernel.o
aarch64-elf-ld -r -b binary -o font.o font.psf
aarch64-elf-ld -nostdlib -nostartfiles -T link.ld kernel.o font.o -o mykernel.aarch64.elf
aarch64-elf-strip -s -K mmio -K fb -K bootboot -K environment mykernel.aarch64.elf
aarch64-elf-ld $(LDFLAGS) kernel.o font.o -o mykernel.aarch64.elf
aarch64-elf-strip $(STRIPFLAGS) mykernel.aarch64.elf
aarch64-elf-readelf -hls mykernel.aarch64.elf >mykernel.aarch64.txt
clean:

View file

@ -29,21 +29,23 @@
#
GOFLAGS = -Wall -fpic -fno-stack-protector -static -nostdinc -nostdlib -nostartfiles -nodefaultlibs
LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment
all: mykernel.x86_64.elf mykernel.aarch64.elf
mykernel.x86_64.elf: go_rt0.s kernel.go
x86_64-elf-gccgo $(GOFLAGS) -c kernel.go -o kernel.o
x86_64-elf-as -c go_rt0.s -o go_rt0.o
x86_64-elf-ld -nostdlib -nostartfiles -T link.ld go_rt0.o kernel.o -o mykernel.x86_64.elf
x86_64-elf-strip -s -K mmio -K fb -K bootboot -K environment mykernel.x86_64.elf
x86_64-elf-ld $(LDFLAGS) go_rt0.o kernel.o -o mykernel.x86_64.elf
x86_64-elf-strip $(STRIPFLAGS) mykernel.x86_64.elf
x86_64-elf-readelf -hls mykernel.x86_64.elf >mykernel.x86_64.txt
mykernel.aarch64.elf: go_rt0.s kernel.go
aarch64-elf-gccgo $(GOFLAGS) -c kernel.go -o kernel.o
aarch64-elf-as -c go_rt0.s -o go_rt0.o
aarch64-elf-ld -nostdlib -nostartfiles -T link.ld go_rt0.o kernel.o -o mykernel.aarch64.elf
aarch64-elf-strip -s -K mmio -K fb -K bootboot -K environment mykernel.aarch64.elf
aarch64-elf-ld $(LDFLAGS) go_rt0.o kernel.o -o mykernel.aarch64.elf
aarch64-elf-strip $(STRIPFLAGS) mykernel.aarch64.elf
aarch64-elf-readelf -hls mykernel.aarch64.elf >mykernel.aarch64.txt
clean:

View file

@ -29,21 +29,23 @@
#
PASFLAGS = -Aelf -n -O3 -Xd -CX -XXs -Tlinux
LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment
all: mykernel.x86_64.elf mykernel.aarch64.elf
mykernel.x86_64.elf: kernel.pas
fpc -Px86_64 $(PASFLAGS) kernel.pas
x86_64-elf-ld -r -b binary -o font.o font.psf
x86_64-elf-ld -nostdlib -nostartfiles -T link.ld kernel.o font.o -o mykernel.x86_64.elf
x86_64-elf-strip -s -K mmio -K fb -K bootboot -K environment mykernel.x86_64.elf
x86_64-elf-ld $(LDFLAGS) kernel.o font.o -o mykernel.x86_64.elf
x86_64-elf-strip $(STRIPFLAGS) mykernel.x86_64.elf
x86_64-elf-readelf -hls mykernel.x86_64.elf >mykernel.x86_64.txt
mykernel.aarch64.elf: kernel.pas
fpc -Paarch64 $(PASFLAGS) kernel.pas
aarch64-elf-ld -r -b binary -o font.o font.psf
aarch64-elf-ld -nostdlib -nostartfiles -T link.ld kernel.o font.o -o mykernel.aarch64.elf
aarch64-elf-strip -s -K mmio -K fb -K bootboot -K environment mykernel.aarch64.elf
aarch64-elf-ld $(LDFLAGS) kernel.o font.o -o mykernel.aarch64.elf
aarch64-elf-strip $(STRIPFLAGS) mykernel.aarch64.elf
aarch64-elf-readelf -hls mykernel.aarch64.elf >mykernel.aarch64.txt
clean:

View file

@ -1,7 +1,7 @@
[package]
name = "mykernel-rust"
version = "0.0.1"
authors = ["Author <email@example.com>"]
authors = ["Vinay Chandra"]
edition = "2018"
[dependencies]

View file

@ -1,3 +1,32 @@
#
# mykernel/rust/Makefile
#
# Copyright (C) 2017 - 2021 Vinay Chandra
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# This file is part of the BOOTBOOT Protocol package.
# @brief An example Makefile for sample kernel
#
#
all: mykernel.x86_64.elf
@ -7,4 +36,4 @@ mykernel.x86_64.elf: src/**
cargo xbuild --target ./triplets/mykernel-x86.json
# Using this causes the kernel to exceed the 2 MB limit
# cargo build -Z build-std=core,alloc --target ./triplets/$mykernel-x86.json
cp ./target/mykernel-x86/debug/mykernel-rust mykernel.x86_64.elf
cp ./target/mykernel-x86/debug/mykernel-rust mykernel.x86_64.elf

71
mykernel/rust/link.ld Normal file
View file

@ -0,0 +1,71 @@
/*
* mykernel/rust/link.ld
*
* Copyright (C) 2017 - 2021 Vinay Chandra
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* This file is part of the BOOTBOOT Protocol package.
* @brief An example linker script for sample kernel
*
*/
KERNEL_OFFSET = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
PHDRS
{
boot PT_LOAD FILEHDR PHDRS; /* one single loadable segment */
}
SECTIONS
{
. = KERNEL_OFFSET;
mmio = .; . += 0x4000000;
fb = .; . += 0x3E00000;
bootboot = .; . += 4096;
environment = .; . += 4096;
.text . + SIZEOF_HEADERS : AT(ADDR(.text) - KERNEL_OFFSET + SIZEOF_HEADERS) {
__text_start = .;
KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) /* code */
. = ALIGN(4096);
__text_end = .;
} :boot
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET) {
__rodata_start = .;
*(.rodata*)
. = ALIGN(4096);
__rodata_end = .;
} :boot
.data : AT(ADDR(.data) - KERNEL_OFFSET) {
__data_start = .;
*(.data*)
. = ALIGN(4096);
__data_end = .;
__bss_start = .;
*(.bss*)
. = ALIGN(4096);
__bss_end = .;
} :boot
/DISCARD/ : { *(.eh_frame) *(.comment) }
}

View file

@ -1,3 +1,34 @@
/*
* mykernel/rust/src/main.rs
*
* Copyright (C) 2017 - 2021 Vinay Chandra
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* This file is part of the BOOTBOOT Protocol package.
* @brief A sample BOOTBOOT compatible kernel
*
*/
// configure Rust compiler
#![no_std]
#![no_main]
@ -12,16 +43,16 @@ mod bootboot;
// Required for -Z build-std flag.
extern crate rlibc;
/// Entry point for the Operating System.
/******************************************
* Entry point, called by BOOTBOOT Loader *
******************************************/
#[no_mangle] // don't mangle the name of this function
fn _start() -> ! {
// int x, y, s=bootboot.fb_scanline, w=bootboot.fb_width, h=bootboot.fb_height;
// for(y=0;y<h;y++) { *((uint32_t*)(&fb + s*y + (w*2)))=0x00FFFFFF; }
/*** NOTE: this code runs on all cores in parallel ***/
unsafe {
let fb = &bootboot::fb as *const u8 as u64;
// Cross hair
// cross-hair to see screen dimension detected correctly
for y in 0..bootboot::bootboot.fb_height {
let addr = fb
+ bootboot::bootboot.fb_scanline as u64 * y as u64
@ -34,7 +65,7 @@ fn _start() -> ! {
*(addr as *mut u64) = 0x00FFFFFF;
}
// RGB boxes in order
// red, green, blue boxes in order
for y in 0..20 {
for x in 0..20 {
let addr = fb
@ -61,18 +92,16 @@ fn _start() -> ! {
}
}
// say hello
puts("Hello from a simple BOOTBOOT kernel");
// hang for now
loop {}
}
/// This function is called on panic.
#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
/**************************
* Display text on screen *
**************************/
fn puts(string: &'static str) {
use bootboot::*;
unsafe {
@ -113,3 +142,12 @@ fn puts(string: &'static str) {
}
}
}
/*************************************
* This function is called on panic. *
*************************************/
#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}

View file

@ -23,6 +23,6 @@
"position-independent-executables": false,
"has-elf-tls": true,
"pre-link-args": {
"ld.lld": ["--script=./triplets/mykernel.ld", "./font.o"]
"ld.lld": ["--script=./link.ld", "./font.o"]
}
}

View file

@ -1,41 +0,0 @@
KERNEL_OFFSET = 0xfffffffff8000000;
PHDRS
{
boot PT_LOAD FILEHDR PHDRS; /* one single loadable segment */
}
SECTIONS
{
. = KERNEL_OFFSET;
mmio = .; . += 0x4000000;
fb = .; . += 0x3E00000;
bootboot = .; . += 4096;
environment = .; . += 4096;
.text . + SIZEOF_HEADERS : AT(ADDR(.text) - KERNEL_OFFSET + SIZEOF_HEADERS) {
__text_start = .;
KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) /* code */
. = ALIGN(4096);
__text_end = .;
} :boot
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET) {
__rodata_start = .;
*(.rodata*)
. = ALIGN(4096);
__rodata_end = .;
} :boot
.data : AT(ADDR(.data) - KERNEL_OFFSET) {
__data_start = .;
*(.data*)
. = ALIGN(4096);
__data_end = .;
__bss_start = .;
*(.bss*)
. = ALIGN(4096);
__bss_end = .;
} :boot
/DISCARD/ : { *(.eh_frame) *(.comment) }
}