Skip to content

A minimalist hardware abstraction layer. Device interfaces, drivers and compositions based on the book "Foundations of Computer Science"

License

Notifications You must be signed in to change notification settings

InductiveComputerScience/infracore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

infracore.io

A minimalist hardware abstraction layer.

It separates hardware into seven different devices with only a few API functions each. Everything the computer can do should be possible with just these API functions. Experience the joy of programming with an easily underatandable API.

This repo contains device interfaces, drivers and example programs.

Devices

Drivers

Examples

  • screen
    • Demo 1 -- Drawing pixels to a screen for some seconds.
    • Demo 2 -- Drawing pixels to a screen in x86-64 assembly.
  • audio
    • Demo 1 -- Sending a pure C tone to an audio device.
    • Demo 2 -- Sending a pure C tone to an audio device in x86-64 assembly.
  • clock
    • Demo 1 -- Prints the current time on screen, waits a second, and prints the time again.
    • Demo 2 -- Runs for 1 second. In x86-64 assembly.
  • disk
    • Demo 1 -- Read a string from disk and print it.
    • Demo 2 -- Read a string from disk and print it in x86-64 assembly.
  • processing unit (PU)
  • processing unit controller (PUC)
    • Demo 1 -- Run two programs in two processing units.
    • Demo 2 -- Restart on exception.
    • Demo 3 -- Running multiple programs but not using more than one CPU.

Examples with Multiple Devices

  • screen and keyboard
    • Demo 1 -- Drawing pixels to a screen, exit by pressing esc.
    • Demo 2 -- Control screen and keyboard with x86-64 assembly.

API Functions

Screen

Keyboard

Clock

Disk

Processing Unit (PU)

Processing Unit Controller (PUC)

How to

You can clone this repository and try out any of the examples. Build by running make.sh and then run ./program to run the demo program.

A typical program has the following parts: A launcher, a program and a build script. The examples below assumes you have cloned the repository into a directory called infracore.

Launcher -- Creates the Devices

Initialize all the devices that your program will use. Each device is created using a device driver. In this example the SDL driver is used for the screen and a file driver is used for the disk. The screen is 640x480 and the disk is 1024 bytes, two blocks of 512 bytes, and stored in the file disk.dat.

CreateScreenLinuxSDL(&screen1, 640, 480, 1920/0.508);
CreateC89File(&disk1, "disk.dat", 2, 512);

Program(screen1, disk1);

CloseScreenLinuxSDL(screen1);
CloseC89File(disk1);

Program -- Your Program

An infracore program consist of a function that takes the devices it uses as input. For example, this program can use the screen and read data from and write data to the disk.

void Program(ScreenStructure *screen1, DiskStructure *disk1){
  ...
}

Another example would be a game. It needs a screen to display the game, an audio device to play sound, a clock to keep track of time and a disk for the game data. Then you would pass the following devices to the program: screen, audio, clock and disk.

Build Script -- Builds the Program

Finally, the program needs to be built.

# Drivers:
gcc -c infracore/drivers/screen-linux-sdl/screen-linux-sdl.c -I infracore/devices/screen/
gcc -c infracore/drivers/disk-c89-file/disk-c89-file.c -std=c89 -I infracore/devices/disk/

# Launcher:
gcc -c launcher.c -I infracore/devices/screen -I infracore/devices/disk

# Program:
gcc -c program.c -I infracore/devices/screen -I infracore/devices/disk

# Make executable:
gcc -o program program.o launcher.o screen-linux-sdl.o disk-c89-file.o -lm -lpthread -lSDL2 -lrt

Book

The code here is based on the contents of the book Foundations of Computer Science.

Foundations of Computer Science

About

A minimalist hardware abstraction layer. Device interfaces, drivers and compositions based on the book "Foundations of Computer Science"

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages