flat assembler
Message board for the users of flat assembler.

Index > OS Construction > [Solved]Many questions ...

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 10 Mar 2018, 13:27
PCI for ATA device ? How i detect connected devices number ? (with protected mode)?
Post 10 Mar 2018, 13:27
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 10 Mar 2018, 19:11
Fulgurance wrote:
PCI for ATA device ? How i detect connected devices number ? (with protected mode)?

There’s plenty of specifications available at wiki.osdev.org, but, please, trust me, your experience seems to be too low to think about it right now. Maybe you’d better spend some time using good old BIOS services before you’re ready to switch to protected mode and do all the stuff directly.
Post 10 Mar 2018, 19:11
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 12 Mar 2018, 21:43
Yes, i'm not pro. I take information for learn more about OS dev. But i learn quickly Cool

But i just would like to program, i don't would like to use any interrupt.

And if i would like to use my small OS on virtualbox, how i program graphic driver for virtualbox. Is there tutoriel ?
Post 12 Mar 2018, 21:43
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 13 Mar 2018, 09:09
Fulgurance wrote:
Yes, i'm not pro. I take information for learn more about OS dev. But i learn quickly Cool

But i just would like to program, i don't would like to use any interrupt.

And if i would like to use my small OS on virtualbox, how i program graphic driver for virtualbox. Is there tutoriel ?

The tutorial is the graphics card specification. Again, wiki.osdev.org has some of them (AFAIR, for the most common emulated video card as well). But if you manage to write such a driver for, say, Intel HD Graphics or nVidia that would provide all or most of the capabilities, that would be a great work.

Seriously, no need to stick to direct hardware progamming. The whole purpose of drivers (for OSDev) is to let you implement something in an easy way to make your OS just work for now, and later you can replace the implementation in a driver-by-driver manner.
Post 13 Mar 2018, 09:09
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 13 Mar 2018, 20:56
Okay, i understand, thanks for your patience and your help.

I have just last question, it's about my little test code to switch to protected mode. When i use it in Virtualbox, virtualbox have an error and close, ONLY when i switch to protected mode. Do i have an error ?

Code:
use16
org 0x0

mov ax,0x7C0
mov ds,ax
mov es,ax
mov ax,0x8000
mov ss,ax
mov sp,0xf000

mov ax, gdtend
mov bx, gdt
sub ax, bx
mov word [gdtptr], ax
xor eax, eax
xor ebx, ebx
mov ax, ds
mov ecx, eax
shl ecx, 4
mov bx, gdt
add ecx, ebx
mov dword [gdtptr+2], ecx
cli
lgdt [gdtptr]

mov eax, cr0
or  ax, 1
mov cr0, eax

jmp next

next:
mov ax, 0x10
mov ds, ax
mov fs, ax
mov gs, ax
mov es, ax
mov ss, ax
mov esp, 0x9F000


gdt:
    db 0, 0, 0, 0, 0, 0, 0, 0
gdt_cs:
    db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10011011b, 11011111b, 0x0
gdt_ds:
    db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10010011b, 11011111b, 0x0
gdtend:

gdtptr:
    dw 0
    dd 0

times 510-($-$$) db 0x90
dw 0xAA55    


EDIT: I have found, problem is org directive.

I don't understand very well, what do exactly org directive; it's not about adressing? But what adress ? RAM ?[/b]

