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

Mykernel Ada example

This commit is contained in:
bzt 2021-01-17 22:31:22 +01:00
parent d64cfbe3e8
commit dd1ff7978e
9 changed files with 542 additions and 6 deletions

View file

@ -14,7 +14,7 @@ Előre lefordított binárisok mellékelve, egyből használhatók.
3. *aarch64-rpi* ARMv8 betöltő Raspberry Pi 3-hoz, 4-hez 3. *aarch64-rpi* ARMv8 betöltő Raspberry Pi 3-hoz, 4-hez
[bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (34k) [bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (34k)
4. *mykernel* egy példa BOOTBOOT [kompatíbilis kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (forrás elérhető [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c)-ben, [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp)-ban, [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas)-ban, [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust)-ban és [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)-ban), ami vonalakat húz meg színes dobozokat rajzol 4. *mykernel* egy példa BOOTBOOT [kompatíbilis kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (forrás elérhető [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c)-ben, [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp)-ban, [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas)-ban, [Adá](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/ada)-ban, [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust)-ban és [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)-ban), ami vonalakat húz meg színes dobozokat rajzol
5. *mkbootimg* minden az egyben, multiplatform [bootolható lemezkép készítő](https://gitlab.com/bztsrc/bootboot/tree/binaries) (Windows, MacOSX, Linux). 5. *mkbootimg* minden az egyben, multiplatform [bootolható lemezkép készítő](https://gitlab.com/bztsrc/bootboot/tree/binaries) (Windows, MacOSX, Linux).

View file

@ -14,7 +14,7 @@ I provide pre-compiled images ready for use.
3. *aarch64-rpi* ARMv8 boot loader for Raspberry Pi 3, 4 3. *aarch64-rpi* ARMv8 boot loader for Raspberry Pi 3, 4
[bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (34k) [bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (34k)
4. *mykernel* an example BOOTBOOT [compatible kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (source available in [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c), [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp), [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas), [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust) and [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)) which draws lines and boxes 4. *mykernel* an example BOOTBOOT [compatible kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (source available in [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c), [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp), [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas), [Ada](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/ada), [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust) and [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)) which draws lines and boxes
5. *mkbootimg* an all-in-one multiplatform [bootable disk image creator](https://gitlab.com/bztsrc/bootboot/tree/binaries/) (Windows, MacOSX, Linux). 5. *mkbootimg* an all-in-one multiplatform [bootable disk image creator](https://gitlab.com/bztsrc/bootboot/tree/binaries/) (Windows, MacOSX, Linux).

View file

@ -12,6 +12,6 @@ után egy ilyen képernyőt kell látnod:
Fordítás Fordítás
-------- --------
Az adott nyelv mappájában csak futtasd a `make` parancsot. Kelleni fog a `gcc`, `fpc` (FreePascal Compiler), Az adott nyelv mappájában csak futtasd a `make` parancsot. Kelleni fog a `gcc`, `g++`, `gnat` (GNU Ada),
`cargo` + `rust`, és a `gccgo` (GNU go-lang fordító, NEM a hivatalos go-lang fordító!). `fpc` (FreePascal Compiler), `cargo` + `rust`, és a `gccgo` (GNU go-lang fordító, NEM a hivatalos go-lang fordító!).

View file

@ -12,5 +12,5 @@ should output a screen like this after a successful boot:
Compilation Compilation
----------- -----------
In the language's directory, just run `make`. You'll need `gcc`, `fpc` (FreePascal Compiler), In the language's directory, just run `make`. You'll need `gcc`, `g++`, `gnat` (GNU Ada), `fpc` (FreePascal
`cargo` + `rust`, and `gccgo` (GNU go-lang compiler, NOT the official go-lang compiler!). Compiler), `cargo` + `rust`, and `gccgo` (GNU go-lang compiler, NOT the official go-lang compiler!).

50
mykernel/ada/Makefile Normal file
View file

@ -0,0 +1,50 @@
#
# mykernel/ada/Makefile
#
# Copyright (C) 2017 - 2021 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 An example Makefile for sample kernel
#
#
ADAFLAGS = -Wall -fpic -fno-stack-protector -nostdinc -nostdlib
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.adb
x86_64-elf-gnat compile $(ADAFLAGS) -c kernel.adb -o kernel.o
x86_64-elf-ld $(LDFLAGS) 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: kernel.adb
aarch64-elf-gnat compile $(ADAFLAGS) -c kernel.adb -o kernel.o
aarch64-elf-ld $(LDFLAGS) kernel.o -o mykernel.aarch64.elf
aarch64-elf-strip $(STRIPFLAGS) mykernel.aarch64.elf
aarch64-elf-readelf -hls mykernel.aarch64.elf >mykernel.aarch64.txt
clean:
rm *.o *.elf *.ali *.txt || true

130
mykernel/ada/bootboot.ads Normal file
View file

@ -0,0 +1,130 @@
--
-- mykernel/ada/bootboot.ads
--
-- Copyright (C) 2017 - 2021 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
--
--
with System;
package bootboot is
type UInt8 is mod (2 ** 8);
type UInt16 is mod (2 ** 16);
type UInt32 is mod (2 ** 32);
type UInt64 is mod (2 ** 64);
type magic_type is array(0 .. 3) of UInt8;
type timezone_type is range -1440 .. +1440;
type datetime_type is array(0 .. 7) of UInt8;
type Screen is array(0 .. Integer'Last) of Uint32;
BOOTBOOT_MMIO : constant := 16#ffffffff_f8000000#; -- memory mapped IO virtual address
BOOTBOOT_FB : constant := 16#ffffffff_fc000000#; -- frame buffer virtual address
BOOTBOOT_INFO : constant := 16#ffffffff_ffe00000#; -- bootboot struct virtual address
BOOTBOOT_ENV : constant := 16#ffffffff_ffe01000#; -- environment string virtual address
BOOTBOOT_CORE : constant := 16#ffffffff_ffe02000#; -- core loadable segment start
-- minimum protocol level:
-- hardcoded kernel name, static kernel memory addresses
PROTOCOL_MINIMAL : constant := 0;
-- static protocol level:
-- kernel name parsed from environment, static kernel memory addresses
PROTOCOL_STATIC : constant := 1;
-- dynamic protocol level:
-- kernel name parsed, kernel memory addresses from ELF or PE symbols
PROTOCOL_DYNAMIC : constant := 2;
-- big-endian flag
PROTOCOL_BIGENDIAN : constant := 128;
-- loader types, just informational
LOADER_BIOS : constant := 0;
LOADER_UEFI : constant := 2;
LOADER_RPI : constant := 4;
LOADER_COREBOOT : constant := 8;
-- framebuffer pixel format, only 32 bits supported
FB_ARGB : constant := 0;
FB_RGBA : constant := 1;
FB_ABGR : constant := 2;
FB_BGRA : constant := 3;
MMAP_USED : constant := 0; -- don't use. Reserved or unknown regions
MMAP_FREE : constant := 1; -- usable memory
MMAP_ACPI : constant := 2; -- acpi memory, volatile and non-volatile as well
MMAP_MMIO : constant := 3; -- memory mapped IO region
INITRD_MAXSIZE : constant := 16; -- Mb
fb : Screen;
for fb'Address use System'To_Address(BOOTBOOT_FB);
pragma Volatile (fb);
type bootboot_struct is
record
-- first 64 bytes is platform independent
magic : magic_type; -- 'BOOT' magic
size : UInt32; -- length of bootboot structure, minimum 128
protocol : UInt8; -- 1, static addresses, see PROTOCOL_* and LOADER_* above
fb_type : UInt8; -- framebuffer type, see FB_* above
numcores : UInt16; -- number of processor cores
bspid : UInt16; -- Bootsrap processor ID (Local APIC Id on x86_64)
timezone : timezone_type; -- in minutes -1440..1440
datetime : datetime_type; -- in BCD yyyymmddhhiiss UTC (independent to timezone)
initrd_ptr : UInt64; -- ramdisk image position and size
initrd_size : UInt64;
fb_ptr : UInt64; -- framebuffer pointer and dimensions
fb_size : UInt32;
fb_width : UInt32;
fb_height : UInt32;
fb_scanline : UInt32;
-- the rest (64 bytes) is platform specific
x86_64_acpi_ptr : UInt64;
x86_64_smbi_ptr : UInt64;
x86_64_efi_ptr : UInt64;
x86_64_mp_ptr : UInt64;
x86_64_unused0 : UInt64;
x86_64_unused1 : UInt64;
x86_64_unused2 : UInt64;
x86_64_unused3 : UInt64;
end record;
bootboot : bootboot_struct;
for bootboot'Address use System'To_Address(BOOTBOOT_INFO);
pragma Volatile (bootboot);
-- mmap entry, type is stored in least significant tetrad (half byte) of size
-- this means size described in 16 byte units (not a problem, most modern
-- firmware report memory in pages, 4096 byte units anyway).
type MMapEnt_type is
record
ptr : UInt64;
size : UInt64;
end record;
MMap : MMapEnt_type;
for MMap'Address use System'To_Address(BOOTBOOT_INFO + 128);
pragma Volatile (MMap);
end bootboot;

116
mykernel/ada/kernel.adb Normal file

File diff suppressed because one or more lines are too long

56
mykernel/ada/link.ld Normal file
View file

@ -0,0 +1,56 @@
/*
* mykernel/ada/link.ld
*
* Copyright (C) 2017 - 2021 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 An example linker script for sample kernel
*
*/
ENTRY(_ada_kernel)
mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
fb = 0xfffffffffc000000;
PHDRS
{
boot PT_LOAD; /* one single loadable segment */
}
SECTIONS
{
. = 0xffffffffffe00000;
bootboot = .; . += 4096;
environment = .; . += 4096;
.text : {
KEEP(*(.text.boot)) *(.text .text.*) /* code */
*(.rodata .rodata.*) /* data */
*(.data .data.*)
} :boot
.bss (NOLOAD) : { /* bss */
. = ALIGN(16);
*(.bss .bss.*)
*(COMMON)
} :boot
/DISCARD/ : { *(.eh_frame) *(.comment) }
}

184
mykernel/ada/system.ads Normal file
View file

@ -0,0 +1,184 @@
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M --
-- --
-- S p e c --
-- (Compiler Version) --
-- --
-- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This version of System is a generic version that is used in building the
-- compiler. Right now, we have a host/target problem if we try to use the
-- "proper" System, and since the compiler itself does not care about most
-- System parameters, this generic version works fine.
pragma Restrictions (No_Implicit_Dynamic_Code);
-- We want to avoid trampolines in the compiler, so it can be used in systems
-- which prevent execution of code on the stack, e.g. in windows environments
-- with DEP (Data Execution Protection) enabled.
pragma Restrictions (No_Finalization);
-- Use restriction No_Finalization to avoid pulling finalization (not allowed
-- in GNAT) inside sem_spark.adb, when defining type Perm_Tree_Access as an
-- access type on incomplete type Perm_Tree_Wrapper (which is required for
-- defining a recursive type).
package System is
pragma Pure;
-- Note that we take advantage of the implementation permission to make
-- this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada
-- 2005, this is Pure in any case (AI-362).
pragma No_Elaboration_Code_All;
-- Allow the use of that restriction in units that WITH this unit
type Name is (SYSTEM_NAME_GNAT);
System_Name : constant Name := SYSTEM_NAME_GNAT;
-- System-Dependent Named Numbers
Min_Int : constant := Long_Long_Integer'First;
Max_Int : constant := Long_Long_Integer'Last;
Max_Binary_Modulus : constant := 2 ** Long_Long_Integer'Size;
Max_Nonbinary_Modulus : constant := 2 ** Integer'Size - 1;
Max_Base_Digits : constant := Long_Long_Float'Digits;
Max_Digits : constant := Long_Long_Float'Digits;
Max_Mantissa : constant := 63;
Fine_Delta : constant := 2.0 ** (-Max_Mantissa);
Tick : constant := 0.01;
-- Storage-related Declarations
type Address is private;
-- Note that we do NOT add pragma Preelaborable_Initialization in this
-- version of System, since it is used for the compiler only, and typical
-- earlier bootstrap compilers don't support this pragma. We don't need
-- it in this context, so there is no problem in omitting it.
Null_Address : constant Address;
Storage_Unit : constant := Standard'Storage_Unit;
Word_Size : constant := Standard'Word_Size;
Memory_Size : constant := 2 ** Standard'Address_Size;
-- Address comparison
function "<" (Left, Right : Address) return Boolean;
function "<=" (Left, Right : Address) return Boolean;
function ">" (Left, Right : Address) return Boolean;
function ">=" (Left, Right : Address) return Boolean;
function "=" (Left, Right : Address) return Boolean;
pragma Import (Intrinsic, "<");
pragma Import (Intrinsic, "<=");
pragma Import (Intrinsic, ">");
pragma Import (Intrinsic, ">=");
pragma Import (Intrinsic, "=");
-- Other System-Dependent Declarations
type Bit_Order is (High_Order_First, Low_Order_First);
Default_Bit_Order : constant Bit_Order :=
Bit_Order'Val (Standard'Default_Bit_Order);
pragma Warnings (Off, Default_Bit_Order); -- kill constant condition warning
-- Priority-related Declarations (RM D.1)
Max_Priority : constant Positive := 30;
Max_Interrupt_Priority : constant Positive := 31;
subtype Any_Priority is Integer range 0 .. 31;
subtype Priority is Any_Priority range 0 .. 30;
subtype Interrupt_Priority is Any_Priority range 31 .. 31;
Default_Priority : constant Priority := 15;
private
type Address is mod Memory_Size;
Null_Address : constant Address := 0;
--------------------------------------
-- System Implementation Parameters --
--------------------------------------
-- These parameters provide information about the target that is used by
-- the compiler. They are in the private part of System, where they can be
-- accessed using the special circuitry in the Targparm unit whose source
-- should be consulted for more detailed descriptions of the individual
-- switch values.
-- This version of system.ads is used only for building the compiler.
-- We really ought to use the proper target system (i.e. the one that
-- corresponds to the host for the compiler), but that causes as yet
-- unsolved makefile problems. For the most part the setting of these
-- parameters is not too critical for the compiler version (e.g. we
-- do not use floating-point anyway in the compiler).
AAMP : constant Boolean := False;
Backend_Divide_Checks : constant Boolean := False;
Backend_Overflow_Checks : constant Boolean := False;
Command_Line_Args : constant Boolean := True;
Configurable_Run_Time : constant Boolean := False;
Denorm : constant Boolean := True;
Duration_32_Bits : constant Boolean := False;
Exit_Status_Supported : constant Boolean := True;
Fractional_Fixed_Ops : constant Boolean := False;
Frontend_Layout : constant Boolean := False;
Machine_Overflows : constant Boolean := False;
Machine_Rounds : constant Boolean := True;
Preallocated_Stacks : constant Boolean := False;
Signed_Zeros : constant Boolean := True;
Stack_Check_Default : constant Boolean := False;
Stack_Check_Probes : constant Boolean := False;
Stack_Check_Limits : constant Boolean := False;
Support_Aggregates : constant Boolean := True;
Support_Composite_Assign : constant Boolean := True;
Support_Composite_Compare : constant Boolean := True;
Support_Long_Shifts : constant Boolean := True;
Always_Compatible_Rep : constant Boolean := True;
Suppress_Standard_Library : constant Boolean := False;
Use_Ada_Main_Program_Name : constant Boolean := False;
Frontend_Exceptions : constant Boolean := False;
ZCX_By_Default : constant Boolean := True;
-- Obsolete entries, to be removed eventually (bootstrap issues)
Front_End_ZCX_Support : constant Boolean := False;
High_Integrity_Mode : constant Boolean := False;
Long_Shifts_Inlined : constant Boolean := True;
Functions_Return_By_DSP : constant Boolean := False;
Support_64_Bit_Divides : constant Boolean := True;
GCC_ZCX_Support : constant Boolean := True;
end System;