When a computer starts up, what does windows have to do to switch the processor to 32 bit mode??
Posted on 2001-04-27 21:30:00 by Hel
Nothing, I believe. The processor's already 32 bit, it's just that most OS's only use 16 bit for the startup code. I've seen some that are only 32 bit. The only real switch is from real mode to protected mode. Check OS Development for Dummies (No offense, that's just the name of the page :D) This message was edited by Qweerdy, on 4/28/2001 6:03:40 AM
Posted on 2001-04-28 06:02:00 by Qweerdy
Wrong Qweerdy, you have to do a lot to get to 32 bits mode ;) i am writeing my own OS...(its a little on hold now, due to HE game... anybody wants to join forces? :D eh...? ) so i know about those things... When started the Micro is on 16 bit real mode, BIOS startup code is then executed and its checks the hardware and setups PnP etc. Problem is that ALL this code is 16 bit...hence the need for windows/you to remake all this code for all possible boards... Win is unable to do that for all boards ...so for some of them it still switches back to 16 bits mode (this takes a lots of time, and is unsure) executes stuff for that board and then makes a switch back to 32 bit protected mode... This kinda defies the initial purpose of BIOS, that is that every board manufacturer will make a set of standard functions that will help OS's to deal with specific hardware. Because PC starts in 16 bit real mode and BIOS is in 16 bit mode (vast majority) BIOS is allmost unusable by windows and other 32 bits OS's :( Conclusion: Terran(Earth) commercial driven tehnology sucks ! :( Anyway.... after BIOS make its stuff it loads the first sector from Floppy or HDD at adress 0000:7C00h segment:offset and executes a jump to it.... it is your duty to take it from here...use the so blamed BIOS (int 13h) to read the rest of your kernel from disk, setup GDT and IDT (at least, but LDT and TSS will usually follow) then GO! for 32 bit protected mode... Well this much i did allready...:) thanks to Linus Torvalds and others that released tehir OS startup code... :) But the real pain just starts here: you must make drivers for all hardware boards that exist on market, not to speck of the standard keyboards, mouses, video boards ... and also task/memory/interupts/filesistem management can add pain to all that :) I hope i will live long enough to do it, after all Linus did it...why not me also :) ? Maybe some of you guys will want to help me in this long jurney .... This message was edited by BogdanOntanu, on 4/28/2001 5:21:07 PM
Posted on 2001-04-28 17:11:00 by BogdanOntanu
For good PMODE and OS, visit the page at http://members.tripod.com/~ladsoft/ Jones.
Posted on 2001-04-29 00:54:00 by sjhenry
BogdanOntanu, im actualy designing my own OS too. I have kinda given up cause I havn't been able to get my hands on any docs for programing any devices (except for the keyboard, haha) and so therefore there is little point, I have got roughly to the stage of entering protected mode, but that is without Interupts etc, very basic. If ya want to join forces I would be happy to give an effot. PS. all windows has to do to swich to proctected mode: (assumes a valid GDT, IDT, LDT and CS:IP in real mode are equal to GDT or LDT entrys in the linear address space)

