flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Going back to 16bit mode in my bootstrap |
Author |
|
mkriegel 01 Aug 2007, 14:56
Why do you need to switch to 16 bit mode in order to load the rest of your kernel. Can't you do this by calling a DMA-driver or sth. like this.???
|
|||
01 Aug 2007, 14:56 |
|
calpol2004 01 Aug 2007, 15:31
Well i can use BIOS interrupts to load the file from the floppy in 16bit mode and because i went in the 32bit mode temporarily and enabled the a20 gate i can load a kernel over 1MB.
I guess it's possible to interface with the floppy controller and load sectors manually but it's so much more convenient to use the bios, more portable too. I can't see how i'd go about using DMA channels to load sectors from a floppy disk, seems a much harder feat. Last edited by calpol2004 on 01 Aug 2007, 15:33; edited 1 time in total |
|||
01 Aug 2007, 15:31 |
|
Dex4u 01 Aug 2007, 15:33
I written some code to goto and from realmode for vesa mode changing, see here:
http://www.dex4u.com/demos/DemoVesa.zip NOTE: I was called "ASHLEY4" when i wrote it. The first thing to remember is you need to set realmode and pmode address the same before goint to pmode and save some realmode settings as here: Code: xor ebx,ebx mov bx,ds shl ebx,4 mov eax,ebx mov [sys_code_1 + 2],ax mov [sys_data_1 + 2],ax mov [Real_code_1 + 2],ax mov [Real_data_1 + 2],ax shr eax,16 mov [sys_code_1 + 4],al mov [sys_data_1 + 4],al mov [Real_code_1 + 4],al mov [Real_data_1 + 4],al mov [sys_code_1 + 7],ah mov [sys_data_1 + 7],ah mov [Real_code_1 + 7],ah mov [Real_data_1 + 7],ah add ebx,gdt mov [gdtr + 2],ebx cli mov ax,cs mov [RealModeCS],ax Now the next thing to do is go back and forth to realmode for every 512bytes loaded, this sounds slow, but i can tell you it the same speed as if you made a pmode driver. In my OS i have two drivers for floppy and hdd, one a Pmode to real, and one a Pmode driver and theres very little between them, but by going to and from pmode you can load from usb key fob etc, if your bios can boot from USB. |
|||
01 Aug 2007, 15:33 |
|
mkriegel 01 Aug 2007, 18:11
Isn't this switching a danger for a well-structured OS?
|
|||
01 Aug 2007, 18:11 |
|
Gizmo 01 Aug 2007, 18:37
Correct me if I'm wrong, but you can enable the a20 gate in real mode since its the keyboard controller your talking to and not the processor.
You can switch modes on 386 and other cpus as much as you want, just store the ivt and restore the pic when you head back to real mode (if you change them any). The 286 cannot go back to real mode. Long mode cannot go back to real or protected mode, but you can use legacy mode. Switching modes is slow so you shouldnt do it alot, but a few places here and there will cause no harm. |
|||
01 Aug 2007, 18:37 |
|
calpol2004 01 Aug 2007, 18:50
Well considering this is a bootstrap...a second part to the bootloader, the switches only take place once. I'm hoping all the switches i'll ever have to do is once 32bit protected provided gizmo is right that it's unnecesary for me to enter 32bit just to enable A20 then come back out.
Because my kernel doesn't multi-task or anything (yet) so even though BIOS interrupts are slow they're still pretty fast and using them is only going to add like 0.1 seconds to a process which no one is going to notice (i may go through it afterwards and re-write it using the controllers instead), it's often worth using them sometimes for extra portability and not having to write as much code :p. I'm currently looking through the bochs documention to find out how to use the debugger, i could then go through the program instruction by instruction and get a better idea what going wrong and test my A20 procedure as i'm not 100% it's functional. Either way, thanks for the help. DexOS Even if your Vesa example doesn't help me with this problem i have been looking for a coded example which uses VESA so you've helped me out there . |
|||
01 Aug 2007, 18:50 |
|
Gizmo 01 Aug 2007, 19:55
To test if your a20 works, compare a known value from 1 address to the value stored at that address + 1meg. If it wraps around and they are equal, then your a20 code didnt work.
Some keyboard controllers are a bit different and your code may not work on every pc. Here is the code I use that I found in a tutorial that trys 2 methods (note its 16 bit): (I havent tried it this way, but it looks like it could be called in C as signed long enableA20(void) ) Code: ;; ;; enableA20.s (adapted from Visopsys OS-loader) ;; ;; Copyright (c) 2000, J. Andrew McLaughlin ;; You're free to use this code in any manner you like, as long as this ;; notice is included (and you give credit where it is due), and as long ;; as you understand and accept that it comes with NO WARRANTY OF ANY KIND. ;; Contact me at jamesamc@yahoo.com about any bugs or problems. ;; use16 Enable_A20: ;store all registers pusha ;disable interupts cli ;5 attempts to enable a20 line mov CX, 5 ;first method of enabling a20 .startAttempt1: ; Wait for the controller to be ready for a command .commandWait1: xor AX, AX in AL, 64h bt AX, 1 jc .commandWait1 ; Tell the controller we want to read the current status. ; Send the command D0h: read output port. mov AL, 0D0h out 64h, AL ;Wait for the controller to be ready with a byte of data .dataWait1: xor AX, AX in AL, 64h bt AX, 0 jnc .dataWait1 ; Read the current port status from port 60h xor AX, AX in AL, 60h ; Save the current value of AX push AX ; Wait for the controller to be ready for a command .commandWait2: in AL, 64h bt AX, 1 jc .commandWait2 ; Tell the controller we want to write the status byte again mov AL, 0D1h out 64h, AL ; Wait for the controller to be ready for the data .commandWait3: xor AX, AX in AL, 64h bt AX, 1 jc .commandWait3 ; Write the new value to port 60h. Remember we saved the old value on the stack pop AX ; Turn on the A20 enable bit or AL, 00000010b out 60h, AL ; Finally, we will attempt to read back the A20 status to ensure it was enabled ; Wait for the controller to be ready for a command .commandWait4: xor AX, AX in AL, 64h bt AX, 1 jc .commandWait4 ; Send the command D0h: read output port. mov AL, 0D0h out 64h, AL ; Wait for the controller to be ready with a byte of data .dataWait2: xor AX, AX in AL, 64h bt AX, 0 jnc .dataWait2 ; Read the current port status from port 60h xor AX, AX in AL, 60h ; Is A20 enabled? bt AX, 1 ; Check the result. If carry is on, A20 is on. jc Enable_A20_success ; If the counter value in CX has not reached zero, we will retry loop .startAttempt1 ;method 2 for chipsets that don't support method 1 mov CX, 5 .startAttempt2: ; Wait for the keyboard to be ready for another command .commandWait6: xor AX, AX in AL, 64h bt AX, 1 jc .commandWait6 ; Tell the controller we want to turn on A20 mov AL, 0DFh out 64h, AL ; Again, we will attempt to read back the A20 status to ensure it was enabled. ; Wait for the controller to be ready for a command .commandWait7: xor AX, AX in AL, 64h bt AX, 1 jc .commandWait7 ; Send the command D0h: read output port. mov AL, 0D0h out 64h, AL ; Wait for the controller to be ready with a byte of data .dataWait3: xor AX, AX in AL, 64h bt AX, 0 jnc .dataWait3 ; Read the current port status from port 60h xor AX, AX in AL, 60h ; Is A20 enabled? bt AX, 1 jc Enable_A20_success ; If the counter value in CX has not reached zero, we will retry loop .startAttempt2 ;unable to enable a20 Enable_A20_fail: sti popa mov EAX, -1 ret ;enabled a20 Enable_A20_success: sti popa xor EAX, EAX ret |
|||
01 Aug 2007, 19:55 |
|
Gizmo 01 Aug 2007, 20:01
You should print out messages detailing the current operation so that when it stalls, the last message displayed may tell you where it is crashing.
Place a message and a hlt and retry the program. If it reaches it, move it down some more and try again- eventually you will reach the crash and then you will have a better idea whats crashing it. |
|||
01 Aug 2007, 20:01 |
|
Dex4u 02 Aug 2007, 01:47
Your welcome here some pointers, it true that not all A20 work on all PC and yes you can set A20 in realmode, also note bochs sets A20 by default, as do a lot of new PC .
As for unrealmode there example in the Dos fasm code or kelvar see here: http://flatassembler.net/examples/kelvar.zip NOTE: When i want to use unrealmode many years ago, i found most example on the net i tried, just did not work. |
|||
02 Aug 2007, 01:47 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.