1
0
Fork 0
mirror of https://gitlab.com/bztsrc/bootboot.git synced 2023-02-13 20:54:32 -05:00

Add basic support for elf

This commit is contained in:
Vinay Chandra Dommeti 2020-06-14 22:17:48 -07:00
parent 619c2f9135
commit 1364dac184
No known key found for this signature in database
GPG key ID: BC9DB2F436F05871
12 changed files with 911 additions and 2 deletions

3
.gitignore vendored
View file

@ -5,3 +5,6 @@ aarch64-rpi/LIC*
aarch64-rpi/*.bin
aarch64-rpi/*.dat
aarch64-rpi/*.elf
mykernel-rust/target
mykernel-rust/Cargo.lock

View file

@ -20,9 +20,9 @@ mkimg: mkimg.c
initrd.bin:
@mkdir initrd initrd/sys 2>/dev/null | true
ifeq ($(PLATFORM),x86)
cp ../mykernel/mykernel.x86_64.elf initrd/sys/core
cp ../mykernel-rust/mykernel.x86_64.elf initrd/sys/core
else
cp ../mykernel/mykernel.aarch64.elf initrd/sys/core
cp ../mykernel-rust/mykernel.aarch64.elf initrd/sys/core
endif
@cd initrd && (find . | cpio -H hpodc -o | gzip > ../initrd.bin) && cd ..
@rm -r initrd 2>/dev/null || true

9
mykernel-rust/Cargo.toml Executable file
View file

@ -0,0 +1,9 @@
[package]
name = "mykernel-rust"
version = "0.0.1"
authors = ["Author <email@example.com>"]
edition = "2018"
[dependencies]
rlibc = "1.0"

10
mykernel-rust/Makefile Normal file
View file

@ -0,0 +1,10 @@
all: mykernel.x86_64.elf
# Kernel build
mykernel.x86_64.elf: src/**
objcopy -O elf64-x86-64 -B i386 -I binary font.psf font.o
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

BIN
mykernel-rust/font.o Normal file

Binary file not shown.

BIN
mykernel-rust/font.psf Normal file

Binary file not shown.

BIN
mykernel-rust/mykernel.x86_64.elf Executable file

Binary file not shown.

1
mykernel-rust/rust-toolchain Executable file
View file

@ -0,0 +1 @@
nightly

View file

@ -0,0 +1,702 @@
/* automatically generated by rust-bindgen */
pub const BOOTBOOT_MAGIC: &'static [u8; 5usize] = b"BOOT\0";
pub const PROTOCOL_MINIMAL: u32 = 0;
pub const PROTOCOL_STATIC: u32 = 1;
pub const PROTOCOL_DYNAMIC: u32 = 2;
pub const PROTOCOL_BIGENDIAN: u32 = 128;
pub const LOADER_BIOS: u32 = 0;
pub const LOADER_UEFI: u32 = 4;
pub const LOADER_RPI: u32 = 8;
pub const FB_ARGB: u32 = 0;
pub const FB_RGBA: u32 = 1;
pub const FB_ABGR: u32 = 2;
pub const FB_BGRA: u32 = 3;
pub const MMAP_USED: u32 = 0;
pub const MMAP_FREE: u32 = 1;
pub const MMAP_ACPI: u32 = 2;
pub const MMAP_MMIO: u32 = 3;
pub const INITRD_MAXSIZE: u32 = 16;
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct MMapEnt {
pub ptr: u64,
pub size: u64,
}
#[test]
fn bindgen_test_layout_MMapEnt() {
assert_eq!(
::core::mem::size_of::<MMapEnt>(),
16usize,
concat!("Size of: ", stringify!(MMapEnt))
);
assert_eq!(
::core::mem::align_of::<MMapEnt>(),
1usize,
concat!("Alignment of ", stringify!(MMapEnt))
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<MMapEnt>())).ptr as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(MMapEnt),
"::",
stringify!(ptr)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<MMapEnt>())).size as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(MMapEnt),
"::",
stringify!(size)
)
);
}
#[repr(C, packed)]
#[derive(Copy, Clone)]
pub struct BOOTBOOT {
pub magic: [u8; 4usize],
pub size: u32,
pub protocol: u8,
pub fb_type: u8,
pub numcores: u16,
pub bspid: u16,
pub timezone: i16,
pub datetime: [u8; 8usize],
pub initrd_ptr: u64,
pub initrd_size: u64,
pub fb_ptr: *mut u8,
pub fb_size: u32,
pub fb_width: u32,
pub fb_height: u32,
pub fb_scanline: u32,
pub arch: BOOTBOOT__bindgen_ty_1,
pub mmap: MMapEnt,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union BOOTBOOT__bindgen_ty_1 {
pub x86_64: BOOTBOOT__bindgen_ty_1__bindgen_ty_1,
pub aarch64: BOOTBOOT__bindgen_ty_1__bindgen_ty_2,
_bindgen_union_align: [u64; 8usize],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct BOOTBOOT__bindgen_ty_1__bindgen_ty_1 {
pub acpi_ptr: u64,
pub smbi_ptr: u64,
pub efi_ptr: u64,
pub mp_ptr: u64,
pub unused0: u64,
pub unused1: u64,
pub unused2: u64,
pub unused3: u64,
}
#[test]
fn bindgen_test_layout_BOOTBOOT__bindgen_ty_1__bindgen_ty_1() {
assert_eq!(
::core::mem::size_of::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>(),
64usize,
concat!(
"Size of: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1)
)
);
assert_eq!(
::core::mem::align_of::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>(),
8usize,
concat!(
"Alignment of ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).acpi_ptr as *const _
as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(acpi_ptr)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).smbi_ptr as *const _
as usize
},
8usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(smbi_ptr)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).efi_ptr as *const _
as usize
},
16usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(efi_ptr)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).mp_ptr as *const _
as usize
},
24usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(mp_ptr)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).unused0 as *const _
as usize
},
32usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(unused0)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).unused1 as *const _
as usize
},
40usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(unused1)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).unused2 as *const _
as usize
},
48usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(unused2)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_1>())).unused3 as *const _
as usize
},
56usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_1),
"::",
stringify!(unused3)
)
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct BOOTBOOT__bindgen_ty_1__bindgen_ty_2 {
pub acpi_ptr: u64,
pub mmio_ptr: u64,
pub efi_ptr: u64,
pub unused0: u64,
pub unused1: u64,
pub unused2: u64,
pub unused3: u64,
pub unused4: u64,
}
#[test]
fn bindgen_test_layout_BOOTBOOT__bindgen_ty_1__bindgen_ty_2() {
assert_eq!(
::core::mem::size_of::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>(),
64usize,
concat!(
"Size of: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2)
)
);
assert_eq!(
::core::mem::align_of::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>(),
8usize,
concat!(
"Alignment of ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).acpi_ptr as *const _
as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(acpi_ptr)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).mmio_ptr as *const _
as usize
},
8usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(mmio_ptr)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).efi_ptr as *const _
as usize
},
16usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(efi_ptr)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).unused0 as *const _
as usize
},
24usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(unused0)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).unused1 as *const _
as usize
},
32usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(unused1)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).unused2 as *const _
as usize
},
40usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(unused2)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).unused3 as *const _
as usize
},
48usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(unused3)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1__bindgen_ty_2>())).unused4 as *const _
as usize
},
56usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1__bindgen_ty_2),
"::",
stringify!(unused4)
)
);
}
#[test]
fn bindgen_test_layout_BOOTBOOT__bindgen_ty_1() {
assert_eq!(
::core::mem::size_of::<BOOTBOOT__bindgen_ty_1>(),
64usize,
concat!("Size of: ", stringify!(BOOTBOOT__bindgen_ty_1))
);
assert_eq!(
::core::mem::align_of::<BOOTBOOT__bindgen_ty_1>(),
8usize,
concat!("Alignment of ", stringify!(BOOTBOOT__bindgen_ty_1))
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1>())).x86_64 as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1),
"::",
stringify!(x86_64)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT__bindgen_ty_1>())).aarch64 as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT__bindgen_ty_1),
"::",
stringify!(aarch64)
)
);
}
#[test]
fn bindgen_test_layout_BOOTBOOT() {
assert_eq!(
::core::mem::size_of::<BOOTBOOT>(),
144usize,
concat!("Size of: ", stringify!(BOOTBOOT))
);
assert_eq!(
::core::mem::align_of::<BOOTBOOT>(),
1usize,
concat!("Alignment of ", stringify!(BOOTBOOT))
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).magic as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(magic)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).size as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(size)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).protocol as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(protocol)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).fb_type as *const _ as usize },
9usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(fb_type)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).numcores as *const _ as usize },
10usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(numcores)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).bspid as *const _ as usize },
12usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(bspid)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).timezone as *const _ as usize },
14usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(timezone)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).datetime as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(datetime)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).initrd_ptr as *const _ as usize },
24usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(initrd_ptr)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).initrd_size as *const _ as usize },
32usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(initrd_size)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).fb_ptr as *const _ as usize },
40usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(fb_ptr)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).fb_size as *const _ as usize },
48usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(fb_size)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).fb_width as *const _ as usize },
52usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(fb_width)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).fb_height as *const _ as usize },
56usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(fb_height)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).fb_scanline as *const _ as usize },
60usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(fb_scanline)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).arch as *const _ as usize },
64usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(arch)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<BOOTBOOT>())).mmap as *const _ as usize },
128usize,
concat!(
"Offset of field: ",
stringify!(BOOTBOOT),
"::",
stringify!(mmap)
)
);
}
extern "C" {
pub static mut bootboot: BOOTBOOT;
}
extern "C" {
pub static mut environment: *mut custom_ctypes::c_uchar;
}
extern "C" {
pub static mut fb: u8;
}
#[doc = " Display text on screen *"]
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct psf2_t {
pub magic: u32,
pub version: u32,
pub headersize: u32,
pub flags: u32,
pub numglyph: u32,
pub bytesperglyph: u32,
pub height: u32,
pub width: u32,
pub glyphs: u8,
}
#[test]
fn bindgen_test_layout_psf2_t() {
assert_eq!(
::core::mem::size_of::<psf2_t>(),
33usize,
concat!("Size of: ", stringify!(psf2_t))
);
assert_eq!(
::core::mem::align_of::<psf2_t>(),
1usize,
concat!("Alignment of ", stringify!(psf2_t))
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).magic as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(magic)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).version as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(version)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).headersize as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(headersize)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).flags as *const _ as usize },
12usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(flags)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).numglyph as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(numglyph)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).bytesperglyph as *const _ as usize },
20usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(bytesperglyph)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).height as *const _ as usize },
24usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(height)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).width as *const _ as usize },
28usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(width)
)
);
assert_eq!(
unsafe { &(*(::core::ptr::null::<psf2_t>())).glyphs as *const _ as usize },
32usize,
concat!(
"Offset of field: ",
stringify!(psf2_t),
"::",
stringify!(glyphs)
)
);
}
extern "C" {
pub static mut _binary_font_psf_start: custom_ctypes::c_uchar;
}
pub mod custom_ctypes { pub type c_int = i64; pub type c_uchar = u64; }

