flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > whats wrong with my code? |
Author |
|
pfranz 07 Feb 2007, 11:47
What do you expect from this code? If it is right (I haven't checked) it jumps to the halt instruction and stops there, since interrupts are disabled.
What you see is a frozen machine, with only power / reset buttons working ... |
|||
07 Feb 2007, 11:47 |
|
cod3b453 07 Feb 2007, 22:34
That code seems ok but there are a few safety precautions you should take when setting up selectors and also some nice tricks to let FASM do some of the work for you:
Code: use16 org 0x7C00 start: cli ; Stop interrupts xor ax,ax mov ds,ax mov es,ax mov ss,ax mov sp, 0x7C00h ; sti ; Uncomment if code used below ; Other Real Mode Stuff Here ; If required... ;cli ; Uncomment if code used above lgdt [GDTR] ; Load GDT mov eax,cr0 ;\ or eax,1 ; Set PM bit mov cr0,eax ;/ jmp pword 0x0008h:PMode ; pword is imporatant here use32 PMode: ; Must do this first mov ax,0x0010 ; Data selector mov ds,ax mov es,ax mov ss,ax ; Can use a different selector if required mov sp,0x00007C00 ; Can be changed ; Protected Mode Code Here jmp $ ; Infinite loop align 16 GDT1: ; Null Selector dq 0 GDT2: ; Code Selector dw 0xFFFF ; Bits 15-0 of limit (the top part) dw 0x0000 ; Base bits 15-0 db 0x00 ; Base 23-16 db 10011011b ; Present, ring 0, executable, non-conforming, readable db 11001111b ; 4 KB, 32-bit ops, 2 reserved bytes, bits 19-16 of limit db 0x00 ; Bits 31-27 of base GDT3: ; Data Selector dw 0xFFFF ; dw 0x0000 ; db 0x00 ; db 10010011b ; Present, ring 0, non-executable, writeable db 11001111b ; 4 KB, 32 bit data (for stack anyways), high bits of base. db 0x00 ; GDTR: ; Global Descriptor Table Register GDTRSize dw ($ - GDT1 - 1) ; Let FASM compute GDT size for you GDTRLinAdd dd GDT1 ; Start of Global Descriptor Table If this doesn't work there may be some problem with the GDT table (I havn't checked it) |
|||
07 Feb 2007, 22:34 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.