How do I start learning how to use Protected Mode (32-bit)?
How do I start learning how to use Protected Mode (32-bit)?
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.
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.
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: How do I start learning how to use Protected Mode (32-bi
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!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.
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.
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.
Re: How do I start learning how to use Protected Mode (32-bi
lea is fully supported on all x86 assemblers.starmanz wrote:... and also it has the LEA instructions which is not supported on some assemblers.
Last edited by mikegonta on Sat Apr 01, 2017 9:55 am, edited 1 time in total.
Re: How do I start learning how to use Protected Mode (32-bi
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.
Re: How do I start learning how to use Protected Mode (32-bi
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
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
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: How do I start learning how to use Protected Mode (32-bi
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.
Re: How do I start learning how to use Protected Mode (32-bi
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.
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.
Re: How do I start learning how to use Protected Mode (32-bi
jeez. just one note, masm32 knows about lea.
Re: How do I start learning how to use Protected Mode (32-bi
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.
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: How do I start learning how to use Protected Mode (32-bi
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":
and
"Journey To The Protected Land":
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.
"Protected Mode":
Code: Select all
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
"Journey To The Protected Land":
Code: Select all
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
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.
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.
Re: How do I start learning how to use Protected Mode (32-bi
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.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.
Learn to read.
Re: How do I start learning how to use Protected Mode (32-bi
And these resources that you used were so good that you can't even use protected mode?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).
There's a moral there if only you had the sense to realise it.
Re: How do I start learning how to use Protected Mode (32-bi
Sup Mike. How's Neptune going?! I really wanna try it out in VirtualBox.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.
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.
Re: How do I start learning how to use Protected Mode (32-bi
Yeah right. Most of it is architecture.iansjack wrote:And these resources that you used were so good that you can't even use protected mode?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).
There's a moral there if only you had the sense to realise it.
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.
Re: How do I start learning how to use Protected Mode (32-bi
It didn't boot because you don't know what you are doing.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?!
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!