flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Print routine

Author
Thread Post new topic Reply to topic
Just me



Joined: 10 Jun 2006
Posts: 14
Just me
Hi all
I'am not to sure if this is a bug or not
Code:
format binary 
org 0x0000 
use16 
;;; Set default screen mode [effect clear screen] 
mov ah,0 
mov al,3 
int 0x10 
mov ax,0x1000 
cli 
mov ds,ax 
mov es,ax 
sti 
call DrawScreen 
jmp $ 

DrawScreen: ;;; Display loader title 
mov ah,2 
xor bh,bh 
mov dh,0 
mov dl,3 
int 0x10 
mov di,TitleBar 
call DisplayString 
ret 

DisplayString: ;;; Enter with SI ptr to string to display 
mov al,[si] ;;; POSSIBLE PROBLEM 
mov ah,0x0a 
xor bx,bx 
mov cx,1 
int 0x10 

ExitDisplayString: ret 

TitleBar: db 'OS 1 [Build 0001] loader',0x00 
    


Now if I put a value directly in the al register it prints, but if not it displays
nothing. The code I have used is pretty much the same as used for
my boot sector. The loader is loaded at [0x1000:0000] and then a jump
made to that location. I just seems a bit wierd that a value used direct works but not if I use a ptr. I have tried other bios routines but with
the same effect!
Any help would be appreciated.
Post 10 Jun 2006, 21:23
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Should you not point TitleBar to si
Code:
mov di,TitleBar     

Even then, it will only print 1 char.
Post 10 Jun 2006, 21:32
View user's profile Send private message Reply with quote
Just me



Joined: 10 Jun 2006
Posts: 14
Just me
Hi Dex4u
Just a silly typo:) The code should display a character but doesn't.

It only displays a character if an index isn't used!!!! ( the al is loaded direct [mov al,'@'])
I wounder if it has anything to do with setting the cursor location bios call?
Post 10 Jun 2006, 22:16
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Can you post the loader code? I think it's possible that DS isn't setted with the current segment. You can also replace "mov ax,0x1000" with "mov ax,cs" to be sure that DS will point to the same segment where the code is located (and the string)
Post 10 Jun 2006, 22:34
View user's profile Send private message Reply with quote
Just me



Joined: 10 Jun 2006
Posts: 14
Just me
Hi locodelassembly
Already tried what you had suggested but didn't work. So as ask the boot
sector code [not very pretty]
Code:
org 0x7c00
use16
format binary

Begin:                  jmp Start
                        nop

TotalDiskSize:          dq 0    ;;; Total size of physical disk in sctors
PartitionTableEntries:
                        db 1                    ;;; Partition bootable [1=Yes, 0=no]
                        dq 2                    ;;; Partition location [0 indexed]
                        dq 160084413            ;;; Partition size in sectors [maybe]
rept 3 {
                        db 0    ;;; Partition bootable [1=Yes, 0=no]
                        dq 0    ;;; Partition location
                        dq 0    ;;; Partition size in sectors
       }

Start:                  xor ax,ax
                        cli
                        mov ds,ax
                        mov ss,ax
                        mov es,ax
                        mov sp,0x7c00
                        sti
                        cld

                        mov si,Message
                        call DisplayString

                        ;;; Attempt to find first bootable partition.
                        mov cx,4
                        mov si,PartitionTableEntries
FindBootablePartition:  lodsb
                        cmp al,0
                        jne FoundBootablepartition
                        add si,16
                        loop FindBootablePartition
                        ;;; No bootable partition has been found so
                        ;;; display an error message.
                        mov si,NoBootablePartition
                        jmp DisplayError

FoundBootablepartition: ;;; Attempt to load in partition starting sector
                        ;;; Assign "ExtendedReadData" start sector to load from
                        ;;; [Note: SI points to "PartitionTableEntries"]
                        mov eax,dword[si]
                        mov dword[StartSectorTransfer],eax
                        mov eax,dword[si+4]
                        mov dword[StartSectorTransfer+4],eax
                        call ReadSector2

                        ;;; Obtain "Root" directory location from partition
                        ;;; sector.
                        mov si,0x7c00+0x0200+0x012d
                        call ReadSector

                        ;;; Obtain "Boot" directory location
                        ;;; Scan each entry in the root directory
                        ;;; to find it.
                        ;;; [Note: First entry is at the beginning of the
                        ;;; root directory]
