OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 5:22 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: How do I start learning how to use Protected Mode (32-bit)?
PostPosted: Tue Mar 28, 2017 11:21 am 
Offline

Joined: Sat Mar 18, 2017 4:52 am
Posts: 17
Hello.

I would like to learn how to use Protected Mode (32-bit) functions. I am using Assembly. The wiki won't help me out since for one, it doesn't explain things and also it has the LEA instructions which is not supported on some assemblers.

Can someone help me please?

Thanks
starmanz.

_________________
AX BX CX DX BP SP SI DI. The registers that never die. 16-bit... will always sit... in a book where people look. My signature is terrible! I think we all know that.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 12:15 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
starmanz wrote:
The wiki won't help me out since for one, it doesn't explain things and also it has the LEA instructions which is not supported on some assemblers.


First off: what? Seriously, an x86 assembler that does not support LEA? You're joking, right? That's like one that doesn't support ADD!

Second, where? The p-mode example doesn't use it at all. The Long Mode example does, and it would be pretty hard for it not to, but that's a different thing altogether.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 1:06 pm 
Offline
Member
Member

Joined: Thu May 19, 2011 5:13 am
Posts: 229
starmanz wrote:
... and also it has the LEA instructions which is not supported on some assemblers.
lea is fully supported on all x86 assemblers.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com


Last edited by mikegonta on Sat Apr 01, 2017 9:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 1:49 pm 
Offline

Joined: Sat Mar 18, 2017 4:52 am
Posts: 17
I wanted to know about learning how to use Protected Mode with OS development, not stupid LEA. It doesn't work on my assembler.

_________________
AX BX CX DX BP SP SI DI. The registers that never die. 16-bit... will always sit... in a book where people look. My signature is terrible! I think we all know that.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 2:43 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Okay... This is how this sounds to me:
1.I can't write a letter A, it works on every paper but mine.
2.I don't care about that stupid xyz instruction, I just want to learn how to write letters A, B and C.

Protected mode is just a processor mode meant to be used with specific features and capabilities. I would suggest you take a look at Intel Manuals. They can be very helpful when it comes to understanding of arch. specifics.
https://software.intel.com/en-us/articles/intel-sdm

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 2:54 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
If you are really using an assembler that doesn't support lea, perhaps you should consider using a proper assembler. Who knows what else it gets wrong.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 3:07 pm 
Offline

Joined: Sat Mar 18, 2017 4:52 am
Posts: 17
Intel manuals? I didn't learn from that because it's so terrible to learn from! You do know that I learn from MASM32 Windows Assembly or x86 MS-DOS DEBUG rather than some manual.

Manuals are bad. Everyone agrees. If you ask "Hey john are manuals good?!", he will say "Nope. They are absolutely complicated".

And what's with this putting pictures of idiots on their websites? Does it build trust? No, it looks stupid. This is why people learn tutorials rather than old documentation copied from 50 years ago. I would rather have something that teaches me functions and talk about what is needed.

I learnt x86 Assembly from a few YouTube videos and a PDF from Chicago ACM (10x better than all that garbage).

I wanted to learn Protected Mode. Instead, you go off into a story of this instruction. Honestly, I never used LEA in my life and I will never need to.

There are probably alternatives out there anyway. The idea of the Intel manual is:
'Come and waste your time reading this trash we came up with in 10 minutes. Yeah, we just copied words we don't even know in and put some trash in'

Please don't recommend me C. Don't recommend me Java (I already know some). Don't recommend me C++ or Python. I want Assembly as my final choice.

_________________
AX BX CX DX BP SP SI DI. The registers that never die. 16-bit... will always sit... in a book where people look. My signature is terrible! I think we all know that.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 4:22 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
jeez. just one note, masm32 knows about lea.

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 5:35 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hello,

You claimed that you know x86 assembly language, yet only 10 days ago you asked about x86 assembly language tutorials. I find it hard to believe that your assembler does not support LEA, and I'd advise for you to take it slowly and learn the language first prior to attempting to go into OS development. Since you plan to use "100% assembly language," it is farther advised to know about ABI's, calling conventions, and optimizations that can be performed on the assembly level.

