OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Nov 14, 2018 1:27 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: GNU AS : "push" and "pop" instructions not supported !
PostPosted: Wed Jul 11, 2018 4:27 am 
Offline

Joined: Sun Jan 29, 2017 2:36 pm
Posts: 8
Hello,

I'm currently writing a MBR, it contains a function to copy some sectors of the disk to the RAM and I decided to pass the parameters to this function by pushing them onto the stack but when I
Code:
as -o mbr.elf mbr.s
GAS says that "push" (and "pop") instructions are not supported !
I can't figure out why they are not supported and how to fix this, can you help me ?
Here is the code of the MBR :
Code:

   .code16   /* CPU is in 16 bits real mode */

start:   
   /* MBR code is loaded at 0x7C00 by the BIOS */
   mov $0x07C0, %ax
   mov %ax, %ds
   /* Stack grows downward from 0x80000 */
   mov $0x8000, %ax
   mov %ax, %ss
   mov $0x00, %sp
   
   movb %dl, (drive) /* Save drive number */

   /* Copy second sector to 0x500 */
   push %dl   /* Drive number */
   mov $0x01, %al   
   push %al   /* Copy 1 sector */
   mov $0x0500, %ax
   push %ax   /* Copy to 0x500 */
   mov $0x02, %al
   push %al   /* Sector 2 */
   mov $0x00, %al
   push %al   /* Head 0 */
   push %al   /* Cylinder 0 */
   call copy

end:
   jmp end
/* ----------------------- Copy function --------------------------

   Copies some sectors to RAM. Push arguments on stack
   in this order:
   + Drive number (byte)
   + Number of sectors to copy (byte)
   + Address of copy (word)
   + First sector CHS address as :
      - Sector (byte)
      - Head (byte)
      - Cylinder (byte)
   
------------------------------------------------------------------- */
copy:
   pop %al      /* Cylinder */
   mov %al, %ch
   and $0xFF, %ch

   pop %dh      /* Head */

   shr 2, %al
   and $0xC0, %al
   pop %cl      /* Sector */
   or %al, %cl

   pop %ax      /* Address */
   mov %ax, %bx
   shr 4, %ax
   sub %ax, %bx
   mov %ax, %es

   pop %al      /* Number of sectors */
   pop %dl      /* Drive number */

   mov $0x02, %al
   int $0x13
   
   ret

drive:
   .byte 0x00
   
   /* Code space padding */
   .skip 446 - (. - start), 0x90

   /* Partition table */
   .skip 0x40, 0x00

   /* Signature */
   .byte 0x55, 0xAA



Thanks in advance !

PS: Is this the proper way to pass parameters to a function ?


Top
 Profile  
 
 Post subject: Re: GNU AS : "push" and "pop" instructions not supported !
PostPosted: Wed Jul 11, 2018 4:31 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 905
You can't push/pop a byte.


Top
 Profile  
 
 Post subject: Re: GNU AS : "push" and "pop" instructions not supported !
PostPosted: Wed Jul 11, 2018 4:56 am 
Offline

Joined: Sun Jan 29, 2017 2:36 pm
Posts: 8
Oh difficulty sometimes hide in simple problems #-o Thank you !


Top
 Profile  
 
 Post subject: Re: GNU AS : "push" and "pop" instructions not supported !
PostPosted: Wed Jul 11, 2018 5:28 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 03, 2008 4:13 am
Posts: 130
Location: Ogre, Latvia, EU
Quote:
PS: Is this the proper way to pass parameters to a function ?

The way you're passing the parameters is fine. The way, you're retrieving them (inside the function) is not.

Call instruction pushes the return address on the stack. The proper (cdecl conforming) way would be something like:
Code:
copy:
    push %bp
    mov %sp, bp

    mov 4(%bp), %ax
    mov 6(%bp), %dx

    /* do something with the values */

    pop %bp
    ret


Note: untested, I may have mixed up the parameter sequence, but the main idea is there.

_________________
If something looks overcomplicated, most likely it is.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: kzinti and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group