Skip to content

Commit b8799bc

Browse files
author
Ian Seyler
committed
Use 32-bit registers where possible.
Saves ~180 bytes with 5-byte vs 9-byte instructions
1 parent 7370a06 commit b8799bc

File tree

17 files changed

+74
-76
lines changed

17 files changed

+74
-76
lines changed

src/drivers/net/i8254x.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ net_i8254x_init:
7575
call net_i8254x_reset
7676

7777
; Store call addresses
78-
mov rax, net_i8254x_config
78+
mov eax, net_i8254x_config
7979
mov [rdi+nt_config], rax
80-
mov rax, net_i8254x_transmit
80+
mov eax, net_i8254x_transmit
8181
mov [rdi+nt_transmit], rax
82-
mov rax, net_i8254x_poll
82+
mov eax, net_i8254x_poll
8383
mov [rdi+nt_poll], rax
8484

8585
net_i8254x_init_error:

src/drivers/net/i8257x.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ net_i8257x_init:
7878
call net_i8257x_reset
7979

8080
; Store call addresses
81-
mov rax, net_i8257x_config
81+
mov eax, net_i8257x_config
8282
mov [rdi+nt_config], rax
83-
mov rax, net_i8257x_transmit
83+
mov eax, net_i8257x_transmit
8484
mov [rdi+nt_transmit], rax
85-
mov rax, net_i8257x_poll
85+
mov eax, net_i8257x_poll
8686
mov [rdi+nt_poll], rax
8787

8888
net_i8257x_init_error:

src/drivers/net/i8259x.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ net_i8259x_init:
7575
call net_i8259x_reset
7676

7777
; Store call addresses
78-
mov rax, net_i8259x_config
78+
mov eax, net_i8259x_config
7979
mov [rdi+nt_config], rax
80-
mov rax, net_i8259x_transmit
80+
mov eax, net_i8259x_transmit
8181
mov [rdi+nt_transmit], rax
82-
mov rax, net_i8259x_poll
82+
mov eax, net_i8259x_poll
8383
mov [rdi+nt_poll], rax
8484
mov eax, i8259x_MAX_DESC - 1
8585
mov [rdi+nt_rx_tail], eax

src/drivers/net/virtio-net.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ virtio_net_init_cap_end:
199199

200200
; Store call addresses
201201
sub rdi, 0x28
202-
mov rax, net_virtio_config
202+
mov eax, net_virtio_config
203203
stosq
204-
mov rax, net_virtio_transmit
204+
mov eax, net_virtio_transmit
205205
stosq
206-
mov rax, net_virtio_poll
206+
mov eax, net_virtio_poll
207207
stosq
208208

209209
virtio_net_init_error:
@@ -452,7 +452,7 @@ net_virtio_transmit:
452452

453453
; Create first entry in the Descriptor Table
454454
mov rdi, r8
455-
mov rax, virtio_net_hdr ; Address of the 12-byte virtio_net_hdr
455+
mov eax, virtio_net_hdr ; Address of the 12-byte virtio_net_hdr
456456
stosq ; 64-bit address
457457
mov eax, 12
458458
stosd ; 32-bit length

src/drivers/nvs/ahci.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ ahci_init_search_ports_done:
176176
ahci_init_done:
177177
bts word [os_nvsVar], 1 ; Set the bit flag that AHCI has been initialized
178178
mov rdi, os_nvs_io
179-
mov rax, ahci_io
179+
mov eax, ahci_io
180180
stosq
181-
mov rax, ahci_id
181+
mov eax, ahci_id
182182
stosq
183183
pop rdx
184184
pop rsi

src/drivers/nvs/nvme.asm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ nvme_init_LBA_end:
174174
nvme_init_done:
175175
bts word [os_nvsVar], 0 ; Set the bit flag that NVMe has been initialized
176176
mov rdi, os_nvs_io
177-
mov rax, nvme_io
177+
mov eax, nvme_io
178178
stosq
179-
mov rax, nvme_id
179+
mov eax, nvme_id
180180
stosq
181181
pop rdx
182182
pop rsi
@@ -352,13 +352,13 @@ nvme_io_next_rpr:
352352
stosq
353353
sub rcx, 1
354354
cmp rcx, 0
355-
jne nvme_io_next_rpr
355+
jne nvme_io_next_rpr
356356
pop rdi
357357
mov rax, os_nvme_rpr
358358
jmp nvme_io_calc_rpr2_end ; Write the address of the RPR2 data
359359
nvme_io_calc_rpr2_skip:
360360
add rax, 4096
361-
nvme_io_calc_rpr2_end:
361+
nvme_io_calc_rpr2_end:
362362
stosq ; CDW8-9 PRP2
363363
pop rcx ; Restore the sector count
364364

