diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | kernel.c | 30 | ||||
-rw-r--r-- | linker.ld | 3 | ||||
-rw-r--r-- | loader_stage1.ld | 11 |
4 files changed, 47 insertions, 5 deletions
@@ -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 $@ @@ -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()); @@ -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 : |