From 0c0b353572da69a01b7f1b3d940b779ff9fcfb26 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 15 Oct 2019 16:57:45 +0200 Subject: adjust for rpi-open-firmware --- linker.ld | 3 +++ loader_stage1.ld | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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 : -- cgit v1.2.3 From c943016f54c6b68191def9acd5862dbf12e45b6c Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 15 Oct 2019 16:58:45 +0200 Subject: remove redundand 'qemu-loader' target --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 7632283..0a10ab6 100644 --- a/Makefile +++ b/Makefile @@ -44,9 +44,6 @@ qemu-elf : kernel.elf qemu-bin : loader.img 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 $^ - pipe_image : pipe_image.c gcc -Wall -std=gnu99 -O3 $^ -o $@ -- cgit v1.2.3 From 1e7a473c66acc37f25420f17e1f26a3ffbaa0439 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 15 Oct 2019 17:00:30 +0200 Subject: make sure qemu-bin command works even with loader compiled for other load address than qemu uses --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0a10ab6..4c3567e 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ 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 $< pipe_image : pipe_image.c -- cgit v1.2.3 From 4f8c9071fade1755793de63b015a13323254ffc7 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 15 Oct 2019 17:23:41 +0200 Subject: add Makefile rule for booting through uart on real rpi --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 4c3567e..f031d7c 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,11 @@ qemu-elf : kernel.elf qemu-bin : loader.elf kernel7.img pipe_image ./pipe_image | 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 gcc -Wall -std=gnu99 -O3 $^ -o $@ -- cgit v1.2.3 From 35fceb4649a142a9936355bfa090f8e8ce22f9fd Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 15 Oct 2019 17:26:58 +0200 Subject: delay greeting message in kernel --- kernel.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel.c b/kernel.c index 5960b15..555aa47 100644 --- a/kernel.c +++ b/kernel.c @@ -11,6 +11,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; -- cgit v1.2.3 From f2f81de9973b5a3028eb6cbbaf3942cc68446f9b Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 22 Oct 2019 16:28:47 +0200 Subject: check current execution mode --- kernel.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kernel.c b/kernel.c index 555aa47..b387a10 100644 --- a/kernel.c +++ b/kernel.c @@ -36,6 +36,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()); -- cgit v1.2.3 From c68891456e3b3c4ad37c36293413405151b87951 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 22 Oct 2019 16:30:15 +0200 Subject: check actual 4 bits that indicate paging support (3 were being checed b4) --- kernel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel.c b/kernel.c index b387a10..76b314d 100644 --- a/kernel.c +++ b/kernel.c @@ -25,7 +25,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; -- cgit v1.2.3