@@ -463,7 +463,7 @@ NVMe_PMRCAP equ 0xE00 ; 4-byte Persistent Memory Region Capabilities
463463
NVMe_PMRCTL equ 0xE04 ; 4-byte Persistent Memory Region Control
464464
NVMe_PMRSTS equ 0xE08 ; 4-byte Persistent Memory Region Status
465465
NVMe_PMREBS equ 0xE0C ; 4-byte Persistent Memory Region Elasticity Buffer Size
466-
NVMe_PMRSWTP equ 0xE10 ; 4-byte Persistent Memory Region Sustained Write Throughput
466+
NVMe_PMRSWTP equ 0xE10 ; 4-byte Persistent Memory Region Sustained Write Throughput
467467
NVMe_PMRMSCL equ 0xE14 ; 4-byte Persistent Memory Region Memory Space Control Lower
468468
NVMe_PMRMSCU equ 0xE18 ; 4-byte Persistent Memory Region Memory Space Control Upper
469469

src/drivers/nvs/virtio-blk.asm

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ virtio_blk_init_cap_end:
105105
; Device Initialization (section 3.1)
106106

107107
; 3.1.1 - Step 1 - Reset the device (section 2.4)
108-
mov al, 0x00
108+
mov al, 0x00
109109
mov [rsi+VIRTIO_DEVICE_STATUS], al
110110
virtio_blk_init_reset_wait:
111111
mov al, [rsi+VIRTIO_DEVICE_STATUS]
@@ -202,9 +202,9 @@ virtio_blk_init_pop:
202202
virtio_blk_init_done:
203203
bts word [os_nvsVar], 3 ; Set the bit flag that Virtio Block has been initialized
204204
mov rdi, os_nvs_io ; Write over the storage function addresses
205-
mov rax, virtio_blk_io
205+
mov eax, virtio_blk_io
206206
stosq
207-
mov rax, virtio_blk_id
207+
mov eax, virtio_blk_id
208208
stosq
209209
pop rax
210210
pop rbx
@@ -248,7 +248,7 @@ virtio_blk_io:
248248
; FIXME: Add desc_index offset
249249

250250
; Add header to Descriptor Entry 0
251-
mov rax, header ; Address of the header
251+
mov eax, header ; Address of the header
252252
stosq ; 64-bit address
253253
mov eax, 16
254254
stosd ; 32-bit length
@@ -267,7 +267,7 @@ virtio_blk_io:
267267
add rdi, 2 ; Skip Next as it is pre-populated
268268

269269
; Add footer to Descriptor Entry 3
270-
mov rax, footer ; Address of the footer
270+
mov eax, footer ; Address of the footer
271271
stosq ; 64-bit address
272272
mov eax, 1
273273
stosd ; 32-bit length
@@ -276,7 +276,7 @@ virtio_blk_io:
276276
add rdi, 2 ; Skip Next as it is pre-populated
277277

278278
; Build the header
279-
mov rdi, header
279+
mov edi, header
280280
; BareMetal I/O opcode for Read is 2, Write is 1
281281
; Virtio-blk I/O opcode for Read is 0, Write is 1
282282
; FIXME: Currently we just clear bit 1.
@@ -290,7 +290,7 @@ virtio_blk_io:
290290
stosq ; starting sector
291291

292292
; Build the footer
293-
mov rdi, footer
293+
mov edi, footer
294294
xor eax, eax
295295
stosb
296296

@@ -331,7 +331,7 @@ virtio_blk_io_wait:
331331

332332

