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.
I've been having trouble getting my OS to boot with GRUB - it's giving me error #7 (loading below 1 mb) with all of the linker scripts I've tried. Here's my linker script:
; Boot.asm
; OS loader
[BITS 32]
[global start]
start:
mov esp, _sys_stack ; This points the stack to our new stack area
jmp stublet
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
; The Multiboot header
align 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd CHECKSUM
; fields used if MULTIBOOT_AOUT_KLUDGE is set in MULTIBOOT_HEADER_FLAGS
dd mboot ; these are PHYSICAL addresses
dd code ; start of kernel .text (code) section
dd bss ; end of kernel .data section
dd end ; end of kernel BSS
dd start ; kernel entry point (initial EIP)
[global _mbinfo]
[global _mbmagic]
[extern code]
[extern bss]
[extern end]
; align 4
;mboot:
; dd MULTIBOOT_HEADER_MAGIC
; dd MULTIBOOT_HEADER_FLAGS
; dd MULTIBOOT_CHECKSUM
; dd mboot
; dd code
; dd bss
; dd end
; dd start
;dd _mboot ; Location of this descriptor
;dd code ; Start of kernel '.text' (code) section.
;dd bss ; End of kernel '.data' section.
;dd end ; End of kernel.
;dd start ; Kernel entry point (initial EIP).
;_mbinfo:
; dd 0
;_mbmagic:
; dd 0
extern _main ; located in Kernel.cpp
call _main ; call int main(void) in Kernel.cpp
cli ; interrupts could disturb the halt
hlt ; halt the CPU
stublet:
jmp $
global _gdt_flush ; Allows the C code to link to this
;extern _gp
extern _gp ; Says that '_gp' is in another file
_gdt_flush:
lgdt [_gp] ; Load the GDT with our '_gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C++ code
global _idt_load
extern _idtp
_idt_load:
lidt [_idtp]
ret
;really long IRQ/ISR section removed
;bss:
SECTION .bss
resb 8192
_sys_stack:
(yes, thrown together from tutorials, but that's why I'm using c++ for the rest )
And, try this to fix the where the linker expects the data section to be in the boot.asm (I was using ELF32, and realized that the binary format did not work completely), also your linker script works.
dd mboot ; these are PHYSICAL addresses
dd start ; start of kernel .text (code) section
dd end ; end of kernel .data section
dd end ; end of kernel BSS
dd start ; kernel entry point (initial EIP)
; Boot.asm
; OS loader
[BITS 32]
[global start]
start:
mov esp, _sys_stack ; This points the stack to our new stack area
jmp stublet
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
; The Multiboot header
align 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd CHECKSUM
; fields used if MULTIBOOT_AOUT_KLUDGE is set in MULTIBOOT_HEADER_FLAGS
dd mboot ; these are PHYSICAL addresses
dd start ; start of kernel .text (code) section
dd end ; end of kernel .data section
dd end ; end of kernel BSS
dd start ; kernel entry point (initial EIP)
[global _mbinfo]
[global _mbmagic]
[extern code]
[extern bss]
[extern end]
extern _main ; located in Kernel.cpp
call _main ; call int main(void) in Kernel.cpp
cli ; interrupts could disturb the halt
hlt ; halt the CPU
stublet:
jmp $
;bss:
SECTION .bss
resb 8192
_sys_stack:
I fixed it, and it the problem is really obvious. Reduce the code back to what I gave you, and slowly add the stuff you changed until it starts giving unexpected results, or errors then you should have found what I found. Once you find it, I can give you a hint that it has to do witht the order of things.
There is also another problem that might cause you problems, but it should not for the moment - if you can find that one too.
Well, the code you gave me appears to be giving rather unexpected results. GRUB doesn't give any errors, but it just continually changes the first character on the screen to a random character and background color, even when it's just this: