tried adding arm9

This commit is contained in:
Morten Delenk 2017-04-29 21:06:24 +00:00
parent d91bab77a4
commit e5db9dfff1
8 changed files with 178 additions and 2 deletions

View file

@ -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("<H",f.read(2))[0] != 2:
raise Exception("Invalid ELF format")
if struct.unpack("<H",f.read(2))[0] != 0x28:
@ -31,7 +32,8 @@ def get_elf_seg(f): #Return entry,section_beg,section_size,section
section_size = 0
section = b''
for ent in range(no_ent):
if struct.unpack("<I",f.read(4)) != 1:
f.seek(phoff+ent*0x20)
if struct.unpack("<I",f.read(4))[0] != 1:
continue
off,vaddr,filesz,memsz=struct.unpack("<IIxxxxII",f.read(20))
section_begin = vaddr
@ -44,7 +46,7 @@ def get_elf_seg(f): #Return entry,section_beg,section_size,section
return (loadAddr,section_begin,section_size,section)
f1 = open(sys.argv[1],"rb")
f2 = open(sys.argv[2],"rb")
f3 = open(sys.argv[3],"wb")
f = open(sys.argv[3],"wb")
arm9_entry,arm9_section_beg,arm9_section_size,arm9_section = get_elf_seg(f1)
arm11_entry,arm11_section_beg,arm11_section_size,arm11_section = get_elf_seg(f2)
arm9_hash=hashlib.sha256(arm9_section).digest()

View file

@ -0,0 +1,3 @@
SET(PLATFORM_C_FLAGS "-I../../kernel/arch/arm/3ds9/include")
SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}")
SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}")

View file

@ -0,0 +1,36 @@
ENTRY(_start)
SECTIONS {
. = 0x08000100;
kernel_start = .;
.text : {
KEEP(*(.text.boot));
*(.text)
}
.data : {
start_ctors = .;
KEEP(*(.init_array));
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)));
KEEP(*(.ctors));
end_ctors = .;
start_dtors = .;
KEEP(*(.fini_array));
KEEP(*(.fini_array.*));
KEEP(*(.dtors));
end_dtors = .;
start_eh_frame = .;
KEEP(*(.eh_frame));
KEEP(*(.eh_frame.*));
QUAD(0);
KEEP(*(.gcc_except_table));
KEEP(*(.gcc_except_table.*));
*(.data)
}
.rodata : {
*(.rodata)
}
.bss : {
*(.bss)
*(COMMON)
}
kernel_end = .;
}

View file

@ -0,0 +1,11 @@
#include "../../../hw/3ds9/picafb/picafb.hpp"
#include <base.hpp>
#include <config.h>
PICAfb term;
void main();
extern "C" void start() { main(); }
void drivers_init() {
setMainTTY(&term);
--term;
}

View file

@ -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 tosomething
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:

View file

@ -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

View file

@ -0,0 +1,13 @@
#include "picafb.hpp"
#include <config.h>
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;
}
}

View file

@ -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();
};