Higher half kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kiwipresse
Member
Member
Posts: 25
Joined: Sun Nov 04, 2007 7:41 am

Higher half kernel

Post by kiwipresse »

Hi,

I'm currently trying to write a higher half kernel based on this http://www.osdev.org/osfaq2/index.php/HigherHalfWithGdt.

However, everytime when I want so change segment selectors a triple fault occurs.


Here is the code:

Code: Select all

        .globl  start, _start
start:
_start:
	lgdt gdtr
	movw $0x10, %ax
	movw %ax, %ds

        hlt
	
multiboot_entry:
        movl    $(stack + STACK_SIZE), %esp
	
        pushl   $0
        popf
	
        pushl   %ebx
        pushl   %eax
	
        call    EXT_C(cmain)
	
     
loop:   hlt
        jmp     loop

	.section .setup
gdtr:
	.word gdt_end - gdt - 1
	.long gdt

gdt:
	.long 0, 0
	.byte 0xFF, 0xFF, 0, 0, 0, 0x9A, 0xCF, 0x40
	.byte 0xFF, 0xFF, 0, 0, 0, 0x92, 0xCF, 0x40
gdt_end:
nm output:

Code: Select all

c010002c T _start
00100006 n gdt
0010001e n gdt_end
00100000 n gdtr
...
c010002c T start
qemu output:
qemu: fatal: triple fault
EAX=00000010 EBX=0002daa0 ECX=00000001 EDX=00000001
ESI=00054729 EDI=0005472a EBP=00067eac ESP=00067e8c
EIP=00100039 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300
CS =0008 00000000 ffffffff 00cf9a00
SS =0010 00000000 ffffffff 00cf9300
DS =0010 00000000 ffffffff 00cf9300
FS =0010 00000000 ffffffff 00cf9300
GS =0010 00000000 ffffffff 00cf9300
LDT=0000 00000000 0000ffff 00008000
TR =0000 00000000 0000ffff 00008000
GDT= 00000000 00000000
IDT= 00000000 000003ff
CR0=60000011 CR2=00000000 CR3=00000000 CR4=00000000
...
kiwipresse
Member
Member
Posts: 25
Joined: Sun Nov 04, 2007 7:41 am

Post by kiwipresse »

Any hints? :(
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Any hints?
1:
GDT= 00000000 00000000
2:
Try using Bochs - It is by far easier for debugging.

3:
You bumped the thread after only one day. That not the right way of How To Ask Questions. If you can't bring up the patience to wait for an answer, you are statistically likely to not be able to bring up that same patience to thoroughly debug your code.

[edit]I can't read[/edit]
Last edited by Combuster on Tue Nov 06, 2007 7:23 am, edited 1 time in total.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Combuster wrote:3:
You bumped the thread after only 2 hours. That not the right way of How To Ask Questions. If you can't bring up the patience to wait for an answer, you are statistically likely to not be able to bring up that same patience to thoroughly debug your code.
Unless I'm missing something, that was 26 hours.
User avatar
JackScott
Member
Member
Posts: 1036
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Post by JackScott »

/me grabs out graphing calculator.
/me taps furiously for three minutes.

Yeah. It was 26 hours.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Nov 5 07 1 am was the first post, Nov 6 07 3 am was the second. 26 hours.

I'd say that's an alright time to wait to bump a thread.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

ok, the bumping of the thread is ok but still he has no answer. so i will give it a try. In your code a don't see any paging setup. did you do that? Where is cmain implemented. In short: can you provide more sources and information?
Author of COBOS
kiwipresse
Member
Member
Posts: 25
Joined: Sun Nov 04, 2007 7:41 am

Post by kiwipresse »

@os64dev: yes, your are right. no paging setup yet. paging is handled within the kmain function, however, to call this procedure I first need to jump to the 'higherhalf' symbol or something similiar.

Perhaps I made any mistakes when transforming from Intel -> AT&T syntax?
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

keep in mind that a higher half kernel needs to have paging as in general there is no memory available at the higher location.

I do it slightly different my bootloader loads the kernel.elf in the lower memory, sets up the paging for the highhalf kernel. Next parse the kernel.elf and copies the segments and then executes the kernel.
Author of COBOS
Post Reply