With that said, your question is lacking context. Are you not able to switch to 32 bit protected mode? What do you mean by "protected mode functions?" What Wiki articles have you looked at regarding this matter, and what - precisely - are you not sure about? It would be better for you to describe what you have tried, what you already understand, and what parts of the respective Wiki articles you are not sure about so that we can clarify things here.

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Tue Mar 28, 2017 7:42 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
For the record, the pages relevant to protected mode which I am familiar with are Protected Mode, Journey To The Protected Land, and GDT (which the 'Journey' page references). The GDT page has no code examples (though it does describe three data structures necessary for switching to 32-bit p-mode), while the code for the other two is:

"Protected Mode":
Code:
    cli          ; disable interrupts
    lgdt [gdtr]  ; load GDT register with start address of Global Descriptor Table
    mov eax, cr0
    or al, 1     ; set PE (Protection Enable) bit in CR0 (Control Register 0)
    mov cr0, eax

    ; Perform far jump to selector 08h (offset into GDT, pointing at a 32bit PM code segment descriptor)
    ; to load CS with proper PM32 descriptor)

    JMP 08h:PModeMain


and

"Journey To The Protected Land":
Code:
    cli
    lgdt [gdtr]
    ; for 386s and later   
    mov eax, cr0
    or eax, 1
    mov cr0,eax
    ; for 286s
    smsw ax
    or ax,1
    lmsw ax
    jmp 08h:main


The only real difference is that the former has more extensive commentary, while the latter gives the code for the (almost entirely obsolete) 16-bit protected mode as well as 32-bit protected mode.

I am curious as to which wiki page the OP is referring to, as none of those three use LEA as can be seen here. In fact, a search for the keyword "LEA" in the wiki's search tool turns up 21 hits, of which 5 are code examples for unrelated topics, 8 are from a sort of pocket repo in John Burger's private pages, one is a linker dump with the instruction in it, one is a reference to the Doug Lea implementation of malloc() (a C function used for memory allocation), and the rest are all... well, pages which have my username in them for one reason or another.

Could you please provide a link for us, @starmanz? I suspect we are looking at very different things (as I said, the pages on 64-bit Long Mode do use LEA, but you would need to be in 32-bit protected mode first before withing to Long mode).

It might also help if you could post both the code you were trying to assemble, and the error messages you got, because if the assembler - especially a rock-solid standard assembler like Microsoft Macro Assembler - is throwing a fit over a common instruction, something weird is going on.

I suspect that the code you have is for either NASM, FASM, or GAS, none of which take quite the same syntax as MASM. Most OS-dev code is written with either GNU Assembler (the GNU Binutils assembler, generally used in conjunction with GCC) or NASM (Netwide Assembler, which is pretty much the de facto standard Intel x86 assembler for anything not involving Visual Studio or GCC) in mind, so a copypasta won't usually work if you are using a different assembler. Flat Assembler (FASM) is pretty common, but it can assemble either MASM or NASM syntax so not as much code targets its own dialect.

Microsoft Macro Assembler is the assembler which Microsoft created in the 1980s as a separate commercial product, but later put under the Visual Studio distribution rules. It can be downloaded here, but it requires Visual Studio 2005 to run (I am not really sure if it works with later editions, I am just going by what is on the web page).

MASM32 is a specific freeware spin-off of MASM which can be downloaded independently. .Note that the license for MASM32 specifically forbids using it to developing programs targeting an operating system other than MS-DOS or MS-Windows, or commercial products of any kind not that it really stops anyone, but the more you know.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Wed Mar 29, 2017 12:09 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
starmanz wrote:
Intel manuals? I didn't learn from that because it's so terrible to learn from! You do know that I learn from MASM32 Windows Assembly or x86 MS-DOS DEBUG rather than some manual.

Manuals are bad. Everyone agrees. If you ask "Hey john are manuals good?!", he will say "Nope. They are absolutely complicated".

[...]

I wanted to learn Protected Mode. Instead, you go off into a story of this instruction. Honestly, I never used LEA in my life and I will never need to.

There are probably alternatives out there anyway. The idea of the Intel manual is:
'Come and waste your time reading this trash we came up with in 10 minutes. Yeah, we just copied words we don't even know in and put some trash in'

