From e5db9dfff19cb43e807cf8d25492727c5f0e0d0a Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Sat, 29 Apr 2017 21:06:24 +0000 Subject: [PATCH] tried adding arm9 --- buildtools/mkfirm.py | 6 +- kernel/arch/arm/3ds9/flags.cmake | 3 + kernel/arch/arm/3ds9/layout.ld | 36 ++++++++++++ kernel/arch/arm/3ds9/start.cpp | 11 ++++ kernel/arch/arm/3ds9/start.s | 94 ++++++++++++++++++++++++++++++++ kernel/hw/3ds9/config.py | 4 ++ kernel/hw/3ds9/picafb/picafb.cpp | 13 +++++ kernel/hw/3ds9/picafb/picafb.hpp | 13 +++++ 8 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 kernel/arch/arm/3ds9/flags.cmake create mode 100644 kernel/arch/arm/3ds9/layout.ld create mode 100644 kernel/arch/arm/3ds9/start.cpp create mode 100644 kernel/arch/arm/3ds9/start.s create mode 100644 kernel/hw/3ds9/picafb/picafb.cpp create mode 100644 kernel/hw/3ds9/picafb/picafb.hpp diff --git a/buildtools/mkfirm.py b/buildtools/mkfirm.py index 8fe1011..a9ff4b8 100755 --- a/buildtools/mkfirm.py +++ b/buildtools/mkfirm.py @@ -16,6 +16,7 @@ def get_elf_seg(f): #Return entry,section_beg,section_size,section raise Exception("Little Endian ELF required!") if f.read(1) != b"\x01": raise Exception("Unknown ELF version!") + f.read(9) if struct.unpack(" +#include + +PICAfb term; +void main(); +extern "C" void start() { main(); } +void drivers_init() { + setMainTTY(&term); + --term; +} diff --git a/kernel/arch/arm/3ds9/start.s b/kernel/arch/arm/3ds9/start.s new file mode 100644 index 0000000..90ded36 --- /dev/null +++ b/kernel/arch/arm/3ds9/start.s @@ -0,0 +1,94 @@ +.align 4 +.global _start +.extern start +.section .text.boot +_start: + mrs r0, cpsr + orr r0, r0, #0x80 + msr cpsr_c, r0 //Disable IRQs + //Flush instruction cache + mov r0, #0 + mcr p15, 0, r0, c7, c5, 0 + + //Use nintendos data cache flusher here, because I don't want to reverse it + ldr r0, =0xFFFF0830 + blx r0 + + //Disable caches and MPU + mrc p15, 0, r0, c1, c0, 0 //read + bic r0, r0, #(1<<12) //Disable instruction cache + bic r0, r0, #(1<<2) //Disable data cache + bic r0, r0, #(1<<0) //disable mpu + mcr p15, 0, r0, c1, c0, 0 //write + + //clear caches again + mov r0, #0 + mcr p15, 0, r0, c7, c5, 0 + ldr r0, =0xFFFF0830 + blx r0 + + ldr sp, =kernel_stack //set stack + + //Configure ITCM to…something + mrc p15, 0, r0, c9, c1, 1 + bic r0, #0b111110 + orr r0, #0b100010 + mcr p15, 0, r0, c9, c1, 1 + + //Configure DTCM to address 0x30000000 + mrc p15, 0, r0, c9, c1, 0 + bic r0, #0b111110 + orr r0, #0b001010 + ldr r1, =0xFFFFF000 + bic r0, r1 + ldr r1, =0x30000000 + orr r0, r1 + mcr p15, 0, r0, c9, c1, 0 + + //Enable both + mrc p15, 0, r0, c1, c0, 0 + orr r0, r0, #(1<<18) + bic r0, r0, #(1<<17) + orr r0, r0, #(1<<16) + mcr p15, 0, r0, c1, c0, 0 + + //Give RW permissions to all memory regions + ldr r0, =0x33333333 + mcr p15, 0, r0, c5, c0, 2 //Write Data + mcr p15, 0, r0, c5, c0, 3 //Write instructions + + //Set MPU and caching + ldr r0, =0xFFFF001F // ffff0000 64k bootrom + ldr r1, =0x3000001B // 30000000 16k dtcm + ldr r2, =0x00000035 // 00000000 128M ITCM + ldr r3, =0x08000029 // 08000000 2M arm9 mem + ldr r4, =0x10000029 // 10000000 2M IO mem + ldr r5, =0x20000037 // 20000000 256M fcram + ldr r6, =0x1FF00027 // 1FF00000 1M DSP + ldr r7, =0x1800002D // 18000000 8M VRAM + mcr p15, 0, r0, c6, c0, 0 + mcr p15, 0, r1, c6, c1, 0 + mcr p15, 0, r2, c6, c2, 0 + mcr p15, 0, r3, c6, c3, 0 + mcr p15, 0, r4, c6, c4, 0 + mcr p15, 0, r5, c6, c5, 0 + mcr p15, 0, r6, c6, c6, 0 + mcr p15, 0, r7, c6, c7, 0 + mov r0, #0b10101001 // unprot | arm9 | fcram | VRAM + mcr p15, 0, r0, c2, c0, 0 // Data cacheable + mcr p15, 0, r0, c2, c0, 1 // Instruction cacheable + mcr p15, 0, r0, c3, c0, 0 // Data bufferable + + // Enable MPU and caching + mcr p15, 0, r0, c3, c0, 0 + orr r0, r0, #(1<<12) + orr r0, r0, #(1<<2) + orr r0, r0, #(1<<0) + mcr p15, 0, r0, c1, c0, 0 + + //Start start + blx start + +.section .bss +.space 16384 +kernel_stack: diff --git a/kernel/hw/3ds9/config.py b/kernel/hw/3ds9/config.py index 3c38403..62eb5b8 100644 --- a/kernel/hw/3ds9/config.py +++ b/kernel/hw/3ds9/config.py @@ -1 +1,5 @@ config["ENABLE_EXTRA_MEMORY"] = get_yes_no("Enable 512KB of memory on n3DS", True) +add_driver(True, "framebuffer") +add_driver(False, "picafb") +print("Enable complete Unicode font: NO (because of the size)") +config["ENABLE_FRAMEBUFFER_UNICODE"] = False diff --git a/kernel/hw/3ds9/picafb/picafb.cpp b/kernel/hw/3ds9/picafb/picafb.cpp new file mode 100644 index 0000000..2c43f93 --- /dev/null +++ b/kernel/hw/3ds9/picafb/picafb.cpp @@ -0,0 +1,13 @@ +#include "picafb.hpp" +#include +PICAfb::PICAfb() : Framebuffer(25, 20) {} +PICAfb::~PICAfb() {} +auto PICAfb::plotPixel(int x, int y, int col) -> void { + unsigned char *lfb = (unsigned char *)0x18300000 + 0x46500; + // XXX I know it's rotated. But I need more vertical space than horizonal space. + int off = (y * 240 + x) * 3; + for (int i = 0; i < 3; i++) { + lfb[off++] = col; + col >>= 8; + } +} diff --git a/kernel/hw/3ds9/picafb/picafb.hpp b/kernel/hw/3ds9/picafb/picafb.hpp new file mode 100644 index 0000000..068999b --- /dev/null +++ b/kernel/hw/3ds9/picafb/picafb.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "../../framebuffer/framebuffer.hpp" +/** + * Framebuffer for the 3ds + */ +class PICAfb : public Framebuffer { + protected: + virtual auto plotPixel(int x, int y, int col) -> void; + + public: + PICAfb(); + virtual ~PICAfb(); +};