Page 1 of 1
Interrupts do not work in real mode
Posted: Sun May 12, 2013 2:37 pm
by gabemaiberger
Hello, I cannot use interrupts in real mode after switching from protected mode
. I followed the instructions at
Real Mode but I fear I have overwritten the bios in memory. Here is the code for switching to real mode:
Code: Select all
realmode:
mov ebx, msgRealMode
call DisplayMessage
mov ebx, msgNWLN
call DisplayMessage
cli
jmp 0x28:switchrealmode
realidtr:
dw 0x3FF
dq 0
BITS 16
switchrealmode:
mov eax, 0x30
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
mov ss, eax
lidt [realidtr]
mov eax, cr0
and eax, 0
mov cr0, eax
jmp 0:gorealmode
gorealmode:
mov ax, 0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0xFFFF
sti
ret
Also, here is my gdt:
Code: Select all
NULL_DESC:
dd 0
dd 0
CODE_DESC:
dw 0xFFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
DATA_DESC:
dw 0xFFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
USERCODE_DESC:
dw 0xFFFF
dw 0
db 0
db 11111010b
db 11001111b
db 0
USERDATA_DESC:
dw 0xFFFF
dw 0
db 0
db 11110010b
db 11001111b
db 0
SIXTEENCODE_DESC:
dw 0xFFFF
dw 0
db 0
db 10011010b
db 00001111b
db 0
SIXTEENDATA_DESC:
dw 0xFFFF
dw 0
db 0
db 10010010b
db 00001111b
db 0
gdtend:
gdtr:
Limit dw gdtend-NULL_DESC-1
Base dd NULL_DESC
Re: Interrupts do not work in real mode
Posted: Sun May 12, 2013 2:40 pm
by AJ
Hi,
Have you reprogrammed the PIC's for protected mode and not changed them back? Have you got a null pointer somewhere that is causing the real mode IVT to be overwritten?
Cheers,
Adam
Re: Interrupts do not work in real mode
Posted: Sun May 12, 2013 2:42 pm
by gabemaiberger
No, I have not programmed the PIC's. Is my code to switch from pm to rm okay?
Re: Interrupts do not work in real mode
Posted: Sun May 12, 2013 4:11 pm
by Mikemk
It's best not to rely on real mode. The preferable method of interacting with hardware in pmode (in most cases) is direct hardware programming via registers. In some cases, such as for VBE, v8086 mode can be used, but those should be minimized.
Re: Interrupts do not work in real mode
Posted: Mon May 13, 2013 1:57 am
by Gigasoft
Try keeping SP even. You should also make sure that you haven't overwritten the IVT, BDA or EBDA.
Re: Interrupts do not work in real mode
Posted: Mon May 13, 2013 2:59 am
by freecrac
gabemaiberger wrote:
Code: Select all
realmode:
BITS 16
switchrealmode:
mov eax, 0x30
If we are using the directive for 16 bit code, then all followling instructions use a operandsize and/or addressize prefix for to to access 32 Bit register/operands/addresses.
Example:
66 B8 30 00 00 00 "mov eax, 0x30"
Code: Select all
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
mov ss, eax
But segmentregister have only a size of 16 bit, so it is recommended to use a 16 bit register for to move a 16 bit address to our segmentregisters like your instructions below in you listing.
Note: This is only a cosmetik thing and it does not change any byte of our code, so it give the same bytes "8E D8" if we use "mov ds,ax", or if we use a "mov ds,eax" .
Code: Select all
mov eax, cr0
and eax, 0
mov cr0, eax
Code: Select all
mov eax, cr0
and eax, not 1
mov cr0, eax
Dirk
Re: Interrupts do not work in real mode
Posted: Mon May 13, 2013 5:52 pm
by gabemaiberger
Hello again, nasm is giving me an error for the code
and that error is:
Code: Select all
./Code/System/kernel.asm:181: error: comma, colon or end of line expected
where line 181 is:
.
Re: Interrupts do not work in real mode
Posted: Mon May 13, 2013 9:27 pm
by Brendan
Hi,
gabemaiberger wrote:Hello again, nasm is giving me an error for the code
Try:
Or (to reduce code size):
Cheers,
Brendan
Re: Interrupts do not work in real mode
Posted: Mon May 13, 2013 11:12 pm
by freecrac
gabemaiberger wrote:Hello again, nasm is giving me an error for the code
and that error is:
Code: Select all
./Code/System/kernel.asm:181: error: comma, colon or end of line expected
where line 181 is:
.
Ups, i use this code with MASM and assemble it without an error. Good to know that NASM do not like it.
Dirk
Re: Interrupts do not work in real mode
Posted: Tue May 14, 2013 6:31 am
by Mikemk
freecrac wrote:Ups, i use this code with MASM and assemble it without an error. Good to know that NASM do not like it.
Dirk
NASM is not MASM
Re: Interrupts do not work in real mode
Posted: Tue May 14, 2013 3:58 pm
by gabemaiberger
Yay! My OS can shut down by me telling it to! The code works!