From 742f388a00e3bfcb62d184e3f7d990908c6c96c6 Mon Sep 17 00:00:00 2001 From: vetch Date: Tue, 22 Oct 2019 17:34:29 +0200 Subject: modify to use in new pipe_image --- RS-232 | 1 - kernel.c | 35 +++++++++++++++++------------------ pipe_image.c | 1 - 3 files changed, 17 insertions(+), 20 deletions(-) delete mode 160000 RS-232 diff --git a/RS-232 b/RS-232 deleted file mode 160000 index 9016e7a..0000000 --- a/RS-232 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9016e7a369f9eab0525aaf9d7653a50de05011ea diff --git a/kernel.c b/kernel.c index c5918a1..3898cf2 100644 --- a/kernel.c +++ b/kernel.c @@ -12,19 +12,18 @@ void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags) // 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"); +// uart_getc(); + uint32_t ID_MMFR0; + // get contents of coprocessor register to check for paging support + asm("mrc p15, 0, %0, c0, c1, 4" : "=r" (ID_MMFR0)); - uint32_t ID_MMFR0; - // get contents of coprocessor register to check for paging support - asm("mrc p15, 0, %0, c0, c1, 4" : "=r" (ID_MMFR0)); +// uart_puts("Hello, kernel World!\r\n"); char *paging; 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 1 : paging = "implementation defined paging\n\r\r\n"; break; case 2 : paging = "VMSAv6, with cache and TLB type registers\n\r"; break; case 3 : paging = "VMSAv7, with support for remapping and access flag\n\r"; break; case 4 : paging = "VMSAv7 with PXN bit supported\n\r"; break; @@ -42,20 +41,20 @@ void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags) 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; + case 0x10 : mode = "User (PL0)\r\n"; break; + case 0x11 : mode = "FIQ (PL1)\r\n"; break; + case 0x12 : mode = "IRQ (PL1)\r\n"; break; + case 0x13 : mode = "Supervisor (PL1)\r\n"; break; + case 0x16 : mode = "Monitor (PL1)\r\n"; break; + case 0x17 : mode = "Abort (PL1)\r\n"; break; + case 0x1a : mode = "Hyp (PL2)\r\n"; break; + case 0x1b : mode = "Undefined (PL1)\r\n"; break; + case 0x1f : mode = "System (PL1)\r\n"; break; + default : mode = "Unknown mode\r\n"; break; } uart_puts(mode); - + while (1) uart_putc(uart_getc()); } diff --git a/pipe_image.c b/pipe_image.c index ab3568c..b52cec2 100644 --- a/pipe_image.c +++ b/pipe_image.c @@ -60,5 +60,4 @@ int main(int argc, char **argv) { bytes_left -= bytes_read; } RS232_CloseComport(comport); - } -- cgit v1.2.3 From dcd4da0d9386e2f48a1161b3464116c2ba90234f Mon Sep 17 00:00:00 2001 From: vetch Date: Tue, 5 Nov 2019 16:24:42 +0100 Subject: modified makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ec5a0e2..2ef48d5 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ qemu-elf : kernel.elf qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $^ qemu-bin : loader.elf kernel7.img pipe_image - ./pipe_image | qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $< + ./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 - -- cgit v1.2.3 From bff735a698a81067ad6a69ae520f3c93a5cec770 Mon Sep 17 00:00:00 2001 From: vetch Date: Tue, 12 Nov 2019 17:45:03 +0100 Subject: finalize Makefile for writing to rpi --- Makefile | 10 ++++++---- interrupts.c | 0 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 interrupts.c diff --git a/Makefile b/Makefile index bb8d06e..d6e8885 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CFLAGS=-mcpu=cortex-a7 -ffreestanding -std=gnu11 -Wall -Wextra -I. - ELFFLAGS=-ffreestanding -O2 -nostdlib -lgcc -I. + all : kernel7.img kernel.o : kernel.c @@ -10,6 +10,9 @@ kernel.o : kernel.c uart.o : uart.c arm-none-eabi-gcc $(CFLAGS) -c $^ -o $@ +interrupts.o : interrupts.c uart.o + arm-none-eabi-gcc $(CFLAGS) -c $^ -o $@ + boot.o : boot.S arm-none-eabi-as -mcpu=cortex-a7 $^ -o $@ @@ -48,9 +51,8 @@ qemu-bin : loader.elf kernel7.img pipe_image ./pipe_image --stdout | qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $< run-on-rpi : kernel7.img pipe_image - ./pipe_image --stdout | socat FILE:/dev/ttyUSB0,b115200,raw - - sleep 1 - screen /dev/ttyUSB0 115200,cs8,-parenb,-cstopb,-hupcl + ./pipe_image --stdout | sudo socat FILE:/dev/ttyUSB0,b115200,raw - +# screen /dev/ttyUSB0 115200,cs8,-parenb,-cstopb,-hupcl pipe_image : pipe_image.c lib/rs232/rs232.c gcc -Wall -std=gnu99 -O3 $^ -o $@ diff --git a/interrupts.c b/interrupts.c new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From d302f79c13df6ecaa63c477c6a811fa94996b7cb Mon Sep 17 00:00:00 2001 From: vetch Date: Tue, 12 Nov 2019 17:45:36 +0100 Subject: add interrupts; add some more content in pipe (commented out for now) --- interrupts.c | 15 +++++++++++++++ pipe_image.c | 21 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/interrupts.c b/interrupts.c index e69de29..3dc3d6f 100644 --- a/interrupts.c +++ b/interrupts.c @@ -0,0 +1,15 @@ +#include "uart.h" +/** + @brief The undefined instruction interrupt handler + + If an undefined instruction is encountered, the CPU will start + executing this function. Just trap here as a debug solution. +*/ +void __attribute__((interrupt("UNDEF"))) undefined_instruction_vector(void) +{ + uart_puts("Undefined instruction occured"); + while( 1 ) + { + /* Do Nothing! */ + } +} \ No newline at end of file diff --git a/pipe_image.c b/pipe_image.c index 03d2c8f..1266e90 100644 --- a/pipe_image.c +++ b/pipe_image.c @@ -50,7 +50,7 @@ int main(int argc, const char **argv) { const int comport=16; if (!stdout_instead_of_uart) - if (RS232_OpenComport(comport, 115200, "8N1", 0) == 1) + if (RS232_OpenComport(comport, 115200, "8N1", 1) == 1) err(-1, "Error opening comport"); uint32_t image_size_le = htole32(image_size); @@ -63,7 +63,7 @@ int main(int argc, const char **argv) { else { if (RS232_SendBuf(comport, (unsigned char*) &image_size_le, 4) - == 1) + == -1) err(-1, "error writing number to serial"); } @@ -84,12 +84,27 @@ int main(int argc, const char **argv) { } else { - if (RS232_SendBuf(comport, buf, bytes_read) == 1) + if (RS232_SendBuf(comport, buf, bytes_read) == -1) err(-1, "error writing to serial"); } bytes_left -= bytes_read; } +/* + while(1){ + int bytes_read=read(0,buf,sizeof(buf)); + if (stdout_instead_of_uart) + { + if (fwrite((unsigned char*) buf, bytes_read, 1, stdout) != 1) + err(-1, "error writing to stdout"); + } + else + { + if (RS232_SendBuf(comport, buf, bytes_read) == 1) + err(-1, "error writing to serial"); + } + } + */ if (!stdout_instead_of_uart) RS232_CloseComport(comport); -- cgit v1.2.3