Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

32 bit protected mode code at boot

Hello,
I am working on code that will switch to protected mode at boot time. I have gotten quite far, but it keeps crashing at one point. I have found it to be the line setting the IDT. I have been unable to find any information on it anywhere. I have used both NASM and the linux AS to compile it and neither generates a proper result. If it's neccessary to know I am loading my boot file at from another boot loader of mine. The boot loader works correctly loading the protected mode code at 0x0500. The following is an excerpt of the part of the file that is crashing with relevent defines. Thanks for any help!

Rory

*********** Excerpt ********************
# set up gdt and idt
# this next line is the one I'm having trouble with...
lidt idt_48 # load idt with 0,0
xorl %eax, %eax # Compute gdt_base
movw %ds, %ax # (Convert %ds:gdt)
shll $4, %eax
addl $gdt, %eax
movl %eax, (gdt_48+2)
lgdt gdt_48 # load gdt with whatever

# these next lines are found at the end of the file as defines
# Descriptor tables
gdt:
.word 0, 0, 0, 0 # dummy
.word 0, 0, 0, 0 # unused

.word 0xFFFF # 4Gb - (0x100000*0x1000)
.word 0 # base address = 0
.word 0x9A00 # code read/exec
.word 0x00CF # granularity = 4096, 386
# (+5th nibble of limit)

.word 0xFFFF # 4Gb - (0x100000*0x1000)
.word 0 # base address = 0
.word 0x9200 # data read/write
.word 0x00CF # granularity = 4096, 386
# (+5th nibble of limit)
idt_48:
.word 0 # idt limit = 0
.word 0, 0 # idt base = 0L
gdt_48:
.word 0x8000 # gdt limit=2048,
# 256 GDT entries

.word 0, 0 # gdt base

*********** End excerpt *************************

Comments

  • DariusDarius Member Posts: 1,666
    I don't know if having an empty IDT is such a good idea, it will definitely be a problem if an interrupt or exception happens along (so this code definitely won't work if you ever turn interrupts on).

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • GozarGozarianGozarGozarian Member Posts: 17
    : I don't know if having an empty IDT is such a good idea, it will definitely be a problem if an interrupt or exception happens along (so this code definitely won't work if you ever turn interrupts on).
    :
    : "We can't do nothing and think someone else will make it right."
    : -Kyoto Now, Bad Religion
    :
    :

    I started to get that impression, but wasn't sure. Do you have an example of a filled in IDT? Or a place to find a good example for NASM? I'm not very good at this yet. :)

    Thanks again,
    Rory
  • smaffysmaffy Member Posts: 20


    why dont you have a look at someone else code, and see how they did it. i mean, the thing you are writing have been written by hundreds of people before you. 54.3% of them will not care if you ripp their whole code. if YOU care, then dont ripp it - just take inspiration from it.

    http://home.swipnet.se/smaffy/snafu/snafu_01c.1.zip
    (ripp the whole thing and say that it was you who wrote it. i dont care.)
  • GozarGozarianGozarGozarian Member Posts: 17
    :
    :
    : why dont you have a look at someone else code, and see how they did it. i mean, the thing you are writing have been written by hundreds of people before you. 54.3% of them will not care if you ripp their whole code. if YOU care, then dont ripp it - just take inspiration from it.
    :
    : http://home.swipnet.se/smaffy/snafu/snafu_01c.1.zip
    : (ripp the whole thing and say that it was you who wrote it. i dont care.)
    :
    Wow. Thanks. That's more helpful than other code that I have seen. It keeps it simple and understandable too. That really helps me to get back on track with the protected mode and even the paging system.

    Thanks again,
    Rory
  • Shawn CarterShawn Carter Member Posts: 0

    _ // http://forcoder.org // free video tutorials and ebooks about { C++ Objective-C C# Delphi Ruby Java Perl Visual Basic Swift C PL/SQL Go Assembly JavaScript Scratch Python Visual Basic .NET PHP MATLAB R Awk Clojure LabVIEW F# Transact-SQL Scheme D ABAP VBScript ML Apex Logo Bash Lisp Hack COBOL Crystal Kotlin Alice Fortran Rust SAS Lua Dart Julia Prolog Erlang Ada Scala FoxPro } _

Sign In or Register to comment.