First commit

This commit is contained in:
Potter360 2024-03-07 18:22:14 +01:00
commit 00f6fc9318
11 changed files with 233 additions and 0 deletions

11
README.md Normal file
View File

@ -0,0 +1,11 @@
# oSDK
oSDK is the sdk going with the omega unikernel.
## installation
You can install the SDK with :
```bash
% chmod +x ./install.sh
% ./install.sh
```

38
default-project/Makefile Normal file
View File

@ -0,0 +1,38 @@
CC=sh-elf-gcc
CFLAGS= -I/usr/local/include -ffreestanding -flto -nostdlib -O2 -Wall -Wextra -Xlinker
NAME=
FILENAME="omega"
OBJCOPY = sh-elf-objcopy
SRC_DIR=src
CONV_DIR=oconv
BUILD_DIR=build
SRC := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*.s)
SRC += $(wildcard $(SRC_DIR)/*/*.c $(SRC_DIR)/*/*.s)
all: mkdir convert compile clean
no_clean : mkdir convert compile
mkdir:
mkdir -p build
convert:
cd oconv && python3 convert.py ../assets/
cd ..
compile: $(FILENAME).g3a
$(FILENAME).g3a : $(BUILD_DIR)/$(FILENAME).bin
mkg3a -n "basic:$(NAME)" -i uns:assets/uns-icon.bmp -i sel:assets/sel-icon.bmp $(BUILD_DIR)/$(FILENAME).bin $(FILENAME).g3a
$(BUILD_DIR)/$(FILENAME).bin : $(BUILD_DIR)/$(FILENAME).elf
$(OBJCOPY) -O binary $(BUILD_DIR)/$(FILENAME).elf $(BUILD_DIR)/$(FILENAME).bin
$(BUILD_DIR)/$(FILENAME).elf: $(SRC)
sh-elf-gcc $(CFLAGS) -T linker.ld -o $(BUILD_DIR)/$(FILENAME).elf $(SRC) /usr/local/lib/omega.a $(wildcard $(CONV_DIR)/*.S) -lgcc
clean:
rm -rf build
rm -f oconv/*.S
.PHONY: all clean

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1 @@
font.png : image, font

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

73
default-project/linker.ld Normal file
View File

@ -0,0 +1,73 @@
ENTRY(_start)
MEMORY
{
rom (rx): o = 0x00300000, l = 2M
/*First 0x1400 bytes are reserved for VBR (starting at 0x08100000)*/
ram (rw): o = 0x08101400, l = 491k
}
SECTIONS
{
_srom = SIZEOF(.pretext) + SIZEOF(.text) + SIZEOF(.rodata);
.pretext : {
*(.text.entry)
} > rom
.text : {
_exch_start = . ;
*(.omega.exch)
_exch_size = ABSOLUTE (. - _exch_start);
_inth_start = . ;
*(.omega.inth)
_inth_size = ABSOLUTE (. - _inth_start);
. = ALIGN(4);
_tlbh_start = . ;
*(.omega.tlbh)
_tlbh_size = ABSOLUTE (. - _tlbh_start);
*(.text .text.*)
} > rom
.rodata : {
*(.rodata .rodata.*)
} > rom
. = ORIGIN(ram);
.data : {
_rdata = .;
*(.data .data.*)
*(.omega.vram)
_ldata = LOADADDR(.data);
} > ram AT > rom
_sdata = SIZEOF(.data);
.bss (NOLOAD) : {
_rbss = . ;
*(.bss .bss.* COMMON)
} > ram :NONE
_sbss = SIZEOF(.bss);
/* not important : comments */
/DISCARD/ : {
*(.comment)
}
}

View File

@ -0,0 +1,72 @@
import subprocess
import sys
import os
from PIL import Image
def rgb_to_rgb565(rgb_tuple):
r = rgb_tuple[0]
g = rgb_tuple[1]
b = rgb_tuple[2]
return (int(r/255*31)<<11)|(int(g/255*63)<<5) | int(b/255*31)
class image:
def __init__(self, path):
self.image = Image.open(path)
def getImage(self):
return self.image
def setImage(self,path):
self.image = Image.open(path)
def getpixels(self):
width, height = self.image.size
pixels = []
for y in range(height):
for x in range(width):
pixel = self.image.getpixel((x, y))
pixels.append(rgb_to_rgb565(pixel))
return pixels
class converter:
def __init__(self, file):
self.file = file
def getFile(self):
return self.file
def setFile(self, file):
self.file = file
def write_word(self, data):
asm = ""
asm += ".word " + hex(data)
return asm
def convert_image(self, symbol, section=".rodata"):
img = image(self.file)
asmc = f".section {section} \n"
asmc += f".global _{symbol}\n"
asmc += f"_{symbol}:\n"
width,height = img.getImage().size
asmc += self.write_word(height) + "\n"
asmc += self.write_word(width) + "\n"
pixels = img.getpixels()
for i in pixels:
asmc += self.write_word(i) + "\n"
f = open(symbol + ".S", "wb")
f.write(asmc.encode('utf-8'))
f.close()
dir = sys.argv[1]
ls = os.listdir(dir)
if not "oconv.txt" in ls:
print(" OConv ----- oconv.txt cannot be found")
exit()
print("\n")
conf = open(f"{dir}oconv.txt", 'r').read().replace(" ","")
files = conf.split("\n")
for file in files:
filename, metadatas = file.split(":")
type, name = metadatas.split(",")
print(f" OConv ----- Converting {filename}")
conv = converter(dir+filename)
if(type == "image"):
conv.convert_image(name)
print("\n")

View File

@ -0,0 +1,14 @@
#include <omega/display.h>
#include <omega/keyboard.h>
int main(void)
{
while(!keydown(KEY_SHIFT))
{
dclear();
dprintf(1,1,C_BLACK,"~~ welcome to omega ~~");
dupdate();
}
return 1;
}

4
install.sh Normal file
View File

@ -0,0 +1,4 @@
sudo mkdir -p /usr/local/share/omega
sudo cp -r default-project /usr/local/share/omega
chmod +x osdk
sudo cp osdk /usr/local/bin

20
osdk Normal file
View File

@ -0,0 +1,20 @@
usage_string=$(cat << EOF
oSDK v.1.0\n
usage: osdk [COMMAND]\n\n
osdk new [<NAME>]\n
Create a new project in a new folder called <NAME>.
EOF
)
new_project() {
mkdir "$1"
cp -r /usr/local/share/omega/default-project/* "$1"
echo "Created a new project $1."
echo "You can now compile the project with 'make'."
}
case "$1" in
"new")
new_project "$2";;
*)
echo ${usage_string};;
esac