Ok, now I'm very, very confused.
First I had the problem where my strcmp didn't work. appearently it was because of segment registers were set wrong.
So I got this new code first for boot.asm:
Code: Select all
BDA equ 0x0040 ; BDA segment
MEM equ 0x0013 ; Offset to memsize.
ReBoot equ 0x0019
SYSTEM_SERVICES equ 0x0015
DISK_IO equ 0x0013
D_STATUS equ 0x0001
D_READ equ 0x0200
D_WRITE equ 0x0300
GET_DP equ 0x0048
jmp 0x7c0:Begin ; For quirky BIOS's so we know CS = 7C0H
Begin:
mov ax, BDA ; Point to BIOS DATA AREA
mov ds, ax
mov ax, [MEM] ; Get number of 1k pages. Probably 27FH
shl ax, 6 ; Convert to segment address
sub ah, 16
cli
mov ss, ax
xor sp, sp
sti
mov ax, cs
add ax, 32
mov es, ax
xor bx, bx ; ES:BX = 0x7c0:0
mov ax, D_READ + 8 ; AH = 2, AL = 8 sectors to read
mov cx, 2 ; Begin @ sector 2
mov dh, 0 ; Head 0, probably was that already
int DISK_IO
jc Failed
jmp 0:0x7e00 ; Jump to second stage.
times 506 - $ db 90H
Failed:
int 0x16
int ReBoot
dw 0xAA55
and then I got this for the beginning of the kernel.asm:
Code: Select all
bits 16 ; if using NASM
use16 ; maybe you're using FASM?
org 0x0000
os_main:
cli
cld
mov ax, 0x7E00
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov sp, 0
sti
; Whatever code you want...
The last line says "Whatever code you want..." so I added a print statement:
Code: Select all
bits 16 ; if using NASM
use16 ; maybe you're using FASM?
org 0x0000
os_main:
cli
cld
mov ax, 0x7E00
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov sp, 0
sti
; the following stuff got added.
mov si, msg_string
call .print_string
jmp $
.print_string:
lodsb
or al, al
jz .done
mov ah, 0x0E
mov bh, 0x00
mov bl, 0x0F
int 0x10
jmp .print_string
.done:
ret
msg_string db "Hello And Welcome", 0
times 0x1000-($-$$) db 0
And when I ran this, it didn't work. so I asked what I did wrong. I got this:
Octocontrabass wrote:
Kirdow wrote:
Code: Select all
jmp 0:0x7e00 ; Jump to second stage.
These two lines of code disagree.
You are jumping to offset 0x7E00, but you have told the assembler that your code is located at offset 0x0000. You have two choices:
jmp 0x07E0:0x0000 and ORG 0x0000
jmp 0x0000:0x7E00 and ORG 0x7E00
Pick either of those options and your code will work.
So I changed that to jmp 0x0000:0x7e00 and ORG 0x7e00
Then I got this too:
Octocontrabass wrote:
Kirdow wrote:
Code: Select all
jmp 0:0x7e00 ; Jump to second stage.
Code: Select all
mov ax, 0x7E00
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
Why are you setting the segment registers to different values instead of using the same value for all of them?
Well, on that one I say it's because you guys gave me that code. I thought it was valid.
So, what I now wonder is, well, multiple things.
1. Why do I get code and when I then use it you say It's the cause of the problem and ask why I use it?
2. If the code I got was a problem, for example the jmp and org thing, why did I get the wrong in the first place?
3.
omarrx024 wrote:
Seriously, it looks to me like you loaded it at 0x07E0:0x0000, not 0x7E00:0x0000. Your bootloader loaded the kernel to 0x07E0:0x0000, and you jumped to 0x0000:0x7E00. Therefore your kernel should be ORG 0x7E00 with segments 0x0000.
Thanks for the info, will try that.
Note: I have a disorder making it harder for me to learn, so when I get the wrong code and you say it should work, and then you say it's wrong, It's making it harder for me in general.