Getting application base address in interrupt handler

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
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Getting application base address in interrupt handler

Post by Revelation »

I'm currently building interrupts for user application to call.

This code for example should print a message:

Code: Select all

[bits 32]
	call PrintMessage
	cli
	hlt

PrintMessage:
	mov eax, 0
        mov ecx, mes
        mov edx, 11  ; size
        int 0x30
	ret

mes db "ROFLMAO!!!!"
But as you can see ecx now contains only the offset of mes in the app. To print the message correctly I must know the base address. How can I find that from within my interrupt handler?
Now is the winter of my disk content.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Getting application base address in interrupt handler

Post by Craze Frog »

At the start of you app, put ORG WhereTheAppIsLoaded, and then make sure you load the app at that location in memory. Then the reference to mem should be correct.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Getting application base address in interrupt handler

Post by Love4Boobies »

If you want to use PIC (Position Independent Code), you might want to pass applications the base address for code and data segments in say, some register at startup. Things can get complicated, but just so you have an idea...
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Getting application base address in interrupt handler

Post by Revelation »

At the start of you app, put ORG WhereTheAppIsLoaded, and then make sure you load the app at that location in memory. Then the reference to mem should be correct.
I am talking about a dynamic system, so this is not an option.
If you want to use PIC (Position Independent Code), you might want to pass applications the base address for code and data segments in say, some register at startup. Things can get complicated, but just so you have an idea...
I am in protected mode, so my code segment is 0x08 and not a real mode segment. How does Linux or Windows do this? Do they make a new GDT entry?
Now is the winter of my disk content.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Getting application base address in interrupt handler

Post by Love4Boobies »

Revelation wrote:I am in protected mode, so my code segment is 0x08 and not a real mode segment. How does Linux or Windows do this? Do they make a new GDT entry?
I'm not really sure how you handle things. For instance, are you using a segmented memory model? Both Windows and Linux use the flat memory model, meaning that for all aplications, memory for both code and data starts at offset 0. When compared to the segmented memory model, yes, there is a penalty related to TLB flushes but the page technique makes the job SO MUCH easier for compilers as they can optimize a lot better and won't have to use PIC for everything. Besides creating a more friendly environment (it looks to the application as though it has the whole memory to itself), using virtual memory is easier this way as there won't be any problems if anyone needs to allocate more memory than its small 'segmented-memory segment'. So it's easier for the memory manager as well. The way they do this is using pages.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Getting application base address in interrupt handler

Post by Revelation »

Okay, so now it's really time to start implementing paging. Thanks!
Now is the winter of my disk content.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Getting application base address in interrupt handler

Post by Craze Frog »

How does Linux or Windows do this?
Just like I told you to do it. And with paging.

But if you just want to test your text printing function, this could probably work:

Code: Select all

   PUSH $
   CALL PrintMessage
   POP  eax
   CLI
   HLT

PrintMessage:
   MOV eax, 0
   MOV ecx, dword [esp+4]
   SUB ecx, dword [esp]
   LEA ecx, [mes+ecx+10]
   MOV edx, 11
   INT $30
RET

mes DB "ROFLMAO!!!!"
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Getting application base address in interrupt handler

Post by yemista »

i think you need some kind of message passing for it to work. in which cases would an interrupt need to read program data?
Post Reply