115
mykernel-rust/src/main.rs Normal file
View file

@ -0,0 +1,115 @@
#![no_std]
#![no_main]
#[cfg(not(test))]
use core::panic::PanicInfo;
#[allow(dead_code)]
#[allow(non_snake_case)]
#[allow(non_camel_case_types)]
mod bootboot;
// Required for -Z build-std flag.
extern crate rlibc;
/// Entry point for the Operating System.
#[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; }
unsafe {
let fb = &bootboot::fb as *const u8 as u64;
// Cross hair
for y in 0..bootboot::bootboot.fb_height {
let addr = fb
+ bootboot::bootboot.fb_scanline as u64 * y as u64
+ bootboot::bootboot.fb_width as u64 * 2;
*(addr as *mut u64) = 0x00FFFFFF;
}
for x in 0..bootboot::bootboot.fb_width {
let addr = fb
+ bootboot::bootboot.fb_scanline as u64 * (bootboot::bootboot.fb_height / 2) as u64 + (x * 4) as u64;
*(addr as *mut u64) = 0x00FFFFFF;
}
// RGB boxes in order
for y in 0..20 {
for x in 0..20 {
let addr = fb
+ bootboot::bootboot.fb_scanline as u64 * (y + 20) as u64
+ (x + 20) * 4;
*(addr as *mut u64) = 0x00FF0000;
}
}
for y in 0..20 {
for x in 0..20 {
let addr = fb
+ bootboot::bootboot.fb_scanline as u64 * (y + 20) as u64
+ (x + 50) * 4;
*(addr as *mut u64) = 0x0000FF00;
}
}
for y in 0..20 {
for x in 0..20 {
let addr = fb
+ bootboot::bootboot.fb_scanline as u64 * (y + 20) as u64
+ (x + 80) * 4;
*(addr as *mut u64) = 0x000000FF;
}
}
}
puts("Hello from a simple BOOTBOOT kernel");
loop {}
}
/// This function is called on panic.
#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
fn puts(string: &'static str) {
use bootboot::*;
unsafe {
let font: *mut bootboot::psf2_t = &_binary_font_psf_start as *const u64 as *mut psf2_t;
let (mut kx, mut line, mut mask, mut offs): (u32, u64, u64, u32);
kx = 0;
let bpl = ((*font).width + 7) / 8;
for s in string.bytes() {
let glyph_a: *mut u8 = (font as u64 + (*font).headersize as u64) as *mut u8;
let mut glyph: *mut u8 = glyph_a.offset(
(if s > 0 && (s as u32) < (*font).numglyph {
s as u32
} else {
0
} * ((*font).bytesperglyph)) as isize,
);
offs = kx * ((*font).width + 1) * 4;
for _y in 0..(*font).height {
line = offs as u64;
mask = 1 << ((*font).width - 1);
for _x in 0..(*font).width {
let target_location = (&bootboot::fb as *const u8 as u64 + line) as *mut u32;
let mut target_value: u32 = 0;
if (*glyph as u64) & (mask) > 0 {
target_value = 0xFFFFFF;
}
*target_location = target_value;
mask >>= 1;
line += 4;
}
let target_location = (&bootboot::fb as *const u8 as u64 + line) as *mut u32;
*target_location = 0;
glyph = glyph.offset(bpl as isize);
offs += bootboot.fb_scanline;
}
kx += 1;
}
}
}

View file

@ -0,0 +1,28 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"dynamic-linking": false,
"relocation-model": "pic",
"code-model": "kernel",
"eliminate-frame-pointer": false,
"exe-suffix": "",
"has-rpath": false,
"no-compiler-rt": true,
"no-default-libraries": true,
"position-independent-executables": false,
"has-elf-tls": true,
"pre-link-args": {
"ld.lld": ["--script=./triplets/mykernel.ld", "./font.o"]
}
}

View file

@ -0,0 +1,41 @@
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) }
}