From dd1ff7978e6ff1f7a2d4264fc01e23584ff01b96 Mon Sep 17 00:00:00 2001 From: bzt Date: Sun, 17 Jan 2021 22:31:22 +0100 Subject: [PATCH] Mykernel Ada example --- OLVASSEL.md | 2 +- README.md | 2 +- mykernel/OLVASSEL.md | 4 +- mykernel/README.md | 4 +- mykernel/ada/Makefile | 50 +++++++++++ mykernel/ada/bootboot.ads | 130 +++++++++++++++++++++++++++ mykernel/ada/kernel.adb | 116 ++++++++++++++++++++++++ mykernel/ada/link.ld | 56 ++++++++++++ mykernel/ada/system.ads | 184 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 542 insertions(+), 6 deletions(-) create mode 100644 mykernel/ada/Makefile create mode 100644 mykernel/ada/bootboot.ads create mode 100644 mykernel/ada/kernel.adb create mode 100644 mykernel/ada/link.ld create mode 100644 mykernel/ada/system.ads diff --git a/OLVASSEL.md b/OLVASSEL.md index 3e743e2..b7366f5 100644 --- a/OLVASSEL.md +++ b/OLVASSEL.md @@ -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 [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). diff --git a/README.md b/README.md index 21c1041..91b9e8f 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ I provide pre-compiled images ready for use. 3. *aarch64-rpi* ARMv8 boot loader for Raspberry Pi 3, 4 [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). diff --git a/mykernel/OLVASSEL.md b/mykernel/OLVASSEL.md index 19ed6e9..1f1a260 100644 --- a/mykernel/OLVASSEL.md +++ b/mykernel/OLVASSEL.md @@ -12,6 +12,6 @@ után egy ilyen képernyőt kell látnod: Fordítás -------- -Az adott nyelv mappájában csak futtasd a `make` parancsot. Kelleni fog a `gcc`, `fpc` (FreePascal Compiler), -`cargo` + `rust`, és a `gccgo` (GNU go-lang fordító, NEM a hivatalos go-lang fordító!). +Az adott nyelv mappájában csak futtasd a `make` parancsot. Kelleni fog a `gcc`, `g++`, `gnat` (GNU Ada), +`fpc` (FreePascal Compiler), `cargo` + `rust`, és a `gccgo` (GNU go-lang fordító, NEM a hivatalos go-lang fordító!). diff --git a/mykernel/README.md b/mykernel/README.md index d505f01..14bec04 100644 --- a/mykernel/README.md +++ b/mykernel/README.md @@ -12,5 +12,5 @@ should output a screen like this after a successful boot: Compilation ----------- -In the language's directory, just run `make`. You'll need `gcc`, `fpc` (FreePascal Compiler), -`cargo` + `rust`, and `gccgo` (GNU go-lang compiler, NOT the official go-lang compiler!). +In the language's directory, just run `make`. You'll need `gcc`, `g++`, `gnat` (GNU Ada), `fpc` (FreePascal +Compiler), `cargo` + `rust`, and `gccgo` (GNU go-lang compiler, NOT the official go-lang compiler!). diff --git a/mykernel/ada/Makefile b/mykernel/ada/Makefile new file mode 100644 index 0000000..b438550 --- /dev/null +++ b/mykernel/ada/Makefile @@ -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 diff --git a/mykernel/ada/bootboot.ads b/mykernel/ada/bootboot.ads new file mode 100644 index 0000000..b10481a --- /dev/null +++ b/mykernel/ada/bootboot.ads @@ -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; diff --git a/mykernel/ada/kernel.adb b/mykernel/ada/kernel.adb new file mode 100644 index 0000000..7b1e36c --- /dev/null +++ b/mykernel/ada/kernel.adb @@ -0,0 +1,116 @@ +-- +-- mykernel/ada/kernel.adb +-- +-- 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 bootboot; + +procedure Kernel is + -- avoid exceptions for which we don't have run-time support (yet) + pragma Suppress (Range_Check); + pragma Suppress (Index_Check); + pragma Suppress (Overflow_Check); + +---------------------------- +-- Display text on screen -- +---------------------------- + procedure puts (Str : in String) is + -- sadly one does not simply reference an external variable in Ada + glyphs : constant array(Natural range <>) of bootboot.UInt8 := (0,0,218,2,128,130,2,128,130,2,128,182,0,0,0,0,0,0,126,129,165,129,129,189,153,129,129,126,0,0,0,0,0,0,126,255,219,255,255,195,231,255,255,126,0,0,0,0,0,0,0,0,108,254,254,254,254,124,56,16,0,0,0,0,0,0,0,0,16,56,124,254,124,56,16,0,0,0,0,0,0,0,0,24,60,60,231,231,231,24,24,60,0,0,0,0,0,0,0,24,60,126,255,255,126,24,24,60,0,0,0,0,0,0,0,0,0,0,24,60,60,24,0,0,0,0,0,0,255,255,255,255,255,255,231,195,195,231,255,255,255,255,255,255,0,0,0,0,0,60,102,66,66,102,60,0,0,0,0,0,255,255,255,255,255,195,153,189,189,153,195,255,255,255,255,255,0,0,30,14,26,50,120,204,204,204,204,120,0,0,0,0,0,0,60,102,102,102,102,60,24,126,24,24,0,0,0,0,0,0,63,51,63,48,48,48,48,112,240,224,0,0,0,0,0,0,127,99,127,99,99,99,99,103,231,230,192,0,0,0,0,0,0,24,24,219,60,231,60,219,24,24,0,0,0,0,0,128,192,224,240,248,254,248,240,224,192,128,0,0,0,0,0,2,6,14,30,62,254,62,30,14,6,2,0,0,0,0,0,0,24,60,126,24,24,24,126,60,24,0,0,0,0,0,0,0,102,102,102,102,102,102,102,0,102,102,0,0,0,0,0,0,127,219,219,219,123,27,27,27,27,27,0,0,0,0,0,124,198,96,56,108,198,198,108,56,12,198,124,0,0,0,0,0,0,0,0,0,0,0,254,254,254,254,0,0,0,0,0,0,24,60,126,24,24,24,126,60,24,126,0,0,0,0,0,0,24,60,126,24,24,24,24,24,24,24,0,0,0,0,0,0,24,24,24,24,24,24,24,126,60,24,0,0,0,0,0,0,0,0,0,24,12,254,12,24,0,0,0,0,0,0,0,0,0,0,0,48,96,254,96,48,0,0,0,0,0,0,0,0,0,0,0,0,192,192,192,254,0,0,0,0,0,0,0,0,0,0,0,40,108,254,108,40,0,0,0,0,0,0,0,0,0,0,16,56,56,124,124,254,254,0,0,0,0,0,0,0,0,0,254,254,124,124,56,56,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,60,60,60,24,24,24,0,24,24,0,0,0,0,0,102,102,102,36,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,254,108,108,108,254,108,108,0,0,0,0,24,24,124,198,194,192,124,6,6,134,198,124,24,24,0,0,0,0,0,0,194,198,12,24,48,96,198,134,0,0,0,0,0,0,56,108,108,56,118,220,204,204,204,118,0,0,0,0,0,48,48,48,32,0,0,0,0,0,0,0,0,0,0,0,0,0,12,24,48,48,48,48,48,48,24,12,0,0,0,0,0,0,48,24,12,12,12,12,12,12,24,48,0,0,0,0,0,0,0,0,0,102,60,255,60,102,0,0,0,0,0,0,0,0,0,0,0,24,24,126,24,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,24,24,48,0,0,0,0,0,0,0,0,0,0,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,24,0,0,0,0,0,0,0,0,2,6,12,24,48,96,192,128,0,0,0,0,0,0,56,108,198,198,214,214,198,198,108,56,0,0,0,0,0,0,24,56,120,24,24,24,24,24,24,126,0,0,0,0,0,0,124,198,6,12,24,48,96,192,198,254,0,0,0,0,0,0,124,198,6,6,60,6,6,6,198,124,0,0,0,0,0,0,12,28,60,108,204,254,12,12,12,30,0,0,0,0,0,0,254,192,192,192,252,6,6,6,198,124,0,0,0,0,0,0,56,96,192,192,252,198,198,198,198,124,0,0,0,0,0,0,254,198,6,6,12,24,48,48,48,48,0,0,0,0,0,0,124,198,198,198,124,198,198,198,198,124,0,0,0,0,0,0,124,198,198,198,126,6,6,6,12,120,0,0,0,0,0,0,0,0,24,24,0,0,0,24,24,0,0,0,0,0,0,0,0,0,24,24,0,0,0,24,24,48,0,0,0,0,0,0,0,6,12,24,48,96,48,24,12,6,0,0,0,0,0,0,0,0,0,126,0,0,126,0,0,0,0,0,0,0,0,0,0,96,48,24,12,6,12,24,48,96,0,0,0,0,0,0,124,198,198,12,24,24,24,0,24,24,0,0,0,0,0,0,0,124,198,198,222,222,222,220,192,124,0,0,0,0,0,0,16,56,108,198,198,254,198,198,198,198,0,0,0,0,0,0,252,102,102,102,124,102,102,102,102,252,0,0,0,0,0,0,60,102,194,192,192,192,192,194,102,60,0,0,0,0,0,0,248,108,102,102,102,102,102,102,108,248,0,0,0,0,0,0,254,102,98,104,120,104,96,98,102,254,0,0,0,0,0,0,254,102,98,104,120,104,96,96,96,240,0,0,0,0,0,0,60,102,194,192,192,222,198,198,102,58,0,0,0,0,0,0,198,198,198,198,254,198,198,198,198,198,0,0,0,0,0,0,60,24,24,24,24,24,24,24,24,60,0,0,0,0,0,0,30,12,12,12,12,12,204,204,204,120,0,0,0,0,0,0,230,102,102,108,120,120,108,102,102,230,0,0,0,0,0,0,240,96,96,96,96,96,96,98,102,254,0,0,0,0,0,0,198,238,254,254,214,198,198,198,198,198,0,0,0,0,0,0,198,230,246,254,222,206,198,198,198,198,0,0,0,0,0,0,124,198,198,198,198,198,198,198,198,124,0,0,0,0,0,0,252,102,102,102,124,96,96,96,96,240,0,0,0,0,0,0,124,198,198,198,198,198,198,214,222,124,12,14,0,0,0,0,252,102,102,102,124,108,102,102,102,230,0,0,0,0,0,0,124,198,198,96,56,12,6,198,198,124,0,0,0,0,0,0,126,126,90,24,24,24,24,24,24,60,0,0,0,0,0,0,198,198,198,198,198,198,198,198,198,124,0,0,0,0,0,0,198,198,198,198,198,198,198,108,56,16,0,0,0,0,0,0,198,198,198,198,214,214,214,254,238,108,0,0,0,0,0,0,198,198,108,124,56,56,124,108,198,198,0,0,0,0,0,0,102,102,102,102,60,24,24,24,24,60,0,0,0,0,0,0,254,198,134,12,24,48,96,194,198,254,0,0,0,0,0,0,60,48,48,48,48,48,48,48,48,60,0,0,0,0,0,0,0,128,192,224,112,56,28,14,6,2,0,0,0,0,0,0,60,12,12,12,12,12,12,12,12,60,0,0,0,0,16,56,108,198,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,48,48,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,120,12,124,204,204,204,118,0,0,0,0,0,0,224,96,96,120,108,102,102,102,102,124,0,0,0,0,0,0,0,0,0,124,198,192,192,192,198,124,0,0,0,0,0,0,28,12,12,60,108,204,204,204,204,118,0,0,0,0,0,0,0,0,0,124,198,254,192,192,198,124,0,0,0,0,0,0,56,108,100,96,240,96,96,96,96,240,0,0,0,0,0,0,0,0,0,118,204,204,204,204,204,124,12,204,120,0,0,0,224,96,96,108,118,102,102,102,102,230,0,0,0,0,0,0,24,24,0,56,24,24,24,24,24,60,0,0,0,0,0,0,6,6,0,14,6,6,6,6,6,6,102,102,60,0,0,0,224,96,96,102,108,120,120,108,102,230,0,0,0,0,0,0,56,24,24,24,24,24,24,24,24,60,0,0,0,0,0,0,0,0,0,236,254,214,214,214,214,198,0,0,0,0,0,0,0,0,0,220,102,102,102,102,102,102,0,0,0,0,0,0,0,0,0,124,198,198,198,198,198,124,0,0,0,0,0,0,0,0,0,220,102,102,102,102,102,124,96,96,240,0,0,0,0,0,0,118,204,204,204,204,204,124,12,12,30,0,0,0,0,0,0,220,118,102,96,96,96,240,0,0,0,0,0,0,0,0,0,124,198,96,56,12,198,124,0,0,0,0,0,0,16,48,48,252,48,48,48,48,54,28,0,0,0,0,0,0,0,0,0,204,204,204,204,204,204,118,0,0,0,0,0,0,0,0,0,102,102,102,102,102,60,24,0,0,0,0,0,0,0,0,0,198,198,214,214,214,254,108,0,0,0,0,0,0,0,0,0,198,108,56,56,56,108,198,0,0,0,0,0,0,0,0,0,198,198,198,198,198,198,126,6,12,248,0,0,0,0,0,0,254,204,24,48,96,198,254,0,0,0,0,0,0,14,24,24,24,112,24,24,24,24,14,0,0,0,0,0,0,24,24,24,24,24,24,24,24,24,24,24,24,0,0,0,0,112,24,24,24,14,24,24,24,24,112,0,0,0,0,0,0,118,220,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,56,108,198,198,198,254,0,0,0,0,0,0); + S : constant Integer := Integer(bootboot.bootboot.fb_scanline)/4; + Kx : Integer := 0; + Line : Integer; + Mask : Integer; + Offs : Integer; + C : Integer; + begin + for Index in Str'First .. Str'Last loop + Offs := Kx * 9; + for Y in Integer range 0 .. 15 loop + Line := Offs; + Mask := 128; + C := Integer(glyphs(Character'Pos(Str(Index))*16 + Y)); + for X in Integer range 0 .. 7 loop + if C >= Mask then + C := C - Mask; + bootboot.fb (Line) := bootboot.UInt32(16#00FFFFFF#); + else + bootboot.fb (Line) := bootboot.UInt32(0); + end if; + Line := Line + 1; + Mask := Mask / 2; + end loop; + bootboot.fb (Line) := bootboot.UInt32(0); + Offs := Offs + S; + end loop; + Kx := Kx + 1; + end loop; + end puts; + +-------------------------------------------- +-- Entry point, called by BOOTBOOT Loader -- +-------------------------------------------- + W : constant Integer := Integer(bootboot.bootboot.fb_width); + H : constant Integer := Integer(bootboot.bootboot.fb_height); + S : constant Integer := Integer(bootboot.bootboot.fb_scanline)/4; +begin + ----- NOTE: this code runs on all cores in parallel ----- + + -- cross-hair to see screen dimension detected correctly + for Y in Integer range 0 .. (H-1) loop + bootboot.fb (S*Y + W/2) := bootboot.UInt32(16#00FFFFFF#); + end loop; + for X in Integer range 0 .. (W-1) loop + bootboot.fb (S*H/2 + X) := bootboot.UInt32(16#00FFFFFF#); + end loop; + + -- red, green, blue boxes in order + for Y in Integer range 0 .. 20 loop + for X in Integer range 0 .. 20 loop + bootboot.fb (S*(Y+20) + (X+20)) := bootboot.UInt32(16#00FF0000#); + end loop; + end loop; + for Y in Integer range 0 .. 20 loop + for X in Integer range 0 .. 20 loop + bootboot.fb (S*(Y+20) + (X+50)) := bootboot.UInt32(16#0000FF00#); + end loop; + end loop; + for Y in Integer range 0 .. 20 loop + for X in Integer range 0 .. 20 loop + bootboot.fb (S*(Y+20) + (X+80)) := bootboot.UInt32(16#000000FF#); + end loop; + end loop; + + -- say hello + puts("Hello from a simple BOOTBOOT kernel"); + + -- hang for now + loop + null; + end loop; +end Kernel; diff --git a/mykernel/ada/link.ld b/mykernel/ada/link.ld new file mode 100644 index 0000000..901a12d --- /dev/null +++ b/mykernel/ada/link.ld @@ -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) } +} diff --git a/mykernel/ada/system.ads b/mykernel/ada/system.ads new file mode 100644 index 0000000..fdfcbff --- /dev/null +++ b/mykernel/ada/system.ads @@ -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 -- +-- . -- +-- -- +-- 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;