Bootloader. Writing strings to the screen
I've written some simple bootloader that works good in QEMU and I decided to try it on real machine. I copied image file to flash drive and tried to load from it. But for some reason I've been getting just black screen with cursor somewhere near the top left corner and it made me think that it might be some problem with displaying strings on the screen. To check that idea I wrote simplistic bootloader that shows a message "Loading Image " and checks whether IO extensions (int 13h ah=42) are supported.If it's supported shows the message "Extensions are here". So in qemu it works and I'm getting these two messages as expected. But on my computer instead of two lines I'm getting one line like this "LoaExtensions are here". To print message I use int 10h ah=0Eh
I tried to set different video modes using ah=0 function of the int 10h but I've always got the same result.
Could you please help me to understand what could be wrong?
This is the code:
bits 16 ; we are in 16 bit real mode
org 0 ; we will set regisers later
start: jmp Main ; jump to start of bootloader
msgLoading db "Loading Image ", 0x0D, 0x0A, 0x00
msgSectorReadingError db "ERROR: Can't read sectors from disk",0x0D,0x0A, 0x00
msgExtNotSupported db "ERROR: BIOS doesn't support LBA",0x0D,0x0A, 0x00
msgErrWhileLoadingImage db "ERROR: Couldn't read seconday image",0x0D,0x0A, 0x00
msgExtSupported db "Extensions are here",0x0D,0x0A, 0x00
imgName db "STAGE2 SYS"
;************************************************;
;************************************************;
; Prints a string
; DS=>SI: 0 terminated string
;************************************************;
Print:
lodsb ; load next byte from string from SI to AL
or al, al ; Does AL=0?
jz PrintDone ; Yep, null terminator found-bail out
mov ah, 0xE ; Nope-Print the character
int 0x10
jmp Print ; Repeat until null terminator found
PrintDone:
ret ; we are done, so return
;************************************************;
; Set Video mode
;
;************************************************;
SetVideoMode:
mov ax,0x0002
int 0x10
ret
;***********************************************;
; Checks whether BIOS supports extensions
;************************************************;
CheckExtenstions:
xor ax,ax
mov ah,0x41
xor dx,dx
mov dl,BYTE[driveNumber]
mov bx,0x55AA
int 0x13
cmp bx,0xAA55
jnz .error
test cl,0x1
jz .error
jmp .exit
.error:
mov si,msgExtNotSupported
call Print
cli
hlt
.exit:
mov si,msgExtSupported
call Print
cli
hlt
ret
Main:
;----------------------------------------------------
; code located at 0000:7C00, adjust segment registers
;----------------------------------------------------
cli ; disable interrupts
mov ax, 0x07C0 ; setup registers to point to our segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;----------------------------------------------------
; create stack
;----------------------------------------------------
mov ax, 0x0000 ; set the stack
mov ss, ax
mov sp, 0xFFFE
mov BYTE[driveNumber],dl
sti ; restore interrupts
call SetVideoMode
mov si, msgLoading ; Show Loading Message
call Print
call CheckExtenstions
cli
hlt
TIMES 510-($-$$) DB 0
DW 0xAA55
assembly nasm x86-16 bootloader bios
|
show 5 more comments
I've written some simple bootloader that works good in QEMU and I decided to try it on real machine. I copied image file to flash drive and tried to load from it. But for some reason I've been getting just black screen with cursor somewhere near the top left corner and it made me think that it might be some problem with displaying strings on the screen. To check that idea I wrote simplistic bootloader that shows a message "Loading Image " and checks whether IO extensions (int 13h ah=42) are supported.If it's supported shows the message "Extensions are here". So in qemu it works and I'm getting these two messages as expected. But on my computer instead of two lines I'm getting one line like this "LoaExtensions are here". To print message I use int 10h ah=0Eh
I tried to set different video modes using ah=0 function of the int 10h but I've always got the same result.
Could you please help me to understand what could be wrong?
This is the code:
bits 16 ; we are in 16 bit real mode
org 0 ; we will set regisers later
start: jmp Main ; jump to start of bootloader
msgLoading db "Loading Image ", 0x0D, 0x0A, 0x00
msgSectorReadingError db "ERROR: Can't read sectors from disk",0x0D,0x0A, 0x00
msgExtNotSupported db "ERROR: BIOS doesn't support LBA",0x0D,0x0A, 0x00
msgErrWhileLoadingImage db "ERROR: Couldn't read seconday image",0x0D,0x0A, 0x00
msgExtSupported db "Extensions are here",0x0D,0x0A, 0x00
imgName db "STAGE2 SYS"
;************************************************;
;************************************************;
; Prints a string
; DS=>SI: 0 terminated string
;************************************************;
Print:
lodsb ; load next byte from string from SI to AL
or al, al ; Does AL=0?
jz PrintDone ; Yep, null terminator found-bail out
mov ah, 0xE ; Nope-Print the character
int 0x10
jmp Print ; Repeat until null terminator found
PrintDone:
ret ; we are done, so return
;************************************************;
; Set Video mode
;
;************************************************;
SetVideoMode:
mov ax,0x0002
int 0x10
ret
;***********************************************;
; Checks whether BIOS supports extensions
;************************************************;
CheckExtenstions:
xor ax,ax
mov ah,0x41
xor dx,dx
mov dl,BYTE[driveNumber]
mov bx,0x55AA
int 0x13
cmp bx,0xAA55
jnz .error
test cl,0x1
jz .error
jmp .exit
.error:
mov si,msgExtNotSupported
call Print
cli
hlt
.exit:
mov si,msgExtSupported
call Print
cli
hlt
ret
Main:
;----------------------------------------------------
; code located at 0000:7C00, adjust segment registers
;----------------------------------------------------
cli ; disable interrupts
mov ax, 0x07C0 ; setup registers to point to our segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;----------------------------------------------------
; create stack
;----------------------------------------------------
mov ax, 0x0000 ; set the stack
mov ss, ax
mov sp, 0xFFFE
mov BYTE[driveNumber],dl
sti ; restore interrupts
call SetVideoMode
mov si, msgLoading ; Show Loading Message
call Print
call CheckExtenstions
cli
hlt
TIMES 510-($-$$) DB 0
DW 0xAA55
assembly nasm x86-16 bootloader bios
what image format are you using? And how did you copy the image to the flash drive
– preciousbetine
Nov 25 '18 at 18:16
1
I recommend you look at this answer,if I had to guess it is because you don't have a BIOS Parameter Block area at the beginning of your bootloader. Your BIOS is probably overwriting the are with drive geometry information and thus clobbering some of your code. That would likely be the case if booting USB with Floppy emulation: stackoverflow.com/a/47320115/3857942
– Michael Petch
Nov 25 '18 at 20:10
1
If you are using USB HDD emulation you shouldn't need a BPB. Although on some BIOSes in HDD Emulation mode you need a partition table with an active partition set, although you would e having the BIOS tell you thee isn't a bootable device orrefuses to boot from the device.
– Michael Petch
Nov 25 '18 at 20:51
1
Just conducted some small experiment. I created partition table using fdisk with one partition on it and I didn't mark it as bootable. Then I created FAT16 on the partition and copied my bootloader bin file (w/o 55AA signature) using dd command. And it worked. So looks like if there is no either BPB or partition table my BIOS does something wrong with my code.
– Andrew Bolotov
Nov 25 '18 at 21:21
2
All BIOSes have quirks. But in general with USB HDD you need a partition table (some BIOSes actually need one marked as active as well).With USB FDD you need a BPB. With USB HDD you shouldn't need both a BPB and Partition Table (Should work with just the partition table)
– Michael Petch
Nov 25 '18 at 21:28
|
show 5 more comments
I've written some simple bootloader that works good in QEMU and I decided to try it on real machine. I copied image file to flash drive and tried to load from it. But for some reason I've been getting just black screen with cursor somewhere near the top left corner and it made me think that it might be some problem with displaying strings on the screen. To check that idea I wrote simplistic bootloader that shows a message "Loading Image " and checks whether IO extensions (int 13h ah=42) are supported.If it's supported shows the message "Extensions are here". So in qemu it works and I'm getting these two messages as expected. But on my computer instead of two lines I'm getting one line like this "LoaExtensions are here". To print message I use int 10h ah=0Eh
I tried to set different video modes using ah=0 function of the int 10h but I've always got the same result.
Could you please help me to understand what could be wrong?
This is the code:
bits 16 ; we are in 16 bit real mode
org 0 ; we will set regisers later
start: jmp Main ; jump to start of bootloader
msgLoading db "Loading Image ", 0x0D, 0x0A, 0x00
msgSectorReadingError db "ERROR: Can't read sectors from disk",0x0D,0x0A, 0x00
msgExtNotSupported db "ERROR: BIOS doesn't support LBA",0x0D,0x0A, 0x00
msgErrWhileLoadingImage db "ERROR: Couldn't read seconday image",0x0D,0x0A, 0x00
msgExtSupported db "Extensions are here",0x0D,0x0A, 0x00
imgName db "STAGE2 SYS"
;************************************************;
;************************************************;
; Prints a string
; DS=>SI: 0 terminated string
;************************************************;
Print:
lodsb ; load next byte from string from SI to AL
or al, al ; Does AL=0?
jz PrintDone ; Yep, null terminator found-bail out
mov ah, 0xE ; Nope-Print the character
int 0x10
jmp Print ; Repeat until null terminator found
PrintDone:
ret ; we are done, so return
;************************************************;
; Set Video mode
;
;************************************************;
SetVideoMode:
mov ax,0x0002
int 0x10
ret
;***********************************************;
; Checks whether BIOS supports extensions
;************************************************;
CheckExtenstions:
xor ax,ax
mov ah,0x41
xor dx,dx
mov dl,BYTE[driveNumber]
mov bx,0x55AA
int 0x13
cmp bx,0xAA55
jnz .error
test cl,0x1
jz .error
jmp .exit
.error:
mov si,msgExtNotSupported
call Print
cli
hlt
.exit:
mov si,msgExtSupported
call Print
cli
hlt
ret
Main:
;----------------------------------------------------
; code located at 0000:7C00, adjust segment registers
;----------------------------------------------------
cli ; disable interrupts
mov ax, 0x07C0 ; setup registers to point to our segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;----------------------------------------------------
; create stack
;----------------------------------------------------
mov ax, 0x0000 ; set the stack
mov ss, ax
mov sp, 0xFFFE
mov BYTE[driveNumber],dl
sti ; restore interrupts
call SetVideoMode
mov si, msgLoading ; Show Loading Message
call Print
call CheckExtenstions
cli
hlt
TIMES 510-($-$$) DB 0
DW 0xAA55
assembly nasm x86-16 bootloader bios
I've written some simple bootloader that works good in QEMU and I decided to try it on real machine. I copied image file to flash drive and tried to load from it. But for some reason I've been getting just black screen with cursor somewhere near the top left corner and it made me think that it might be some problem with displaying strings on the screen. To check that idea I wrote simplistic bootloader that shows a message "Loading Image " and checks whether IO extensions (int 13h ah=42) are supported.If it's supported shows the message "Extensions are here". So in qemu it works and I'm getting these two messages as expected. But on my computer instead of two lines I'm getting one line like this "LoaExtensions are here". To print message I use int 10h ah=0Eh
I tried to set different video modes using ah=0 function of the int 10h but I've always got the same result.
Could you please help me to understand what could be wrong?
This is the code:
bits 16 ; we are in 16 bit real mode
org 0 ; we will set regisers later
start: jmp Main ; jump to start of bootloader
msgLoading db "Loading Image ", 0x0D, 0x0A, 0x00
msgSectorReadingError db "ERROR: Can't read sectors from disk",0x0D,0x0A, 0x00
msgExtNotSupported db "ERROR: BIOS doesn't support LBA",0x0D,0x0A, 0x00
msgErrWhileLoadingImage db "ERROR: Couldn't read seconday image",0x0D,0x0A, 0x00
msgExtSupported db "Extensions are here",0x0D,0x0A, 0x00
imgName db "STAGE2 SYS"
;************************************************;
;************************************************;
; Prints a string
; DS=>SI: 0 terminated string
;************************************************;
Print:
lodsb ; load next byte from string from SI to AL
or al, al ; Does AL=0?
jz PrintDone ; Yep, null terminator found-bail out
mov ah, 0xE ; Nope-Print the character
int 0x10
jmp Print ; Repeat until null terminator found
PrintDone:
ret ; we are done, so return
;************************************************;
; Set Video mode
;
;************************************************;
SetVideoMode:
mov ax,0x0002
int 0x10
ret
;***********************************************;
; Checks whether BIOS supports extensions
;************************************************;
CheckExtenstions:
xor ax,ax
mov ah,0x41
xor dx,dx
mov dl,BYTE[driveNumber]
mov bx,0x55AA
int 0x13
cmp bx,0xAA55
jnz .error
test cl,0x1
jz .error
jmp .exit
.error:
mov si,msgExtNotSupported
call Print
cli
hlt
.exit:
mov si,msgExtSupported
call Print
cli
hlt
ret
Main:
;----------------------------------------------------
; code located at 0000:7C00, adjust segment registers
;----------------------------------------------------
cli ; disable interrupts
mov ax, 0x07C0 ; setup registers to point to our segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;----------------------------------------------------
; create stack
;----------------------------------------------------
mov ax, 0x0000 ; set the stack
mov ss, ax
mov sp, 0xFFFE
mov BYTE[driveNumber],dl
sti ; restore interrupts
call SetVideoMode
mov si, msgLoading ; Show Loading Message
call Print
call CheckExtenstions
cli
hlt
TIMES 510-($-$$) DB 0
DW 0xAA55
assembly nasm x86-16 bootloader bios
assembly nasm x86-16 bootloader bios
edited Nov 25 '18 at 20:12
Michael Petch
25.5k556102
25.5k556102
asked Nov 25 '18 at 17:55
Andrew BolotovAndrew Bolotov
324
324
what image format are you using? And how did you copy the image to the flash drive
– preciousbetine
Nov 25 '18 at 18:16
1
I recommend you look at this answer,if I had to guess it is because you don't have a BIOS Parameter Block area at the beginning of your bootloader. Your BIOS is probably overwriting the are with drive geometry information and thus clobbering some of your code. That would likely be the case if booting USB with Floppy emulation: stackoverflow.com/a/47320115/3857942
– Michael Petch
Nov 25 '18 at 20:10
1
If you are using USB HDD emulation you shouldn't need a BPB. Although on some BIOSes in HDD Emulation mode you need a partition table with an active partition set, although you would e having the BIOS tell you thee isn't a bootable device orrefuses to boot from the device.
– Michael Petch
Nov 25 '18 at 20:51
1
Just conducted some small experiment. I created partition table using fdisk with one partition on it and I didn't mark it as bootable. Then I created FAT16 on the partition and copied my bootloader bin file (w/o 55AA signature) using dd command. And it worked. So looks like if there is no either BPB or partition table my BIOS does something wrong with my code.
– Andrew Bolotov
Nov 25 '18 at 21:21
2
All BIOSes have quirks. But in general with USB HDD you need a partition table (some BIOSes actually need one marked as active as well).With USB FDD you need a BPB. With USB HDD you shouldn't need both a BPB and Partition Table (Should work with just the partition table)
– Michael Petch
Nov 25 '18 at 21:28
|
show 5 more comments
what image format are you using? And how did you copy the image to the flash drive
– preciousbetine
Nov 25 '18 at 18:16
1
I recommend you look at this answer,if I had to guess it is because you don't have a BIOS Parameter Block area at the beginning of your bootloader. Your BIOS is probably overwriting the are with drive geometry information and thus clobbering some of your code. That would likely be the case if booting USB with Floppy emulation: stackoverflow.com/a/47320115/3857942
– Michael Petch
Nov 25 '18 at 20:10
1
If you are using USB HDD emulation you shouldn't need a BPB. Although on some BIOSes in HDD Emulation mode you need a partition table with an active partition set, although you would e having the BIOS tell you thee isn't a bootable device orrefuses to boot from the device.
– Michael Petch
Nov 25 '18 at 20:51
1
Just conducted some small experiment. I created partition table using fdisk with one partition on it and I didn't mark it as bootable. Then I created FAT16 on the partition and copied my bootloader bin file (w/o 55AA signature) using dd command. And it worked. So looks like if there is no either BPB or partition table my BIOS does something wrong with my code.
– Andrew Bolotov
Nov 25 '18 at 21:21
2
All BIOSes have quirks. But in general with USB HDD you need a partition table (some BIOSes actually need one marked as active as well).With USB FDD you need a BPB. With USB HDD you shouldn't need both a BPB and Partition Table (Should work with just the partition table)
– Michael Petch
Nov 25 '18 at 21:28
what image format are you using? And how did you copy the image to the flash drive
– preciousbetine
Nov 25 '18 at 18:16
what image format are you using? And how did you copy the image to the flash drive
– preciousbetine
Nov 25 '18 at 18:16
1
1
I recommend you look at this answer,if I had to guess it is because you don't have a BIOS Parameter Block area at the beginning of your bootloader. Your BIOS is probably overwriting the are with drive geometry information and thus clobbering some of your code. That would likely be the case if booting USB with Floppy emulation: stackoverflow.com/a/47320115/3857942
– Michael Petch
Nov 25 '18 at 20:10
I recommend you look at this answer,if I had to guess it is because you don't have a BIOS Parameter Block area at the beginning of your bootloader. Your BIOS is probably overwriting the are with drive geometry information and thus clobbering some of your code. That would likely be the case if booting USB with Floppy emulation: stackoverflow.com/a/47320115/3857942
– Michael Petch
Nov 25 '18 at 20:10
1
1
If you are using USB HDD emulation you shouldn't need a BPB. Although on some BIOSes in HDD Emulation mode you need a partition table with an active partition set, although you would e having the BIOS tell you thee isn't a bootable device orrefuses to boot from the device.
– Michael Petch
Nov 25 '18 at 20:51
If you are using USB HDD emulation you shouldn't need a BPB. Although on some BIOSes in HDD Emulation mode you need a partition table with an active partition set, although you would e having the BIOS tell you thee isn't a bootable device orrefuses to boot from the device.
– Michael Petch
Nov 25 '18 at 20:51
1
1
Just conducted some small experiment. I created partition table using fdisk with one partition on it and I didn't mark it as bootable. Then I created FAT16 on the partition and copied my bootloader bin file (w/o 55AA signature) using dd command. And it worked. So looks like if there is no either BPB or partition table my BIOS does something wrong with my code.
– Andrew Bolotov
Nov 25 '18 at 21:21
Just conducted some small experiment. I created partition table using fdisk with one partition on it and I didn't mark it as bootable. Then I created FAT16 on the partition and copied my bootloader bin file (w/o 55AA signature) using dd command. And it worked. So looks like if there is no either BPB or partition table my BIOS does something wrong with my code.
– Andrew Bolotov
Nov 25 '18 at 21:21
2
2
All BIOSes have quirks. But in general with USB HDD you need a partition table (some BIOSes actually need one marked as active as well).With USB FDD you need a BPB. With USB HDD you shouldn't need both a BPB and Partition Table (Should work with just the partition table)
– Michael Petch
Nov 25 '18 at 21:28
All BIOSes have quirks. But in general with USB HDD you need a partition table (some BIOSes actually need one marked as active as well).With USB FDD you need a BPB. With USB HDD you shouldn't need both a BPB and Partition Table (Should work with just the partition table)
– Michael Petch
Nov 25 '18 at 21:28
|
show 5 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470276%2fbootloader-writing-strings-to-the-screen%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470276%2fbootloader-writing-strings-to-the-screen%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what image format are you using? And how did you copy the image to the flash drive
– preciousbetine
Nov 25 '18 at 18:16
1
I recommend you look at this answer,if I had to guess it is because you don't have a BIOS Parameter Block area at the beginning of your bootloader. Your BIOS is probably overwriting the are with drive geometry information and thus clobbering some of your code. That would likely be the case if booting USB with Floppy emulation: stackoverflow.com/a/47320115/3857942
– Michael Petch
Nov 25 '18 at 20:10
1
If you are using USB HDD emulation you shouldn't need a BPB. Although on some BIOSes in HDD Emulation mode you need a partition table with an active partition set, although you would e having the BIOS tell you thee isn't a bootable device orrefuses to boot from the device.
– Michael Petch
Nov 25 '18 at 20:51
1
Just conducted some small experiment. I created partition table using fdisk with one partition on it and I didn't mark it as bootable. Then I created FAT16 on the partition and copied my bootloader bin file (w/o 55AA signature) using dd command. And it worked. So looks like if there is no either BPB or partition table my BIOS does something wrong with my code.
– Andrew Bolotov
Nov 25 '18 at 21:21
2
All BIOSes have quirks. But in general with USB HDD you need a partition table (some BIOSes actually need one marked as active as well).With USB FDD you need a BPB. With USB HDD you shouldn't need both a BPB and Partition Table (Should work with just the partition table)
– Michael Petch
Nov 25 '18 at 21:28