[...]

I want Assembly as my final choice.


If you want to write any amount of decent code in any language, especially in OSdev you will have to let this attitude go. Manuals, manuals, manuals, manuals. You will eat and breathe manuals.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Wed Mar 29, 2017 12:51 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
starmanz wrote:
Intel manuals? I didn't learn from that because it's so terrible to learn from! You do know that I learn from MASM32 Windows Assembly or x86 MS-DOS DEBUG rather than some manual.
...
I learnt x86 Assembly from a few YouTube videos and a PDF from Chicago ACM (10x better than all that garbage).

And these resources that you used were so good that you can't even use protected mode?

There's a moral there if only you had the sense to realise it.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Wed Mar 29, 2017 3:30 am 
Offline

Joined: Sat Mar 18, 2017 4:52 am
Posts: 17
neon wrote:
Hello,

You claimed that you know x86 assembly language, yet only 10 days ago you asked about x86 assembly language tutorials. I find it hard to believe that your assembler does not support LEA, and I'd advise for you to take it slowly and learn the language first prior to attempting to go into OS development. Since you plan to use "100% assembly language," it is farther advised to know about ABI's, calling conventions, and optimizations that can be performed on the assembly level.

With that said, your question is lacking context. Are you not able to switch to 32 bit protected mode? What do you mean by "protected mode functions?" What Wiki articles have you looked at regarding this matter, and what - precisely - are you not sure about? It would be better for you to describe what you have tried, what you already understand, and what parts of the respective Wiki articles you are not sure about so that we can clarify things here.


Sup Mike. How's Neptune going?! I really wanna try it out in VirtualBox.

Anyway.
Guys, your answers are bad. All the forums and wiki pages will tell you to read 10000 pages of nonsense.

Like Daddy Pig reading instructions or Homer Simpson trying to read them but they were in French.

It would've been recommended to find an online tutorial, wouldn't it?

I learnt Assembly from less than 7000 pages of useless stuff. I would get more satisfaction if I just read 10 pages. Intel manuals suck! And don't say that is a swear. It would be considered it 30 years ago. 25-40 pages of reading is all you need.

Why don't you marry your manual? OMG! OMG!

Can't you see what I want? Instead, you talk about something else ignoring everything I asked for.

Example: "I need a tutorial for the GDT. By the way, why doesn't this boot?

"It doesn't boot because..."
WHAT ABOUT THE GDT?!

Please. I'm not trying to be rude. I want a tutorial on how to start using Protected Mode. I said I wanna learn Assembly so you would give me a beginners tutorial.

_________________
AX BX CX DX BP SP SI DI. The registers that never die. 16-bit... will always sit... in a book where people look. My signature is terrible! I think we all know that.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Wed Mar 29, 2017 3:33 am 
Offline

Joined: Sat Mar 18, 2017 4:52 am
Posts: 17
iansjack wrote:
starmanz wrote:
Intel manuals? I didn't learn from that because it's so terrible to learn from! You do know that I learn from MASM32 Windows Assembly or x86 MS-DOS DEBUG rather than some manual.
...
I learnt x86 Assembly from a few YouTube videos and a PDF from Chicago ACM (10x better than all that garbage).

And these resources that you used were so good that you can't even use protected mode?

There's a moral there if only you had the sense to realise it.


Yeah right. Most of it is architecture.

_________________
AX BX CX DX BP SP SI DI. The registers that never die. 16-bit... will always sit... in a book where people look. My signature is terrible! I think we all know that.


Top
 Profile  
 
 Post subject: Re: How do I start learning how to use Protected Mode (32-bi
PostPosted: Wed Mar 29, 2017 3:39 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Quote:
Example: "I need a tutorial for the GDT. By the way, why doesn't this boot?

"It doesn't boot because..."
WHAT ABOUT THE GDT?!

It didn't boot because you don't know what you are doing.

You don't know what you are doing because you don't understand how the processor works.

You don't understand how the processor works because you didn't read the manual that describes how it works.

You didn't read the manual because, with one week's experience, you already know better than those who have been doing low-level programming for decades.

The comparison with Homer Simpson is most apposite.

Ignorance is bliss!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 176 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group