Is it possible to emulate specific GPU ? For example Intel 965 HD graphic card ? (it's free software)
Post 13 Mar 2018, 20:56
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 14 Mar 2018, 09:41
Fulgurance wrote:
Okay, i understand, thanks for your patience and your help.

I have just last question, it's about my little test code to switch to protected mode. When i use it in Virtualbox, virtualbox have an error and close, ONLY when i switch to protected mode. Do i have an error ?

Code:
use16
org 0x0

mov ax,0x7C0
mov ds,ax
mov es,ax
mov ax,0x8000
mov ss,ax
mov sp,0xf000

mov ax, gdtend
mov bx, gdt
sub ax, bx
mov word [gdtptr], ax
xor eax, eax
xor ebx, ebx
mov ax, ds
mov ecx, eax
shl ecx, 4
mov bx, gdt
add ecx, ebx
mov dword [gdtptr+2], ecx
cli
lgdt [gdtptr]

mov eax, cr0
or  ax, 1
mov cr0, eax

jmp next

next:
mov ax, 0x10
mov ds, ax
mov fs, ax
mov gs, ax
mov es, ax
mov ss, ax
mov esp, 0x9F000


gdt:
    db 0, 0, 0, 0, 0, 0, 0, 0
gdt_cs:
    db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10011011b, 11011111b, 0x0
gdt_ds:
    db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10010011b, 11011111b, 0x0
gdtend:

gdtptr:
    dw 0
    dd 0

times 510-($-$$) db 0x90
dw 0xAA55    


EDIT: I have found, problem is org directive.

I don't understand very well, what do exactly org directive; it's not about adressing? But what adress ? RAM ?[/b]

Is it possible to emulate specific GPU ? For example Intel 965 HD graphic card ? (it's free software)

What made you think the problem is with org? From what I can tell, the main problem is that your code continues to run after setting up segments and stack and thus runs data as code.

Assembler is a program that translates your program line-by-line into a sequence of bytes. There’s an internal counter that is used to find exact values for labels. Each time assembler generates a byte this counter is incremented by 1. By default, the initial value for the counter is 0. org is like “please, set your counter’s value to this one”. That’s why I’m pretty sure org cannot be your problem since it does effectively nothing in your program.
Post 14 Mar 2018, 09:41
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 14 Mar 2018, 15:39
Oh yes... it's just that ... okay, sorry, i'm really stupid ...

If i understand very well, org directive is just for add "virtual" adress, just for calculate adress interval for compiler ?

And i have little question, after enter protected, why assembly example do
Code:
jmp dword 0x8:0x1000    


I understand is necessary to jump to kernel, but why 0x8 ? I don't understand very well...
Post 14 Mar 2018, 15:39
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 14 Mar 2018, 20:43
Fulgurance wrote:
Oh yes... it's just that ... okay, sorry, i'm really stupid ...

If i understand very well, org directive is just for add "virtual" adress, just for calculate adress interval for compiler ?

And i have little question, after enter protected, why assembly example do
Code:
jmp dword 0x8:0x1000    


I understand is necessary to jump to kernel, but why 0x8 ? I don't understand very well...

The word “virtual” is what makes me a bit nervous since there’s a virtual directive in FASM. But, yes, in a sense that’s what org is for. In fact it is expected to be used to simplify coding: whenever you start a new block that is supposed to be loaded at some point in memory you just prependit with the offset of that point and have no need to think of anything else, the rest (address calculation for labels) is done by assembler.

As for your question about 0x8, I’ll just give you a hint: take a closer look at your GDT.
Post 14 Mar 2018, 20:43
View user's profile Send private message Visit poster's website Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 14 Mar 2018, 20:44
Fulgurance wrote:
I understand is necessary to jump to kernel, but why 0x8 ? I don't understand very well...

It explicitly uses the CS of the recently-loaded GDT. CS points to the second descriptor: the first one (0-7) being the "null descriptor", the second one, CS, starts at 8.
Say you decide to have 2 descriptors for real-mode CS and DS and 2 descriptors for protected-mode CS and DS, you'd be using 0x18 (24) instead of 8.
Post 14 Mar 2018, 20:44
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 14 Mar 2018, 21:10
ManOfSteel wrote:
Fulgurance wrote:
I understand is necessary to jump to kernel, but why 0x8 ? I don't understand very well...

It explicitly uses the CS of the recently-loaded GDT. CS points to the second descriptor: the first one (0-7) being the "null descriptor", the second one, CS, starts at 8.
Say you decide to have 2 descriptors for real-mode CS and DS and 2 descriptors for protected-mode CS and DS, you'd be using 0x18 (24) instead of 8.

I’ll make a few corrections here.

First, the “uses the CS of the recently-loaded GDT” part here means “loads the selector 0x8 into CS which is the segment #1 (zero-based index) in the recently-loaded GDT”. The reason it is 0x8 is in the internal format of a protected-mode segment selector (see Intel SDM).

Second, let me note that for the rest of ManOfSteel’s post CS and DS should be read as “code segment” and “data segment”, not as segment register names.

Third, if my memory serves me, there’re no requirements about the order of segment descriptors in GDT/LDTs, so the actual index of a segment would only be 0x18 if the number and order of segment declarations is exactly as described in the example.
Post 14 Mar 2018, 21:10
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 15 Mar 2018, 14:42
Okay, i understand, thanks Smile

Just one question, how is it possible on protected mode to load kernel on RAM without interrupt ?
Post 15 Mar 2018, 14:42
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 15 Mar 2018, 15:16
Fulgurance wrote:
Okay, i understand, thanks Smile

Just one question, how is it possible on protected mode to load kernel on RAM without interrupt ?

The question has already been answered. Nothing changes with protected mode except the addressing scheme and a few things not related to interrupts/no interrupts question.
Post 15 Mar 2018, 15:16
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 16 Mar 2018, 16:27
Okay sorry.

I have problem. I have made mbr with on second sector simple main loop code, but i fail to load it. What i don't understand ? (I have crash on virtualbox)

Look:

Code:
use16
org 0x0

mov ax,0x7C0
mov ds,ax
mov es,ax
mov ax,0x8000
mov ss,ax
mov sp,0xf000

cli
lgdt [gdt]
mov eax,cr0
or ax,0x1
mov cr0,eax
jmp protected_mode

protected_mode:
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov esp,0x9f000

jmp dword 0x8:start

gdt_begin: db 0,0,0,0,0,0,0,0
gdt_cs: db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10011011b, 11011111b, 0x0
gdt_ds: db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10010011b, 11011111b, 0x0
gdt_end:
gdt: dw gdt_end-gdt_begin
     dd gdt_begin

times 510-($-$$) db 0x90
dw 0xAA55

use32
start:
main:
jmp main

times 2048-($-$$) db 0x90    


I don't understand when i turn to protected mode how to jump into my kernel on second sector... Can you give me explications ? I think i don't understant something.
Post 16 Mar 2018, 16:27
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 16 Mar 2018, 19:50
Fulgurance wrote:
I don't understand when i turn to protected mode how to jump into my kernel on second sector... Can you give me explications ? I think i don't understant something.

Only the first 512 bytes are read into memory by BIOS. So your second sector is not in memory until you load it from disk.
Post 16 Mar 2018, 19:50
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 16 Mar 2018, 20:42
Oh okay . I have again to learn many things Sad

Thanks for your patience and your help. I mark this post solved Wink
Post 16 Mar 2018, 20:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.