raspi3.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {
  2. Copyright (c) 1998-2022 by the Free Pascal development team
  3. Raspberry Pi 3 startup code for aarch64-embedded targets
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit raspi3;
  18. {$goto on}
  19. {$INLINE ON}
  20. interface
  21. implementation
  22. uses
  23. consoleio, mmio, mailbox, raspiuart, gpio;
  24. procedure _FPC_haltproc; assembler; nostackframe; public name '_haltproc';
  25. asm
  26. .Lhalt:
  27. wfe
  28. b .Lhalt
  29. end;
  30. function RaspiWrite(ACh: char; AUserData: pointer): boolean;
  31. begin
  32. UARTPuts(PeripheralBase, ACh);
  33. RaspiWrite := true;
  34. end;
  35. function RaspiRead(var ACh: char; AUserData: pointer): boolean;
  36. begin
  37. ACh := UARTGet(PeripheralBase);
  38. RaspiRead := true;
  39. end;
  40. {$ifndef CUSTOM_ENTRY}
  41. procedure PASCALMAIN; external name 'PASCALMAIN';
  42. var
  43. _stack_top: record end; external name '_stack_top';
  44. _bss_start: record end; external name '_bss_start';
  45. _bss_size: record end; external name '_bss_size';
  46. { This start makes sure we only execute on core 0 - the others will halt }
  47. procedure _FPC_start; assembler; nostackframe;
  48. label
  49. _start;
  50. asm
  51. .init
  52. .align 16
  53. .globl _start
  54. _start:
  55. // find core, only enable 0
  56. mrs x1, mpidr_el1
  57. and x1, x1, #3
  58. // cpu id > 0, stop
  59. cbz x1, .L2
  60. .L1:
  61. wfe
  62. b .L1
  63. .L2:
  64. // set up the stack
  65. ldr x0, .L_stack_top
  66. mov sp, x0
  67. // clear BSS here
  68. ldr x1, .L_bss_start
  69. ldr w2, .L_bss_size
  70. .L3:
  71. cbz w2, .L4
  72. str xzr, [x1], #8
  73. sub w2, w2, #1
  74. cbnz w2, .L3
  75. .L4:
  76. bl PASCALMAIN
  77. bl _FPC_haltproc
  78. .L_stack_top:
  79. .word _stack_top
  80. .L_bss_start:
  81. .word _bss_start
  82. .L_bss_size:
  83. .word _bss_size
  84. .text
  85. end;
  86. {$endif CUSTOM_ENTRY}
  87. begin
  88. UARTInit(PeripheralBase);
  89. OpenIO(Input, @RaspiWrite, @RaspiRead, fmInput, nil);
  90. OpenIO(Output, @RaspiWrite, @RaspiRead, fmOutput, nil);
  91. OpenIO(ErrOutput, @RaspiWrite, @RaspiRead, fmOutput, nil);
  92. OpenIO(StdOut, @RaspiWrite, @RaspiRead, fmOutput, nil);
  93. OpenIO(StdErr, @RaspiWrite, @RaspiRead, fmOutput, nil);
  94. end.