Re: GRUB + GDT + IDT = TRIPLE FAULT??
Posted: Thu Jan 07, 2016 1:33 pm
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.
The Place to Start for Operating System Developers
http://f.osdev.org/
Isn't it data_at(%esp + 4) = eax?Brendan wrote:Code: Select all
movl %eax,4(%esp) # eax = address_of_gdt_ptr
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
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.
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
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
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
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