Where do i start??

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
jrfritz

Re:Where do i start??

Post by jrfritz »

I think you mean this:


;Read in BootLoader
ReadIn_Kernel:
mov dl, [BootDrive] ;Drive to Read From

mov ax, 0x08 ;Segment to load DiskData to
mov es, ax

mov bx, 0x1000 ;Offset

mov ah, 0x02 ;Get the Segment:Offset from ES:BX

mov ch, 0 ;Cylinder
mov dh, 1 ;Head NEEDS 1!!!
mov al, 4 ;Sectors to Load
mov cl, 6 ;Sector to Start Loading at

int 0x13 ;Read!

jc ReadIn_Kernel ;If there is an Error, Try Again!
Berserk

Re:Where do i start??

Post by Berserk »

Nope, Still Triple Faults when i do the Jump.

Why would i need to set the head to 1 anyway?
Berserk

Re:Where do i start??

Post by Berserk »

Hey, I GOT THE KERNEL TO LOAD!!!

I am going to clean up the code a bit now ;)

Cya.
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

My Kernel is Loaded, i am in Graphics Mode 3, but my printf function doesn't work. Well, i don't think anything is wrong with the function. But why won't it print text?

Here is the Code for my printf function ;D:

Code: Select all

unsigned int printf(char *TextToPrint, unsigned int LineToPrintTextOn, unsigned TextColour)
{
   char* video = (char*)0xB8000;
   unsigned int i = 0;

   i = (LineToPrintTextOn * 80 * 2);

   while (*TextToPrint != NULL)
   {
      if (*TextToPrint == '\n') // check for a new line
      {
         LineToPrintTextOn++;
         i = (LineToPrintTextOn * 80 * 2);
         *TextToPrint++;
      }
      else
      {
         video[i] = *TextToPrint;
         *TextToPrint++;
         i++;

         video[i] = TextColour; //Text Colour
         i++;
      }
   }

 return 1;
}
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

Yep, my Kernel works fine. Just to make sure that my kernel works, in my bootloader i switched to graphics mode 13, and then put some pixels to the screen from my kernel! It worked great. But when i am in TextMode 3, i can't PrintText to the screen, so could somebody please look at the function. What am i doing wrong?

Could it be something in the BootLoader?

Well, at least the Kernel actually gets loaded ;)

Thanks in advance ;);D
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

I am just going to say some more stuff, then i'll wait for somebody's help. Please, i really want to get this working ;D

Ok, my Kernel has C++ support, it is loaded from an asm module that is linked to is, the module looks like this:

Code: Select all

[BITS 32]

[GLOBAL KernelLoader]
[EXTERN _k_main]

 KernelLoader:
                 call _k_main

                 cli
                 hlt
The Kernel layour is like this:

First is has the clrscr function, then the printf, then the k_main function.

When i try to print text nothing happens? Could this be that thing gow gcc puts strings before the main function or something?

