Page 4 of 5

Re:My print string function

Posted: Fri Mar 26, 2004 11:42 am
by bubach
Ok, thanks.
When i get those functions working i will upload it so that u can see (correct and comment) what i have done. ;)

/ Christoffer

Re:My print string function

Posted: Sun Mar 28, 2004 10:34 am
by Candy
Might I add a suggestion for your assembly skills?

When you call a function in the usual ABI (not sure how you call it, the one on 32-bit linux at least, and probably 32-bit windows as well) you have to save all registers but EAX, and EAX is, for integer returns, *always* used. Even in void functions you can wreck EAX.

This saves a lot of useless movs and pushes/pops :)

Grtz, Candy

Re:My print string function

Posted: Mon Mar 29, 2004 2:19 am
by bubach
Ok, thanks...

Re:My print string function

Posted: Tue Sep 07, 2004 12:05 pm
by bubach
I am back! About 6 months of php-programming have passed since my last visit, but now i am back and i will ask stupid questions until i get this working... :)

Candy, could you be so kind to take another look at this file (slightly cleaned up), and remind me of what stupid misstake i have done? ;)

/ Christoffer

Re:My print string function

Posted: Tue Sep 07, 2004 3:22 pm
by kernel_journeyman
What's that you're doing there? It looks as if you're in 32-bit pmode there. Are you programming the video card directly using the processor's I/O address space? Where did you get the information to do that? Thanks!

Re:My print string function

Posted: Tue Sep 07, 2004 3:48 pm
by Candy
Strictly speaking a VGA CRTC, whereas not all modern video cards emulate that. Or so I've heard, didn't test a thing graphical yet.

Re:My print string function

Posted: Wed Sep 08, 2004 12:45 am
by bubach
i did some more cleaning in the code yesterday, here it is.
can somebody show me there (asm) functions for getcursorxy and/or print_char, so i can compare?


screenshots: http://bubach.1go.dk/os/

Re:My print string function

Posted: Wed Sep 08, 2004 2:22 am
by Brendan
Hi,
bubach wrote: i did some more cleaning in the code yesterday, here it is.
can somebody show me there (asm) functions for getcursorxy and/or print_char, so i can compare?
Answer these questions and I'll rewrite/optimize your code:
- which routines are called by other code?
- what is each segment register normally set to?
- what's more important, speed or size?
- what's the oldest CPU you support?


Cheers,

Brendan

Re:My print string function

Posted: Wed Sep 08, 2004 4:09 am
by bubach
Oh, i don?t care that much about optimization. The reason i "cleaned" it up was becasue the code looked like **** with for example both tabbing and spaces mixed.

The problem is that it doesn?t work. I think that is the getcursorxy and/or print_char function that is buggy.

Re:My print string function

Posted: Wed Sep 08, 2004 5:00 am
by Brendan
Hi,
bubach wrote: Oh, i don?t care that much about optimization. The reason i "cleaned" it up was becasue the code looked like **** with for example both tabbing and spaces mixed.

The problem is that it doesn?t work. I think that is the getcursorxy and/or print_char function that is buggy.
Sorry - I didn't realize it was still buggy :)

I couldn't find anything wrong with getcursorxy, but print_char is a bit messed up. Try this:

Code: Select all

; Print char. IN: bl = char, bh = attrib 
;----------------------------------------
print_char:     pushad
                push    es
                push    ebx

                call    getcursorxy

                cmp     dh, 80
                jb      .l1
                inc     dl
                xor     dh, dh
   .l1:
                cmp     dl, 25
                jb      .l2
                call    scroll_up
   .l2:
                call    getcursor

                movzx   eax, bx
                pop     ebx
                mov     [es:(eax*2 + 0xb8000)], bx

                pop     es
                popad
                ret
Cheers,

Brendan

Re:My print string function

Posted: Wed Sep 08, 2004 5:42 am
by bubach
It looks alot better! Thanks.
Now to see if that fixes the problem...

Re:My print string function

Posted: Thu Sep 09, 2004 8:38 am
by bubach
Finally i got print_char working.
The function is slightly modified from the one you gave me:

Code: Select all

; Print char. IN: bl = char, bh = attrib 
;----------------------------------------
print_char:
                pushad
                push    es
                push    ebx

                call    getcursorxy

                cmp     dl, 25
                jb      .l1
                cmp     dh, 80
                jb      .l1
                call    scroll_up
                
            .l1:
                call    getcursor
                call    inccursor

                movzx   eax, bx
                pop     ebx
                mov     [es:(eax*2 + 0xb8000)], bx

                pop     es
                popad
                ret
that code seems to work fine, but the print string function is really wierd, it clears the screen and goes wild with the cursor on the bottom of the screen.
this is how it looks:

Code: Select all

; Display a asciiz message on the screen.
;       Input: SI = Message, AL = COLOR.
;--------------------------------------------
print:
                pushad
                mov     bh, al

   .DisplayChar:
                lodsb
                or      al, al
                jz      .Done

                cmp     al, 0x0D
                je      .Enter

                cmp     al, 0x0A
                je      .DisplayChar

                mov     bl, al
                call    print_char
                jmp     .DisplayChar

         .Enter:
                call    getcursorxy
                mov     dh, 0x00
                inc     dl
                call    setcursorxy
                jmp     .DisplayChar

          .Done:
                popad
                ret
i have also tried the most basic version, like this:

Code: Select all

; Display a asciiz message on the screen.
;       Input: SI = Message, AL = COLOR.
;--------------------------------------------
print:
                pushad
                mov     bh, al

   .DisplayChar:
                lodsb
                or      al, al
                jz      .Done

                mov     bl, al
                call    print_char
                jmp     .DisplayChar

          .Done:
                popad
                ret
with the same result.
any idea what could be wrong?

Re:My print string function

Posted: Thu Sep 09, 2004 11:50 am
by bubach
I was reading throw some old posts and are wondering if i could get a more detailed explenation on the things that Candy points out below?
Candy wrote: and your stack pointer & gdt are:

Code: Select all

esp:0x9ffc3
gdtr:base=0x88e4, limit=0x17
so that is WAY over the limit. It ends up at a 81ae which is a LOT more than 0x17.
PS: your stack pointer is unaligned. Align it :).
how do i fix this?

And this might be the solution to the print problem:
Candy wrote: You don't set the org for your kernel properly!

The call to your string printing function disassembles as:

Code: Select all

(0).[572064] [0x00100230] 0008:00100230 (unk. ctxt): mov ESI, 00000015         ; be15000000
(0).[572064] [0x00100235] 0008:00100235 (unk. ctxt): mov AL, 0e                ; b00e
(0).[572064] [0x00100237] 0008:00100237 (unk. ctxt): call 001000cd             ; e891feffff
Your string is at 0x00100005. You currently try to print the interrupt vector table.
but how do i fix this?

Re:My print string function

Posted: Sat Sep 11, 2004 11:29 am
by bubach
I finally got it working, throw pm with Candy.
Thanks to all that have helped me.

A nice picture:
Image

I will attach the final (and working) version of text.inc
Hmm, what to do next? :-)

/ bubach

Re:My print string function

Posted: Sat Sep 11, 2004 11:37 am
by Neo
what pic?