bootloader.asm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ;
  2. ; Copyright 2026 Aarav Ravindra Kharade
  3. ;
  4. ; Licensed under the Apache License, Version 2.0 (the "License");
  5. ; you may not use this file except in compliance with the License.
  6. ; You may obtain a copy of the License at
  7. ;
  8. ; http://www.apache.org/licenses/LICENSE-2.0
  9. ;
  10. ; Unless required by applicable law or agreed to in writing, software
  11. ; distributed under the License is distributed on an "AS IS" BASIS,
  12. ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ; See the License for the specific language governing permissions and
  14. ; limitations under the License.
  15. ;
  16. [BITS 16]
  17. [ORG 0x7C00]
  18. start:
  19. ; Set up segments
  20. xor ax, ax
  21. mov ds, ax
  22. mov es, ax
  23. mov ss, ax
  24. mov sp, 0x7C00
  25. ; Save boot drive passed in dl by the BIOS
  26. mov [boot_drive], dl
  27. ; Clear screen
  28. mov ah, 0x00
  29. mov al, 0x03
  30. int 0x10
  31. ; Print startup messages
  32. mov si, msg_start
  33. call print_string
  34. mov si, msg_key
  35. call print_string
  36. mov si, msg_drm
  37. call print_string
  38. mov si, msg_kernel
  39. call print_string
  40. ; Load Stage 2 from disk using LBA read
  41. mov dl, [boot_drive]
  42. mov ah, 0x42
  43. mov si, dap
  44. int 0x13
  45. jc disk_error
  46. ; Jump to Stage 2
  47. jmp 0x0000:0x7E00
  48. disk_error:
  49. mov si, msg_err
  50. call print_string
  51. halt:
  52. hlt
  53. jmp halt
  54. ; --- Functions ---
  55. print_string:
  56. mov ah, 0x0E ; Teletype output
  57. .loop:
  58. lodsb
  59. or al, al
  60. jz .done
  61. int 0x10
  62. jmp .loop
  63. .done:
  64. ret
  65. ; --- Data ---
  66. msg_start: db "Welcome to ArkOS Bootloader", 13, 10, 0
  67. msg_key: db "Checking Hardware Secure Key... OK", 13, 10, 0
  68. msg_drm: db "Loading DRM Module... OK", 13, 10, 0
  69. msg_kernel: db "Loading Kernel & Launching OS...", 13, 10, 0
  70. msg_err: db "Disk Error loading Stage 2!", 13, 10, 0
  71. boot_drive: db 0
  72. align 4
  73. dap:
  74. db 0x10 ; size of DAP
  75. db 0 ; zero
  76. dw 7 ; number of sectors to read
  77. dw 0x7E00 ; offset
  78. dw 0x0000 ; segment
  79. dq 34 ; LBA 34 (Stage 2 starts at sector 34 in hybrid GPT layout)
  80. times 446-($-$$) db 0
  81. ; Partition table placeholder (4 partitions * 16 bytes = 64 bytes)
  82. times 64 db 0
  83. ; Boot signature
  84. dw 0xAA55