diff --git a/arm9loaderhax.bin b/arm9loaderhax.bin new file mode 100755 index 0000000..f8141ca Binary files /dev/null and b/arm9loaderhax.bin differ diff --git a/kernel.settings b/kernel.settings index 6dcff75..cfc2938 100644 --- a/kernel.settings +++ b/kernel.settings @@ -1,15 +1,20 @@ -arch = x86_64 +arch = 3ds MODE = debug #MODE = release # enables optimization export PATH := $(HOME)/opt/bin:$(PATH) -ARCHFLAGS = ifeq ($(arch),x86) PREFIX = i686-elf- + libpath = i686-elf else ifeq ($(arch),x86_64) PREFIX = x86_64-elf- - ARCHFLAGS = + libpath = x86_64-elf + else + ifeq ($(arch),3ds) + PREFIX = arm-none-eabi- + libpath = arm-none-eabi + endif endif endif diff --git a/kernel/Makefile b/kernel/Makefile index 7f3131a..244b4ca 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,11 +2,11 @@ include ../kernel.settings SRCS = $(shell find hal/$(arch) -name '*.cpp' -o -name '*.[cS]') KERNSRCS = $(shell find kernel -name '*.cpp' -o -name '*.c') #OBJS = $(addsuffix .o,$(basename $(SRCS))) -OBJS = $(addsuffix .o,$(basename $(KERNSRCS))) +OBJS = #$(addsuffix .o,$(basename $(KERNSRCS))) LD = $(PREFIX)g++ LDFLAGS = -nostdlib -nodefaultlibs -nostdlib -fno-builtin $(ARCHFLAGS) -T kernel-$(arch).ld -z max-page-size=0x1000 -all: hal kernel +all: hal #kernel #uncomment when done with 3ds $(LD) $(LDFLAGS) -o mtgos $(OBJS) libhal.a -lgcc hal: make -C hal diff --git a/kernel/hal/3ds/Makefile b/kernel/hal/3ds/Makefile new file mode 100644 index 0000000..24ff54f --- /dev/null +++ b/kernel/hal/3ds/Makefile @@ -0,0 +1,36 @@ +include ../../../kernel.settings +ARM9SRCS = $(shell find arm9 -name '*.cpp' -o -name '*.[cS]') +ARM11SRCS = $(shell find arm11 -name '*.cpp' -o -name '*.[cS]') +ARM9OBJS = $(addsuffix .o,$(basename $(ARM9SRCS))) +ARM11OBJS = $(addsuffix .o,$(basename $(ARM11SRCS))) +ARM9FLAGS = -mcpu=arm946e-s -march=armv5te -mlittle-endian +ARM11FLAGS = -mcpu=mpcore -mlittle-endian + +CPP = $(PREFIX)g++ +CC = $(PREFIX)gcc +AR = $(PREFIX)ar +ASFLAGS = +CFLAGS += -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../kernel/c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie +CPPFLAGS += -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../kernel/c_include -I../../kernel/include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie -Wno-reorder + +all: $(ARM9OBJS) $(ARM11OBJS) + +arm9/%.o: arm9/%.cpp + $(CPP) $(CPPFLAGS) $(ARM9FLAGS) -c -o $@ $^ + +arm9/%.o: arm9/%.c + $(CC) $(CFLAGS) $(ARM9FLAGS) -c -o $@ $^ + +arm9/%.o: arm9/%.S + $(CC) $(CFLAGS) $(ARM9FLAGS) -c -o $@ $^ + +arm11/%.o: arm11/%.cpp + $(CPP) $(CPPFLAGS) $(ARM9FLAGS) -c -o $@ $^ + +arm11/%.o: arm11/%.c + $(CC) $(CFLAGS) $(ARM9FLAGS) -c -o $@ $^ + +arm11/%.o: arm11/%.S + $(CC) $(CFLAGS) $(ARM9FLAGS) -c -o $@ $^ + +clean: diff --git a/kernel/hal/3ds/arm11/init/arm11init.cpp b/kernel/hal/3ds/arm11/init/arm11init.cpp new file mode 100644 index 0000000..fdfe608 --- /dev/null +++ b/kernel/hal/3ds/arm11/init/arm11init.cpp @@ -0,0 +1,66 @@ +//Notice: 0x1FFFFFF8 is a pointer to a function that is being executed by +//A11 SYS_CORE +//If it's zero, SYS_CORE is ready for a new task +#include +#include +void(**fpointer)(void)=(void(**)(void))0x1FFFFFF8; +void __attribute__((naked)) arm11Stub(void) +{ + //Disable interrupts + __asm(".word 0xF10C01C0"); + + //Wait for the entry to be set + while(*fpointer == &arm11Stub); + + //Jump to it + (*fpointer)(); +} +void mainRoutine() { + *fpointer=nullptr; + while(true) { + if(!(*fpointer)) + continue; + (*fpointer)(); + *fpointer=nullptr; + } +} +unsigned int seed=0; +unsigned int random() { + return seed=0x41C64E6D * seed + 0x00006073; +} +#define CALCXY_top(x,y) ((x)*240+240-(y)) +void initScreen() { + //top screen lfb size: 0x5dc00 + //bottom screen lfb size: 0x4b000 + //lfb locations: 0x18000000 (left 1) + //lfb locations: 0x18060000 (left 2) + //lfb locations: 0x180C0000 (right 1) + //lfb locations: 0x18120000 (right 2) + //lfb locations: 0x18180000 (bottom 1) + //lfb locations: 0x181D0000 (bottom 2) + unsigned int *fb_init=(unsigned int*)0x10400400; + fb_init[0x70/4]&=~0x7; + fb_init[0x170/4]&=~0x7; + fb_init[0x68/4]=0x18000000; //Left eye + fb_init[0x6C/4]=0x18060000; //Left eye + fb_init[0x90/4]=960; + fb_init[0x94/4]=0x180C0000; //Right eye + fb_init[0x98/4]=0x18120000; //Right eye + fb_init[0x168/4]=0x18180000; + fb_init[0x16C/4]=0x181D0000; + fb_init[0x190/4]=960; + int *lfb=(int*)0x18060000; + for(int bx=0;bx<32;bx++) { + for(int by=0;by<8;by++) { + for(int x=0;x<8;x++) { + for(int y=0;y<8;y++) { + if(font[bx+by*32][y]&(1<