Possible GDT issues

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.
DefinitelyNotMars
Posts: 7
Joined: Thu Dec 22, 2016 8:38 pm

Possible GDT issues

Post by DefinitelyNotMars »

Hello, I am trying to build a kernel targeting x86. My compiler is currently clang. I think I am stuck on working with the Global Descriptor Table. My current assembly code to load my C repeatedly crashes

Code: Select all

.set ALIGN,    1<<0             
.set MEMINFO,  1<<1
.set FLAGS,    ALIGN | MEMINFO
.set MAGIC,    0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)

.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM

.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

.section .data
_gdt:
.quad 0x0000000000000000
.quad 0x00CF9A000000FFFF
.quad 0x00CF92000000FFFF
.quad 0x00CFFA000000FFFF
.quad 0x00CFF2000000FFFF
_gdtr:
.word .-_gdt-1
.long _gdt


.section .text
.global _start
.type _start, @function
_start:


	lgdt _gdtr
	ljmp $0x08, $_code
	_code:
	mov $10, %ax
	mov %ax, %ds
	mov %ax, %fs
	mov %ax, %es
	mov %ax, %gs
	mov %ax, %ss

	mov $stack_top, %esp
	call kmain

	cli
lp:	hlt
	jmp lp

	setup_gdt:
		lgdt _gdtr
		ret

.size _start, . - _start
How can I narrow it down, or if this is a more common problem, what can I do to fix this?

EDIT: My software is currently loaded by GRUB
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Possible GDT issues

Post by Octocontrabass »

DefinitelyNotMars wrote:How can I narrow it down, or if this is a more common problem, what can I do to fix this?
I don't see any obvious bugs, but I'm not exactly fluent in AT&T syntax.

You can narrow it down if you're using an emulator like Bochs or qemu that will dump the CPU state when the emulated CPU crashes. The crash dump will include information like the instruction that causes the fault and the contents of the segment descriptor caches. If that's not enough, some emulators also include (or can connect to) debuggers that you can use to locate the problem.

And, of course, you can show us the steps you've taken to debug the problem and we might spot something you've overlooked.
DefinitelyNotMars
Posts: 7
Joined: Thu Dec 22, 2016 8:38 pm

Re: Possible GDT issues

Post by DefinitelyNotMars »

Thanks for replying. I installed bochs and set it up to boot my ISO file.

Code: Select all

