aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvetch <vetch97@gmail.com>2019-10-22 16:30:57 +0200
committervetch <vetch97@gmail.com>2019-10-22 16:30:57 +0200
commitd2b5a5f97b71c2966796f2287fda2bfd6cc531ec (patch)
tree06364df08dac547bee8c6882f1468540f91df7b6
parentf742223614e126c7d485a5bbcdb15b97e73055aa (diff)
parentc68891456e3b3c4ad37c36293413405151b87951 (diff)
downloadrpi-MMU-example-d2b5a5f97b71c2966796f2287fda2bfd6cc531ec.tar.gz
rpi-MMU-example-d2b5a5f97b71c2966796f2287fda2bfd6cc531ec.zip
Merge branch 'bob' of https://repo.or.cz/RPi-MMU-example into alice
-rw-r--r--Makefile8
-rw-r--r--kernel.c30
-rw-r--r--linker.ld3
-rw-r--r--loader_stage1.ld11
4 files changed, 47 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index b05600f..96a809a 100644
--- a/Makefile
+++ b/Makefile
@@ -44,11 +44,13 @@ loader.img : loader.elf
qemu-elf : kernel.elf
qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $^
-qemu-bin : loader.img kernel7.img pipe_image
+qemu-bin : loader.elf kernel7.img pipe_image
./pipe_image | qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $<
-qemu-loader : loader.img
- qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $^
+run-on-rpi : kernel7.img pipe_image
+ ./pipe_image | socat FILE:/dev/ttyUSB0,b115200,raw -
+ sleep 1
+ screen /dev/ttyUSB0 115200,cs8,-parenb,-cstopb,-hupcl
pipe_image : pipe_image.c RS-232/rs232.c
gcc -Wall -std=gnu99 -O3 $^ -o $@
diff --git a/kernel.c b/kernel.c
index f5a2b2e..c5918a1 100644
--- a/kernel.c
+++ b/kernel.c
@@ -8,6 +8,12 @@ void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
(void) atags;
uart_init();
+
+ // When we attach screen session after loading kernel with socat
+ // we miss kernel's greeting... So we'll make the kernel wait for
+ // one char we're going to send from within screen
+ uart_getc();
+
uart_puts("Hello, kernel World!\r\n");
uint32_t ID_MMFR0;
@@ -16,7 +22,7 @@ void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
char *paging;
- switch(ID_MMFR0 & 7) /* lowest 4 bits indicate VMSA support */ {
+ switch(ID_MMFR0 & 0xf) /* lowest 4 bits indicate VMSA support */ {
case 0 : paging = "no paging\n\r"; break;
case 1 : paging = "implementation defined paging\n\r"; break;
case 2 : paging = "VMSAv6, with cache and TLB type registers\n\r"; break;
@@ -27,6 +33,28 @@ void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
}
uart_puts(paging);
+
+ uint32_t CPSR;
+ // get content of current program status register to check the current
+ // processor mode
+ asm("mrs %0, cpsr" : "=r" (CPSR) :: "memory");
+
+ char *mode;
+
+ switch(CPSR & 0x1f) /* lowest 5 bits indicate processor mode */ {
+ case 0x10 : mode = "User (PL0)"; break;
+ case 0x11 : mode = "FIQ (PL1)"; break;
+ case 0x12 : mode = "IRQ (PL1)"; break;
+ case 0x13 : mode = "Supervisor (PL1)"; break;
+ case 0x16 : mode = "Monitor (PL1)"; break;
+ case 0x17 : mode = "Abort (PL1)"; break;
+ case 0x1a : mode = "Hyp (PL2)"; break;
+ case 0x1b : mode = "Undefined (PL1)"; break;
+ case 0x1f : mode = "System (PL1)"; break;
+ default : mode = "Unknown mode"; break;
+ }
+
+ uart_puts(mode);
while (1)
uart_putc(uart_getc());
diff --git a/linker.ld b/linker.ld
index c9a91df..e7bfdb8 100644
--- a/linker.ld
+++ b/linker.ld
@@ -9,8 +9,11 @@ SECTIONS
/* Since we're using a bootloader now, we can compile the kernel */
/* for 0x8000 and bootloader will load it properly (although it */
/* itself still has to be compiled for 0x10000) */
+ /* rpi-open-firmware, ont he other hand, loads kernel at 0x2000000 */
+ /* This issue is also to be avoided by the use of bootloader */
. = 0x8000;
/* For AArch64, use . = 0x80000; Unless this too is wrong in qemu… */
+
__start = .;
__text_start = .;
.text :
diff --git a/loader_stage1.ld b/loader_stage1.ld
index ce11095..507e367 100644
--- a/loader_stage1.ld
+++ b/loader_stage1.ld
@@ -6,8 +6,17 @@ SECTIONS
/* Warning! Internet says RPis in 32-bit mode load binary at 0x8000! */
/* My experiments do, however, show, that qemu emulating RPi2 */
/* loads it at 0x10000! (took some pain to find out) */
- . = 0x10000;
+
+ /* . = 0x10000; */
+
+ /* rpi-open-firmware, on the other hand, loads it at 0x2000000 */
+ /* (and this should be not-so-hard to change by modifying the */
+ /* firmware */
+
+ . = 0x2000000;
+
/* For AArch64, use . = 0x80000; Unless this too is wrong */
+
__start = .;
__text_start = .;
.text :