I am using Ubuntu Hardy to compile and code on, and a Windows 98 machine to test on (it hasn't got very far...)
I have been following this tutorial (just for getting started):
http://www.osdever.n.../cpp_kernel.pdf
Attached is all the code I have at this point (zipped), but here it is for anyone who wants to see it:
#ifndef VIDEO_HEADER
#define VIDEO_HEADER
class Video{
private:
unsigned short* videoMemory;
unsigned int row;
unsigned int column;
public:
Video();
// ~Video();
void clear();
void write(char* p);
void put(char c);
};
#endif
#include "Video.h"
Video::Video(){
row = column = 0;
videoMemory = (unsigned short*)0xb800;
}
//Video::~Video(){
//}
void Video::clear(){
for(unsigned int i=0; i<(80825); i++){
videoMemory[i] = (unsigned char)' '|0x0700;
}
row = column = 0;
}
void Video::write(char* cp){
char* str = cp;
for(char* ch = str; *ch; ch++){
put(*ch);
}
}
void Video::put(char c){
if(column >= 80 || c == '\n'){
column = 0;
row += 80;
}
if(row >= (80*25)){
clear(); // scroll the screen later on.
}
videoMemory[row+column] = (unsigned char)c|0x0700;
column++;
}
#include "Video.h"
int main(void){
Video vid;
vid.write("Welcome to ModOs v1.0a!");
}
[BITS 32] ; protected mode [global start] [extern main] ; this is in our c++ code start: call main ; call int main(void) in C++ file cli; disables interrupts hlt; halts the CPU
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS{
.text 0x100000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
date = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss : {
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
The following code is copied from here:
http://code.google.c.../wiki/FirstStep
; Fat12 Bootloader
[BITS 16] ; We need 16-bit intructions for Real mode
[ORG 0x7C00] ; The BIOS loads the boot sector into memory location 0x7C00
jmp word load_kernel ; Load the OS Kernel
;----------Fat 12 Header junk----------;
db "ONYXDISK" ; OEM Label String
dw 512 ; Bytes per sector
db 1 ; Sectors per FAT cluster
dw 36 ; Resered sector count
db 2 ; number of FATs
dw 224 ; Root dir entries
dw 2880 ; Total Sectors
db 240 ; Double sided, 18 sectors per track
dw 9 ; Sectors per FAT
dw 18 ; Sectors per track
dw 2 ; Head count (double sided)
dd 0 ; Hidden sector count
drive db 0 ; Used to store boot device
;----------Bootsector Code----------;
load_kernel:
jmp read_disk ; Load the OS into memory
;jmp get_ram ; Get ram amount
jmp enter_pm ; Enter Protected Mode
read_disk:
mov ah, 0 ; RESET-command
int 13h ; Call interrupt 13h
mov [drive], dl ; Store boot disk
or ah, ah ; Check for error code
jnz read_disk ; Try again if ah != 0
mov ax, 0
mov ax, 0
mov es, ax
mov bx, 0x1000 ; Destination address = 0000:1000
mov ah, 02h ; READ SECTOR-command
mov al, 12h ; Number of sectors to read (0x12 = 18 sectors)
mov dl, [drive] ; Load boot disk
mov ch, 0 ; Cylinder = 0
mov cl, 2 ; Starting Sector = 3
mov dh, 0 ; Head = 1
int 13h ; Call interrupt 13h
or ah, ah ; Check for error code
jnz load_kernel ; Try again if ah != 0
cli ; Disable interrupts, we want to be alone
enter_pm:
xor ax, ax ; Clear AX register
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
;----------Entering Protected Mode----------;
mov eax, cr0 ; Copy the contents of CR0 into EAX
or eax, 1 ; Set bit 0 (0xFE = Real Mode)
mov cr0, eax ; Copy the contents of EAX into CR0
jmp 08h:kernel_segments ; Jump to code segment, offset kernel_segments
[BITS 32] ; We now need 32-bit instructions
kernel_segments:
mov ax, 10h ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
jmp 08h:0x1000 ; Jump to section 08h (code), offset 01000h
;----------Global Descriptor Table----------;
gdt: ; Address for the GDT
gdt_null: ; Null Segment
dd 0
dd 0
KERNEL_CODE equ $-gdt
gdt_kernel_code:
dw 0FFFFh ; Limit 0xFFFF
dw 0 ; Base 0:15
db 0 ; Base 16:23
db 09Ah ; Present, Ring 0, Code, Non-conforming, Readable
db 0CFh ; Page-granular
db 0 ; Base 24:31
KERNEL_DATA equ $-gdt
gdt_kernel_data:
dw 0FFFFh ; Limit 0xFFFF
dw 0 ; Base 0:15
db 0 ; Base 16:23
db 092h ; Present, Ring 0, Data, Expand-up, Writable
db 0CFh ; Page-granular
db 0 ; Base 24:32
gdt_interrupts:
dw 0FFFFh
dw 01000h
db 0
db 10011110b
db 11001111b
db 0
gdt_end: ; Used to calculate the size of the GDT
gdt_desc: ; The GDT descriptor
dw gdt_end - gdt - 1 ; Limit (size)
dd gdt ; Address of the GDT
times 510-($-$$) db 0 ; Fill up the file with zeros
dw 0AA55h ; Boot sector identifyer
Other commands I have used for compiling, linking and CD burning:
//Compile for assembly files: nasm -f bin Bootloader.asm -o boot.bin nasm -f aout loader.asm -o loader.o //Compile for c++ files: g++-2.95 -c Video.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions g++-2.95 -c Kernel.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions //Linker commands: ld -Ttext 0x1000 Link.ld -o Kernel.bin loader.o Kernel.o Video.o //CD Write commands: dd if=boot.bin of=os.img bs=512 count=1 dd if=Kernel.bin of=os.img bs=512 seek=1
So, I have no idea why this isn't working, does anyone know how to make this successful?
Attached files: [attachment=11989:attachment]
Any help would be greatly appreciated.

New Topic/Question
Reply



MultiQuote





|