Hallo,
ich habe den Kernel abgeändert, sodass er VGA nutzt und eigentlich ein Pixel der Position x=10 und y=10 blau färben müsste. Nun tut er dies leider nicht. Es kommt einfach ein schwarzer Bildschirm, wo nur steht, dass das BIOS geladen wurde. Der QEMU-log ist genauso wie vorher! Das Compilen ging fehlerfrei. Es gabe lediglich 3 warnungen auf unbenutze Werte. Das ist aber normal. Ich hoffe ihr könnt mir noch einmal helfen. Solbalt ich ein pixel erfolgreich gefärbt habe komme ich vorerst alleine weiter. Hier mein Code:
asmKernel.asm:
global loader ; Unser Einsprungspunkt
extern kernelMain ; kernelMain() aus Kernel.cpp
extern initialiseConstructors ; aus Startup.cpp
FLAGS equ 0
MAGIC equ 0x1BADB002 ; Magicnumber - Erkennungsmerkmal für GRUB
CHECKSUM equ -(MAGIC + FLAGS) ; Checksum
section .text
align 4
MultiBootHeader:
dd MAGIC ; Magic number
dd FLAGS ; Flags
dd CHECKSUM ; Checksum
loader:
mov esp,0x200000 ; Stack an die 2MB-Grenze platzieren
push eax ; Multiboot-Magicnumber auf den Stack legen
push ebx ; Adresse der Multiboot-Structure auf den Stack legen
call initialiseConstructors ; Konstruktoren aufrufen
call kernelMain ; kernelMain aufrufen
stop:
jmp stop
Kernel.cpp:
// Einbinden unseres Header
#include "Video.h"
#include "Multiboot.h"
#include "stdio.h"
extern "C" void kernelMain(const Multiboot& multiboot_structur,
uint32_t multiboot_magic);
void kernelMain(const Multiboot& multiboot_structur,
uint32_t multiboot_magic)
{
if (multiboot_magic != MULTIBOOT_MAGIC)
{
// Fehler!
//screen << background(color::light_gray) << color::blue << "Loading BOS(S)-Kernel...";
return;
}
}
link.txt:
ENTRY(loader)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)
SECTIONS
{
. = 0x0100000;
.text :
{
*(.text*)
*(.rodata)
}
.data :
{
start_ctors = .;
*(.ctors)
end_ctors = .;
*(.data)
}
.bss :
{
*(.bss)
}
/DISCARD/ : { *(.dtors) *(.comment) }
}
Multiboot.h:
#ifndef MULTIBOOT_H
#define MULTIBOOT_H
#include "stdint.h"
#define MULTIBOOT_MAGIC 0x2BADB002
struct Multiboot
{
uint32_t flags;
uint32_t mem_lower;
uint32_t mem_upper;
uint32_t bootdevce;
uint32_t cmdline;
uint32_t module_count;
uint32_t module_address;
/* etc... */
} PACKED;
#endif
Startup.cpp:
typedef void (*constructor)();
// Im Linkerskript definiert
extern "C" constructor start_ctors;
extern "C" constructor end_ctors;
extern "C" void initialiseConstructors();
// Ruft die Konstruktoren für globale/statische Objekte auf
void initialiseConstructors()
{
for (constructor* i = &start_ctors;i != &end_ctors;++i)
(*i)();
}
stdint.h:
/* ISO C9x 7.18 Integer types <stdint.h>
* Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Date: 2000-12-02
*/
#ifndef _STDINT_H
#define _STDINT_H
#define __need_wint_t
#define __need_wchar_t
#include <stddef.h>
/* 7.18.1.1 Exact-width integer types */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned uint32_t;
/* 7.18.1.2 Minimum-width integer types */
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef short int_least16_t;
typedef unsigned short uint_least16_t;
typedef int int_least32_t;
typedef unsigned uint_least32_t;
/* 7.18.1.3 Fastest minimum-width integer types
* Not actually guaranteed to be fastest for all purposes
* Here we use the exact-width types for 8 and 16-bit ints.
*/
typedef signed char int_fast8_t;
typedef unsigned char uint_fast8_t;
typedef short int_fast16_t;
typedef unsigned short uint_fast16_t;
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
/* 7.18.1.4 Integer types capable of holding object pointers */
#ifndef _INTPTR_T_DEFINED
#define _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef int intptr_t;
#endif
#endif
#ifndef _UINTPTR_T_DEFINED
#define _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
typedef unsigned int uintptr_t;
#endif
#endif
/* 7.18.2 Limits of specified-width integer types */
#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
/* 7.18.2.1 Limits of exact-width integer types */
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT64_MIN (-9223372036854775807LL - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 0xff /* 255U */
#define UINT16_MAX 0xffff /* 65535U */
#define UINT32_MAX 0xffffffff /* 4294967295U */
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
/* 7.18.2.2 Limits of minimum-width integer types */
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
/* 7.18.2.3 Limits of fastest minimum-width integer types */
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
/* 7.18.2.4 Limits of integer types capable of holding
object pointers */
#ifdef _WIN64
#define INTPTR_MIN INT64_MIN
#define INTPTR_MAX INT64_MAX
#define UINTPTR_MAX UINT64_MAX
#else
#define INTPTR_MIN INT32_MIN
#define INTPTR_MAX INT32_MAX
#define UINTPTR_MAX UINT32_MAX
#endif
/* 7.18.2.5 Limits of greatest-width integer types */
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
/* 7.18.3 Limits of other integer types */
#define PTRDIFF_MIN INTPTR_MIN
#define PTRDIFF_MAX INTPTR_MAX
#define SIG_ATOMIC_MIN INTPTR_MIN
#define SIG_ATOMIC_MAX INTPTR_MAX
#define SIZE_MAX UINTPTR_MAX
#ifndef WCHAR_MIN /* also in wchar.h */
#define WCHAR_MIN 0
#define WCHAR_MAX 0xffff /* UINT16_MAX */
#endif
/*
* wint_t is unsigned short for compatibility with MS runtime
*/
#define WINT_MIN 0
#define WINT_MAX 0xffff /* UINT16_MAX */
#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
/* 7.18.4 Macros for integer constants */
#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
/* 7.18.4.1 Macros for minimum-width integer constants
Accoding to Douglas Gwyn <gwyn@arl.mil>:
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
9899:1999 as initially published, the expansion was required
to be an integer constant of precisely matching type, which
is impossible to accomplish for the shorter types on most
platforms, because C99 provides no standard way to designate
an integer constant with width less than that of type int.
TC1 changed this to require just an integer constant
*expression* with *promoted* type."
*/
#define INT8_C(val) val
#define UINT8_C(val) val
#define INT16_C(val) val
#define UINT16_C(val) val
#define INT32_C(val) val
#define UINT32_C(val) val##U
#define INT64_C(val) val##LL
#define UINT64_C(val) val##ULL
/* 7.18.4.2 Macros for greatest-width integer constants */
#define INTMAX_C(val) INT64_C(val)
#define UINTMAX_C(val) UINT64_C(val)
#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
#endif
Video.cpp:
#include "Video.h"
Video screen;
Video::Video()
: m_videomem((uint16_t*) 0xA0000 ), m_color(0x0700)
{
clear();
}
Video::~Video(){
}
void Video::clear(){
setpixel(10, 10, color::blue);
}
Video& Video::operator << (const char* s){
return *this;
}
Video& Video::operator << (color::type color){
return *this;
}
Video& Video::operator << (const background& color){
return *this;
}
void Video::setpixel(int x, int y, color::type color) {
int offset;
if(0 <= x && x < 320) {
if(0 <= y && y < 200) {
offset = 320*y + x;
m_videomem[offset] = color;
}
}
}
Video.h:
#ifndef VIDEO_H
#define VIDEO_H
#include "stdint.h"
namespace color
{
enum type
{
black = 0x00,
blue = 0x01,
green = 0x02,
cyan = 0x03,
red = 0x04,
magenta = 0x05,
brown = 0x06,
light_gray = 0x07,
dark_gray = 0x08,
light_blue = 0x09,
light_green = 0x0A,
light_cyan = 0x0B,
light_red = 0x0C,
light_magenta = 0x0D,
yellow = 0x0E,
white = 0x0F
};
}
struct background
{
inline background(color::type color)
: m_color(color){}
color::type m_color;
};
class Video
{
public:
// Konstruktor
Video();
// Destruktor
~Video();
// Leeren des Bildschirms, die Größe beträgt 80x25 Zeichen
void clear();
// Textausgabe
Video& operator << (const char* s);
// Vordergrundfarbe setzen
Video& operator << (color::type color);
// Hintergrundfarbe setzen
Video& operator << (const background& color);
// Ausgabe eines einzelnen Zeichens
void setpixel(int x, int y, color::type color);
private:
// Zeiger auf den Videospeicher
uint16_t* m_videomem;
// FB/BG-Farbe
uint16_t m_color;
};
// Globale Instanz der Video-Klasse, Definition in Video.cpp
extern Video screen;
#endif