-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
373 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,43 @@ | ||
/****************************************************************************** | ||
* kernel.ld | ||
* by Alex Chadwick | ||
* | ||
* A linker script for generation of raspberry pi kernel images. | ||
******************************************************************************/ | ||
|
||
SEARCH_DIR("=/usr/lib/arm-none-eabi/lib"); | ||
|
||
SECTIONS { | ||
/* | ||
* INFO: 0x10000 for QEMU and 0x8000 for raspi2 | ||
*/ | ||
__start = 0x8000; | ||
.init 0x8000 : { | ||
*(.init) | ||
/* Loader section that boots and setup the mmu before going into virtual | ||
* addressing | ||
*/ | ||
. = 0x8000; | ||
__start = .; | ||
.init : { | ||
build/loader.o(.text* .data* .bss* .rodata*) | ||
} | ||
|
||
__text_start = .; | ||
.text : | ||
{ | ||
KEEP(*(.text.boot)) | ||
*(.text) | ||
.initsys : { | ||
build/initsys.o(.text* .data* .bss* .rodata*) | ||
} | ||
. = ALIGN(4096); | ||
__text_end = .; | ||
|
||
__rodata_start = .; | ||
.rodata : | ||
{ | ||
*(.rodata) | ||
} | ||
. = ALIGN(4096); | ||
__rodata_end = .; | ||
|
||
__data_start = .; | ||
.data : | ||
{ | ||
*(.data) | ||
__kernel_phy_start = ALIGN(4k); | ||
.text (__kernel_phy_start + 0xf0000000) : AT(__kernel_phy_start) { | ||
*(.text*) | ||
} | ||
. = ALIGN(4096); | ||
__data_end = .; | ||
__bss_start = .; | ||
.bss : | ||
{ | ||
bss = .; | ||
*(.bss) | ||
. = ALIGN(4K); | ||
.rodata : { | ||
*(.rodata*) | ||
} | ||
. = ALIGN(4096); | ||
__bss_end = .; | ||
__end = .; | ||
. = ALIGN(4K); | ||
.data : { | ||
*(.data) | ||
} | ||
. = ALIGN(4K); | ||
.bss : { | ||
__kernel_bss_start = ABSOLUTE(.); | ||
*(.bss) | ||
*(COMMON) | ||
__kernel_bss_end = ABSOLUTE(.); | ||
} | ||
. = ALIGN(4K); | ||
__ramfs_start = .; | ||
.fs : { | ||
build/fs.img(.data*) | ||
} | ||
__kernel_phy_end = . - 0xf0000000; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,43 @@ | ||
/****************************************************************************** | ||
* kernel.ld | ||
* by Alex Chadwick | ||
* | ||
* A linker script for generation of raspberry pi kernel images. | ||
******************************************************************************/ | ||
|
||
SEARCH_DIR("=/usr/lib/arm-none-eabi/lib"); | ||
|
||
SECTIONS { | ||
/* | ||
* INFO: 0x10000 for QEMU and 0x8000 for raspi2 | ||
*/ | ||
__start = 0x10000; | ||
.init 0x10000 : { | ||
*(.init) | ||
/* Loader section that boots and setup the mmu before going into virtual | ||
* addressing | ||
*/ | ||
. = 0x10000; | ||
__start = .; | ||
.init : { | ||
build/loader.o(.text* .data* .bss* .rodata*) | ||
} | ||
|
||
__text_start = .; | ||
.text : | ||
{ | ||
KEEP(*(.text.boot)) | ||
*(.text) | ||
.initsys : { | ||
build/initsys.o(.text* .data* .bss* .rodata*) | ||
} | ||
. = ALIGN(4096); | ||
__text_end = .; | ||
|
||
__rodata_start = .; | ||
.rodata : | ||
{ | ||
*(.rodata) | ||
|
||
__kernel_phy_start = ALIGN(4k); | ||
.text (__kernel_phy_start + 0xf0000000) : AT(__kernel_phy_start) { | ||
*(.text*) | ||
} | ||
. = ALIGN(4096); | ||
__rodata_end = .; | ||
__data_start = .; | ||
.data : | ||
{ | ||
*(.data) | ||
. = ALIGN(4K); | ||
.rodata : { | ||
*(.rodata*) | ||
} | ||
. = ALIGN(4096); | ||
__data_end = .; | ||
__bss_start = .; | ||
.bss : | ||
{ | ||
bss = .; | ||
*(.bss) | ||
. = ALIGN(4K); | ||
.data : { | ||
*(.data) | ||
} | ||
. = ALIGN(4096); | ||
__bss_end = .; | ||
__end = .; | ||
. = ALIGN(4K); | ||
.bss : { | ||
__kernel_bss_start = ABSOLUTE(.); | ||
*(.bss) | ||
*(COMMON) | ||
__kernel_bss_end = ABSOLUTE(.); | ||
} | ||
. = ALIGN(4K); | ||
__ramfs_start = .; | ||
.fs : { | ||
build/fs.img(.data*) | ||
} | ||
__kernel_phy_end = . - 0xf0000000; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "stdint.h" | ||
#include "stddef.h" | ||
#include "mmu.h" | ||
|
||
#define KERNEL_TTB_ADDRESS 0x4000 | ||
|
||
extern int __kernel_phy_end; | ||
|
||
|
||
|
||
void init_map(uintptr_t from, uintptr_t to, uint32_t flags) { | ||
uintptr_t address_section = (KERNEL_TTB_ADDRESS | (uintptr_t)((from & 0xFFF00000) >> 18)); | ||
uint32_t value_section = (0xFFF00000 & to) | flags | SECTION; | ||
*((uint32_t*)(address_section)) = value_section; | ||
} | ||
|
||
void init_setup_ttb() { | ||
uintptr_t i; | ||
const int section_size = 0x00100000; | ||
for(i=0;i<0x80000000;i+=section_size) { // temporary linear mapping (deleted as soon as we enter real kernel mode) | ||
init_map(i,i,ENABLE_CACHE | ENABLE_WRITE_BUFFER | DC_CLIENT); | ||
} | ||
|
||
for(;i<0xbf000000;i+=section_size) { // physical ram mapping for kernel. | ||
init_map(i,i-0x80000000,ENABLE_CACHE | ENABLE_WRITE_BUFFER | DC_CLIENT); | ||
} | ||
|
||
for(;i<0xc0000000;i+=section_size) { // peripherals mapping | ||
#ifdef RPI2 | ||
init_map(i,i-0x80000000,DC_CLIENT); | ||
#else | ||
init_map(i,i-0x9f000000,DC_CLIENT); | ||
#endif | ||
} | ||
for(i=0xf0000000;i<0xf0000001+(uintptr_t)&__kernel_phy_end;i+=section_size) { // kernel data & code mapping | ||
init_map(i,i-0xf0000000,ENABLE_CACHE | ENABLE_WRITE_BUFFER | DC_CLIENT); | ||
} | ||
} | ||
|
||
int init_get_ram() { | ||
uint32_t* atags_ptr = (uint32_t*)0x100; | ||
|
||
#define ATAG_NONE 0 | ||
#define ATAG_CORE 0x54410001 | ||
#define ATAG_MEM 0x54410002 | ||
|
||
while (*(atags_ptr+1) != ATAG_NONE) { | ||
if (*(atags_ptr+1) == ATAG_MEM) { | ||
return *(atags_ptr+2); | ||
} | ||
atags_ptr += (*atags_ptr); | ||
} | ||
while(1){} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.