/branches/dd/kernel/generic/include/string.h |
---|
42,14 → 42,14 |
extern char invalch; |
extern wchar_t chr_decode(const char *, size_t *, size_t); |
extern bool chr_encode(const wchar_t, char *, size_t *, size_t limit); |
extern size_t utf8_count_bytes(const char *str, count_t count); |
extern bool chr_encode(const wchar_t, char *, size_t *, size_t); |
extern size_t str_lsize(const char *, count_t); |
extern bool ascii_check(const wchar_t ch); |
extern bool unicode_check(const wchar_t ch); |
extern size_t strlen(const char *str); |
extern size_t strlen_utf8(const char *str); |
extern size_t strlen_utf32(const wchar_t *str); |
extern count_t str_length(const char *str); |
extern count_t wstr_length(const wchar_t *str); |
extern int strcmp(const char *src, const char *dst); |
extern int strncmp(const char *src, const char *dst, size_t len); |
/branches/dd/kernel/generic/src/printf/printf_core.c |
---|
254,7 → 254,7 |
return printf_putstr(nullstr, ps); |
/* Print leading spaces */ |
size_t size = strlen_utf8(str); |
size_t size = str_length(str); |
if (precision == 0) |
precision = size; |
268,7 → 268,7 |
} |
int retval; |
size_t bytes = utf8_count_bytes(str, min(size, precision)); |
size_t bytes = str_lsize(str, min(size, precision)); |
if ((retval = printf_putnchars_utf8(str, bytes, ps)) < 0) |
return -counter; |
298,7 → 298,7 |
return printf_putstr(nullstr, ps); |
/* Print leading spaces */ |
size_t size = strlen_utf32(str); |
size_t size = wstr_length(str); |
if (precision == 0) |
precision = size; |
/branches/dd/kernel/generic/src/lib/string.c |
---|
199,37 → 199,35 |
return true; |
} |
/** Get bytes used by UTF-8 characters. |
/** Get size of string, with length limit. |
* |
* Get the number of bytes (count of plain characters) which |
* are used by a given count of UTF-8 characters in a string. |
* As UTF-8 encoding is multibyte, there is no constant |
* correspondence between number of characters and used bytes. |
* Get the number of bytes which are used by up to @a max_len first |
* characters in the string @a str. If @a max_len is greater than |
* the length of @a str, the entire string is measured. |
* |
* @param str UTF-8 string to consider. |
* @param count Number of UTF-8 characters to count. |
* @param str String to consider. |
* @param count Maximum number of characters to measure. |
* |
* @return Number of bytes used by the characters. |
* |
*/ |
size_t utf8_count_bytes(const char *str, count_t count) |
size_t str_lsize(const char *str, count_t max_len) |
{ |
size_t size = 0; |
index_t index = 0; |
index_t iprev; |
count_t len = 0; |
size_t cur = 0; |
size_t prev; |
wchar_t ch; |
while (true) { |
iprev = index; |
if (size >= count) |
prev = cur; |
if (len >= max_len) |
break; |
ch = chr_decode(str, &index, UTF8_NO_LIMIT); |
ch = chr_decode(str, &cur, UTF8_NO_LIMIT); |
if (ch == '\0') break; |
size++; |
len++; |
} |
return iprev; |
return prev; |
} |
/** Check whether character is plain ASCII. |
262,7 → 260,7 |
* |
* @param str NULL-terminated string. |
* |
* @return Number of characters in str. |
* @return Number of characters in @a str. |
* |
*/ |
size_t strlen(const char *str) |
273,38 → 271,37 |
return size; |
} |
/** Return number of UTF-8 characters in a string. |
/** Return number of characters in a string. |
* |
* @param str NULL-terminated UTF-8 string. |
* |
* @return Number of UTF-8 characters in str. |
* |
* @param str NULL-terminated string. |
* @return Number of characters in string. |
*/ |
size_t strlen_utf8(const char *str) |
count_t str_length(const char *str) |
{ |
size_t size = 0; |
index_t index = 0; |
count_t len = 0; |
size_t offset = 0; |
while (chr_decode(str, &index, UTF8_NO_LIMIT) != 0) { |
size++; |
while (chr_decode(str, &offset, UTF8_NO_LIMIT) != 0) { |
len++; |
} |
return size; |
return len; |
} |
/** Return number of UTF-32 characters in a string. |
/** Return number of characters in a wide string. |
* |
* @param str NULL-terminated UTF-32 string. |
* |
* @return Number of UTF-32 characters in str. |
* |
* @param str NULL-terminated wide string. |
* @return Number of characters in @a str. |
*/ |
size_t strlen_utf32(const wchar_t *str) |
count_t wstr_length(const wchar_t *wstr) |
{ |
size_t size; |
for (size = 0; str[size]; size++); |
count_t len; |
return size; |
len = 0; |
while (*wstr++ != '\0') |
++len; |
return len; |
} |
/** Compare two NULL terminated strings |
/branches/dd/kernel/arch/sparc64/src/asm.S |
---|
228,7 → 228,12 |
b _memsetb |
nop |
.global memsetw |
memsetw: |
b _memsetw |
nop |
.macro WRITE_ALTERNATE_REGISTER reg, bit |
rdpr %pstate, %g1 ! save PSTATE.PEF |
wrpr %g0, (\bit | PSTATE_PRIV_BIT), %pstate |
/branches/dd/kernel/arch/sparc64/src/drivers/sgcn.c |
---|
130,7 → 130,7 |
/* functions referenced from definitions of I/O operations structures */ |
static void sgcn_putchar(outdev_t *, const char, bool); |
static void sgcn_putchar(outdev_t *, const wchar_t, bool); |
/** SGCN output device operations */ |
static outdev_operations_t sgcnout_ops = { |
264,18 → 264,20 |
} |
/** |
* SGCN output operation. Prints a single character to the SGCN. If the line |
* feed character is written ('\n'), the carriage return character ('\r') is |
* written straight away. |
* SGCN output operation. Prints a single character to the SGCN. Newline |
* character is converted to CRLF. |
*/ |
static void sgcn_putchar(outdev_t *od, const char c, bool silent) |
static void sgcn_putchar(outdev_t *od, const wchar_t ch, bool silent) |
{ |
if (!silent) { |
spinlock_lock(&sgcn_output_lock); |
sgcn_do_putchar(c); |
if (c == '\n') |
if (ascii_check(ch)) { |
if (ch == '\n') |
sgcn_do_putchar('\r'); |
sgcn_do_putchar(ch); |
} else |
sgcn_do_putchar(invalch); |
spinlock_unlock(&sgcn_output_lock); |
} |
/branches/dd/uspace/srv/pci/libpci/i386-ports.c |
---|
14,7 → 14,10 |
#include "internal.h" |
#define PCI_CONF1 0xcf8 |
#define PCI_CONF1_SIZE 8 |
static void conf12_init(struct pci_access *a) |
{ |
} |
71,6 → 74,14 |
unsigned int tmp; |
int res = 0; |
/* |
* Gain control over PCI configuration ports. |
*/ |
void * addr; |
if (pio_enable((void *)PCI_CONF1, PCI_CONF1_SIZE, &addr)) { |
return 0; |
} |
pio_write_8(0xCFB, 0x01); |
tmp = pio_read_32(0xCF8); |
pio_write_32(0xCF8, 0x80000000); |
142,6 → 153,17 |
static int conf2_detect(struct pci_access *a) |
{ |
/* |
* Gain control over PCI configuration ports. |
*/ |
void * addr; |
if (pio_enable((void *)PCI_CONF1, PCI_CONF1_SIZE, &addr)) { |
return 0; |
} |
if (pio_enable((void *)0xC000, 0x1000, &addr)) { |
return 0; |
} |
/* This is ugly and tends to produce false positives. Beware. */ |
pio_write_8(0xCFB, 0x00); |
pio_write_8(0xCF8, 0x00); |
178,7 → 200,7 |
pio_write_8(0xcf8, 0); |
return pci_generic_block_read(d, pos, buf, len); |
} |
pio_write_8((void *)0xcf8, 0); |
pio_write_8(0xcf8, 0); |
return 1; |
} |
/branches/dd/uspace/srv/pci/libpci/pci.h |
---|
26,6 → 26,7 |
/* Known access methods, remember to update access.c as well */ |
PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */ |
PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */ |
PCI_ACCESS_US2I, |
PCI_ACCESS_MAX |
}; |
/branches/dd/uspace/srv/pci/libpci/access.c |
---|
16,8 → 16,19 |
#include "internal.h" |
static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = { |
#ifdef UARCH_ia32 |
&pm_intel_conf1, |
&pm_intel_conf2, |
#else |
0, |
0, |
#endif |
#ifdef UARCH_sparc64 |
&pm_us2i |
#else |
0 |
#endif |
}; |
struct pci_access *pci_alloc(void) |
/branches/dd/uspace/srv/pci/libpci/internal.h |
---|
38,6 → 38,6 |
struct pci_dev *pci_alloc_dev(struct pci_access *); |
int pci_link_dev(struct pci_access *, struct pci_dev *); |
extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc, |
extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_us2i, pm_linux_proc, |
pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device, |
pm_dump, pm_linux_sysfs; |
/branches/dd/uspace/srv/pci/libpci/us2i.c |
---|
0,0 → 1,125 |
#include <unistd.h> |
#include <ddi.h> |
#include <libarch/ddi.h> |
#include <stdio.h> |
#include "internal.h" |
#include "header.h" |
/* physical addresses and offsets */ |
#define U2P_BASE 0x1FE00000000 |
#define PCI_CONF_OFFSET 0x001000000 |
#define PCI_CONF_SIZE 0x001000000 |
#define PCI_CONF_BASE (U2P_BASE + PCI_CONF_OFFSET) |
/* virtual address of PCI configuration space */ |
static void *conf_addr = 0; |
/* |
* virtual address of specified PCI configuration register: |
* bus ... bus number (0 for top level PCI bus B, 1 for top level PCI bus A) |
* dev ... device number (0 - 15) |
* fn ... function number (0 - 7) |
* reg ... register number (register's position within PCI configuration header) |
**/ |
#define CONF_ADDR(bus, dev, fn, reg) (conf_addr + ((bus << 16) | (dev << 11) | (fn << 8) | (reg << 2))) |
static void us2i_init(struct pci_access *a) |
{ |
} |
static void us2i_cleanup(struct pci_access *a UNUSED) |
{ |
} |
static int us2i_detect(struct pci_access *a) |
{ |
unsigned int tmp; |
/* |
* Gain control over PCI configuration ports. |
*/ |
if (pio_enable((void *)PCI_CONF_BASE, PCI_CONF_SIZE, &conf_addr)) { |
return 0; |
} |
printf("PCI: conf_addr = %lx", conf_addr); |
printf("PCI: vendor id address = %lx", CONF_ADDR(0, 0, 0, PCI_VENDOR_ID)); |
asm volatile ("sethi 0x42224, %g0"); |
int vendor_id = pio_read_16(CONF_ADDR(0, 0, 0, PCI_VENDOR_ID)); |
vendor_id = vendor_id | pio_read_8(CONF_ADDR(0, 0, 0, PCI_VENDOR_ID + 1)) << 8; |
int device_id = pio_read_8(CONF_ADDR(0, 0, 0, PCI_DEVICE_ID)); |
device_id = device_id | pio_read_8(CONF_ADDR(0, 0, 0, PCI_DEVICE_ID + 1)) << 8; |
printf("PCI: vendor id = %x", vendor_id); |
printf("PCI: device id = %x", device_id); |
return vendor_id == 0x108E && device_id == 0x8000; // should be Psycho from Sun Microsystems |
} |
static int us2i_read(struct pci_dev *d, int pos, byte * buf, int len) |
{ |
if (pos >= 256) |
return 0; |
switch (len) { |
case 1: |
buf[0] = pio_read_8(CONF_ADDR(d->bus, d->dev, d->func, pos)); |
break; |
case 2: |
us2i_read(d, pos + 1, buf, 1); // unlike PCI, sparc uses big endian |
us2i_read(d, pos, buf + 1, 1); |
break; |
case 4: |
us2i_read(d, pos + 3, buf, 1); // endians in an ugly way ... FIX ME |
us2i_read(d, pos + 2, buf + 1, 1); |
us2i_read(d, pos + 1, buf + 2, 1); |
us2i_read(d, pos, buf + 3, 1); |
break; |
default: |
return pci_generic_block_read(d, pos, buf, len); |
} |
return 1; |
} |
static int us2i_write(struct pci_dev *d, int pos, byte * buf, int len) |
{ |
if (pos >= 256) |
return 0; |
switch (len) { |
case 1: |
pio_write_8(CONF_ADDR(d->bus, d->dev, d->func, pos), buf[0]); |
break; |
case 2: |
us2i_write(d, pos + 1, buf, 1); // unlike PCI, sparc uses big endian |
us2i_write(d, pos, buf + 1, 1); |
break; |
case 4: |
us2i_write(d, pos + 3, buf, 1); // endians in an ugly way ... FIX ME |
us2i_write(d, pos + 2, buf + 1, 1); |
us2i_write(d, pos + 1, buf + 2, 1); |
us2i_write(d, pos, buf + 3, 1); |
break; |
default: |
return pci_generic_block_write(d, pos, buf, len); |
} |
return 1; |
} |
struct pci_methods pm_us2i = { |
"Ultra Sparc IIi", |
NULL, /* config */ |
us2i_detect, |
us2i_init, |
us2i_cleanup, |
pci_generic_scan, |
pci_generic_fill_info, |
us2i_read, |
us2i_write, |
NULL, /* init_dev */ |
NULL /* cleanup_dev */ |
}; |
/branches/dd/uspace/srv/pci/libpci/Makefile |
---|
15,7 → 15,7 |
PCILIB=libpci.a |
OBJS += i386-ports.o |
OBJS += i386-ports.o us2i.o |
all: $(PCILIB) |
/branches/dd/uspace/srv/pci/pci.c |
---|
22,9 → 22,6 |
#include "libpci/pci.h" |
#define PCI_CONF1 0xcf8 |
#define PCI_CONF1_SIZE 8 |
#define NAME "PCI" |
static struct pci_access *pacc; |
38,12 → 35,6 |
printf("%s: HelenOS PCI driver\n", NAME); |
/* |
* Gain control over PCI configuration ports. |
*/ |
void * addr; |
pio_enable((void *) PCI_CONF1, PCI_CONF1_SIZE, &addr); |
pacc = pci_alloc(); /* Get the pci_access structure */ |
pci_init(pacc); /* Initialize the PCI library */ |
pci_scan_bus(pacc); /* We want to get the list of devices */ |
/branches/dd/uspace/Makefile |
---|
65,7 → 65,8 |
ifeq ($(UARCH),sparc64) |
DIRS += \ |
srv/fhc \ |
srv/obio |
srv/obio \ |
srv/pci |
endif |
BUILDS := $(addsuffix .build,$(DIRS)) |
/branches/dd/boot/arch/sparc64/loader/Makefile |
---|
101,7 → 101,8 |
$(USPACEDIR)/srv/fb/fb \ |
$(USPACEDIR)/srv/kbd/kbd \ |
$(USPACEDIR)/srv/console/console \ |
$(USPACEDIR)/srv/fs/tmpfs/tmpfs |
$(USPACEDIR)/srv/fs/tmpfs/tmpfs \ |
$(USPACEDIR)/srv/pci/pci |
ifeq ($(MACHINE),generic) |
RD_SRVS += \ |