So you guys say I'm wrong :P
Maybe this can help a bit:
This is the kernel entry point. Everything works fine. I've tested the divide by Zero Exception. And the keyboard and timer in the C-code work great.
But as I told if I make the kernel larger than 16 kb (by printing very much gibberish to the screen with main.c) it doesn't work anymore.
Is that the problem? That I try to fill the 16k's with text and not with code?
Well here's the code anyway:
Code: Select all
; start.asm
[BITS 32]
global start
start:
mov esp, _sys_stack ; This points the stack to our new stack area
jmp stublet
ALIGN 4
mboot:
MULTIBOOT_PAGE_ALIGN equ 1<<0 ; align loaded modules on page boundaries
MULTIBOOT_MEMORY_INFO equ 1<<1 ; provide memory map
MULTIBOOT_AOUT_KLUDGE equ 1<<16
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE ; this is the Multiboot 'flag' field
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
EXTERN code, bss, end
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
; AOUT kludge - must be physical addresses. Make a note of these:
; The linker script fills in the data for these ones!
dd mboot
dd code
dd bss
dd end
dd start
stublet:
extern _main
call _main
jmp $
; This will set up our new segment registers. We need to do
; a far jump order to set CS.
; This is declared in C as 'extern void gdt_flush();'
global _gdt_flush
extern _gp
_gdt_flush:
lgdt [_gp]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
jmp 0x08:flush2
flush2:
ret
; Loads the IDT defined in '_idtp' into the processor.
; This is declared in C as 'extern void idt_load();'
global _idt_load
extern _idtp
_idt_load:
lidt [_idtp]
ret
global _isr0
;.... etc. (to _isr31)
; 0: Divide By Zero Exception
_isr0:
cli
push byte 0
push byte 0
jmp isr_common_stub
;.... etc.
extern _fault_handler
; This is our common ISR stub. It saves the processor state, sets
; up for kernel mode segments, calls the C-level fault handler,
; and finally restores the stack frame.
isr_common_stub:
pusha
push ds
push es
push fs
push gs
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
mov eax, _fault_handler
call eax
pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
global _irq0
;.... etc. (to _irq15)
; 32: IRQ0
_irq0:
cli
push byte 0
push byte 32
jmp irq_common_stub
;.... etc.
extern _irq_handler
irq_common_stub:
pusha
push ds
push es
push fs
push gs
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
mov eax, _irq_handler
call eax
pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
; Here is the definition of our BSS section. Right now, we'll use
; it just to store the stack. Remember that a stack actually grows
; downwards, so we declare the size of the data before declaring
; the identifier '_sys_stack'
SECTION .bss
resb 8192 ; This reserves 8KBytes of memory here
_sys_stack:
and this is the linker script:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x0100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
I've tried to change the 'phys' in the linkerscript and to align the sections with words like 8192.
But as soon as I change the ALIGN in .text to a greater value than 4096. Grub says: Error 13 invalid or unsupported executable format.
-Can I change something in the linkerscript to solve it. Like the 'phys'. Or should I change the stacksize in the kernel entry point.
-Can someone explain to me what the sections actually mean and what they're for.
-I use GRUB 0.94 and I use DJGPP 2.03
-@ Tora OS: Do you dev on Win32 or not? :P Maybe it's just m$ that causes the problem :P