OSDever Kernel Error with NASM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
ChosenOreo
Member
Member
Posts: 25
Joined: Sun May 29, 2011 5:16 pm
Location: Inside A Computer
Contact:

OSDever Kernel Error with NASM

Post by ChosenOreo »

I followed the kernel tutorial at http://www.osdever.net/bkerndev/Docs/basickernel.htm, and I recieved the two errors:

Code: Select all

start.asm:20: error: symbol 'MULTIBOOT_HEADER_MAGIC' undefined
start.asm:24: error: symbol 'MULTIBOOT_HEADER_MAGIC' undefined
My Assembly code is as follows:

Code: Select all

; This is the kernel's entry point. We could either call main here,
; or we can use this to setup the stack or other nice stuff, like
; perhaps setting up the GDT and segments. Please note that interrupts
; are disabled at this point: More on interrupts later!
[BITS 32]
global start
start:
    mov esp, sys_stack     ; This points the stack to our new stack area
    jmp stublet

; This part MUST be 4byte aligned, so we solve that issue using 'ALIGN 4'
ALIGN 4
mboot:
    ; Multiboot macros to make a few lines later more readable
    MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end

    ; This is the GRUB Multiboot header. A boot signature
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM
    
    ; AOUT kludge - must be physical addresses. Make a note of these:
    ; The linker script fills in the data for these ones!
    dd mboot
    dd code
    dd bss
    dd end
    dd start

; This is an endless loop here. Make a note of this: Later on, we
; will insert an 'extern _main', followed by 'call _main', right
; before the 'jmp $'.
stublet:
    jmp $


; Shortly we will add code for loading the GDT right here!


; In just a few pages in this tutorial, we will add our Interrupt
; Service Routines (ISRs) right here!



; Here is the definition of our BSS section. Right now, we'll use
; it just to store the stack. Remember that a stack actually grows
; downwards, so we declare the size of the data before declaring
; the identifier '_sys_stack'
SECTION .bss
    resb 8192               ; This reserves 8KBytes of memory here
sys_stack:
Any Help?

-ChosenOreo
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: OSDever Kernel Error with NASM

Post by bluemoon »

Code: Select all

nasm -felf -o a.o a.nasm
I copy&paste exactly your code and see no error. I'm using nasm on mac, NASM version 2.09.02 compiled on Sep 17 2010
What's your nasm version?
User avatar
ChosenOreo
Member
Member
Posts: 25
Joined: Sun May 29, 2011 5:16 pm
Location: Inside A Computer
Contact:

Re: OSDever Kernel Error with NASM

Post by ChosenOreo »

I'm using NASM on Xubuntu 11.04 Natty Narwhal

My version is 2.09.04 - Compiled Nov 26 2010

I compiled it with:

Code: Select all

nasm -f aout -o start.o start.asm
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: OSDever Kernel Error with NASM

Post by Brendan »

Hi,

I can't see a problem, and because bluemoon didn't have a problem either it makes me wonder if the problem can't be seen.

For example, sometimes when you copy & paste from a web page you get strange white-space characters (like the "non-breaking space" character, and the '\r' linefeed character) and (especially if your text editor supports Unicode) you end up with the strange white-space characters in your source code; and some tools don't like them.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
ChosenOreo
Member
Member
Posts: 25
Joined: Sun May 29, 2011 5:16 pm
Location: Inside A Computer
Contact:

Re: OSDever Kernel Error with NASM

Post by ChosenOreo »

I typed it letter by letter... I wonder if I missed something. I'll try copying the code over, and I'll see if it works!
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: OSDever Kernel Error with NASM

Post by Chandra »

ChosenOreo wrote:I typed it letter by letter...
which makes me guess that you mistyped the macro MULTIBOOT_HEADER_MAGIC. All you have to do now is to copy and paste the whole code and see if that works :lol:
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
ChosenOreo
Member
Member
Posts: 25
Joined: Sun May 29, 2011 5:16 pm
Location: Inside A Computer
Contact:

Re: OSDever Kernel Error with NASM

Post by ChosenOreo »

Nope, same error...
What is going on...
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OSDever Kernel Error with NASM

Post by neon »

bah, just replace MULTIBOOT_HEADER_MAGIC on lines 20 and 24 with 0x1BADB002....And dont copy and paste anymore. Alternatively use a %define.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: OSDever Kernel Error with NASM

Post by Brendan »

Hi,
ChosenOreo wrote:Nope, same error...
What is going on...
I cut & pasted it and assembled it "as is" with no errors; using NASM 2.09.04 under Gentoo, and "nasm -f aout -o start.o start.asm".

Maybe your makefile is assembling an old/different version or something.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply