Code: Select all
TEST dd 0x00
TEST2 dd 0x00
mov dword[TEST], [TEST2]
Code: Select all
TEST dd 0x00
TEST2 dd 0x00
mov dword[TEST], [TEST2]
Code: Select all
org 0 ; we start everything at zero
jmp start
MANU_DESC db 'mkdosfs '
BLOCK_SIZE dw 512
BLOCKS_PER_ALLOCATION_UNIT db 128
RESERVED_BLOCKS dw 1
TOTAL_FATS db 1
TOTAL_ROOT_ENTRIES dw 512
TOTAL_BLOCKS dw 0xffff
MEDIA_DESCRIPTOR db 0xf8
BLOCKS_PER_FAT dw 0x01
BLOCKS_PER_TRACK dw 18
TOTAL_HEADS dw 0x02
HIDDEN_BLOCKS dd 0x00
TOTAL_BLOCKS_2 dd 0x00
DRIVE_NUMBER dw 0x00
EXTENDED_BOOT_SIGNATURE db 0x29
VOLUME_SERIAL_NUMBER dd 0x9d86f18c
VOLUME_LABEL db 'SEAGULL '
FILE_SYSTEM_IDENTIFIER db 'FAT16 '
; Calculated in memory
ROOT_DIRECTORY dd 0x00
DAPACK:
db 0x10
db 0
.len: dw 1
.loc: dd 0x7e00
.sec: dd 2
dd 0
start:
mov ax, 0x7c0
mov ds, ax
mov es, ax
mov sp, 0x1000
mov bp, 0
mov ss, bp
; Root Directory Logical Sector = (TOTAL_FATS * BLOCKS_PER_FAT) + (RESERVED_BLOCKS)
mov ax, [TOTAL_FATS]
mul word [BLOCKS_PER_FAT]
mov word [ROOT_DIRECTORY+2], dx
push dx
add ax, [RESERVED_BLOCKS]
mov word [ROOT_DIRECTORY], ax
; Load root directory
mov word [DAPACK.sec], ax
pop dx
mov word [DAPACK.sec+2], dx
mov si, DAPACK ; address of "disk address packet"
mov ah, 0x42 ; AL is unused
mov dl, 0x80 ; drive number 0 (OR the drive # with 0x80)
int 0x13
jc err
mov si, 512
mov bx, 40
call print_until
jmp $
err:
mov si, ERROR
call print
jmp $
print:
pusha
mov ah, 0eh
.repeat:
lodsb
cmp al, 0
je .done
int 10h
jmp .repeat
.done:
popa
ret
print_until:
mov ah, 0eh
.repeat:
lodsb
cmp bx, 0
je .done
int 10h
dec bx
jmp .repeat
.done:
popa
ret
ERROR db "Failed to load sector", 10, 13, 0
times 510-($-$$) db 0 ; fill in the remaining space with zero
dw 0xaa55 ; legacy boot signature
Code: Select all
start:
mov ax, 0x7c0
mov ds, ax
mov es, ax
mov sp, 0x1000
mov bp, 0 ; <----- Critical point
mov ss, bp
Code: Select all
start:
jmp 0x7c0:update_cs
update_cs:
mov ax, 0x7c0
mov ds, ax
mov es, ax
cli
mov sp, 0x1000
mov bp, 0
mov ss, bp
sti
How many bytes is a jump? 2? 3? 5? How many bytes should exist between the start of the sector and the OEM field?org 0
jmp start
MANU_DESC db 'mkdosfs '
Code: Select all
jmp word start
Code: Select all
jmp short start
nop
Code: Select all
start: JMP loader
TIMES 0Bh-$+start DB 0
bpbBytesPerSector: DW 512
I believe you meant the direction flag, not the carry flag.Prochamber wrote:By the way, if you want to do memory to memory moves, you could use the movs instruction. This copies a byte,
word or double word from DS:SI to ES:DI and increases both SI and DI if the carry flag is cleared. Otherwise they are decreased.
Hi thanks for your response, When I look at the hex code the jump has allocated 3 bytes and the file system works fineProchamber wrote:Here's the problem: Optimizations.
When the context is not specific and optimizations are enabled, NASM will try to generate the smallest and/or fastest instruction possible. The maximum level of optimization is enabled by default. Your initial jump must occupy three bytes or it will break the file system.
So, unless you disable optimizations or specify the length of your jump NASM will compile this as the smallest possible jump, which is a two byte jump. I recommend you either
a) Be more specific (recommended)ORCode: Select all
jmp word start
b) Assemble with the -O0 flag to disable optimizations.Code: Select all
jmp short start nop
By the way, if you want to do memory to memory moves, you could use the movs instruction. This copies a byte,
word or double word from DS:SI to ES:DI and increases both SI and DI if the carry flag is cleared. Otherwise they are decreased.
Code: Select all
00000000 EB4F jmp short 0x51
Yes I am sure because both windows and linux can recognize the file system and it runs fine in qemu. But I am not 100% sure I have the latest version of nasm so I will modify the JMP just to take precautions cheers for letting me know about thatProchamber wrote:Are you sure? When I compiled your code with the latest version of NASM, ndisasm shows the first instruction being a two byte 'short' jump with no intervention. This is followed directly by the OEM identifier.Code: Select all
00000000 EB4F jmp short 0x51
Code: Select all
print_until:
pusha
mov ah, 0Eh
.repeat:
lodsb
int 10h
loop .repeat
popa
ret
It's not necessary to disable interrupts if the SS is loaded first. The processor does it for you automatically.You should clear interrupt before changing the stack pointer and segment then restore them afterwards.
The Intel manual wrote:Loading the SS register with a MOV instruction inhibits all interrupts until after the execution of the next instruction. This operation allows a stack pointer to be loaded into the ESP register with the next instruction (MOV ESP, stack-pointer value) before an interrupt occurs1. Be aware that the LSS instruction offers a more efficient method of loading the SS and ESP registers.