mirror of
https://gitlab.com/bztsrc/bootboot.git
synced 2023-02-13 20:54:32 -05:00
107 lines
3.8 KiB
C
107 lines
3.8 KiB
C
/*
|
|
* mykernel/kernel.c
|
|
*
|
|
* Copyright (C) 2017 bzt (bztsrc@gitlab)
|
|
*
|
|
* 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
|
|
*
|
|
*/
|
|
|
|
/* function to display a string, see below */
|
|
void puts(char *s);
|
|
|
|
/* we don't assume stdint.h exists */
|
|
typedef short int int16_t;
|
|
typedef unsigned char uint8_t;
|
|
typedef unsigned short int uint16_t;
|
|
typedef unsigned int uint32_t;
|
|
typedef unsigned long int uint64_t;
|
|
|
|
#include <bootboot.h>
|
|
|
|
/* imported virtual addresses, see linker script */
|
|
extern BOOTBOOT bootboot; // see bootboot.h
|
|
extern unsigned char *environment; // configuration, UTF-8 text key=value pairs
|
|
extern uint8_t fb; // linear framebuffer mapped
|
|
|
|
/******************************************
|
|
* Entry point, called by BOOTBOOT Loader *
|
|
******************************************/
|
|
void _start()
|
|
{
|
|
/*** NOTE: this code runs on all cores in parallel ***/
|
|
int x, y, s=bootboot.fb_scanline, w=bootboot.fb_width, h=bootboot.fb_height;
|
|
|
|
// cross-hair to see screen dimension detected correctly
|
|
for(y=0;y<h;y++) { *((uint32_t*)(&fb + s*y + (w*2)))=0x00FFFFFF; }
|
|
for(x=0;x<w;x++) { *((uint32_t*)(&fb + s*(h/2)+x*4))=0x00FFFFFF; }
|
|
|
|
// red, green, blue boxes in order
|
|
for(y=0;y<20;y++) { for(x=0;x<20;x++) { *((uint32_t*)(&fb + s*(y+20) + (x+20)*4))=0x00FF0000; } }
|
|
for(y=0;y<20;y++) { for(x=0;x<20;x++) { *((uint32_t*)(&fb + s*(y+20) + (x+50)*4))=0x0000FF00; } }
|
|
for(y=0;y<20;y++) { for(x=0;x<20;x++) { *((uint32_t*)(&fb + s*(y+20) + (x+80)*4))=0x000000FF; } }
|
|
|
|
// say hello
|
|
puts("Hello from a simple BOOTBOOT kernel");
|
|
|
|
// hang for now
|
|
while(1);
|
|
}
|
|
|
|
/**************************
|
|
* Display text on screen *
|
|
**************************/
|
|
typedef struct {
|
|
uint32_t magic;
|
|
uint32_t version;
|
|
uint32_t headersize;
|
|
uint32_t flags;
|
|
uint32_t numglyph;
|
|
uint32_t bytesperglyph;
|
|
uint32_t height;
|
|
uint32_t width;
|
|
uint8_t glyphs;
|
|
} __attribute__((packed)) psf2_t;
|
|
extern volatile unsigned char _binary_font_psf_start;
|
|
|
|
void puts(char *s)
|
|
{
|
|
psf2_t *font = (psf2_t*)&_binary_font_psf_start;
|
|
int x,y,kx=0,line,mask,offs;
|
|
int bpl=(font->width+7)/8;
|
|
while(*s) {
|
|
unsigned char *glyph = (unsigned char*)&_binary_font_psf_start + font->headersize +
|
|
(*s>0&&*s<font->numglyph?*s:0)*font->bytesperglyph;
|
|
offs = (kx * (font->width+1) * 4);
|
|
for(y=0;y<font->height;y++) {
|
|
line=offs; mask=1<<(font->width-1);
|
|
for(x=0;x<font->width;x++) {
|
|
*((uint32_t*)((uint64_t)&fb+line))=((int)*glyph) & (mask)?0xFFFFFF:0;
|
|
mask>>=1; line+=4;
|
|
}
|
|
*((uint32_t*)((uint64_t)&fb+line))=0; glyph+=bpl; offs+=bootboot.fb_scanline;
|
|
}
|
|
s++; kx++;
|
|
}
|
|
}
|