(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000f0
is where it crashed I think. It would appear that I am executing outside of where I should be, am I correct?
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Possible GDT issues

Post by Octocontrabass »

That's the very first instruction the CPU executes after it powers on or resets. It looks like the Bochs debugger has halted there waiting for your input. If you don't want to run any particular debugger commands, press "c" and then enter to tell Bochs to keep going.
User avatar
sleephacker
Member
Member
Posts: 97
Joined: Thu Aug 06, 2015 6:41 am
Location: Netherlands

Re: Possible GDT issues

Post by sleephacker »

DefinitelyNotMars wrote:

Code: Select all

lgdt _gdtr
	ljmp $0x08, $_code
	_code:
	mov $10, %ax
	mov %ax, %ds
I don't know how your assembler handles numbers, but I think it should be:

Code: Select all

mov $0x10, %ax
mov %ax, %ds
because 10 in decimal is not a valid GDT selector.
If your GDT is loaded correctly, your data selector should be at offset 0x10 (hexadecimal).
DefinitelyNotMars
Posts: 7
Joined: Thu Dec 22, 2016 8:38 pm

Re: Possible GDT issues

Post by DefinitelyNotMars »

So, that was a bit of an embarrassing problem. I have fixed it but it still crashes, here's the bochsout.txt:

Code: Select all

00000000000i[      ] Bochs x86 Emulator 2.6.8
00000000000i[      ]   Built from SVN snapshot on May 3, 2015
00000000000i[      ] Compiled on Dec 25 2016 at 21:53:42
00000000000i[      ] System configuration
00000000000i[      ]   processors: 1 (cores=1, HT threads=1)
00000000000i[      ]   A20 line support: yes
00000000000i[      ]   load configurable MSRs from file "msrs.def"
00000000000i[      ] IPS is set to 50000000
00000000000i[      ] CPU configuration
00000000000i[      ]   SMP support: no
00000000000i[      ]   Using pre-defined CPU configuration: core2_penryn_t9600
00000000000i[      ] Optimization configuration
00000000000i[      ]   RepeatSpeedups support: yes
00000000000i[      ]   Fast function calls: yes
00000000000i[      ]   Handlers Chaining speedups: no
00000000000i[      ] Devices configuration
00000000000i[      ]   NE2000 support: yes
00000000000i[      ]   PCI support: yes, enabled=yes
00000000000i[      ]   SB16 support: yes
00000000000i[      ]   USB support: yes
00000000000i[      ]   VGA extension support: vbe cirrus
00000000000i[MEM0  ] allocated memory at 0x117d84000. after alignment, vector=0x117d84000
00000000000i[MEM0  ] 256.00MB
00000000000i[MEM0  ] mem block size = 0x00100000, blocks=256
00000000000i[MEM0  ] rom at 0xfffe0000/131072 ('/usr/local/Cellar/bochs/2.6.8/share/bochs/BIOS-bochs-latest')
00000000000i[      ] lt_dlhandle is 0x7fcccb0858b0
00000000000i[PLUGIN] loaded plugin libbx_hdimage.so
00000000000i[      ] lt_dlhandle is 0x7fcccb085c70
00000000000i[PLUGIN] loaded plugin libbx_soundmod.so
00000000000i[SNDLOW] Sound lowlevel module 'osx' initialized
00000000000i[SNDCTL] Installed sound driver 'osx' at index #0
00000000000i[      ] lt_dlhandle is 0x7fccc9d112f0
00000000000i[PLUGIN] loaded plugin libbx_pci.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d11840
00000000000i[PLUGIN] loaded plugin libbx_pci2isa.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d113a0
00000000000i[PLUGIN] loaded plugin libbx_usb_uhci.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d13f70
00000000000i[PLUGIN] loaded plugin libbx_usb_common.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d13b10
00000000000i[PLUGIN] loaded plugin libbx_acpi.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d14860
00000000000i[PLUGIN] loaded plugin libbx_cmos.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d14ee0
00000000000i[PLUGIN] loaded plugin libbx_dma.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d154c0
00000000000i[PLUGIN] loaded plugin libbx_pic.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d15900
00000000000i[PLUGIN] loaded plugin libbx_pit.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d15e50
00000000000i[PLUGIN] loaded plugin libbx_vga.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d161f0
00000000000i[PLUGIN] loaded plugin libbx_floppy.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d16940
00000000000i[PLUGIN] loaded plugin libbx_ioapic.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d16df0
00000000000i[PLUGIN] loaded plugin libbx_keyboard.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d174e0
00000000000i[PLUGIN] loaded plugin libbx_harddrv.so
00000000000i[      ] lt_dlhandle is 0x7fccc9d178b0
00000000000i[PLUGIN] loaded plugin libbx_pci_ide.so
00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method
00000000000i[DEV   ] i440FX PMC present at device 0, function 0
00000000000i[PLUGIN] init_dev of 'pci2isa' plugin device by virtual method
00000000000i[DEV   ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS  ] Using local time for initial clock
00000000000i[CMOS  ] Setting initial clock to: Mon Dec 26 19:56:24 2016 (time0=1482800184)
00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA   ] channel 4 used by cascade
00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'pit' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'vga' plugin device by virtual method
00000000000i[MEM0  ] Register memory access handlers: 0x0000000a0000 - 0x0000000bffff
00000000000i[VGA   ] interval=200000, mode=realtime
00000000000i[MEM0  ] Register memory access handlers: 0x0000e0000000 - 0x0000e0ffffff
00000000000i[BXVGA ] VBE Bochs Display Extension Enabled
00000000000i[XGUI  ] test_alloc_colors: 16 colors available out of 16 colors tried
00000000000i[XGUI  ] font 8 wide x 16 high, display depth = 24
00000000000i[MEM0  ] rom at 0xc0000/41472 ('/usr/local/Cellar/bochs/2.6.8/share/bochs/VGABIOS-lgpl-latest')
00000000000i[PLUGIN] init_dev of 'floppy' plugin device by virtual method
00000000000i[DMA   ] channel 2 used by Floppy Drive
00000000000i[FLOPPY] tried to open '/dev/fd0' read/write: No such file or directory
00000000000i[FLOPPY] tried to open '/dev/fd0' read only: No such file or directory
00000000000i[PLUGIN] init_dev of 'acpi' plugin device by virtual method
00000000000i[DEV   ] ACPI Controller present at device 1, function 3
00000000000i[PLUGIN] init_dev of 'ioapic' plugin device by virtual method
00000000000i[IOAPIC] initializing I/O APIC
00000000000i[MEM0  ] Register memory access handlers: 0x0000fec00000 - 0x0000fec00fff
00000000000i[IOAPIC] IOAPIC enabled (base address = 0xfec00000)
00000000000i[PLUGIN] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD   ] will paste characters every 400 keyboard ticks
00000000000i[PLUGIN] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD    ] CD on ata0-0: 'ANTARES.iso'
00000000000i[CD1   ] load cdrom with path=ANTARES.iso
00000000000i[CD1   ] Opening image file as a cd.
00000000000i[HD    ] Media present in CD-ROM drive
00000000000i[HD    ] Capacity is 2543 sectors (4.97 MB)
00000000000i[HD    ] Using boot sequence cdrom, none, none
00000000000i[HD    ] Floppy boot signature check is enabled
00000000000i[PLUGIN] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[DEV   ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[PLUGIN] init_dev of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[PCSPK ] Using lowlevel sound support for output
00000000000i[PLUGIN] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR   ] parallel port 1 at 0x0378 irq 7
00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER   ] com1 at 0x03f8 irq 4 (mode: null)
00000000000i[PLUGIN] init_dev of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'usb_uhci' plugin device by virtual method
00000000000i[DEV   ] USB UHCI present at device 1, function 2
00000000000i[UHCI  ] USB UHCI initialized
00000000000i[PLUGIN] register state of 'pci' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pci2isa' plugin device by virtual method
00000000000i[PLUGIN] register state of 'cmos' plugin device by virtual method
00000000000i[PLUGIN] register state of 'dma' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pic' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pit' plugin device by virtual method
00000000000i[PLUGIN] register state of 'vga' plugin device by virtual method
00000000000i[PLUGIN] register state of 'floppy' plugin device by virtual method
00000000000i[PLUGIN] register state of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] register state of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] register state of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] register state of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] register state of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] register state of 'serial' plugin device by virtual method
00000000000i[PLUGIN] register state of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] register state of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] register state of 'usb_uhci' plugin device by virtual method
00000000000i[PLUGIN] register state of 'acpi' plugin device by virtual method
00000000000i[PLUGIN] register state of 'ioapic' plugin device by virtual method
00000000000i[PLUGIN] register state of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] register state of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pci_ide' plugin device by virtual method
00000000000i[SYS   ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0  ] cpu hardware reset
00000000000i[APIC0 ] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000
00000000000i[CPU0  ] CPUID[0x00000000]: 0000000d 756e6547 6c65746e 49656e69
00000000000i[CPU0  ] CPUID[0x00000001]: 0001067a 00010800 0408e3dd bfebfbff
00000000000i[CPU0  ] CPUID[0x00000002]: 05b0b101 005657f0 00000000 2cb4304e
00000000000i[CPU0  ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x00000004]: 04000121 01c0003f 0000003f 00000001
00000000000i[CPU0  ] CPUID[0x00000005]: 00000040 00000040 00000003 03122220
00000000000i[CPU0  ] CPUID[0x00000006]: 00000003 00000002 00000003 00000000
00000000000i[CPU0  ] CPUID[0x00000007]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x00000008]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x00000009]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] WARNING: Architectural Performance Monitoring is not implemented
00000000000i[CPU0  ] CPUID[0x0000000a]: 07280202 00000000 00000000 00000503
00000000000i[CPU0  ] CPUID[0x0000000b]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x0000000c]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x0000000d]: 00000003 00000240 00000240 00000000
00000000000i[PLUGIN] reset of 'pci' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pci2isa' plugin device by virtual method
00000000000i[PLUGIN] reset of 'cmos' plugin device by virtual method
00000000000i[PLUGIN] reset of 'dma' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pic' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pit' plugin device by virtual method
00000000000i[PLUGIN] reset of 'vga' plugin device by virtual method
00000000000i[PLUGIN] reset of 'floppy' plugin device by virtual method
00000000000i[PLUGIN] reset of 'acpi' plugin device by virtual method
00000000000i[PLUGIN] reset of 'ioapic' plugin device by virtual method
00000000000i[PLUGIN] reset of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] reset of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pci_ide' plugin device by virtual method
00000000000i[PLUGIN] reset of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] reset of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] reset of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] reset of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] reset of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLUGIN] reset of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] reset of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] reset of 'usb_uhci' plugin device by virtual method
00000000000i[      ] set SIGINT handler to bx_debug_ctrlc_handler
00000004661i[BIOS  ] $Revision: 12579 $ $Date: 2014-12-26 11:31:39 +0100 (Fr, 26. Dez 2014) $
00000337543i[KBD   ] reset-disable command received
00000363302i[BIOS  ] Starting rombios32
00000363740i[BIOS  ] Shutdown flag 0
00000364332i[BIOS  ] ram_size=0x10000000
00000364775i[BIOS  ] ram_end=256MB
00000860685i[BIOS  ] Found 1 cpu(s)
00000874889i[BIOS  ] bios_table_addr: 0x000fa498 end=0x000fcc00
00000874923d[PCI   ] i440FX PMC read  register 0x00 value 0x00008086
00000874929d[PCI   ] i440FX PMC read  register 0x02 value 0x00001237
00000874952d[PCI   ] i440FX PMC read  register 0x00 value 0x00008086
00000874958d[PCI   ] i440FX PMC read  register 0x02 value 0x00001237
00000874979d[PCI   ] i440FX PMC read  register 0x59 value 0x00000000
00001202684i[PCI   ] i440FX PMC write to PAM register 59 (TLB Flush)
00001530613i[P2ISA ] PCI IRQ routing: PIRQA# set to 0x0b
00001530632i[P2ISA ] PCI IRQ routing: PIRQB# set to 0x09
00001530651i[P2ISA ] PCI IRQ routing: PIRQC# set to 0x0b
00001530670i[P2ISA ] PCI IRQ routing: PIRQD# set to 0x09
00001530680i[P2ISA ] write: ELCR2 = 0x0a
00001531450i[BIOS  ] PIIX3/PIIX4 init: elcr=00 0a
00001537298d[PCI   ] i440FX PMC read  register 0x00 value 0x00008086
00001537304d[PCI   ] i440FX PMC read  register 0x02 value 0x00001237
00001537328d[PCI   ] i440FX PMC read  register 0x0a value 0x00000600
00001537335d[PCI   ] i440FX PMC read  register 0x00 value 0x00008086
00001537343d[PCI   ] i440FX PMC read  register 0x02 value 0x00001237
00001539173i[BIOS  ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
00001539215d[PCI   ] i440FX PMC read  register 0x10 value 0x00000000
00001539243d[PCI   ] i440FX PMC read  register 0x14 value 0x00000000
00001539271d[PCI   ] i440FX PMC read  register 0x18 value 0x00000000
00001539299d[PCI   ] i440FX PMC read  register 0x1c value 0x00000000
00001539327d[PCI   ] i440FX PMC read  register 0x20 value 0x00000000
00001539355d[PCI   ] i440FX PMC read  register 0x24 value 0x00000000
00001539381d[PCI   ] i440FX PMC read  register 0x30 value 0x00000000
00001539393d[PCI   ] i440FX PMC read  register 0x3d value 0x00000000
00001541452i[BIOS  ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
00001543570i[BIOS  ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
00001543795i[PIDE  ] new BM-DMA address: 0xc000
00001544411i[BIOS  ] region 4: 0x0000c000
00001546422i[BIOS  ] PCI: bus=0 devfn=0x0a: vendor_id=0x8086 device_id=0x7020 class=0x0c03
00001546622i[UHCI  ] new base address: 0xc020
00001547238i[BIOS  ] region 4: 0x0000c020
00001547363i[UHCI  ] new irq line = 9
00001549258i[BIOS  ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
00001549490i[ACPI  ] new irq line = 11
00001549502i[ACPI  ] new irq line = 9
00001549527i[ACPI  ] new PM base address: 0xb000
00001549541i[ACPI  ] new SM base address: 0xb100
00001549569i[PCI   ] setting SMRAM control register to 0x4a
00001713662i[CPU0  ] Enter to System Management Mode
00001713672i[CPU0  ] RSM: Resuming from System Management Mode
00001877693i[PCI   ] setting SMRAM control register to 0x0a
00001883345d[PCI   ] i440FX PMC read  register 0x00 value 0x00008086
00001883351d[PCI   ] i440FX PMC read  register 0x02 value 0x00001237
00001883369d[PCI   ] i440FX PMC read  register 0x0a value 0x00000600
00001883377d[PCI   ] i440FX PMC read  register 0x30 value 0x00000000
00001892600i[BIOS  ] MP table addr=0x000fa570 MPC table addr=0x000fa4a0 size=0xc8
00001894422i[BIOS  ] SMBIOS table addr=0x000fa580
00001896603i[BIOS  ] ACPI tables: RSDP addr=0x000fa6a0 ACPI DATA addr=0x0fff0000 size=0xf72
00001899815i[BIOS  ] Firmware waking vector 0xfff00cc
00001901601d[PCI   ] i440FX PMC read  register 0x59 value 0x00000030
00001901610i[PCI   ] i440FX PMC write to PAM register 59 (TLB Flush)
00001902333i[BIOS  ] bios_table_cur_addr: 0x000fa6c4
00002029950i[VBIOS ] VGABios $Id: vgabios.c,v 1.76 2013/02/10 08:07:03 vruppert Exp $
00002030021i[BXVGA ] VBE known Display Interface b0c0
00002030053i[BXVGA ] VBE known Display Interface b0c5
00002032978i[VBIOS ] VBE Bios $Id: vbe.c,v 1.65 2014/07/08 18:02:25 vruppert Exp $
00006244506i[BIOS  ] IDE time out
00007604800i[XGUI  ] charmap update. Font Height is 16
00162710391i[BIOS  ] Booting from 07c0:0000
00308586880e[CPU0  ] fetch_raw_descriptor: GDT: index (4677) 8ce > limit (20)
00308586880e[CPU0  ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00308586880e[CPU0  ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00308586880i[CPU0  ] CPU is in protected mode (active)
00308586880i[CPU0  ] CS.mode = 32 bit
00308586880i[CPU0  ] SS.mode = 32 bit
00308586880i[CPU0  ] EFER   = 0x00000000
00308586880i[CPU0  ] | EAX=00000010  EBX=00010000  ECX=00000000  EDX=00000000
00308586880i[CPU0  ] | ESP=00106010  EBP=00000000  ESI=00000000  EDI=00000000
00308586880i[CPU0  ] | IOPL=0 ID vip vif ac vm RF nt of df if tf sf ZF af PF cf
00308586880i[CPU0  ] | SEG sltr(index|ti|rpl)     base    limit G D
00308586880i[CPU0  ] |  CS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  SS:0018( 0003| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] | EIP=0010042e (0010042e)
00308586880i[CPU0  ] | CR0=0x60000011 CR2=0x00000000
00308586880i[CPU0  ] | CR3=0x00000000 CR4=0x00000000
00308586880e[CPU0  ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00308586880i[SYS   ] bx_pc_system_c::Reset(HARDWARE) called
00308586880i[CPU0  ] cpu hardware reset
00308586880i[APIC0 ] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000
00308586880i[CPU0  ] CPUID[0x00000000]: 0000000d 756e6547 6c65746e 49656e69
00308586880i[CPU0  ] CPUID[0x00000001]: 0001067a 00010800 0408e3dd bfebfbff
00308586880i[CPU0  ] CPUID[0x00000002]: 05b0b101 005657f0 00000000 2cb4304e
00308586880i[CPU0  ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
00308586880i[CPU0  ] CPUID[0x00000004]: 04000121 01c0003f 0000003f 00000001
00308586880i[CPU0  ] CPUID[0x00000005]: 00000040 00000040 00000003 03122220
00308586880i[CPU0  ] CPUID[0x00000006]: 00000003 00000002 00000003 00000000
00308586880i[CPU0  ] CPUID[0x00000007]: 00000000 00000000 00000000 00000000
00308586880i[CPU0  ] CPUID[0x00000008]: 00000000 00000000 00000000 00000000
00308586880i[CPU0  ] CPUID[0x00000009]: 00000000 00000000 00000000 00000000
00308586880i[CPU0  ] WARNING: Architectural Performance Monitoring is not implemented
00308586880i[CPU0  ] CPUID[0x0000000a]: 07280202 00000000 00000000 00000503
00308586880i[CPU0  ] CPUID[0x0000000b]: 00000000 00000000 00000000 00000000
00308586880i[CPU0  ] CPUID[0x0000000c]: 00000000 00000000 00000000 00000000
00308586880i[CPU0  ] CPUID[0x0000000d]: 00000003 00000240 00000240 00000000
00308586880i[PLUGIN] reset of 'pci' plugin device by virtual method
00308586880i[PLUGIN] reset of 'pci2isa' plugin device by virtual method
00308586880i[PLUGIN] reset of 'cmos' plugin device by virtual method
00308586880i[PLUGIN] reset of 'dma' plugin device by virtual method
00308586880i[PLUGIN] reset of 'pic' plugin device by virtual method
00308586880i[PLUGIN] reset of 'pit' plugin device by virtual method
00308586880i[PLUGIN] reset of 'vga' plugin device by virtual method
00308586880i[PLUGIN] reset of 'floppy' plugin device by virtual method
00308586880i[PLUGIN] reset of 'acpi' plugin device by virtual method
00308586880i[PLUGIN] reset of 'ioapic' plugin device by virtual method
00308586880i[PLUGIN] reset of 'keyboard' plugin device by virtual method
00308586880i[PLUGIN] reset of 'harddrv' plugin device by virtual method
00308586880i[PLUGIN] reset of 'pci_ide' plugin device by virtual method
00308586880i[PLUGIN] reset of 'unmapped' plugin device by virtual method
00308586880i[PLUGIN] reset of 'biosdev' plugin device by virtual method
00308586880i[PLUGIN] reset of 'speaker' plugin device by virtual method
00308586880i[PLUGIN] reset of 'extfpuirq' plugin device by virtual method
00308586880i[PLUGIN] reset of 'parallel' plugin device by virtual method
00308586880i[PLUGIN] reset of 'serial' plugin device by virtual method
00308586880i[PLUGIN] reset of 'gameport' plugin device by virtual method
00308586880i[PLUGIN] reset of 'iodebug' plugin device by virtual method
00308586880i[PLUGIN] reset of 'usb_uhci' plugin device by virtual method
00308586881i[      ] dbg: Quit
00308586881i[CPU0  ] CPU is in real mode (active)
00308586881i[CPU0  ] CS.mode = 16 bit
00308586881i[CPU0  ] SS.mode = 16 bit
00308586881i[CPU0  ] EFER   = 0x00000000
00308586881i[CPU0  ] | EAX=00000000  EBX=00000000  ECX=00000000  EDX=00000000
00308586881i[CPU0  ] | ESP=00000000  EBP=00000000  ESI=00000000  EDI=00000000
00308586881i[CPU0  ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf
00308586881i[CPU0  ] | SEG sltr(index|ti|rpl)     base    limit G D
00308586881i[CPU0  ] |  CS:f000( 1e00| 0|  0) ffff0000 0000ffff 0 0
00308586881i[CPU0  ] |  DS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00308586881i[CPU0  ] |  SS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00308586881i[CPU0  ] |  ES:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00308586881i[CPU0  ] |  FS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00308586881i[CPU0  ] |  GS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00308586881i[CPU0  ] | EIP=0000fff0 (0000fff0)
00308586881i[CPU0  ] | CR0=0x60000010 CR2=0x00000000
00308586881i[CPU0  ] | CR3=0x00000000 CR4=0x00000000
00308586881d[PCI   ] Exit
00308586881i[CMOS  ] Last time is 1482800190 (Mon Dec 26 19:56:30 2016)
00308586881i[XGUI  ] Exit
00308586881i[SIM   ] quit_sim called with exit code 0
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Possible GDT issues

Post by Octocontrabass »

Code: Select all

00308586880e[CPU0  ] fetch_raw_descriptor: GDT: index (4677) 8ce > limit (20)
Something is trying to load a segment register with the value 0x4677, but that's outside the current GDT.

Code: Select all

00308586880i[CPU0  ] | EAX=00000010  EBX=00010000  ECX=00000000  EDX=00000000
00308586880i[CPU0  ] | ESP=00106010  EBP=00000000  ESI=00000000  EDI=00000000
The value 0x4677 isn't in any of the GPRs, so I'm not sure where it's coming from.

Code: Select all

00308586880i[CPU0  ] | SEG sltr(index|ti|rpl)     base    limit G D
00308586880i[CPU0  ] |  CS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  SS:0018( 0003| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00308586880i[CPU0  ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
The first segment register you reload is CS, with the value 0x0008. Since CS is 0x0010 (probably the value GRUB uses), the fault is probably happening at or before the first far jump.

Code: Select all

00308586880i[CPU0  ] | EIP=0010042e (0010042e)
The faulting instruction is at 0x0010042E. Use objdump on your kernel to see what instruction will be at that address, or set a breakpoint with the Bochs debugger to catch the CPU right before the fault happens.
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Possible GDT issues

Post by FallenAvatar »

DefinitelyNotMars wrote:...
In addition to what Octocontrabass says, you probably want to disable reset on triple fault in Bochs.

- Monk
DefinitelyNotMars
Posts: 7
Joined: Thu Dec 22, 2016 8:38 pm

Re: Possible GDT issues

Post by DefinitelyNotMars »

Code: Select all

0010042e: (                    ): lss esp, ds:0x00106010    ; 0fb22510601000
This seems to be most like

Code: Select all

mov $stack_top, %esp
DefinitelyNotMars
Posts: 7
Joined: Thu Dec 22, 2016 8:38 pm

Re: Possible GDT issues

Post by DefinitelyNotMars »

I think I figured out the

Code: Select all

00325237054e[CPU0  ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00325237054e[CPU0  ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
SS has the value 0x0018 which is binary 11000. Which means the first entry of the IDT
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Possible GDT issues

Post by Octocontrabass »

DefinitelyNotMars wrote:

Code: Select all

0010042e: (                    ): lss esp, ds:0x00106010    ; 0fb22510601000
This seems to be most like

Code: Select all

mov $stack_top, %esp
LSS and MOV are two entirely different instructions. I don't see LSS anywhere in the code you posted, so I can't tell you why it might not be working.
DefinitelyNotMars wrote:I think I figured out the

Code: Select all

00325237054e[CPU0  ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00325237054e[CPU0  ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
SS has the value 0x0018 which is binary 11000. Which means the first entry of the IDT
Uh, no. Those lines just mean you haven't set up the IDT yet. It has nothing to do with the problem you're trying to solve right now.
DefinitelyNotMars
Posts: 7
Joined: Thu Dec 22, 2016 8:38 pm

Re: Possible GDT issues

Post by DefinitelyNotMars »

Sorry, I was tired, but after further investigation, those instructions are not in my code, nor are they in my binary file. This would lead me to believe that my code has escaped the cli, hlt, jmp loop that I created
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Possible GDT issues

Post by Octocontrabass »

It looks like it's crashing before any of your code runs. Either your (virtual disk) installation of GRUB is messed up, or you've miscompiled your kernel.

What steps did you follow to build your disk image with GRUB?

What steps did you follow to compile your kernel?
DefinitelyNotMars
Posts: 7
Joined: Thu Dec 22, 2016 8:38 pm

Re: Possible GDT issues

Post by DefinitelyNotMars »

To compile, link, and make an iso for my kernel I do this:

Code: Select all

iso: link
	grub-mkrescue iso -o ANTARES.iso
link: objects
	echo "On a Mac, this will fail!"
	i686-elf-ld -T link.ld kernelc.o kernela.o -o kernel.bin
objects:
	clang --target=i686-none-elf -ffreestanding -c kernel.c -o kernelc.o
	clang --target=i686-none-elf -ffreestanding -c kernel.asm -o kernela.o
rgmf
Posts: 17
Joined: Wed Sep 28, 2016 1:45 pm

Re: Possible GDT issues

Post by rgmf »

What is the value of DS register before lgdt _gdtr instruction? I had an issue like this and It was because DS register had a wrong value. I think lgdt _gdtr is lgdt DS:_gdtr.

Anyway, Magic Breakpoints in Bochs could help you.
Post Reply