My print string function

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.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post 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
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post by bubach »

Ok, thanks...
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
kernel_journeyman

Re:My print string function

Post 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!
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post 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.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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/
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:My print string function

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:My print string function

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post by bubach »

It looks alot better! Thanks.
Now to see if that fixes the problem...
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:My print string function

Post by Neo »

what pic?
Only Human
Post Reply