Page 2 of 2

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Thu Jan 07, 2016 1:33 pm
by ggodw000
years ago, i tried to use linux for assembly, i dont remember the details but i do remember it sucked bad. i transitioned to using masm32 for windows.

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Thu Jan 07, 2016 2:41 pm
by Roman
Brendan wrote:

Code: Select all

movl %eax,4(%esp)      # eax = address_of_gdt_ptr
Isn't it data_at(%esp + 4) = eax?

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Thu Jan 07, 2016 5:50 pm
by Brendan
Hi,
Roman wrote:
Brendan wrote:

Code: Select all

movl %eax,4(%esp)      # eax = address_of_gdt_ptr
Isn't it data_at(%esp + 4) = eax?
For AT&T syntax (and not GAS in "intel syntax mode") it'd be "data_at(%esp + 4) = eax", but it is in "intel syntax mode" so it's "eax = data_at(%esp + 4)".


Cheers,

Brendan

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Fri Jan 08, 2016 4:02 pm
by glauxosdever
Hi,

ggodw000 wrote:years ago, i tried to use linux for assembly, i dont remember the details but i do remember it sucked bad. i transitioned to using masm32 for windows.
Linux for assembly? You probably meant that you tried either to write assembly code for linux, either to use a specific assembler to assemble your code. I can assume then that you didn't like either assembly code for linux, either you used GAS, which has an incomprehensive memory addressing scheme. Anyway NASM and MASM are not very different from what I have read.


Regards,
glauxosdever

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Fri Jan 08, 2016 4:15 pm
by ggodw000
glauxosdever wrote:Hi,

ggodw000 wrote:years ago, i tried to use linux for assembly, i dont remember the details but i do remember it sucked bad. i transitioned to using masm32 for windows.
Linux for assembly? You probably meant that you tried either to write assembly code for linux, either to use a specific assembler to assemble your code. I can assume then that you didn't like either assembly code for linux, either you used GAS, which has an incomprehensive memory addressing scheme. Anyway NASM and MASM are not very different from what I have read.


Regards,
glauxosdever
i dont know which one is better, i just got used to masm32 as i had 2-3yrs experience development experience. many people here in this forum seems to use NASM, which i am thinking to explore.
when i attempted to linux, something that subtle issue keep driving me insane, i think it was like trying to mov some value into register from memory and just not working and kept tying up my whole project.

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Fri Jan 08, 2016 6:00 pm
by Quaker763
Hello,

First, I would SERIOUSLY recommend putting .intel_syntax noprefix at the top of your ASM sources. GNU AS syntax is so convoluted I'm genuinely surprised it even exists.

So now that we can use the instruction dest,src styleof assembly, I would wipe the entire GDT section and start again. Here, you can use mov eax, [esp + 4] to get your gdt struct from C and then the lgdt instruction with lgdt eax

Thanks,
Quaker763

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Sat Jan 09, 2016 6:01 am
by glauxosdever
Hi,

Quaker763 wrote:Hello,

First, I would SERIOUSLY recommend putting .intel_syntax noprefix at the top of your ASM sources. GNU AS syntax is so convoluted I'm genuinely surprised it even exists.

So now that we can use the instruction dest,src styleof assembly, I would wipe the entire GDT section and start again. Here, you can use mov eax, [esp + 4] to get your gdt struct from C and then the lgdt instruction with lgdt eax

Thanks,
Quaker763
First, I would seriously recommend using GAS native syntax, if you choose to use this assembler. Using non native syntax may be inconvenient and/or dangerous. Second, if you don't want to use GAS native syntax (no surprise for me), you should use another assembler instead of GAS. Currently I'm using NASM, but I'm concerned that it doesn't support architectures other than x86.


Regards,
glauxosdever

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Sat Jan 09, 2016 6:27 am
by Octacone
Guys this is not a topic about syntax versus another syntax, from now I'll be using NASM on Linux and I don't need anything >x86 right now.

I still don't know why am I getting that error when compiling my OS, everything compiles all right and then my OS appears in QEMU and then crashes with that error. Can you please help me with that, and yes I have that null segment thingy.

-thehardcoreOS

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Sat Jan 09, 2016 6:03 pm
by Octocontrabass
Your code is jumping off into nowhere. You'll have to figure out what it was doing before that. This is a good time to learn some debugger skills.

Even if you aren't able to figure out what's wrong, you're more likely to get a helpful answer if you can tell us where in your code the crash occurs.

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Wed Jan 13, 2016 11:43 am
by Octacone
Qemu: fatal: Trying to execute code outside RAM or ROM at 0x13f87dbd

Can't figure it out.

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Wed Jan 13, 2016 12:34 pm
by iansjack
Sounds like a bad stack. Use your debugger to investigate it just before the error.

Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Thu Jan 14, 2016 7:05 am
by osdever
thehardcoreOS wrote:I can't use default NASM because default makefile from osdev.org doesn't allow me that I guess.

