BARE BONES file boot.s

Programming, for all ages and all languages.
Post Reply
bilsch01
Member
Member
Posts: 42
Joined: Sat Dec 19, 2015 10:48 am

BARE BONES file boot.s

Post 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.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: BARE BONES file boot.s

Post 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.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: BARE BONES file boot.s

Post by Roman »

In GAS you don't have to define external symbols. In NASM you have to.

Code: Select all

extern kernel_main
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
bilsch01
Member
Member
Posts: 42
Joined: Sat Dec 19, 2015 10:48 am

Re: BARE BONES file boot.s

Post by bilsch01 »

extern kernel_main - that's it ! thanks
Post Reply