1

I'm building a small os as a challenge for myself. I read many articles online saying that to override the interrupt vector table you need to change the physical address of 0000: interrupt number*4 and 0000: (interrupt number*4)+2. I wrote down a piece of code that does exactly that but when trying to run it on a virtual machine, nothing happens. Could any of you guys share their knowledge and tell what am I wrong at? this is my code:

mov ax,0
mov es,ax
mov ax,cs ;; set ax to the current segment
mov [es:01a6h], ax ;; change 0000:(interrupt number*4)+2
mov ax,interrupt1 ;; set ax to the offset of the interrupt  
mov [es:01a4h], ax ;; change 0000:(interrupt number*4)
int 69h
jmp $

this is the interrupt:

interrupt1: MOV ah,09h mov al,'c' ;;; its function is to write down the letter c in red mov bx,0004 MOV cx,1 int 10h iret

I am using nasm and Oracle Virtual box.

Elad Ezra
  • 33
  • 10
  • `0x69*4=0x1a4` in my calculator. – Jester Mar 14 '17 at 18:58
  • noticed that this is the code before i got that, i did fix it before and it didnt help – Elad Ezra Mar 14 '17 at 18:59
  • Make sure your `org` is set up correctly. Post a full [mcve]. – Jester Mar 14 '17 at 19:21
  • @Jester can you elaborate? I haven't used org at all since the boot loader of my os loads this to the next section of ram and jumps to it – Elad Ezra Mar 14 '17 at 19:27
  • I think i hit jackpot overhere, can I call an interrupt from inside another interrupt? – Elad Ezra Mar 14 '17 at 19:32
  • We don't know how the segments are set up because you didn't show it. As such, the assembler's idea of offsets might not match the actual values at runtime. You did not use an `org` so the assembler assumes offset 0, not segment 0 which is what you use. – Jester Mar 14 '17 at 19:37
  • @Jester ok, if i want to tell the assembler this code offset is 512 bytes after [ORG 0x7C00] how would I do that? – Elad Ezra Mar 14 '17 at 19:54
  • `org 0x7e00` of course. – Jester Mar 14 '17 at 23:10
  • @Jester one last question, can I use `int 10h` in my interrupt? – Elad Ezra Mar 15 '17 at 08:13
  • @EladEzra : I'd like to revisit this question. Your solution makes little sense UNLESS there is some other problem with your code (the _STI_ is masking some other issue IMHO). If you made available (add it as an update to the bottom of your question) the code for your bootloader (all the stages - sounds like you had at least 2 of them from your comments) it would allow us to determine what is really going on. I reiterate you don't need interrupts on to call an interrupt that contains another _INT_ call. You should be able to do `int 10h` inside `int 69h` with interrupts off (_CLI_) – Michael Petch Apr 26 '17 at 04:19
  • I no longer have that code... I have an updated version which is 500 lines long. If you want i can send you it by mail or somthing if youre interested... – Elad Ezra Apr 27 '17 at 11:47
  • Sure, you can email it to mpetch@gmail.com – Michael Petch Apr 27 '17 at 13:49

1 Answers1

0

apparently to use interrupts inside of interrupts you need to turn on the interrupt flag using sti, because it is disabled automatically

Elad Ezra
  • 33
  • 10
  • 4
    This is untrue. You need to turn on external interrupts with _STI_ for an external interrupt to fire. You do not need to turn on interrupts to initiate a software interrupt (like `int 10h`). – Michael Petch Mar 17 '17 at 16:14
  • Out of curiosity is there more to the code in the question. For instance did you happen to remap the PIC so that the master PIC was placed at interrupt 0x68? My assumption was that you had and you were intending to use `int 10h` to print a character each time the keyboard was pressed? – Michael Petch Apr 20 '17 at 14:09
  • I am actually building my own small os, i am using software interrupts as kernel... – Elad Ezra Apr 21 '17 at 15:17