main.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2018 bzt (bztsrc@github)
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. */
  25. #include "uart.h"
  26. void main()
  27. {
  28. int size=0;
  29. char *kernel=(char*)0x80000;
  30. // set up serial console
  31. uart_init();
  32. // say hello. To reduce loader size I removed uart_puts()
  33. again:
  34. uart_send('R');
  35. uart_send('B');
  36. uart_send('I');
  37. uart_send('N');
  38. uart_send('6');
  39. uart_send('4');
  40. uart_send('\r');
  41. uart_send('\n');
  42. // notify raspbootcom to send the kernel
  43. uart_send(3);
  44. uart_send(3);
  45. uart_send(3);
  46. // read the kernel's size
  47. size=uart_getc();
  48. size|=uart_getc()<<8;
  49. size|=uart_getc()<<16;
  50. size|=uart_getc()<<24;
  51. // send negative or positive acknowledge
  52. if(size<64 || size>1024*1024) {
  53. // size error
  54. uart_send('S');
  55. uart_send('E');
  56. goto again;
  57. }
  58. uart_send('O');
  59. uart_send('K');
  60. // read the kernel
  61. while(size--) *kernel++ = uart_getc();
  62. // restore arguments and jump to the new kernel.
  63. asm volatile (
  64. "mov x0, x10;"
  65. "mov x1, x11;"
  66. "mov x2, x12;"
  67. "mov x3, x13;"
  68. // we must force an absolute address to branch to
  69. "mov x30, 0x80000; ret"
  70. );
  71. }