C++ Bare Bones: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
Use external linkage rather than stack, as in the C version of this tutorial.
Line 108:
<source lang="asm">
global loader ; making entry point visible to linker
global magic ; we will use this in kmain
global mbd ; we will use this in kmain
 
extern kmain ; kmain is defined in kmain.cpp
Line 135 ⟶ 137:
loader:
mov esp, stack + STACKSIZE ; set up the stack
push eax mov [magic], eax ; Multiboot magic number
push ebx mov [mbd], ebx ; Multiboot info structure
 
mov ebx, start_ctors ; call the constructors
Line 166 ⟶ 168:
 
align 4
magic: resd 1
stack:
mbd: resd 1
stack: resb STACKSIZE ; reserve 16k stack on a doubleword boundary
</source>
 
Line 191 ⟶ 194:
# reserve initial kernel stack space
.set STACKSIZE, 0x4000 # that is, 16k.
.commlcomm stack, STACKSIZE, 32 # reserve 16k stack on a quadworddoubleword boundary
.comm mbd, 4 # we will use this in kmain
.comm magic, 4 # we will use this in kmain
 
loader:
mov $(stack + STACKSIZE), %esp # set up the stack
pushmovl %eax, magic # Multiboot magic number
pushmovl %ebx, mbd # Multiboot data structure
 
mov $start_ctors, %ebx # call the constructors
Line 234 ⟶ 239:
 
<source lang="c">
#include <cstdint>
extern "C" void kmain( void* mbd, unsigned int magic )
 
extern "C" void kmain( void* mbd, unsigned int magic )
{
extern "C" uint32_t magic;
extern "C" void *mbd;
 
if ( magic != 0x2BADB002 )
{