general ISR for BareMetal

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
platatomi
Posts: 5
Joined: Sun May 06, 2012 3:53 pm

general ISR for BareMetal

Post by platatomi »

I been working on expanding BareMetal OS, starting with installing ISR's for the built-in functions that come with BareMetal (like screen output, string length, etc). I decide to use interrupt 0x90 (sounds like a good number) and the service routines are working fine, but I cannot find an efficient way to call the correct function based on the function number:

this is the structure the int 0x90 handler now:

Code: Select all


;RAX = function number

general_int:

cmp rax, 0
je some_function

cmp rax, 1
je another_function

;and so forth

iretq



How can do this more efficiently, without tons of comparisons?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: general ISR for BareMetal

Post by gerryg400 »

The normal way is to use a jump table. An array of addresses to jump to indexed by the function number.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: general ISR for BareMetal

Post by Nessphoro »

call [jumpTable+rax*8]
platatomi
Posts: 5
Joined: Sun May 06, 2012 3:53 pm

Re: general ISR for BareMetal

Post by platatomi »

Oh yeah, just like an array of function pointers in C. Thanks.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: general ISR for BareMetal

Post by Kazinsal »

Nessphoro wrote:call [jumpTable+rax*8]
This, but make sure you test to see if RAX is in the valid range for ISR functions.

So, if you have five functions, with RAX being 0-4, do a cmp rax, 4 ; ja .out_of_range (or something like that) so you don't execute garbage if someone calls your ISR with RAX being, say, 5.
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: general ISR for BareMetal

Post by IanSeyler »

Are there any advantages to this over the existing call table setup? It's nice to see people using the OS by the way!

-Ian
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
platatomi
Posts: 5
Joined: Sun May 06, 2012 3:53 pm

Re: general ISR for BareMetal

Post by platatomi »

Well, not really. It's probably more flexible if applications can use interrupts instead of depending on an exact address (in case things need to be moved in the future) to call system functions, however it works great either way. I just thought it would be fun to write ISRs, as im not quite at the full-fledged multitasking OS level yet.

I have to say, BareMetal is great! It's well comented and a great learning tool.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: general ISR for BareMetal

Post by bubach »

Your first ISR could be to get the calltable address then, to remove any assumtion. ;) And I have to agree, the OS looks great.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
Post Reply