Got almost everything working except this thing.
Got almost everything working except this thing.
Hi!
I've just started doing my own bootloader and kernel but I am stuck with a probably simple thing but I can not get it to work.
I am able to load the kernel but I cant seem to get arrays to work. What is the problem?
Im using WinXP with Mingw gcc, ld and Nasm.
I've just started doing my own bootloader and kernel but I am stuck with a probably simple thing but I can not get it to work.
I am able to load the kernel but I cant seem to get arrays to work. What is the problem?
Im using WinXP with Mingw gcc, ld and Nasm.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:Got almost everything working except this thing.
Are you asking us to guess?Jens wrote:What is the problem?
(Hint: Try at least providing some code and error messages...)
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re:Got almost everything working except this thing.
I think the problem might have something to do with my compiling commands or perhaps that I have forgot to setup some register or something... i have shorten some code so that it could be posted here.
==== BOOT.ASM ====
[bits 16]
[org 0x7c00]
jmp boot ; jump over the data to our code
;-----------------------Data-----------------------;
;------------GDT Table---------------;
;----------End GDT Table-------------;
;------------Variables---------------;
;----------End Variables-------------;
;------------Functions---------------;
;; 'wait keyboard to clear' function ;;
wkc:
;; 'wait keyboard to be full' function ;;
wkf:
;; 'halt on error' function ;;
halt:
;----------End Functions-------------;
;---------------------End Data---------------------;
boot:
mov [drive],dl ; save boot drive number(0x00=floppy 0x80=hard drive)
mov ax,cs ; setup ds segment
mov ds,ax
mov es,ax
mov fs,ax
mov ax,0x1D0 ; stack is at 0x1D00
mov ss,ax ; align stack also
mov sp,0x200 ; 512 byte stack
mov ax,0xb800 ; setup video segment
mov gs,ax
jmp init ; Some BIOSes jump to 0x7c0:0x0 rather than 0x0:0x7c0
init:
==== A20 ====
sti
==== LOAD KERNEL ====
; move GDT to 0x500
xor ax,ax
mov ds,ax
mov es,ax
mov si,GDT ; Move From [DS:SI]
mov di,[GDTbase] ; Move to [ES:DI]
mov cx,[GDTsize] ; size of GDT
cld ; Clear the Direction Flag
rep movsb ; Move it
cli
;enter pmode
mov eax,cr0
or al,1
mov cr0,eax
;load gdt
lgdt[GDTR]
;clear cs/ip/eip
jmp CODESEL:FLUSH ; set cs to CODESEL
[bits 32]
FLUSH:
;refresh all segment registers
mov eax,DATASEL
mov ds,eax
mov es,eax
mov fs,eax
mov gs,eax
mov ss,eax
mov esp,0xffff
;jump to kernel
jmp CODESEL:0x100000
hlt
TIMES 510-($-$$) DB 0
SIGNATURE DW 0xAA55
==== LOAD.ASM ====
[bits 32] ; 32bit code here
[global start] ; start is a global function
[extern _k_main] ; this is the kernel function
start:
call _k_main
jmp $
==== MAIN.C ====
void k_main() {
while(1);
}
==== COMPILE COMMANDS ====
nasm -f bin boot.asm -o boot.bin
nasm -f win32 load.asm -o load.o
C:\Program\CodeBlocks\bin\gcc -ffreestanding -c main.c -o main.o
C:\Program\CodeBlocks\bin\ld -T link.ld -o kernel.o load.o main.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
partcopy boot.bin 0 200 hd10meg.img
partcopy kernel.bin 0 400 hd10meg.img 200
==== BOOT.ASM ====
[bits 16]
[org 0x7c00]
jmp boot ; jump over the data to our code
;-----------------------Data-----------------------;
;------------GDT Table---------------;
;----------End GDT Table-------------;
;------------Variables---------------;
;----------End Variables-------------;
;------------Functions---------------;
;; 'wait keyboard to clear' function ;;
wkc:
;; 'wait keyboard to be full' function ;;
wkf:
;; 'halt on error' function ;;
halt:
;----------End Functions-------------;
;---------------------End Data---------------------;
boot:
mov [drive],dl ; save boot drive number(0x00=floppy 0x80=hard drive)
mov ax,cs ; setup ds segment
mov ds,ax
mov es,ax
mov fs,ax
mov ax,0x1D0 ; stack is at 0x1D00
mov ss,ax ; align stack also
mov sp,0x200 ; 512 byte stack
mov ax,0xb800 ; setup video segment
mov gs,ax
jmp init ; Some BIOSes jump to 0x7c0:0x0 rather than 0x0:0x7c0
init:
==== A20 ====
sti
==== LOAD KERNEL ====
; move GDT to 0x500
xor ax,ax
mov ds,ax
mov es,ax
mov si,GDT ; Move From [DS:SI]
mov di,[GDTbase] ; Move to [ES:DI]
mov cx,[GDTsize] ; size of GDT
cld ; Clear the Direction Flag
rep movsb ; Move it
cli
;enter pmode
mov eax,cr0
or al,1
mov cr0,eax
;load gdt
lgdt[GDTR]
;clear cs/ip/eip
jmp CODESEL:FLUSH ; set cs to CODESEL
[bits 32]
FLUSH:
;refresh all segment registers
mov eax,DATASEL
mov ds,eax
mov es,eax
mov fs,eax
mov gs,eax
mov ss,eax
mov esp,0xffff
;jump to kernel
jmp CODESEL:0x100000
hlt
TIMES 510-($-$$) DB 0
SIGNATURE DW 0xAA55
==== LOAD.ASM ====
[bits 32] ; 32bit code here
[global start] ; start is a global function
[extern _k_main] ; this is the kernel function
start:
call _k_main
jmp $
==== MAIN.C ====
void k_main() {
while(1);
}
==== COMPILE COMMANDS ====
nasm -f bin boot.asm -o boot.bin
nasm -f win32 load.asm -o load.o
C:\Program\CodeBlocks\bin\gcc -ffreestanding -c main.c -o main.o
C:\Program\CodeBlocks\bin\ld -T link.ld -o kernel.o load.o main.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
partcopy boot.bin 0 200 hd10meg.img
partcopy kernel.bin 0 400 hd10meg.img 200
Re:Got almost everything working except this thing.
SORRY!!! Arrays work, but pointers dont... this main.c doesnt work for instance:
Code: Select all
void print(char message[])
{
unsigned char *vidmem = (unsigned char *)0xB8000;
*vidmem = message[0];
}
void k_main()
{
char *myString;
myString = "hejsan";
print(myString);
while(1);
}
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:Got almost everything working except this thing.
Your code would be easier to read if you put code tags around it.Jens wrote:Code: Select all
void print(char message[]) { unsigned char *vidmem = (unsigned char *)0xB8000; *vidmem = message[0]; }
Video memory in text mode is actually an interleaving of character bytes and attribute bytes. Here is an example from the FAQ of what you're trying to do:
Code: Select all
/* note this example will always write to the top
line of the screen */
void write_string(int colour, char *string)
{
char *video=(char*)0xB8000;
while(*string!=0)
{
*video=*string;
string++;
video++;
*video=colour;
video++;
}
}
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re:Got almost everything working except this thing.
Thanks alot for the reply! The print function you gave me was alot better than the one i had, thanx you!
However the problem still exist... if I define the string as
char *myString = {'h','i',0};
i can print(myString); but not if i define it as
char *myString = "hi";
Well... ill probably figure it out eventually...
However the problem still exist... if I define the string as
char *myString = {'h','i',0};
i can print(myString); but not if i define it as
char *myString = "hi";
Well... ill probably figure it out eventually...
Re:Got almost everything working except this thing.
Another oops! The line:
char *myString = {...};
was ment to be:
char myString[3] = {...};
char *myString = {...};
was ment to be:
char myString[3] = {...};
Re:Got almost everything working except this thing.
The .rodata section. Add "*(.rodata*)" to .text in the link script.
Re:Got almost everything working except this thing.
That didnt help. This is my linker script:
ENTRY(start)
SECTIONS
{
.text 0x00100000 : {
*(.text)
*(.rodata*)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
}
ENTRY(start)
SECTIONS
{
.text 0x00100000 : {
*(.text)
*(.rodata*)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
}
Re:Got almost everything working except this thing.
I have also tried *(.rodata) and also making it its own section... nothing works...
Re:Got almost everything working except this thing.
Solved it... the compiler named it .rdata and not .rodata... now it works! yes!
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Got almost everything working except this thing.
just out of curiosity, what compiler is that ? (version, distro, etc. "gcc --version" should tell this all)
Re:Got almost everything working except this thing.
I somehow doubt that "gcc --version" will help, since I also doubt that he's using gcc.Pype.Clicker wrote: just out of curiosity, what compiler is that ? (version, distro, etc. "gcc --version" should tell this all)
Re:Got almost everything working except this thing.
Candy wrote:I somehow doubt that "gcc --version" will help, since I also doubt that he's using gcc.Pype.Clicker wrote: just out of curiosity, what compiler is that ? (version, distro, etc. "gcc --version" should tell this all)
Either the MinGW people changed it because they felt like it (unlikely), or COFF/PE calls it "rdata" and it was changed to match.Jens wrote:Im using WinXP with Mingw gcc, ld and Nasm.
Re:Got almost everything working except this thing.
Remind me not to post before drinking at least one +2 coffee (yes, our coffee machine actually calls it a +2 coffee if you press extra strong twice).AR wrote:Candy wrote:I somehow doubt that "gcc --version" will help, since I also doubt that he's using gcc.Pype.Clicker wrote: just out of curiosity, what compiler is that ? (version, distro, etc. "gcc --version" should tell this all)Either the MinGW people changed it because they felt like it (unlikely), or COFF/PE calls it "rdata" and it was changed to match.Jens wrote:Im using WinXP with Mingw gcc, ld and Nasm.