flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Extra Characters on first line, x64 only (fixed, not bug)

Author
Thread Post new topic Reply to topic
Daedalus



Joined: 25 Mar 2007
Posts: 52
Daedalus 03 Mar 2008, 08:12
When I compile this code:

Code:
format binary as 'img'
use16
org 0x7c00

;############################## Start of 1st part  ##############################
part1:

jmp bootcode  ;Jump to bootcode

;The code below is based on the FAT16 definition.
  times 3-($-$$) db 0
  DB "BosByte"           ;Microsoft wants us to put "MSWIN4.1" in here... fuck them!
  times 11-($-$$) db 0
  DW 512     ;Bytes per sector (do not change!)
  DB 1       ;Sectors per Cluster
  DW 1       ;Reserved sector count
  DB 0x02    ;Num FATs (is ALWAYS 0x02)
  DW 512     ;Root entry's count (Should be 512 for FAT16)
  DW 2880    ;Sector count (2880 for 1.44 MB floppy)
  DB 0xF0    ;Media (0xF0 is common)
  DW 9       ;FatSize
  DW 18      ;Sectors per Track (used by Interupt)
  DW 2       ;Heads count (should be 2 for 1.44 MB floppy)
  DD 0       ;Hidden sectors
  DD 0       ;Used by FAT32
  ;Should be at offset 36 now . . .
  DB 0x00    ;Drivenum (0 = floppy1)
  DB 0       ;Reserved for windows NT, fuck windows!
  DB 0x29    ;Indicates that the following three fields are present
  DD 12345   ;VolumeID (just random shizzle)
  DB "W00t-OS" ;VolumeName (max 11 chars)
  times 54-($-$$) db " " ;Fill Volumename up to 11 chars
  DB "FAT16" ;FileSysType (max 8 chars)
  times 62-($-$$) db " " ;Fill FileSysType up to 8 chars
;End of FAT16 header

times 64-($-$$) db 0
;Now start the bootcode at offset 64:

bootcode:

;Creating stack . . .
cli
mov ax, 0x9000
mov ss, ax
mov ax, 0xFFFF
mov sp, ax
sti
;Stack created

call initscreen

mov si, BootMsg1
call puts

mov bl, 0x0C
mov si, BootMsg2
call putcs

call loadpart2

jmp part2

BootMsg1: DB "NM-SOFT W00t-OS [Version 0.0.1]",13,10,"Copyright (C) 2008 NM-Soft. All rights reserved.",10,13,0
BootMsg2: DB 10,13,"Please wait while loading W00t-OS from drive A . . .",10,13,0

;-------------- Functions  ---------------

include 'functions1.inc.asm'

;Loadpart2(void)
loadpart2:
 mov ah, 0x02
 mov al, 3    ;number of sectors to read
 mov cl, 2    ;Sector number
 mov dl, 0x00 ;Drive number (0=A:, 1=2nd floppy, 80h=drive 0, 81h=drive 1)
 mov ch, 0x00
 mov dh, 0x00
 push 0x0000
 pop es
 mov bx, part2   ; ES:BX = pointer to buffer
 int 0x13    ; int IO (ah = 0x02 means READ) sets CF on error, clears it on succes
 jnc .return
 mov si,.errormsg
 call puts
.error:
 jmp .error
.return:
 ret
.errormsg:
 DB "An error occured while loading sectors 0x02 to 0x04.",0


;##############################  End of 1st part   ##############################

times 510-($-$$) db 0
dw 0xAA55

;############################## Start of 2nd part  ##############################
part2:

call mode13

mov si, .msg1
call puts

;Create GDT

mov ax, 0x0100
mov es, ax
mov di, 0x0000

;Making a GDT POINTER:

; bx base low   (word)
; dx base high  (word)
; cx limit      (word)

.gdtPointer:
mov bx, 0x1006        ;base low   (word)
mov dx, 0             ;base high  (word)
mov cx, 5*8-1         ;limit      (word)   = count(entries) * sizeof(entry) - 1
call gdtWritePointer  ;Write GDT POINTER

;Making the GDT itself:

mov bx, 0  ;base low
mov dx, 0  ;base high
mov cx, 0  ;limit
mov al, 0  ;access
mov ah, 0  ;gran
call gdtWriteEntry   ;First entry should be NULL

mov bx, 0             ;base low   (word)
mov dx, 0             ;base high  (word)
mov cx, 0xFfFF        ;limit low  (word)
mov ah, 0x0F + 16*1100b ;limit high (nibble) + gran (nibble)
mov al, 0x9A          ;access (byte)
call gdtWriteEntry ;Write CODE segment (covers all memory)

mov bx, 0             ;base low   (word)
mov dx, 0             ;base high  (word)
mov cx, 0xFFFF        ;limit low  (word)
mov ah, 0x0F + 16*1100b ;limit high (nibble) + gran (nibble)
mov al, 0x92          ;access (byte)
call gdtWriteEntry ;Write DATA segment (covers all memory)