FileEntryLoop1:         mov di,DiskError2+4
                        mov si,0x7c00+0x0200+0x28
                        ;cld
                        mov cx,5
                        repe cmpsb
                        ;cmp cx,0
                        jcxz CheckForDirectoryMarker
                        ;;; Load in next file entry and loop
NotADirectoryEntry:     mov eax,dword[0x7c00+0x0200+0x0e]
                        cmp eax,0
                        je Test1
ReturnTest1:            mov dword[StartSectorTransfer],eax
                        mov eax,dword[0x7c00+0x0200+0x0e+4]
                        mov dword[StartSectorTransfer+4],eax
                        call ReadSector2
                        jmp FileEntryLoop1

Test1:                  ;;; Check for last entry in file table
                        mov eax,dword[0x7c00+0x0200+0x0e+4]
                        cmp eax,0
                        je NoBootDirectory      ;;; No more entries in root directory
                        mov eax,dword[0x7c00+0x0200+0x0e]
                        jmp ReturnTest1


CheckForDirectoryMarker:cmp byte[0x07c00+0x0200+0x0137],1
                        jne NotADirectoryEntry
                        ;;; File entry marker is for a directory
                        ;;; Load directory "Boot" sector first entry
                        mov si,0x7c00+0x0200+0x0138
                        call ReadSector

                        ;;; Now at the top entry in the "boot" directory
FileEntryLoop2:         mov di,FileIs
                        mov si,0x7c00+0x0200+0x28
                        mov cx,14
                        repe cmpsb
                        ;cmp cx,0
                        jcxz CheckForFileMarker
                        ;;; Check for last entry in file table
NotAFileEntry:          mov eax,dword[0x7c00+0x0200+0x0e+4]
                        cmp eax,0
                        je Test2
ReturnTest2:            mov dword[StartSectorTransfer],eax
                        mov eax,dword[0x7c00+0x0200+0x0e+4]
                        mov dword[StartSectorTransfer+4],eax
                        call ReadSector2
                        jmp FileEntryLoop2

Test2:                  ;;; Check for last entry in file table
                        mov eax,dword[0x7c00+0x0200+0x0e+4]
                        cmp eax,0
                        je NoLoaderBinary
                        mov eax,dword[0x7c00+0x0200+0x0e]
                        jmp ReturnTest2

CheckForFileMarker:     cmp byte[0x07c00+0x0200+0x0137],0
                        jne NotAFileEntry

                        ;;; Attempt to load "Loader.binary"
                        mov ax,0x1000
                        mov [MSegment],ax
                        xor ax,ax
                        mov ax,[MOffset]
                        ;;; Location
                        mov eax,dword[0x7c00+0x0200+0x0148]
                        mov dword[StartSectorTransfer],eax
                        mov eax,dword[0x7c00+0x0200+0x0148+4]
                        mov dword[StartSectorTransfer+4],eax
                        ;;; Size
                        mov al,byte[0x7c00+0x0200+0x0140]
                        mov byte[Sectors],al

                        call ReadSector2


                        jmp 0x1000:0000


DisplayString:          ;;; Enter with SI ptr to string to display
                        lodsb
                        or al,al
                        jz ExitDisplayString
                        mov ah,0x0e
                        int 0x10
                        jmp DisplayString
ExitDisplayString:      ret


ReadSector:             mov eax,dword[si]
                        mov dword[StartSectorTransfer],eax
                        mov eax,dword[si+4]
                        mov dword[StartSectorTransfer+4],eax
ReadSector2:            mov ah,0x42
                        mov dl,0x80
                        mov si,ExtendedReadData
                        int 0x13
                        jc DiskReadError
                        ret

NoBootDirectory:        mov si,DiskError2
                        jmp DisplayError

NoLoaderBinary:         mov si,FileIs
                        call DisplayString
                        mov si,DiskError3
                        jmp DisplayError

DiskReadError:          mov si,DiskError1

DisplayError:           call DisplayString
                        jmp $

ExtendedReadData:       db 0x10
                        db 0                    ;;; Reserved
Sectors:                db 1                    ;;; Number of sectors to process
                        db 0                    ;;; Reserved
MOffset:                dw 0x7c00+512           ;;; Memory offset to transfer sectors too
MSegment:               dw 0                    ;;; Memory segment to transfer sectors too
StartSectorTransfer:    dq 2                    ;;; Starting sectors to transfer data from