I use MinGW (just so you'se know)

So could somebody that has C++ support help me out, the support works fine, it just doesn't want to print text??

I know that Tom & whytme_t have C++ support ;D So if you'se know, please help.

Thanks in advance,
I'll be back in 15 hours ;)
Cya.
beyondsociety

Re:Where do i start??

Post by beyondsociety »

Code: Select all

         mov ax, 0x08            ;Segment to load DiskData to
         mov es, ax
         mov bx, 0x1000
You cant do this unless you are already in pmode. Because the 0x08 is the Code Segment Descriptor. But I could be wrong!
Berserk

Re:Where do i start??

Post by Berserk »

The Kernel Loads, it works. It just doesn't want to print text to the screen in text mode 3?

Do you know what might be the problem? (Look at previous posts)?
beyondsociety

Re:Where do i start??

Post by beyondsociety »

Sorry but, I can't help you. I still working on my C kernel.

If you post your pmode bootsector, I'll be glad to take a look at it.
Berserk

Re:Where do i start??

Post by Berserk »

Here:

Code: Select all

[BITS 16]
[ORG 0x7E00]

;Jump over the Functions & Variables, and goto the BootCode
 jmp StartOf_Code

 BootDrive db 0

 StartOf_Code:
                mov [BootDrive], dl


;Reset the FloppyDrive
 Reset_FloppyDrive:
                mov ax, 0x00               ;Select Reset Function
                mov dl, [BootDrive]        ;Select Drive to Reset
                int 0x13                   ;Call FloppyDrive Interrupt

                jc Reset_FloppyDrive       ;If there is an Error, Try Again!

;Read in Kernel
 ReadIn_Kernel:
                mov dl, [BootDrive]        ;Drive to Read From

                mov ax, 0x08               ;Segment to load DiskData to
                mov es, ax

                mov bx, 0x2000             ;Offset

                mov ah, 0x02               ;Get the Segment:Offset from ES:BX

                mov ch, 0                  ;Cylinder
                mov dh, 0                  ;Head
                mov al, 10                 ;Sectors to Load
                mov cl, 6                  ;Sector to Start Loading at

                int 0x13                   ;Read!

                jc ReadIn_Kernel

                jmp Enter_ProtectedMode

;Enter PM (Protected Mode)
 Enter_ProtectedMode:

 ;Disable Interrupts
                cli

;Enable the A20 Gate
 Enable_A20_Gate:
                call Empty_8042
                mov  al, 0x0D1
                out  0x64, al

                call Empty_8042
                mov  al, 0x0DF
                out  0x60, al

                call Empty_8042
                jmp  A20_Gate_Enabled

 Empty_8042:
                mov  al, 0x0D0
                in   al, 0x64
                test al, 2
                jnz  Empty_8042
                ret

 A20_Gate_Enabled:

;Move the GDT into Memory
                mov ax, 0x1000
                mov es, ax
                mov si, GDT
                xor di, di
                mov cx, 6
                cld
                rep movsd

;Load the GDT (Global Descriptor Table) Pointer
                lgdt [GDT_Pointer]

;Set PM (ProtectedMode) Bit
                mov eax, cr0
                or eax,  1
                mov cr0, eax

;Jump into PM Code
                jmp 0x08:In_ProtectedMode

[BITS 32]

;This is where Protected Mode is Entered!
 In_ProtectedMode:

;Put the Data Selector into eax for setting up other registers
                mov eax, 0x10

;Make SS, DS, ES, FS and GS = The Data Selector
                mov ss, eax
                mov ds, eax
                mov es, eax
                mov fs, eax
                mov gs, eax

;Set up a Protected Mode Stack
                mov eax, 0x10
                mov ss,  eax
                mov esp, 0xFFFF

;Stop the FloppyDisk Drive Motor from Spinning
 Stop_FloppyDisk_Drive_Motor:
                mov dl, [BootDrive]

;Select - Stop FloppyDisk Drive Motor Function!
                mov edx, 0x3F2
                mov al,  0x0C

;Stop the Motor:
                out dx, al

                jmp 0x08:0x2000

GDT_Pointer:
                dw 0xFFFF
                dd 0x00010000

GDT:
;Null 0x00 Descriptor
                dd 0
                dd 0

;CodeSegment 0x08 Descriptor
                db 11111111b ; 7:0 of Limit
                db 11111111b ; 15:8 of Limit
                db 00000000b ; 7:0 of Base
                db 00000000b ; 15:8 of Base
                db 00000000b ; 23:16 of Base
                db 10011010b ; Present | DPL = 0 | Code or Data Seg | Code Seg | Non-Conforming | Readable | Not Accessed
                db 11001111b ; 4KB Granular | 32-Bit | Reserved | Avl = 0 | 20:16 of Limit
                db 00000000b ; 32:24 of Base

;DataSegment 0x10 Descriptor
                db 11111111b ; 7:0 of Limit
                db 11111111b ; 15:8 of Limit
                db 00000000b ; 7:0 of Base
                db 00000000b ; 15:8 of Base
                db 00000000b ; 23:16 of Base
                db 10010010b ; Present | DPL = 0 | Code or Data Seg | Data Seg | Expand Up | Writable | Not Accessed
                db 11001111b ; 4KB Granular | 32-Bit | Reserved | Avl = 0 | 20:16 of Limit
                db 00000000b ; 32:24 of Base
EndOf_GDT
 CodePadding     times 2048-($-$$) db 0
NOTE: I took most of the comments out of it, so my post wouldn't be too big ;)

This is my Second Stage Loader. As i said, my Kernel Loads fine, but it doesn't want to print text to the screen in text mode 3!
beyondsociety

Re:Where do i start??

Post by beyondsociety »

This won't work, because your in real-mode

Code: Select all

mov ax, 0x08              ; Should be: 0x0000
mov es, ax
mov bx, 0x2000          ; This is okay   
Segments mean a totally different thing in real-mode compared to in protected-mode. In protected mode that 0x08 is actually a selector for the code segment in protected mode.

I see no code for printing text to the screen in text mode 3!. Is it in your bootsector or is it in your C kernel.
Berserk

Re:Where do i start??

Post by Berserk »

Hey,

Ok i changed it, but it seemed to work without me changing it anyways ;D

My printf function is in my C++ Kernel (With no Run-Time support, i just made it C++ so i could use classes ;)) The code you just saw is my SECOND stage loader ;D It gets loaded by my BootSector!

I posted it in a previous thread, so i am not going to post it again ;D Just scroll up!

NOTE: I use MinGW.

I wonder what the problem is? I made my BootLoader go into mode 13, and i put some pixels to the screen and it works fine. But when i try and print text in mode 3, the screen just remains black??
beyondsociety

Re:Where do i start??

Post by beyondsociety »

I've tried to look at the previous posts and most of them look like gobbygook. I suggest posting your bootsector code. You can either post it here for other people to see or you can IM me on this forum and post it there.

By the way, in order to send a IM message, click on my name, click on private message.
Berserk

Re:Where do i start??

Post by Berserk »

Hi,

What would the BootSector Code help you determine?

It's just a BootSector that loads the second stage loader! The second stage loader is in my previous post!

And how come the code looks jumbled? It looks fine to me?
beyondsociety

Re:Where do i start??

Post by beyondsociety »

Are you setting up graphics mode 3 in your bootsector?
If so, would you post it.

Its easier for me to see your problem if I have code. The main reason was so that I could look at your graphics mode code.

Are you tying to print your messages from your C kernel?
If so, then theres probally something wrong with your kernel code and I'll see if I can take a look at it.

I was referring to the different kinds of code in all your posts. There was not one post where you had your whole bootsector code. Because of this, I couldn't see what your problem was.
Post Reply