flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Octavio 07 Jan 2006, 13:19
You forget the 'org 7c00h' instruction, take a look to some bootloader writen in nasm ,there must be a lot of them.
|
|||
![]() |
|
Dex4u 07 Jan 2006, 16:33
This is the code for cdpod, with graphic's part taken out, as you can see "org 0x7C00" is missing.
Code: ;************************************; \\|//; (@ @); ASHLEY4.; Entry for the 512b compo.;; Assemble with fasm; c:\fasm CdPod.asm CdPod.bin;; Keys = (UpArrow + Enter = Play).; Keys = (DownArrow + Enter = Stop).;;************************************org 0x7C00use16;****************************; Realmode startup code.;****************************start: xor ax,ax mov ds,ax mov es,ax mov ss,ax mov sp,0x7C00;****************************; Vesa start code.;**************************** mov bx,4112h mov ax,4f01h mov di,Mode_Info mov cx,bx int 10h mov ax,4f02h int 10h;*****************************; Setting up, to enter pmode.;***************************** cli lgdt [gdtr] mov eax, cr0 or al,0x1 mov cr0,eax jmp 0x10: protected;*****************************; Pmode. This is how your code should be, not tested. Code: ;************************************; \\|//; (@ @); ASHLEY4.; Entry for the 512b compo.;; Assemble with fasm; c:\fasm CdPod.asm CdPod.bin;************************************org 0x7C00use16;****************************; Realmode startup code.;****************************start: xor ax,ax mov ds,ax mov es,ax mov ss,ax mov sp,0x7C00;****************************; Vesa start code.;**************************** mov bx,4112h mov ax,4f01h mov di,Mode_Info mov cx,bx int 10h mov ax,4f02h int 10h;**************************************; Put your A20 code here:;************************************** lgdt [gdtr] mov eax,cr0 or al,0x1 mov cr0,eax mov ax,0x8 mov ds,ax mov es,ax mov eax,cr0 and al,0xfe mov cr0,eax;================================; Do your stuff here:;================================;*************************************; GDT.;*************************************gdt: dw 0x0000, 0x0000, 0x0000, 0x0000sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CFsys_code: dw 0xFFFF, 0x0000, 0x9800, 0x00CFgdt_end:gdtr: dw gdt_end - gdt - 1 dd gdt;*************************************; Make program 510 byte's + 0xaa55;*************************************times 510- ($-start) db 0 dw 0xaa55;*************************************; Put uninitialized data here.;*************************************include 'vesa.inc';*************************************; $$$$££££( vote for me PS: As anyone can see "your" code is just a cut & pasting of "CdPod", you will not learn by just C&P and will not be able to understand the code, once you find code that works, try and work out what the code does and comment it, it will help you learn ![]() |
|||
![]() |
|
Redragon 07 Jan 2006, 17:52
i also found that CdPod and Solar OS were two of the best sources to read through and learn from. i went from not knowing what ax meant, to now being able to read asm somewhat like a second language. no, im no where near as good as anyone here, but i just keep trying and learning as i go, i also found that what works good is to retype the code, say to CdPod or some of Solar (theres quite a bit of code there). and if you dont know what a certain part means, look it up or find out somehow, then you will be better at knowing what does what, and how it all comes together.
thanks Dex & Bogdan! _________________ (AH+AL=AX)+E=EAX |
|||
![]() |
|
Dex4u 07 Jan 2006, 18:13
Thanks Redragon, We all learn from each other, i also learnt from Solar and give full credit in Dex4u
Code: ;=========================================================;; Kernel32. 11/12/03 ;;---------------------------------------------------------;; ;; A 32bit pmode OS called "Dex4u". ;; fasm kernel32.asm kernel32.exe ;; ;; Thanks to: Tomasz Grysztar,Christopher Giese ;; Alexei A. Frounze, smaffy, Ontanu Bogdan Valenti. ;; Bubach. ;; ;; Dex4u V0.01 ;; (c) Craig Bamford, All rights reserved. ;;=========================================================; But just in case he mist it, thanks ![]() |
|||
![]() |
|
Goat6 07 Jan 2006, 18:35
I have looked over this material, over and over again.
I even got the documentation to NASM so that I could make sure I could translate the code properly from FASM to NASM. The code enter unreal mode fine, but if I ad ANY cod before or after the UM code the system triple faults. I also made sure that I properly set the segment registers. But I cant fugure out whats wrong. Also this code will go into a secondary loader NOT a boot loader. My Plan is to, Have the Boot Loader load the secondary loader called 'Loader.bin', Loader.bin then loads the memory manager, process manager, Device manager, ect. At the end of all these actions I will place structures that discribe these processes into memory, then setup a timer interrupt to jump to the first processin line which is the process manager, then the memory manager sence the process and memory managers must work together to store processes. I use the timer so that the system will automaticly jump to the process manager, but will allow time for my loading screen to be viewed. But if I cant add any code to the unreal mode init code then this is all for nothing. I appreciate any advice all of you could give. Thanks. ![]() ![]() ![]() _________________ Death is not the opposite of life but rather the absence of it. |
|||
![]() |
|
Dex4u 07 Jan 2006, 21:27
Code: [bits 16][ORG 0x7C00][SEGMENT .text];;;;-----Real Mode Startup-----;;;;start: xor ax,ax mov ds,ax mov es,ax mov ss,ax mov sp,0x7C00 ;;;;-----Setup VESA-----;;;; mov bx,4112h mov ax,4f01h mov di,Mode_Info mov cx,bx int 10h mov ax,4f02h int 10h;;;;-----Enter Unreal Mode-----;;;; lgdt [gdtr] mov eax, cr0 or al,0x1 mov cr0,eax mov ax,8h mov ds,ax mov es,ax mov eax, cr0 and al,0xfe mov cr0,eax ;Enable A20 mov eax, 0DFh out 64h, eax ;;;;-----Kernel Main Code-----;;;; Hang: jmp Hang[SEGMENT .bss]%include "vesa.inc"[SEGMENT .data]gdt: dw 0x0000 dw 0x0000 dw 0x0000 dw 0x0000sys_data: dw 0xFFFF dw 0 db 0 db 10010010b db 11001111b db 0gdt_end:gdtr: dw gdt_end - gdt - 1 dd gdt If you still get the same problem, with the above code let me know, also you need to check your A20 code some do not work. |
|||
![]() |
|
bogdanontanu 07 Jan 2006, 21:45
Hi,
It is nice to findout that SolarOS was somehow helpfull for others aslo;) After all, helping others understand was one of it's purposes. However the path to walk can not be transfered with the source code. For this you need more close contact Now about this code here... As a general rule: When developing an OS for the first time (and if you are not GOD himself) YOU MOST PE PARANOICALY CAUTIOUS! Please suspect everything anytime and never assume anything! Beeing busy, I will not go as far as testing your code rigurousely but after a quick look... This is what I did noticed (not necessary in the order of importance): 1)Setting stack at 0x7c00 is a little risky. A much higher address like 0x9C00:0000 (right below A000 video segment) is more cautious. Here the stack is too low and right under the boot loaded sector. As a consequence you are playing with fire (do you have a match?) A stack underflow will erase your code and a stack overflow will hit the real mode INTERUPT table... please choose ![]() 2)The VESA calls are not tested for an error ![]() Even more you do NOT test the very existence of a VESA interface. 3)After enabling protected mode Are you sure that the instruction: jmp 0x10: protected is assembled corectly? because the [bits 32] is AFTER that instruction (uncertain on FASM here) 4)You are resetting the whole CR0 low 8 bits and NOT only the protected mode bit. This must hurt the CPU a little ![]() 5)In protected mode you insist on keeping the stack low 6)Enable A20 line is done OK only by that 2 instructions? 7) Maybe you GDT table is not ok? Well if it did work in CdPod i assume it is ok ![]() I did not have the dedication to check it out but I have noticed an ODD thing: like having the DATA selector before the CODE selector ...oh dear no problem here but still ... ![]() Just to make myself a better oppinion. In the End: I suggest that you check any assumtions you make with some string/character output funtions to the normal text screen located at 0xB000:0000 Just do not enable VESA GFX mode until you are sure everything is ok. Unreal mode is just a tweak, with some limited use, I would not use it before I have everything working ok and also have a very clear need to do so. The only use I can see for unreal mode is to load a kernel that is bigger than 1M into the high memory areas. So, until your kernel grows bigger that 1M... you do not really need it. BUT you do need a working functional protected mode and a good grasp of it! The motto: "Death is not the opposite of life but rather the absence of it..." it is one of my favourite sayings.... I wonder IF you really understand the meaning of it? Last edited by bogdanontanu on 07 Jan 2006, 22:01; edited 1 time in total |
|||
![]() |
|
Dex4u 07 Jan 2006, 21:59
@bogdanontanu, he has used code that was from a 512b compo entry, which because of fitting things in, left out things like vesa error or even checking for vesa, he should of read the warning
Quote:
Also its unrealmode he wants to get into. |
|||
![]() |
|
Tomasz Grysztar 07 Jan 2006, 23:59
bogdanontanu wrote: Are you sure that the instruction: In that place the protected mode is already enabled, but the code selector has not yet been reloaded - thus this instruction is still in 16-bit. How could it be assembled incorrectly here? |
|||
![]() |
|
Borsuc 08 Jan 2006, 16:45
bogdanontanu wrote: A stack underflow will erase your code If the code will never be used again, what's wrong with erasing it? Sure, I agree with you and don't recommend this idea, but it will not be so fatal. ![]() The boot loader code is usually not used twice, so it can be erased as it is executed. ![]() Examples like SolOS are a good resource of learning, but you should also read some books or talk with someone with experience. In theory, it's a good idea to collect a lot of resources, and select what's good from all of them, since no single one will be perfect, and usually each has it's own advantages and disadvantages. Redragon wrote: i went from not knowing what ax meant, to now being able to read asm somewhat like a second language. Wow, you must be pretty smart by learning only by example. Good luck ![]() Dex4u wrote: We all learn from each other Very true ![]() ![]() |
|||
![]() |
|
dasyar 08 Jan 2006, 19:44
From what I can tell, and I have been down this road before, you are trying to use some readily available code in FASM format, and you are trying to compile it with NASM. For protectected mode that scheme will not work. There are differences in how you would do it in FASM and NASM. I suggest that you go here http://my.execpc.com/~geezer/index.htm, and find geezers tutorial as to how to get into PMODE, and then how to proceed from there. But, if you want to waste your time cutting and pasting and then finding out it does not work, well ...
I think what you may want to do is think about making a decission as to which compiler you will stick with. It will save you a lot of wasted time in the long run. |
|||
![]() |
|
Octavio 11 Jan 2006, 12:03
bogdanontanu wrote: Hi, why? many bios load the boot code with this setting. Quote:
Usually this is a reserved memory area. |
|||
![]() |
|
bogdanontanu 11 Jan 2006, 18:15
Octavio wrote:
Yes, but you are warned about this low on stack space condition for boot loader code. Many boot loaders immediately change the stack location to a more safeer area. Since the stack expands downwards it is logically to assume that a higher memory area is the best location for a stack since it provides more place for "expasion". Quote:
Yes there is an rezerved area in there of approximative 1K or 2K in size but as you may notice I have suggested a value that is a little under that reserved area. Anyway, as I have said in my post I was not trying to be extreemly exact here. Instead I was tryoing to teach some usefull attitude / concepts / philosophy: Play it safe and cautious when exploring unknown areas Especially when you are a newbie and can not see the consequences of your choices far in advance. This kind of attitude always plays back with faster learning, less frustration and better progress ... Well at least for me it does so even afer i have become more experienced, so I honestly try to propose it to others as well. But by all mean please feel free to choose other methods of paths as you like... to Grey beast: Yes i guess everybody knows you can overwrite the boot loader code after it's job was done However why to do so? To complicate things a little and save 512 bytes of RAM and later on to require 4Megabytes minimum for the OS to run? _________________ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
|||
![]() |
|
Borsuc 13 Jan 2006, 17:32
bogdanontanu wrote: Yes i guess everybody knows you can overwrite the boot loader code after it's job was done I know, it is not necessary useful, but at least it's not a big tragedy if it will erase a few boot code. If it works OK, it doesn't need to be changed. Octavio wrote: many bios load the boot code with this setting. What is exactly loaded by the BIOS at boot? I only know 'bout dl register which is drive number, and cs which is 0, because boot loader starts at 0000:7C00. What else is common for BIOSes at boot? If I do not set up my own stack via the boot loader code, what does the BIOS actually load in sp and ss? any articles/links? thanks |
|||
![]() |
|
dasyar 13 Jan 2006, 19:58
The function of the BIOS, is to bootstrap, which means find a bootable source, and load the bootsector of that source to 7c0. At that point the processor runs what ever is there.
|
|||
![]() |
|
Borsuc 13 Jan 2006, 20:04
to which values are sp and ss (and other registers, for that matter) initialized? i only know dl is the drive number.
|
|||
![]() |
|
Octavio 14 Jan 2006, 10:13
The_Grey_Beast wrote: to which values are sp and ss (and other registers, for that matter) initialized? i only know dl is the drive number. you must initialize registers yourself, dirfferent bios have different values at boot time. i start my boot code like this: xor ax,ax es=ax ds=ax ss=ax sp=7c00h cld cs:ip can be 0:7c00h or 7c0h:0 but the code works the same. |
|||
![]() |
|
Borsuc 15 Jan 2006, 12:07
thanks
![]() I thought the direction flag is cleared at startup? some boot loaders I see were obviously not using cld and used string instructions.. in comments it says cld is not needed?? ![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.