Message:                db 'Please wait...',0x0d,0x0a,0x00
NoBootablePartition:    db 'No bootable partition found',0x00
DiskError1:             db 'Unable to read disk',0x00
DiskError2:             db 'No \Boot',0x00
FileIs:                 db 'Loader.binary',0x00
DiskError3:             db ' not found',0x00
times 510-($-Begin) db 0
dw 0xaa55
    

Hope this helps
Post 11 Jun 2006, 10:41
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Maybe you could take a look at bubachs BOS, as that, loads to the same address:
http://bos.asmhackers.net/downloads.php
Also does this not work ?.
Code:
mov al,byte[CS:TitleBar]  ;;; POSSIBLE PROBLEM     
Post 11 Jun 2006, 11:55
View user's profile Send private message Reply with quote
Just me



Joined: 10 Jun 2006
Posts: 14
Just me
Hi Dex4u
Just tried, still no luck Sad
Post 11 Jun 2006, 15:28
View user's profile Send private message Reply with quote
Just me



Joined: 10 Jun 2006
Posts: 14
Just me
Hi all.
Just run some tests and it appears that the dl register is cleared
after assignment Confused
Code:
format binary
org 0x0000
use16

                        cli
                        mov ax,0x1000
                        mov ds,ax
                        sti
                        mov si,TitleBar
                        mov dl,byte[si]
                        mov cx,8
L1:                     shl dl,1
                        jc DisplayOne
DisplayZero:            mov al,'0'
                        jmp J1
DisplayOne:             mov al,'1'
J1:                     mov ah,0x0e
                        xor bx,bx
                        int 0x10
                        loop L1
                        jmp $
test1:                  db 0xff
TitleBar:               db '@OS 1 [Build 0001] loader',0x00 
    

Somethings isn't right Sad
Post 11 Jun 2006, 16:25
View user's profile Send private message Reply with quote
Just me



Joined: 10 Jun 2006
Posts: 14
Just me
Hi all
Just done another test. This time I have loaded the file directly
after the boot sector and the si register has a value!
Any idea's?
Post 11 Jun 2006, 17:40
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
I am doing some test i will get back to you with what i find.
Post 11 Jun 2006, 17:50
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Right heres what i have found, first the problem is with your loader, as if i load it using BOS to the same address, it works fine.
Try this:
Name the below code "kernel.asm" and replace the "kernel.asm in bubach's BOS.
you can get it here: http://bos.asmhackers.net/downloads.php
you need 0.0.4
This a slite modded ver of your code.
Code:
format binaryorg 0x0000use16;;; Set default screen mode [effect clear screen]mov ah,0mov al,3int 0x10mov ax,0x1000climov ds,axmov es,axsticall DrawScreenjmp $DrawScreen: ;;; Display loader titlemov ah,2xor bh,bhmov dh,0mov dl,3int 0x10mov si,TitleBarcall DisplayStringretDisplayString: ;;; Enter with SI ptr to string to display        mov   ah,0Eh                       ; Request displayagain1:        lodsb                              ; load a byte into AL from DS:SI        or   al,al                         ; Or AL        jz   done1                         ; Jump 0, to label done1        int  10h                           ; Call interrupt service        jmp  again1                        ; Jump to label again1done1: retTitleBar: db 'OS 1 [Build 0001] loader',0x00times 1024*6- ($-0)  db 0 ; this is just to make it bigger.    

Also see your loading from HDD, i would be carefull.
But i think your problem my be here:
Code:
ExtendedReadData:       db 0x10                        db 0                    ;;; ReservedSectors:                db 1                    ;;; Number of sectors to process                        db 0                    ;;; ReservedMOffset:                dw 0x7c00+512           ;;; Memory offset to transfer sectors tooMSegment:               dw 0                    ;;; Memory segment to transfer sectors tooStartSectorTransfer:    dq 2                    ;;; Starting sectors to transfer data from    
Post 11 Jun 2006, 19:11
View user's profile Send private message Reply with quote
Just me



Joined: 10 Jun 2006
Posts: 14
Just me
Hi Dex4u
The last bit of code you have pointed out is over written later on in the
loader process:) The first bit of code has already been tried. The original loader code is a little bit longer and the problem was only noticed when I tried to display a string.
Anyway I have decided to load the loader code directly after the boot code. This seems to work.
Thanks for everybody's help:)
Post 11 Jun 2006, 19:46
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Your welcome, i use bootprog to load my OS, it will load a com or exe from anywhere on the floppy or hdd.
http://alexfru.chat.ru/epm.html#bootprog
Post 11 Jun 2006, 20:05
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.