I am trying to enter pmode and execute some C-code i have linked to my bootsector program.
I have been disabling interrupts like crazy as you can see in my code.
[BITS 16]
[global start]
[extern load_kernel]
start:
jmp start_load
nop
resb 0x3E
start_load:
cli
cld
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov fs, ax
mov gs, ax
mov sp, 0x7bfe
cli
seta20.1:
in al, 0x64
test al, 2
jnz seta20.1
mov al, 0xD1
out 0x64, al
seta20.2:
in al, 0x64
and ax, byte 2
jnz seta20.2
mov al, 0xDF
out 0x60, al
cli
lgdt [gdt_ptr]
mov eax,cr0
inc eax
mov cr0,eax
cli
jmp 8:pmode
[BITS 32]
pmode:
mov ax, 0x10
mov ds, ax
mov es, ax
mov ss, ax
mov fs, ax
mov gs, ax
call load_kernel
the load_kernel() is just a while(1); as of now
i compile it with
nasm -f aout bootsector.asm
and the c-code with
gcc -c kernel_loader.c
then i link them together with
ld -T link.ld bootsector.o kernel_loader.o -o boot
and then i write the boot file to a floppy image (skipping the BPB though)
I use this link-script (link.ld)
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x7c00 : {
code = .; _code = .; __code = .;
*(.text)
}
.data : {
data = .; _data = .; __data = .;
*(.data)
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
}
end = .; _end = .; __end = .;
}
When run, Bochs just keep resetting indefinately with the following error.
(0) [0x00007c78] 0000:00007c78 (unk. ctxt): jmp 0008:7c7d ; ea7d7c0800
<bochs:30>
00000694946e[CPU ] jump_protected: gate type 0 unsupported
00000694946e[CPU ] exception(): 3rd (13) exception with no resolution, shutdown
status is 00h, resetting
Error: (0) print_guard_results: guard_found ? (stop reason 0)
Next at t=694946
(0) [0x00007c78] 0000:7c78 (unk. ctxt): jmp 0008:7c7d ; ea7d7c0800
It's the jmp 8:pmode-instruction that fails.. why?
If i remove it i can enter C.. but nothing seems to work properly.
Can anyone help me?
pmode is driving me crazy
Re:pmode is driving me crazy
I'm suprised that ld lets you link as you've got 16bit code at the start of the asm and ld is strictly 32bit
Pete
Pete
Re:pmode is driving me crazy
No idea, i ripped this from some website.
gdt:
; NULL descriptor
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0
LINEAR_DATA_SEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 92h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
LINEAR_CODE_SEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 9Ah ; present,ring 0,code,non-conforming,readable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
gdt_end:
gdt_ptr:
dw gdt_end - gdt - 1
dd gdt
Anything wrong with it?
gdt:
; NULL descriptor
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0
LINEAR_DATA_SEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 92h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
LINEAR_CODE_SEL equ $-gdt
dw 0FFFFh
dw 0
db 0
db 9Ah ; present,ring 0,code,non-conforming,readable
db 0CFh ; page-granular (4 gig limit), 32-bit
db 0
gdt_end:
gdt_ptr:
dw gdt_end - gdt - 1
dd gdt
Anything wrong with it?
Re:pmode is driving me crazy
Yes. You're trying to use a descriptor that's full of zeroes. That's why Bochs is saying "jump_protected: gate type 0 unsupported". Remove the 'unused descriptor' -- your code is trying to use it, when reall it should be using the one after it.
Actually, looking closer, your GDT bears no relation to the rest of your code. You're trying to jump to selector 0x08. Your code segment is at 0x18. I think what your descriptor should look like is:
1. Null (zeroes)
2. Linear code
3. Linear data
You can't rip a GDT from one website and some mode switching code from another website and expect them to work. Understand the code you've got, even if you didn't write it yourself.
Actually, looking closer, your GDT bears no relation to the rest of your code. You're trying to jump to selector 0x08. Your code segment is at 0x18. I think what your descriptor should look like is:
1. Null (zeroes)
2. Linear code
3. Linear data
You can't rip a GDT from one website and some mode switching code from another website and expect them to work. Understand the code you've got, even if you didn't write it yourself.
Re:pmode is driving me crazy
Ok, thanks for the advice.
I will start googling, and will not continue coding until I understand GDT-completely
I will start googling, and will not continue coding until I understand GDT-completely