Bona Fide OS Development
http://forums.osdever.net/

Declaring initialized data with NASM
http://forums.osdever.net/viewtopic.php?f=5&t=410
Page 1 of 1

Author:  RyanSchuster [ Thu Sep 09, 2010 9:57 pm ]
Post subject:  Declaring initialized data with NASM

Hello, World!

i'm only using assembly in my toy OS project, (not trying to be a badass or anything, i just think it's a fun way to learn 32 bit assembly coming from the 16 bit world of the 8086) and i'm working on my IDT now, so i have something like this for each entry:
Code:
;interrupt 00
;division by zero exception
    dw    0x0000            ;offset low word
    dw    0x0008            ;selector
    dw    0x8E00            ;present and ring 0
    dw    0x0000            ;offset upper word

i'd like to have the offset initialized when i assemble it rather than write it in as it runs, like this:
Code:
    dd    div_by_zero_handler

but the upper and lower words are split all topsy-turvy like. Reading through the NASM manual, it seems like what i want are the >> and & operators, but when i try
Code:
;interrupt 00
;division by zero exception
    dw    isr_00 & 0xFFFF        ;offset low word
    dw    0x0008            ;selector
    dw    0x8E00            ;present and ring 0
    dw    isr_00 >> 16 & 0xFFFF    ;offset upper word

NASM spits it back out saying "shift operator may only be applied to scalar values."

Kinda long post, but my question is this:
How can i initialize data using only the upper or lower word of an address?

Author:  RyanSchuster [ Wed Sep 22, 2010 6:07 pm ]
Post subject:  Re: Declaring initialized data with NASM

Sorry to double post, but...

i figured out that i did not want to initialize my IDT when i assembled it, as then i would have to initialize the entire IDT or mess around with the linker script to get another uninitialized section to go right after it which i would then have to fill with zeros anyway.

But if anyone knows how to extract the upper and lower words of addresses to initialize parts of data like that, i would still like to know how since it might be useful sometime.

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/