mov bx, 0x0000        ;base low   (word)         base = 90000
mov dx, 0x0009        ;base high  (word)
mov cx, 0xFFFF        ;limit low  (word)         limit = A0000
mov ah, 0x00 + 16*0100b ;limit high (nibble) + gran (nibble)
mov al, 0x92          ;access (byte)
call gdtWriteEntry ;Write STACK segment (0x9000:0 - 0x9000:0xFFFF)

mov bx, 0x0000        ;base low   (word)         base = A0000
mov dx, 0x000A        ;base high  (word)
mov cx, 0xFFFF        ;limit low  (word)         limit = C0000
mov ah, 0x01 + 16*0100b ;limit high (nibble) + gran (nibble)
mov al, 0x92          ;access (byte)
call gdtWriteEntry ;Write VIDEO segment (0xA000:0 - 0xB000:0xFFFF)

mov si, .msg2
call puts

;Now entering Protected Mode:

mov al, '0'
call putc

mov al, '1'
call putc

lgdt [.gdtPointer]  ;Let the CPU know where the GDT (pointer) is

mov al, '2'
call putc

mov ax,2401
int 15  ;enable A20

mov al, '3'
call putc

mov al, 'a'
call putc
mov eax, cr0
mov al, 'b'
call putc
or eax, 1        ;Set de PE bit in the MSW register
mov al, 'c'
call putc
mov cr0, eax

mov si, .msg1
call fputs

mov ax, 8*2 ; item 2 in GDT is the DATA segment . . .
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

mov al, '5'
call putc

mov ax, 8*3 ; item 3 in GDT is the STACK segment . . .
mov ss, ax

mov al, '6'
call putc

cli ;Disable interupts

jmp 0x08:ProtectedMode ;Far jump to protected mode (0x08 referers to item 8 in the GDT, that's the CODE segment)

.msg1:
DB "W00t-OS was succesfully loaded from drive A.",10,13,10,13,"Creating GDT . . .",10,13,0

.msg2:
DB 10,13,10,13,"Entering protected mode (32 bit) . . .",10,13,0

ProtectedMode:

call fprintcolors

.end:
jmp .end


;-------------- Functions  ---------------

include 'functions2.inc.asm'

include 'gdt.inc.asm'

;##############################  End of 2nd part   ##############################

times 2048-($-$$) db 0

;##############################  End of everyting  ##############################

times 1474560-($-$$) db 0
    


It doesn't work on x64 because the first line has "extra characters on line", but it does work on 32 bit XP.


Last edited by Daedalus on 03 Mar 2008, 14:57; edited 1 time in total
Post 03 Mar 2008, 08:12
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 03 Mar 2008, 08:44
You have an extraneous "as 'img'" on your first line. Just delete that part so that the first line is "format binary".
Post 03 Mar 2008, 08:44
View user's profile Send private message Visit poster's website Reply with quote
Daedalus



Joined: 25 Mar 2007
Posts: 52
Daedalus 03 Mar 2008, 08:53
That doesn't explain why it does work on one and doesn't on the other? It outputs the file as bootloader.img then. It's convenient and it works on 32bit.
Post 03 Mar 2008, 08:53
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 03 Mar 2008, 09:01
Daedalus wrote:
That doesn't explain why it does work on one and doesn't on the other? It outputs the file as bootloader.img then. It's convenient and it works on 32bit.
Okay, I didn't realise what you were doing. But what do you mean by x64? I thought fasm only comes in 32bit versions?
Post 03 Mar 2008, 09:01
View user's profile Send private message Visit poster's website Reply with quote
Daedalus



Joined: 25 Mar 2007
Posts: 52
Daedalus 03 Mar 2008, 09:07
Oh sorry.

I have Windows XP x64 edition and Windows XP 32 bit.

This code DOES compile on Windows XP 32, but doesn't on Windows XP x64 edition.

I'm using the same executable (same FASM), but for some reason it executes different on XP x64 edition than on 32bit XP.
Post 03 Mar 2008, 09:07
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 03 Mar 2008, 09:31
Daedalus wrote:
This code DOES compile on Windows XP 32, but doesn't on Windows XP x64 edition.
I'm using the same executable (same FASM), but for some reason it executes different on XP x64 edition than on 32bit XP.
That seems kinda weird Confused

I guess the only thing I can think of to check is that the version numbers etc. are really the same (anything below 1.67.22 doesn't have the 'as' operator). So assuming that the versions are the same, as you say, then it would seem to be a Windows issue??

I can't test here, I've only got Win32.
Post 03 Mar 2008, 09:31
View user's profile Send private message Visit poster's website Reply with quote
Daedalus



Joined: 25 Mar 2007
Posts: 52
Daedalus 03 Mar 2008, 14:56
Ah, that ought to be it then.. I figured they were using the same version number, but the link I had on my desktop was outdated, I do have both, haha. I'm using 1.67.14 on Win x64. My bad.

Thanks. Smile
Post 03 Mar 2008, 14:56
View user's profile Send private message MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.