Author Topic: Problem about dd instruction  (Read 19486 times)

Offline VishalPawale

  • Jr. Member
  • *
  • Posts: 10
  • Country: in
Problem about dd instruction
« on: December 12, 2011, 03:46:33 PM »
Hi guys,

what does following instructions do????

     dd gdt
gdt
    ;something goes here

so does here dd acts as jmp instruction???

« Last Edit: December 12, 2011, 04:51:12 PM by VishalPawale »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problem about dd instruction
« Reply #1 on: December 12, 2011, 10:05:16 PM »
No, "dd" just declares a dword (32 bits) of data. Unless the label "gdt" is a coincidence, you're probably looking at something like...

Code: [Select]
gdtr:
    dw 23 ; ? size of gdt - 1
    dd gdt ; physical(!) address of gdt
gdt:
    dd   0, 0
    dd   0x0000ffff,0x00cf9a00
    dd   0x0000ffff,0x00cf9200
; maybe more descriptors?

Rather than a "jmp", this would be used as:
Code: [Select]
    lgdt [gdtr]

The "trick", besides getting the descriptors right (these are arbitrary), is that the address of gdt in gdtr must be a physical address, not the usual offset:segment address that we encounter almost everyplace else. Happy rebootin'!

Best,
Frank


Offline VishalPawale

  • Jr. Member
  • *
  • Posts: 10
  • Country: in
Re: Problem about dd instruction
« Reply #2 on: December 13, 2011, 06:39:16 AM »
Hi Frank,


Code: [Select]
gdtr:
    dw 23 ; ? size of gdt - 1
    dd gdt ; physical(!) address of gdt
gdt:
    dd   0, 0
    dd   0x0000ffff,0x00cf9a00
    dd   0x0000ffff,0x00cf9200
; maybe more descriptors?

so here instruction   
   dd gdt

will give physical address of label gdt right?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problem about dd instruction
« Reply #3 on: December 13, 2011, 07:27:50 AM »
Well, no - just an offset... which may be the physical address, depending on where the code is loaded. In a bootsector, with "org 0x7C00", it's the physical address (if the code hasn't been moved). If it's in a .com file, it will have to be adjusted by "segment * 16" at runtime - Nasm doesn't know in which sector dos has chosen to load our file, only that it's loaded at an offset of 0x100 into that segment.

What are you trying to do? (edit) Same thing as last time, back in September?

Best,
Frank

« Last Edit: December 13, 2011, 07:39:30 AM by Frank Kotler »

Offline VishalPawale

  • Jr. Member
  • *
  • Posts: 10
  • Country: in
Re: Problem about dd instruction
« Reply #4 on: December 13, 2011, 07:51:46 AM »
Hi,


Ok, actually due to college I did not get time to work on it, so now this time I am trying to build it in two stages, now I am able load second file but have a doubt about "dd gdt " instruction and address or position of gdt in my code......

And also do you know how to make .iso (just trying) in linux of our nasm generated binary code?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problem about dd instruction
« Reply #5 on: December 13, 2011, 08:06:29 AM »
Okay... back in September we were padding the "first stage" out to 512 bytes, followed by the "second stage", and loading the second stage to 7E00h. If that's still what you're doing, "dd gdt" ought to be the correct(?) physical address.

I've made an .iso in Linux, but to be honest I forget just how it went. Try "man mkisofs", and see if that helps...

Best,
Frank


Offline VishalPawale

  • Jr. Member
  • *
  • Posts: 10
  • Country: in
Re: Problem about dd instruction
« Reply #6 on: December 13, 2011, 08:20:20 AM »

No, I made it but by different way so now this time I am able to load my second file in memory.

But actually I have out about what should be the address of GDT, otherwise I can initialize them anywhere in the code, but does it gonna create problems ahead, I mean where should I put the code for GDT?

Okay I will try "man mkisofs"

Also I tried putting int 15h with function 8300 and 86h for adding timer instead of putting manual delay but int 15h doesnt work any suggestions..???

Thanks.
« Last Edit: December 13, 2011, 08:25:38 AM by VishalPawale »

Offline avcaballero

  • Full Member
  • **
  • Posts: 133
  • Country: es
    • Abre los Ojos al Ensamblador
Re: Problem about dd instruction
« Reply #7 on: December 13, 2011, 11:19:35 AM »
Maybe you want access BIOS time data, for example. Intercepting interruptions, accessing PIT, ...

http://www.abreojosensamblador.net/Productos/AOE/html/Pags_en/Chap17.html

Excuse me, my english is not excellent  :-\

Offline VishalPawale

  • Jr. Member
  • *
  • Posts: 10
  • Country: in
Re: Problem about dd instruction
« Reply #8 on: December 13, 2011, 09:16:03 PM »
Maybe you want access BIOS time data, for example. Intercepting interruptions, accessing PIT, ...

http://www.abreojosensamblador.net/Productos/AOE/html/Pags_en/Chap17.html

Excuse me, my english is not excellent  :-\


Thanks Buddy,
It's really useful and working fine for me......:)



Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problem about dd instruction
« Reply #9 on: December 21, 2011, 10:10:12 PM »
Sorry for the delay - haven't been in the mood to reboot. Due to a brief power glitch, I rebooted into dos and tried out that int 15h/86h delay. A guy over on the AsmCommunity forum also told me that it doesn't work. Works for me...

Code: [Select]
org 100h

DELAY equ 5000000
DELAYHI equ DELAY >> 16
DELAYLO equ DELAY & 0FFFFh

section .text
mov cx, DELAYHI
mov dx, DELAYLO
mov ah, 86h
int 15h
ret

Haven't tried it from a bootsector, but it "should" work. I don't know what the problem is. If Alfonso's method works, that's probably better anyway (Thanks for that, and for the "hangman" example!). Once you switch to pmode, the BIOS methods won't work anyway, and you'll need that PIT information!

You should be able to put your gdt anywhere you want, as long as "dd gdt" points to it. I probably should have said "linear address" rather than "physical address" - same thing, until you enable paging. I have recently heard that the gdt should be aligned (16 bytes?), but I can't confirm that. Shouldn't hurt.

Lots of information about gdt (and other OSish topics) at http://wiki.osdev.org - check it out if you're not familiar with it!

Best,
Frank


Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Problem about dd instruction
« Reply #10 on: December 22, 2011, 12:59:38 AM »
A guy over on the AsmCommunity forum also told me that it doesn't work. Works for me...

There are some notes about this function in Ralph Brown's Interrupt List.