Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
movl $0x0000FFFF, 0x808 # Data segment descriptor
movl $0x00CF9200, 0x80C # read/write
<--SNIPPED-->
.code32 # This part is compiled in 32 bits mode
start32:
movw $0x8, %ax # We set up %ds and %ss pointing on the Data segment
movw %ax, %ds
movw %ax, %ss
jmp . # We stay right here
Here's another problem. When the 32 bit code runs the base of the segment will be 0x00000000, not 0x07C00 (as it was in real mode). This will make the "jmp ." jump to 0x000000?? rather than 0x00007C??.
It's all easily fixed though, start your code with:
.org 0x7C00
.code16 # We assemble this code in 16 bits mode
.globl _start
_start:
jmp $0x00:$here # Not sure about AT&T syntax here!
here:
cli
xorw %ax, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $stack_top, %sp
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
_start:
cli
mov %cs, %ax
movw %ax, %ds
lgdt %ds:gdt_register
mov %cr0, %eax
or $0x01, %al
mov %eax, %cr0
sti
ljmp $0x8,$start32
.code32 # This part is compiled in 32 bits mode
start32:
movw $0x10, %ax # We set up %ds and %ss pointing on the Data segment
movw %ax, %ds
movw %ax, %ss
jmp .
gdt_register:
.word (gdt_end - gdt_start -1)
.long gdt_start
gdt_start:
null_descritor:
.long 0x0
.long 0x0
code_descriptor:
.word 0x0FFFF
.word 0x0
.byte 0x0
.byte 0b10011010
.byte 0b11001111
.byte 0x0
.word 0x0FFFF
.word 0x0
.byte 0x0
.byte 0b10011010
.byte 0b11001111
.byte 0x0
gdt_end:
.fill 0x1FE - ( . - START ), 1, 0
.byte 0x55
.byte 0xAA
Ive been over many tutorials and they all seem to define the GDT table
differently (in a different order). My code seems to fail at the jmp into
the 32bit code. Sorry bout the lack of comments.