Page 1 of 1

BARE BONES file boot.s

Posted: Fri Jan 29, 2016 11:45 pm
by bilsch01
I converted BARE BONES file boot.s (see below) into NASM format (boot.asm below) as well as I could. I tried to assemble boot.asm (nasm boot.asm -o boot.o) and I get the error:

symbol `kernel_main' undefined

Of course. So why doesnt: (as boot.s -o boot.o) get the same error?. boot.s has the same undefined symbol yet it assembles fine.

BARE BONES 'as' format boot.s

.set ALIGN, 1<<0 # align loaded modules on page boundaries
.set MEMINFO, 1<<1 # provide memory map
.set FLAGS, ALIGN | MEMINFO # this is the Multiboot 'flag' field
.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .bootstrap_stack, "aw", @nobits
stack_bottom:
.skip 16384 # 16 KiB
stack_top:
.section .text
.global _start
.type _start, @function
_start:
call kernel_main
cli
hlt
.Lhang:
jmp .Lhang

.size _start, . - _start

NASM format: boot.asm:

FLAGS EQU 3
MAGIC EQU 0x1badb002
CHECKSUM EQU -(MAGIC + FLAGS)
SECTION .multiboot
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM
SECTION bootstrap_stack nobits
stack_bottom:
resb 16384 ; 16 KiB
stack_top:
SECTION .text
global _start
_start:
call kernel_main
cli
hlt
Lhang:
jmp Lhang
Thanks. Bill S.

Re: BARE BONES file boot.s

Posted: Sat Jan 30, 2016 12:57 am
by iansjack
kernel_main() should be defined in your kernel.c file. It sounds as if you are trying to build an executable just from boot.o and forgetting to produce, and link, kernel.o also. You need to use the -f elf switch with your nasm command.

Re: BARE BONES file boot.s

Posted: Sat Jan 30, 2016 2:15 am
by Roman
In GAS you don't have to define external symbols. In NASM you have to.

Code: Select all

extern kernel_main

Re: BARE BONES file boot.s

Posted: Sat Jan 30, 2016 3:19 am
by bilsch01
extern kernel_main - that's it ! thanks