333333
; -----------------------------------------------------------------------------
334-
; virtio_blk_id --
334+
; virtio_blk_id --
335335
; IN: EAX = CDW0
336336
; EBX = CDW1
337337
; ECX = CDW10
@@ -380,15 +380,15 @@ VIRTIO_BLK_MIN_IO_SIZE equ 0x2E ; 16-bit SUGGESTED MINIMUM I/O SIZE IN BLOCKS
380380
VIRTIO_BLK_OPT_IO_SIZE equ 0x30 ; 32-bit OPTIMAL (SUGGESTED MAXIMUM) I/O SIZE IN BLOCKS
381381
VIRTIO_BLK_WRITEBACK equ 0x34 ; 8-bit
382382
VIRTIO_BLK_NUM_QUEUES equ 0x36 ; 16-bit
383-
VIRTIO_BLK_MAX_DISCARD_SECTORS equ 0x38 ; 32-bit
384-
VIRTIO_BLK_MAX_DISCARD_SEG equ 0x3C ; 32-bit
385-
VIRTIO_BLK_DISCARD_SECTOR_ALIGNMENT equ 0x40 ; 32-bit
386-
VIRTIO_BLK_MAX_WRITE_ZEROES_SECTORS equ 0x44 ; 32-bit
387-
VIRTIO_BLK_MAX_WRITE_ZEROES_SEG equ 0x48 ; 32-bit
383+
VIRTIO_BLK_MAX_DISCARD_SECTORS equ 0x38 ; 32-bit
384+
VIRTIO_BLK_MAX_DISCARD_SEG equ 0x3C ; 32-bit
385+
VIRTIO_BLK_DISCARD_SECTOR_ALIGNMENT equ 0x40 ; 32-bit
386+
VIRTIO_BLK_MAX_WRITE_ZEROES_SECTORS equ 0x44 ; 32-bit
387+
VIRTIO_BLK_MAX_WRITE_ZEROES_SEG equ 0x48 ; 32-bit
388388
VIRTIO_BLK_WRITE_ZEROES_MAY_UNMAP equ 0x4C ; 8-bit
389-
VIRTIO_BLK_MAX_SECURE_ERASE_SECTORS equ 0x50 ; 32-bit
390-
VIRTIO_BLK_MAX_SECURE_ERASE_SEG equ 0x54 ; 32-bit
391-
VIRTIO_BLK_SECURE_ERASE_SECTOR_ALIGNMENT equ 0x58 ; 32-bit
389+
VIRTIO_BLK_MAX_SECURE_ERASE_SECTORS equ 0x50 ; 32-bit
390+
VIRTIO_BLK_MAX_SECURE_ERASE_SEG equ 0x54 ; 32-bit
391+
VIRTIO_BLK_SECURE_ERASE_SECTOR_ALIGNMENT equ 0x58 ; 32-bit
392392

393393
; VIRTIO_DEVICEFEATURES bits
394394
VIRTIO_BLK_F_BARRIER equ 0 ; Legacy - Device supports request barriers

src/drivers/ps2.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ps2_init:
6868
bt ebx, 0
6969
jnc init_64_no_ps2keyboard
7070
mov edi, 0x21
71-
mov rax, int_keyboard
71+
mov eax, int_keyboard
7272
call create_gate
7373
; Enable specific interrupt
7474
mov ecx, 1 ; Keyboard IRQ
@@ -121,11 +121,11 @@ keydown:
121121
je keyboard_lowercase
122122

123123
keyboard_uppercase:
124-
mov rbx, keylayoutupper
124+
mov ebx, keylayoutupper
125125
jmp keyboard_processkey
126126

127127
keyboard_lowercase:
128-
mov rbx, keylayoutlower
128+
mov ebx, keylayoutlower
129129

130130
keyboard_processkey: ; Convert the scan code
131131
add rbx, rax

src/drivers/serial.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ serial_init_skip_arch:
2727
%ifdef NO_LFB
2828
; Configure interrupt handler
2929
mov edi, 0x24
30-
mov rax, int_serial
30+
mov eax, int_serial
3131
call create_gate
3232

3333
; Enable specific interrupts
@@ -41,7 +41,7 @@ serial_init_skip_arch:
4141
out dx, al
4242
%endif
4343

44-
mov rax, b_output_serial
44+
mov eax, b_output_serial
4545
mov [0x100018], rax ; Set kernel b_output to the serial port
4646

4747
serial_init_error:

src/drivers/vga.asm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ vga_init:
2222
mov dx, 0x03C8 ; DAC Address Write Mode Register
2323
out dx, al
2424
mov dx, 0x03C9 ; DAC Data Register
25-
mov rbx, 16 ; 16 lines
25+
mov ebx, 16 ; 16 lines
2626
nextlineq:
27-
mov rcx, 16 ; 16 colors
28-
mov rsi, palette
27+
mov ecx, 16 ; 16 colors
28+
mov esi, palette
2929
nexttritone:
3030
lodsb
3131
out dx, al
@@ -43,16 +43,16 @@ nexttritone:
4343
mov dx, 0x03C8 ; DAC Address Write Mode Register
4444
out dx, al
4545
mov dx, 0x03C9 ; DAC Data Register
46-
mov rsi, palette
47-
add rsi, 18
46+
mov esi, palette
47+
add esi, 18
4848
lodsb
4949
out dx, al
5050
lodsb
5151
out dx, al
5252
lodsb
5353
out dx, al
5454

55-
mov rax, vga_output_chars
55+
mov eax, vga_output_chars
5656
mov [0x100018], rax
5757

5858
ret

0 commit comments

Comments
 (0)