I still don't know why am I getting tripe faults and do I need to replace "eax" with some numbers/pointers?
Is there any straight forward way of fixing this or it is just that code is so broken it can't be fixed?

-thehardcoreOS
I can give you my makefile. Edit it for your OS, please.

Code: Select all

ARROW=\e[1;34m==>\e[1;37m

#U365 Makefile configuration

LSCRIPT    = link
BUILD_DIR  = build
SRC_DIR    = src
INC_DIR    = include
OS_VER     = "0.6"

#Filenames

ARCH       = i686
BINFORMAT  = elf
BITS       = 32
ISODIR     = $(BUILD_DIR)/iso/fs
GRUB_BIN   = /usr/lib/grub/i386-pc/
CROSS      = ~/opt/cross
CROSSBIN   = $(CROSS)/bin/
GAS        = $(CROSSBIN)$(ARCH)-$(BINFORMAT)-as #AT&T-syntax assembler
CC         = $(CROSSBIN)$(ARCH)-$(BINFORMAT)-gcc
IASM       = yasm #Intel-syntax assembler
BINFILE    = u365#Compiled ELF binary and ISO image name.
EMU        = qemu-system-i386
EFLAGS     = -cdrom $(BINFILE).iso
DEFS       = -DOSVER=$(OS_VER)
MKRSCFLAGS = -d $(GRUB_BIN) -o $(BINFILE).iso $(ISODIR)
CFLAGS     = -O3 -ffreestanding -Wall -Wextra -Wmaybe-uninitialized -fno-exceptions -std=gnu11 -Iinclude -c $(DEFS)
GASFLAGS   =
IASFLAGS   = -f $(BINFORMAT)$(BITS)
LDFLAGS    = -T $(LSCRIPT).ld -o $(BUILD_DIR)/bin/$(BINFILE).$(BINFORMAT) -O2 -nostdlib

# Source file names computing
# Multiboot header first
SOURCES  := $(SRC_DIR)/arch/$(ARCH)/boot.s
# Al common sources
SOURCES  += $(shell find $(SRC_DIR) -name "*.c"   -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
SOURCES  += $(shell find $(SRC_DIR) -name "*.s"   -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
SOURCES  += $(shell find $(SRC_DIR) -name "*.asm" -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
# Architecture-dependent sources
SOURCES  += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.c' -type f -print)
SOURCES  += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.s' -and -not -path "$(SRC_DIR)/arch/$(ARCH)/boot.s" -type f -print)
SOURCES  += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.asm' -type f -print)

FAKE := $(shell echo $(SOURCES))
# Object file names computing
OBJS     := $(patsubst $(SRC_DIR)/%.c,"$(BUILD_DIR)/obj/%.c.o",$(SOURCES))
OBJS     := $(patsubst $(SRC_DIR)/%.s,"$(BUILD_DIR)/obj/%.s.o",$(OBJS))
OBJS     := $(patsubst $(SRC_DIR)/%.asm,"$(BUILD_DIR)/obj/%.asm.o",$(OBJS))
#End

# target      _welcome dependencies
all:          _welcome clean directories compile link iso run
	@echo -n

# Welcome user at make call
_welcome:
	@echo -e " \e[1;33mMakefile:\e[0m \e[1;32mU365\e[0m"

compile:     _welcome clean directories _compile $(SOURCES)
#	@echo -e " $(ARROW) Compiling GDT\e[0m"
#	@$(IASM) $(SRC_DIR)/arch/$(ARCH)/gdt.s -o $(BUILD_DIR)/obj/gdt.o $(IASFLAGS)
#	@echo -e " $(ARROW) Compiling IDT\e[0m"
#	@$(IASM) $(SRC_DIR)/arch/$(ARCH)/idt.s -o $(BUILD_DIR)/obj/idt.o $(IASFLAGS)
#	@echo -e " $(ARROW) Compiling C sources\e[0m"
#	@$(CC) $(SOURCES) $(SRC_DIR)/arch/$(ARCH)/init.c $(IOBJS) $(CFLAGS) $(LDFLAGS)
	@echo -n

link:        _welcome clean directories compile
	@echo -e " $(ARROW) Linking\e[0m"
	@$(CC) $(OBJS) $(LDFLAGS)


iso:         _welcome directories
	@echo -e " $(ARROW) Generating an ISO image\e[0m"

	@echo "insmod gfxterm;  \
insmod vbe;  \
timeout=5;   \
loadfont /boot/grub/fonts/unicode.pf2;  \
set gfxmode=1024x768;  \
terminal_output gfxterm;  \
menuentry "U365 Basic System 1.0"  \
{  \
	multiboot /boot/u365.elf;  \
	boot;  \
}  \
" > $(BUILD_DIR)/iso/fs/grub.cfg

	@cp $(BUILD_DIR)/iso/fs/grub.cfg $(BUILD_DIR)/iso/fs/boot/grub/grub.cfg
	@cp $(BUILD_DIR)/bin/$(BINFILE).$(BINFORMAT) $(BUILD_DIR)/iso/fs/boot/
	@grub-mkrescue $(MKRSCFLAGS) &> /dev/null
	@echo -n

run:         _welcome
	@echo -e " $(ARROW) Booting the ISO image\e[0m"
	$(EMU) $(EFLAGS)
	@echo -n

clean:       _welcome
	@echo -e " $(ARROW) Cleaning\e[0m"
	@rm $(BUILD_DIR) *.iso -rf
	@echo -n

directories: _welcome
	@echo -e " $(ARROW) Creating build directories\e[0m"
	@mkdir -p $(BUILD_DIR)/obj/arch/$(ARCH) $(BUILD_DIR)/bin $(BUILD_DIR)/iso/fs/boot/grub $(BUILD_DIR)/iso/fs/fonts
	@echo -n

Makefile:
	@echo -e " \e[1;31mStrange make bug prevented\e[0m"

# Compilation notification - do not remove
_compile:
	@echo -e " $(ARROW) Compiling\e[0m"

# Compilation routines
%.c:          _welcome directories _compile
	@echo -e " \e[0;32m Building C file:\e[0m \e[1;32m$@\e[0m"
	@$(CC) $@ -o $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/obj/%.c.o,$@) $(CFLAGS)
	@echo -n

%.s:          _welcome directories _compile
	@echo -e " \e[0;32m Building GAS file:\e[0m \e[1;32m$@\e[0m"
	@$(GAS) $@ -o $(patsubst $(SRC_DIR)/%.s,$(BUILD_DIR)/obj/%.s.o,$@)
	@echo -n

%.asm:        _welcome directories _compile
	@echo -e " \e[0;32m Building IAS file:\e[0m \e[1;32m$@\e[0m"
	@$(IASM) $@ -o $(patsubst $(SRC_DIR)/%.asm,$(BUILD_DIR)/obj/%.asm.o,$@) $(IASFLAGS)
	@echo -n


Re: GRUB + GDT + IDT = TRIPLE FAULT??

Posted: Fri Jan 15, 2016 7:53 am
by Octacone
catnikita255 wrote:
thehardcoreOS wrote:I can't use default NASM because default makefile from osdev.org doesn't allow me that I guess.

I still don't know why am I getting tripe faults and do I need to replace "eax" with some numbers/pointers?
Is there any straight forward way of fixing this or it is just that code is so broken it can't be fixed?

-thehardcoreOS
I can give you my makefile. Edit it for your OS, please.

Code: Select all

ARROW=\e[1;34m==>\e[1;37m

#U365 Makefile configuration

LSCRIPT    = link
BUILD_DIR  = build
SRC_DIR    = src
INC_DIR    = include
OS_VER     = "0.6"

#Filenames

ARCH       = i686
BINFORMAT  = elf
BITS       = 32
ISODIR     = $(BUILD_DIR)/iso/fs
GRUB_BIN   = /usr/lib/grub/i386-pc/
CROSS      = ~/opt/cross
CROSSBIN   = $(CROSS)/bin/
GAS        = $(CROSSBIN)$(ARCH)-$(BINFORMAT)-as #AT&T-syntax assembler
CC         = $(CROSSBIN)$(ARCH)-$(BINFORMAT)-gcc
IASM       = yasm #Intel-syntax assembler
BINFILE    = u365#Compiled ELF binary and ISO image name.
EMU        = qemu-system-i386
EFLAGS     = -cdrom $(BINFILE).iso
DEFS       = -DOSVER=$(OS_VER)
MKRSCFLAGS = -d $(GRUB_BIN) -o $(BINFILE).iso $(ISODIR)
CFLAGS     = -O3 -ffreestanding -Wall -Wextra -Wmaybe-uninitialized -fno-exceptions -std=gnu11 -Iinclude -c $(DEFS)
GASFLAGS   =
IASFLAGS   = -f $(BINFORMAT)$(BITS)
LDFLAGS    = -T $(LSCRIPT).ld -o $(BUILD_DIR)/bin/$(BINFILE).$(BINFORMAT) -O2 -nostdlib

# Source file names computing
# Multiboot header first
SOURCES  := $(SRC_DIR)/arch/$(ARCH)/boot.s
# Al common sources
SOURCES  += $(shell find $(SRC_DIR) -name "*.c"   -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
SOURCES  += $(shell find $(SRC_DIR) -name "*.s"   -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
SOURCES  += $(shell find $(SRC_DIR) -name "*.asm" -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
# Architecture-dependent sources
SOURCES  += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.c' -type f -print)
SOURCES  += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.s' -and -not -path "$(SRC_DIR)/arch/$(ARCH)/boot.s" -type f -print)
SOURCES  += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.asm' -type f -print)

FAKE := $(shell echo $(SOURCES))
# Object file names computing
OBJS     := $(patsubst $(SRC_DIR)/%.c,"$(BUILD_DIR)/obj/%.c.o",$(SOURCES))
OBJS     := $(patsubst $(SRC_DIR)/%.s,"$(BUILD_DIR)/obj/%.s.o",$(OBJS))
OBJS     := $(patsubst $(SRC_DIR)/%.asm,"$(BUILD_DIR)/obj/%.asm.o",$(OBJS))
#End

# target      _welcome dependencies
all:          _welcome clean directories compile link iso run
	@echo -n

# Welcome user at make call
_welcome:
	@echo -e " \e[1;33mMakefile:\e[0m \e[1;32mU365\e[0m"

compile:     _welcome clean directories _compile $(SOURCES)
#	@echo -e " $(ARROW) Compiling GDT\e[0m"
#	@$(IASM) $(SRC_DIR)/arch/$(ARCH)/gdt.s -o $(BUILD_DIR)/obj/gdt.o $(IASFLAGS)
#	@echo -e " $(ARROW) Compiling IDT\e[0m"
#	@$(IASM) $(SRC_DIR)/arch/$(ARCH)/idt.s -o $(BUILD_DIR)/obj/idt.o $(IASFLAGS)
#	@echo -e " $(ARROW) Compiling C sources\e[0m"
#	@$(CC) $(SOURCES) $(SRC_DIR)/arch/$(ARCH)/init.c $(IOBJS) $(CFLAGS) $(LDFLAGS)
	@echo -n

link:        _welcome clean directories compile
	@echo -e " $(ARROW) Linking\e[0m"
	@$(CC) $(OBJS) $(LDFLAGS)


iso:         _welcome directories
	@echo -e " $(ARROW) Generating an ISO image\e[0m"

	@echo "insmod gfxterm;  \
insmod vbe;  \
timeout=5;   \
loadfont /boot/grub/fonts/unicode.pf2;  \
set gfxmode=1024x768;  \
terminal_output gfxterm;  \
menuentry "U365 Basic System 1.0"  \
{  \
	multiboot /boot/u365.elf;  \
	boot;  \
}  \
" > $(BUILD_DIR)/iso/fs/grub.cfg

	@cp $(BUILD_DIR)/iso/fs/grub.cfg $(BUILD_DIR)/iso/fs/boot/grub/grub.cfg
	@cp $(BUILD_DIR)/bin/$(BINFILE).$(BINFORMAT) $(BUILD_DIR)/iso/fs/boot/
	@grub-mkrescue $(MKRSCFLAGS) &> /dev/null
	@echo -n

run:         _welcome
	@echo -e " $(ARROW) Booting the ISO image\e[0m"
	$(EMU) $(EFLAGS)
	@echo -n

clean:       _welcome
	@echo -e " $(ARROW) Cleaning\e[0m"
	@rm $(BUILD_DIR) *.iso -rf
	@echo -n

directories: _welcome
	@echo -e " $(ARROW) Creating build directories\e[0m"
	@mkdir -p $(BUILD_DIR)/obj/arch/$(ARCH) $(BUILD_DIR)/bin $(BUILD_DIR)/iso/fs/boot/grub $(BUILD_DIR)/iso/fs/fonts
	@echo -n

Makefile:
	@echo -e " \e[1;31mStrange make bug prevented\e[0m"

# Compilation notification - do not remove
_compile:
	@echo -e " $(ARROW) Compiling\e[0m"

# Compilation routines
%.c:          _welcome directories _compile
	@echo -e " \e[0;32m Building C file:\e[0m \e[1;32m$@\e[0m"
	@$(CC) $@ -o $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/obj/%.c.o,$@) $(CFLAGS)
	@echo -n

%.s:          _welcome directories _compile
	@echo -e " \e[0;32m Building GAS file:\e[0m \e[1;32m$@\e[0m"
	@$(GAS) $@ -o $(patsubst $(SRC_DIR)/%.s,$(BUILD_DIR)/obj/%.s.o,$@)
	@echo -n

%.asm:        _welcome directories _compile
	@echo -e " \e[0;32m Building IAS file:\e[0m \e[1;32m$@\e[0m"
	@$(IASM) $@ -o $(patsubst $(SRC_DIR)/%.asm,$(BUILD_DIR)/obj/%.asm.o,$@) $(IASFLAGS)
	@echo -n


Thanks for sharing, I will see what can I make out of this. :)