├── .gitignore ├── README.md ├── debug ├── run └── src ├── README.md ├── bsp ├── README.md └── src │ └── arch │ └── x86 │ ├── x86-ata.adb │ ├── x86-ata.ads │ ├── x86-descriptors.ads │ ├── x86-gdt.ads │ ├── x86-idt.ads │ ├── x86-interrupts-names.ads │ ├── x86-interrupts.ads │ ├── x86-memory-paging.adb │ ├── x86-memory-paging.ads │ ├── x86-memory.ads │ ├── x86-pci.ads │ ├── x86-pic.adb │ ├── x86-pic.ads │ ├── x86-pit.adb │ ├── x86-pit.ads │ ├── x86-port_io.adb │ ├── x86-port_io.ads │ ├── x86-serial.ads │ ├── x86-tss.ads │ ├── x86-vga.ads │ └── x86.ads ├── iso ├── .gitignore ├── boot │ └── grub │ │ └── grub.cfg └── makefile ├── kernel ├── .gitignore ├── README.md ├── kernel.adc ├── kernel.gpr ├── makefile └── src │ └── arch │ ├── common │ ├── cxos-debug.ads │ ├── cxos-devices-graphics.ads │ ├── cxos-devices-storage.ads │ ├── cxos-devices.ads │ ├── cxos-error_handling.ads │ ├── cxos-filesystems.ads │ ├── cxos-vfs.adb │ ├── cxos-vfs.ads │ ├── cxos.adb │ ├── cxos.ads │ ├── elf.adb │ ├── elf.ads │ └── multiboot.ads │ └── x86 │ ├── cxos-boot-entry.S │ ├── cxos-boot-multiboot.S │ ├── cxos-boot-multiboot_init.adb │ ├── cxos-boot-multiboot_init.ads │ ├── cxos-boot-paging.S │ ├── cxos-boot-protected_mode_init.S │ ├── cxos-boot.adb │ ├── cxos-boot.ads │ ├── cxos-debug.adb │ ├── cxos-devices-graphics-vga.adb │ ├── cxos-devices-graphics-vga.ads │ ├── cxos-devices-pci-print.adb │ ├── cxos-devices-pci-print.ads │ ├── cxos-devices-pci.adb │ ├── cxos-devices-pci.ads │ ├── cxos-devices-serial.adb │ ├── cxos-devices-serial.ads │ ├── cxos-devices-storage-ata.adb │ ├── cxos-devices-storage-ata.ads │ ├── cxos-devices-storage-atapi.ads │ ├── cxos-devices.adb │ ├── cxos-error_handling.adb │ ├── cxos-exceptions-entry.S │ ├── cxos-exceptions-testing.ads │ ├── cxos-exceptions-testing_func.S │ ├── cxos-exceptions.adb │ ├── cxos-exceptions.ads │ ├── cxos-filesystems-fat-print.adb │ ├── cxos-filesystems-fat-print.ads │ ├── cxos-filesystems-fat.adb │ ├── cxos-filesystems-fat.ads │ ├── cxos-gdt-load.S │ ├── cxos-gdt.adb │ ├── cxos-gdt.ads │ ├── cxos-idt-load.S │ ├── cxos-idt.adb │ ├── cxos-idt.ads │ ├── cxos-interrupts.adb │ ├── cxos-interrupts.ads │ ├── cxos-irq_handlers-entry.S │ ├── cxos-irq_handlers.adb │ ├── cxos-irq_handlers.ads │ ├── cxos-memory-get_stack_top.S │ ├── cxos-memory-map.adb │ ├── cxos-memory-map.ads │ ├── cxos-memory-paging-flush_tlb.S │ ├── cxos-memory-paging.adb │ ├── cxos-memory-paging.ads │ ├── cxos-memory.adb │ ├── cxos-memory.ads │ ├── cxos-pic.adb │ ├── cxos-pic.ads │ ├── cxos-pit.adb │ ├── cxos-pit.ads │ ├── cxos-tasking-switch.S │ ├── cxos-tasking.adb │ ├── cxos-tasking.ads │ ├── cxos-time_keeping.adb │ ├── cxos-time_keeping.ads │ └── x86.ld ├── makefile ├── runtime ├── .gitignore ├── README.md ├── makefile ├── runtime.adc ├── runtime.gpr └── src │ └── arch │ ├── common │ ├── a-charac.ads │ ├── a-chlat1.ads │ ├── a-cwila1.ads │ ├── a-unccon.ads │ ├── ada.ads │ ├── interfac.ads │ ├── memory.adb │ ├── memory.ads │ ├── s-atacco.ads │ ├── s-exnint.adb │ ├── s-exnint.ads │ ├── s-expuns.adb │ ├── s-expuns.ads │ ├── s-imgint.adb │ ├── s-imgint.ads │ ├── s-imguns.adb │ ├── s-imguns.ads │ ├── s-maccod.ads │ ├── s-pack12.adb │ ├── s-pack12.ads │ ├── s-stoele.adb │ ├── s-stoele.ads │ └── s-unstyp.ads │ └── x86 │ ├── a-interr.ads │ ├── s-parame.ads │ ├── s-secsta.adb │ ├── s-secsta.ads │ └── system.ads └── util ├── README.build_cross_gnat.md ├── README.md ├── _shared.sh ├── bochsrc ├── build_cross_gnat ├── debugrc └── test_disk ├── .gitignore ├── makefile └── test_disk_files ├── file_with_long_file_name.ext └── short.file /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | dev 3 | *.log 4 | *.out 5 | *.swp 6 | *.swo 7 | *.fat 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CXOS 2 | 3 | ## Background 4 | CXOS is a personal research project operating-system implemented in Ada. The current aims of the project are to learn the fundamentals of operating system development and research the benefits provided by the Ada programming language for engineering safety-critical bare-metal software. 5 | 6 | The operating system currently exclusively targets the x86 platform. An ARM/MIPS implementation is being considered for the long-term. 7 | 8 | ## Current status 9 | CXOS currently contains only an extremely minimal implementation, offering no interactivity. Currently CXOS has a working higher-half kernel, physical memory manager and several peripheral drivers. Currently development is focused on reaching a working tasking implementation and userland. 10 | 11 | ## Project goals 12 | The long-term goals of the project as of time-of-writing are to implement a minimal non-graphical user-interface and basic user applications. After this has been achieved, planning will begin on a more robust and planned implementation more focused on security and efficiency. Future porting to RISC architectures is being considered. 13 | 14 | ## Name 15 | The name `cxos` was chosen at random, based upon the precedent set by my previous operating-system development research projects. All of which were given a working title of `_xos`, where `_` is a random letter. The original research project was called`jxos`, named by a stylised amalgamation of `ajxs` and `os`. Once CXOS reaches a point of development where more specific, purposeful architectual design choices become relevant and development of userland applications begins a more fitting, long-term name will be selected. 16 | 17 | ## Development 18 | CXOS requires an Ada2012 compiler targeting the `i686-elf` platform. A recipe for compiling a GCC cross-compiler from `x86-64-linux-elf` to `i686-elf` from source can be found within the `src/util/build_cross_gnat` script. Contributions are not presently being solicited from the community, however any advice would definitely be appreciated. 19 | 20 | While I would welcome any help on the project, work has not yet reached a point where development is following a structured plan or can be easily subdivided amongst multiple developers. I would however absolutely welcome anyone submitting pull requests to resolve any issues they encounter. 21 | 22 | -------------------------------------------------------------------------------- /debug: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Launches GDB with a prescribed set of commands to load the OS debug symbols. 4 | 5 | gdb -command=./src/util/debugrc 6 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Cleans and builds the OS image. 4 | make clean -C "src"; make -C "src" && make emu -C "src" 5 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # CXOS 2 | 3 | ## ISO 4 | Contains the configuration files necessary for creating an ISO image from the built OS that can either be written to removable media or loaded directly by `qemu`. The `make debug` target will automatically load the generated ISO. The OS uses GRUB as a bootloader, the config files for which can be found in this directory. 5 | 6 | ## Kernel 7 | The main kernel source code. The source files here are built together with the OS' custom Ada runtime to produce the final OS executable. Refer to the `README` file in this directory for more information. 8 | 9 | ## Runtime 10 | Contains the OS customised Ada runtime targeting a bare-metal x86 system. The functionality for bootstrapping the system is contained inside this directory. Refer to the `README` file in this directory for more information. 11 | -------------------------------------------------------------------------------- /src/bsp/README.md: -------------------------------------------------------------------------------- 1 | # CXOS Board Support Packages 2 | 3 | Contains support code related to interfacing with specific hardware platforms. 4 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-descriptors.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with System; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- X86.DESCRIPTORS 17 | -- 18 | -- Purpose: 19 | -- This package contains definitions common to the use of descriptors in the 20 | -- x86 system. These are used in the Global Descriptor Table (GDT) and the 21 | -- Interrupt Descriptor Table (IDT). 22 | -- Refer to 'system-x86-gdt.ads' and 'system-x86-idt.ads' respectively. 23 | ------------------------------------------------------------------------------- 24 | package x86.Descriptors is 25 | pragma Preelaborate; 26 | 27 | ---------------------------------------------------------------------------- 28 | -- The privilege level for a particular descriptor. 29 | -- These correspond to the 'protection ring' that this descriptor is 30 | -- accessible from. 31 | ---------------------------------------------------------------------------- 32 | type Descriptor_Privilege_Level is ( 33 | Ring_0, 34 | Ring_1, 35 | Ring_2, 36 | Ring_3 37 | ) 38 | with Size => 2; 39 | for Descriptor_Privilege_Level use ( 40 | Ring_0 => 0, 41 | Ring_1 => 1, 42 | Ring_2 => 2, 43 | Ring_3 => 3 44 | ); 45 | 46 | ---------------------------------------------------------------------------- 47 | -- Range type for Descriptor tables. 48 | ---------------------------------------------------------------------------- 49 | subtype Descriptor_Entry_Range is Natural; 50 | 51 | ---------------------------------------------------------------------------- 52 | -- The format of the System Table Descriptor pointer used by the processor 53 | -- to load descriptor tables like the GDT and IDT. 54 | ---------------------------------------------------------------------------- 55 | type System_Table_Descriptor is 56 | record 57 | Size : Unsigned_16; 58 | Offset : System.Address; 59 | end record 60 | with Size => 48; 61 | for System_Table_Descriptor use 62 | record 63 | Size at 0 range 0 .. 15; 64 | Offset at 0 range 16 .. 47; 65 | end record; 66 | end x86.Descriptors; 67 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-gdt.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with x86.Descriptors; use x86.Descriptors; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- X86.GDT 17 | -- 18 | -- Purpose: 19 | -- This package contains definitions forthe Global Descriptor Table. 20 | ------------------------------------------------------------------------------- 21 | package x86.GDT is 22 | pragma Preelaborate; 23 | 24 | ---------------------------------------------------------------------------- 25 | -- The type of this memory segment. 26 | ---------------------------------------------------------------------------- 27 | type Segment_Type is ( 28 | Code, 29 | Data, 30 | None, 31 | Task_Type 32 | ); 33 | 34 | ---------------------------------------------------------------------------- 35 | -- Descriptor type information. 36 | -- Refer to Page 100. Intel IA-32 SDM 3a. 37 | ---------------------------------------------------------------------------- 38 | type Descriptor_Type_T is 39 | record 40 | A : Boolean; 41 | W_R : Boolean; 42 | E_C : Boolean; 43 | Field_Type : Boolean; 44 | end record 45 | with Size => 4; 46 | for Descriptor_Type_T use 47 | record 48 | A at 0 range 0 .. 0; 49 | W_R at 0 range 1 .. 1; 50 | E_C at 0 range 2 .. 2; 51 | Field_Type at 0 range 3 .. 3; 52 | end record; 53 | 54 | ---------------------------------------------------------------------------- 55 | -- An individual segment descriptor within the GDT. 56 | -- Refer to Page 98. Intel IA-32 SDM 3a. 57 | ---------------------------------------------------------------------------- 58 | type GDT_Descriptor is 59 | record 60 | Limit_Low : Unsigned_16; 61 | Base_Low : Unsigned_16; 62 | Base_Mid : Unsigned_8; 63 | Descriptor_Type : Descriptor_Type_T; 64 | S : Boolean; 65 | DPL : Descriptor_Privilege_Level; 66 | P : Boolean; 67 | Limit_High : Unsigned_4; 68 | AVL : Boolean; 69 | L : Boolean; 70 | DB : Boolean; 71 | G : Boolean; 72 | Base_High : Unsigned_8; 73 | end record 74 | with Size => 64; 75 | for GDT_Descriptor use 76 | record 77 | Limit_Low at 0 range 0 .. 15; 78 | Base_Low at 0 range 16 .. 31; 79 | Base_Mid at 4 range 0 .. 7; 80 | Descriptor_Type at 4 range 8 .. 11; 81 | S at 4 range 12 .. 12; 82 | DPL at 4 range 13 .. 14; 83 | P at 4 range 15 .. 15; 84 | Limit_High at 4 range 16 .. 19; 85 | AVL at 4 range 20 .. 20; 86 | L at 4 range 21 .. 21; 87 | DB at 4 range 22 .. 22; 88 | G at 4 range 23 .. 23; 89 | Base_High at 4 range 24 .. 31; 90 | end record; 91 | 92 | ---------------------------------------------------------------------------- 93 | -- GDT table type. 94 | ---------------------------------------------------------------------------- 95 | type Global_Descriptor_Table_T is 96 | array (Descriptor_Entry_Range range <>) of GDT_Descriptor; 97 | 98 | end x86.GDT; 99 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-idt.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with x86.Descriptors; use x86.Descriptors; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- X86.IDT 17 | -- 18 | -- Purpose: 19 | -- This package contains definitions for the Interrupt Descriptor 20 | -- Table. 21 | ------------------------------------------------------------------------------- 22 | package x86.IDT is 23 | pragma Preelaborate; 24 | 25 | ---------------------------------------------------------------------------- 26 | -- Descriptor type information. 27 | -- Differs from GDT descriptor type field. 28 | -- Refer to Page 197. Intel IA-32 SDM 3a. 29 | ---------------------------------------------------------------------------- 30 | type Descriptor_Type_T is ( 31 | None, 32 | Interrupt_Gate_16_Bit, 33 | Interrupt_Gate_32_Bit 34 | ) 35 | with Size => 4; 36 | for Descriptor_Type_T use ( 37 | None => 0, 38 | Interrupt_Gate_16_Bit => 16#6#, 39 | Interrupt_Gate_32_Bit => 16#E# 40 | ); 41 | 42 | ---------------------------------------------------------------------------- 43 | -- An individual segment descriptor within the IDT. 44 | -- Refer to Page 197. Intel IA-32 SDM 3a. 45 | ---------------------------------------------------------------------------- 46 | type IDT_Descriptor is 47 | record 48 | Offset_Low : Unsigned_16; 49 | Selector : Unsigned_16; 50 | Reserved : Unsigned_8; 51 | Descriptor_Type : Descriptor_Type_T; 52 | S : Boolean; 53 | DPL : Descriptor_Privilege_Level; 54 | P : Boolean; 55 | Offset_High : Unsigned_16; 56 | end record 57 | with Size => 64; 58 | for IDT_Descriptor use 59 | record 60 | Offset_Low at 0 range 0 .. 15; 61 | Selector at 0 range 16 .. 31; 62 | Reserved at 4 range 0 .. 7; 63 | Descriptor_Type at 4 range 8 .. 11; 64 | S at 4 range 12 .. 12; 65 | DPL at 4 range 13 .. 14; 66 | P at 4 range 15 .. 15; 67 | Offset_High at 4 range 16 .. 31; 68 | end record; 69 | 70 | ---------------------------------------------------------------------------- 71 | -- IDT table type. 72 | ---------------------------------------------------------------------------- 73 | type Interrupt_Descriptor_Table_T is 74 | array (Descriptor_Entry_Range range <>) of IDT_Descriptor; 75 | end x86.IDT; 76 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-interrupts-names.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Interrupts; use Ada.Interrupts; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- Ada.Interrupts.Names 16 | -- 17 | -- Purpose: 18 | -- Contains the names for system interrupts. 19 | ------------------------------------------------------------------------------- 20 | package x86.Interrupts.Names is 21 | pragma Preelaborate; 22 | 23 | IRQ0 : constant Interrupt_ID := 0; 24 | IRQ1 : constant Interrupt_ID := 1; 25 | IRQ2 : constant Interrupt_ID := 2; 26 | IRQ3 : constant Interrupt_ID := 3; 27 | IRQ4 : constant Interrupt_ID := 4; 28 | IRQ5 : constant Interrupt_ID := 5; 29 | IRQ6 : constant Interrupt_ID := 6; 30 | IRQ7 : constant Interrupt_ID := 7; 31 | IRQ8 : constant Interrupt_ID := 8; 32 | IRQ9 : constant Interrupt_ID := 9; 33 | IRQ10 : constant Interrupt_ID := 10; 34 | IRQ11 : constant Interrupt_ID := 11; 35 | IRQ12 : constant Interrupt_ID := 12; 36 | IRQ13 : constant Interrupt_ID := 13; 37 | IRQ14 : constant Interrupt_ID := 14; 38 | IRQ15 : constant Interrupt_ID := 15; 39 | end x86.Interrupts.Names; 40 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-interrupts.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- X86.INTERRUPTS 14 | -- 15 | -- Purpose: 16 | -- This package contains code for managing x86 processor interrupts. 17 | ------------------------------------------------------------------------------- 18 | package x86.Interrupts is 19 | pragma Preelaborate; 20 | end x86.Interrupts; 21 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-memory.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- X86.MEMORY 14 | -- 15 | -- Purpose: 16 | -- This package contains code and defintions for implementing and working 17 | -- with memory on the x86 platform. 18 | ------------------------------------------------------------------------------- 19 | package x86.Memory is 20 | pragma Preelaborate (x86.Memory); 21 | end x86.Memory; 22 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-pic.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System.Storage_Elements; use System.Storage_Elements; 13 | 14 | package body x86.PIC is 15 | ---------------------------------------------------------------------------- 16 | -- Get_Port_Address 17 | ---------------------------------------------------------------------------- 18 | function Get_Controller_Base_Address ( 19 | Controller : PIC_Controller_T 20 | ) return System.Address is 21 | begin 22 | case Controller is 23 | when PIC1 => 24 | return To_Address (16#20#); 25 | when PIC2 => 26 | return To_Address (16#A0#); 27 | end case; 28 | exception 29 | when Constraint_Error => 30 | return System.Null_Address; 31 | end Get_Controller_Base_Address; 32 | 33 | end x86.PIC; 34 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-pic.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- X86.PIC 16 | -- 17 | -- Purpose: 18 | -- This package contains code for working with the x86 8259A programmable 19 | -- interrupt controller. 20 | ------------------------------------------------------------------------------- 21 | package x86.PIC is 22 | pragma Preelaborate; 23 | 24 | ---------------------------------------------------------------------------- 25 | -- PIC Controller type. 26 | -- Used in selecting which PIC to perform an operation on. 27 | ---------------------------------------------------------------------------- 28 | type PIC_Controller_T is ( 29 | PIC1, 30 | PIC2 31 | ); 32 | 33 | ---------------------------------------------------------------------------- 34 | -- Get_Controller_Base_Address 35 | -- 36 | -- Purpose: 37 | -- This function gets the base address for a particular PIC controller. 38 | ---------------------------------------------------------------------------- 39 | function Get_Controller_Base_Address ( 40 | Controller : PIC_Controller_T 41 | ) return System.Address; 42 | 43 | end x86.PIC; 44 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-pit.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System; 13 | with System.Storage_Elements; use System.Storage_Elements; 14 | 15 | package body x86.PIT is 16 | ---------------------------------------------------------------------------- 17 | -- Get_Register_Address 18 | -- 19 | -- Implementation Notes: 20 | -- - Returns a constant value stored within the function. 21 | ---------------------------------------------------------------------------- 22 | function Get_Register_Address ( 23 | Register : PIT_Register_T 24 | ) return System.Address is 25 | Channel_0_Address : constant System.Address := To_Address (16#40#); 26 | Channel_1_Address : constant System.Address := To_Address (16#41#); 27 | Channel_2_Address : constant System.Address := To_Address (16#42#); 28 | Command_Address : constant System.Address := To_Address (16#43#); 29 | begin 30 | case Register is 31 | when Channel_0_Data => 32 | return Channel_0_Address; 33 | when Channel_1_Data => 34 | return Channel_1_Address; 35 | when Channel_2_Data => 36 | return Channel_2_Address; 37 | when Command => 38 | return Command_Address; 39 | end case; 40 | exception 41 | when Constraint_Error => 42 | return System.Null_Address; 43 | end Get_Register_Address; 44 | 45 | end x86.PIT; 46 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-port_io.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System.Machine_Code; 13 | 14 | package body x86.Port_IO is 15 | ---------------------------------------------------------------------------- 16 | -- Inb 17 | ---------------------------------------------------------------------------- 18 | function Inb ( 19 | Port : System.Address 20 | ) return Interfaces.Unsigned_8 is 21 | Data : Interfaces.Unsigned_8; 22 | begin 23 | System.Machine_Code.Asm ( 24 | Template => "inb %w1, %0", 25 | Inputs => ( 26 | System.Address'Asm_Input ("Nd", Port) 27 | ), 28 | Outputs => ( 29 | Interfaces.Unsigned_8'Asm_Output ("=a", Data) 30 | ), 31 | Volatile => True); 32 | 33 | return Data; 34 | end Inb; 35 | 36 | ---------------------------------------------------------------------------- 37 | -- Inl 38 | ---------------------------------------------------------------------------- 39 | function Inl ( 40 | Port : System.Address 41 | ) return Interfaces.Unsigned_32 is 42 | Data : Interfaces.Unsigned_32; 43 | begin 44 | System.Machine_Code.Asm ( 45 | Template => "inl %w1, %0", 46 | Inputs => ( 47 | System.Address'Asm_Input ("Nd", Port) 48 | ), 49 | Outputs => ( 50 | Interfaces.Unsigned_32'Asm_Output ("=a", Data) 51 | ), 52 | Volatile => True); 53 | 54 | return Data; 55 | end Inl; 56 | 57 | ---------------------------------------------------------------------------- 58 | -- Inw 59 | ---------------------------------------------------------------------------- 60 | function Inw ( 61 | Port : System.Address 62 | ) return Interfaces.Unsigned_16 is 63 | Data : Interfaces.Unsigned_16; 64 | begin 65 | System.Machine_Code.Asm ( 66 | Template => "inw %w1, %0", 67 | Inputs => ( 68 | System.Address'Asm_Input ("Nd", Port) 69 | ), 70 | Outputs => ( 71 | Interfaces.Unsigned_16'Asm_Output ("=a", Data) 72 | ), 73 | Volatile => True); 74 | 75 | return Data; 76 | end Inw; 77 | 78 | ---------------------------------------------------------------------------- 79 | -- Outb 80 | ---------------------------------------------------------------------------- 81 | procedure Outb ( 82 | Port : System.Address; 83 | Data : Interfaces.Unsigned_8 84 | ) is 85 | begin 86 | System.Machine_Code.Asm ( 87 | Template => "outb %0, %w1", 88 | Inputs => ( 89 | Interfaces.Unsigned_8'Asm_Input ("a", Data), 90 | System.Address'Asm_Input ("Nd", Port) 91 | ), 92 | Volatile => True); 93 | end Outb; 94 | 95 | ---------------------------------------------------------------------------- 96 | -- Outl 97 | ---------------------------------------------------------------------------- 98 | procedure Outl ( 99 | Port : System.Address; 100 | Data : Interfaces.Unsigned_32 101 | ) is 102 | begin 103 | System.Machine_Code.Asm ( 104 | Template => "outl %0, %w1", 105 | Inputs => ( 106 | Interfaces.Unsigned_32'Asm_Input ("a", Data), 107 | System.Address'Asm_Input ("Nd", Port) 108 | ), 109 | Volatile => True); 110 | end Outl; 111 | 112 | ---------------------------------------------------------------------------- 113 | -- Outw 114 | ---------------------------------------------------------------------------- 115 | procedure Outw ( 116 | Port : System.Address; 117 | Data : Interfaces.Unsigned_16 118 | ) is 119 | begin 120 | System.Machine_Code.Asm ( 121 | Template => "outw %0, %w1", 122 | Inputs => ( 123 | Interfaces.Unsigned_16'Asm_Input ("a", Data), 124 | System.Address'Asm_Input ("Nd", Port) 125 | ), 126 | Volatile => True); 127 | end Outw; 128 | end x86.Port_IO; 129 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-port_io.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with System; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- X86.PORT_IO 17 | -- 18 | -- Purpose: 19 | -- This package contains functionality for port-mapped I/O on the x86 20 | -- platform. 21 | -- Functions are included for inputting and outputting data to port-mapped 22 | -- addresses, useful for interacting with system peripherals. 23 | ------------------------------------------------------------------------------- 24 | package x86.Port_IO is 25 | pragma Preelaborate; 26 | 27 | ---------------------------------------------------------------------------- 28 | -- Inb 29 | -- 30 | -- Purpose: 31 | -- This function reads a byte from a particular IO port. 32 | -- Exceptions: 33 | -- None. 34 | ---------------------------------------------------------------------------- 35 | function Inb ( 36 | Port : System.Address 37 | ) return Unsigned_8 38 | with Volatile_Function; 39 | 40 | ---------------------------------------------------------------------------- 41 | -- Outb 42 | -- 43 | -- Purpose: 44 | -- This function writes a byte to a particular IO port. 45 | -- Exceptions: 46 | -- None. 47 | ---------------------------------------------------------------------------- 48 | procedure Outb ( 49 | Port : System.Address; 50 | Data : Unsigned_8 51 | ); 52 | 53 | ---------------------------------------------------------------------------- 54 | -- Inw 55 | -- 56 | -- Purpose: 57 | -- This function reads a word from a particular IO port. 58 | -- Exceptions: 59 | -- None. 60 | ---------------------------------------------------------------------------- 61 | function Inw ( 62 | Port : System.Address 63 | ) return Unsigned_16 64 | with Volatile_Function; 65 | 66 | ---------------------------------------------------------------------------- 67 | -- Outw 68 | -- 69 | -- Purpose: 70 | -- This function writes a word to a particular IO port. 71 | -- Exceptions: 72 | -- None. 73 | ---------------------------------------------------------------------------- 74 | procedure Outw ( 75 | Port : System.Address; 76 | Data : Unsigned_16 77 | ); 78 | 79 | ---------------------------------------------------------------------------- 80 | -- Inl 81 | -- 82 | -- Purpose: 83 | -- This function reads a DWord from a particular IO port. 84 | -- Exceptions: 85 | -- None. 86 | ---------------------------------------------------------------------------- 87 | function Inl ( 88 | Port : System.Address 89 | ) return Unsigned_32 90 | with Volatile_Function; 91 | 92 | ---------------------------------------------------------------------------- 93 | -- Outl 94 | -- 95 | -- Purpose: 96 | -- This function writes a DWord to a particular IO port. 97 | -- Exceptions: 98 | -- None. 99 | ---------------------------------------------------------------------------- 100 | procedure Outl ( 101 | Port : System.Address; 102 | Data : Unsigned_32 103 | ); 104 | end x86.Port_IO; 105 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-serial.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Unchecked_Conversion; 13 | with Interfaces; use Interfaces; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- X86.SERIAL 17 | -- 18 | -- Purpose: 19 | -- This package contains the type definitons for a basic Serial I/O driver. 20 | -- The procedures and type definitions contained within this module can be 21 | -- used to interact with the system's serial ports. 22 | ------------------------------------------------------------------------------- 23 | package x86.Serial is 24 | pragma Preelaborate; 25 | 26 | ---------------------------------------------------------------------------- 27 | -- The maximum supported baud rate. 28 | ---------------------------------------------------------------------------- 29 | MAXIMUM_BAUD_RATE : constant := 115200; 30 | 31 | ---------------------------------------------------------------------------- 32 | -- Serial Baud Rate 33 | ---------------------------------------------------------------------------- 34 | subtype Baud_Rate is Natural range 50 .. MAXIMUM_BAUD_RATE; 35 | 36 | ---------------------------------------------------------------------------- 37 | -- Serial Port Type 38 | -- Defines the serial ports that can be used in the system. 39 | ---------------------------------------------------------------------------- 40 | type Serial_Port is ( 41 | COM1, 42 | COM2, 43 | COM3, 44 | COM4 45 | ); 46 | 47 | ---------------------------------------------------------------------------- 48 | -- Serial Interrupt Type 49 | -- Defines the types of interrupts the serial port can generate. 50 | ---------------------------------------------------------------------------- 51 | type Serial_Interrupt_Type is ( 52 | Modem_Line_Status, 53 | Rx_Data_Available, 54 | Rx_Line_Status, 55 | Tx_Empty 56 | ); 57 | 58 | ---------------------------------------------------------------------------- 59 | -- Port Interrupt status/enable register type. 60 | -- This type can be used for getting/setting the interrupt generation 61 | -- status of a particular interrupt type. 62 | -- For more information refer to page 17 of the PC16550D datasheet. 63 | ---------------------------------------------------------------------------- 64 | type Port_Interrupt_Status is 65 | record 66 | ERBFI : Boolean; 67 | ETBEI : Boolean; 68 | ELSI : Boolean; 69 | EDSSI : Boolean; 70 | end record 71 | with Size => 8, 72 | Convention => C, 73 | Volatile; 74 | for Port_Interrupt_Status use 75 | record 76 | ERBFI at 0 range 0 .. 0; 77 | ETBEI at 0 range 1 .. 1; 78 | ELSI at 0 range 2 .. 2; 79 | EDSSI at 0 range 3 .. 3; 80 | end record; 81 | 82 | ---------------------------------------------------------------------------- 83 | -- Serial Port register type. 84 | ---------------------------------------------------------------------------- 85 | type Serial_Port_Register_Type is ( 86 | Rx_Buffer_Tx_Holding, 87 | Interrupt_Enable, 88 | Interrupt_Ident_FIFO_Control, 89 | Line_Control, 90 | Modem_Control, 91 | Line_Status, 92 | Modem_Status, 93 | Scratch 94 | ); 95 | 96 | ---------------------------------------------------------------------------- 97 | -- Byte_To_Port_Interrupt_Status 98 | -- 99 | -- Purpose: 100 | -- Unchecked conversion to read a port's interrupt status from 101 | -- an IO port. 102 | -- Exceptions: 103 | -- None. 104 | ---------------------------------------------------------------------------- 105 | function Byte_To_Port_Interrupt_Status is 106 | new Ada.Unchecked_Conversion ( 107 | Source => Unsigned_8, 108 | Target => Port_Interrupt_Status 109 | ); 110 | 111 | ---------------------------------------------------------------------------- 112 | -- Port_Interrupt_Status_To_Byte 113 | -- 114 | -- Purpose: 115 | -- Unchecked conversion to write a port's interrupt status to 116 | -- an IO port. 117 | -- Exceptions: 118 | -- None. 119 | ---------------------------------------------------------------------------- 120 | function Port_Interrupt_Status_To_Byte is 121 | new Ada.Unchecked_Conversion ( 122 | Source => Port_Interrupt_Status, 123 | Target => Unsigned_8 124 | ); 125 | 126 | end x86.Serial; 127 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-tss.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- SYSTEM.X86.TSS 16 | -- 17 | -- Purpose: 18 | -- This package contains definitions for the x86 Task State Segment. 19 | ------------------------------------------------------------------------------- 20 | package x86.TSS is 21 | pragma Preelaborate; 22 | 23 | ---------------------------------------------------------------------------- 24 | -- Task State Segment Type. 25 | -- Refer to Page 242. Intel IA-32 SDM 3a. 26 | ---------------------------------------------------------------------------- 27 | type Task_State_Segment is 28 | record 29 | LINK : Unsigned_16; 30 | Reserved : Unsigned_16 := 0; 31 | ESP0 : Unsigned_32; 32 | SS0 : Unsigned_16; 33 | Reserved_1 : Unsigned_16 := 0; 34 | ESP1 : Unsigned_32; 35 | SS1 : Unsigned_16; 36 | Reserved_2 : Unsigned_16 := 0; 37 | ESP2 : Unsigned_32; 38 | SS2 : Unsigned_16; 39 | Reserved_3 : Unsigned_16 := 0; 40 | CR3 : Unsigned_32; 41 | EIP : Unsigned_32; 42 | EFLAGS : Unsigned_32; 43 | EAX : Unsigned_32; 44 | ECX : Unsigned_32; 45 | EDX : Unsigned_32; 46 | EBX : Unsigned_32; 47 | ESP : Unsigned_32; 48 | EBP : Unsigned_32; 49 | ESI : Unsigned_32; 50 | EDI : Unsigned_32; 51 | ES : Unsigned_16; 52 | Reserved_4 : Unsigned_16 := 0; 53 | CS : Unsigned_16; 54 | Reserved_5 : Unsigned_16 := 0; 55 | SS : Unsigned_16; 56 | Reserved_6 : Unsigned_16 := 0; 57 | DS : Unsigned_16; 58 | Reserved_7 : Unsigned_16 := 0; 59 | FS : Unsigned_16; 60 | Reserved_8 : Unsigned_16 := 0; 61 | GS : Unsigned_16; 62 | Reserved_9 : Unsigned_16 := 0; 63 | LDTR : Unsigned_16; 64 | Reserved_10 : Unsigned_16 := 0; 65 | Reserved_11 : Unsigned_16 := 0; 66 | IOPB : Unsigned_16; 67 | end record 68 | with Size => 832; 69 | for Task_State_Segment use 70 | record 71 | LINK at 0 range 0 .. 15; 72 | Reserved at 0 range 16 .. 31; 73 | ESP0 at 4 range 0 .. 31; 74 | SS0 at 8 range 0 .. 15; 75 | Reserved_1 at 8 range 16 .. 31; 76 | ESP1 at 12 range 0 .. 31; 77 | SS1 at 16 range 0 .. 15; 78 | Reserved_2 at 16 range 16 .. 31; 79 | ESP2 at 20 range 0 .. 31; 80 | SS2 at 24 range 0 .. 15; 81 | Reserved_3 at 24 range 16 .. 31; 82 | CR3 at 28 range 0 .. 31; 83 | EIP at 32 range 0 .. 31; 84 | EFLAGS at 36 range 0 .. 31; 85 | EAX at 40 range 0 .. 31; 86 | ECX at 44 range 0 .. 31; 87 | EDX at 48 range 0 .. 31; 88 | EBX at 52 range 0 .. 31; 89 | ESP at 56 range 0 .. 31; 90 | EBP at 60 range 0 .. 31; 91 | ESI at 64 range 0 .. 31; 92 | EDI at 68 range 0 .. 31; 93 | ES at 72 range 0 .. 15; 94 | Reserved_4 at 72 range 16 .. 31; 95 | CS at 76 range 0 .. 15; 96 | Reserved_5 at 76 range 16 .. 31; 97 | SS at 80 range 0 .. 15; 98 | Reserved_6 at 80 range 16 .. 31; 99 | DS at 84 range 0 .. 15; 100 | Reserved_7 at 84 range 16 .. 31; 101 | FS at 88 range 0 .. 15; 102 | Reserved_8 at 88 range 16 .. 31; 103 | GS at 92 range 0 .. 15; 104 | Reserved_9 at 92 range 16 .. 31; 105 | LDTR at 96 range 0 .. 15; 106 | Reserved_10 at 96 range 16 .. 31; 107 | Reserved_11 at 100 range 0 .. 15; 108 | IOPB at 100 range 16 .. 31; 109 | end record; 110 | end x86.TSS; 111 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86-vga.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- X86.VGA 14 | -- 15 | -- Purpose: 16 | -- This package contains the basic types necessary to implement a 17 | -- VGA text-mode driver. 18 | ------------------------------------------------------------------------------- 19 | package x86.Vga is 20 | pragma Preelaborate; 21 | 22 | ---------------------------------------------------------------------------- 23 | -- The predefined VGA color codes. 24 | ---------------------------------------------------------------------------- 25 | type Color is ( 26 | Black, 27 | Blue, 28 | Green, 29 | Cyan, 30 | Red, 31 | Magenta, 32 | Brown, 33 | Light_Grey, 34 | Dark_Grey, 35 | Light_Blue, 36 | Light_Green, 37 | Light_Cyan, 38 | Light_Red, 39 | Light_Magenta, 40 | Yellow, 41 | White 42 | ) 43 | with Size => 4; 44 | for Color use ( 45 | Black => 0, 46 | Blue => 1, 47 | Green => 2, 48 | Cyan => 3, 49 | Red => 4, 50 | Magenta => 5, 51 | Brown => 6, 52 | Light_Grey => 7, 53 | Dark_Grey => 8, 54 | Light_Blue => 9, 55 | Light_Green => 10, 56 | Light_Cyan => 11, 57 | Light_Red => 12, 58 | Light_Magenta => 13, 59 | Yellow => 14, 60 | White => 15 61 | ); 62 | 63 | VGA_COL_COUNT : constant := 80; 64 | VGA_ROW_COUNT : constant := 24; 65 | 66 | subtype Col is Natural range 0 .. VGA_COL_COUNT - 1; 67 | subtype Row is Natural range 0 .. VGA_ROW_COUNT - 1; 68 | 69 | ---------------------------------------------------------------------------- 70 | -- Represents the encoding of an individual character entry in the 71 | -- VGA screen buffer. 72 | ---------------------------------------------------------------------------- 73 | type Vga_Buffer_Char is 74 | record 75 | Char : Character; 76 | Foreground : Color; 77 | Background : Color; 78 | end record 79 | with Size => 16; 80 | for Vga_Buffer_Char use 81 | record 82 | Char at 0 range 0 .. 7; 83 | Foreground at 1 range 0 .. 3; 84 | Background at 1 range 4 .. 7; 85 | end record; 86 | 87 | ---------------------------------------------------------------------------- 88 | -- Vga Buffer type. 89 | ---------------------------------------------------------------------------- 90 | type Vga_Buffer is 91 | array (Natural range 0 .. (VGA_COL_COUNT * VGA_ROW_COUNT) - 1) 92 | of Vga_Buffer_Char; 93 | end x86.Vga; 94 | -------------------------------------------------------------------------------- /src/bsp/src/arch/x86/x86.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- SYSTEM.X86 14 | -- 15 | -- Purpose: 16 | -- Base package for all x86 BSP packages. 17 | ------------------------------------------------------------------------------- 18 | package x86 is 19 | pragma Preelaborate; 20 | end x86; 21 | -------------------------------------------------------------------------------- /src/iso/.gitignore: -------------------------------------------------------------------------------- 1 | *.elf 2 | -------------------------------------------------------------------------------- /src/iso/boot/grub/grub.cfg: -------------------------------------------------------------------------------- 1 | set timeout=0 2 | set default="0" 3 | menuentry "main" { 4 | multiboot /boot/cxos.elf 5 | } 6 | -------------------------------------------------------------------------------- /src/iso/makefile: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2020, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .POSIX: 13 | .DELETE_ON_ERROR: 14 | MAKEFLAGS += --warn-undefined-variables 15 | MAKEFLAGS += --no-builtin-rules 16 | 17 | KERNEL_DIR := ../kernel 18 | KERNEL_BINARY := ${KERNEL_DIR}/build/cxos.elf 19 | 20 | BUILD_DIR := build 21 | ISO := ${BUILD_DIR}/cxos.img 22 | 23 | .PHONY: all clean 24 | 25 | all: ${ISO} 26 | 27 | clean: 28 | rm -rf ${BUILD_DIR} 29 | 30 | ${ISO}: ${KERNEL_BINARY} ${BUILD_DIR} 31 | cp "${KERNEL_BINARY}" ./boot 32 | grub-mkrescue -o ${ISO} . 33 | 34 | ${BUILD_DIR}: 35 | mkdir -p ${BUILD_DIR} 36 | -------------------------------------------------------------------------------- /src/kernel/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | obj 3 | gnatprove 4 | *.ali 5 | *.o 6 | *.a 7 | *.elf 8 | *.bin 9 | *.img 10 | *.log 11 | *.out 12 | -------------------------------------------------------------------------------- /src/kernel/README.md: -------------------------------------------------------------------------------- 1 | # CXOS Kernel 2 | 3 | The sources for the main Kernel are contained within this directory. The main entry point for the x86 implementation of the kernel is contained within the `src/arch/x86/cxos-boot-entry.S` file. 4 | -------------------------------------------------------------------------------- /src/kernel/kernel.adc: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | pragma Discard_Names; 13 | pragma Normalize_Scalars; 14 | pragma Restrictions (Immediate_Reclamation); 15 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 16 | pragma Restrictions (Max_Protected_Entries => 0); 17 | pragma Restrictions (Max_Select_Alternatives => 0); 18 | pragma Restrictions (Max_Task_Entries => 0); 19 | pragma Restrictions (Max_Tasks => 0); 20 | pragma Restrictions (No_Abort_Statements); 21 | pragma Restrictions (No_Allocators); 22 | pragma Restrictions (No_Calendar); 23 | -- pragma Restrictions (No_Default_Initialization); 24 | pragma Restrictions (No_Default_Stream_Attributes); 25 | pragma Restrictions (No_Delay); 26 | pragma Restrictions (No_Dispatch); 27 | pragma Restrictions (No_Dispatching_Calls); 28 | pragma Restrictions (No_Dynamic_Attachment); 29 | pragma Restrictions (No_Dynamic_Priorities); 30 | pragma Restrictions (No_Entry_Calls_In_Elaboration_Code); 31 | pragma Restrictions (No_Entry_Queue); 32 | pragma Restrictions (No_Enumeration_Maps); 33 | pragma Restrictions (No_Exception_Propagation); 34 | pragma Restrictions (No_Exception_Registration); 35 | pragma Restrictions (No_Finalization); 36 | pragma Restrictions (No_Fixed_Point); 37 | pragma Restrictions (No_Implicit_Dynamic_Code); 38 | pragma Restrictions (No_Implicit_Heap_Allocations); 39 | pragma Restrictions (No_Initialize_Scalars); 40 | pragma Restrictions (No_Io); 41 | pragma Restrictions (No_Local_Allocators); 42 | pragma Restrictions (No_Local_Protected_Objects); 43 | pragma Restrictions (No_Local_Timing_Events); 44 | pragma Restrictions (No_Nested_Finalization); 45 | pragma Restrictions (No_Obsolescent_Features); 46 | pragma Restrictions (No_Protected_Type_Allocators); 47 | pragma Restrictions (No_Protected_Types); 48 | pragma Restrictions (No_Recursion); 49 | pragma Restrictions (No_Relative_Delay); 50 | pragma Restrictions (No_Requeue_Statements); 51 | pragma Restrictions (No_Select_Statements); 52 | pragma Restrictions (No_Specific_Termination_Handlers); 53 | pragma Restrictions (No_Stream_Optimizations); 54 | pragma Restrictions (No_Streams); 55 | pragma Restrictions (No_Task_Allocators); 56 | pragma Restrictions (No_Task_Attributes_Package); 57 | pragma Restrictions (No_Task_Hierarchy); 58 | pragma Restrictions (No_Task_Termination); 59 | pragma Restrictions (No_Tasking); 60 | pragma Restrictions (No_Terminate_Alternatives); 61 | pragma Restrictions (No_Unchecked_Access); 62 | pragma Restrictions (Simple_Barriers); 63 | pragma Restrictions (Static_Priorities); 64 | pragma Restrictions (Static_Storage_Size); 65 | 66 | -------------------------------------------------------------------------------- /src/kernel/kernel.gpr: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | project Kernel is 13 | ---------------------------------------------------------------------------- 14 | -- The valid target architectures for the project. 15 | ---------------------------------------------------------------------------- 16 | type Arch_Type is ( 17 | "x86" 18 | ); 19 | 20 | ---------------------------------------------------------------------------- 21 | -- The selected architecture. 22 | ---------------------------------------------------------------------------- 23 | ARCH : Arch_Type := "x86"; 24 | 25 | for Source_Dirs use ( 26 | "../bsp/src/arch/" & ARCH, 27 | "src", 28 | "src/arch/common", 29 | "src/arch/" & ARCH 30 | ); 31 | for Object_Dir use "obj"; 32 | for Exec_Dir use "build"; 33 | for Create_Missing_Dirs use "True"; 34 | 35 | for Languages use ( 36 | "Ada", 37 | "Asm_Cpp" 38 | ); 39 | 40 | case ARCH is 41 | when "x86" => 42 | for Main use ("cxos-boot-entry.S"); 43 | end case; 44 | 45 | package Builder is 46 | case ARCH is 47 | when "x86" => 48 | for Executable ("cxos-boot-entry.S") use "cxos"; 49 | end case; 50 | 51 | for Executable_Suffix use ".elf"; 52 | for Global_Configuration_Pragmas use "kernel.adc"; 53 | for Global_Compilation_Switches ("Others") use ( 54 | "-nostdlib" 55 | ); 56 | end Builder; 57 | 58 | package Compiler is 59 | for Default_Switches ("Ada") use ( 60 | "-O0", 61 | "-ffunction-sections", 62 | "-fdata-sections", 63 | "-fno-omit-frame-pointer", 64 | "-ggdb", 65 | "-gnat2012", 66 | "-gnatwadehl", 67 | "-gnatVa", 68 | "-gnaty3abcdefhiklmnoprstux" 69 | ); 70 | 71 | for Default_Switches ("Asm_Cpp") use ( 72 | "-ggdb" 73 | ); 74 | end Compiler; 75 | 76 | package Linker is 77 | for Switches (others) use ( 78 | "-Wl,--gc-sections", 79 | "-static", 80 | "-nostartfiles", 81 | "-nodefaultlibs", 82 | "-T" & Kernel'Project_Dir & "src/arch/" & ARCH & "/" & ARCH & ".ld" 83 | ); 84 | end Linker; 85 | 86 | for Runtime ("Ada") use "../runtime/build"; 87 | 88 | case ARCH is 89 | when "x86" => 90 | for Target use "i686-elf"; 91 | end case; 92 | end Kernel; 93 | -------------------------------------------------------------------------------- /src/kernel/makefile: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2020, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .POSIX: 13 | .DELETE_ON_ERROR: 14 | MAKEFLAGS += --warn-undefined-variables 15 | MAKEFLAGS += --no-builtin-rules 16 | 17 | BUILD_DIR := build 18 | KERNEL_BINARY := ${BUILD_DIR}/cxos.elf 19 | KERNEL_PROJ := kernel 20 | 21 | .PHONY: all clean 22 | 23 | all: ${KERNEL_BINARY} 24 | 25 | clean: 26 | gprclean -P${KERNEL_PROJ} 27 | 28 | ${KERNEL_BINARY}: 29 | gprbuild -P${KERNEL_PROJ} 30 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-debug.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.DEBUG 14 | -- 15 | -- Purpose: 16 | -- This package contains logic for debugging kernel functionality. 17 | -- This is a generic package. The debug methods are architecture-specific. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Debug is 20 | pragma Preelaborate; 21 | 22 | ---------------------------------------------------------------------------- 23 | -- Put_String 24 | ---------------------------------------------------------------------------- 25 | procedure Put_String ( 26 | Data : String 27 | ); 28 | 29 | ---------------------------------------------------------------------------- 30 | -- Put_String_Wide 31 | ---------------------------------------------------------------------------- 32 | procedure Put_String_Wide ( 33 | Data : Wide_String 34 | ); 35 | 36 | end Cxos.Debug; 37 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-devices-graphics.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.DEVICES.GRAPHICS 14 | -- 15 | -- Purpose: 16 | -- Base package for specific packages for working with graphics at the 17 | -- system level. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Devices.Graphics is 20 | pragma Preelaborate; 21 | end Cxos.Devices.Graphics; 22 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-devices-storage.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- CXOS.DEVICES.STORAGE 16 | -- 17 | -- Purpose: 18 | -- This package contains definitons and functionality for working with 19 | -- storage devices. 20 | ------------------------------------------------------------------------------- 21 | package Cxos.Devices.Storage is 22 | pragma Preelaborate; 23 | 24 | ---------------------------------------------------------------------------- 25 | -- Storage device read buffer type. 26 | -- Acts as a generic buffer type to use when reading from storage devices. 27 | ---------------------------------------------------------------------------- 28 | type Read_Buffer is array (Natural range <>) of Unsigned_8; 29 | end Cxos.Devices.Storage; 30 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-devices.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.DEVICES 14 | -- 15 | -- Purpose: 16 | -- This package contains definitons and functionality for working with 17 | -- system devices. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Devices is 20 | pragma Preelaborate; 21 | 22 | ---------------------------------------------------------------------------- 23 | -- Process Result type. 24 | -- Tracks the outcome of internal functions. 25 | ---------------------------------------------------------------------------- 26 | type Process_Result is ( 27 | Bus_Read_Error, 28 | Command_Aborted, 29 | Device_Busy, 30 | Device_In_Error_State, 31 | Device_Non_ATA, 32 | Device_Not_Found, 33 | Device_Not_Present, 34 | Device_Read_Buffer_Overflow, 35 | Drive_Fault, 36 | Invalid_Command, 37 | Packet_Interface_Not_Supported, 38 | Success, 39 | Unhandled_Exception 40 | ); 41 | 42 | ---------------------------------------------------------------------------- 43 | ---------------------------------------------------------------------------- 44 | type Device_Bus_Type_T is ( 45 | Device_Bus_Type_PCI 46 | ); 47 | 48 | ---------------------------------------------------------------------------- 49 | ---------------------------------------------------------------------------- 50 | type Device_Bus_T is 51 | record 52 | Device_Bus_Type : Device_Bus_Type_T; 53 | end record; 54 | 55 | ---------------------------------------------------------------------------- 56 | -- Initialise 57 | ---------------------------------------------------------------------------- 58 | procedure Initialise; 59 | 60 | end Cxos.Devices; 61 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-error_handling.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- CXOS.ERROR_HANDLING 16 | -- 17 | -- Purpose: 18 | -- This package contains functionality for reporting and handling kernel 19 | -- errors. 20 | ------------------------------------------------------------------------------- 21 | package Cxos.Error_Handling is 22 | pragma Preelaborate; 23 | 24 | ---------------------------------------------------------------------------- 25 | -- Log_Kernel_Error 26 | -- 27 | -- This procedure logs a kernel error, logging and outputting the error 28 | -- string as configured. 29 | ---------------------------------------------------------------------------- 30 | procedure Log_Kernel_Error ( 31 | Message : String 32 | ); 33 | 34 | private 35 | ---------------------------------------------------------------------------- 36 | -- Whether errors should be printed to the debug output. 37 | ---------------------------------------------------------------------------- 38 | DEBUG_PRINT_ERRORS : constant Boolean := True; 39 | 40 | ---------------------------------------------------------------------------- 41 | -- Last_Chance_Handler 42 | -- 43 | -- Purpose: 44 | -- The runtime Last_Chance_Handler function. 45 | -- This procedure is the GNAT mandated handler for any uncaught 46 | -- exceptions that are propagated to the top level. 47 | -- This runtime, like other bareboard targets, does not support exception 48 | -- propagation. So any uncaught exception will be handled here. 49 | -- Exceptions: 50 | -- None. 51 | ---------------------------------------------------------------------------- 52 | procedure Last_Chance_Handler ( 53 | Msg : System.Address; 54 | Line : Integer 55 | ) with Export, 56 | Convention => C, 57 | External_Name => "__gnat_last_chance_handler"; 58 | 59 | end Cxos.Error_Handling; 60 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-filesystems.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.FILESYSTEMS 14 | -- 15 | -- Purpose: 16 | -- This package contains definitons and functionality for working with 17 | -- filesystems. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Filesystems is 20 | pragma Preelaborate; 21 | end Cxos.Filesystems; 22 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-vfs.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | package body Cxos.VFS is 13 | ---------------------------------------------------------------------------- 14 | -- Initialise 15 | ---------------------------------------------------------------------------- 16 | procedure Initialise ( 17 | Status : out Program_Status 18 | ) is 19 | begin 20 | Status := Success; 21 | end Initialise; 22 | 23 | end Cxos.VFS; 24 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos-vfs.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.VFS 14 | -- 15 | -- Purpose: 16 | -- This package contains functionality for interacting with the virtual 17 | -- file system. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.VFS is 20 | pragma Preelaborate; 21 | 22 | ---------------------------------------------------------------------------- 23 | -- Program status type. 24 | -- Used to track the result of package processes. 25 | ---------------------------------------------------------------------------- 26 | type Program_Status is ( 27 | Success, 28 | Unhandled_Exception 29 | ); 30 | 31 | ---------------------------------------------------------------------------- 32 | -- File type. 33 | ---------------------------------------------------------------------------- 34 | type Directory_Entry_T is 35 | record 36 | Name : Wide_String (1 .. 512); 37 | end record; 38 | 39 | ---------------------------------------------------------------------------- 40 | -- Initialise 41 | -- 42 | -- Purpose: 43 | -- This function initialises the kernel's virtual file system. 44 | -- Exceptions: 45 | -- None. 46 | ---------------------------------------------------------------------------- 47 | procedure Initialise ( 48 | Status : out Program_Status 49 | ); 50 | 51 | end Cxos.VFS; 52 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Characters.Latin_1; 13 | with Cxos.Debug; 14 | with Cxos.Tasking; 15 | 16 | package body Cxos is 17 | package Chars renames Ada.Characters.Latin_1; 18 | 19 | ---------------------------------------------------------------------------- 20 | -- Main 21 | ---------------------------------------------------------------------------- 22 | procedure Main is 23 | begin 24 | -- Print the ASCII splash screen. 25 | Print_Splash; 26 | 27 | loop 28 | Cxos.Tasking.Idle; 29 | end loop; 30 | end Main; 31 | 32 | ---------------------------------------------------------------------------- 33 | -- Print_Splash 34 | ---------------------------------------------------------------------------- 35 | procedure Print_Splash is 36 | Line_1 : constant String := " /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ "; 37 | Line_2 : constant String := " /$$__ $$| $$ / $$ /$$__ $$ /$$__ $$"; 38 | Line_3 : constant String := "| $$ \__/| $$/ $$/| $$ \ $$| $$ \__/"; 39 | Line_4 : constant String := "| $$ \ $$$$/ | $$ | $$| $$$$$$ "; 40 | Line_5 : constant String := "| $$ >$$ $$ | $$ | $$ \____ $$"; 41 | Line_6 : constant String := "| $$ $$ /$$/\ $$| $$ | $$ /$$ \ $$"; 42 | Line_7 : constant String := "| $$$$$$/| $$ \ $$| $$$$$$/| $$$$$$/"; 43 | Line_8 : constant String := " \______/ |__/ |__/ \______/ \______/ "; 44 | begin 45 | Print_Splash_to_Serial : 46 | begin 47 | Cxos.Debug.Put_String ("" & Chars.LF); 48 | Cxos.Debug.Put_String (Line_1 & Chars.LF); 49 | Cxos.Debug.Put_String (Line_2 & Chars.LF); 50 | Cxos.Debug.Put_String (Line_3 & Chars.LF); 51 | Cxos.Debug.Put_String (Line_4 & Chars.LF); 52 | Cxos.Debug.Put_String (Line_5 & Chars.LF); 53 | Cxos.Debug.Put_String (Line_6 & Chars.LF); 54 | Cxos.Debug.Put_String (Line_7 & Chars.LF); 55 | Cxos.Debug.Put_String (Line_8 & Chars.LF); 56 | Cxos.Debug.Put_String ("" & Chars.LF); 57 | end Print_Splash_to_Serial; 58 | end Print_Splash; 59 | end Cxos; 60 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/cxos.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS 14 | -- 15 | -- Purpose: 16 | -- This package contains the main Kernel code. 17 | ------------------------------------------------------------------------------- 18 | package Cxos is 19 | pragma Preelaborate; 20 | 21 | ---------------------------------------------------------------------------- 22 | -- Main 23 | -- 24 | -- Purpose: 25 | -- The main kernel loop. 26 | -- Exceptions: 27 | -- None. 28 | ---------------------------------------------------------------------------- 29 | procedure Main 30 | with No_Return, 31 | Export, 32 | Convention => Ada, 33 | External_Name => "__main"; 34 | 35 | private 36 | ---------------------------------------------------------------------------- 37 | -- Print_Splash 38 | -- 39 | -- Purpose: 40 | -- Prints the CXOS test splash screen. 41 | -- Exceptions: 42 | -- None. 43 | ---------------------------------------------------------------------------- 44 | procedure Print_Splash; 45 | end Cxos; 46 | -------------------------------------------------------------------------------- /src/kernel/src/arch/common/elf.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | package body Elf is 13 | ---------------------------------------------------------------------------- 14 | -- Validate_Elf_Header_Magic_Number 15 | ---------------------------------------------------------------------------- 16 | function Validate_Elf_Header_Magic_Number ( 17 | Magic_Number : Elf_File_Magic_Number 18 | ) return Boolean is 19 | -- The expected value for the ELF Magic Number. 20 | Elf_Header_Magic_Number : constant Elf_File_Magic_Number 21 | := Character'Val (16#7F#) & "ELF"; 22 | begin 23 | return Magic_Number = Elf_Header_Magic_Number; 24 | end Validate_Elf_Header_Magic_Number; 25 | end Elf; 26 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-boot-entry.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2019, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .set MULTIBOOT_BOOTLOADER_MAGIC, 0x1BADB002 13 | .set MULTIBOOT_HEADER_FLAGS, 0x3 14 | .set MULTIBOOT_HEADER_CHECKSUM, -(MULTIBOOT_BOOTLOADER_MAGIC + MULTIBOOT_HEADER_FLAGS) 15 | 16 | .section .multiboot 17 | ##################################################################### 18 | # Multiboot header 19 | ##################################################################### 20 | .align 4 21 | .long MULTIBOOT_BOOTLOADER_MAGIC 22 | .long MULTIBOOT_HEADER_FLAGS 23 | .long MULTIBOOT_HEADER_CHECKSUM 24 | 25 | .section .bss, "aw", @nobits 26 | 27 | ##################################################################### 28 | # Multiboot Variables 29 | # These are stored globally so they are acessible to the kernel 30 | # during kernel initialisation. 31 | # Since the runtime and hardware is initialised first, these sre 32 | # stored here to not rely on the stack or registers to store these. 33 | ##################################################################### 34 | .global multiboot_magic 35 | multiboot_magic: 36 | .skip 4 37 | .global multiboot_struct_ptr 38 | multiboot_struct_ptr: 39 | .skip 4 40 | 41 | 42 | .section .text 43 | 44 | ##################################################################### 45 | # Boot Hang 46 | # 47 | # Fixes the machine in an endless loop. 48 | # Used to halt the processor in the case of a boot error. 49 | ##################################################################### 50 | .boot_hang: 51 | jmp .boot_hang 52 | 53 | 54 | ##################################################################### 55 | # Boot entry point 56 | # 57 | # Main boot entry point. 58 | # Execution begins here. 59 | ##################################################################### 60 | .global _start 61 | .type _start, @function 62 | _start: 63 | # Disable interrupts prior to system initialisation. 64 | cli 65 | 66 | # Save multiboot variables in global variables. 67 | # These are used in the kernel start procedure to authenticate 68 | # the bootloader. 69 | # See: https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Machine-state 70 | 71 | movl $KERNEL_VMA_OFFSET, %edx # Move kernel VMA offset into EDX. 72 | 73 | movl $multiboot_magic, %ecx # Move multiboot_magic address into ECX. 74 | subl %edx, %ecx # Subtract VMA offset. 75 | movl %eax, (%ecx) # Move magic number into the reserved address. 76 | 77 | movl $multiboot_struct_ptr, %ecx # Move multiboot_struct address into ECX. 78 | subl %edx, %ecx # Subtract VMA offset. 79 | movl %ebx, (%ecx) # Move struct to the reserved address. 80 | 81 | # Setup stack. 82 | movl $kernel_stack_top, %eax # Load stack top in EAX. 83 | subl %edx, %eax # Subtract higher-half offset. 84 | movl %eax, %esp # Load stack. 85 | 86 | # Copy Multiboot data to a reserved location where it can be accessed by the 87 | # kernel after paging has been enabled. 88 | call copy_multiboot_data 89 | 90 | # Initialise the boot page structures. 91 | call init_boot_page_directory 92 | 93 | # Move VMA offset into EAX. 94 | movl $KERNEL_VMA_OFFSET, %eax 95 | 96 | # Load page directory. 97 | movl $boot_page_directory, %ecx # Load address of the page dir into CR3. 98 | subl %eax, %ecx # Subtract VMA offset. 99 | movl %ecx, %cr3 # Move the address into CR3. 100 | 101 | .enable_paging: 102 | # Set write-protect and paging-enabled flags. 103 | movl %cr0, %ecx 104 | orl $0x80010000, %ecx 105 | movl %ecx, %cr0 106 | 107 | # Perform an absolute jump to higher half. 108 | lea .higher_half_jump, %ecx 109 | jmp *%ecx 110 | 111 | .higher_half_jump: 112 | # Load kernel stack 113 | movl $0xFF000000, %eax # Load the stack base in EAX. 114 | addl $KERNEL_STACK_SIZE, %eax # Add the stack size to EAX. 115 | movl %eax, %esp # Load stack. 116 | 117 | # Remove the boot paging identity mapping. 118 | call remove_identity_mapping 119 | 120 | # Initialise Ada runtime. 121 | call adainit 122 | 123 | # Initialise the kernel. 124 | call __kernel_init 125 | 126 | # Jump to the kernel main loop. 127 | call __main 128 | 129 | cli 130 | hlt 131 | 132 | # Halt the machine indefinitely if execution reaches this point. 133 | jmp .boot_hang 134 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-boot-multiboot_init.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with System; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- CXOS.BOOT.MULTIBOOT_INIT 17 | -- 18 | -- Purpose: 19 | -- This package contains code and defintions for working with the 20 | -- multiboot information structures provided at system init by the 21 | -- bootloader. 22 | ------------------------------------------------------------------------------- 23 | private package Cxos.Boot.Multiboot_Init is 24 | pragma Preelaborate; 25 | 26 | ---------------------------------------------------------------------------- 27 | -- Process Result type. 28 | -- Used for storing and returning the result of an internal memory related 29 | -- procedure. 30 | ---------------------------------------------------------------------------- 31 | type Process_Result is ( 32 | Success, 33 | Unhandled_Exception 34 | ); 35 | 36 | ---------------------------------------------------------------------------- 37 | -- Parse_Multiboot_Info 38 | -- 39 | -- Purpose: 40 | -- Parses the multiboot info structures. 41 | ---------------------------------------------------------------------------- 42 | function Parse_Multiboot_Info return Process_Result; 43 | 44 | ---------------------------------------------------------------------------- 45 | -- Clear_Multiboot_Reserved_Data 46 | -- 47 | -- Purpose: 48 | -- Marks the memory reserved for the multiboot data as being free and 49 | -- reusable. 50 | ---------------------------------------------------------------------------- 51 | function Clear_Multiboot_Reserved_Data return Process_Result; 52 | 53 | private 54 | ---------------------------------------------------------------------------- 55 | -- Multiboot section information type. 56 | -- Contains information necessary to load a particular multiboot section 57 | -- that has been copied to an alternate location during boot. 58 | ---------------------------------------------------------------------------- 59 | type Multiboot_Section_Info is 60 | record 61 | Section_Addr : System.Address; 62 | Section_Length : Unsigned_32; 63 | Section_Present : Boolean; 64 | end record 65 | with Size => 72; 66 | for Multiboot_Section_Info use 67 | record 68 | Section_Addr at 0 range 0 .. 31; 69 | Section_Length at 4 range 0 .. 31; 70 | Section_Present at 8 range 0 .. 7; 71 | end record; 72 | 73 | ---------------------------------------------------------------------------- 74 | -- Parse_Multiboot_Memory_Map 75 | -- 76 | -- Purpose: 77 | -- Parses the multiboot memory map structures, mapping the specified 78 | -- memory regions listed in the multiboot structure. 79 | -- Exceptions: 80 | -- None. 81 | ---------------------------------------------------------------------------- 82 | function Parse_Multiboot_Memory_Map ( 83 | Memory_Map_Addr : System.Address; 84 | Memory_Map_Length : Unsigned_32 85 | ) return Process_Result; 86 | 87 | ---------------------------------------------------------------------------- 88 | -- Parse_Multiboot_Drive_Map 89 | -- 90 | -- Purpose: 91 | -- This function parses the Multiboot information structure's drive map. 92 | -- Exceptions: 93 | -- None. 94 | ---------------------------------------------------------------------------- 95 | function Parse_Multiboot_Drive_Map ( 96 | Drive_Map_Addr : System.Address; 97 | Drive_Map_Length : Unsigned_32 98 | ) return Process_Result; 99 | 100 | end Cxos.Boot.Multiboot_Init; 101 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-boot-protected_mode_init.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2019, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .section .text 13 | 14 | ##################################################################### 15 | # Protected_Mode_Init 16 | # 17 | # Performs the jump to protected mode. 18 | # Reloads the segment registers after the jump. 19 | ##################################################################### 20 | .global __protected_mode_init 21 | .type __protected_mode_init, @function 22 | __protected_mode_init: 23 | # Clear interrupt flag. 24 | cli 25 | 26 | # Enable protected mode flag in processor control register 0. 27 | movl %cr0, %eax 28 | orl $0x1, %eax 29 | movl %eax, %cr0 30 | 31 | # This far-jump instruction loads the value of '1' into the CS register. JMP is used 32 | # here since we can't modify CS with the MOV instruction. The JMP instruction used with 33 | # the format 'CS:OFFSET' will reload the CS register to the target of the jump. 34 | # Refer to: https://c9x.me/x86/html/file_module_x86_id_147.html 35 | # This refers to GDT entry 1 being the code segment. 36 | # This is because bit 1 << 3 is the index bit of the segment structure, the 0x8 here 37 | # will set that bit to '1'. 38 | # Refer to 3.4.2 of the Intel SDM on page 95 for a description of the segment selector 39 | # structure. 40 | # For a simple explanation, refer to: https://stackoverflow.com/a/23979175/5931673 41 | ljmp $0x0008, $.Lpmode_reload_segments 42 | 43 | .Lpmode_reload_segments: 44 | mov $0x10, %eax 45 | mov %ax, %ds 46 | mov %ax, %es 47 | mov %ax, %fs 48 | mov %ax, %gs 49 | mov %ax, %ss 50 | 51 | # Set interrupt flag. 52 | sti 53 | 54 | ret 55 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-boot.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.BOOT 14 | -- 15 | -- Purpose: 16 | -- This package contains the kernel boot code. 17 | ------------------------------------------------------------------------------- 18 | package Cxos.Boot is 19 | pragma Preelaborate; 20 | 21 | ---------------------------------------------------------------------------- 22 | -- Program status type. 23 | -- Used to track the result of individual functions. 24 | ---------------------------------------------------------------------------- 25 | type Program_Status is ( 26 | Success, 27 | Unhandled_Exception, 28 | Unset 29 | ); 30 | 31 | ---------------------------------------------------------------------------- 32 | -- Initialise_Kernel 33 | -- 34 | -- Purpose: 35 | -- Initialises the kernel. 36 | -- Exceptions: 37 | -- None. 38 | ---------------------------------------------------------------------------- 39 | procedure Initialise_Kernel 40 | with Export, 41 | Convention => Assembler, 42 | External_Name => "__kernel_init"; 43 | 44 | private 45 | ---------------------------------------------------------------------------- 46 | -- Mark_Kernel_Memory 47 | -- 48 | -- Purpose: 49 | -- This procedure marks the memory used by the kernel as being allocated 50 | -- and non-free in the memory map. 51 | -- Exceptions: 52 | -- None. 53 | ---------------------------------------------------------------------------- 54 | procedure Mark_Kernel_Memory (Status : out Program_Status); 55 | 56 | ---------------------------------------------------------------------------- 57 | -- Protected_Mode_Init 58 | -- 59 | -- Purpose: 60 | -- Performs the final jump to protected mode. 61 | -- Exceptions: 62 | -- None. 63 | ---------------------------------------------------------------------------- 64 | procedure Protected_Mode_Init 65 | with Import, 66 | Convention => Assembler, 67 | External_Name => "__protected_mode_init"; 68 | 69 | end Cxos.Boot; 70 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-debug.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Characters.Latin_1; 13 | with Cxos.Devices.Serial; 14 | with Interfaces; use Interfaces; 15 | 16 | package body Cxos.Debug is 17 | ---------------------------------------------------------------------------- 18 | -- Put_String 19 | -- 20 | -- Implementation Notes: 21 | -- Prints output to COM1. 22 | ---------------------------------------------------------------------------- 23 | procedure Put_String ( 24 | Data : String 25 | ) is 26 | begin 27 | Cxos.Devices.Serial.Put_String (Data); 28 | end Put_String; 29 | 30 | ---------------------------------------------------------------------------- 31 | -- Put_String_Wide 32 | ---------------------------------------------------------------------------- 33 | procedure Put_String_Wide ( 34 | Data : Wide_String 35 | ) is 36 | begin 37 | for C of Data loop 38 | -- Converts each individual wide char and prints it. 39 | Print_Wide_Char : 40 | declare 41 | -- An individual Char converted to its nearest ASCII match. 42 | Ascii_Char : Character; 43 | begin 44 | Ascii_Char := 45 | Character'Val (Unsigned_8 (Wide_Character'Pos (C))); 46 | Cxos.Devices.Serial.Put_String ("" & Ascii_Char); 47 | exception 48 | when Constraint_Error => 49 | Cxos.Devices.Serial. 50 | Put_String ("" & Ada.Characters.Latin_1.NUL); 51 | end Print_Wide_Char; 52 | end loop; 53 | end Put_String_Wide; 54 | 55 | end Cxos.Debug; 56 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-devices-graphics-vga.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | package body Cxos.Devices.Graphics.Vga is 13 | ---------------------------------------------------------------------------- 14 | -- Clear 15 | ---------------------------------------------------------------------------- 16 | procedure Clear ( 17 | Bg : Color 18 | ) is 19 | begin 20 | for X in Col'Range loop 21 | for Y in Row'Range loop 22 | Put_Char (X, Y, Bg, Bg, ' '); 23 | end loop; 24 | end loop; 25 | exception 26 | when Constraint_Error => 27 | null; 28 | end Clear; 29 | 30 | ---------------------------------------------------------------------------- 31 | -- Put_Char 32 | ---------------------------------------------------------------------------- 33 | procedure Put_Char ( 34 | X : Col; 35 | Y : Row; 36 | Fg : Color; 37 | Bg : Color; 38 | Ch : Character 39 | ) is 40 | begin 41 | Vga_Output_Buffer (Y * VGA_COL_COUNT + X) := (Ch, Fg, Bg); 42 | exception 43 | when Constraint_Error => 44 | null; 45 | end Put_Char; 46 | 47 | ---------------------------------------------------------------------------- 48 | -- Put_String 49 | ---------------------------------------------------------------------------- 50 | procedure Put_String ( 51 | X : Col; 52 | Y : Row; 53 | Fg : Color; 54 | Bg : Color; 55 | S : String 56 | ) is 57 | C : Natural := 0; 58 | begin 59 | for I in S'Range loop 60 | Put_Char (X + C, Y, Fg, Bg, S (I)); 61 | C := C + 1; 62 | end loop; 63 | exception 64 | when Constraint_Error => 65 | null; 66 | end Put_String; 67 | 68 | end Cxos.Devices.Graphics.Vga; 69 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-devices-graphics-vga.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System.Storage_Elements; use System.Storage_Elements; 13 | with x86.Vga; use x86.Vga; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- CXOS.DEVICES.GRAPHICS.VGA 17 | -- 18 | -- Purpose: 19 | -- Package for interfacing with VGA hardware. 20 | ------------------------------------------------------------------------------- 21 | package Cxos.Devices.Graphics.Vga is 22 | pragma Preelaborate; 23 | 24 | ---------------------------------------------------------------------------- 25 | -- Put_String 26 | -- 27 | -- Purpose: 28 | -- This procedure prints a string to an arbitrary position within 29 | -- the VGA text-mode buffer. 30 | ---------------------------------------------------------------------------- 31 | procedure Put_String ( 32 | X : Col; 33 | Y : Row; 34 | Fg : Color; 35 | Bg : Color; 36 | S : String 37 | ); 38 | 39 | ---------------------------------------------------------------------------- 40 | -- Clear 41 | -- 42 | -- Purpose: 43 | -- This procedure clears the VGA text-mode buffer. 44 | -- Calling this function will clear the screen, filling it with the 45 | -- specified background colour. 46 | ---------------------------------------------------------------------------- 47 | procedure Clear ( 48 | Bg : Color 49 | ); 50 | 51 | private 52 | ---------------------------------------------------------------------------- 53 | -- The address of the VGA memory buffer. 54 | ---------------------------------------------------------------------------- 55 | VGA_MEMORY_ADDRESS : constant Integer_Address := 16#FF400000#; 56 | 57 | ---------------------------------------------------------------------------- 58 | -- Put_Char 59 | -- 60 | -- Purpose: 61 | -- This procedure prints a character to an arbitrary position within 62 | -- the VGA text-mode buffer. 63 | -- Exceptions: 64 | -- None. 65 | ---------------------------------------------------------------------------- 66 | procedure Put_Char ( 67 | X : Col; 68 | Y : Row; 69 | Fg : Color; 70 | Bg : Color; 71 | Ch : Character 72 | ); 73 | 74 | ---------------------------------------------------------------------------- 75 | -- The actual VGA screen buffer memory. 76 | ---------------------------------------------------------------------------- 77 | Vga_Output_Buffer : Vga_Buffer 78 | with Import, 79 | Convention => Ada, 80 | Address => To_Address (VGA_MEMORY_ADDRESS), 81 | Volatile; 82 | 83 | end Cxos.Devices.Graphics.Vga; 84 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-devices-pci-print.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.DEVICES.PCI.PRINT 14 | -- 15 | -- Purpose: 16 | -- This package contains code for printing information about PCI devices. 17 | ------------------------------------------------------------------------------- 18 | private package Cxos.Devices.PCI.Print is 19 | pragma Preelaborate; 20 | 21 | ---------------------------------------------------------------------------- 22 | -- Print_Pci_Device 23 | -- 24 | -- Purpose: 25 | -- This procedure prints information about a PCI device record. 26 | ---------------------------------------------------------------------------- 27 | procedure Print_PCI_Device ( 28 | Device : PCI_Device_T 29 | ); 30 | 31 | end Cxos.Devices.PCI.Print; 32 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-devices-storage-atapi.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.DEVICES.STORAGE.ATAPI 14 | -- 15 | -- Purpose: 16 | -- This package contains definitons and functionality for working with 17 | -- ATA devices implementing the packet interface. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Devices.Storage.ATAPI is 20 | pragma Preelaborate; 21 | end Cxos.Devices.Storage.ATAPI; 22 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-devices.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Characters.Latin_1; 13 | with Cxos.Error_Handling; 14 | with Cxos.Devices.Storage.ATA; use Cxos.Devices.Storage.ATA; 15 | 16 | package body Cxos.Devices is 17 | package Chars renames Ada.Characters.Latin_1; 18 | 19 | -- Error handler shorthand. 20 | procedure Log_Error (Message : String) 21 | renames Cxos.Error_Handling.Log_Kernel_Error; 22 | 23 | ---------------------------------------------------------------------------- 24 | -- Initialise 25 | ---------------------------------------------------------------------------- 26 | procedure Initialise is 27 | Status : Cxos.Devices.Storage.ATA.Program_Status; 28 | begin 29 | Cxos.Devices.Storage.ATA.Find_ATA_Devices (Status); 30 | if Status /= Success then 31 | Log_Error ("Error finding ATA devices" & Chars.LF); 32 | end if; 33 | exception 34 | when Constraint_Error => 35 | return; 36 | end Initialise; 37 | 38 | end Cxos.Devices; 39 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-error_handling.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Characters.Latin_1; 13 | with Cxos.Debug; 14 | 15 | package body Cxos.Error_Handling is 16 | package Chars renames Ada.Characters.Latin_1; 17 | 18 | ---------------------------------------------------------------------------- 19 | -- Last_Chance_Handler 20 | ---------------------------------------------------------------------------- 21 | procedure Last_Chance_Handler ( 22 | Msg : System.Address; 23 | Line : Integer 24 | ) is 25 | begin 26 | null; 27 | end Last_Chance_Handler; 28 | 29 | ---------------------------------------------------------------------------- 30 | -- Log_Kernel_Error 31 | ---------------------------------------------------------------------------- 32 | procedure Log_Kernel_Error ( 33 | Message : String 34 | ) is 35 | begin 36 | if DEBUG_PRINT_ERRORS then 37 | Cxos.Debug.Put_String (Message & Chars.LF); 38 | end if; 39 | end Log_Kernel_Error; 40 | end Cxos.Error_Handling; 41 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-exceptions-testing.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.EXCEPTIONS.TESTING 14 | -- 15 | -- Purpose: 16 | -- This package contains code for testing handling of x86 processor 17 | -- exceptions. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Exceptions.Testing is 20 | pragma Preelaborate; 21 | 22 | ---------------------------------------------------------------------------- 23 | -- Test_Divide_By_Zero 24 | -- 25 | -- Purpose: 26 | -- This procedure triggers a processor divide-by-zero exception. 27 | -- Exceptions: 28 | -- None. 29 | ---------------------------------------------------------------------------- 30 | procedure Test_Divide_By_Zero 31 | with Import, 32 | Convention => Assembler, 33 | External_Name => "__test_div0"; 34 | 35 | end Cxos.Exceptions.Testing; 36 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-exceptions-testing_func.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Test DIV0 exception 3 | # 4 | # Triggers a divide-by-0 processor exception. 5 | ##################################################################### 6 | .global __test_div0 7 | .type __test_div0, @function 8 | __test_div0: 9 | movl $0, %eax 10 | movl $0, %ecx 11 | idiv %ecx 12 | ret 13 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-filesystems-fat-print.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; 13 | with Cxos.Debug; 14 | with Cxos.Error_Handling; 15 | 16 | package body Cxos.Filesystems.FAT.Print is 17 | package Chars renames Ada.Characters.Latin_1; 18 | procedure Debug_Print (Data : String) renames Cxos.Debug.Put_String; 19 | -- Error logging function shorthand. 20 | procedure Log_Error (Message : String) 21 | renames Cxos.Error_Handling.Log_Kernel_Error; 22 | 23 | ---------------------------------------------------------------------------- 24 | -- Print_Filesystem_Info 25 | ---------------------------------------------------------------------------- 26 | procedure Print_Filesystem_Info (Boot_Sector : Boot_Sector_T) is 27 | -- The extended BIOS parameter block, if the filesystem is FAT12/16. 28 | EBPB : Extended_BIOS_Parameter_Block 29 | with Import, 30 | Convention => Ada, 31 | Address => Boot_Sector.BPB_Buffer'Address; 32 | 33 | -- The type of this FAT filesystem. 34 | Filesystem_Type : FAT_Type_T := FAT12; 35 | -- The status of internal operations. 36 | Status : Program_Status; 37 | begin 38 | Get_Filesystem_Type (Boot_Sector, Filesystem_Type, Status); 39 | if Status /= Success then 40 | Log_Error ("Error getting FAT device filesystem type" & Chars.LF); 41 | return; 42 | end if; 43 | 44 | Debug_Print ("FAT Filesystem:" & Chars.LF); 45 | 46 | Debug_Print (" FAT type: "); 47 | case Filesystem_Type is 48 | when FAT12 => 49 | Debug_Print ("FAT12"); 50 | when FAT16 => 51 | Debug_Print ("FAT16"); 52 | when FAT32 => 53 | Debug_Print ("FAT32"); 54 | when ExFAT => 55 | Debug_Print ("ExFAT"); 56 | end case; 57 | Debug_Print ("" & Chars.LF); 58 | 59 | Debug_Print (" Boot Jump Bytes: "); 60 | for I in Natural range 1 .. 3 loop 61 | Debug_Print ("" & Boot_Sector.Boot_Jump (I)'Image); 62 | end loop; 63 | Debug_Print ("" & Chars.LF); 64 | 65 | Debug_Print (" OEM name: "); 66 | for I in Natural range 1 .. 8 loop 67 | Debug_Print ("" & Boot_Sector.OEM_Name (I)); 68 | end loop; 69 | Debug_Print ("" & Chars.LF); 70 | 71 | Debug_Print (" Bytes_Per_Sector: " & 72 | EBPB.BPB.Bytes_Per_Sector'Image & Chars.LF); 73 | Debug_Print (" Sectors_Per_Cluster: " & 74 | EBPB.BPB.Sectors_Per_Cluster'Image & Chars.LF); 75 | Debug_Print (" Reserved_Sector_Count: " & 76 | EBPB.BPB.Reserved_Sector_Count'Image & Chars.LF); 77 | Debug_Print (" Table_Count: " & 78 | EBPB.BPB.Table_Count'Image & Chars.LF); 79 | Debug_Print (" Root_Entry_Count: " & 80 | EBPB.BPB.Root_Entry_Count'Image & Chars.LF); 81 | Debug_Print (" Total_Sector_Count: " & 82 | EBPB.BPB.Total_Sector_Count'Image & Chars.LF); 83 | Debug_Print (" Table_Size: " & 84 | EBPB.BPB.Table_Size'Image & Chars.LF); 85 | Debug_Print (" Media_Type: " & 86 | EBPB.BPB.Media_Type'Image & Chars.LF); 87 | Debug_Print (" Sectors_Per_Track: " & 88 | EBPB.BPB.Sectors_Per_Track'Image & Chars.LF); 89 | Debug_Print (" Head_Side_Count: " & 90 | EBPB.BPB.Head_Side_Count'Image & Chars.LF); 91 | Debug_Print (" Hidden_Sector_Count: " & 92 | EBPB.BPB.Hidden_Sector_Count'Image & Chars.LF); 93 | Debug_Print (" Large_Sector_Count: " & 94 | EBPB.BPB.Large_Sector_Count'Image & Chars.LF); 95 | 96 | Debug_Print ("------------------------" & Chars.LF); 97 | exception 98 | when Constraint_Error => 99 | return; 100 | end Print_Filesystem_Info; 101 | 102 | end Cxos.Filesystems.FAT.Print; 103 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-filesystems-fat-print.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.FILESYSTEMS.FAT.PRINT 14 | -- 15 | -- Purpose: 16 | -- This package contains functionality for printing information about 17 | -- a particular FAT filesystem. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Filesystems.FAT.Print is 20 | pragma Preelaborate; 21 | 22 | ---------------------------------------------------------------------------- 23 | -- Print_Filesystem_Info 24 | -- 25 | -- Purpose: 26 | -- Prints information about a FAT formatted device. 27 | ---------------------------------------------------------------------------- 28 | procedure Print_Filesystem_Info (Boot_Sector : Boot_Sector_T); 29 | 30 | end Cxos.Filesystems.FAT.Print; 31 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-gdt-load.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2019, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .section .text 13 | 14 | ##################################################################### 15 | # GDT Load 16 | # 17 | # Instructs the processor on the location of the Global Descriptor 18 | # Table. 19 | ##################################################################### 20 | .global cxos_gdt_load 21 | .type cxos_gdt_load, @function 22 | cxos_gdt_load: 23 | lgdt gdt_pointer 24 | ret 25 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-gdt.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System; 13 | with System.Storage_Elements; use System.Storage_Elements; 14 | with x86.Descriptors; use x86.Descriptors; 15 | with x86.GDT; use x86.GDT; 16 | 17 | ------------------------------------------------------------------------------- 18 | -- CXOS.GDT 19 | -- 20 | -- Purpose: 21 | -- This package contains code for initialising the Global Descriptor Table. 22 | -- The initialisation procedure within is called by the system init code. 23 | ------------------------------------------------------------------------------- 24 | package Cxos.GDT is 25 | pragma Preelaborate; 26 | 27 | ---------------------------------------------------------------------------- 28 | -- Finalise 29 | -- 30 | -- Purpose: 31 | -- This procedure finalises the initialisation of the GDT. 32 | -- This function initiates the loading of the global descriptor table. 33 | -- Exceptions: 34 | -- None. 35 | ---------------------------------------------------------------------------- 36 | procedure Finalise 37 | with Import, 38 | Convention => Assembler, 39 | External_Name => "cxos_gdt_load"; 40 | 41 | ---------------------------------------------------------------------------- 42 | -- Initialise 43 | -- 44 | -- Purpose: 45 | -- This procedure initialises the x86 platform's Global Descriptor Table. 46 | -- Exceptions: 47 | -- None. 48 | ---------------------------------------------------------------------------- 49 | procedure Initialise; 50 | 51 | private 52 | ---------------------------------------------------------------------------- 53 | -- Install_Descriptor 54 | -- 55 | -- Purpose: 56 | -- This procedure creates an individual descriptor entry in the x86 57 | -- platform's Global Descriptor Table. 58 | -- Exceptions: 59 | -- None. 60 | ---------------------------------------------------------------------------- 61 | procedure Install_Descriptor ( 62 | Index : Descriptor_Entry_Range; 63 | Base_Addr : System.Address := To_Address (0); 64 | Limit_Addr : System.Address := To_Address (0); 65 | Privilege : Descriptor_Privilege_Level := Ring_0; 66 | Entry_Type : Segment_Type := None 67 | ); 68 | 69 | ---------------------------------------------------------------------------- 70 | -- The number of entries in the Global Descriptor Table. 71 | -- Room for this number of entries is statically allocated. 72 | ---------------------------------------------------------------------------- 73 | GDT_LENGTH : constant := 16; 74 | 75 | ---------------------------------------------------------------------------- 76 | -- The actual global descriptor table entity. 77 | -- The length of the entries is statically allocated. 78 | ---------------------------------------------------------------------------- 79 | Global_Descriptor_Table : 80 | Global_Descriptor_Table_T (0 .. (GDT_LENGTH - 1)) := (others => 81 | ( 82 | Limit_Low => 0, 83 | Base_Low => 0, 84 | Base_Mid => 0, 85 | Descriptor_Type => ( 86 | A => False, 87 | W_R => False, 88 | E_C => False, 89 | Field_Type => False 90 | ), 91 | S => False, 92 | DPL => Ring_0, 93 | P => False, 94 | Limit_High => 0, 95 | AVL => False, 96 | L => False, 97 | DB => False, 98 | G => False, 99 | Base_High => 0 100 | )) 101 | with Alignment => 16, 102 | Export, 103 | Convention => Assembler, 104 | External_Name => "global_descriptor_table", 105 | Volatile; 106 | 107 | ---------------------------------------------------------------------------- 108 | -- The pointer to the GDT needed by the processor to load the GDT. 109 | ---------------------------------------------------------------------------- 110 | GDT_Ptr : System_Table_Descriptor 111 | with Export, 112 | Convention => Assembler, 113 | External_Name => "gdt_pointer", 114 | Volatile; 115 | 116 | end Cxos.GDT; 117 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-idt-load.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2019, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .section .text 13 | 14 | ##################################################################### 15 | # IDT Load 16 | # 17 | # Instructs the processor on the location of the Interrupt 18 | # Descriptor Table. 19 | ##################################################################### 20 | .global cxos_idt_load 21 | .type cxos_idt_load, @function 22 | cxos_idt_load: 23 | lidt idt_pointer 24 | ret 25 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-idt.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System.Storage_Elements; use System.Storage_Elements; 13 | 14 | package body Cxos.IDT is 15 | ---------------------------------------------------------------------------- 16 | -- Initialise 17 | ---------------------------------------------------------------------------- 18 | procedure Initialise is 19 | begin 20 | -- Initialise all IDT Entries. 21 | Initialise_Loop : 22 | for I in Descriptor_Entry_Range range 0 .. IDT_LENGTH loop 23 | Initialise_Descriptor (I); 24 | end loop Initialise_Loop; 25 | 26 | -- Initialise the IDT pointer. 27 | IDT_Ptr.Size := Interrupt_Descriptor_Table'Size - 1; 28 | IDT_Ptr.Offset := Interrupt_Descriptor_Table'Address; 29 | exception 30 | when Constraint_Error => 31 | null; 32 | end Initialise; 33 | 34 | ---------------------------------------------------------------------------- 35 | -- Initialise_Descriptor 36 | -- 37 | -- Implementation Notes: 38 | -- - Zeroes out an individual descriptor entry. 39 | ---------------------------------------------------------------------------- 40 | procedure Initialise_Descriptor ( 41 | Index : Descriptor_Entry_Range 42 | ) is 43 | begin 44 | Interrupt_Descriptor_Table (Index) := ( 45 | Offset_Low => 0, 46 | Selector => 0, 47 | Reserved => 0, 48 | Descriptor_Type => None, 49 | S => False, 50 | DPL => Ring_0, 51 | P => False, 52 | Offset_High => 0 53 | ); 54 | 55 | exception 56 | when Constraint_Error => 57 | return; 58 | end Initialise_Descriptor; 59 | 60 | ---------------------------------------------------------------------------- 61 | -- Install_Descriptor 62 | ---------------------------------------------------------------------------- 63 | procedure Install_Descriptor ( 64 | Index : Descriptor_Entry_Range; 65 | Offset_Addr : System.Address; 66 | Selector : Unsigned_16; 67 | Privilege : Descriptor_Privilege_Level := Ring_0 68 | ) is 69 | begin 70 | -- Set the descriptor's offset fields. 71 | -- If an overflow occurs here the procedure will exit. 72 | Set_Descriptor_Offset : 73 | declare 74 | Offset : constant Unsigned_32 := 75 | Unsigned_32 (To_Integer (Offset_Addr)); 76 | begin 77 | Interrupt_Descriptor_Table (Index).Offset_Low := 78 | Unsigned_16 (Offset and 16#FFFF#); 79 | Interrupt_Descriptor_Table (Index).Offset_High := 80 | Unsigned_16 (Shift_Right (Offset, 16) and 16#FFFF#); 81 | exception 82 | when Constraint_Error => 83 | return; 84 | end Set_Descriptor_Offset; 85 | 86 | Interrupt_Descriptor_Table (Index).Selector := Selector; 87 | Interrupt_Descriptor_Table (Index).Descriptor_Type 88 | := Interrupt_Gate_32_Bit; 89 | Interrupt_Descriptor_Table (Index).Reserved := 0; 90 | Interrupt_Descriptor_Table (Index).S := False; 91 | Interrupt_Descriptor_Table (Index).DPL := Privilege; 92 | Interrupt_Descriptor_Table (Index).P := True; 93 | 94 | exception 95 | when Constraint_Error => 96 | return; 97 | end Install_Descriptor; 98 | end Cxos.IDT; 99 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-idt.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with System; 14 | with x86.Descriptors; use x86.Descriptors; 15 | with x86.IDT; use x86.IDT; 16 | 17 | ------------------------------------------------------------------------------- 18 | -- CXOS.IDT 19 | -- 20 | -- Purpose: 21 | -- This package contains code for initialising the Interrupt Descriptor 22 | -- Table. The initialisation procedure within is called by the system 23 | -- init code. 24 | ------------------------------------------------------------------------------- 25 | package Cxos.IDT is 26 | pragma Preelaborate; 27 | 28 | ---------------------------------------------------------------------------- 29 | -- Finalise 30 | -- 31 | -- Purpose: 32 | -- This procedure loads the IDT into the processor register. 33 | -- Exceptions: 34 | -- None. 35 | ---------------------------------------------------------------------------- 36 | procedure Finalise 37 | with Import, 38 | Convention => Assembler, 39 | External_Name => "cxos_idt_load"; 40 | 41 | ---------------------------------------------------------------------------- 42 | -- Initialise 43 | -- 44 | -- Purpose: 45 | -- This procedure initialises the x86 platform's Interrupt 46 | -- Descriptor Table. 47 | -- Exceptions: 48 | -- None. 49 | ---------------------------------------------------------------------------- 50 | procedure Initialise; 51 | 52 | ---------------------------------------------------------------------------- 53 | -- Install_Descriptor 54 | -- 55 | -- Purpose: 56 | -- This procedure creates an individual descriptor entry in the x86 57 | -- platform's Interrupt Descriptor Table. 58 | -- Exceptions: 59 | -- None. 60 | ---------------------------------------------------------------------------- 61 | procedure Install_Descriptor ( 62 | Index : Descriptor_Entry_Range; 63 | Offset_Addr : System.Address; 64 | Selector : Unsigned_16; 65 | Privilege : Descriptor_Privilege_Level := Ring_0 66 | ); 67 | 68 | private 69 | ---------------------------------------------------------------------------- 70 | -- Initialise_Descriptor 71 | -- 72 | -- Purpose: 73 | -- This initialises a descriptor entry. It creates an unused descriptor 74 | -- entry at an arbitrary position in the IDT. 75 | -- Exceptions: 76 | -- None. 77 | ---------------------------------------------------------------------------- 78 | procedure Initialise_Descriptor ( 79 | Index : Descriptor_Entry_Range 80 | ); 81 | 82 | ---------------------------------------------------------------------------- 83 | -- The number of entries in the Global Descriptor Table. 84 | -- Room for this number of entries is statically allocated. 85 | ---------------------------------------------------------------------------- 86 | IDT_LENGTH : constant := 256; 87 | 88 | ---------------------------------------------------------------------------- 89 | -- The actual Interrupt descriptor table entity. 90 | -- The length of the entries is statically allocated. 91 | ---------------------------------------------------------------------------- 92 | Interrupt_Descriptor_Table : 93 | Interrupt_Descriptor_Table_T (0 .. (IDT_LENGTH - 1)) 94 | with Alignment => 8, 95 | Export, 96 | Convention => Assembler, 97 | External_Name => "interrupt_descriptor_table", 98 | Volatile; 99 | 100 | ---------------------------------------------------------------------------- 101 | -- The pointer to the IDT needed by the processor to load the IDT. 102 | ---------------------------------------------------------------------------- 103 | IDT_Ptr : System_Table_Descriptor 104 | with Export, 105 | Convention => Assembler, 106 | External_Name => "idt_pointer", 107 | Volatile; 108 | end Cxos.IDT; 109 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-interrupts.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Cxos.IRQ_Handlers; 13 | with Cxos.IDT; 14 | with Cxos.PIC; 15 | with x86.Interrupts.Names; 16 | with System.Machine_Code; 17 | 18 | package body Cxos.Interrupts is 19 | use x86.Interrupts.Names; 20 | 21 | ---------------------------------------------------------------------------- 22 | -- Initialise 23 | ---------------------------------------------------------------------------- 24 | function Initialise return Process_Result is 25 | begin 26 | -- Install a handler for IRQ0. 27 | Cxos.PIC.Set_Interrupt_Mask (IRQ0, False); 28 | Cxos.IDT.Install_Descriptor (32, 29 | Cxos.IRQ_Handlers.IRQ0_Handler'Address, 16#8#); 30 | 31 | -- Install a handler for IRQ1. 32 | Cxos.PIC.Set_Interrupt_Mask (IRQ1, False); 33 | Cxos.IDT.Install_Descriptor (33, 34 | Cxos.IRQ_Handlers.IRQ1_Handler'Address, 16#8#); 35 | 36 | return Success; 37 | end Initialise; 38 | 39 | ---------------------------------------------------------------------------- 40 | -- Set_Interrupt_Flag 41 | ---------------------------------------------------------------------------- 42 | procedure Set_Interrupt_Flag ( 43 | Status : Boolean 44 | ) is 45 | begin 46 | case Status is 47 | when True => 48 | System.Machine_Code.Asm ( 49 | Template => "sti", 50 | Volatile => True); 51 | when False => 52 | System.Machine_Code.Asm ( 53 | Template => "cli", 54 | Volatile => True); 55 | end case; 56 | exception 57 | when Constraint_Error => 58 | return; 59 | end Set_Interrupt_Flag; 60 | end Cxos.Interrupts; 61 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-interrupts.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | ------------------------------------------------------------------------------- 13 | -- CXOS.INTERRUPTS 14 | -- 15 | -- Purpose: 16 | -- This package contains code and definitions for setting and working with 17 | -- interrupts. 18 | ------------------------------------------------------------------------------- 19 | package Cxos.Interrupts is 20 | pragma Preelaborate; 21 | 22 | ---------------------------------------------------------------------------- 23 | -- Process Result type. 24 | -- Used for tracking the results of package processes and reporting 25 | -- specific errors to the caller. 26 | ---------------------------------------------------------------------------- 27 | type Process_Result is ( 28 | Failure, 29 | Success 30 | ); 31 | 32 | ---------------------------------------------------------------------------- 33 | -- Initialise 34 | -- 35 | -- Purpose: 36 | -- This procedure initialises interrupt handlers for the kernel. 37 | -- Exceptions: 38 | -- None. 39 | ---------------------------------------------------------------------------- 40 | function Initialise return Process_Result; 41 | 42 | ---------------------------------------------------------------------------- 43 | -- Set_Interrupt_Flag 44 | -- 45 | -- Purpose: 46 | -- Sets or clears the interrupt flag in the processor EFLAGS register. 47 | -- If this is set to true, the processor begins responding to external 48 | -- maskable interrupts. Otherwise all maskable interrupts are ignored. 49 | -- Exceptions: 50 | -- None. 51 | ---------------------------------------------------------------------------- 52 | procedure Set_Interrupt_Flag ( 53 | Status : Boolean 54 | ); 55 | end Cxos.Interrupts; 56 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-memory-get_stack_top.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2019, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .section .text 13 | 14 | ##################################################################### 15 | # Get stack top 16 | # 17 | # Returns a pointer to the currently loaded process' stack top. 18 | ##################################################################### 19 | .global cxos_memory_get_stack_top 20 | .type cxos_memory_get_stack_top, @function 21 | cxos_memory_get_stack_top: 22 | movl %esp, %eax # Move ESP into EAX. 23 | ret 24 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-memory-paging-flush_tlb.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2019, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .section .text 13 | 14 | 15 | ##################################################################### 16 | # Flush_Tlb 17 | # 18 | # Reloads the Translation Lookaside Buffer. 19 | ##################################################################### 20 | .global cxos_memory_paging_flush_tlb 21 | .type cxos_memory_paging_flush_tlb, @function 22 | cxos_memory_paging_flush_tlb: 23 | movl %cr3, %eax 24 | movl %eax, %cr3 25 | 26 | ret 27 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-memory.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | package body Cxos.Memory is 13 | ---------------------------------------------------------------------------- 14 | -- Allocate_Kernel_Memory 15 | ---------------------------------------------------------------------------- 16 | procedure Allocate_Kernel_Memory ( 17 | Size : Positive; 18 | Addr : out System.Address; 19 | Status : out Process_Result 20 | ) is 21 | begin 22 | Addr := System.Null_Address; 23 | 24 | pragma Unreferenced (Size); 25 | 26 | Status := Success; 27 | end Allocate_Kernel_Memory; 28 | 29 | end Cxos.Memory; 30 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-memory.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- CXOS.MEMORY 16 | -- 17 | -- Purpose: 18 | -- This package contains code and defintions for working with memory. 19 | ------------------------------------------------------------------------------- 20 | package Cxos.Memory is 21 | pragma Preelaborate; 22 | 23 | ---------------------------------------------------------------------------- 24 | -- Process Result type. 25 | -- Used for storing and returning the result of an internal memory related 26 | -- procedure. 27 | ---------------------------------------------------------------------------- 28 | type Process_Result is ( 29 | Frame_Allocation_Error, 30 | Frame_Not_Allocated, 31 | Invalid_Argument, 32 | Invalid_Non_Aligned_Address, 33 | Invalid_Page_Directory, 34 | Invalid_Table_Index, 35 | Invalid_Value, 36 | Invalid_Address_Argument, 37 | Invalid_Index_Argument, 38 | No_Free_Frames, 39 | Memory_Map_Not_Present, 40 | Success, 41 | Unhandled_Exception, 42 | Unset 43 | ); 44 | 45 | ---------------------------------------------------------------------------- 46 | -- Get_Stack_Top 47 | -- 48 | -- Purpose: 49 | -- This function returns a pointer to the currently loaded task's stack 50 | -- top in virtual memory. 51 | ---------------------------------------------------------------------------- 52 | function Get_Stack_Top return System.Address 53 | with Import, 54 | Convention => Assembler, 55 | External_Name => "cxos_memory_get_stack_top"; 56 | 57 | ---------------------------------------------------------------------------- 58 | -- Allocate_Kernel_Memory 59 | ---------------------------------------------------------------------------- 60 | procedure Allocate_Kernel_Memory ( 61 | Size : Positive; 62 | Addr : out System.Address; 63 | Status : out Process_Result 64 | ); 65 | 66 | private 67 | ---------------------------------------------------------------------------- 68 | -- The size of the kernel stack, in bytes. 69 | ---------------------------------------------------------------------------- 70 | KERNEL_STACK_SIZE : constant := 16#4000#; 71 | 72 | ---------------------------------------------------------------------------- 73 | -- The size of the kernel secondary stack, in bytes. 74 | ---------------------------------------------------------------------------- 75 | KERNEL_SECONDARY_STACK_SIZE : constant := 16#4000#; 76 | 77 | end Cxos.Memory; 78 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-pic.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Ada.Interrupts; use Ada.Interrupts; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- CXOS.DEVICES.PIC 16 | -- 17 | -- Purpose: 18 | -- This package contains code for working with the x86 8259A programmable 19 | -- interrupt controller. 20 | ------------------------------------------------------------------------------- 21 | package Cxos.PIC is 22 | pragma Preelaborate; 23 | 24 | ---------------------------------------------------------------------------- 25 | -- Initialise 26 | -- 27 | -- Purpose: 28 | -- This procedure initialises the x86 PIC. 29 | -- Exceptions: 30 | -- None. 31 | ---------------------------------------------------------------------------- 32 | procedure Initialise; 33 | 34 | ---------------------------------------------------------------------------- 35 | -- Send_EOI 36 | -- 37 | -- Purpose: 38 | -- This function sends an EOI signal to the PIC controller. 39 | -- Exceptions: 40 | -- None. 41 | ---------------------------------------------------------------------------- 42 | procedure Send_EOI ( 43 | IRQ : Interrupt_ID 44 | ); 45 | 46 | ---------------------------------------------------------------------------- 47 | -- Set_Interrupt_Mask 48 | -- 49 | -- Purpose: 50 | -- Sets the mask status of an individual interrupt. 51 | -- Exceptions: 52 | -- None. 53 | ---------------------------------------------------------------------------- 54 | procedure Set_Interrupt_Mask ( 55 | IRQ : Interrupt_ID; 56 | Status : Boolean 57 | ); 58 | 59 | end Cxos.PIC; 60 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-pit.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System; 13 | with x86.Port_IO; use x86.Port_IO; 14 | 15 | package body Cxos.PIT is 16 | ---------------------------------------------------------------------------- 17 | -- Initialise 18 | -- 19 | -- Implementation Notes: 20 | -- - Only initialises Channel 0. 21 | ---------------------------------------------------------------------------- 22 | procedure Initialise is 23 | -- The predefined initial value to select for a 100hz rate. 24 | INITIAL_VALUE_100HZ : constant Unsigned_16 := 11931; 25 | begin 26 | -- Initialise Channel 0 to pulse at 100hz, using operating mode 2, 27 | -- raising an interrupt every 10ms. 28 | Initialise_Channel (Channel_0, Rate_Generator, INITIAL_VALUE_100HZ); 29 | end Initialise; 30 | 31 | ---------------------------------------------------------------------------- 32 | -- Initialise_Channel 33 | -- 34 | -- Implementation Notes: 35 | -- - Ensure that interrupt IRQ0 is masked before setting this to avoid 36 | -- any race conditions in different threads, if applicable. 37 | ---------------------------------------------------------------------------- 38 | procedure Initialise_Channel ( 39 | Channel : PIT_Channel_T; 40 | Operating_Mode : Operating_Mode_Type; 41 | Initial_Value : Unsigned_16 42 | ) is 43 | Channel_Address : System.Address; 44 | Command_Address : System.Address; 45 | Command_Data : Mode_Select_Register; 46 | begin 47 | if not Operating_Mode'Valid then 48 | return; 49 | end if; 50 | 51 | -- Get the register address for the selected PIT channel. 52 | Get_Channel_Register_Address : 53 | declare 54 | Channel_Register : PIT_Register_T; 55 | begin 56 | case Channel is 57 | when Channel_0 => 58 | Channel_Register := Channel_0_Data; 59 | when Channel_1 => 60 | Channel_Register := Channel_1_Data; 61 | when Channel_2 => 62 | Channel_Register := Channel_2_Data; 63 | end case; 64 | 65 | Command_Address := Get_Register_Address (Command); 66 | Channel_Address := Get_Register_Address (Channel_Register); 67 | exception 68 | when Constraint_Error => 69 | return; 70 | end Get_Channel_Register_Address; 71 | 72 | -- Select the channel the command is for. 73 | Set_Command_Channel : 74 | begin 75 | case Channel is 76 | when Channel_0 => 77 | Command_Data.Channel_Select := Channel_0; 78 | when Channel_1 => 79 | Command_Data.Channel_Select := Channel_1; 80 | when Channel_2 => 81 | Command_Data.Channel_Select := Channel_2; 82 | end case; 83 | exception 84 | when Constraint_Error => 85 | return; 86 | end Set_Command_Channel; 87 | 88 | -- Set the channel operating mode. 89 | Set_Operating_Mode : 90 | begin 91 | Command_Data.Operating_Mode := Operating_Mode; 92 | exception 93 | when Constraint_Error => 94 | return; 95 | end Set_Operating_Mode; 96 | 97 | -- Binary mode is always 16bit in x86. 98 | Command_Data.Binary_Mode := Binary_16_Bit; 99 | 100 | -- Set the access value to prepare the PIT to receive the data. 101 | Command_Data.Port_Access := Low_High_Byte; 102 | 103 | -- Write the command data to prepare the channel to receive the 104 | -- low/high bytes of the initial value. 105 | Outb (Command_Address, Mode_Select_Register_To_Byte (Command_Data)); 106 | 107 | -- Write the initial value, low byte first. 108 | Write_Initial_Value : 109 | declare 110 | Low_Byte : Unsigned_8; 111 | High_Byte : Unsigned_8; 112 | begin 113 | Low_Byte := Unsigned_8 (Initial_Value and 16#FF#); 114 | High_Byte := Unsigned_8 ( 115 | Shift_Left (Initial_Value and 16#FF00#, 8)); 116 | 117 | Outb (Channel_Address, Low_Byte); 118 | Outb (Channel_Address, High_Byte); 119 | exception 120 | when Constraint_Error => 121 | return; 122 | end Write_Initial_Value; 123 | end Initialise_Channel; 124 | end Cxos.PIT; 125 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-pit.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with x86.PIT; use x86.PIT; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- CXOS.PIT 17 | -- 18 | -- Purpose: 19 | -- This package contains code for working with the x86 8253/8254 20 | -- Programmable Interval Timer. 21 | ------------------------------------------------------------------------------- 22 | package Cxos.PIT is 23 | pragma Preelaborate; 24 | 25 | ---------------------------------------------------------------------------- 26 | -- Initialise 27 | -- 28 | -- Purpose: 29 | -- This procedure initialises the x86 PIT. 30 | -- Exceptions: 31 | -- None. 32 | ---------------------------------------------------------------------------- 33 | procedure Initialise; 34 | 35 | private 36 | ---------------------------------------------------------------------------- 37 | -- Initialise_Channel 38 | -- 39 | -- Purpose: 40 | -- This procedure initialises an individual PIT channel. This sets the 41 | -- initial value for the channel as well as its operating mode. 42 | -- Exceptions: 43 | -- None. 44 | ---------------------------------------------------------------------------- 45 | procedure Initialise_Channel ( 46 | Channel : PIT_Channel_T; 47 | Operating_Mode : Operating_Mode_Type; 48 | Initial_Value : Unsigned_16 49 | ); 50 | 51 | end Cxos.PIT; 52 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-tasking-switch.S: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2019, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .section .text 13 | 14 | .type cxos_tasking_save_process_state, @function 15 | .global cxos_tasking_save_process_state 16 | cxos_tasking_save_process_state: 17 | pushl %ebp 18 | movl %esp, %ebp 19 | 20 | pushl %esi # Preserve ESI. 21 | 22 | movl 8(%ebp), %esi # The address of the process block. 23 | 24 | pushl %eax # Preserve EAX. 25 | movl %cr3, %eax 26 | movl %eax, 8(%esi) 27 | 28 | popl %eax # Restore EAX. 29 | movl %ebx, 16(%esi) 30 | movl %ecx, 20(%esi) 31 | movl %edx, 24(%esi) 32 | movl %edi, 28(%esi) 33 | 34 | movl %esi, %edi 35 | popl %esi # Restore ESI. 36 | movl %esi, 32(%edi) 37 | 38 | movl %ebp, 36(%edi) 39 | 40 | movl %ebp, %esp 41 | popl %ebp 42 | 43 | movl %esp, 4(%edi) 44 | 45 | ret 46 | 47 | 48 | ##################################################################### 49 | # Load process 50 | # 51 | # Switches to the provided process. 52 | ##################################################################### 53 | .type cxos_tasking_load_process, @function 54 | .global cxos_tasking_load_process 55 | cxos_tasking_load_process: 56 | pushl %ebp 57 | movl %esp, %ebp 58 | 59 | movl 8(%ebp), %esi # The address of the process block. 60 | movl 4(%esi), %eax # Move next task's ESP to EAX. 61 | movl 8(%esi), %ebx # Move next task's CR3 to EBX. 62 | 63 | movl %ebx, %cr3 # Load new address space. 64 | movl %eax, %esp 65 | 66 | popl %ebp 67 | ret 68 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-time_keeping.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | package body Cxos.Time_Keeping is 13 | ---------------------------------------------------------------------------- 14 | -- Clock 15 | ---------------------------------------------------------------------------- 16 | function Clock return Time is 17 | begin 18 | return System_Time; 19 | end Clock; 20 | 21 | ---------------------------------------------------------------------------- 22 | -- Initialise 23 | -- 24 | -- Implementation Notes: 25 | -- - Sets the system internal clock to 0. 26 | ---------------------------------------------------------------------------- 27 | procedure Initialise is 28 | begin 29 | System_Time := 0; 30 | end Initialise; 31 | 32 | ---------------------------------------------------------------------------- 33 | -- System_Tick_Handler 34 | -- 35 | -- Implementation Notes: 36 | -- - Handles an individual system 'tick' generated by the system's 37 | -- Programmable Interval Timer. Each call to this function will 38 | -- increment the internal timer by the predefined timer interval. 39 | ---------------------------------------------------------------------------- 40 | procedure System_Tick_Handler is 41 | begin 42 | System_Time := System_Time + SYSTEM_TICK_PERIOD; 43 | end System_Tick_Handler; 44 | 45 | end Cxos.Time_Keeping; 46 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/cxos-time_keeping.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | pragma Restrictions (No_Elaboration_Code); 13 | 14 | ------------------------------------------------------------------------------- 15 | -- CXOS.TIME_KEEPING 16 | -- 17 | -- Purpose: 18 | -- This package contains code for working with the system time. 19 | -- Functionality for time keeping is contained within this package. Such as 20 | -- reading the current system clock as well as the functionality for 21 | -- initialising and incrementing the timer. 22 | ------------------------------------------------------------------------------- 23 | package Cxos.Time_Keeping is 24 | pragma Preelaborate; 25 | 26 | ---------------------------------------------------------------------------- 27 | -- Time type. 28 | -- Represents a millisecond count. 29 | ---------------------------------------------------------------------------- 30 | type Time is mod 2 ** 64 31 | with Size => 64; 32 | 33 | ---------------------------------------------------------------------------- 34 | -- Clock 35 | -- 36 | -- Purpose: 37 | -- This function returns the current system time. 38 | -- Exceptions: 39 | -- None. 40 | ---------------------------------------------------------------------------- 41 | function Clock return Time 42 | with Volatile_Function; 43 | 44 | ---------------------------------------------------------------------------- 45 | -- Initialise 46 | -- 47 | -- Purpose: 48 | -- This procedure initialises the system timer. 49 | -- Exceptions: 50 | -- None. 51 | ---------------------------------------------------------------------------- 52 | procedure Initialise; 53 | 54 | ---------------------------------------------------------------------------- 55 | -- System_Tick_Handler 56 | -- 57 | -- Purpose: 58 | -- This procedure handles a tick from the system timer. 59 | -- This is called by the IRQ0 handler, which is triggered by the 60 | -- system's Programmable Interval Timer. 61 | -- Exceptions: 62 | -- None. 63 | ---------------------------------------------------------------------------- 64 | procedure System_Tick_Handler; 65 | 66 | private 67 | ---------------------------------------------------------------------------- 68 | -- This is the period of time, measured in milliseconds, represented by a 69 | -- single processor timer 'tick'. 70 | ---------------------------------------------------------------------------- 71 | SYSTEM_TICK_PERIOD : constant Time := 10; 72 | 73 | ---------------------------------------------------------------------------- 74 | -- This is the system's internal time. 75 | ---------------------------------------------------------------------------- 76 | System_Time : Time 77 | with Volatile; 78 | 79 | end Cxos.Time_Keeping; 80 | -------------------------------------------------------------------------------- /src/kernel/src/arch/x86/x86.ld: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2019, CXOS. 3 | * This program is free software; you can redistribute it and/or modify it 4 | * under the terms of the GNU General Public License as published by the 5 | * Free Software Foundation; either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * Authors: 9 | * Anthony 10 | */ 11 | 12 | /** The physical starting address of the kernel. */ 13 | KERNEL_PHYS_START = 0x100000; 14 | /** 15 | * The offset between the physical start and the start of the kernel's 16 | * mapping in virtual memory. 17 | */ 18 | KERNEL_VMA_OFFSET = 0xC0000000; 19 | /** The size of the kernel stack. */ 20 | KERNEL_STACK_SIZE = 0x4000; 21 | /** The size of the kernel secondary stack. */ 22 | KERNEL_SEC_STACK_SIZE = 0x1000; 23 | 24 | ENTRY (_start) 25 | SECTIONS { 26 | . = KERNEL_PHYS_START; 27 | . += KERNEL_VMA_OFFSET; 28 | kernel_start = .; 29 | 30 | .text ALIGN(4K) : AT (ADDR (.text) - KERNEL_VMA_OFFSET) 31 | { 32 | *(.multiboot) 33 | text_start = .; 34 | *(.text*) 35 | text_end = .; 36 | } 37 | 38 | .rodata ALIGN (4K) : AT (ADDR (.rodata) - KERNEL_VMA_OFFSET) 39 | { 40 | rodata_start = .; 41 | *(.rodata*) 42 | rodata_end = .; 43 | } 44 | 45 | .data ALIGN (4K) : AT (ADDR (.data) - KERNEL_VMA_OFFSET) 46 | { 47 | data_start = .; 48 | *(.data*) 49 | data_end = .; 50 | } 51 | 52 | .bss ALIGN (4K) : AT (ADDR (.bss) - KERNEL_VMA_OFFSET) 53 | { 54 | bss_start = .; 55 | *(COMMON) 56 | *(.bss*) 57 | 58 | . = ALIGN (4K); 59 | kernel_stack_bottom = .; 60 | . += KERNEL_STACK_SIZE; 61 | kernel_stack_top = .; 62 | 63 | . = ALIGN (4K); 64 | /** Secondary stack grows upwards, towards higher addresses. **/ 65 | kernel_sec_stack_top = .; 66 | . += KERNEL_SEC_STACK_SIZE; 67 | kernel_sec_stack_bottom = .; 68 | 69 | /** Reserve 1MB for saving any needed multiboot data. */ 70 | . = ALIGN (4K); 71 | multiboot_reserved_start = .; 72 | . += 1M; 73 | multiboot_reserved_end = .; 74 | 75 | /** Boot paging structures. */ 76 | . = ALIGN (4K); 77 | boot_page_directory = .; 78 | . += 0x1000; 79 | boot_page_tables = .; 80 | /** 81 | * Calculate the number of page tables necessary to hold the kernel. 82 | * Skip the amount of space necessary to hold this amount of pages. 83 | */ 84 | . += (1 + ((KERNEL_PHYS_START + kernel_end - kernel_start) / 0x400000)) * 0x1000; 85 | 86 | kernel_stack_table = .; 87 | . += 0x1000; 88 | boot_graphics_table = .; 89 | . += 0x1000; 90 | boot_mapping_table = .; 91 | . += 0x1000; 92 | 93 | bss_end = .; 94 | } 95 | 96 | kernel_end = .; 97 | } 98 | -------------------------------------------------------------------------------- /src/makefile: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2020, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .POSIX: 13 | .DELETE_ON_ERROR: 14 | MAKEFLAGS += --warn-undefined-variables 15 | MAKEFLAGS += --no-builtin-rules 16 | 17 | .PHONY: all clean debug emu runtime kernel 18 | 19 | KERNEL_DIR := kernel 20 | KERNEL_BINARY := ${KERNEL_DIR}/build/cxos.elf 21 | 22 | RUNTIME_DIR := runtime 23 | RUNTIME_BINARY := ${RUNTIME_DIR}/build/adalib/libgnat.a 24 | 25 | ISO_DIR := iso 26 | ISO := ${ISO_DIR}/build/cxos.img 27 | 28 | SERIAL_FILENAME := serial.log 29 | 30 | TEST_DISK_DIR := "util/test_disk" 31 | TEST_DISK_IMG := "${TEST_DISK_DIR}/test_fat16.img" 32 | 33 | QEMU_FLAGS := \ 34 | -accel tcg,thread=single \ 35 | -boot order=dc \ 36 | -cpu core2duo \ 37 | -drive format=raw,media=cdrom,file=${ISO} \ 38 | -drive format=raw,media=disk,file=${TEST_DISK_IMG} \ 39 | -m 128 \ 40 | -machine pc \ 41 | -no-reboot \ 42 | -smp 1 \ 43 | -usb \ 44 | -vga std 45 | 46 | all: ${ISO} ${TEST_DISK_IMG} 47 | 48 | ${ISO}: ${KERNEL_BINARY} ${BUILD_DIR} 49 | make -C "${ISO_DIR}" 50 | 51 | clean: 52 | # Ensure the kernel directory is cleaned before the rts dir. 53 | # gprclean needs to see that there is a valid rts to perform any operations. 54 | make clean -C "${ISO_DIR}" 55 | make clean -C "${KERNEL_DIR}" 56 | make clean -C "${RUNTIME_DIR}" 57 | make clean -C "${TEST_DISK_DIR}" 58 | 59 | debug: ${ISO} 60 | qemu-system-i386 \ 61 | ${QEMU_FLAGS} \ 62 | -nographic \ 63 | -d cpu_reset,int,guest_errors \ 64 | -gdb tcp::1234 \ 65 | -S \ 66 | -serial file:${SERIAL_FILENAME} 67 | 68 | emu: ${ISO} 69 | qemu-system-i386 \ 70 | ${QEMU_FLAGS} \ 71 | -serial stdio 72 | 73 | bochs: ${ISO} 74 | bochs -f ./src/util/bochsrc 75 | 76 | kernel: ${KERNEL_BINARY} 77 | 78 | runtime: ${RUNTIME_BINARY} 79 | 80 | iso: ${ISO} 81 | 82 | ${RUNTIME_BINARY}: 83 | make -C "${RUNTIME_DIR}" 84 | 85 | ${KERNEL_BINARY}: ${RUNTIME_BINARY} 86 | make -C "${KERNEL_DIR}" 87 | 88 | ${BUILD_DIR}: 89 | mkdir -p ${BUILD_DIR} 90 | 91 | ${TEST_DISK_IMG}: 92 | make -C ${TEST_DISK_DIR} 93 | -------------------------------------------------------------------------------- /src/runtime/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | obj 3 | gnatprove 4 | *.ali 5 | *.o 6 | *.a 7 | *.elf 8 | *.bin 9 | *.img 10 | -------------------------------------------------------------------------------- /src/runtime/README.md: -------------------------------------------------------------------------------- 1 | # CXOS Kernel Ada Runtime 2 | 3 | This directory contains the source for the Kernel's customised Ada runtime. 4 | This runtime has been specifically constructed to target 'bareboard' x86 development. Unlike an Ada runtime for a hosted environment, this runtime is unable to provide most of the facilities outlined in the Ada Language Reference. The runtime contains the functions necessary for initialising the underlying x86 platform and launching the kernel. 5 | 6 | -------------------------------------------------------------------------------- /src/runtime/makefile: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2020, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .POSIX: 13 | .DELETE_ON_ERROR: 14 | MAKEFLAGS += --warn-undefined-variables 15 | MAKEFLAGS += --no-builtin-rules 16 | 17 | ARCH := x86 18 | 19 | BUILD_DIR := build 20 | LIB_DIR := ${BUILD_DIR}/adalib 21 | INCLUDE_DIR := ${BUILD_DIR}/adainclude 22 | 23 | RUNTIME_BINARY := ${LIB_DIR}/libgnat.a 24 | RUNTIME_PROJ := runtime 25 | 26 | ARCH_SRC_DIR := src/arch/${ARCH} 27 | COMMON_SRC_DIR := src/arch/common 28 | 29 | .PHONY: all clean 30 | 31 | all: ${RUNTIME_BINARY} 32 | 33 | clean: 34 | gprclean -P${RUNTIME_PROJ} 35 | rm -rf ${BUILD_DIR} 36 | 37 | ${RUNTIME_BINARY}: ${INCLUDE_DIR}/*.ad[sb] ${LIB_DIR} 38 | gprbuild -P${RUNTIME_PROJ} 39 | 40 | ${INCLUDE_DIR}/*.ad[sb]: ${ARCH_SRC_DIR}/*.ad[sb] ${COMMON_SRC_DIR}/*.ad[sb] ${INCLUDE_DIR} 41 | cp -a ${ARCH_SRC_DIR}/*.ad[sb] ${INCLUDE_DIR} 42 | cp -a ${COMMON_SRC_DIR}/*.ad[sb] ${INCLUDE_DIR} 43 | 44 | ${INCLUDE_DIR}: 45 | mkdir -p ${INCLUDE_DIR} 46 | 47 | ${LIB_DIR}: 48 | mkdir -p ${LIB_DIR} 49 | -------------------------------------------------------------------------------- /src/runtime/runtime.adc: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | -- Refer to: https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/standard_and_implementation_defined_restrictions.html 13 | pragma Discard_Names; 14 | pragma Normalize_Scalars; 15 | pragma Restrictions (No_Access_Subprograms); 16 | pragma Restrictions (No_Allocators); 17 | pragma Restrictions (No_Calendar); 18 | -- pragma Restrictions (No_Default_Initialization); 19 | pragma Restrictions (No_Delay); 20 | pragma Restrictions (No_Dispatch); 21 | pragma Restrictions (No_Enumeration_Maps); 22 | pragma Restrictions (No_Exception_Propagation); 23 | pragma Restrictions (No_Finalization); 24 | pragma Restrictions (No_Fixed_Point); 25 | pragma Restrictions (No_Implicit_Dynamic_Code); 26 | pragma Restrictions (No_Implicit_Heap_Allocations); 27 | pragma Restrictions (No_Initialize_Scalars); 28 | pragma Restrictions (No_IO); 29 | pragma Restrictions (No_Obsolescent_Features); 30 | pragma Restrictions (No_Protected_Types); 31 | pragma Restrictions (No_Recursion); 32 | pragma Restrictions (No_Reentrancy); 33 | pragma Restrictions (No_Streams); 34 | pragma Restrictions (No_Tasking); 35 | pragma Restrictions (No_Unchecked_Access); 36 | pragma Restrictions (Static_Storage_Size); 37 | -------------------------------------------------------------------------------- /src/runtime/runtime.gpr: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | library project Runtime is 13 | ---------------------------------------------------------------------------- 14 | -- The valid target architectures for the project. 15 | ---------------------------------------------------------------------------- 16 | type Arch_Type is ( 17 | "x86" 18 | ); 19 | 20 | ---------------------------------------------------------------------------- 21 | -- The selected architecture. 22 | ---------------------------------------------------------------------------- 23 | ARCH : Arch_Type := "x86"; 24 | 25 | for Create_Missing_Dirs use "True"; 26 | for Source_Dirs use ("build/adainclude"); 27 | for Object_Dir use "obj"; 28 | 29 | for Languages use ( 30 | "Ada" 31 | ); 32 | 33 | package Builder is 34 | for Global_Configuration_Pragmas use "runtime.adc"; 35 | for Switches ("Others") use ( 36 | "-nostdlib" 37 | ); 38 | end Builder; 39 | 40 | package Compiler is 41 | for Default_Switches ("Ada") use ( 42 | "-O0", 43 | "-ffunction-sections", 44 | "-fdata-sections", 45 | "-fno-omit-frame-pointer", 46 | "-ggdb", 47 | "-gnat2012", 48 | "-gnatg", 49 | "-gnatwadehl", 50 | "-gnatVa", 51 | "-gnaty3abcdefhiklmnoprstux", 52 | "-Wl,--gc-sections" 53 | ); 54 | 55 | for Default_Switches ("Asm_Cpp") use ( 56 | "-ggdb" 57 | ); 58 | end Compiler; 59 | 60 | for Library_Dir use "build/adalib"; 61 | for Library_Kind use "static"; 62 | for Library_Name use "gnat"; 63 | 64 | for Runtime ("Ada") use "build"; 65 | 66 | case ARCH is 67 | when "x86" => 68 | for Target use "i686-elf"; 69 | end case; 70 | end Runtime; 71 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/a-charac.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- A D A . C H A R A C T E R S -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- This specification is derived from the Ada Reference Manual for use with -- 10 | -- GNAT. In accordance with the copyright of that document, you can freely -- 11 | -- copy and modify this specification, provided that if you redistribute a -- 12 | -- modified version, any changes that you have made are clearly indicated. -- 13 | -- -- 14 | ------------------------------------------------------------------------------ 15 | 16 | package Ada.Characters is 17 | pragma Pure; 18 | end Ada.Characters; 19 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/a-unccon.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT COMPILER COMPONENTS -- 4 | -- -- 5 | -- A D A . U N C H E C K E D _ C O N V E R S I O N -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- This specification is derived from the Ada Reference Manual for use with -- 10 | -- GNAT. In accordance with the copyright of that document, you can freely -- 11 | -- copy and modify this specification, provided that if you redistribute a -- 12 | -- modified version, any changes that you have made are clearly indicated. -- 13 | -- -- 14 | ------------------------------------------------------------------------------ 15 | 16 | generic 17 | type Source (<>) is limited private; 18 | type Target (<>) is limited private; 19 | 20 | function Ada.Unchecked_Conversion (S : Source) return Target; 21 | 22 | pragma No_Elaboration_Code_All (Ada.Unchecked_Conversion); 23 | pragma Pure (Ada.Unchecked_Conversion); 24 | pragma Import (Intrinsic, Ada.Unchecked_Conversion); 25 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/ada.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- A D A -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- This specification is derived from the Ada Reference Manual for use with -- 10 | -- GNAT. In accordance with the copyright of that document, you can freely -- 11 | -- copy and modify this specification, provided that if you redistribute a -- 12 | -- modified version, any changes that you have made are clearly indicated. -- 13 | -- -- 14 | ------------------------------------------------------------------------------ 15 | 16 | package Ada is 17 | pragma No_Elaboration_Code_All; 18 | pragma Pure; 19 | 20 | end Ada; 21 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/memory.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | package body Memory is 13 | ---------------------------------------------------------------------------- 14 | -- Copy 15 | ---------------------------------------------------------------------------- 16 | function Copy ( 17 | Dest : System.Address; 18 | Source : System.Address; 19 | Count : Integer 20 | ) return System.Address is 21 | -- The source array. 22 | Source_Array : Byte_Array (1 .. Count) 23 | with Import, 24 | Address => Source; 25 | -- The destination array. 26 | Dest_Array : Byte_Array (1 .. Count) 27 | with Import, 28 | Address => Dest; 29 | begin 30 | -- If there is no length, do nothing. 31 | if Count < 1 then 32 | return Dest; 33 | end if; 34 | 35 | -- If the source and destinations are equal, do nothing. 36 | if Dest = Source then 37 | return Dest; 38 | end if; 39 | 40 | -- Copy via slicing. 41 | Dest_Array (1 .. Count) := Source_Array (1 .. Count); 42 | 43 | return Dest; 44 | exception 45 | when Constraint_Error => 46 | return Null_Address; 47 | end Copy; 48 | 49 | ---------------------------------------------------------------------------- 50 | -- Move 51 | ---------------------------------------------------------------------------- 52 | function Move ( 53 | Dest : System.Address; 54 | Source : System.Address; 55 | Count : Integer 56 | ) return System.Address is 57 | -- The source array. 58 | Source_Array : Byte_Array (1 .. Count) 59 | with Import, 60 | Address => Source; 61 | -- The destination array. 62 | Dest_Array : Byte_Array (1 .. Count) 63 | with Import, 64 | Address => Dest; 65 | begin 66 | -- If there is no length, do nothing. 67 | if Count < 1 then 68 | return Dest; 69 | end if; 70 | 71 | -- If the source and destinations are equal, do nothing. 72 | if Dest = Source then 73 | return Dest; 74 | end if; 75 | 76 | if Source < Dest then 77 | -- If the source is less than the destination, copy backwards to 78 | -- avoid any issues arising from the memory spaces overlapping. 79 | Copy_Downwards : 80 | declare 81 | -- Loop counter. 82 | I : Integer; 83 | begin 84 | I := Count; 85 | 86 | loop 87 | Dest_Array (I) := Source_Array (I); 88 | 89 | I := I - 1; 90 | exit when I = 0; 91 | end loop; 92 | 93 | return Dest; 94 | exception 95 | when Constraint_Error => 96 | return Null_Address; 97 | end Copy_Downwards; 98 | end if; 99 | 100 | for I in 1 .. Count loop 101 | Dest_Array (I) := Source_Array (I); 102 | end loop; 103 | 104 | return Dest; 105 | end Move; 106 | end Memory; 107 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/memory.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with Interfaces; use Interfaces; 13 | with System; use System; 14 | 15 | ------------------------------------------------------------------------------- 16 | -- MEMORY 17 | -- 18 | -- Purpose: 19 | -- This package contains code and defintions for working with memory common 20 | -- to all platforms. 21 | ------------------------------------------------------------------------------- 22 | package Memory is 23 | pragma Preelaborate (Memory); 24 | 25 | ---------------------------------------------------------------------------- 26 | -- Byte Array Type. 27 | -- Used in memory operations. The type is aliased to ensure that the 28 | -- element at every index of the array is treated as a pointer and not 29 | -- stored in registers. 30 | ---------------------------------------------------------------------------- 31 | type Byte_Array is array (Natural range <>) 32 | of aliased Unsigned_8; 33 | 34 | ---------------------------------------------------------------------------- 35 | -- Copy 36 | -- 37 | -- Purpose: 38 | -- Generic memcpy implementation. 39 | -- This is reuired by the runtime for default initialisation of 40 | -- package variables. 41 | -- Exceptions: 42 | -- None. 43 | ---------------------------------------------------------------------------- 44 | function Copy ( 45 | Dest : System.Address; 46 | Source : System.Address; 47 | Count : Integer 48 | ) return System.Address 49 | with Export, 50 | Convention => C, 51 | External_Name => "memcpy"; 52 | 53 | ---------------------------------------------------------------------------- 54 | -- Move 55 | -- 56 | -- Purpose: 57 | -- Generic memmove implementation. 58 | ---------------------------------------------------------------------------- 59 | function Move ( 60 | Dest : System.Address; 61 | Source : System.Address; 62 | Count : Integer 63 | ) return System.Address 64 | with Export, 65 | Convention => C, 66 | External_Name => "memmove"; 67 | 68 | end Memory; 69 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-atacco.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT COMPILER COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . A D D R E S S _ T O _ A C C E S S _ C O N V E R S I O N S -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- This specification is derived from the Ada Reference Manual for use with -- 12 | -- GNAT. The copyright notice above, and the license provisions that follow -- 13 | -- apply solely to the contents of the part following the private keyword. -- 14 | -- -- 15 | -- GNAT is free software; you can redistribute it and/or modify it under -- 16 | -- terms of the GNU General Public License as published by the Free Soft- -- 17 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 18 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 19 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 20 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 21 | -- -- 22 | -- As a special exception under Section 7 of GPL version 3, you are granted -- 23 | -- additional permissions described in the GCC Runtime Library Exception, -- 24 | -- version 3.1, as published by the Free Software Foundation. -- 25 | -- -- 26 | -- You should have received a copy of the GNU General Public License and -- 27 | -- a copy of the GCC Runtime Library Exception along with this program; -- 28 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 29 | -- . -- 30 | -- -- 31 | -- GNAT was originally developed by the GNAT team at New York University. -- 32 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 33 | -- -- 34 | ------------------------------------------------------------------------------ 35 | 36 | with Ada.Characters.Latin_1; 37 | 38 | generic 39 | type Object (<>) is limited private; 40 | 41 | package System.Address_To_Access_Conversions is 42 | pragma Preelaborate; 43 | 44 | pragma Compile_Time_Warning 45 | (Object'Unconstrained_Array, 46 | "Object is unconstrained array type" & Ada.Characters.Latin_1.LF & 47 | "To_Pointer results may not have bounds"); 48 | 49 | type Object_Pointer is access all Object; 50 | for Object_Pointer'Size use Standard'Address_Size; 51 | 52 | pragma No_Strict_Aliasing (Object_Pointer); 53 | -- Strictly speaking, this routine should not be used to generate pointers 54 | -- to other than proper values of the proper type, but in practice, this 55 | -- is done all the time. This pragma stops the compiler from doing some 56 | -- optimizations that may cause unexpected results based on the assumption 57 | -- of no strict aliasing. 58 | 59 | function To_Pointer (Value : Address) return Object_Pointer; 60 | function To_Address (Value : Object_Pointer) return Address; 61 | 62 | pragma Import (Intrinsic, To_Pointer); 63 | pragma Import (Intrinsic, To_Address); 64 | 65 | end System.Address_To_Access_Conversions; 66 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-exnint.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . E X N _ I N T -- 6 | -- -- 7 | -- B o d y -- 8 | -- -- 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- -- 19 | -- -- 20 | -- -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | package body System.Exn_Int is 33 | 34 | ----------------- 35 | -- Exn_Integer -- 36 | ----------------- 37 | 38 | function Exn_Integer (Left : Integer; Right : Natural) return Integer is 39 | pragma Suppress (Division_Check); 40 | pragma Suppress (Overflow_Check); 41 | 42 | Result : Integer; 43 | Factor : Integer; 44 | Exp : Natural; 45 | 46 | begin 47 | Result := 1; 48 | Factor := Left; 49 | Exp := Right; 50 | 51 | -- We use the standard logarithmic approach, Exp gets shifted right 52 | -- testing successive low order bits and Factor is the value of the 53 | -- base raised to the next power of 2. 54 | 55 | -- Note: it is not worth special casing base values -1, 0, +1 since 56 | -- the expander does this when the base is a literal, and other cases 57 | -- will be extremely rare. 58 | 59 | if Exp /= 0 then 60 | loop 61 | if Exp rem 2 /= 0 then 62 | Result := Result * Factor; 63 | end if; 64 | 65 | Exp := Exp / 2; 66 | exit when Exp = 0; 67 | Factor := Factor * Factor; 68 | end loop; 69 | end if; 70 | 71 | return Result; 72 | exception 73 | when Constraint_Error => 74 | return 0; 75 | end Exn_Integer; 76 | 77 | end System.Exn_Int; 78 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-exnint.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . E X N _ I N T -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- -- 19 | -- -- 20 | -- -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | -- Integer exponentiation (checks off) 33 | 34 | package System.Exn_Int is 35 | pragma Pure; 36 | 37 | function Exn_Integer (Left : Integer; Right : Natural) return Integer; 38 | 39 | end System.Exn_Int; 40 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-expuns.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . E X P _ U N S -- 6 | -- -- 7 | -- B o d y -- 8 | -- -- 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- -- 19 | -- -- 20 | -- -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | with System.Unsigned_Types; use System.Unsigned_Types; 33 | 34 | package body System.Exp_Uns is 35 | 36 | ------------------ 37 | -- Exp_Unsigned -- 38 | ------------------ 39 | 40 | function Exp_Unsigned 41 | (Left : Unsigned; 42 | Right : Natural) 43 | return Unsigned 44 | is 45 | Result : Unsigned; 46 | Factor : Unsigned; 47 | Exp : Natural; 48 | begin 49 | Result := 1; 50 | Factor := Left; 51 | Exp := Right; 52 | 53 | -- We use the standard logarithmic approach, Exp gets shifted right 54 | -- testing successive low order bits and Factor is the value of the 55 | -- base raised to the next power of 2. 56 | 57 | -- Note: it is not worth special casing the cases of base values -1,0,+1 58 | -- since the expander does this when the base is a literal, and other 59 | -- cases will be extremely rare. 60 | 61 | if Exp /= 0 then 62 | loop 63 | if Exp rem 2 /= 0 then 64 | Result := Result * Factor; 65 | end if; 66 | 67 | Exp := Exp / 2; 68 | exit when Exp = 0; 69 | Factor := Factor * Factor; 70 | end loop; 71 | end if; 72 | 73 | return Result; 74 | exception 75 | when Constraint_Error => 76 | return 0; 77 | end Exp_Unsigned; 78 | 79 | end System.Exp_Uns; 80 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-expuns.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . E X P _ U N S -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- -- 19 | -- -- 20 | -- -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | -- This function performs exponentiation of unsigned types (with binary 33 | -- modulus values up to and including that of Unsigned_Types.Unsigned). 34 | -- The result is always full width, the caller must do a masking operation 35 | -- the modulus is less than 2 ** (Unsigned'Size). 36 | 37 | with System.Unsigned_Types; 38 | 39 | package System.Exp_Uns is 40 | pragma Pure; 41 | 42 | function Exp_Unsigned 43 | (Left : System.Unsigned_Types.Unsigned; 44 | Right : Natural) 45 | return System.Unsigned_Types.Unsigned; 46 | 47 | end System.Exp_Uns; 48 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-imgint.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . I M G _ I N T -- 6 | -- -- 7 | -- B o d y -- 8 | -- -- 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- -- 19 | -- -- 20 | -- -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | package body System.Img_Int is 33 | ------------------- 34 | -- Image_Integer -- 35 | ------------------- 36 | 37 | procedure Image_Integer 38 | (V : Integer; 39 | S : in out String; 40 | P : out Natural) 41 | is 42 | pragma Assert (S'First = 1); 43 | 44 | begin 45 | if V >= 0 then 46 | S (1) := ' '; 47 | P := 1; 48 | else 49 | P := 0; 50 | end if; 51 | 52 | Set_Image_Integer (V, S, P); 53 | exception 54 | when Constraint_Error => 55 | return; 56 | end Image_Integer; 57 | 58 | ---------------------------------------------------------------------------- 59 | -- Set_Image_Integer 60 | -- 61 | -- Implementation Notes: 62 | -- - Refer to: http://www.nihamkin.com/2016/11/25/ 63 | -- writing-linux-modules-in-ada-part-3/ 64 | ---------------------------------------------------------------------------- 65 | procedure Set_Image_Integer ( 66 | V : Integer; 67 | S : in out String; 68 | P : in out Natural 69 | ) is 70 | -- The number of digits in the resulting string. 71 | Digit_Count : Natural := 0; 72 | begin 73 | Get_Digit_Count : 74 | declare 75 | V2 : Integer := V; 76 | begin 77 | while V2 /= 0 loop 78 | Digit_Count := Digit_Count + 1; 79 | V2 := V2 / 10; 80 | end loop; 81 | exception 82 | when Constraint_Error => 83 | Digit_Count := 0; 84 | end Get_Digit_Count; 85 | 86 | Write_To_String : 87 | begin 88 | if Digit_Count = 0 then 89 | P := P + 1; 90 | S (P) := '0'; 91 | else 92 | for I in reverse 0 .. (Digit_Count - 1) loop 93 | P := P + 1; 94 | S (P) := Character'Val (48 + (V / 10 ** I) rem 10); 95 | end loop; 96 | end if; 97 | exception 98 | when Constraint_Error => 99 | return; 100 | end Write_To_String; 101 | end Set_Image_Integer; 102 | 103 | end System.Img_Int; 104 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-imgint.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . I M G _ I N T -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- -- 19 | -- -- 20 | -- -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | -- This package contains the routines for supporting the Image attribute for 33 | -- signed integer types up to Size Integer'Size, and also for conversion 34 | -- operations required in Text_IO.Integer_IO for such types. 35 | 36 | package System.Img_Int is 37 | pragma Pure; 38 | 39 | procedure Image_Integer 40 | (V : Integer; 41 | S : in out String; 42 | P : out Natural); 43 | -- Computes Integer'Image (V) and stores the result in S (1 .. P) 44 | -- setting the resulting value of P. The caller guarantees that S 45 | -- is long enough to hold the result, and that S'First is 1. 46 | 47 | procedure Set_Image_Integer 48 | (V : Integer; 49 | S : in out String; 50 | P : in out Natural); 51 | -- Stores the image of V in S starting at S (P + 1), P is updated to point 52 | -- to the last character stored. The value stored is identical to the value 53 | -- of Integer'Image (V) except that no leading space is stored when V is 54 | -- non-negative. The caller guarantees that S is long enough to hold the 55 | -- result. S need not have a lower bound of 1. 56 | 57 | end System.Img_Int; 58 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-imguns.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System.Unsigned_Types; use System.Unsigned_Types; 13 | 14 | package body System.Img_Uns is 15 | ---------------------------------------------------------------------------- 16 | -- Image_Unsigned 17 | ---------------------------------------------------------------------------- 18 | procedure Image_Unsigned ( 19 | V : System.Unsigned_Types.Unsigned; 20 | S : in out String; 21 | P : out Natural 22 | ) is 23 | pragma Assert (S'First = 1); 24 | begin 25 | S (1) := ' '; 26 | P := 1; 27 | Set_Image_Unsigned (V, S, P); 28 | exception 29 | when Constraint_Error => 30 | return; 31 | end Image_Unsigned; 32 | 33 | ---------------------------------------------------------------------------- 34 | -- Set_Image_Unsigned 35 | -- 36 | -- Implementation Notes: 37 | -- - Refer to: http://www.nihamkin.com/2016/11/25/ 38 | -- writing-linux-modules-in-ada-part-3/ 39 | ---------------------------------------------------------------------------- 40 | procedure Set_Image_Unsigned ( 41 | V : Unsigned; 42 | S : in out String; 43 | P : in out Natural 44 | ) is 45 | -- The number of digits in the resulting string. 46 | Digit_Count : Natural := 0; 47 | begin 48 | Get_Digit_Count : 49 | declare 50 | V2 : Unsigned := V; 51 | begin 52 | while V2 /= 0 loop 53 | Digit_Count := Digit_Count + 1; 54 | V2 := V2 / 10; 55 | end loop; 56 | exception 57 | when Constraint_Error => 58 | Digit_Count := 0; 59 | end Get_Digit_Count; 60 | 61 | Write_To_String : 62 | begin 63 | if Digit_Count = 0 then 64 | P := P + 1; 65 | S (P) := '0'; 66 | else 67 | for I in reverse 0 .. (Digit_Count - 1) loop 68 | P := P + 1; 69 | S (P) := Character'Val (48 + (V / 10 ** I) rem 10); 70 | end loop; 71 | end if; 72 | exception 73 | when Constraint_Error => 74 | return; 75 | end Write_To_String; 76 | end Set_Image_Unsigned; 77 | 78 | end System.Img_Uns; 79 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-imguns.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Copyright (c) 2019, CXOS. 3 | -- This program is free software; you can redistribute it and/or modify it 4 | -- under the terms of the GNU General Public License as published by the 5 | -- Free Software Foundation; either version 3 of the License, or 6 | -- (at your option) any later version. 7 | -- 8 | -- Authors: 9 | -- Anthony 10 | ------------------------------------------------------------------------------- 11 | 12 | with System.Unsigned_Types; 13 | 14 | ------------------------------------------------------------------------------- 15 | -- SYSTEM.IMG_UNS 16 | -- 17 | -- Purpose: 18 | -- This package provides an implementation of the Image attribute for 19 | -- unsigned integer types. 20 | ------------------------------------------------------------------------------- 21 | package System.Img_Uns is 22 | pragma Pure; 23 | 24 | ---------------------------------------------------------------------------- 25 | -- Image_Unsigned 26 | -- 27 | -- purpose: 28 | -- Computes Unsigned'Image (V) and stores the result in S (1 .. P) \ 29 | -- setting the resulting value of P. The caller guarantees that S is 30 | -- long enough to hold the result, and that S'First is 1. 31 | ---------------------------------------------------------------------------- 32 | procedure Image_Unsigned ( 33 | V : System.Unsigned_Types.Unsigned; 34 | S : in out String; 35 | P : out Natural 36 | ) 37 | with Inline; 38 | 39 | ---------------------------------------------------------------------------- 40 | -- Set_Image_Unsigned 41 | -- 42 | -- Purpose: 43 | -- Stores the image of V in S starting at S (P + 1), P is updated to 44 | -- point to the last character stored. The value stored is identical 45 | -- to the value of Unsigned'Image (V) except that no leading space is 46 | -- stored. The caller guarantees that S is long enough to hold the 47 | -- result. S need not have a lower bound of 1. 48 | ---------------------------------------------------------------------------- 49 | procedure Set_Image_Unsigned ( 50 | V : System.Unsigned_Types.Unsigned; 51 | S : in out String; 52 | P : in out Natural 53 | ); 54 | 55 | end System.Img_Uns; 56 | -------------------------------------------------------------------------------- /src/runtime/src/arch/common/s-pack12.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT RUN-TIME COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . P A C K _ 1 2 -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- As a special exception under Section 7 of GPL version 3, you are granted -- 19 | -- additional permissions described in the GCC Runtime Library Exception, -- 20 | -- version 3.1, as published by the Free Software Foundation. -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | -- Handling of packed arrays with Component_Size = 12 33 | 34 | package System.Pack_12 is 35 | pragma Preelaborate; 36 | 37 | Bits : constant := 12; 38 | 39 | type Bits_12 is mod 2 ** Bits; 40 | for Bits_12'Size use Bits; 41 | 42 | -- In all subprograms below, Rev_SSO is set True if the array has the 43 | -- non-default scalar storage order. 44 | 45 | function Get_12 46 | (Arr : System.Address; 47 | N : Natural; 48 | Rev_SSO : Boolean) return Bits_12 with Inline; 49 | -- Arr is the address of the packed array, N is the zero-based 50 | -- subscript. This element is extracted and returned. 51 | 52 | procedure Set_12 53 | (Arr : System.Address; 54 | N : Natural; 55 | E : Bits_12; 56 | Rev_SSO : Boolean) with Inline; 57 | -- Arr is the address of the packed array, N is the zero-based 58 | -- subscript. This element is set to the given value. 59 | 60 | function GetU_12 61 | (Arr : System.Address; 62 | N : Natural; 63 | Rev_SSO : Boolean) return Bits_12 with Inline; 64 | -- Arr is the address of the packed array, N is the zero-based 65 | -- subscript. This element is extracted and returned. This version 66 | -- is used when Arr may represent an unaligned address. 67 | 68 | procedure SetU_12 69 | (Arr : System.Address; 70 | N : Natural; 71 | E : Bits_12; 72 | Rev_SSO : Boolean) with Inline; 73 | -- Arr is the address of the packed array, N is the zero-based 74 | -- subscript. This element is set to the given value. This version 75 | -- is used when Arr may represent an unaligned address 76 | 77 | end System.Pack_12; 78 | -------------------------------------------------------------------------------- /src/runtime/src/arch/x86/a-interr.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Ada.Interrupts 3 | -- 4 | -- Purpose: 5 | -- Contains functionality for handling system interrupts. 6 | ------------------------------------------------------------------------------- 7 | package Ada.Interrupts is 8 | pragma Preelaborate (Ada.Interrupts); 9 | 10 | pragma Implementation_Defined; 11 | 12 | type Interrupt_ID is new Natural; 13 | end Ada.Interrupts; 14 | -------------------------------------------------------------------------------- /src/runtime/src/arch/x86/s-parame.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- -- 3 | -- GNAT COMPILER COMPONENTS -- 4 | -- -- 5 | -- S Y S T E M . P A R A M E T E R S -- 6 | -- -- 7 | -- S p e c -- 8 | -- -- 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- 10 | -- -- 11 | -- GNAT is free software; you can redistribute it and/or modify it under -- 12 | -- terms of the GNU General Public License as published by the Free Soft- -- 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- 16 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- 17 | -- -- 18 | -- -- 19 | -- -- 20 | -- -- 21 | -- -- 22 | -- You should have received a copy of the GNU General Public License and -- 23 | -- a copy of the GCC Runtime Library Exception along with this program; -- 24 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 25 | -- . -- 26 | -- -- 27 | -- GNAT was originally developed by the GNAT team at New York University. -- 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- 29 | -- -- 30 | ------------------------------------------------------------------------------ 31 | 32 | -- This is a generic zfp version the package 33 | 34 | -- This package defines some system dependent parameters for GNAT. These 35 | -- are values that are referenced by the runtime library and are therefore 36 | -- relevant to the target machine. 37 | 38 | -- The parameters whose value is defined in the spec are not generally 39 | -- expected to be changed. If they are changed, it will be necessary to 40 | -- recompile the run-time library. 41 | 42 | -- The parameters which are defined by functions can be changed by modifying 43 | -- the body of System.Parameters in file s-parame.adb. A change to this body 44 | -- requires only rebinding and relinking of the application. 45 | 46 | -- Note: do not introduce any pragma Inline statements into this unit, since 47 | -- otherwise the relinking and rebinding capability would be deactivated. 48 | 49 | package System.Parameters is 50 | pragma Pure; 51 | 52 | ------------------------------ 53 | -- Stack Allocation Control -- 54 | ------------------------------ 55 | 56 | type Size_Type is range 57 | -(2 ** (Integer'(Standard'Address_Size) - 1)) .. 58 | +(2 ** (Integer'(Standard'Address_Size) - 1)) - 1; 59 | -- Type used to provide task stack sizes to the runtime. Sized to permit 60 | -- stack sizes of up to half the total addressable memory space. This may 61 | -- seem excessively large (even for 32-bit systems), however there are many 62 | -- instances of users requiring large stack sizes (for example string 63 | -- processing). 64 | 65 | Unspecified_Size : constant Size_Type := Size_Type'First; 66 | -- Value used to indicate that no size type is set 67 | 68 | Runtime_Default_Sec_Stack_Size : constant Size_Type := 4096; 69 | -- The run-time chosen default size for secondary stacks that may be 70 | -- overridden by the user with the use of binder -D switch. 71 | 72 | end System.Parameters; 73 | -------------------------------------------------------------------------------- /src/util/README.build_cross_gnat.md: -------------------------------------------------------------------------------- 1 | # GNAT cross-compiler build script 2 | 3 | The provided `build_cross_gnat` script provides a working recipe for building a GNAT cross compiler targeting `i686-elf` suitable for building the `cxos` kernel. 4 | This script is currently configured for Ubuntu Linux, but should be easily adaptable to other systems. Feel free to extend this script to improve compatibility. This script has been tested across several Ubuntu machines. 5 | 6 | ## Prerequisites 7 | 8 | The script requires that you have the sources for `gcc`, `binutils` and `newlib` downloaded on your system. These are available from the GNU FTP servers ([GCC](https://ftp.gnu.org/gnu/gcc/) and [Binutils](https://ftp.gnu.org/gnu/binutils/)) and the sourceware FTP ([newlib]ftp://sourceware.org/pub/newlib/index.html)). 9 | By default the script will assume that you have these sources extracted in the location `${HOME}/src/`. The folders used as the source folders are easily configurable in the script. 10 | 11 | ## Post-setup 12 | 13 | Before you can use the newly configured toolchain with `gprbuild`, you will firstly need to ensure that your new toolchain's install directory is properly added to your `PATH` variable. 14 | Additionally, you will need to ensure that `gprbuild` correctly recognises our toolchain and is configured for library development. This is done by adding configuration information about our toolchain to GPRBuild's 'knowledge base'. There are multiple ways to accomplish this, but the simplest way is detailed below: 15 | 16 | Open up GPRBuild's linker configuration file, typically located at `${prefix}/share/gprconfig/linker.xml`, where `${prefix}` is the location of your GNAT install directory (in the case that you have GPRBuild installed with AdaCore GNAT. Other configurations may have a different directory structure). This file instructs GPRBuild how to link executables and libraries using the various supported toolchains. 17 | The easiest way to do this is to duplicate an existing toolchain configuration. Inside this file, search for an existing configuration such as `leon-elf`, and duplicate each entry for the existing configuration. modifying it to suit our `i686-elf` target. 18 | 19 | For example: 20 | ```xml 21 | 22 | 23 | //... 24 | 25 | 26 | 27 | for Library_Support use "static_only"; 28 | for Library_Builder use "${GPRCONFIG_PREFIX}libexec/gprbuild/gprlib"; 29 | 30 | 31 | 32 | //... 33 | 34 | 35 | 36 | 37 | 38 | 39 | for Archive_Builder use ("i686-elf-ar", "cr"); 40 | for Archive_Builder_Append_Option use ("q"); 41 | for Archive_Indexer use ("i686-elf-ranlib"); 42 | for Archive_Suffix use ".a"; 43 | 44 | 45 | ``` 46 | 47 | Once you have duplicated all of these toolchain entries and modified them for our toolchain, paying special attention to preserve any regex special characters, you should now be able to successfully use the newly built toolchain together with GPRBuild. 48 | 49 | Additional documentation can be found on GPRBuild's configuration [here](http://docs.adacore.com/live/wave/gprbuild/html/gprbuild_ug/gprbuild_ug/companion_tools.html). 50 | -------------------------------------------------------------------------------- /src/util/README.md: -------------------------------------------------------------------------------- 1 | # Utils 2 | 3 | This folder contains various scripts and utilities to assist in setup and development. 4 | 5 | ## build_cross_gnat 6 | 7 | This script contains a working recipe for building an Ada capable GCC cross-compiler. This script was developed and has been tested on Ubuntu 18.08. A Linux distribution will be required to use this script, results may vary by distro but the recipe shouldn't differ too much. 8 | 9 | ## debugrc 10 | 11 | This script is loaded and executed automatically by GDB when debugging the kernel. This will automatically connect to the QEMU GDB stub launched when using the `/debug` script in the main repo directory. Commands to aid in debugging can be placed here. 12 | -------------------------------------------------------------------------------- /src/util/_shared.sh: -------------------------------------------------------------------------------- 1 | # check if a package is installed, and install it if not. 2 | function check_install_package { 3 | local pkg_name="${1}" 4 | local pkg_status=$(dpkg-query -W --showformat='${Status}\n' ${pkg_name} | grep "install ok installed") 5 | if [ "" == "$pkg_status" ]; then 6 | echo "Intalling ${pkg_name}." 7 | sudo apt-get --yes install "${pkg_name}" 8 | else 9 | echo "${pkg_name} is already installed." 10 | fi 11 | } 12 | 13 | function append_to_bashrc() { 14 | local text="$1" 15 | local bashrc="${HOME}/.bashrc" 16 | 17 | printf "%s\\n" "${text}" >> "${bashrc}" 18 | } 19 | 20 | 21 | function append_to_PATH() { 22 | local dir="$1" 23 | local path_prefix='PATH=$PATH:' 24 | 25 | append_to_bashrc "${path_prefix}${dir}" 26 | } 27 | 28 | 29 | function die_with_message { 30 | echo "$1" >&2 31 | exit 1 32 | } 33 | 34 | 35 | function prompt_to_confirm { 36 | read -n 1 -p "Please press ENTER to confirm." var 37 | if [ ${#var} -ne 0 ]; then 38 | echo "Aborted." 39 | exit 0 40 | fi 41 | } 42 | 43 | 44 | # Check if a file has been downloaded to the user's download directory, otherwise download it. 45 | function check_for_local_download { 46 | local file_url="${1}" 47 | if [ -z "${file_url}" ]; then 48 | echo "No URL passed to check_for_local_download()! Exiting." >&2 49 | exit 1 50 | fi 51 | 52 | local file_name="${file_url##*/}" 53 | local download_dir="${HOME}/Downloads" 54 | local local_downloaded_copy="${download_dir}/${file_name}" 55 | 56 | # check if we have a local downloaded copy already 57 | if [ -e ${local_downloaded_copy} ]; then 58 | echo "Using local copy found at ${local_downloaded_copy}." >&2 59 | echo ${local_downloaded_copy} 60 | else 61 | local tmp_dir="$(mktemp -d)" 62 | echo "No local copy found. Downloading from ${file_url}..." >&2 63 | wget -q "${file_url}" -P "${tmp_dir}" || die_with_message "Failure downloading ${file_url}! Exiting." 64 | echo ${tmp_dir}/${file_name} 65 | fi 66 | } 67 | -------------------------------------------------------------------------------- /src/util/bochsrc: -------------------------------------------------------------------------------- 1 | ata0-master: type=cdrom, path=build/cxos.img, status=inserted 2 | boot: cdrom 3 | com1: enabled=1, mode=term 4 | cpu: count=1, ips=10000000, reset_on_triple_fault=0 5 | display_library: x, options="gui_debug" 6 | megs: 256 7 | -------------------------------------------------------------------------------- /src/util/debugrc: -------------------------------------------------------------------------------- 1 | set architecture i386 2 | target remote localhost:1234 3 | file src/kernel/build/cxos.elf -readnow 4 | 5 | # b initialise_kernel_page_directory 6 | # b map_page_frame 7 | # b x86-memory-paging.adb:557 8 | # x /32tg &memory_map 9 | # b __load_page_directory 10 | # print_mmap_region 11 | 12 | # x /1xg &idt_pointer 13 | # x /5xg &global_descriptor_table 14 | # x /3xg &interrupt_descriptor_table+(256) 15 | # 16 | 17 | b switch_to_process 18 | -------------------------------------------------------------------------------- /src/util/test_disk/.gitignore: -------------------------------------------------------------------------------- 1 | *.fat 2 | *.img 3 | test_disk_files 4 | -------------------------------------------------------------------------------- /src/util/test_disk/makefile: -------------------------------------------------------------------------------- 1 | ##################################################################### 2 | # Copyright (c) 2020, CXOS. 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # Authors: 9 | # Anthony 10 | ##################################################################### 11 | 12 | .POSIX: 13 | .DELETE_ON_ERROR: 14 | MAKEFLAGS += --warn-undefined-variables 15 | MAKEFLAGS += --no-builtin-rules 16 | 17 | .PHONY: all clean 18 | 19 | TEST_DISK_FAT12_IMG := ./test_fat12.img 20 | TEST_DISK_FAT12_IMG_SIZE := 2880 21 | 22 | TEST_DISK_FAT16_IMG := ./test_fat16.img 23 | 24 | TEST_DISK_CONTENTS := $(shell ls -d ./test_disk_files/*) 25 | 26 | all: ${TEST_DISK_FAT12_IMG} ${TEST_DISK_FAT16_IMG} 27 | 28 | clean: 29 | rm -f ${TEST_DISK_FAT12_IMG} ${TEST_DISK_FAT16_IMG} 30 | 31 | ${TEST_DISK_FAT12_IMG}: 32 | dd if=/dev/zero of=${TEST_DISK_FAT12_IMG} bs=1k count=${TEST_DISK_FAT12_IMG_SIZE} 33 | mformat -i ${TEST_DISK_FAT12_IMG} -f ${TEST_DISK_FAT12_IMG_SIZE} :: 34 | mcopy -i ${TEST_DISK_FAT12_IMG} ${TEST_DISK_CONTENTS} :: 35 | 36 | ${TEST_DISK_FAT16_IMG}: 37 | dd if=/dev/zero of=${TEST_DISK_FAT16_IMG} count=16 bs=1M 38 | mkfs.fat -F 16 ${TEST_DISK_FAT16_IMG} 39 | mcopy -i ${TEST_DISK_FAT16_IMG} ${TEST_DISK_CONTENTS} :: 40 | -------------------------------------------------------------------------------- /src/util/test_disk/test_disk_files/file_with_long_file_name.ext: -------------------------------------------------------------------------------- 1 | File with long filename. 2 | -------------------------------------------------------------------------------- /src/util/test_disk/test_disk_files/short.file: -------------------------------------------------------------------------------- 1 | File with short filename. 2 | --------------------------------------------------------------------------------