Guten Tag
Sobald ich mein System über den GRUB starte, kann ich keine globalen Variablen nutzen. (qemu -fda floppy.img)
Das heisst wenn ich im globalen Bereich z.B eine char* deklariere & definiere, gibt die printf funktion nichts aus, wenn ich diese Variable als Parameter übergebe.
wenn ich aber denn Kernel mit qemu direkt starte, dann kann ich die globalen Variablen problemlos nutzen. (qemu -kernel kernel.bin)
Muss ich irgendwo noch explizit für den globalen Bereich speicher reservieren?
Die relevanten Files:
loader.asm
global loader ; making entry point visible to linker
extern kernel ; kmain is defined in kmain.cpp
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
section .text
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM
; reserve initial kernel stack space
STACKSIZE equ 0x200000 ; that's 2MB
;STACKSIZE equ 0xFFFF
loader:
mov esp, stack + STACKSIZE ; set up the stack
push eax ; Multiboot magic number
push ebx ; Multiboot info structure
call kernel ; call kernel proper
cli
.hang:
hlt ; halt machine should kernel return
jmp .hang
section .bss
align 4
stack:
resb STACKSIZE ; reserve 16k stack on a doubleword boundary
kernel.c
#include "global.h"
#include "video.h"
#include "keyboard.h"
#include "commandline.h"
#include "utils.h"
void kernel( void* mbd, unsigned int magic )
{
if ( magic != 0x2BADB002 )
{
/* Something went not according to specs. Print an error */
/* message and halt, but do *not* rely on the multiboot */
/* data structure. */
printf("GRUB-Magic-Number ist nicht korrekt!",10);
}
/* You could either use multiboot.h */
/* (http://www.gnu.org/software/grub/manual/multiboot/multiboot.html#multiboot_002eh) */
/* or do your offsets yourself. The following is merely an example. */
//char * boot_loader_name =(char*) ((long*)mbd)[16];
while((inportb(0x64) & 0x2)) {}
outportb(0x60, 0xF4);
clear_screen();
printf("Welcome to TinyOS 0.1 !", 0);
changeColor(GREEN_TEXT,0x0);
update_cursor(1,0);
}
loader.ld
ENTRY (loader)
SECTIONS
{
. = 0x00100000;
.text ALIGN (0x1000) :
{
*(.text)
}
.rodata ALIGN (0x1000) :
{
*(.rodata*)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss :
{
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}
comple_scriph.sh
nasm -f elf -o loader.o loader.asm
gcc -m32 -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
gcc -m32 -o clear_screen.o -c clear_screen.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
gcc -m32 -o change_color.o -c change_color.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
gcc -m32 -o printf.o -c printf.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
gcc -m32 -o cursor.o -c cursor.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
gcc -m32 -o utils.o -c utils.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
gcc -m32 -o keyboard.o -c keyboard.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
gcc -m32 -o commandline.o -c commandline.c -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
ld -m elf_i386 -T loader.ld -o kernel.bin loader.o kernel.o clear_screen.o change_color.o printf.o cursor.o utils.o keyboard.o commandline.o
cat stage1 stage2 pad kernel.bin > floppy.img
Danke im Voraus.
Freundliche Grüsse
James