GRUB + GDT + IDT = TRIPLE FAULT??
-
- Member
- Posts: 396
- Joined: Wed Nov 18, 2015 3:04 pm
- Location: San Jose San Francisco Bay Area
- Contact:
Re: GRUB + GDT + IDT = TRIPLE FAULT??
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.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
Re: GRUB + GDT + IDT = TRIPLE FAULT??
Isn't it data_at(%esp + 4) = eax?Brendan wrote:Code: Select all
movl %eax,4(%esp) # eax = address_of_gdt_ptr
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: GRUB + GDT + IDT = TRIPLE FAULT??
Hi,
Cheers,
Brendan
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)".Roman wrote:Isn't it data_at(%esp + 4) = eax?Brendan wrote:Code: Select all
movl %eax,4(%esp) # eax = address_of_gdt_ptr
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
Re: GRUB + GDT + IDT = TRIPLE FAULT??
Hi,
Regards,
glauxosdever
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.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.
Regards,
glauxosdever
-
- Member
- Posts: 396
- Joined: Wed Nov 18, 2015 3:04 pm
- Location: San Jose San Francisco Bay Area
- Contact:
Re: GRUB + GDT + IDT = TRIPLE FAULT??
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.glauxosdever wrote:Hi,
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.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.
Regards,
glauxosdever
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.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
Re: GRUB + GDT + IDT = TRIPLE FAULT??
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 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
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
Re: GRUB + GDT + IDT = TRIPLE FAULT??
Hi,
Regards,
glauxosdever
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.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
Regards,
glauxosdever
Re: GRUB + GDT + IDT = TRIPLE FAULT??
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
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
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
-
- Member
- Posts: 5588
- Joined: Mon Mar 25, 2013 7:01 pm
Re: GRUB + GDT + IDT = TRIPLE FAULT??
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.
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??
Qemu: fatal: Trying to execute code outside RAM or ROM at 0x13f87dbd
Can't figure it out.
Can't figure it out.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: GRUB + GDT + IDT = TRIPLE FAULT??
Sounds like a bad stack. Use your debugger to investigate it just before the error.
Re: GRUB + GDT + IDT = TRIPLE FAULT??
I can give you my makefile. Edit it for your OS, please.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
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
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: GRUB + GDT + IDT = TRIPLE FAULT??
catnikita255 wrote:I can give you my makefile. Edit it for your OS, please.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?
-thehardcoreOSCode: 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.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader