Untitled_Kernel/src/start.s

50 lines
1.9 KiB
ArmAsm
Raw Normal View History

//C main function for our kernel
//See: kernel.c
.extern kern_main
//This will be our entrypoint function name - gotta initialize it now as global so the linker knows later.
.global start
//multiboot for GRUB to boot it. Ideally stage01_bootloader will be able to support the multiboot standard.
//regardless of who's doing it, we have to set the required stuff
.set MB_MAGIC, 0x1BADB002 // bytes that bootloader will use to find this place
.set MB_FLAGS, (1 << 0) | (1 << 1) // flags request the following from the bootloader: maintain page boundaries + provide a memory map
.set MB_CHECKSUM, (0 - (MB_MAGIC + MB_FLAGS)) // Fails if checksum doesn't pass. Kind of arbitrary, but required.
//Now we actually place the multiboot stuff into the resulting executable...
.section .multiboot
.align 4 // 4 byte alignment
.long MB_MAGIC
.long MB_FLAGS
.long MB_CHECKSUM
// Set up for C code. Practically the only requirement for C-generated assembly to work properly is alignment and the presence of a stack.
.section .bss
.align 16
stack_bottom:
.skip 4096 // 4096 bytes (4kb) large stack. by skipping some amount of data (and eventually filling it with zeroes?), we've essentially just reserved space for our stack.
//Remember, stack grows DOWNWARD! So the last thing in the section -> the highest memory address -> the very first thing on the stack!
//Therefore, we put a label here to represent the top of our stack for later.
stack_top:
//Actual code. Entry point goes here!
.section .text
//Here it is!
start:
//Lets set up the stack. Stack grows downward on x86. We did the work earlier of defining where the top of the stack is, so just tell esp.
mov $stack_top, %esp //set the stack pointer
pushl %ebx
pushl %eax
//To C-land!
call kern_main
//You should never get here, but in case you do, we will just hang.
hang:
cli //Interrupts: off
hlt //Halt!
jmp hang //just in case...