Tasm bootloader

bocha111 Messages postés 1 Date d'inscription mercredi 18 avril 2012 Statut Membre Dernière intervention 25 juin 2012 - 21 juin 2012 à 16:00
Greg159357 Messages postés 112 Date d'inscription lundi 21 octobre 2013 Statut Membre Dernière intervention 4 janvier 2014 - 10 nov. 2013 à 17:33
Hello exerybody

i want to know how to create a bootloader in tasm version

thanks !

2 réponses

Greg159357 Messages postés 112 Date d'inscription lundi 21 octobre 2013 Statut Membre Dernière intervention 4 janvier 2014
10 nov. 2013 à 17:29
I don't do TASM but maybe this code will work (it's NASM) :
[BITS 16]
[ORG 0x0]

jmp start
start:

	mov ax, 0x07C0
	mov ds, ax
	mov es, ax
	mov ax, 0x8000
	mov ss, ax
	mov sp, 0xF000

	mov [bootdrv], dl
	jmp detectcpu
	
detectcpu:
	mov si, msgproc
	call print
	
	mov si, msgproc8086
	pushf
	
	xor ah, ah
	call testflags
	cmp ah, 0xF0
	je endcpu
	
	mov si, msgproc286
	mov ah, 0xF0
	call testflags
	jz endcpu
	
	mov si, msgproc386
	jmp endcpu
	
testflags:
	push ax
	popf
	pushf
	pop ax
	and ax, 0xF0
	ret
	
endcpu:
	popf
	call print
	mov si, msg
	call print
	mov si, msgkey
	call print
	call sleep
	jmp nextgdt
	
sleep:
	xor eax, eax
	int 16h
	cmp al, 0
	je sleep
	cmp al, 'R'
	je restart
	cmp al, 'r'
	je restart
	ret
	
restart:
	mov al, 0xFE
	out 0x64, al
	
nextgdt:
	xor ax, ax
	int 0x13
	
	push es
	mov ax, 256
	mov es, ax
	mov bx, 0
	mov ah, 2
	mov al, 50
	mov ch, 0
	mov cl, 2
	mov dh, 0
	mov dl, [bootdrv]
	int 0x13
	pop es
	
	mov ax, gdtend
	mov bx, gdt
	sub ax, bx
	mov word [gdtptr], ax
	
	xor eax, eax
	xor ebx, ebx
	mov ax, ds
	mov ecx, eax
	shl ecx, 4
	mov bx, gdt
	add ecx, ebx
	mov dword [gdtptr+2], ecx
	
	cli
	lgdt [gdtptr]
	
	mov eax, cr0
	or ax, 1
	mov cr0, eax
	jmp next
	
next:
	mov ax, 0x10
	mov ds, ax
	mov fs, ax
	mov gs, ax
	mov es, ax
	mov ss, ax
	mov esp, 0x9F000 
	jmp dword 0x8:0x1000
	
print:
	push ax
	push bx
	push cx
	push dx
	xor bh, bh
	mov ah, 0x03
	int 0x10
	mov cx, 1
printnew:
	lodsb
	or al, al
	jz eos
	cmp al, 13
	je newline
	mov ah, 0x0A
	int 0x10
	inc dl
	cmp dl, 80
	jmp cursor
	
newline:
	inc dh
	xor dl, dl
cursor:
	mov ah, 0x02
	int 0x10
	jmp printnew
	
eos:
	pop dx
	pop cx
	pop bx
	pop ax
	ret

bootdrv: db 0
gdt: db 0, 0, 0, 0, 0, 0, 0, 0
gdt_cs: db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10011011b, 11011111b, 0x0
gdt_ds: db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10010011b, 11011111b, 0x0
gdtend:
gdtptr:
dw 0
dd 0
msgkey: db 'Press any key to starting kernel or press R to restart ', 0
msg: db 'Loading GDT and jumping to kernel', 13, 0
msgproc: db 'Processor : ', 0
msgproc8086: db '8086 or 8088', 13, 0
msgproc286: db '286', 13, 0
msgproc386: db '386', 13, 0
times 510-($-$$) db 0
dw 0xAA55
0
Greg159357 Messages postés 112 Date d'inscription lundi 21 octobre 2013 Statut Membre Dernière intervention 4 janvier 2014
10 nov. 2013 à 17:33
The kernel must be set to 1000h
0
Rejoignez-nous