start_gcc.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-07-16 JasonHu,GuEe-GUI first version
  9. */
  10. #define __ASSEMBLY__
  11. #include "multiboot2.h"
  12. # the size of stack is 16KB
  13. #define STACK_SIZE 0x4000
  14. #define KSTACK_TOP_PHY 0x9f000
  15. .code32
  16. .extern rt_boot_setup_entry, primary_cpu_entry
  17. .section .init
  18. .globl start, _start
  19. start:
  20. _start:
  21. jmp multiboot_entry
  22. .align 8
  23. multiboot_header:
  24. .long MULTIBOOT2_HEADER_MAGIC # magic number (multiboot 2)
  25. .long MULTIBOOT_ARCHITECTURE_I386 # architecture 0 (protected mode i386)
  26. .long multiboot_header_end - multiboot_header # header length
  27. # checksum
  28. .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
  29. # insert optional multiboot tags here
  30. # required end tag
  31. .align 8
  32. .short MULTIBOOT_HEADER_TAG_END # type
  33. .short 0 # flags
  34. .long 8 # size
  35. multiboot_header_end:
  36. multiboot_entry:
  37. # initialize the stack pointer
  38. movl $(stack + STACK_SIZE), %esp
  39. # reset EFLAGS
  40. pushl $0
  41. popf
  42. # push the pointer to the Multiboot information structure
  43. pushl %ebx
  44. # push the magic value
  45. pushl %eax
  46. # jump to rt_boot_setup_entry
  47. call rt_boot_setup_entry
  48. # jump to setup_fail if rt_boot_setup_entry return -1
  49. popl %eax
  50. cmpl $-1, %eax
  51. je setup_fail
  52. # set kernel stack top
  53. movl $KSTACK_TOP_PHY, %esp
  54. # jump to kernel_start
  55. movl $primary_cpu_entry, %eax
  56. jmp *%eax
  57. setup_fail:
  58. # print "Error!" in protected mode
  59. movl $0xcf72cf45, 0xb8000
  60. movl $0xcf6fcf72, 0xb8004
  61. movl $0xcf21cf72, 0xb8008
  62. multiboot_hlt:
  63. hlt
  64. jmp multiboot_hlt
  65. .comm stack, STACK_SIZE