Point a struct to a specific address

Programming, for all ages and all languages.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

here is the EXACT code, compiler under GCC in a windows environment and executed on an actual computer.

Code: Select all

asm("cli; jmp _main; hlt;"); // pseudo hop from bootloader

#include "../Libraries/system.h" 

struct gdt_ptr 
{ 
    unsigned short limit; 
    unsigned int base; 
} __attribute__((packed)); 


struct gdt_ptr *pGDT; 

int main() 
{ 
    init_video(); // add basic video output suppor (printf)
    pGDT = 0x500; // move entire struct to 0x500
    pGDT->limit = 0x1234;  // add dummy val to 0x500
    pGDT->base = 0x5678;   // add dummy val to 0x502
    printf("%x | %x | %x \n", pGDT, &pGDT->limit, &pGDT->base); // produces 0x500,0x500,0x502
    printf("%x | %x \n", pGDT->limit, pGDT->base);  // produces 0x1234, 0x5678
    for (;;); // neverending loop
    return 0; // if something fails in the loop for some strange reason, return nil. 
}
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

JamesM wrote:Solar:

The code is changing a GDT. What makes you think it is designed to be run in a hosted environment?
I admit confusing 01000101 with the OP. I guess Alzheimer is getting worse faster than I thought.
Every good solution is obvious once you've found it.
Post Reply