Ada Bare Bones: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
Added a note re gnat version numbers. |
m →GAS |
||
Line 416: | Line 416: | ||
<source lang="asm"> |
<source lang="asm"> |
||
.global startup # |
.global startup # Make the startup entry point symbol visible to the linker |
||
# Setup the Multiboot header (see GRUB docs for details) |
|||
.set ALIGN, 1<<0 # |
.set ALIGN, 1<<0 # Align loaded modules on page boundaries |
||
.set MEMINFO, 1<<1 # |
.set MEMINFO, 1<<1 # Provide memory map |
||
.set FLAGS, ALIGN | MEMINFO # |
.set FLAGS, ALIGN | MEMINFO # This is the Multiboot 'flag' field |
||
.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header |
.set MAGIC, 0x1BADB002 # 'magic number' lets your bootloader find the header |
||
.set CHECKSUM, -(MAGIC + FLAGS) # |
.set CHECKSUM, -(MAGIC + FLAGS) # Checksum required |
||
header: # Must be in the first 8kb of the kernel file |
|||
.align 4 |
|||
.align 4, 0x90 # Pad the location counter (in the current subsection) to a 4-byte |
|||
# (DWORD) storage boundary. The way alignment is specified can vary |
|||
# with host system architecture. |
|||
.long MAGIC |
.long MAGIC |
||
.long FLAGS |
.long FLAGS |
||
.long CHECKSUM |
.long CHECKSUM |
||
# |
# Reserve initial kernel stack space |
||
.set STACKSIZE, 0x4000 # |
.set STACKSIZE, 0x4000 # 0x4000 being 16k. |
||
.lcomm stack, STACKSIZE # Reserve 16k stack on a doubleword (32bit) boundary |
|||
# On my binutils the following line didn't work as the .lcomm instruction takes 2 parameters. |
|||
.comm mbd, 4 # Declare common symbol mbd, allocate it 4-bytes (DWORD) of |
|||
# uninitialized memory. |
|||
.comm |
.comm magic, 4 # Declare common symbol magic, allocate it 4-bytes (DWORD) of |
||
# uninitialized memory. |
|||
startup: |
startup: |
||
movl $(stack + STACKSIZE), %esp # |
movl $(stack + STACKSIZE), %esp # Set up the stack |
||
movl %eax, magic # Multiboot magic number |
|||
⚫ | |||
# The following saves the contents of the registers as they will likely be |
|||
# overwritten because main is not our actual entry point, Bare_Bones is. We |
|||
# will use these 2 symbols inside Bare_Bones. |
|||
movl %eax, magic # EAX indicates to the OS that it was loaded by a Multiboot-compliant boot |
|||
# loader |
|||
movl %ebx, mbd # EBX must contain the physical address of the Multiboot information |
|||
⚫ | |||
call main # Call main (created by gnatbind) |
|||
cli # Disable interrupts. then intentionally hang the system. |
|||
# CLI only affects the interrupt flag for the processor on which it is |
|||
# executed. |
|||
cli |
|||
hang: |
hang: |
||
hlt # |
hlt # Because the HLT instruction halts until an interrupt occurs, the |
||
# combination of a CLI followed by a HLT is used to intentionally hang |
|||
# the computer if the kernel returns. |
|||
# HLT is in a loop just in case a single HLT instruction fails to execute |
|||
# for some reason, (such as in the case of an NMI). |
|||
jmp hang |
jmp hang |
||
</source> |
</source> |