mov eax,cr0
or eax,1
mov cr0,eax
jmp far cs:[@F]
@@:
This message was edited by George, on 4/29/2001 5:43:23 AM
Posted on 2001-04-29 05:14:00 by George
Hi I will post here some old code...after all i am not so advanced...and i related a lot on work of Linus Torvalds...so credit goes to him and many other esp the V2Os team :) (i just again have to search my HDD and retest it ) I will explain GDT to anybody needs it... ;) Intel system programming manuals will do it also :) And yes i will like to join forces with you George ...and anybody else ... but take care...i intend to keep that OS under my control :) and sometimes i have strange ideeas :D Besides it will be a OPEN SOURCE PROJECT... main concern is SPEED, no bugs and of course FULL ASM... :) i think a GPL licence will do? also? This message was edited by BogdanOntanu, on 4/30/2001 3:11:58 AM
Posted on 2001-04-30 03:03:00 by BogdanOntanu
Before I begin, I dont really understand most of the system type selectors (such as trap, call gates etc), I know what TSS and LDT are for, but I am not deep enough into the IA to know these. In fact if you could explain these to me it would be much appreciated. Also I assume that paging is not used at all. The GDT is of couse the Global Desciptor table and is located in memory by the GDTR register. Now note the GDTR register contains a pointer to the GDT, and the size (or limit) of the GDT, unfornatly the twist here is that the GDT is not located in it own segment such as the LDT, as this is impossible, because you need the GDT to declare the segments, rather the address is in the liner address space (a chicken and a egg problem). The next step in initlizing the GDT that the first selector is not used, im not sure if it has to be initialized to zero, but an attempt to use a selector value of 0000, will result in an exception. From here on you have to build your selectors to allow for code executions and and memory access, and not least important a stack. A stack and data segments essentialy have the same basic attributes, but a code segemtn is a different story. A point to notice is that under IA32, a code segment can NOT be given write acess, even under Ring0. To overcome this, you overlap your segments so that you can read/write to a memory location, but still execute from that same location. Windows itself uses this technique, you can self-modify your code, but still write the same address. The next issue, even through segment selectors are 16Bit, the GDT and LDT may not contain more than 8192 selectors, this is because each segment register is used differently than in real-mode. Bits 0&1 are the RPL (Requested priviledge level) Bit 2 is the table indictcator bit (Set for LDT, clear for GDT) Bit 3:15 index into the table selector. Take special notice of the table indicator bit. It is used directly as to if bits 3:15 of the selector form a reference into the GDT or LDT. Now to fill the GDT, first of all, you cant just bung up any old GDT with any old selector values to make the switch from real mode to protected mode. This is for one important reason, addressing methods in the two modes. A good way to explain this is through an example. When you OS first loads from a bootsector (I am assuming it is from a bootsector, but the princibals still apply from DOS.), it gains executions at address 0000h:7C00h, this code then loads the rest of the 16Bit initializtion code into say the address 1000h:0000h. Now to switch from real to protected mode. The most important thing to remember is THAT ALL THE REGISTERS REMAIN THE SAME (except for CR0 of course), BUT THE SEGMENT REGISTERS ESPICALY TAKE ON VERY DIFFERENT MEANINGS. To correctly do this you would have to create at the 1000h selector in the GDT the code segment to allow the phyical address of execution to remain the same. All that memory, about 8000h bytes of it would be wasted because you would not need those segments for such a basic stage of your OS. Thats about all I have time for at the moment, it gives you the general idea, about what to do, if you have anymore questions, post here or email me. This message was edited by George, on 4/30/2001 3:48:49 AM
Posted on 2001-04-30 03:26:00 by George
Ok i found some OLD OS system code, is NASM Specific but i belive it can be easy converted to MASM/TASM/SPASM/whatever its quite long...so i think i will have to make a new web page... soon ... to upload new versions there... Maybe Me, George, and any Other interested guys will start to work base on this NEAR ZERO OS start code :) After all its allways fun to start from zero...so many opportunities ;) I belive this code has some bug in the Interupts tables or service routines...but is a good start, also some things where commented out as i was experimenting things i also wonder why TABs dont show right...:(


;	bootsector system loader
;	version 0.0.3
; 
;	compile with:
;	===============
;	nasm -f bin os4.asm -o os4.bin -l os4.lst
;rwawrite (from linux was used to write the code
;on sector zero of a flloppy after compile
;
;	Credits go to:
;	=========================
;	Linus Torvalds and Linux 
;	GazOS, V2OS
;	and may other anonymous inet heroes
;

	BITS 16

	ORG 0x0000

boot01:
	jmp	boot02
	nop

; data zone , variables we may need
;========================================
boot_drv	db	0	; drive number we where loaded from :)
cs_segment	dw	0
Track		db	0
Sector		db	0
Head		db	0
Length		dw	1
x1		dd	boot01
x2		dd	boot02

; back to code
; ===============================================
; BIOS loads this first  512bytes sector at linear 0000:7C00h
; so we set DS to 0x07C0
; in order to correctly access data references
; ===============================================
align 16

boot02:
	cli			; please no interupts
	mov	ax,0x07C0
	mov	ds,ax
	mov	es,ax		; es same as ds

	mov	,dl	; save drive #

; here we make our own stack
; at 0x9000:0xFFF0 linear 0x0009:FFF0

	mov	ax,0x9000	; segment for stack
	mov	ss,ax
	mov	sp,0xFFF0	; offset for stack

	sti			; enable ints again

; clear direction flag
; repetitive string operations 
; will increment SI/DI from now on

	cld			

; print a short wellcome message

	mov	si,msg_001
	call	Print_Msg 

; test  our hex printing routine

	mov	dx,0xface	; arbitrary hex constant to print
	call	Print_Hex16
	call	Print_CRLF


	mov	ax,0x07C0	; base memory for loading
	mov	es,ax
; ========================================================
; Load the Setup Code Sectors at linear 0x0000:7e00
; Note that ES is already set up above at ES=0x07C0
; buffer is at es:bx ie 0x7c00:0200 and 0x7C00+0x0200=0x7E00
; =========================================================

load_setup:
	xor	cx,cx
	xor	ah,ah		; func.no.0 = reset FDC 
	xor	dl,dl		; drive.no=0 ie disk a:
	int 	0x13		; use bios call 

	xor	dx,dx		; drive 0, head 0
	mov	cl,2		; sector 2, track 0
	mov	bx,0x0200	; offset of loading
				; address ES:BX = 07C00:0200, linear 0x0000:7E00
	mov	ah,2		; func.no.2=read sectors
	mov	al,16		; 8 sectors 8*512=4096=4k=0x1000h 
				; setup is loaded at 0x7E00-0x8E00
	int	0x13		; read it via bios call
	jnc	ok_load_setup	; if ok - continue

; Ouch...here we have an error.... :(

	push	ax		; save error code
	call	Print_CRLF	; newline
	pop	ax		; retrive error code
	mov	dx,ax
	call	Print_Hex16	; print error code

; if error ... lets try it again ....
	
	jmp	load_setup

ok_load_setup:
	mov	si,msg_002	; print happy message...
	call	Print_Msg 			 


; nothig more to do here ...eh..
; bye-bye First Sector .... for now


;	jmp	far dword Sector_002

; QUICK HACK FOR A -FAR- JMP INSTRUCTION
	DB 0xEA			; jump to sector 02
	DW 0x7E00		; offset 
	DW 0x0000		; segment 


; ************************************
; utility routines for the bootsector
; ************************************
;
; First a message printing routine
; using bios call to output ASCII letters to Screen
; until the last char=0 when it stops and returns
; ===================================================
Print_Msg:
		lodsb		; al=, si=si+1
		or	al,al
		jz	ok_msg1

; BIOS int 0x10 function 0x0E = write char to console
		mov	ah,0x0E	; ah=0x0e al=ascii code of char to output
		int	10h
Posted on 2001-05-01 02:14:00 by BogdanOntanu

 Wow. That's alot :) I can see that there's some humours in the-
 re. As usual. ehehe.

 I just copied and save it into my harddrive.  (i'm not sure  if
 George did. and I'm not sure if he really need the code above.)
 Just to let you know, so  that you can delete  the msg above if
 needed (I'm using 56K modem and it  took abit to load the page.
 at first, I thought that the FORUM is down or something...).

 Thanx for the code! (I never thought of having all the sector -
 in one file!! I once thought that people actually create a boot
 sector and then the main setup with another file).

 alot of things in that are clear to me. Except the GDT (the se-
 tting up part. That's the thing that always slow me down in sy-
 ystem programming.)

 But anyway, I'll try and go over  the GDT part  and try my best
 to understand it.

 A thousand thanx for your TIME.
Posted on 2001-05-01 18:54:00 by disease_2000
take care with the code as i remember this version has some problems with Interupts.... i belive i was switching som words or bytes wrong somwere in the IDT or ISR ...so botom line it will crash IF you use Interupts... so to make it work: coment the int 5 stuff and also do a CLI in your 32 bit code... also it takes more then a single sector on floppy but rawwrite will write it ok and it will also load ok as long as its not more the a single track... 18sectors i belive...still plenty of space until that ;) i will leave the message with code here...maybe some other guys will want to take a look...when i restart working and have a better working wersion... i will send it to Iczelion to post it to its page ...and also upload it somwhere elese on the net ;) i feel like i must start building a web page for my new full ASM OS ;) LOL ;) everybody feels like that after the bootsector...i only wonder when i will start the GUI ...
Posted on 2001-05-02 05:14:00 by BogdanOntanu