-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls.asm
More file actions
173 lines (147 loc) · 2.73 KB
/
Copy pathls.asm
File metadata and controls
173 lines (147 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
; ls.asm - Verbose directory listing
; Shows name, sector, count, load address, and type for each table entry
bits 16
org 0xA000
SYSCALL_INT equ 0x80
SYS_PUTC equ 0x01
SYS_PUTS equ 0x02
start:
mov ax, cs
mov ds, ax
xor ax, ax
mov es, ax
; Print header
mov si, msg_header
call sys_puts
; Program table is at kernel-known address 0x0600
; Keep loop state in memory because syscalls may clobber registers.
mov byte [entry_index], 0
mov al, [es:0x0604]
mov [entry_count], al
.list_loop:
mov al, [entry_index]
cmp al, [entry_count]
jae .done
; Calculate entry offset: base(0x0600) + 16 + (index * 16)
xor ax, ax
mov al, [entry_index]
shl ax, 4
mov bx, 0x0600
add bx, 16 ; skip header
add bx, ax ; add index offset
mov [entry_ptr], bx
; name
call print_name_8bytes
; sector
mov si, msg_sector
call sys_puts
mov bx, [entry_ptr]
mov al, [es:bx + 8]
call print_hex8
; count (size in sectors)
mov si, msg_count
call sys_puts
mov bx, [entry_ptr]
mov al, [es:bx + 9]
call print_hex8
; load address
mov si, msg_load
call sys_puts
mov bx, [entry_ptr]
mov ax, [es:bx + 10]
call print_hex16
; entry type
mov si, msg_type
call sys_puts
mov bx, [entry_ptr]
mov al, [es:bx + 14]
cmp al, 1
je .type_prog
cmp al, 2
je .type_text
mov al, '?'
jmp .type_out
.type_prog:
mov al, 'P'
jmp .type_out
.type_text:
mov al, 'T'
.type_out:
call sys_putc_char
mov si, msg_newline
call sys_puts
inc byte [entry_index]
jmp .list_loop
.done:
ret
; Print exactly 8 bytes or until first null
print_name_8bytes:
xor dx, dx
.name_loop:
cmp dx, 8
jae .name_done
mov al, [es:bx]
cmp al, 0
je .name_done
call sys_putc_char
inc bx
inc dx
jmp .name_loop
.name_done:
ret
print_hex16:
push ax
mov al, ah
call print_hex8
pop ax
call print_hex8
ret
print_hex8:
push ax
mov bl, al
shr al, 4
call print_hex_digit
mov al, bl
and al, 0x0F
call print_hex_digit
pop ax
ret
print_hex_digit:
and al, 0x0F
cmp al, 10
jl .digit
add al, 'A' - 10
jmp .emit
.digit:
add al, '0'
.emit:
call sys_putc_char
ret
; Syscall: putc
sys_putc_char:
mov ah, SYS_PUTC
int SYSCALL_INT
ret
; Syscall: puts
sys_puts:
mov ah, SYS_PUTS
int SYSCALL_INT
ret
msg_header:
db "Directory (verbose):", 13, 10, 0
msg_sector:
db " sec:", 0
msg_count:
db " cnt:", 0
msg_load:
db " load:0x", 0
msg_type:
db " type:", 0
msg_newline:
db 13, 10, 0
entry_count:
db 0
entry_index:
db 0
entry_ptr:
dw 0