Why this code is crashing when call procedure in loop?

0

I tried to write own simple bootloader, I had this code:

.code16 # Generate 16 bit code

.globl set_protected_mode
.globl set_real_mode
__init:
call set_protected_mode
call set_real_mode
jmp __init

# jmp init # Jump to init function in init.c

set_real_mode:
cli
mov %cr0, %eax
and $0xfffffffe,%eax
mov %eax, %cr0
sti
jmp %cs:__set_another_mode_done

set_protected_mode:
cli # Disable interrupts
mov %cr0, %eax
or $0x1, %eax
mov %eax, %cr0
sti # Enable interrupts
jmp %cs:__set_another_mode_done

__set_another_mode_done:
ret # Back to calling function in protected or real mode

And It crashes after some time in protected mode.

I'm using GNU Assembler v2.24, Ubuntu 14.04 and testing in bochs.

Log from bochs:

00014944437e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
========================================================================
Event type: ERROR
Device: [CPU0 ]
Message: interrupt(): gate descriptor is not valid sys seg (vector=0x01)

Can anyone explain why it crashed?

Is there anything can I do to fix it?

assembly
x86
bootloader
protected-mode
bochs
asked on Stack Overflow Apr 7, 2016 by krystian71115 • edited Apr 7, 2016 by Jester

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0